public inbox for [email protected]
 help / color / mirror / Atom feed
From: "Paul E. McKenney" <[email protected]>
To: [email protected]
Cc: [email protected], [email protected], [email protected],
	"Thomas Weißschuh" <[email protected]>,
	"Willy Tarreau" <[email protected]>
Subject: [PATCH nolibc 19/19] selftests/nolibc: add tests for multi-object linkage
Date: Thu, 12 Oct 2023 12:32:33 -0700	[thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <b34ce3cf-3fcc-4eb0-a658-229c197455ef@paulmck-laptop>

From: Thomas Weißschuh <[email protected]>

While uncommon, nolibc executables can be linked together from multiple
compilation units.
Add some tests to make sure everything works in that case.

Signed-off-by: Thomas Weißschuh <[email protected]>
Link: https://lore.kernel.org/lkml/[email protected]/
Acked-by: Willy Tarreau <[email protected]>
---
 tools/testing/selftests/nolibc/Makefile       | 12 ++++-----
 .../selftests/nolibc/nolibc-test-linkage.c    | 26 +++++++++++++++++++
 .../selftests/nolibc/nolibc-test-linkage.h    |  9 +++++++
 tools/testing/selftests/nolibc/nolibc-test.c  |  4 +++
 4 files changed, 45 insertions(+), 6 deletions(-)
 create mode 100644 tools/testing/selftests/nolibc/nolibc-test-linkage.c
 create mode 100644 tools/testing/selftests/nolibc/nolibc-test-linkage.h

diff --git a/tools/testing/selftests/nolibc/Makefile b/tools/testing/selftests/nolibc/Makefile
index af60e07d3c12..a0fc07253baf 100644
--- a/tools/testing/selftests/nolibc/Makefile
+++ b/tools/testing/selftests/nolibc/Makefile
@@ -171,17 +171,17 @@ sysroot/$(ARCH)/include:
 	$(Q)mv sysroot/sysroot sysroot/$(ARCH)
 
 ifneq ($(NOLIBC_SYSROOT),0)
-nolibc-test: nolibc-test.c sysroot/$(ARCH)/include
+nolibc-test: nolibc-test.c nolibc-test-linkage.c sysroot/$(ARCH)/include
 	$(QUIET_CC)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ \
-	  -nostdlib -nostdinc -static -Isysroot/$(ARCH)/include $< -lgcc
+	  -nostdlib -nostdinc -static -Isysroot/$(ARCH)/include nolibc-test.c nolibc-test-linkage.c -lgcc
 else
-nolibc-test: nolibc-test.c
+nolibc-test: nolibc-test.c nolibc-test-linkage.c
 	$(QUIET_CC)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ \
-	  -nostdlib -static -include ../../../include/nolibc/nolibc.h $< -lgcc
+	  -nostdlib -static -include ../../../include/nolibc/nolibc.h nolibc-test.c nolibc-test-linkage.c -lgcc
 endif
 
-libc-test: nolibc-test.c
-	$(QUIET_CC)$(HOSTCC) -o $@ $<
+libc-test: nolibc-test.c nolibc-test-linkage.c
+	$(QUIET_CC)$(HOSTCC) -o $@ nolibc-test.c nolibc-test-linkage.c
 
 # local libc-test
 run-libc-test: libc-test
diff --git a/tools/testing/selftests/nolibc/nolibc-test-linkage.c b/tools/testing/selftests/nolibc/nolibc-test-linkage.c
new file mode 100644
index 000000000000..5ff4c8a1db2a
--- /dev/null
+++ b/tools/testing/selftests/nolibc/nolibc-test-linkage.c
@@ -0,0 +1,26 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#include "nolibc-test-linkage.h"
+
+#ifndef NOLIBC
+#include <errno.h>
+#endif
+
+void *linkage_test_errno_addr(void)
+{
+	return &errno;
+}
+
+int linkage_test_constructor_test_value;
+
+__attribute__((constructor))
+static void constructor1(void)
+{
+	linkage_test_constructor_test_value = 2;
+}
+
+__attribute__((constructor))
+static void constructor2(void)
+{
+	linkage_test_constructor_test_value *= 3;
+}
diff --git a/tools/testing/selftests/nolibc/nolibc-test-linkage.h b/tools/testing/selftests/nolibc/nolibc-test-linkage.h
new file mode 100644
index 000000000000..c66473070d73
--- /dev/null
+++ b/tools/testing/selftests/nolibc/nolibc-test-linkage.h
@@ -0,0 +1,9 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifndef _NOLIBC_TEST_LINKAGE_H
+#define _NOLIBC_TEST_LINKAGE_H
+
+void *linkage_test_errno_addr(void);
+extern int linkage_test_constructor_test_value;
+
+#endif /* _NOLIBC_TEST_LINKAGE_H */
diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c
index 8da7f15d010e..2f10541e6f38 100644
--- a/tools/testing/selftests/nolibc/nolibc-test.c
+++ b/tools/testing/selftests/nolibc/nolibc-test.c
@@ -41,6 +41,8 @@
 #endif
 #endif
 
+#include "nolibc-test-linkage.h"
+
 /* for the type of int_fast16_t and int_fast32_t, musl differs from glibc and nolibc */
 #define SINT_MAX_OF_TYPE(type) (((type)1 << (sizeof(type) * 8 - 2)) - (type)1 + ((type)1 << (sizeof(type) * 8 - 2)))
 #define SINT_MIN_OF_TYPE(type) (-SINT_MAX_OF_TYPE(type) - 1)
@@ -647,6 +649,8 @@ int run_startup(int min, int max)
 		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(1, constructor_test_value, 2); break;
+		CASE_TEST(linkage_errno);    EXPECT_PTREQ(1, linkage_test_errno_addr(), &errno); break;
+		CASE_TEST(linkage_constr);   EXPECT_EQ(1, linkage_test_constructor_test_value, 6); break;
 		case __LINE__:
 			return ret; /* must be last */
 		/* note: do not set any defaults so as to permit holes above */
-- 
2.40.1


      parent reply	other threads:[~2023-10-12 19:32 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-12 19:32 [PATCH nolibc 0/19] Updates to nolibc for v6.7 (and three for v6.6) Paul E. McKenney
2023-10-12 19:32 ` [PATCH nolibc 01/19] tools/nolibc: i386: Fix a stack misalign bug on _start Paul E. McKenney
2023-10-12 19:32 ` [PATCH nolibc 02/19] MAINTAINERS: nolibc: update tree location Paul E. McKenney
2023-10-12 19:32 ` [PATCH nolibc 03/19] tools/nolibc: mark start_c as weak Paul E. McKenney
2023-10-12 19:32 ` [PATCH nolibc 04/19] tools/nolibc: add stdarg.h header Paul E. McKenney
2023-10-12 19:32 ` [PATCH nolibc 05/19] selftests/nolibc: use -nostdinc for nolibc-test Paul E. McKenney
2023-10-12 19:32 ` [PATCH nolibc 06/19] tools/nolibc: x86-64: Use `rep movsb` for `memcpy()` and `memmove()` Paul E. McKenney
2023-10-12 19:32 ` [PATCH nolibc 07/19] tools/nolibc: x86-64: Use `rep stosb` for `memset()` Paul E. McKenney
2023-10-12 19:32 ` [PATCH nolibc 08/19] tools/nolibc: string: Remove the `_nolibc_memcpy_down()` function Paul E. McKenney
2023-10-12 19:32 ` [PATCH nolibc 09/19] tools/nolibc: string: Remove the `_nolibc_memcpy_up()` function Paul E. McKenney
2023-10-12 19:32 ` [PATCH nolibc 10/19] selftests/nolibc: libc-test: avoid -Wstringop-overflow warnings Paul E. McKenney
2023-10-12 19:32 ` [PATCH nolibc 11/19] selftests/nolibc: don't embed initramfs into kernel image Paul E. McKenney
2023-10-12 19:32 ` [PATCH nolibc 12/19] selftests/nolibc: allow building i386 with multiarch compiler Paul E. McKenney
2023-10-12 19:32 ` [PATCH nolibc 13/19] tools/nolibc: avoid unused parameter warnings for ENOSYS fallbacks Paul E. McKenney
2023-10-12 19:32 ` [PATCH nolibc 14/19] tools/nolibc: don't define new syscall number Paul E. McKenney
2023-10-12 19:32 ` [PATCH nolibc 15/19] tools/nolibc: automatically detect necessity to use pselect6 Paul E. McKenney
2023-10-12 19:32 ` [PATCH nolibc 16/19] tools/nolibc: drop test for getauxval(AT_PAGESZ) Paul E. McKenney
2023-10-12 19:32 ` [PATCH nolibc 17/19] tools/nolibc: add support for constructors and destructors Paul E. McKenney
2023-10-12 19:32 ` [PATCH nolibc 18/19] selftests/nolibc: use qemu-system-ppc64 for ppc64le Paul E. McKenney
2023-10-12 19:32 ` Paul E. McKenney [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox