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:
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
Using the -Q --help=x combination (for values of x, see GCC documentation) e.g:
gcc -Q --help=target
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.
$ 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.
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:
$ gcc -Q -O3 -march=native --help=optimizers --help=target --help=c
--help=common --help=warnings | sort
When you invoke GCC, it normally does preprocessing, compilation, assembly and linking. The "overall options" allow you to stop this process at an intermediate stage. For example, the -c option says not to run the linker.
The different options of gcc command allow the user to stop the compilation process at different stages. Most Useful Options with Examples: Here source. c is the C program code file. -o opt: This will compile the source.
gcc -Wall enables all compiler's warning messages. This option should always be used, in order to generate better code.
The -E option causes gcc to run the preprocessor, display the expanded output, and then exit without compiling the resulting source code.
From GCC documentation:
--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)
It appears that --help simply shows which options one can enable, while -Q allows one to see if it is actually enabled. Also:
The output is sensitive to the effects of previous command-line options
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With