GCC Optimizations
"Michael D." <[email protected]> Mon, 23 Oct 2017 06:17:58 +0200
| Newsgroups | gmane.linux.lfs.general |
|---|---|
| Message-ID | <[email protected]> |
Hi :)
Been playing around with optimizations when compiling LFS using JHALFS.
Sharing my findings to those who might find it useful, and looking for
feedback on what could be improved :)
So far I've come up with this:
CFLAGS="-g0 -O3 -pipe -m64 -mfxsr -march=nehalem"
CXXFLAGS=$CFLAGS
LDFLAGS="-Wl,-O3 -Wl,-s"
And using 'make -j6' (JHALFS makes exceptions for packages which
doesn't play well with parallel builds).
Also been playing around with "-ffast-math" and "-funroll-loops" - but
according to the interwebs, they can cause slower/bigger code, so
omitting them for now.
Not sure if I gain much from the instruction flag "-mfxsr", but it's the
only instruction set supported by my CPU that isn't enabled by
"-march=nehalem".
Nor if I gain anything from specifying "-m64" since it's compiled on a
pure x86_64 system.
Explanations:
- This is the number 0 (Zero)
/
/ - This is the uppercase letter "O" as in "Open"
/ /
CFLAGS="-g0 -O3 -pipe -m64 -mfxsr -march=nehalem"
-g0 = Prevents GCC from adding Debug Information to Binaries and Libs.
-O3 = The highest recommended level of Optimization done by GCC.
-pipe = Makes GCC use pipes instead of slow files when parsing information from one process to another.
-m64 = Sets|'int'| to 32 bits and|'long'| and pointer types to 64 bits.
-mfxsr = An instruction set - but haven't been able to find any useful information.
-march=nehalem = Tells GCC it can use the instruction sets found in Nehalem CPU's: MMX, SSE, SSE2, SSE3, SSSE3, SSE4.1, SSE4.2 and POPCNT instruction set support.
- This is the lowercase letter L as in "Love"
/
/ - The uppercase letter O as in "Okay"
/ /
LDFLAGS="-Wl,-O3 -Wl,-s"
-Wl,flag = Tells GCC to pass the following flag to the Library Linker.
-Wl,-O3 = Tells GCC to pass the optimization -O3 flag to the Linker.
-Wl,-s = Tells GCC to pass the -s flag the the linker so it removes all symbol tables and relocation information's from the executable. (Unsafe?)
The -Wl works with comma-delimited flags, so LDFLAGS could also be written as:
LDFLAGS="-Wl,-O3,-s"
Since the -Wl flag instructs GCC to pass the attached flag (eg. -O3 or -s) to its linker, the flags could be embedded (anywhere) in the CFLAGS like this:
CFLAGS="-g0 -O3 -pipe -m64 -Wl,-O3,s -mfxsr -march=nehalem"
Hope someone finds it useful :)
Best regards
Michael
----
Some useful links to the GCC Documentation:
https://gcc.gnu.org/onlinedocs/gcc/index.html
https://gcc.gnu.org/onlinedocs/gcc/Option-Summary.html
https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html
https://gcc.gnu.org/onlinedocs/gcc/Link-Options.html
https://gcc.gnu.org/onlinedocs/gcc/x86-Options.html
https://gcc.gnu.org/onlinedocs/gcc/Debugging-Options.html
--
http://lists.linuxfromscratch.org/listinfo/lfs-chat
FAQ: http://www.linuxfromscratch.org/blfs/faq.html
Unsubscribe: See the above information page