[PATCH] selftests/nolibc: only use libgcc when really necessary
From: Thomas Weißschuh
Date: Sat Apr 04 2026 - 08:59:22 EST
nolibc should work without libgcc to be compatible with as many
toolchains as possible. Currently the functionality tested by
nolibc-test does not contain any dependencies, make sure it stays
this way by not linking libgcc anymore.
On the ppc target GCC always emits references to '_restgpr_' functions,
so keep linking libgcc there.
Signed-off-by: Thomas Weißschuh <linux@xxxxxxxxxxxxxx>
---
tools/testing/selftests/nolibc/Makefile.nolibc | 17 ++++-------------
1 file changed, 4 insertions(+), 13 deletions(-)
diff --git a/tools/testing/selftests/nolibc/Makefile.nolibc b/tools/testing/selftests/nolibc/Makefile.nolibc
index 2d32cec1105f..f30bc68470cc 100644
--- a/tools/testing/selftests/nolibc/Makefile.nolibc
+++ b/tools/testing/selftests/nolibc/Makefile.nolibc
@@ -232,23 +232,14 @@ ifeq ($(origin XARCH),command line)
CFLAGS_XARCH = $(CFLAGS_$(XARCH))
endif
+LDLIBS_ppc = $(if $(LLVM),,-lgcc)
+LDLIBS = $(LDLIBS_$(XARCH))
+
include Makefile.include
CFLAGS ?= $(CFLAGS_NOLIBC_TEST) $(CFLAGS_XARCH) $(CFLAGS_EXTRA)
LDFLAGS :=
-LIBGCC := -lgcc
-
-ifeq ($(ARCH),x86)
-# Not needed on x86, probably not present for x32
-LIBGCC :=
-endif
-
-ifneq ($(LLVM),)
-# Not needed for clang
-LIBGCC :=
-endif
-
# Modify CFLAGS based on LLVM=
include $(srctree)/tools/scripts/Makefile.include
@@ -304,7 +295,7 @@ sysroot/$(ARCH)/include:
nolibc-test: $(NOLIBC_TEST_SOURCES) sysroot/$(ARCH)/include
$(QUIET_CC)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ \
- -nostdlib -nostdinc -static -Isysroot/$(ARCH)/include $(NOLIBC_TEST_SOURCES) $(LIBGCC)
+ -nostdlib -nostdinc -static -Isysroot/$(ARCH)/include $(NOLIBC_TEST_SOURCES) $(LDLIBS)
libc-test: $(NOLIBC_TEST_SOURCES)
$(QUIET_CC)$(HOSTCC) -o $@ $(NOLIBC_TEST_SOURCES)
---
base-commit: 4b31f409c33f6661a72f52b90b6a61c9bd7034ad
change-id: 20260404-nolibc-libgcc-eb5bc6bc5ff5
Best regards,
--
Thomas Weißschuh <linux@xxxxxxxxxxxxxx>