我想检索用于编译给定可执行文件的GCC版本。我试过readelf
,但没有得到相关信息。有什么想法吗?
发布于 2012-03-13 03:47:40
它通常存储在注释部分中
strings -a <binary/library> |grep "GCC: ("
返回GCC:(GNU) X.X.X
strip -R .comment <binary>
strings -a <binary/library> |grep "GCC: ("
不返回任何输出
剥离.comment (以及.note)部分以通过以下方式减小大小并不少见
strip --strip-all -R .note -R .comment <binary>
strip --strip-unneeded -R .note -R .comment <library>
注意: busybox字符串在缺省情况下指定.comment部分所需的-a选项
编辑:与Berendra Tusla的答案相反,它不需要使用任何调试标志进行编译,此方法就可以工作。
二进制示例:
# echo "int main(void){}">a.c
# gcc -o a a.c -s
# strings -a a |grep GCC
GCC: (GNU) 4.3.4
# strip -R .comment a
# strings -a a |grep GCC
#
对象示例:
# gcc -c a.c -s
# strings -a a.o |grep GCC
GCC: (GNU) 4.3.4
# strip -R .comment a.o
# strings -a a |grep GCC
#
请注意,没有任何-g (调试)标志,而存在-s标志,该标志可以剥离不需要的符号。除非删除.comment部分,否则仍然可以使用GCC信息。如果您需要保持此信息的完整性,您可能需要检查您的makefile (或适用的构建脚本),以验证-fno-ident不在您的$CFLAGS中,并且$STRIP命令缺少-R .comment。-fno-ident从一开始就阻止gcc在评论部分生成这些符号。
发布于 2013-03-03 23:55:39
我刚刚在这里读到的另外两种方法(可能更简单)是:https://unix.stackexchange.com/questions/719/can-we-get-compiler-information-from-an-elf-binary
$ readelf -p .comment /usr/lib64/flash-plugin/libflashplayer.so
String dump of section '.comment':
[ 1] GCC: (GNU) 4.3.2 20081105 (Red Hat 4.3.2-7)
[ 2e] GCC: (GNU) 4.3.2
...
和
$ objdump -s --section .comment /usr/lib64/flash-plugin/libflashplayer.so
/usr/lib64/flash-plugin/libflashplayer.so: file format elf64-x86-64
Contents of section .comment:
0000 00474343 3a202847 4e552920 342e332e .GCC: (GNU) 4.3.
0010 32203230 30383131 30352028 52656420 2 20081105 (Red
0020 48617420 342e332e 322d3729 00004743 Hat 4.3.2-7)..GC
0030 433a2028 474e5529 20342e33 2e320000 C: (GNU) 4.3.2..
...
发布于 2017-06-01 23:00:03
您可以使用elfinfo实用程序。这也支持检测Go和FPC的编译器版本,除了GCC。
https://stackoverflow.com/questions/2387040
复制相似问题