简体   繁体   English

如何判断elf文件的链接类型?

[英]How to tell the linking type of an elf file?

I'm doing a script that checking the elf file, and in some point it need to check the linking type for it. 我正在做一个检查elf文件的脚本,在某些时候需要检查它的链接类型。
So, 所以,
Is there any tools in Linux or stable way that I can use to check if an output file is totally static linked or dynamic linked? Linux中是否有任何工具或稳定的方式可用于检查输出文件是完全静态链接还是动态链接?

'ld.so --verify' can check if the file is dynamic linked, but it also check if is it handable by this linker, so I can not use the result as the determing for link type. 'ld.so --verify'可以检查文件是否是动态链接的,但它也检查该链接器是否可以处理,因此我不能将结果用作链接类型的确定。

Other tools like 'nm','file' do check the output file and provide some information about linking type by print message, which make it not very reliable to use..eg if I write script to grep words 'dynamically linked' 'statically linked' of standard output from 'file $filename' as a verify of the link type doesn't feel reliable.. 像'nm','file'这样的其他工具会检查输出文件,并通过打印消息提供有关链接类型的一些信息,这使得它使用起来不太可靠......如果我写脚本来grep单词'动态链接''静态来自'file $ filename'的标准输出的链接'作为链接类型的验证感觉不可靠..

so, Is there any simple way or small tools to check the link type? 那么,有没有简单的方法或小工具来检查链接类型? or why it is not possible? 或者为什么不可能?

您可以在二进制文件上使用ldd ,如果它是动态链接的,它会打印共享库并返回0 ,如果它是静态链接的,则返回1

I don't know of a utility that does specifically what you are looking for - as mentioned, ldd can be (ab-)used to determine it. 我不知道具体做什么的实用程序 - 正如所提到的, ldd可以用(ab-)来确定它。 file might also be of use. file也可能有用。 But the information is in the ELF header and just needs to be parsed correctly, so writing a simple program to do it shouldn't be difficult... 但是信息是在ELF头文件中,只需要正确解析,所以写一个简单的程序来做它应该不难...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM