openSUSE:LTO

Jump to: navigation, search
LTO stands for Link Time Optimization and it is a GCC optimization technique that improves speed and reduces size of binaries. The page collects all relevant information about enablement of the LTO in most of the openSUSE:Factory packages

Introduction

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). That typically improves speed of an executable and better dead code elimination is responsible for smaller binaries and debug info. The LTO has been developed for quite some time and we as toolchain team believe it is mature enough to be used in production.

LTO enablement in openSUSE:Factory

We would like to enable LTO in project settings, specifically $optflags, where new RPM macro %{_lto_cflags} will be added. The macro expands to -flto=N, where N is number of jobs and it is useful for parallel LTO linking. The $optflags are automatically expanded to CFLAGS and CXXFLAGS, or accepted by an autoconf replacement like cmake. That will enable LTO in most of the packages that use the GCC compiler.

Based on our experiments there will be packages that can't currently be built with LTO by default. We expect the number of such packages will not extend 5%. We will create opensSUSE bugzilla entries for the problematic packages and a brief analysis will be provided. The most common issues will be collected in this WIKI page.

LTO disablement in a SPEC file

Disablement of the LTO is very simple. One needs to add %define _lto_cflags %{nil} into a SPEC file.

Reproducing LTO build failures

Right now there is not a staging project where the failure can be seen. However, one can easily add following line to a SPEC file in order to enable LTO:

 %global optflags %optflags %{_lto_cflags}

Package build failure FAQ

Symbol versioning

Symbol versioning is not supported right now. Following issue provides more detail information. It is planned to add the support for GCC 10.1 release. One possible workaround is described on Stack Overflow.

GObject Introspection

A GNOME package can fail due to following issue. The issue is still under investigation. Sample error message:

Invalid GType function: 'ostree_async_progress_get_type'
Failed to find symbol 'ostree_async_progress_get_type'

Static libraries

Some packages ship a static libraries that are made of an archive. The libraries contain of just LTO bytecode and should not be shipped. One should use -ffat-lto-objects and brp-check-suse strips the LTO bytecode.