Skip to content

Commit 795285e

Browse files
broonieshuahkh
authored andcommitted
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 <[email protected]> Signed-off-by: Shuah Khan <[email protected]>
1 parent f2906aa commit 795285e

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

tools/testing/selftests/lib.mk

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,31 @@ else ifneq ($(filter -%,$(LLVM)),)
77
LLVM_SUFFIX := $(LLVM)
88
endif
99

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
1132
else
1233
CC := $(CROSS_COMPILE)gcc
13-
endif
34+
endif # LLVM
1435

1536
ifeq (0,$(MAKELEVEL))
1637
ifeq ($(OUTPUT),)

0 commit comments

Comments
 (0)