Link Time Optimization

LTO abbreviates Link Time Optimization (or Link Time Optimisation for some). This page gives a quick rough summary on what to expect from it, how to get it into your Debian packages, and why (or why not) to go for it.

LTO grants the compiler the opportunity to see more than a single .o file at a time. This grants extra freedom for the optimisation that yields:

The reduced code size is a good control to learn if the LTO truly kicked in. Sidenote: All other optimisation flags still apply.

Downsides of LTO are

How to get LTO into your Debian packages

There is only one weird thing: The compiler still compiles when you think it should be linking. This is why you pass the compile time flags (like -O2 etc.) also at link time. Here a recipe that seems to work:

Frankly speaking, there is apparently the same effect by just adding -flto to the LDFLAGS, not the whole $CFLAGS. Anyway - that is why this is a wiki, please add your piece of wisdom to this page. For ideas how to integrate the environment variables into the build have a peek at this wiki's Hardening page.