]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
meson: detect and use __attribute__((no_reorder))
authorZbigniew Jędrzejewski-Szmek <zbyszek@amutable.com>
Thu, 2 Apr 2026 20:20:48 +0000 (22:20 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@amutable.com>
Fri, 3 Apr 2026 11:05:27 +0000 (13:05 +0200)
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
src/fundamental/macro-fundamental.h
src/shared/options.h
src/shared/verbs.h

index c9e96b259149585a55258e92fe9dee9e98df50d0..0f8f0b5375ac680bea799d3a67c5844f75ad72bf 100644 (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
 
index 5690859cf4b42e195550a4977535776ffd1db157..f595be2cc5dd23c6a472ebdbdd406d65500bbb45 100644 (file)
 #  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
index afa17d9e3006fd552272a14731d5eedded44bcf2..c1ffa595ce828827b023bfae8725f1faef16b3bc 100644 (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,                                  \
index cd18359cd75ac2181d75addb973858aea68b0dce..51a9e3a5253f2d0c94ef0db2152332a4f4ef55e7 100644 (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,                                              \