selftests/nolibc: only use libgcc when really necessary

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@weissschuh.net>
Acked-by: Willy Tarreau <w@1wt.eu>
Link: https://patch.msgid.link/20260404-nolibc-libgcc-v1-1-eb3ecfe0e176@weissschuh.net
This commit is contained in:
Thomas Weißschuh 2026-04-04 14:59:03 +02:00
parent e70a7bb575
commit 08b96aa962

View File

@ -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)