GCC编译器选项:哪组启用的选项是正确的?

8

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

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

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

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

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

然而,当我使用相同的优化选项运行方法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
...

相反,

$ 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]
...

查看选项-falign-functions、-falign-jumps、-falign-labels和-falign-loops,方法2声称它们都已启用,而方法1仅声称启用了-falign-labels。此外,选项-fdce和-fdse根据方法2已启用,但根据方法1未启用。

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

附注:方法2的选项列表不完整,因为选项被分组,并且只有使用--help=选项请求的组别才会列出。要查看方法2中所有选项,请运行:

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

1

来自GCC文档:

--help={class|[^]qualifier}[,...] 打印(在标准输出上)编译器可以理解的符合所有指定类别和限定符的命令行选项的描述。

然而

如果-Q选项出现在--help=选项之前的命令行上,则--help=显示的描述性文字会更改。不再描述显示的选项,而是给出指示,表示该选项是启用、禁用还是设置为特定值(假定编译器在使用--help=选项时知道这一点)

看起来,-help只是展示了可以启用哪些选项,而-Q允许查看是否已实际启用。此外:

输出会受到先前命令行选项的影响


实际上,-Q 修改输出以显示启用了哪些选项,并且在方法 1 和 2 中都使用。然而,问题是为什么在提供简单的 C 源文件(方法 1)或 --help(方法 2)时结果会有所不同。难道方法 1 只是不完整吗? - zan

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接