[PATCH v4 3/7] bfd: Improve nm and objdump without section header

H.J. Lu hjl.tools@gmail.com
Fri Jul 7 15:26:11 GMT 2023


On Fri, Jun 30, 2023 at 7:12 PM Simon Marchi <simon.marchi@polymtl.ca> wrote:
>
> On 6/6/23 13:58, H.J. Lu wrote:
> > When there is no section header in an executable or shared library, we
> > reconstruct dynamic symbol table from the PT_DYNAMIC segment, which
> > contains DT_HASH/DT_GNU_HASH/DT_MIPS_XHASH, DT_STRTAB, DT_SYMTAB,
> > DT_STRSZ, and DT_SYMENT entries, to improve nm and objdump.  For DT_HASH,
> > the number of dynamic symbol table entries equals the number of chains.
> > For DT_GNU_HASH/DT_MIPS_XHASH, only defined symbols with non-STB_LOCAL
> > indings are in hash table.  Since DT_GNU_HASH/DT_MIPS_XHASH place all
> > symbols with STB_LOCAL binding before symbols with other bindings and
> > all undefined symbols defined ones in dynamic symbol table, the highest
> > symbol index in DT_GNU_HASH/DT_MIPS_XHASH is the highest dynamic symbol
> > table index.  We can also get symbol version from DT_VERSYM, DT_VERDEF
> > and DT_VERNEED entries.
> >
> > dt_symtab, dt_versym, dt_verdef, dt_verneed, dt_symtab_count,
> > dt_verdef_count, dt_verneed_count and dt_strtab are added to
> > elf_obj_tdata to store dynamic symbol table information.
>
> Hi,
>
> This broke a GDB test:
>
>     gdb/ $ make check TESTS="gdb.base/eu-strip-infcall.exp"
>     FAIL: gdb.base/eu-strip-infcall.exp: gdb_breakpoint: set breakpoint at main
>
> Looking at gdb/testsuite/gdb.log, before:
>
>     (gdb) file /home/smarchi/build/binutils-gdb/gdb/testsuite/outputs/gdb.base/eu-strip-infcall/eu-strip-infcall
>
>     Reading symbols from /home/smarchi/build/binutils-gdb/gdb/testsuite/outputs/gdb.base/eu-strip-infcall/eu-strip-infcall...
>
>     Reading symbols from /home/smarchi/build/binutils-gdb/gdb/testsuite/outputs/gdb.base/eu-strip-infcall/eu-strip-infcall.debug...
>
>
> and after:
>
> (gdb) file /home/smarchi/build/binutils-gdb/gdb/testsuite/outputs/gdb.base/eu-strip-infcall/eu-strip-infcall
>
> Reading symbols from /home/smarchi/build/binutils-gdb/gdb/testsuite/outputs/gdb.base/eu-strip-infcall/eu-strip-infcall...
>
> warning: `/home/smarchi/build/binutils-gdb/gdb/testsuite/outputs/gdb.base/eu-strip-infcall/eu-strip-infcall.debug': can't read symbols: file format not recognized.
>
> (No debugging symbols found in /home/smarchi/build/binutils-gdb/gdb/testsuite/outputs/gdb.base/eu-strip-infcall/eu-strip-infcall)
>
>
> Can you please check if it's a problem with your patch, or if it's really a malformed file?
>
> Thanks,
>
> Simon

It works for me:

$ make check TESTS="gdb.base/eu-strip-infcall.exp"
....
=== gdb Summary ===

# of expected passes 1

My change only impacts files without section header. eu-strip-infcall.exp does
"eu-strip -f ${binfile}.debug $binfile", which doesn't remove section header.

-- 
H.J.


More information about the Binutils mailing list