This PR adds -Wl,O2
to our gitian and guix LDFLAGS. This makes the linker perform certain optimisations (and is different from LTO).
Any -O argument will enable optimizations in GNU ld. We can use -O2 here, as this matches our compile flags. Note that this would also enable additional optimizations if using the lld or gold linkers, when compared to -O0.
A nice writeup + diagrams of some of these optimizations is available here: http://lwn.net/Articles/192624/.
master
0# bitcoind
1Histogram for `.gnu.hash' bucket list length (total of 3 buckets)
2 Length Number % of total Coverage
3 0 1 ( 33.3%) 0.0%
4 1 0 ( 0.0%) 0.0%
5 2 1 ( 33.3%) 40.0%
6 3 1 ( 33.3%) 100.0%
0# bitcoin-qt
1Histogram for `.gnu.hash' bucket list length (total of 3 buckets)
2 Length Number % of total Coverage
3 0 0 ( 0.0%) 0.0%
4 1 1 ( 33.3%) 10.0%
5 2 0 ( 0.0%) 10.0%
6 3 0 ( 0.0%) 10.0%
7 4 1 ( 33.3%) 50.0%
8 5 1 ( 33.3%) 100.0%
this PR:
0# bitcoind
1Histogram for `.gnu.hash' bucket list length (total of 8 buckets)
2 Length Number % of total Coverage
3 0 3 ( 37.5%) 0.0%
4 1 5 ( 62.5%) 100.0%
0# bitcoin-qt
1Histogram for `.gnu.hash' bucket list length (total of 19 buckets)
2 Length Number % of total Coverage
3 0 9 ( 47.4%) 0.0%
4 1 10 ( 52.6%) 100.0%
GNU ld -O
If level is a numeric values greater than zero ld optimizes the output. This might take significantly longer and therefore probably should only be enabled for the final binary. At the moment this option only affects ELF shared library generation. Future releases of the linker may make more use of this option. Also currently there is no difference in the linker’s behaviour for different non-zero values of this option. Again this may change with future releases.
lld -O
Optimize output file size