0
0
Fork 0
mirror of https://github.com/netdata/netdata.git synced 2025-04-07 23:05:41 +00:00
netdata_netdata/packaging/cmake
Austin S. Hemmelgarn 10815cb24a
Add LTO support in CMake build system. ()
* Add LTO support in CMake build system.

Internally, CMake calls LTO ‘Interprocedural Optimization’, and it
provides functionality for checking for support for this as well as
enabling it by default for targets. This leverages that support to
auto-detect LTO and enable it if it’s supported.

* Default to disabling LTO for Debug builds.

* Add handling for LTO to netdata installer code.

* Switch back to DISABLE_LTO as option name.

Using `ENABLE_LTO` leads to a possibility for confusion among users, as it
does behave in the most intuitive manner. Instead of ensuring that LTO
is used (and thus behaving like every other `ENABLE_*` option we have),
it allows the usage LTO if it’s supported. Thus a build with
`-DENABLE_LTO=True` may not actually be built with LTO.

By instead using `DISABLE_LTO`, the behavior matches up directly with
how most people are likely to interpret the meaning, because a build
with `-DDISABLE_LTO=True` will _never_ have LTO flags added to the
compiler/linker flags.

* Fix condition for determining default for DISABLE_LTO.

* Turn off LTO auto-detection in RPM package builds.

On pretty much all RPM platforms, the RPM build process itself will
correctly add the required compiler flags when building, so we don’t
actually need to auto-detect LTO support in CMake here.

Additionally, on at least some RPM platforms, CMake’s auto-detection
for LTO support actually breaks the build when used.

* Disable function and data sections when using LTO.

On at least some systems, `-fdata-sections` combined with LTO reliably
causes failures at link time with our code.

The final binary size on systems where the combination _works_ differs by
no more than a few KiB on average (tested on 64-bit x86 on Ubuntu 22.04,
Debian 12, Fedora 39, and Rocky Linux 9), so we’re not actually getting
almost any benefit out of using both with things as they are now, but
LTO gives us a meaasurable performance improvement that per-function and
per-data sections do not.

* Restructure in-line with current repo state.

* Disable LTO on Windows builds since it doesn’t work there.

* Fix compiler flag handling order.

* Switch LTO option name to USE_LTO for consistency with USE_MOLD.
2025-01-31 08:22:23 -05:00
..
Modules Add LTO support in CMake build system. () 2025-01-31 08:22:23 -05:00
pkg-files Updated copyright notices () 2024-12-20 15:25:45 +02:00
config.cmake.h.in Bundle cmake cache. () 2025-01-31 10:39:14 +02:00