[systemd-devel] Is LTO worth it?
Lennart Poettering
lennart at poettering.net
Mon Jan 11 15:39:39 UTC 2021
On Mo, 11.01.21 15:34, Michael Biebl (mbiebl at gmail.com) wrote:
> Hi,
>
> we've been using LTO in the Debian build for as long as I can
> remember, but I begin to question whether that is a good idea.
> On Debian sid (gcc (Debian 10.2.1-6) 10.2.1 20210110, GNU ld (GNU
> Binutils for Debian) 2.35.1),
> an LTO build almost takes twice as long as a no-LTO build.
> I also debdiffed the produced binary and LTO seems to produce bigger
> binaries as well.
LTO is about optimization for speed primarily. That it can strip
unneeded stuff is just an additional nice effect.
LTO used to be absolutely important to us, since we linked a lot of
the common code statically into all our binaries, and with LTO's help
we stripped the bits unnecessary for the specific binary out of it. we
don't build things like that anymore though. we now have a big private
shared library instead that all our tools link against. The shared lib
carries basically everything, and you can't strip much out of it, or out of
the binaries easily...
So, LTO is typically a good idea to optimize stuff where the
granularity of .c modules is "finegrained" (i.e. where the
functions-per-c-file-ratio is small), since otherwise the compiler
would never get the chance to inline a function or so. But it's not
really that essential anymore for us, for building remotely
reasonably-sized binaries.
Note that other distros will soon go for LTO for everything:
https://fedoraproject.org/wiki/LTOByDefault
(I think Suse is even further ahead on this)
So, it's up to you where you want to take things, but I sense the
future is "yes to LTO" and not "no to LTO".
Lennart
--
Lennart Poettering, Berlin
More information about the systemd-devel
mailing list