Skip to content

Commit d4e6fbd

Browse files
Valentin Obstshuahkh
authored andcommitted
selftests: default to host arch for LLVM builds
Align the behavior for gcc and clang builds by interpreting unset `ARCH` and `CROSS_COMPILE` variables in `LLVM` builds as a sign that the user wants to build for the host architecture. This patch preserves the properties that setting the `ARCH` variable to an unknown value will trigger an error that complains about insufficient information, and that a set `CROSS_COMPILE` variable will override the target triple that is determined based on presence/absence of `ARCH`. When compiling with clang, i.e., `LLVM` is set, an unset `ARCH` variable in combination with an unset `CROSS_COMPILE` variable, i.e., compiling for the host architecture, leads to compilation failures since `lib.mk` can not determine the clang target triple. In this case, the following error message is displayed for each subsystem that does not set `ARCH` in its own Makefile before including `lib.mk` (lines wrapped at 75 chrs): make[1]: Entering directory '/mnt/build/linux/tools/testing/selftests/ sysctl' ../lib.mk:33: *** Specify CROSS_COMPILE or add '--target=' option to lib.mk. Stop. make[1]: Leaving directory '/mnt/build/linux/tools/testing/selftests/ sysctl' In the same scenario a gcc build would default to the host architecture, i.e., it would use plain `gcc`. Fixes: 795285e ("selftests: Fix clang cross compilation") Reviewed-by: Mark Brown <[email protected]> Signed-off-by: Valentin Obst <[email protected]> Reviewed-by: John Hubbard <[email protected]> Signed-off-by: Shuah Khan <[email protected]>
1 parent d8171aa commit d4e6fbd

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

tools/testing/selftests/lib.mk

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

10+
CLANG := $(LLVM_PREFIX)clang$(LLVM_SUFFIX)
11+
1012
CLANG_TARGET_FLAGS_arm := arm-linux-gnueabi
1113
CLANG_TARGET_FLAGS_arm64 := aarch64-linux-gnu
1214
CLANG_TARGET_FLAGS_hexagon := hexagon-linux-musl
@@ -18,7 +20,13 @@ CLANG_TARGET_FLAGS_riscv := riscv64-linux-gnu
1820
CLANG_TARGET_FLAGS_s390 := s390x-linux-gnu
1921
CLANG_TARGET_FLAGS_x86 := x86_64-linux-gnu
2022
CLANG_TARGET_FLAGS_x86_64 := x86_64-linux-gnu
21-
CLANG_TARGET_FLAGS := $(CLANG_TARGET_FLAGS_$(ARCH))
23+
24+
# Default to host architecture if ARCH is not explicitly given.
25+
ifeq ($(ARCH),)
26+
CLANG_TARGET_FLAGS := $(shell $(CLANG) -print-target-triple)
27+
else
28+
CLANG_TARGET_FLAGS := $(CLANG_TARGET_FLAGS_$(ARCH))
29+
endif
2230

2331
ifeq ($(CROSS_COMPILE),)
2432
ifeq ($(CLANG_TARGET_FLAGS),)
@@ -30,7 +38,7 @@ else
3038
CLANG_FLAGS += --target=$(notdir $(CROSS_COMPILE:%-=%))
3139
endif # CROSS_COMPILE
3240

33-
CC := $(LLVM_PREFIX)clang$(LLVM_SUFFIX) $(CLANG_FLAGS) -fintegrated-as
41+
CC := $(CLANG) $(CLANG_FLAGS) -fintegrated-as
3442
else
3543
CC := $(CROSS_COMPILE)gcc
3644
endif # LLVM

0 commit comments

Comments
 (0)