Search code examples
cubuntugccdefault-valuecompiler-flags

Are default gcc compiler options gcc version specific or OS specific or both?


I am wondering if the default gcc compiler options can vary any if so where I can expect different default compiler options. Do default compiler options vary from one gcc version to another (e.g gcc 4.6 -> gcc 4.8)or are they always the same? Do default compiler options vary from one OS version to another (e.g. Ubuntu 12.04 -> 14.04)?

I expect that default compiler options are different regarding two different OS, like Ubuntu and Debian, right?


Solution

  • Yes, you can generally expect the default flags to be quite different. Fortunately, you don't need to know what the flags are, and you don't need to set them.

    Ubuntu and Debian are pretty similar, since Ubuntu is so closely based on Debian. But you will see a variety of different options, since the actual options that GCC uses are fairly technical. You can see them by running the following:

    gcc -Q -v -x c -c /dev/null
    

    This asks GCC to compile /dev/null as a C program (-x c -c /dev/null) and print out a bunch of developer info (-Q -v). I ran this with GCC 4.4, 4.6, and 4.8 and got different results. Here are the differences between the options for 4.4 and 4.6 on my machine:

    < -falign-loops
    < -fargument-alias
    > -fdelete-null-pointer-checks
    > -fprefetch-loop-arrays
    > -fsched-critical-path-heuristic
    > -fsched-dep-count-heuristic
    > -fsched-group-heuristic
    > -fsched-last-insn-heuristic
    > -fsched-rank-heuristic
    > -fsched-spec-insn-heuristic
    > -fshow-column
    > -fstrict-volatile-bitfields
    > -ftree-forwprop
    > -ftree-loop-if-convert
    > -ftree-phiprop
    > -ftree-pta
    > -ftree-slp-vectorize
    > -fvar-tracking-assignments
    < -mfused-madd
    

    Here are the diffs from version 4.6 to 4.8 on my machine:

    > -faggressive-loop-optimizations
    > -fgnu-runtime
    > -fgnu-unique
    < -finline-functions-called-once
    > -finline-atomics
    > -fira-hoist-pressure
    > -fsync-libcalls
    > -ftree-coalesce-vars
    < -fvect-cost-model
    > -mfxsr
    > -mlong-double-80
    

    On my machine, GCC uses 80 different options by default when compiling C! The options will also change when you compile C++ or compile on different platforms.

    But that's okay. You can basically ignore all of these options and just focus on the most important ones, which are the various -W warning flags, -O optimization flags (which are really just shortcuts for a ton of preselected -f flags and a few -m—on my computer, -O2 enables 63 additional flags!), and the -g debug data flag.

    And of course, the basic flags, like -std=, -c, -o, -l, -I, etc.

    I mean, do you really need to know what -fbranch-count-reg does? Not really.