17

I've built a simple program like this:

g++ application.cpp -o application.exe

and then executed the command;

ldd application.exe
...
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 
...

I want to list all the symbols of the libc library:

nm /lib/x86_64-linux-gnu/libc.so.6
nm: /lib/x86_64-linux-gnu/libc.so.6: no symbols

nm --defined-only /lib/x86_64-linux-gnu/libc.so.6
nm: /lib/x86_64-linux-gnu/libc.so.6: no symbols

Why nm reports no symbols? If libc.so.6 is not a library, but a some kind of a link to the actual library, then how can I find the actual library?

Alexey
  • 710
  • 3
  • 7
  • 19
  • Is `/lib/x86_64-linux-gnu/libc.so.6` stripped? What is the output of `file /lib/x86_64-linux-gnu/libc.so.6`? – ks1322 Jan 05 '19 at 13:45
  • You can try `readelf -s libc.so.6`, also see [Why nm shows no symbols for /lib/i386-linux-gnu/libc.so.6?](https://unix.stackexchange.com/questions/282616/why-nm-shows-no-symbols-for-lib-i386-linux-gnu-libc-so-6) . – Rick Jun 03 '22 at 17:28

1 Answers1

31

By default, nm reads the .symtab section in ELF objects, which is optional in non-relocatable objects. With the -D/--dynamic option, you can instruct nm to read the dynamic symbol table (which are the symbols actually used at run time). You may also want to use --with-symbol-versions because glibc uses symbol versioning extensively.

Alternatively, you can use eu-readelf --symbols=.dynsym or objdump -Tw. (readelf -sDW does not include symbol versioning information.)

Florian Weimer
  • 32,022
  • 3
  • 48
  • 92
  • 1
    Thanks! Why --dynamic isn't a default option then?? – Alexey Jan 05 '19 at 13:58
  • The `nm` command is very old and dynamic linking did not exist back then (and some binutils targets still do not support it). Changing the data source based on object type would likely be too confusing. – Florian Weimer Jan 05 '19 at 13:59
  • OK, maybe there exist more modern and convenient tools for analysing library symbols then? – Alexey Jan 05 '19 at 14:04
  • 1
    @FlorianWeimer: Curiously, the commentary I remember from 1998 already regarded it as a bug that `nm` doesn't list exported symbols from stripped `.so` files by default. – Joshua Mar 28 '22 at 01:45