Search:  
Gentoo Wiki

CFLAGS_matrix

This article is part of the Tips & Tricks series.
Terminals / Shells Network X Window System Portage System Filesystems Kernel Other
Split-arrows.gifIt has been suggested that this article be split into multiple articles accessible from a disambiguation or index page.   (Discuss)

Colors:

Contents

CFLAGS for optimization

FlagDescriptionKnown Issues
-O2Enables 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.This flag is generally approved, and generally considered safe. It is the recommended default for Gentoo and probably most other distributions as well.
-OsOptimize 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).This is a default flag for recent linux kernels.
-O3Enables 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.Considered risky.
-falign-functions=64Intended for Athlon-XP. Align to 64 byte command buffer on Athlon-XP.Probably detrimental on processors with smaller cache sizes, such as the Athlon XP (512k L2 cache), Pentium 4 (256k/512k L2 cache). It might work better with newer Intel processors, such as the Pentium D 8xx (2x1 MB L2 cache) or the Pentium D 9xx (2x2 MB L2 cache).
-fivoptsEnabled by default in gcc-4.3.1 (other versions not checked). According to the media-libs/mesa-7.0.1 ebuild, this flag is buggy on gcc 4.2!
-fomit-frame-pointer Don't keep the frame pointer in a register for functions that don't need one. This avoids the instructions to save, set up and restore frame pointers; it also makes an extra register available in many functions. This flag is automatically enabled on optimization levels -O, -O2, -O3 and -Os on machines where it does not interfere with debugging.This flag can harm debugging on some machines. According to http://www.gentoo.org/proj/en/qa/backtraces.xml, this flag avoids gdb from generating a backtrace reliably.

When used to compile Wine this flag breaks Wine's internal routines for protected apps and games, making these unusable as protection cannot be verified or bypassed, so its advised to do not use this flag to build Wine.

-frename-registersAllows processor registers to be used more flexibly.Avoid using this flag at all. It's pointless on any architectures except for PPC and x86_64, and it's buggy even there. It slows down compiling noticeably too. There is some probability that the compiler will emit incorrect code on many packages. On amd64 gcc4 will take three times longer to compile (it'll halt on insn-attrtab.c).
-fseeRemoves redundant instructions and rearranges those that remain optimally. Buggy in GCC 4.2, can cause miscompilation. Less buggy in GCC 4.3, but still causes miscompilation, although more rarely. Compiling ffmpeg results in rapidly growing memory use. Was added to O3 but later removed.
-ftracerStrengthens other optimization passes by duplicating code.Although they seem to compile fine, TeTeX and GTK+-2.6 misbehave weirdly at runtime. It also bloats code a bit.
-ftree-loop-linear"Perform linear loop transformations on tree." according to the gcc manual.Unfortunately, this flag triggers a bug (#25211) in gcc version 4.1.x;in particular, when compiling the mesa package. Supposedly works in gcc versions <=4.0.3 or >=4.2.0.
-ftree-parallelize-loops=n Tries to split logic intensive loops into parallel operations. Intended for SMP systems.New switch in GCC 4.3, often causes miscompilation when combined with vectorisation, in which dependencies may fail on depended packages compiled with both switches. Based on OpenMP.
-ftree-vectorizeTries to vectorize loops - make them use single instruction multiple data operations (GCC 4.x)Most packages compile, but many produce segfaults : fontconfig, poppler, librsvg, dbus, alsa-lib, zlib, bjam (boost-build), particularly on Pentium 4s. Included in O3 as of GCC 4.3, safe as of 4.3.2.
-fvect-cost-modelPerforms analysis on code before vectorising, to ensure that it is worth vectorising.New flag in GCC 4.3. Not dangerous to use, but can be counter-productive in that it prevents vectorisation that would be beneficial. Has no effect without -ftree-vectorize.
-malign-doubleControl whether GCC aligns "double", "long double", and "long long" variables on a two word boundary or a one word boundaryUnfortunately, code compiled with this flag might not work with code compiled without this flag, and the gcc manual does mention this. GNU tar compiled with this flag produced strange errors, and strace showed that stat function calls were returning corrupted values, versus GNU tar compiled without this flag which worked fine. A glibc compiled without this flag seems to be the culprit.
-mfpmath=sse,387Attempt to use both SSE and i387 floating point mathDo not use this flag. The GCC register allocator will produce suboptimal floating point code since it doesn't grok two distinct register stacks yet. It's still marked experimental even in the latest GCC release (4.0.0 as of now). The only platform on which this MAY improve things is AMD64, and it's controversial even there. Causes strange bugs with GTK applications like gaim. See bug #74439 for an example.

LDFLAGS for optimization

FlagDescriptionKnown Issues
-Wl,--as-neededThis causes libraries to be linked only if it is really necessary.Binutils prior to 2.17 has problems with this flag. Openttd 0.4.8 will fail to compile, complaining about the pthreads library (perhaps only with USE flag nptlonly).
-Wl,-O1ld optimizes the outputConsidered to be safe.
-Wl,--hash-style=gnuGNU hash style allows less relocations when applications start thus speeding up applications' start up timeIt may break your old applications. Consider rebuilding the whole world.
-Wl,--enable-new-dtagsThe dynamic tags will be created as needed. Especially beneficial for C++ applications and librariesPossibly not safe to use with some applications like OpenOffice.
-sOmit all symbol information from the output file.This flag should never be set in LDFLAGS. See “Stripping” in the Gentoo documentation for an explanation. (In short: portage handles stripping automatically. Add ‘nostrip’ to FEATURES if you want to disable stripping—usually done if you want to use a debugger.)

CXXFLAGS for optimization

FlagDescriptionKnown Issues
-fvisibility-inlines-hiddenAvoids exporting unneeded symbols from libraries, making them smaller.Doesn't work with gcc 3.3! Some older wxGTK versions don't compile. The wxGTK-2.6 version compiles, but doesn't work. Prelinking will no longer work. Used where safe by KDE, if USE contains kdehiddenvisibility.

Miscellaneous CFLAGS

FlagCategoryDescriptionKnown Issues
-ffast-mathApproximationCompromises floating point number accuracy slightly, for speed improvements.Breaks IEEE or ISO norms; can trigger segfaults.

OpenOffice will segfault if KDE dialogs are used and kde-libs was compiled with -ffast-math.
Apache 2 segfaults with GCC 4.1.1 and this flag.
Breakages are also known to occur with postgresql, mpfr, gmp and nss_ldap.
Automatically used within ffmpeg where it is safe.
Appears to trigger a bug in sys-devel/m4-1.4.10.

-mmmx -m3dnow -msse -msse2 -msse3 -mssse3Instruction setsThese switches enable or disable the use of instructions in the MMX, SSE, or 3DNow! extended instruction sets.Automatically set by most -march flags. Only use these for compiling Mesa 3D drivers. Don't add to make.conf. Beneficial when no buit-in target automatically uses them.
-fvisibility=hiddenDeveloper-only flagDo not use this flag in your C(XX)FLAGS! It requires source level changes from the developers or from the Gentoo maintainers, and it will sooner or later badly break your system. Won't compile: pango-1.8.1, perl-5.8.6-r4. Will compile but cause malfunctions later on: Many shared libraries (known example nvidia-glx-7167-r1). Used where safe by KDE, if USE contains kdehiddenvisibility.
-D_FILE_OFFSET_BITS=64file size limitOn 32-bit systems, enables file sizes over 2Gigabytes. Useful for ftp of iso images works with lftp gftp (Opera probably) Causes emerge of glibc-2.5 to fail - remove this flag before merging glibc and restore it afterwards. If you "succeed" to merge glibc with it, further breakage may occur, such as non-functional ALSA dmix device (all applications using it failing with "Inappropriate ioctl for device"). If you still think it's worth it, avoid mixing binaries compiled with and without this flag; because it changes the width of off_t, struct/stack bugs are possible. If you use it, recompile your whole system to be safe.
-WVerbose Compile WarningsEnables more warnings when compiling Although most packages work fine some die silently because they don't expect feedback.
Retrieved from "http://www.gentoo-wiki.info/CFLAGS_matrix"

Last modified: Sun, 12 Oct 2008 03:28:00 +0000 Hits: 54,886