简体   繁体   English

如何在我的二进制文件中找到哪个共享库导出了哪个导入的符号?

[英]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,您可以为foogrepprintf

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.

相关问题 如何找到哪个共享库启动了一个线程 - How to find which shared library started a thread 将导出的符号保留在共享库中 - Keep exported symbol in shared library 如何确定符号在(linux)中定义的库 - How to determine which library a symbol is defined in (linux) gdb:如何了解哪个共享库加载了有问题的共享库 - gdb: how to learn which shared library loaded a shared library in question 将二进制文件与导出的文本文件进行比较,找出哪些二进制文件已更改或自上次导出以来是下一个 - Compare binary to exported textfiles and find which binary files have changed or are next since last export 找不到在另一个动态库中定义的符号 - Cannot find symbol which is defined in another dynamic library 如何找出程序或其他库使用共享对象的哪些功能? - How do I find out which functions of a shared object are used by a program or an other library? 如何知道我的程序在运行时实际使用哪个共享库? - How to know which shared library my program is actually using at run time? 如何检查共享库中的哪些符号具有非位置无关代码(PIC)? - How to check which symbols on my shared library have non-position independent code (PIC)? Linux:如何找出我的库的哪个(子)依赖项需要特定的库? - Linux: How to find out which (sub) dependency of my library needs a specific library?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM