meson: detect and use __attribute__((no_reorder))

In some builds (package builds, so with optimization and lto, but I
haven't been able to pin down the exact combination on options that
matters), we end up with items in the verbs array reordered. The order
matters (because of groups, but also because we have some specific order
for display), so this reordering is something that we don't want.

From what I was able to read, the compiler + linker generally keep the
order within a single translation unit, but this is more of a convention
and implementation choice than a guarantee. Add this attribute [1]. It
seems to have the desired effect in CI.

[1] https://gcc.gnu.org/onlinedocs/gcc-15.2.0/gcc/Common-Function-Attributes.html#index-no_005freorder-function-attribute
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2026-04-03 13:05:27 +02:00
parent 4419840ad1
commit fec559d034
4 changed files with 17 additions and 0 deletions
+9
View File
@@ -549,6 +549,15 @@ foreach attr : possible_c_attributes
conf.set10('HAVE_ATTRIBUTE_' + attr.to_upper(), have)
endforeach
# TODO: drop this manual check when meson learns about this attribute
possible_c_attributes += ['no_reorder']
have = cc.compiles(
'__attribute__((__no_reorder__)) int x;',
args : '-Werror=attributes',
name : '__attribute__((__no_reorder__))')
conf.set10('HAVE_ATTRIBUTE_NO_REORDER', have)
#####################################################################
# compilation result tests
+6
View File
@@ -116,6 +116,12 @@
# define _retain_
#endif
#if HAVE_ATTRIBUTE_NO_REORDER
# define _no_reorder_ __attribute__((__no_reorder__))
#else
# define _no_reorder_
#endif
#if __GNUC__ >= 15
# define _nonnull_if_nonzero_(p, n) __attribute__((nonnull_if_nonzero(p, n)))
#else
+1
View File
@@ -25,6 +25,7 @@ typedef struct Option {
_alignptr_ \
_used_ \
_retain_ \
_no_reorder_ \
_variable_no_sanitize_address_ \
static const Option CONCATENATE(option, counter) = { \
.id = 0x100 + counter, \
+1
View File
@@ -26,6 +26,7 @@ typedef struct {
_alignptr_ \
_used_ \
_retain_ \
_no_reorder_ \
_variable_no_sanitize_address_ \
static const Verb CONCATENATE(verb_data_, __COUNTER__) = { \
.verb = v, \