On Thu, Dec 3, 2020 at 2:10 PM Andrew Delgadillo <ad...@google.com> wrote:
>
> 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 <ad...@google.com>

Hi Andrew, thanks for the patch. Can you walk me through how to build
the selftests?

Documentation/dev-tools/kselftest.rst says:
$ make -C tools/testing/selftests

And if I do:
$ make CC=clang defconfig
$ make CC=clang -C tools/testing/selftests -j

I observe a spew of errors.  If I apply your patch and rerun the
above, I see what looks like the same spew of errors.  Am I "holding
it wrong" or could the docs use a refresh?

> ---
>  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
>


-- 
Thanks,
~Nick Desaulniers

Reply via email to