GCC编译器选项:哪些选项是正确的?

时间:2022-07-08 07:00:19

I am trying to figure out which compiler options are enabled for GCC (4.7.3, Macports installation on Mac OS X 10.6.8). I know of the following methods:

我正在尝试找出哪些编译器选项可以用于GCC (4.7.3, Macports在Mac OS X 10.6.8上的安装)。我知道以下方法:

  1. Using the -Q option with a simple input file as suggested by GCC 4.3.3 compiler options enabled:

    使用-Q选项和GCC 4.3.3编译器选项建议的简单输入文件:

    gcc -Q -v -o hello hello.c
    
  2. Using the -Q --help=x combination (for values of x, see GCC documentation) e.g:

    使用-Q -help=x组合(对于x的值,请参阅GCC文档)

    gcc -Q --help=target
    
  3. To see enabled defines:

    看到启用定义:

    echo "" | gcc -E -dM - | sort
    

However, when I run method 1 and 2 with the same set of optimization options I get two different sets of enabled/disabled options.

但是,当我使用相同的优化选项集运行方法1和2时,我得到了两个不同的启用/禁用选项集。

$ gcc -Q -v -O3 -march=native -o hello hello.c

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
options passed:  -v -D__DYNAMIC__ hello.c -march=corei7-avx -mcx16 -msahf
-mno-movbe -maes -mpclmul -mpopcnt -mno-abm -mno-lwp -mno-fma -mno-fma4
-mno-xop -mno-bmi -mno-bmi2 -mno-tbm -mavx -mno-avx2 -msse4.2 -msse4.1
-mno-lzcnt -mno-rdrnd -mno-f16c -mno-fsgsbase --param l1-cache-size=32
--param l1-cache-line-size=64 --param l2-cache-size=6144 -mtune=corei7-avx
-fPIC -mmacosx-version-min=10.6.8 -O3
options enabled:  -Wnonportable-cfstrings -fPIC -falign-labels
-fasynchronous-unwind-tables -fauto-inc-dec -fbranch-count-reg
-fcaller-saves -fcombine-stack-adjustments -fcommon -fcompare-elim
-fcprop-registers -fcrossjumping -fcse-follow-jumps -fdebug-types-section
-fdefer-pop -fdelete-null-pointer-checks -fdevirtualize -fearly-inlining
...

whereas

$ gcc -Q -O3 -march=native --help=optimizers

-falign-functions                   [enabled]
-falign-jumps                       [enabled]
-falign-labels                      [enabled]
-falign-loops                       [enabled]
-fasynchronous-unwind-tables        [enabled]
-fbranch-count-reg                  [enabled]
-fbranch-probabilities              [disabled]
-fbranch-target-load-optimize       [disabled]
-fbranch-target-load-optimize2      [disabled]
-fbtr-bb-exclusive                  [disabled]
-fcaller-saves                      [enabled]
-fcombine-stack-adjustments         [enabled]
-fcommon                            [enabled]
-fcompare-elim                      [enabled]
-fconserve-stack                    [disabled]
-fcprop-registers                   [enabled]
-fcrossjumping                      [enabled]
-fcse-follow-jumps                  [enabled]
-fcx-fortran-rules                  [disabled]
-fcx-limited-range                  [disabled]
-fdata-sections                     [disabled]
-fdce                               [enabled]
-fdefer-pop                         [enabled]
-fdelayed-branch                    [disabled]
-fdelete-null-pointer-checks        [enabled]
-fdevirtualize                      [enabled]
-fdse                               [enabled]
-fearly-inlining                    [enabled]
...

Looking at options -falign-functions, -falign-jumps, -falign-labels, and -falign-loops Method 2 claims they are all enabled, while Method 1 says only -falign-labels is enabled. Also options -fdce and -fdse are enabled according to Method 2 but not according to Method 1.

查看选项-falign-functions、- faligni -跳转、- faligni -label和-falign-loop方法2声明它们都已启用,而方法1表示只启用- faligni -label。还可以根据方法2启用选项-fdce和-fdse,但不是按照方法1。

Question: which method should I trust?

问题:我应该信任哪种方法?

Side note: the list of method 2 is incomplete, because the options are grouped and only the group(s) requested with the --help= option are listed. To see all options in method 2 run:

附注:方法2的列表是不完整的,因为选项是分组的,只列出了请求的组(s)。在方法2中查看所有选项:

$ gcc -Q -O3 -march=native --help=optimizers --help=target --help=c 
--help=common --help=warnings | sort

1 个解决方案

#1


1  

From GCC documentation:

从GCC文档:

--help={class|[^]qualifier}[,...] Print (on the standard output) a description of the command-line options understood by the compiler that fit into all specified classes and qualifiers.

——帮助= {类|[^]限定符}[,……打印(在标准输出上)对编译器所理解的命令行选项的描述,它适用于所有指定的类和限定符。

whereas

If the -Q option appears on the command line before the --help= option, then the descriptive text displayed by --help= is changed. Instead of describing the displayed options, an indication is given as to whether the option is enabled, disabled or set to a specific value (assuming that the compiler knows this at the point where the --help= option is used)

如果-Q选项出现在-help=选项之前的命令行中,那么-help=的描述性文本将被更改。没有描述显示的选项,而是给出了选项是否启用、禁用或设置为特定值(假设编译器在使用-help=选项时知道这一点)。

It appears that --help simply shows which options one can enable, while -Q allows one to see if it is actually enabled. Also:

它看起来——帮助简单地显示了一个可以启用的选项,而-Q允许查看它是否真的启用了。另外:

The output is sensitive to the effects of previous command-line options

输出对前面的命令行选项的影响非常敏感。

#1


1  

From GCC documentation:

从GCC文档:

--help={class|[^]qualifier}[,...] Print (on the standard output) a description of the command-line options understood by the compiler that fit into all specified classes and qualifiers.

——帮助= {类|[^]限定符}[,……打印(在标准输出上)对编译器所理解的命令行选项的描述,它适用于所有指定的类和限定符。

whereas

If the -Q option appears on the command line before the --help= option, then the descriptive text displayed by --help= is changed. Instead of describing the displayed options, an indication is given as to whether the option is enabled, disabled or set to a specific value (assuming that the compiler knows this at the point where the --help= option is used)

如果-Q选项出现在-help=选项之前的命令行中,那么-help=的描述性文本将被更改。没有描述显示的选项,而是给出了选项是否启用、禁用或设置为特定值(假设编译器在使用-help=选项时知道这一点)。

It appears that --help simply shows which options one can enable, while -Q allows one to see if it is actually enabled. Also:

它看起来——帮助简单地显示了一个可以启用的选项,而-Q允许查看它是否真的启用了。另外:

The output is sensitive to the effects of previous command-line options

输出对前面的命令行选项的影响非常敏感。