Re: [RFC][PATCH v4 18/32] objtool: mcount: Move nop_mcount()

From: Matt Helsley
Date: Sat Jun 13 2020 - 15:49:39 EST


On Fri, Jun 12, 2020 at 03:26:56PM +0200, Peter Zijlstra wrote:
> On Tue, Jun 02, 2020 at 12:50:11PM -0700, Matt Helsley wrote:
> > +static int nop_mcount(struct section * const rels,
> > + const char *const txtname)
> > +{
> > + struct reloc *reloc;
> > + struct section *txts = find_section_by_index(lf, rels->sh.sh_info);
> > + unsigned mcountsym = 0;
> > + int once = 0;
> > +
> > + list_for_each_entry(reloc, &rels->reloc_list, list) {
> > + int ret = -1;
> > +
> > + if (!mcountsym)
> > + mcountsym = get_mcountsym(reloc);
> > +
> > + if (mcountsym == GELF_R_INFO(reloc->sym->idx, reloc->type) && !is_fake_mcount(reloc)) {
>
> This makes no sense to me; why not have mcountsym be a 'struct symbol
> *' and have get_mcountsym() return one of those.
>
> if (reloc->sym == mcountsym && ... )
>
> is much nicer, no?

Indeed! I'll change it from returning an unsigned long to struct symbol * before I
move it out of the wrapper code.

>
> > + if (make_nop) {
> > + ret = make_nop(txts, reloc->offset);
> > + if (ret < 0)
> > + return -1;
> > + }
> > + if (warn_on_notrace_sect && !once) {
> > + printf("Section %s has mcount callers being ignored\n",
> > + txtname);
> > + once = 1;
> > + /* just warn? */
> > + if (!make_nop)
> > + return 0;
> > + }
> > + }
> > +
> > + /*
> > + * If we successfully removed the mcount, mark the relocation
> > + * as a nop (don't do anything with it).
> > + */
> > + if (!ret) {
> > + reloc->type = rel_type_nop;
> > + rels->changed = true;
>
> I have an elf_write_rela(), I'll make sure to Cc you.

Thanks! I might also make use of your patch to rewrite instructions. We
need a way to turn certain prologue instructions into nops. Would it be
more widely useful to move that functionality out of mcount and into
the objtool ELF/per-arch code or do you think it's better inside the
mcount subcommand code?

Cheers,
-Matt