lkml.org 
[lkml]   [2021]   [Mar]   [19]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [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@infradead.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.

\
 
 \ /
  Last update: 2021-03-19 08:58    [W:0.079 / U:0.580 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site