When working with shared libraries (.so
files) on Linux, you may need to inspect which symbols (functions, variables, or other entities) they export. These libraries are linked at runtime, and unlike static libraries, their internal symbols may be stripped or hidden. This tutorial provides 2 methods how to view symbols in shared library on Linux.
Method 1 - nm command
The nm
tool (part of the Binutils package) can list symbols from both static and shared libraries. For shared libraries, we should include the -D
option, which tells nm
to display dynamic (exported) symbols.
For example, to examine the /usr/lib/x86_64-linux-gnu/libz.so
shared library, run the following command:
nm -D /usr/lib/x86_64-linux-gnu/libz.so
Example output (truncated):
00000000000073e0 T adler32
00000000000073f0 T adler32_combine@@ZLIB_1.2.2
00000000000074e0 T adler32_combine64@@ZLIB_1.2.3.3
0000000000006d10 T adler32_z@@ZLIB_1.2.9
U close@GLIBC_2.2.5
0000000000010110 T compress
000000000000ffd0 T compress2
0000000000010120 T compressBound@@ZLIB_1.2.0
00000000000075f0 T crc32
0000000000008c60 T crc32_combine@@ZLIB_1.2.2
0000000000008c70 T crc32_combine64@@ZLIB_1.2.3.3
00000000000075e0 i crc32_z@@ZLIB_1.2.9
...
If the library includes C++ code, symbol names will appear mangled. To demangle and make them human-readable, use the -C
option:
nm -DC /usr/lib/gcc/x86_64-linux-gnu/11/libstdc++.so
Method 2 - objdump command
Another powerful way to explore symbol tables is with objdump
command (included in Binutils package). While nm
only lists symbols, objdump
with -T
option gives additional details, such as versioning and which symbols are imported versus exported.
objdump -T /usr/lib/x86_64-linux-gnu/libz.so
Example output (truncated):
0000000000000000 DF *UND* 0000000000000000 (GLIBC_2.3.4) __snprintf_chk
0000000000000000 DF *UND* 0000000000000000 (GLIBC_2.2.5) free
0000000000000000 DF *UND* 0000000000000000 (GLIBC_2.2.5) __errno_location
0000000000000000 w D *UND* 0000000000000000 Base _ITM_deregisterTMCloneTable
0000000000000000 DF *UND* 0000000000000000 (GLIBC_2.2.5) write
0000000000000000 DF *UND* 0000000000000000 (GLIBC_2.2.5) strlen
0000000000000000 DF *UND* 0000000000000000 (GLIBC_2.4) __stack_chk_fail
0000000000000000 DF *UND* 0000000000000000 (GLIBC_2.2.5) snprintf
0000000000000000 DF *UND* 0000000000000000 (GLIBC_2.2.5) memset
0000000000000000 DF *UND* 0000000000000000 (GLIBC_2.2.5) close
0000000000000000 DF *UND* 0000000000000000 (GLIBC_2.2.5) memchr
0000000000000000 DF *UND* 0000000000000000 (GLIBC_2.2.5) read
...
Just like nm
, objdump
also supports C++ demangling via the -C
option:
objdump -TC /usr/lib/gcc/x86_64-linux-gnu/11/libstdc++.so
Leave a Comment
Cancel reply