简体   繁体   English

看不见的GCC优化标志?

[英]Invisible GCC optimization flags?

I'm building some large project using GCC 4.4.2 . 我正在使用GCC 4.4.2构建一些大型项目。 Since I want to build it for release, I use -O1 GCC optimization flag, but unluckily it messes somehow with my code, and the final binaries do not work as expected, when building with -O0 flag (or no optimization) everything works fine. 由于我要构建它以进行发布,因此我使用-O1 GCC优化标志,但不幸的是,它与我的代码有些混乱,并且最终的二进制文件无法按预期工作,当使用-O0标志(或不进行优化)构建时,一切正常。 I had a similar problem with my project before, in that time it was the -fstrict-aliasing flag that caused troubles on -O2 optimization level, I managed to find that it was caused by that specific flag by making a search on all flags that are mentioned in this documentation, regarding the -O2 optimization level: 之前我的项目有一个类似的问题,那时候是-fstrict-aliasing标志在-O2优化级别上引起了麻烦,我通过搜索所有标志来设法找到它是由特定标志引起的关于-O2优化级别,在本文档中进行了介绍:

http://gcc.gnu.org/onlinedocs/gcc-4.4.2/gcc/Optimize-Options.html http://gcc.gnu.org/onlinedocs/gcc-4.4.2/gcc/Optimize-Options.html

Now I tried to do the same with the list they mention regarding the -O1 flag, but unfortunately it seems that not all the flags mentioned, or there are some hidden flags being enabled, because when I compile with just -O1 flag or with just a list of the provided flags (without putting -O1 itself) I get different compilation results, and my binaries refuse to work only with the specific -O1 flag, so I can't find the exact troublemaking option. 现在,我尝试对他们提到的有关-O1标志的列表进行相同的操作,但是不幸的是,似乎并不是所有提到的标志,还是启用了一些隐藏标志,因为当我仅使用-O1标志或仅使用-O1标志进行编译时提供的标志列表(不带-O1本身),我得到不同的编译结果,并且我的二进制文件仅使用特定的-O1标志拒绝工作,因此我找不到确切的麻烦选择。

Is it possible to know what hidden options the -O1 option includes, and how can I disable some of them? 是否有可能知道-O1选项包括哪些隐藏选项,以及如何禁用其中一些?

You can run gcc -Q -v on a small C file to have GCC dump the options being used. 您可以在一个小的C文件上运行gcc -Q -v ,以使GCC转储正在使用的选项。 Run it with and without the -O1 option to get the difference between the enabled options. 在有-O1选项和没有-O1选项的情况下运行它,以获取已启用选项之间的差异。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM