From 19a3cc83353e3bb4bc28769f8606139a3d350d2d Mon Sep 17 00:00:00 2001 From: Andi Kleen Date: Wed, 2 Apr 2014 21:49:27 +0200 Subject: Kbuild, lto: Add Link Time Optimization support v3 With LTO gcc will do whole program optimizations for the whole kernel and each module. This increases compile time, but can generate faster and smaller code and allows the compiler to do global checking. For example the compiler can complain now about type mismatches for symbols between different files. LTO allows gcc to inline functions between different files and do various other optimization across the whole binary. It might also trigger bugs due to more aggressive optimizations. It allows gcc to drop unused code. It also allows it to check types over the whole program. The compile time is definitely slower. For gcc 4.8 on a typical monolithic config it is about 58% slower. 4.9 drastically improved performance, with slowdown being 38% or so. Also incremenential rebuilds are somewhat slower, as the whole kernel always needs to be reoptimized. Very modular kernels have less build time slow down, as the LTO will run for each module individually. This adds the basic Kbuild plumbing for LTO: - In Kbuild add a new scripts/Makefile.lto that checks the tool chain (note the checks may not be fully bulletproof) and when the tests pass sets the LTO options Currently LTO is very finicky about the tool chain. - Add a new LDFINAL variable that controls the final link for vmlinux or module. In this case we call gcc-ld instead of ld, to run the LTO step. - For slim LTO builds (object files containing no backup executable) force AR to gcc-ar - Theoretically LTO should pass through compiler options from the compiler to the link step, but this doesn't work for all options. So the Makefile sets most of these options manually. - Kconfigs: Since LTO with allyesconfig needs more than 4G of memory (~8G) and has the potential to makes people's system swap to death. I used a nested config that ensures that a simple allyesconfig disables LTO. It has to be explicitely enabled. - Some depencies on other Kconfigs: MODVERSIONS, GCOV, FUNCTION_TRACER, KALLSYMS_ALL, single chain WCHAN are incompatible with LTO currently, mostly because they they require setting special compiler options for specific files, which LTO currently doesn't support. MODVERSIONS should in principle work with gcc 4.9, but still disabled. FUNCTION_TRACER/GCOV can be fixed with a unmerged gcc patch. - Also disable strict copy user checks because they trigger errors with LTO. - modpost symbol checking is downgraded to a warning, as in some cases modpost runs before the final link and it cannot resolve LTO symbols at this point. For more information see Documentation/lto-build Thanks to HJ Lu, Joe Mario, Honza Hubicka, Richard Guenther, Don Zickus, Changlong Xie who helped with this project (and probably some more who I forgot, sorry) v2: Merge documentation file into this patch Improve documentation and Kconfig, fix a lot of obsolete comments. Exclude READABLE_ASM Some random fixes v3: Remove CONFIG_LTO_SLIM, is on by default. Signed-off-by: Andi Kleen Signed-off-by: Michal Marek --- lib/Kconfig.debug | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index dd7f8858188a..6ed8f51b8538 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -180,7 +180,7 @@ config STRIP_ASM_SYMS config READABLE_ASM bool "Generate readable assembler code" - depends on DEBUG_KERNEL + depends on DEBUG_KERNEL && !LTO help Disable some compiler optimizations that tend to generate human unreadable assembler output. This may make the kernel slightly slower, but it helps -- cgit v1.2.3