从一个编译的可执行文件的编译选项? [英] Get the compiler options from a compiled executable?

查看:432
本文介绍了从一个编译的可执行文件的编译选项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这有什么办法可以看到使用了什么样的编译和标记来创建* nix的可执行文件?我有一个旧版本,我的code编译,我想看看它是否有或没有优化的编译。谷歌并没有太大的帮助,但我不知道我使用的是正确的关键字。

It there a way to see what compiler and flags were used to create an executable file in *nix? I have an old version of my code compiled and I would like to see whether it was compiled with or without optimization. Google was not too helpful, but I'm not sure I am using the correct keywords.

推荐答案

GCC有一个 -frecord-GCC开关该选项:

gcc has a -frecord-gcc-switches option for that:

   -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.out 

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

当然,它不会为没有该选项编译的可执行文件运行。

Of course, it won't work for executables compiled without that option.

有关优化的简单情况,你的可能的尝试使用调试器,如果该文件与调试信息编译。如果你踩通过它一点点,你可能会注意到某些变量优化掉了。这表明,优化发生了。

For the simple case of optimizations, you could try using a debugger if the file was compiled with debug info. If you step through it a little, you may notice that some variables were 'optimized out'. That suggests that optimization took place.

这篇关于从一个编译的可执行文件的编译选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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