Reputation: 91
I'm doing a script that checking the elf file, and in some point it need to check the linking type for it.
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?
'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.
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..e.g. 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..
so, Is there any simple way or small tools to check the link type? or why it is not possible?
Upvotes: 4
Views: 4759
Reputation: 62459
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. file
might also be of use. 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...
Upvotes: 2
Reputation: 17322
You can use ldd
on a binary if it's dynamically linked it prints the shared libraries and returns 0
, if it was statically linked it returns 1
Upvotes: 2