[PATCH v2 1/4] tools/nolibc: derive clang target flags from ARCH if CROSS_COMPILE is not set
From: Thomas Weißschuh
Date: Wed Dec 02 2026 - 02:30:14 EST
The clang --target= flags are important to make sure that the UAPI
headers match the clang's architecture. If they don't match the
header test compilation may fail spuriously.
Currently the --target= flags are only derived from the CROSS_COMPILE
variable. This variable may not be set for native builds or for native
LLVM builds. Currently this works by chance.
Fall back to ARCH to determine the --target= flags if CROSS_COMPILE
was not set. ARCH is always set.
Signed-off-by: Thomas Weißschuh <linux@xxxxxxxxxxxxxx>
---
tools/include/nolibc/Makefile | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/tools/include/nolibc/Makefile b/tools/include/nolibc/Makefile
index 0880be0f6ef5..20160f3f9547 100644
--- a/tools/include/nolibc/Makefile
+++ b/tools/include/nolibc/Makefile
@@ -122,6 +122,14 @@ headers_standalone: headers
CFLAGS_s390 := -m64
CFLAGS := $(CFLAGS_$(ARCH))
+ifneq ($(LLVM),)
+ifeq ($(CLANG_CROSS_FLAGS),)
+SRCARCH := $(ARCH)
+include $(srctree)/scripts/Makefile.clang
+CLANG_CROSS_FLAGS := --target=$(CLANG_TARGET_FLAGS)
+endif
+endif
+
headers_check: headers_standalone
$(Q)for header in $(filter-out crt.h std.h,$(all_files)); do \
$(CC) $(CFLAGS) $(CLANG_CROSS_FLAGS) -Wall -Werror -nostdinc -fsyntax-only -x c /dev/null \
--
2.56.1