CFLAGS
From CLFS-HINTS
CFLAGS on CLFS Systems
On a CLFS system we set CFLAGS system-wide using the BUILD32, BUILDN32, and BUILD64 environment variables in the file /etc/profile.d/50-multilib.sh. Both the CLFS Book and CBLFS Wiki set these variables to -m32, -m64, -mabi=32, -mabi=n32, or -mabi=64 as appropriate for the architecture. To use any of these flags system-wide, just append them to your BUILD32, BUILDN32, or BUILD64 environment variables in /etc/profile.d/50-multilib.sh.
A complete listing of gcc options is found in the gcc manual. The following tables provide some feedback from CLFS users on their experience with various gcc options.
CFLAGS for Optimizations
| FLAG | DESCRIPTION | KNOWN ISSUES |
|---|---|---|
| -O2 | Enables nearly all supported optimizations that do not involve a space-speed tradeoff. Does not enable loop unrolling or function inlining. As compared to -O, -O2 yields faster binaries at the cost of greater compilation time. | Generally considered safe to use this level of optimization. Tends to be the default optimization level found in Makefiles when the maintainers specify gcc flags. |
| -Os | Optimize for size. -Os enables all -O2 optimizations that do not typically increase code size. It also performs further optimizations designed to reduce code size. Usually produces binaries smaller than those compiled with -O2, but also may slightly degrade performance (or increase performance due to more effective caching, reduced dependencies, and smaller code to link/execute). | |
| -O3 | Enables all optimizations specified by -O2 and also -finline-functions, -funswitch-loops and -fgcse-after-reload. The generated binary is most often bigger, and may be faster or slower. | Generally considered a risky optimiztion level. |
| -pipe | Use pipes rather than temporary files for communication between the various stages of compilation. | Speeds builds. |
| -combine | If you are compiling multiple source files, this option tells the driver to pass all the source files to the compiler at once. Currently the only language for which this is supported is C. | Can speed compilation but some applications (e.g., ffmpeg) fail because of too many files. |
| -mtune=cpu-type | Tune to cpu-type everything applicable about the generated code, except for the ABI and the set of available instructions. | On ix86 and x86_64 platforms the compiler will not generate any code that does not run on the i386 without the -march=cpu-type option being used. |
| -march=cpu-type | Generate instructions for the machine type cpu-type. Specifying -march=cpu-type implies -mtune=cpu-type. |
CFLAGS for i386 and x86_64 Platforms
| FLAG | DESCRIPTION | KNOWN ISSUES |
|---|---|---|
| -mmmx -m3dnow -msse -msse2 -msse3 -mssse3 | Enable or disable the use of instructions in the MMX, SSE, or 3DNow! extended instruction sets. | Automatically set by most -march, but not -mtune flags. |
