如何检索用于编译给定ELF可执行文件的GCC版本? [英] How to retrieve the GCC version used to compile a given ELF executable?

查看:228
本文介绍了如何检索用于编译给定ELF可执行文件的GCC版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检索用于编译给定可执行文件的GCC版本。我试过 readelf 但没有得到这些信息。任何想法?

解决方案

它通常存储在评论部分

  strings -a< binary / library> | grepGCC:(

返回
GCC:(GNU)XXX

  strip -R .comment< binary> 
strings -a< binary / library> | grepGCC:

不返回输出

不是不常见的是通过

  strip --strip-all  - 去掉.comment(以及.note) R .note -R .comment< binary> 
strip --strip-unneeded -R .note -R .comment< library>

注意:busybox字符串默认指定了-a选项,这对于.comment部分是必需的。

编辑:Contrary对于Berendra Tusla的回答,它不需要使用任何调试标志来编译这个方法。



二进制例子:

 #echoint main(void){}> ac 
#gcc -oa ac -s
#strings -aa | grep GCC
GCC:(GNU)4.3.4
#strip - .comment a
#strings -aa | grep GCC

对象示例:

 #gcc -c ac -s 
#strings -a ao | grep GCC
GCC:(GNU)4.3.4
#strip - R .comment ao
#strings -aa | grep GCC

注意缺少任何-g(调试)标志和存在用于去除不需要的符号的-s标志。除非.comment部分被移除,否则GCC信息仍可用。如果您需要保持此信息不变,则可能需要检查makefile(或适用的构建脚本)以验证-fno-ident不在$ CFLAGS中,而$ STRIP命令缺少-R .comment。 -fno-ident防止gcc在注释部分生成这些符号以开始。


I'd like to retrieve the GCC version used to compile a given executable. I tried readelf but didn't get the information. Any thoughts?

解决方案

It is normally stored in the comment section

strings -a <binary/library> |grep "GCC: ("

returns GCC: (GNU) X.X.X

strip -R .comment <binary>
strings -a <binary/library> |grep "GCC: ("

returns no output

It is not uncommon to strip the .comment (as well as .note) section out to reduce size via

strip --strip-all -R .note -R .comment <binary>
strip --strip-unneeded -R .note -R .comment <library>

Note: busybox strings specifies the -a option by default, which is needed for the .comment section

Edit: Contrary to Berendra Tusla's answer, it does not need to be compiled with any debugging flags for this method to work.

Binary example:

# 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
#

Object example:

# 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
#

Note the absence of any -g (debugging) flags and the presence of the -s flag which strips unneeded symbols. The GCC info is still available unless the .comment section is removed. If you need to keep this info intact, you may need to check your makefile (or applicable build script) to verify that -fno-ident is not in your $CFLAGS and the $STRIP command lacks -R .comment. -fno-ident prevents gcc from generating these symbols in the comment section to begin with.

这篇关于如何检索用于编译给定ELF可执行文件的GCC版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆