objtool: support symtab_shndx during dump
PATCH 1/1 objtool: support symtab_shndx during dump
When getting the symbol index number, make sure to use the extended symbol table information in order to support symbol index's greater than 64K.
--- tools/objtool/orc_dump.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-)
tools/objtool/orc_dump.c +16 -4
@@ -74,7 +74,8 @@ int orc_dump(const char *_objname)GElf_Rela rela;GElf_Sym sym;Elf_Data *data, *symtab =NULL , *rela_orc_ip =NULL ; - +Elf_Data *xsymtab =NULL ; +Elf32_Word shndx; objname = _objname;
@@ -138,6 +139,8 @@ int orc_dump(const char *_objname) orc_ip_addr = sh.sh_addr; }else if (!strcmp (name,".rela.orc_unwind_ip" )) { rela_orc_ip = data; + }else if (!strcmp (name,".symtab_shndx" )) { + xsymtab = data; } }
@@ -157,13 +160,22 @@ int orc_dump(const char *_objname)return -1 ; } -if (!gelf_getsym (symtab,GELF_R_SYM (rela.r_info), &sym)) { -WARN_ELF ("gelf_getsym" ); +if (!gelf_getsymshndx (symtab, xsymtab, +GELF_R_SYM (rela.r_info), + &sym, &shndx)) { +WARN_ELF ("gelf_getsymshndx" );return -1 ; }if (GELF_ST_TYPE (sym.st_info) ==STT_SECTION ) { - scn =elf_getscn (elf, sym.st_shndx); +if ((sym.st_shndx >SHN_UNDEF && + sym.st_shndx <SHN_LORESERVE ) || + (xsymtab && sym.st_shndx ==SHN_XINDEX )) { +if (sym.st_shndx !=SHN_XINDEX ) + shndx = sym.st_shndx; + } + + scn =elf_getscn (elf, shndx);if (!scn) {WARN_ELF ("elf_getscn" );return -1 ;
Signature · 1 line
2.20.1
Quoted 5 lines · Kristen Carlson Accardi
When getting the symbol index number, make sure to use the extended symbol table information in order to support symbol index's greater than 64K.
Signed-off-by Kristen Carlson Accardi <[email protected]>
M
Quoted 3 lines · Kristen Carlson Accardi
When getting the symbol index number, make sure to use the extended symbol table information in order to support symbol index's greater than 64K.
"indexes"
tools/objtool/orc_dump.c int orc_dump(const char *_objname) · line 175
Quoted 7 lines
tools/objtool/orc_dump.c +5
-1if (GELF_ST_TYPE (sym.st_info) ==STT_SECTION ) { - scn =elf_getscn (elf, sym.st_shndx); +if ((sym.st_shndx >SHN_UNDEF && + sym.st_shndx <SHN_LORESERVE ) || + (xsymtab && sym.st_shndx ==SHN_XINDEX )) { +if (sym.st_shndx !=SHN_XINDEX ) + shndx = sym.st_shndx;
The sym.st_shndx checks are redundant, if 'sym.st_shndx == SHN_XINDEX' then 'sym.st_shndx != SHN_XINDEX' can't be true.
Actually I think this can be even further simplified to something like
if (!shndx) shndx = sym.st_shndx;
Signature · 1 line
Josh
Quoted 12 lines · Josh Poimboeuf
tools/objtool/orc_dump.c int orc_dump(const char *_objname) · line 175
Quoted 7 lines · Kristen Carlson Accardi
tools/objtool/orc_dump.c +5
-1if (GELF_ST_TYPE (sym.st_info) ==STT_SECTION ) { - scn =elf_getscn (elf, sym.st_shndx); +if ((sym.st_shndx >SHN_UNDEF && + sym.st_shndx <SHN_LORESERVE ) || + (xsymtab && sym.st_shndx ==SHN_XINDEX )) { +if (sym.st_shndx !=SHN_XINDEX ) + shndx = sym.st_shndx;The sym.st_shndx checks are redundant, if 'sym.st_shndx ==
SHN_XINDEX' then 'sym.st_shndx !=SHN_XINDEX' can't be true.
It is probably a copy-paste from read_symbols() in elf.c, where the logic is different.
Quoted 4 lines
Actually I think this can be even further simplified to something like
if (!shndx) shndx = sym.st_shndx;
This relies on the fact that gelf_getsymshndx() always initializes shndx, no? I think it would be better to initialize it in orc_dump() too. Safer and easier to read. It applies to Kristen's patch as well. I missed that.
Miroslav
Quoted 15 lines · Miroslav Benes
Quoted 12 lines · Josh Poimboeuf
tools/objtool/orc_dump.c int orc_dump(const char *_objname) · line 175
Quoted 7 lines · Kristen Carlson Accardi
tools/objtool/orc_dump.c +5
-1if (GELF_ST_TYPE (sym.st_info) ==STT_SECTION ) { - scn =elf_getscn (elf, sym.st_shndx); +if ((sym.st_shndx >SHN_UNDEF && + sym.st_shndx <SHN_LORESERVE ) || + (xsymtab && sym.st_shndx ==SHN_XINDEX )) { +if (sym.st_shndx !=SHN_XINDEX ) + shndx = sym.st_shndx;The sym.st_shndx checks are redundant, if 'sym.st_shndx ==
SHN_XINDEX' then 'sym.st_shndx !=SHN_XINDEX' can't be true.
Quoted 2 lines
It is probably a copy-paste from
read_symbols()inelf.c, where the logic is different.
Yeah.
Quoted 8 lines
Quoted 4 lines
Actually I think this can be even further simplified to something like
if (!shndx) shndx = sym.st_shndx;This relies on the fact that
gelf_getsymshndx()always initializes shndx, no? I think it would be better to initialize it inorc_dump()too. Safer and easier to read. It applies to Kristen's patch as well. I missed that.
Agreed.
Signature · 1 line
Josh