build: remove -flto-partition=none when building with GCC

Older versions of GCC (< 12) have issues building NM with LTO because
they drop libnm symbols added via '_asm__(".symver " ...)', which we
use to support symbols backported to older versions of the DSO.

Nowadays, GCC supports a new "__symver__" attribute that is
LTO-friendly; use that when possible and remove the
-flto-partition=none hack, as it increases memory usage when
compiling.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/1714
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/2142
This commit is contained in:
Beniamino Galvani
2025-02-18 17:55:45 +01:00
parent 481afec6ea
commit 5ed963e054
2 changed files with 23 additions and 6 deletions

View File

@@ -173,13 +173,13 @@ endif
enable_lto = get_option('b_lto')
if enable_lto
if cc.get_id() == 'clang'
clang_version = cc.version()
if clang_version <= '18.0.0'
error('Clang version should be greater then 18.0.0 got : ' + clang_version)
cc_version = cc.version()
if cc.get_id() == 'clang'
if cc_version <= '18.0.0'
error('Clang version should be greater than 18.0.0, got : ' + cc_version)
endif
else
# Meson already adds '-flto'
elif cc_version < '12.0'
# GCC < 12 breaks libnm symbol versioning with LTO, use workarounds
lto_flag = '-flto-partition=none'
assert(cc.has_argument(lto_flag), '-flto-partition=none not supported. Disable link-time optimization with -Db_lto=false.')
common_flags += lto_flag