我想检索用于编译给定可执行文件的 GCC 版本。我试过readelf
但没有得到信息。有什么想法吗?
一般存放在评论区
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字符串默认指定-a选项,这是.comment部分需要的
编辑:与 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 在注释部分生成这些符号。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)