Skip to content

Commit a782d45

Browse files
committed
selftests/nolibc: stop testing constructor order
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 <[email protected]> Closes: https://lore.kernel.org/lkml/[email protected]/ Link: https://lore.kernel.org/r/20250306-nolibc-constructor-order-v1-1-68fd161cc5ec@weissschuh.net Acked-by: Willy Tarreau <[email protected]> Signed-off-by: Thomas Weißschuh <[email protected]>
1 parent 6e40620 commit a782d45

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

tools/testing/selftests/nolibc/nolibc-test-linkage.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ void *linkage_test_errno_addr(void)
1111
return &errno;
1212
}
1313

14-
int linkage_test_constructor_test_value;
14+
int linkage_test_constructor_test_value = 0;
1515

1616
__attribute__((constructor))
1717
static void constructor1(void)
1818
{
19-
linkage_test_constructor_test_value = 2;
19+
linkage_test_constructor_test_value |= 1 << 0;
2020
}
2121

2222
__attribute__((constructor))
2323
static void constructor2(void)
2424
{
25-
linkage_test_constructor_test_value *= 3;
25+
linkage_test_constructor_test_value |= 1 << 1;
2626
}

tools/testing/selftests/nolibc/nolibc-test.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -692,14 +692,14 @@ int expect_strtox(int llen, void *func, const char *input, int base, intmax_t ex
692692
__attribute__((constructor))
693693
static void constructor1(void)
694694
{
695-
constructor_test_value = 1;
695+
constructor_test_value |= 1 << 0;
696696
}
697697

698698
__attribute__((constructor))
699699
static void constructor2(int argc, char **argv, char **envp)
700700
{
701701
if (argc && argv && envp)
702-
constructor_test_value *= 2;
702+
constructor_test_value |= 1 << 1;
703703
}
704704

705705
int run_startup(int min, int max)
@@ -738,9 +738,9 @@ int run_startup(int min, int max)
738738
CASE_TEST(environ_HOME); EXPECT_PTRNZ(1, getenv("HOME")); break;
739739
CASE_TEST(auxv_addr); EXPECT_PTRGT(test_auxv != (void *)-1, test_auxv, brk); break;
740740
CASE_TEST(auxv_AT_UID); EXPECT_EQ(1, getauxval(AT_UID), getuid()); break;
741-
CASE_TEST(constructor); EXPECT_EQ(is_nolibc, constructor_test_value, 2); break;
741+
CASE_TEST(constructor); EXPECT_EQ(is_nolibc, constructor_test_value, 0x3); break;
742742
CASE_TEST(linkage_errno); EXPECT_PTREQ(1, linkage_test_errno_addr(), &errno); break;
743-
CASE_TEST(linkage_constr); EXPECT_EQ(is_nolibc, linkage_test_constructor_test_value, 6); break;
743+
CASE_TEST(linkage_constr); EXPECT_EQ(1, linkage_test_constructor_test_value, 0x3); break;
744744
case __LINE__:
745745
return ret; /* must be last */
746746
/* note: do not set any defaults so as to permit holes above */

0 commit comments

Comments
 (0)