Link Time Optimization (LTO) gives GCC the capability of dumping its
internal representation (GIMPLE) to disk, so that all the different
compilation units that make up a single executable can be optimized as
a single module. This expands the scope of inter-procedural
optimizations to encompass the whole program (or, rather, everything
that is visible at link time).
A new user-visible feature is warning about type mismatches across
units.
Some Linux distros are migrating towards enabling it by default for all
packages, as Phoronix claims. Some OSes (like OpenBSD) don't touch the compile flags of their packages though, so we should do it ourselves.
This change adds autoconf-archive back as a dependency because I used autoconf-archive macros to get it done. Sorry, I only had the idea after the commit that removed it was pushed to master.
This change replaces the CFLAGS with "-O2 -flto -g" and appends the same flags to LDFLAGS (LTO requires this) if the user hasn't set CFLAGS, effectively changing AC_PROG_CC's default of "-O2 -g". I checked out scrot 1.6, 1.7, and commit 6d299f5 (current master as of writing this), and compiled all 3 of them with CFLAGS='-O2', copying each resulting binary to /tmp/. Then I compiled 6d299f5 with CFLAGS='-O2 -flto' to show the difference made by this change:
There's an overall trend with scrot getting 5% smaller with all the cleanups that have been made so far, and now LTO on top of 6d299f5 reduces the binary by a further 7% for a total 12% reduction in binary size. LTO and code quality aren't purely there for smaller binaries, but smaller executables are an easy way to notice them.
Quoting GCC Documentation:
It also has the nice side effect of allowing warnings across translation units, as attested by these internet blogs: gcc 8: link time and interprocedura optimization gnu link time optimization finds non-matching declarations
Some Linux distros are migrating towards enabling it by default for all packages, as Phoronix claims. Some OSes (like OpenBSD) don't touch the compile flags of their packages though, so we should do it ourselves.
This change adds autoconf-archive back as a dependency because I used autoconf-archive macros to get it done. Sorry, I only had the idea after the commit that removed it was pushed to master.
This change replaces the CFLAGS with "-O2 -flto -g" and appends the same flags to LDFLAGS (LTO requires this) if the user hasn't set CFLAGS, effectively changing AC_PROG_CC's default of "-O2 -g". I checked out scrot 1.6, 1.7, and commit 6d299f5 (current master as of writing this), and compiled all 3 of them with CFLAGS='-O2', copying each resulting binary to /tmp/. Then I compiled 6d299f5 with CFLAGS='-O2 -flto' to show the difference made by this change:
There's an overall trend with scrot getting 5% smaller with all the cleanups that have been made so far, and now LTO on top of 6d299f5 reduces the binary by a further 7% for a total 12% reduction in binary size. LTO and code quality aren't purely there for smaller binaries, but smaller executables are an easy way to notice them.
I also turned on all warnings by default.