From fec559d034ed32929771c80922fd2c2249edba15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 2 Apr 2026 22:20:48 +0200 Subject: [PATCH] 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 --- meson.build | 9 +++++++++ src/fundamental/macro-fundamental.h | 6 ++++++ src/shared/options.h | 1 + src/shared/verbs.h | 1 + 4 files changed, 17 insertions(+) diff --git a/meson.build b/meson.build index c9e96b2591..0f8f0b5375 100644 --- a/meson.build +++ b/meson.build @@ -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 diff --git a/src/fundamental/macro-fundamental.h b/src/fundamental/macro-fundamental.h index 5690859cf4..f595be2cc5 100644 --- a/src/fundamental/macro-fundamental.h +++ b/src/fundamental/macro-fundamental.h @@ -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 diff --git a/src/shared/options.h b/src/shared/options.h index afa17d9e30..c1ffa595ce 100644 --- a/src/shared/options.h +++ b/src/shared/options.h @@ -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, \ diff --git a/src/shared/verbs.h b/src/shared/verbs.h index cd18359cd7..51a9e3a525 100644 --- a/src/shared/verbs.h +++ b/src/shared/verbs.h @@ -26,6 +26,7 @@ typedef struct { _alignptr_ \ _used_ \ _retain_ \ + _no_reorder_ \ _variable_no_sanitize_address_ \ static const Verb CONCATENATE(verb_data_, __COUNTER__) = { \ .verb = v, \