How do I list the symbols in a .so file
The standard tool for listing symbols is nm
, you can use it simply like this:
nm -gD yourLib.so
If you want to see symbols of a C++ library, add the "-C" option which demangle the symbols (it's far more readable demangled).
nm -gDC yourLib.so
If your .so file is in elf format, you have two options:
Either objdump
(-C
is also useful for demangling C++):
$ objdump -TC libz.so
libz.so: file format elf64-x86-64
DYNAMIC SYMBOL TABLE:
0000000000002010 l d .init 0000000000000000 .init
0000000000000000 DF *UND* 0000000000000000 GLIBC_2.2.5 free
0000000000000000 DF *UND* 0000000000000000 GLIBC_2.2.5 __errno_location
0000000000000000 w D *UND* 0000000000000000 _ITM_deregisterTMCloneTable
Or use readelf
:
$ readelf -Ws libz.so
Symbol table '.dynsym' contains 112 entries:
Num: Value Size Type Bind Vis Ndx Name
0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND
1: 0000000000002010 0 SECTION LOCAL DEFAULT 10
2: 0000000000000000 0 FUNC GLOBAL DEFAULT UND free@GLIBC_2.2.5 (14)
3: 0000000000000000 0 FUNC GLOBAL DEFAULT UND __errno_location@GLIBC_2.2.5 (14)
4: 0000000000000000 0 NOTYPE WEAK DEFAULT UND _ITM_deregisterTMCloneTable
nm - show file that declares a symbol in a .so file
If I compile this file into a shared object file, file.so, I should get a "U" for the
get_data
symbol
You are mistaken: since nothing references get_data
, you wouldn't in fact get a U
for it.
To answer your question: the info that file.cpp
referenced get_data
symbol is gone, unless you compiled file.cpp
with debugging info.
If you did, you could use objdump -dS file.so
to find that file.cpp
is where the reference originates.
How do I find out what all symbols are exported from a shared object?
Do you have a "shared object" (usually a shared library on AIX), a UNIX shared library, or a Windows DLL? These are all different things, and your question conflates them all :-(
- For an AIX shared object, use
dump -Tv /path/to/foo.o
. - For an ELF shared library, use
readelf -Ws --dyn-syms /path/to/libfoo.so
, or (if you have GNU nm)nm -D /path/to/libfoo.so
. - For a non-ELF UNIX shared library, please state which UNIX you are interested in.
- For a Windows DLL, use
dumpbin /EXPORTS foo.dll
.
How can I look inside a Linux .so or .a object and see what functions they contain?
you can do nm Linux.so
and it'll show the functions and variables inside the .so file.
Related Topics
How to Make a Fully Statically Linked .Exe With Visual Studio Express 2005
Static Initialization Order Fiasco
What Is the Usefulness of 'Enable_Shared_From_This'
Does C++ Support 'Finally' Blocks? (And What's This 'Raii' I Keep Hearing About)
How to Detect Whether There Is a Specific Member Variable in Class
How Does the Import Library Work - Details
Unmangling the Result of Std::Type_Info::Name
Uninitialized Variable Behaviour in C++
What Happens When I Print an Uninitialized Variable in C++
What Happens to a Detached Thread When Main() Exits
Reading and Writing Binary File
Cmake Error At Cmakelists.Txt:30 (Project): No Cmake_C_Compiler Could Be Found
Are There Any Valid Use Cases to Use New and Delete, Raw Pointers or C-Style Arrays With Modern C++
Copy a File in a Sane, Safe and Efficient Way