lib.mk defaults to gcc when CC is not set. When building selftests as part of a kernel compilation, MAKEFLAGS is cleared to allow implicit build rules to be used. This has the side-effect of clearing the CC variable, which will cause selftests to be built with gcc regardless of if we are using gcc or clang. To remedy this, propagate the CC variable when clearing makeflags to ensure the correct compiler is used. Signed-off-by: Andrew Delgadillo <adelg@xxxxxxxxxx> --- tools/testing/selftests/Makefile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile index d9c283503159..a4dd6d7e8276 100644 --- a/tools/testing/selftests/Makefile +++ b/tools/testing/selftests/Makefile @@ -90,10 +90,12 @@ FORCE_TARGETS ?= # Clear LDFLAGS and MAKEFLAGS when implicit rules are missing. This provides # implicit rules to sub-test Makefiles which avoids build failures in test -# Makefile that don't have explicit build rules. +# Makefile that don't have explicit build rules. Since lib.mk defaults to +# using gcc for compilation when the CC variable is not set, we propagate the +# CC variable so if clang is being used, selftests will build with clang. ifeq (,$(LINK.c)) override LDFLAGS = -override MAKEFLAGS = +override MAKEFLAGS = CC=$(CC) endif # Append kselftest to KBUILD_OUTPUT and O to avoid cluttering -- 2.29.2.576.ga3fc446d84-goog