From fabc22f5998e610eb7ba70a963cab9f94dca5c0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 19 Mar 2026 17:06:17 +0100 Subject: [PATCH] meson: disable __attribute__((__retain__)) on old compilers This attribute was introduced in gcc 11, and our baseline is currently 8.4. So let's allow using _retain_ everywhere, but make it into a noop if not supported. Using __has_attribute was suggested, but with gcc-11.5.0-14.el9.x86_64, __has__attribute(__retain__) is true, but we get a warning when the attribute is actually used. --- meson.build | 6 ++++++ src/boot/meson.build | 7 +++++-- src/fundamental/macro-fundamental.h | 7 ++++++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/meson.build b/meson.build index 3672005d75..c52f8e17c2 100644 --- a/meson.build +++ b/meson.build @@ -524,6 +524,12 @@ if cc.compiles(''' add_project_arguments('-Werror=shadow', language : 'c') endif +have = cc.compiles( + '__attribute__((__retain__)) int x;', + args : '-Werror=attributes', + name : '__attribute__((__retain__))') +conf.set10('HAVE_ATTRIBUTE_RETAIN', have) + if cxx_cmd != '' add_project_arguments(cxx.get_supported_arguments(basic_disabled_warnings), language : 'cpp') endif diff --git a/src/boot/meson.build b/src/boot/meson.build index 06c8146a9e..c51510e96f 100644 --- a/src/boot/meson.build +++ b/src/boot/meson.build @@ -80,8 +80,11 @@ endif efi_conf = configuration_data() # import several configs from userspace -foreach name : ['HAVE_WARNING_ZERO_LENGTH_BOUNDS', 'HAVE_WARNING_ZERO_AS_NULL_POINTER_CONSTANT'] - efi_conf.set10(name, conf.get(name) == 1) +foreach name : ['HAVE_ATTRIBUTE_RETAIN', + 'HAVE_WARNING_ZERO_AS_NULL_POINTER_CONSTANT', + 'HAVE_WARNING_ZERO_LENGTH_BOUNDS', + ] + efi_conf.set(name, conf.get(name)) endforeach efi_conf.set10('ENABLE_TPM', get_option('tpm')) diff --git a/src/fundamental/macro-fundamental.h b/src/fundamental/macro-fundamental.h index e8757b1fc3..39004183d9 100644 --- a/src/fundamental/macro-fundamental.h +++ b/src/fundamental/macro-fundamental.h @@ -88,7 +88,6 @@ #define _printf_(a, b) __attribute__((__format__(printf, a, b))) #define _public_ __attribute__((__visibility__("default"))) #define _pure_ __attribute__((__pure__)) -#define _retain_ __attribute__((__retain__)) #define _returns_nonnull_ __attribute__((__returns_nonnull__)) #define _section_(x) __attribute__((__section__(x))) #define _sentinel_ __attribute__((__sentinel__)) @@ -99,6 +98,12 @@ #define _weak_ __attribute__((__weak__)) #define _weakref_(x) __attribute__((__weakref__(#x))) +#if HAVE_ATTRIBUTE_RETAIN +# define _retain_ __attribute__((__retain__)) +#else +# define _retain_ +#endif + #ifdef __clang__ # define _alloc_(...) #else