diff --git a/src/core/nm-config-data.h b/src/core/nm-config-data.h index fa58d869c7..92a7cb5c6f 100644 --- a/src/core/nm-config-data.h +++ b/src/core/nm-config-data.h @@ -195,16 +195,16 @@ const char *nm_config_data_get_iwd_config_path(const NMConfigData *self); extern const char *__start_connection_defaults[]; extern const char *__stop_connection_defaults[]; -#define NM_CON_DEFAULT_NOP(name) \ - static const char *NM_UNIQ_T(connection_default, NM_UNIQ) \ - _nm_used _nm_section("connection_defaults") = "" name +#define NM_CON_DEFAULT_NOP(name) \ + static const char * NM_UNIQ_T(connection_default, NM_UNIQ) \ + _nm_used _nm_retain _nm_section("connection_defaults") = "" name -#define NM_CON_DEFAULT(name) \ - ({ \ - static const char *__con_default_prop _nm_used _nm_section("connection_defaults") = \ - "" name; \ - \ - name; \ +#define NM_CON_DEFAULT(name) \ + ({ \ + static const char *__con_default_prop _nm_used _nm_retain _nm_section( \ + "connection_defaults") = "" name; \ + \ + name; \ }) const char *nm_config_data_get_connection_default(const NMConfigData *self, diff --git a/src/libnm-std-aux/nm-std-aux.h b/src/libnm-std-aux/nm-std-aux.h index ce4d06d25b..b79b1c6533 100644 --- a/src/libnm-std-aux/nm-std-aux.h +++ b/src/libnm-std-aux/nm-std-aux.h @@ -26,6 +26,21 @@ #define _nm_alignof(type) __alignof(type) #define _nm_alignas(type) _nm_align(_nm_alignof(type)) #define _nm_deprecated(msg) __attribute__((__deprecated__(msg))) +#define _nm_retain + +#if defined(__clang__) && defined(__has_attribute) +#if __has_attribute(__retain__) +/* __attribute__((__retain__)) is supported in clang 13+, but is warned about + * as an unknown attribute in older versions. We assume older versions are used + * together with linkers that do not require the attribute. + * + * Ideally __has_attribute(__retain__) would be checked in other compilers as + * well, but it is broken in GCC (bug 99587). Limit it to clang for now, as it + * is only known to be needed for linking lld. */ +#undef _nm_retain +#define _nm_retain __attribute__((__retain__)) +#endif +#endif #if defined(__clang__) && __clang_major__ == 13 /* Clang 13 can emit -Wunused-but-set-variable warning for cleanup variables