[英]How to find which shared library exported which imported symbol in my binary?
I am trying to find the shared library which imported an external symbol.我正在尝试查找导入外部符号的共享库。 Currently I can get all imported symbols by using nm or many alternatives such as using radare2.目前,我可以使用 nm 或许多替代方法(例如使用radare2)来获取所有导入的符号。 I can also get the libraries which the binary is dependent on by using ldd.我还可以通过使用 ldd 来获取二进制文件所依赖的库。 However, I got stuck at this point since I cannot find an efficient way to get which external symbol in my binary is dependent on which shared library.但是,我被困在这一点上,因为我找不到一种有效的方法来获取二进制文件中的哪个外部符号取决于哪个共享库。 So, for example how can I find the shared library which exports the function named foo or printf or anything in an efficient way?那么,例如,我怎样才能找到导出名为 foo 或 printf 的 function 或任何有效方式的共享库? I provide an example:我举个例子:
Output of nm -D myfile
w __cxa_finalize
U foo
w __gmon_start__
w _ITM_deregisterTMCloneTable
w _ITM_registerTMCloneTable
U __libc_start_main
U printf
U puts
Output of ldd
linux-vdso.so.1 (0x00007ffd30904000)
libfoo.so => /home/user/Desktop/dynamic_link_example/libfoo.so (0x00007f1b08aaf000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f1b088a1000)
/lib64/ld-linux-x86-64.so.2 (0x00007f1b08abb000)
So, for example how can I find the shared library which exports the function named foo or printf or anything in an efficient way?那么,例如,我怎样才能找到导出名为 foo 或 printf 的 function 或任何有效方式的共享库?
You can run your program with env LD_DEBUG=bindings./a.out
.您可以使用env LD_DEBUG=bindings./a.out
运行您的程序。 This will produce a lot of output, which you can grep
for foo
and printf
.这将产生很多 output,您可以为foo
和grep
和printf
。
Note that the answer to "which external symbol in my binary is dependent on which shared library" is "whichever library defines this symbol first".请注意,“我的二进制文件中的哪个外部符号取决于哪个共享库”的答案是“哪个库首先定义了这个符号”。
So if today your binary depends on lifoo.so
for foo
and on libc.so.6
for printf
, nothing stops you from running with a different libfoo.so
tomorrow, and that different version of libfoo.so
may define different symbols.因此,如果今天您的二进制文件依赖于lifoo.so
用于foo
并且依赖于libc.so.6
用于printf
,那么明天没有什么能阻止您使用不同的libfoo.so
运行,并且不同版本的libfoo.so
可能会定义不同的符号。 If the new version of libfoo.so
defines printf
, that would cause the answer to your question for symbol printf
to change from libc.so.6
to libfoo.so
.如果新版本的libfoo.so
定义了printf
,这将导致您对符号printf
问题的答案从libc.so.6
更改为libfoo.so
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.