[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <YFRZOZtZrRdsLSwP@hirez.programming.kicks-ass.net>
Date: Fri, 19 Mar 2021 08:56:41 +0100
From: Peter Zijlstra <peterz@...radead.org>
To: Josh Poimboeuf <jpoimboe@...hat.com>
Cc: x86@...nel.org, jgross@...e.com, mbenes@...e.com,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH v2 11/14] objtool: Add elf_create_undef_symbol()
On Thu, Mar 18, 2021 at 09:29:23PM -0500, Josh Poimboeuf wrote:
> On Thu, Mar 18, 2021 at 06:11:14PM +0100, Peter Zijlstra wrote:
> > Allow objtool to create undefined symbols; this allows creating
> > relocations to symbols not currently in the symbol table.
> >
> > Signed-off-by: Peter Zijlstra (Intel) <peterz@...radead.org>
> > ---
> > tools/objtool/elf.c | 63 ++++++++++++++++++++++++++++++++++++
> > tools/objtool/include/objtool/elf.h | 1
> > 2 files changed, 64 insertions(+)
> >
> > --- a/tools/objtool/elf.c
> > +++ b/tools/objtool/elf.c
> > @@ -724,6 +724,69 @@ static int elf_strtab_concat(struct elf
> > return len;
> > }
> >
> > +struct symbol *elf_create_undef_symbol(struct elf *elf, const char *name)
> > +{
> > + struct section *symtab;
> > + struct symbol *sym;
> > + Elf_Data *data;
> > + Elf_Scn *s;
> > +
> > + sym = malloc(sizeof(*sym));
> > + if (!sym) {
> > + perror("malloc");
> > + return NULL;
> > + }
> > + memset(sym, 0, sizeof(*sym));
> > +
> > + sym->name = strdup(name);
> > +
> > + sym->sym.st_name = elf_strtab_concat(elf, sym->name, NULL);
> > + if (sym->sym.st_name == -1)
> > + return NULL;
> > +
> > + sym->sym.st_info = 0x10; /* STB_GLOBAL, STT_NOTYPE */
>
> There's a generic macro for this:
>
> sym->sym.st_info = GELF_ST_INFO(STB_GLOBAL, STT_NOTYPE);
Ah, I remember not finding that many moons ago when I wrote that ..
> And sym->bind and sym->type should probably get set.
They are, it's in that elf_add_symbol() thing.
Powered by blists - more mailing lists