UPSTREAM: kbuild: warn if a different compiler is used for external module builds
It is always safe to use the same compiler for the kernel and external modules, but in reality, some distributions such as Fedora release a different version of GCC from the one used for building the kernel. There was a long discussion about mixing different compilers [1]. I do not repeat it here, but at least, showing a heads up in that case is better than nothing. Linus suggested [2]: And a warning might be more palatable even if different compiler version work fine together. Just a heads up on "it looks like you might be mixing compiler versions" is a valid note, and isn't necessarily wrong. Even when they work well together, maybe you want to have people at least _aware_ of it. This commit shows a warning unless the compiler is exactly the same. warning: the compiler differs from the one used to build the kernel The kernel was built by: gcc (GCC) 11.1.1 20210531 (Red Hat 11.1.1-3) You are using: gcc (GCC) 11.2.1 20210728 (Red Hat 11.2.1-1) Check the difference, and if it is OK with you, please proceed at your risk. To avoid the locale issue as in commit bcbcf50f5218 ("kbuild: fix ld-version.sh to not be affected by locale"), pass LC_ALL=C to "$(CC) --version". [1] https://lore.kernel.org/linux-hardening/efe6b039a544da8215d5e54aa7c4b6d1986fc2b0.1611607264.git.jpoimboe@redhat.com/ [2] https://lore.kernel.org/lkml/CAHk-=wgjwhDy-y4mQh34L+2aF=n6BjzHdqAW2=8wri5x7O04pA@mail.gmail.com/ Acked-by: Josh Poimboeuf <jpoimboe@redhat.com> Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> (cherry picked from commit 6072b2c49d23eb69b6dca06ad095d3a9633b2b80) Bug: 209655537 Signed-off-by: Nick Desaulniers <ndesaulniers@google.com> Change-Id: Ibbeeca6c7139f1d03621a8ba2137bafa32c14474
This commit is contained in:
parent
d52d26e4db
commit
a419239633
14
Makefile
14
Makefile
@ -596,7 +596,7 @@ endif
|
||||
# Some architectures define CROSS_COMPILE in arch/$(SRCARCH)/Makefile.
|
||||
# CC_VERSION_TEXT is referenced from Kconfig (so it needs export),
|
||||
# and from include/config/auto.conf.cmd to detect the compiler upgrade.
|
||||
CC_VERSION_TEXT = $(subst $(pound),,$(shell $(CC) --version 2>/dev/null | head -n 1))
|
||||
CC_VERSION_TEXT = $(subst $(pound),,$(shell LC_ALL=C $(CC) --version 2>/dev/null | head -n 1))
|
||||
|
||||
ifneq ($(findstring clang,$(CC_VERSION_TEXT)),)
|
||||
ifneq ($(CROSS_COMPILE),)
|
||||
@ -1853,6 +1853,16 @@ clean-dirs := $(KBUILD_EXTMOD)
|
||||
clean: rm-files := $(KBUILD_EXTMOD)/Module.symvers $(KBUILD_EXTMOD)/modules.nsdeps \
|
||||
$(KBUILD_EXTMOD)/compile_commands.json $(KBUILD_EXTMOD)/.thinlto-cache
|
||||
|
||||
PHONY += prepare
|
||||
# now expand this into a simple variable to reduce the cost of shell evaluations
|
||||
prepare: CC_VERSION_TEXT := $(CC_VERSION_TEXT)
|
||||
prepare:
|
||||
@if [ "$(CC_VERSION_TEXT)" != $(CONFIG_CC_VERSION_TEXT) ]; then \
|
||||
echo >&2 "warning: the compiler differs from the one used to build the kernel"; \
|
||||
echo >&2 " The kernel was built by: "$(CONFIG_CC_VERSION_TEXT); \
|
||||
echo >&2 " You are using: $(CC_VERSION_TEXT)"; \
|
||||
fi
|
||||
|
||||
PHONY += help
|
||||
help:
|
||||
@echo ' Building external modules.'
|
||||
@ -1866,7 +1876,7 @@ help:
|
||||
@echo ''
|
||||
|
||||
# no-op for external module builds
|
||||
PHONY += prepare modules_prepare
|
||||
PHONY += modules_prepare
|
||||
|
||||
endif # KBUILD_EXTMOD
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user