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.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2026-03-20 15:26:47 +01:00
parent a0eae2ab7b
commit fabc22f599
3 changed files with 17 additions and 3 deletions
+6
View 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
+5 -2
View 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'))
+6 -1
View 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__))
@@ -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