Skip to content

Commit 5141d3a

Browse files
samitolvanenkees
authored andcommitted
objtool: Preserve special st_shndx indexes in elf_update_symbol
elf_update_symbol fails to preserve the special st_shndx values between [SHN_LORESERVE, SHN_HIRESERVE], which results in it converting SHN_ABS entries into SHN_UNDEF, for example. Explicitly check for the special indexes and ensure these symbols are not marked undefined. Fixes: ead165f ("objtool: Fix symbol creation") Signed-off-by: Sami Tolvanen <[email protected]> Acked-by: Peter Zijlstra (Intel) <[email protected]> Tested-by: Peter Zijlstra (Intel) <[email protected]> Signed-off-by: Kees Cook <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 5659b59 commit 5141d3a

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

tools/objtool/elf.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,11 @@ static int elf_update_symbol(struct elf *elf, struct section *symtab,
619619
Elf64_Xword entsize = symtab->sh.sh_entsize;
620620
int max_idx, idx = sym->idx;
621621
Elf_Scn *s, *t = NULL;
622+
bool is_special_shndx = sym->sym.st_shndx >= SHN_LORESERVE &&
623+
sym->sym.st_shndx != SHN_XINDEX;
624+
625+
if (is_special_shndx)
626+
shndx = sym->sym.st_shndx;
622627

623628
s = elf_getscn(elf->elf, symtab->idx);
624629
if (!s) {
@@ -704,7 +709,7 @@ static int elf_update_symbol(struct elf *elf, struct section *symtab,
704709
}
705710

706711
/* setup extended section index magic and write the symbol */
707-
if (shndx >= SHN_UNDEF && shndx < SHN_LORESERVE) {
712+
if ((shndx >= SHN_UNDEF && shndx < SHN_LORESERVE) || is_special_shndx) {
708713
sym->sym.st_shndx = shndx;
709714
if (!shndx_data)
710715
shndx = 0;

0 commit comments

Comments
 (0)