Why nm libc.so reports no symbols?
Asked Answered
S

1

21

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 some kind of a link to the actual library, then how can I find the actual library?

Samara answered 5/1, 2019 at 13:34 Comment(2)
Is /lib/x86_64-linux-gnu/libc.so.6 stripped? What is the output of file /lib/x86_64-linux-gnu/libc.so.6?Just
You can try readelf -s libc.so.6, also see Why nm shows no symbols for /lib/i386-linux-gnu/libc.so.6? .Musing
T
40

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.)

Toddtoddie answered 5/1, 2019 at 13:40 Comment(5)
Thanks! Why --dynamic isn't a default option then??Samara
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.Toddtoddie
OK, maybe there exist more modern and convenient tools for analysing library symbols then?Samara
@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.Nudity
--with-symbol-versions appears to be the default with nm, so only the -D/--dynamic is required for to read the dynamic symbol table.Sacculate

© 2022 - 2024 — McMap. All rights reserved.