objtool: Fix .symtab_shndx handling for elf_create_undef_symbol()
authorPeter Zijlstra <peterz@infradead.org>
Mon, 7 Jun 2021 09:45:58 +0000 (11:45 +0200)
committerPeter Zijlstra <peterz@infradead.org>
Thu, 10 Jun 2021 08:08:24 +0000 (10:08 +0200)
commit584fd3b31889852d0d6f3dd1e3d8e9619b660d2c
tree6343458bd05d3a2021ca0cdb3f62a13650dc01b2
parent614124bea77e452aa6df7a8714e8bc820b489922
objtool: Fix .symtab_shndx handling for elf_create_undef_symbol()

When an ELF object uses extended symbol section indexes (IOW it has a
.symtab_shndx section), these must be kept in sync with the regular
symbol table (.symtab).

So for every new symbol we emit, make sure to also emit a
.symtab_shndx value to keep the arrays of equal size.

Note: since we're writing an UNDEF symbol, most GElf_Sym fields will
be 0 and we can repurpose one (st_size) to host the 0 for the xshndx
value.

Fixes: 2f2f7e47f052 ("objtool: Add elf_create_undef_symbol()")
Reported-by: Nick Desaulniers <ndesaulniers@google.com>
Suggested-by: Fangrui Song <maskray@google.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Tested-by: Nick Desaulniers <ndesaulniers@google.com>
Link: https://lkml.kernel.org/r/YL3q1qFO9QIRL/BA@hirez.programming.kicks-ass.net
tools/objtool/elf.c