Linux see symbols in so

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.

The platform makes a difference. Apple provides a GCC 4.0, but its nm does not respond to some options, like -D and -g (IIRC).

11 Answers 11

The standard tool for listing symbols is nm , you can use it simply like this:

If you want to see symbols of a C++ library, add the «-C» option which demangle the symbols (it’s far more readable demangled).

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 
$ 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 

Источник

Читайте также:  Xerox phaser 3117 драйвер astra linux

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:

If you want to see symbols of a C++ library, add the «-C» option which demangle the symbols (it’s far more readable demangled).

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 
$ 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 [email protected]_2.2.5 (14) 3: 0000000000000000 0 FUNC GLOBAL DEFAULT UND [email protected]_2.2.5 (14) 4: 0000000000000000 0 NOTYPE WEAK DEFAULT UND _ITM_deregisterTMCloneTable 

Solution 2:

If your .so file is in elf format, you can use readelf program to extract symbol information from the binary. This command will give you the symbol table:

readelf -Ws /usr/lib/libexample.so 

You only should extract those that are defined in this .so file, not in the libraries referenced by it. Seventh column should contain a number in this case. You can extract it by using a simple regex:

readelf -Ws /usr/lib/libstdc++.so.6 | grep '^\([[:space:]]\+[^[:space:]]\+\)\[[:space:]]\+[[:digit:]]\+' 
readelf -Ws /usr/lib/libstdc++.so.6 | awk ''; 

Solution 3:

objdump -TC /usr/lib/libexample.so 

Solution 4:

For shared libraries libNAME.so the -D switch was necessary to see symbols in my Linux

Читайте также:  Creating bash file linux

and for static library as reported by others

Solution 5:

I kept wondering why -fvisibility=hidden and #pragma GCC visibility did not seem to have any influence, as all the symbols were always visible with nm — until I found this post that pointed me to readelf and objdump, which made me realize that there seem to actually be two symbol tables:

I think the former contains debugging symbols that can be stripped with strip or the -s switch that you can give to the linker or the install command. And even if nm does not list anything anymore, your exported symbols are still exported because they are in the ELF «dynamic symbol table», which is the latter.

Источник

List symbols in a .so file

Learn Algorithms and become a National Programmer

In this article, we have presented different commands which can be used to list all or specific symbols in a given shared object .so file. This involve different commands with nm, objdump and readelf.

Table of contents:

The different commands to list different symbols in a given shared object (.so) file are as follows:

4 commands with nm

nm is a tool that comes with binutils. To install binutils, use the following steps.

nm --demangle --dynamic --defined-only
nm --demangle --dynamic --extern-only
nm --demangle --dynamic --defined-only --extern-only
nm --demangle --dynamic --defined-only --extern-only | grep

objdump command

To get the list of symbols in a given .so file using objdump command, use the following:

readelf command

If the shared object .so file is in ELF format, one can use readelf command as follows to list the symbols:

This will list all symbols including the ones in shared objects referenced by the current .so file. To get the symbols in the current .so file, we need to check the information in the 7th column which can be extracted using awk command as follows:

Читайте также:  Linux source build directory

With these commands presented in this article at OpenGenus, you must have a complete idea of how to list the different symbols in a given .so file. You can use this information for debugging «symbol not found» error.

Geoffrey Ziskovin

Geoffrey Ziskovin

Geoffrey Ziskovin is an American Software Developer and Author with an experience of over 30 years. He started his career with Haskell and has interviewed over 700 candidates for Fortune 500 companies

OpenGenus Tech Review Team

Linux

[FIXED] /usr/lib/libstdc++.so.6: version ‘GLIBCXX_3.4.16’ not found

In this article, we have explored the cause of the error «/usr/lib/libstdc++.so.6: version ‘GLIBCXX_3.4.16’ not found» and presented 3 fixes to resolve this runtime error.

Geoffrey Ziskovin

Geoffrey Ziskovin

Power Set of String in Lexicographic order

In this article, we have explored what is the meaning of Power Set of String and the algorithm to generate Power Set of String in Lexicographic order.

Источник

Оцените статью
Adblock
detector