]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
selftests/nolibc: stop testing constructor order
authorThomas Weißschuh <linux@weissschuh.net>
Thu, 6 Mar 2025 21:52:39 +0000 (22:52 +0100)
committerThomas Weißschuh <linux@weissschuh.net>
Fri, 7 Mar 2025 06:34:12 +0000 (07:34 +0100)
The execution order of constructors in undefined and depends on the
toolchain.  While recent toolchains seems to have a stable order, it
doesn't work for older ones and may also change at any time.

Stop validating the order and instead only validate that all
constructors are executed.

Reported-by: Willy Tarreau <w@1wt.eu>
Closes: https://lore.kernel.org/lkml/20250301110735.GA18621@1wt.eu/
Link: https://lore.kernel.org/r/20250306-nolibc-constructor-order-v1-1-68fd161cc5ec@weissschuh.net
Acked-by: Willy Tarreau <w@1wt.eu>
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
tools/testing/selftests/nolibc/nolibc-test-linkage.c
tools/testing/selftests/nolibc/nolibc-test.c

index 5ff4c8a1db2a46cf3f8cb55bdabaa5e8819b344c..a7ca8325863face9cd4134a717fe4c7761bdeb7f 100644 (file)
@@ -11,16 +11,16 @@ void *linkage_test_errno_addr(void)
        return &errno;
 }
 
-int linkage_test_constructor_test_value;
+int linkage_test_constructor_test_value = 0;
 
 __attribute__((constructor))
 static void constructor1(void)
 {
-       linkage_test_constructor_test_value = 2;
+       linkage_test_constructor_test_value |= 1 << 0;
 }
 
 __attribute__((constructor))
 static void constructor2(void)
 {
-       linkage_test_constructor_test_value *= 3;
+       linkage_test_constructor_test_value |= 1 << 1;
 }
index a5abf16dbfe0f2aed286964fdfc391bc6201ef3b..5884a891c491544050fc35b07322c73a1a9dbaf3 100644 (file)
@@ -692,14 +692,14 @@ int expect_strtox(int llen, void *func, const char *input, int base, intmax_t ex
 __attribute__((constructor))
 static void constructor1(void)
 {
-       constructor_test_value = 1;
+       constructor_test_value |= 1 << 0;
 }
 
 __attribute__((constructor))
 static void constructor2(int argc, char **argv, char **envp)
 {
        if (argc && argv && envp)
-               constructor_test_value *= 2;
+               constructor_test_value |= 1 << 1;
 }
 
 int run_startup(int min, int max)
@@ -738,9 +738,9 @@ int run_startup(int min, int max)
                CASE_TEST(environ_HOME);     EXPECT_PTRNZ(1, getenv("HOME")); break;
                CASE_TEST(auxv_addr);        EXPECT_PTRGT(test_auxv != (void *)-1, test_auxv, brk); break;
                CASE_TEST(auxv_AT_UID);      EXPECT_EQ(1, getauxval(AT_UID), getuid()); break;
-               CASE_TEST(constructor);      EXPECT_EQ(is_nolibc, constructor_test_value, 2); break;
+               CASE_TEST(constructor);      EXPECT_EQ(is_nolibc, constructor_test_value, 0x3); break;
                CASE_TEST(linkage_errno);    EXPECT_PTREQ(1, linkage_test_errno_addr(), &errno); break;
-               CASE_TEST(linkage_constr);   EXPECT_EQ(is_nolibc, linkage_test_constructor_test_value, 6); break;
+               CASE_TEST(linkage_constr);   EXPECT_EQ(1, linkage_test_constructor_test_value, 0x3); break;
                case __LINE__:
                        return ret; /* must be last */
                /* note: do not set any defaults so as to permit holes above */