如何知道共享库二进制文件是否使用-fPIC选项构建

Aym*_*men 6 linux shared-libraries fpic

我正在研究嵌入式Linux环境.我有一组二进制格式的共享库(我没有源代码和Makefile),我想检查它们是否已经使用-fPIC选项进行编译.是否有任何工具或方法来测试共享库二进制文件是否已编译-fPIC?

问候.

yug*_*ugr 0

如果没有-fPIC. 它会报告类似的内容

/usr/bin/ld: /tmp/ccbCwoJo.o: relocation R_X86_64_PC32 against symbol `_Z1ff' can not be used when making a shared object; recompile with -fPIC
Run Code Online (Sandbox Code Playgroud)

但如果您确实想检查某些内容,请 grep 查找 PLT 调用:

$ objdump -d a.out | g @plt
 628:   e8 23 00 00 00          callq  650 <__gmon_start__@plt>
0000000000000650 <__gmon_start__@plt>:
0000000000000660 <__cxa_finalize@plt>:
0000000000000670 <_Z1ff@plt>:
0000000000000680 <cosf@plt>:
0000000000000690 <sinf@plt>:
 72e:   e8 2d ff ff ff          callq  660 <__cxa_finalize@plt>
 7df:   e8 8c fe ff ff          callq  670 <_Z1ff@plt>
 819:   e8 62 fe ff ff          callq  680 <cosf@plt>
 82e:   e8 5d fe ff ff          callq  690 <sinf@plt>
Run Code Online (Sandbox Code Playgroud)