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

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: 795285ef2425 ("selftests: Fix clang cross compilation")
Reviewed-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Valentin Obst <kernel@valentinobst.de>
Reviewed-by: John Hubbard <jhubbard@nvidia.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

authored by

Valentin Obst and committed by
Shuah Khan
d4e6fbd2 d8171aa4

+10 -2
+10 -2
tools/testing/selftests/lib.mk
··· 7 7 LLVM_SUFFIX := $(LLVM) 8 8 endif 9 9 10 + CLANG := $(LLVM_PREFIX)clang$(LLVM_SUFFIX) 11 + 10 12 CLANG_TARGET_FLAGS_arm := arm-linux-gnueabi 11 13 CLANG_TARGET_FLAGS_arm64 := aarch64-linux-gnu 12 14 CLANG_TARGET_FLAGS_hexagon := hexagon-linux-musl ··· 20 18 CLANG_TARGET_FLAGS_s390 := s390x-linux-gnu 21 19 CLANG_TARGET_FLAGS_x86 := x86_64-linux-gnu 22 20 CLANG_TARGET_FLAGS_x86_64 := x86_64-linux-gnu 23 - CLANG_TARGET_FLAGS := $(CLANG_TARGET_FLAGS_$(ARCH)) 21 + 22 + # Default to host architecture if ARCH is not explicitly given. 23 + ifeq ($(ARCH),) 24 + CLANG_TARGET_FLAGS := $(shell $(CLANG) -print-target-triple) 25 + else 26 + CLANG_TARGET_FLAGS := $(CLANG_TARGET_FLAGS_$(ARCH)) 27 + endif 24 28 25 29 ifeq ($(CROSS_COMPILE),) 26 30 ifeq ($(CLANG_TARGET_FLAGS),) ··· 38 30 CLANG_FLAGS += --target=$(notdir $(CROSS_COMPILE:%-=%)) 39 31 endif # CROSS_COMPILE 40 32 41 - CC := $(LLVM_PREFIX)clang$(LLVM_SUFFIX) $(CLANG_FLAGS) -fintegrated-as 33 + CC := $(CLANG) $(CLANG_FLAGS) -fintegrated-as 42 34 else 43 35 CC := $(CROSS_COMPILE)gcc 44 36 endif # LLVM