From: Zbigniew Jędrzejewski-Szmek Date: Thu, 2 Apr 2026 20:20:48 +0000 (+0200) Subject: meson: detect and use __attribute__((no_reorder)) X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fec559d034ed32929771c80922fd2c2249edba15;p=thirdparty%2Fsystemd.git 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 --- diff --git a/meson.build b/meson.build index c9e96b25914..0f8f0b5375a 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 5690859cf4b..f595be2cc5d 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 afa17d9e300..c1ffa595ce8 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 cd18359cd75..51a9e3a5253 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, \