From 5ed963e054e94d4bd8e07e2fc914f675ebda33b1 Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Tue, 18 Feb 2025 17:55:45 +0100 Subject: [PATCH] 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 --- meson.build | 12 ++++++------ src/libnm-glib-aux/nm-macros-internal.h | 17 +++++++++++++++++ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/meson.build b/meson.build index 45bff7b7be..53dc6d9e1d 100644 --- a/meson.build +++ b/meson.build @@ -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 diff --git a/src/libnm-glib-aux/nm-macros-internal.h b/src/libnm-glib-aux/nm-macros-internal.h index 151e7a4f4b..940e8c30a8 100644 --- a/src/libnm-glib-aux/nm-macros-internal.h +++ b/src/libnm-glib-aux/nm-macros-internal.h @@ -1021,6 +1021,22 @@ nm_g_variant_equal(GVariant *a, GVariant *b) /*****************************************************************************/ +#if defined(__GNUC__) && (__GNUC__ >= 12) +#define _NM_BACKPORT_SYMBOL_IMPL(version, \ + return_type, \ + orig_func, \ + versioned_func, \ + args_typed, \ + args) \ + return_type versioned_func args_typed; \ + \ + __attribute__((__symver__( \ + G_STRINGIFY(orig_func) "@" G_STRINGIFY(version)))) return_type versioned_func args_typed \ + { \ + return orig_func args; \ + } \ + return_type orig_func args_typed; +#else #define _NM_BACKPORT_SYMBOL_IMPL(version, \ return_type, \ orig_func, \ @@ -1035,6 +1051,7 @@ nm_g_variant_equal(GVariant *a, GVariant *b) return_type orig_func args_typed; \ __asm__(".symver " G_STRINGIFY(versioned_func) ", " G_STRINGIFY(orig_func) "@" G_STRINGIFY( \ version)) +#endif #define NM_BACKPORT_SYMBOL(version, return_type, func, args_typed, args) \ _NM_BACKPORT_SYMBOL_IMPL(version, return_type, func, _##func##_##version, args_typed, args)