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?

> +                     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.

> +             }
> +     }
> +     return 0;
> +}

Reply via email to