栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

从编译的可执行文件中获取编译器选项?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

从编译的可执行文件中获取编译器选项?

gcc

-frecord-gcc-switches
为此提供了一个选项:

   -frecord-gcc-switches       This switch causes the command line that was used to invoke the compiler to       be recorded into the object file that is being created.  This switch is only       implemented on some targets and the exact format of the recording is target       and binary file format dependent, but it usually takes the form of a section       containing ASCII text.

之后,ELF可执行文件将包含

.GCC.command.line
带有该信息的部分。

$ gcc -O2 -frecord-gcc-switches a.c$ readelf -p .GCC.command.line a.outString dump of section '.GCC.command.line':  [     0]  a.c  [     4]  -mtune=generic  [    13]  -march=x86-64  [    21]  -O2  [    25]  -frecord-gcc-switches

当然,如果没有该选项编译的可执行文件将无法使用。


对于简单的优化情况,如果文件是使用调试信息编译的,则 可以 尝试使用调试器。如果稍稍进行,可能会注意到一些变量已被“优化”。这表明发生了优化。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/399067.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号