Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I list the symbols in a .so file

How do I list the symbols being exported from a .so file? If possible, I'd also like to know their source (e.g. if they are pulled in from a static library).

I'm using gcc 4.0.2, if that makes a difference.

like image 602
Moe Avatar asked Aug 29 '08 16:08

Moe


People also ask

How do I get symbols in .so files?

Try adding -l to the nm flags in order to get the source of each symbol. If the library is compiled with debugging info (gcc -g) this should be the source file and line number.

What are library symbols?

A symbol library is a collection of symbols. Typically the symbols in a symbol library belong to a specific group or correspond to a specific standard. Symbol libraries can be stored in a project or in a master data pool.

Is .so a binary?

so are dynamic libraries. If you use code stored inside them, it's not taken and embedded into your own binary. Instead it's just referenced, so the binary will depend on them and the code from the so file is added/loaded at runtime. In Visual Studio/Windows these would be .


1 Answers

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 
like image 77
Steve Gury Avatar answered Sep 24 '22 00:09

Steve Gury