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 <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>
pull/1183/head
Thomas Weißschuh 2025-03-06 22:52:39 +01:00
parent 6e406202a4
commit a782d45c86
2 changed files with 7 additions and 7 deletions

View File

@ -11,16 +11,16 @@ void *linkage_test_errno_addr(void)
return &errno; return &errno;
} }
int linkage_test_constructor_test_value; int linkage_test_constructor_test_value = 0;
__attribute__((constructor)) __attribute__((constructor))
static void constructor1(void) static void constructor1(void)
{ {
linkage_test_constructor_test_value = 2; linkage_test_constructor_test_value |= 1 << 0;
} }
__attribute__((constructor)) __attribute__((constructor))
static void constructor2(void) static void constructor2(void)
{ {
linkage_test_constructor_test_value *= 3; linkage_test_constructor_test_value |= 1 << 1;
} }

View File

@ -692,14 +692,14 @@ int expect_strtox(int llen, void *func, const char *input, int base, intmax_t ex
__attribute__((constructor)) __attribute__((constructor))
static void constructor1(void) static void constructor1(void)
{ {
constructor_test_value = 1; constructor_test_value |= 1 << 0;
} }
__attribute__((constructor)) __attribute__((constructor))
static void constructor2(int argc, char **argv, char **envp) static void constructor2(int argc, char **argv, char **envp)
{ {
if (argc && argv && envp) if (argc && argv && envp)
constructor_test_value *= 2; constructor_test_value |= 1 << 1;
} }
int run_startup(int min, int max) 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(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_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(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_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__: case __LINE__:
return ret; /* must be last */ return ret; /* must be last */
/* note: do not set any defaults so as to permit holes above */ /* note: do not set any defaults so as to permit holes above */