问题描述
如何列出从 .so 文件导出的符号?如果可能,我还想知道它们的来源(例如,它们是否是从静态库中提取的).
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).
我使用的是 gcc 4.0.2,如果这有区别的话.
I'm using gcc 4.0.2, if that makes a difference.
推荐答案
列出符号的标准工具是 nm
,你可以像这样简单地使用它:
The standard tool for listing symbols is nm
, you can use it simply like this:
nm -gD yourLib.so
如果您想查看 C++ 库的符号,请添加-C"选项,该选项可对符号进行解构(解构后可读性更高).
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
如果您的 .so 文件是 elf 格式,您有两个选择:
If your .so file is in elf format, you have two options:
任一objdump
(-C
也可用于对 C++ 进行分解):
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
:
$ 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
这篇关于如何列出 .so 文件中的符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!