在我的 Linux 机器上进行一些测试时,我需要找出哪些函数属于某个库。
我使用了 bash 命令“ldconfig -p”,它列出了一些库。
但是如何列出功能?
答案1
使用objdump -tT ${FILE}
或readelf -s ${FILE}
。
$ objdump -T /lib/x86_64-linux-gnu/libz.so.1
/lib/x86_64-linux-gnu/libz.so.1: file format elf64-x86-64
DYNAMIC SYMBOL TABLE:
0000000000001c58 l d .init 0000000000000000 .init
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 _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
[...]
00000000000024c0 g DF .text 00000000000000f9 ZLIB_1.2.2 adler32_combine
0000000000002ba0 g DF .text 0000000000000005 ZLIB_1.2.3.3 crc32_combine64
0000000000010170 g DF .text 0000000000000074 Base gzdopen
0000000000000000 g DO *ABS* 0000000000000000 ZLIB_1.2.7.1 ZLIB_1.2.7.1
0000000000000000 g DO *ABS* 0000000000000000 ZLIB_1.2.3.3 ZLIB_1.2.3.3
000000000000c780 g DF .text 0000000000000036 Base inflateSyncPoint
00000000000104f0 g DF .text 0000000000000059 ZLIB_1.2.3.5 gzoffset64
0000000000011160 g DF .text 0000000000000005 ZLIB_1.2.5.2 gzgetc_
0000000000000000 g DO *ABS* 0000000000000000 ZLIB_1.2.3.4 ZLIB_1.2.3.4
0000000000000000 g DO *ABS* 0000000000000000 ZLIB_1.2.3.5 ZLIB_1.2.3.5
00000000000043a0 g DF .text 00000000000000cd ZLIB_1.2.5.2 deflateResetKeep
0000000000010550 g DF .text 0000000000000005 ZLIB_1.2.3.5 gzoffset
000000000000fdd0 g DF .text 0000000000000023 Base gzclose
[...]
在objdump
的输出中:
- 任何标记的符号
*UND*
都驻留在另一个库中(动态链接)- 例如
free
,,write
等等……
- 例如
- 任何带有部分的符号(例如:
.init
或.text
)都驻留在此库中- 例如
gzdopen
,,gzclose
等等……
- 例如
您可以使用ldd
它来找出二进制文件(可执行文件或库)链接了哪些库:
$ ldd /lib/x86_64-linux-gnu/libz.so.1
linux-vdso.so.1 => (0x00007ffc478f7000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f92da469000)
/lib64/ld-linux-x86-64.so.2 (0x00007f92daa4d000)