Ubuntu 21.04 will enable LTO optimization for its packages

According to the mailing list, Ubuntu 21.04 will enable LTO support for its package construction. Link time optimization (LTO) is a method for optimizing multiple compilation units of the entire program during linking. The generated code is faster and the file is smaller. Now, upstream projects like GCC and Python have turned on LTO by default or provide LTO configuration options, and other Linux distributions also turn on LTO by default when they are released. In addition, Linux Kernel 5.12 may also support LTO optimization.
According to the Ubuntu wiki, with the exception of riscv64, Ubuntu 21.04 plans to enable LTO by default for all 64-bit architectures after adding glibc 2.33 to the release. Currently, LTO’s compiler flags have been added to dpkg-buildflags, which can be overridden in package building, and will be enabled on amd64, arm64, ppc64el, and s390x. At the same time, Ubuntu 21.04 provides LTO switches:

On architectures where LTO is disabled, it can be enabled in the rules file by

  • export DEB_BUILD_MAINT_OPTIONS=optimize=+lto

It can be disabled by

  • export DEB_BUILD_MAINT_OPTIONS=optimize=-lto

In addition, the developer has tested the LTO support with GCC 9 and GCC 10 respectively.