]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
meson: disable __attribute__((__retain__)) on old compilers
authorZbigniew Jędrzejewski-Szmek <zbyszek@amutable.com>
Thu, 19 Mar 2026 16:06:17 +0000 (17:06 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@amutable.com>
Fri, 20 Mar 2026 14:26:47 +0000 (15:26 +0100)
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
src/boot/meson.build
src/fundamental/macro-fundamental.h

index 3672005d75b173ef1103e7a9095e3490be9cdc98..c52f8e17c2bbe6e5e4a96cf2a5093865a5ad3d4c 100644 (file)
@@ -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
index 06c8146a9ebcbcf129c91c1c0b4e321c0a32d21c..c51510e96f4a19d78a73a568afc776f4ba574245 100644 (file)
@@ -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'))
index e8757b1fc37a4051c2adc98f6cd08b3a048c9a5d..39004183d90f286dd6f45e13738055ff95fad7a2 100644 (file)
@@ -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__))
 #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