Commit a782d45c authored by Thomas Weißschuh's avatar Thomas Weißschuh
Browse files

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: default avatarWilly 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: default avatarWilly Tarreau <w@1wt.eu>
Signed-off-by: default avatarThomas Weißschuh <linux@weissschuh.net>
parent 6e406202
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -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;
}
+4 −4
Original line number Diff line number Diff line
@@ -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 */