GCC / ELF - 我的符号来自哪里?

时间:2022-06-25 13:19:49

There is an executable that is dynamically linked to number of shared objects. How can I determine, to which of them some symbol (imported into executable) belongs ?

有一个可执行文件动态链接到多个共享对象。如何确定某些符号(导入可执行文件)属于哪一个?

If there are more than one possibility, could I silmulate ld and see from where it is being taken ?

如果有多种可能性,我可以将ld模仿并查看它的拍摄地点吗?

4 个解决方案

#1


5  

Have a look at nm(1), objdump(1) and elfdump(1).

看看nm(1),objdump(1)和elfdump(1)。

#2


5  

As well as the ones Charlie mentioned, "ldd" might do some of what you're looking for.

除了查理提到的那些,“ldd”可能会做你正在寻找的一些东西。

#3


3  

If you can relink the executable, the simplest way to find out where references and definitions come from is using ld -y flag. For example:

如果可以重新链接可执行文件,找到引用和定义来源的最简单方法是使用ld -y标志。例如:

$ cat t.c
int main() { printf("Hello\n"); return 0; } 

$ gcc t.c -Wl,-yprintf 
/lib/libc.so.6: definition of printf

If you can not relink the executable, then run ldd on it, and then run 'nm -D' on all the libraries listed in order, and grep for the symbol you are interested in.

如果您无法重新链接可执行文件,则在其上运行ldd,然后对按顺序列出的所有库运行'nm -D',并为您感兴趣的符号grep。

#4


1  

$LD_DEBUG=bindings my_program

That would print all the symbol bindings on the console.

这将打印控制台上的所有符号绑定。

#1


5  

Have a look at nm(1), objdump(1) and elfdump(1).

看看nm(1),objdump(1)和elfdump(1)。

#2


5  

As well as the ones Charlie mentioned, "ldd" might do some of what you're looking for.

除了查理提到的那些,“ldd”可能会做你正在寻找的一些东西。

#3


3  

If you can relink the executable, the simplest way to find out where references and definitions come from is using ld -y flag. For example:

如果可以重新链接可执行文件,找到引用和定义来源的最简单方法是使用ld -y标志。例如:

$ cat t.c
int main() { printf("Hello\n"); return 0; } 

$ gcc t.c -Wl,-yprintf 
/lib/libc.so.6: definition of printf

If you can not relink the executable, then run ldd on it, and then run 'nm -D' on all the libraries listed in order, and grep for the symbol you are interested in.

如果您无法重新链接可执行文件,则在其上运行ldd,然后对按顺序列出的所有库运行'nm -D',并为您感兴趣的符号grep。

#4


1  

$LD_DEBUG=bindings my_program

That would print all the symbol bindings on the console.

这将打印控制台上的所有符号绑定。