2

On Fedora 31, I see that gdb knows the symbols of some system binaries, e.g. main of /usr/bin/true:

$ gdb -ex 'set height 0' -ex 'disas main' -ex q /bin/true
Reading symbols from /bin/true...
Reading symbols from .gnu_debugdata for /usr/bin/true...
(No debugging symbols found in .gnu_debugdata for /usr/bin/true)
Dump of assembler code for function main:
   0x0000000000002550 <+0>: endbr64 
   0x0000000000002554 <+4>: cmp    edi,0x2
[..]

But main doesn't show up in objdump -d nor `nm output:

$ objdump -d /usr/bin/true | grep '\<main\>'
$ nm /usr/bin/true | grep main
nm: /usr/bin/true: no symbols
$ nm -D /usr/bin/true | grep '\<main\>'
$

How come? Is gdb able to read the main symbol from some additional symbol table?

When I compile my own binaries with gcc, nm/objdump show the main symbol as expected. Also, when I strip such a binary, gdb can't find the main symbol, as well.

I assume that rpmbuild calls gcc/strip with some special flags that cause the above behavior. What are those?

maxschlepzig
  • 35,645
  • 14
  • 145
  • 182
  • External/split debug information? https://sourceware.org/gdb/onlinedocs/gdb/Separate-Debug-Files.html – Hasturkun Jan 19 '20 at 16:36
  • @Hasturkun, this is what I first thought, too - but gdb also prints: `No debugging symbols found in .gnu_debugdata for /usr/bin/true` – maxschlepzig Jan 19 '20 at 16:39

1 Answers1

0

Is gdb able to read the main symbol from some additional symbol table?

Yes: the one contained in the .gnu_debugdata section. More info here.

gdb also prints: No debugging symbols found in .gnu_debugdata for /usr/bin/true

GDB says: there are no debugging symbols (i.e. ones with file/line info, variable info, etc.). It doesn't say "there are no symbols" (i.e. things you would see in nm output). In fact, symbols are raison d'etre for .gnu_debugdata in the first place.

maxschlepzig
  • 35,645
  • 14
  • 145
  • 182
Employed Russian
  • 199,314
  • 34
  • 295
  • 362