Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests: Fix clang cross compilation

Unlike GCC clang uses a single compiler image to support multiple target
architectures meaning that we can't simply rely on CROSS_COMPILE to select
the output architecture. Instead we must pass --target to the compiler to
tell it what to output, kselftest was not doing this so cross compilation
of kselftest using clang resulted in kselftest being built for the host
architecture.

More work is required to fix tests using custom rules but this gets the
bulk of things building.

Signed-off-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

authored by

Mark Brown and committed by
Shuah Khan
795285ef f2906aa8

+23 -2
+23 -2
tools/testing/selftests/lib.mk
··· 7 7 LLVM_SUFFIX := $(LLVM) 8 8 endif 9 9 10 - CC := $(LLVM_PREFIX)clang$(LLVM_SUFFIX) 10 + CLANG_TARGET_FLAGS_arm := arm-linux-gnueabi 11 + CLANG_TARGET_FLAGS_arm64 := aarch64-linux-gnu 12 + CLANG_TARGET_FLAGS_hexagon := hexagon-linux-musl 13 + CLANG_TARGET_FLAGS_m68k := m68k-linux-gnu 14 + CLANG_TARGET_FLAGS_mips := mipsel-linux-gnu 15 + CLANG_TARGET_FLAGS_powerpc := powerpc64le-linux-gnu 16 + CLANG_TARGET_FLAGS_riscv := riscv64-linux-gnu 17 + CLANG_TARGET_FLAGS_s390 := s390x-linux-gnu 18 + CLANG_TARGET_FLAGS_x86 := x86_64-linux-gnu 19 + CLANG_TARGET_FLAGS := $(CLANG_TARGET_FLAGS_$(ARCH)) 20 + 21 + ifeq ($(CROSS_COMPILE),) 22 + ifeq ($(CLANG_TARGET_FLAGS),) 23 + $(error Specify CROSS_COMPILE or add '--target=' option to lib.mk 24 + else 25 + CLANG_FLAGS += --target=$(CLANG_TARGET_FLAGS) 26 + endif # CLANG_TARGET_FLAGS 27 + else 28 + CLANG_FLAGS += --target=$(notdir $(CROSS_COMPILE:%-=%)) 29 + endif # CROSS_COMPILE 30 + 31 + CC := $(LLVM_PREFIX)clang$(LLVM_SUFFIX) $(CLANG_FLAGS) -fintegrated-as 11 32 else 12 33 CC := $(CROSS_COMPILE)gcc 13 - endif 34 + endif # LLVM 14 35 15 36 ifeq (0,$(MAKELEVEL)) 16 37 ifeq ($(OUTPUT),)