Re: [PATCH v2 09/14] objtool: Extract elf_strtab_concat()

From: Peter Zijlstra
Date: Fri Mar 19 2021 - 05:52:55 EST


On Thu, Mar 18, 2021 at 09:10:38PM -0500, Josh Poimboeuf wrote:
> On Thu, Mar 18, 2021 at 06:11:12PM +0100, Peter Zijlstra wrote:
> > Create a common helper to append strings to a strtab.
> >
> > Signed-off-by: Peter Zijlstra (Intel) <peterz@xxxxxxxxxxxxx>
> > ---
> > tools/objtool/elf.c | 73 +++++++++++++++++++++++++++++-----------------------
> > 1 file changed, 42 insertions(+), 31 deletions(-)
> >
> > --- a/tools/objtool/elf.c
> > +++ b/tools/objtool/elf.c
> > @@ -676,13 +676,51 @@ struct elf *elf_open_read(const char *na
> > return NULL;
> > }
> >
> > +static int elf_strtab_concat(struct elf *elf, char *name, const char *strtab_name)
> > +{
> > + struct section *strtab = NULL;
> > + Elf_Data *data;
> > + Elf_Scn *s;
> > + int len;
> > +
> > + if (strtab_name)
> > + strtab = find_section_by_name(elf, strtab_name);
> > + if (!strtab)
> > + strtab = find_section_by_name(elf, ".strtab");
> > + if (!strtab) {
> > + WARN("can't find %s or .strtab section", strtab_name);
> > + return -1;
> > + }
>
> This part's a bit mysterious (and it loses the Clang comment). Maybe we
> can leave the section finding logic in elf_create_section()?

Sure, made it compile too ;-)