Skip to content
rofl0r edited this page Nov 22, 2015 · 1 revision

LTO

in order to create a full-featured LTO toolchain, build stage1 (which will build gcc474, the last gcc that can be compiled with the stage0 "C-only" C-compiler), and then issue

BINUTILS_DYNAMIC=1 butch rebuild binutils

and

GCC_DYNAMIC=1 butch rebuild gcc520

this produces a toolchain with LTO linker plugin which can be used across archive (.a) boundaries. put -flto -fuse-linker-plugin into your optcflags (AND optldflags!) in /etc/butch-optflags.sh and compile stuff. note that you need to put the optimization level (for example -Os) as well in both optcflags and optldflags!

the lto support was enabled in the commit range https://github.com/sabotage-linux/sabotage/compare/6b2942af147e...75e40e798533 . you may want to read the commit messages for details.

NOTE:

this is only about cross-archive LTO support via -fuse-linker-plugin. packages that do not depend on or use archives (i.e. are dependency-free) already support LTO with the standard gcc4 toolchain via -flto.

NOTE:

tests showed that -flto -fuse-linker-plugin do not substantially decrease binary size when used with -Os. the standard CFLAGS with -ffunction-sections and -fdata-sections together with -Wl,--gc-sections produce equal or better results in terms of binary size while using substantially less compilation time. OTOH -flto -fwhole-program (does not require linker plugin) works great when all translation units are passed to CC in a single invocation: example:

$CC -Os -s -flto -fwhole-program foo.c bar.c baz.c -o binary