linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Josh Poimboeuf <jpoimboe@redhat.com>
To: Masahiro Yamada <masahiroy@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
	Michal Marek <michal.lkml@markovi.net>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Kees Cook <keescook@chromium.org>,
	linux-hardening@vger.kernel.org,
	Linux Kbuild mailing list <linux-kbuild@vger.kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Justin Forbes <jforbes@redhat.com>,
	Ondrej Mosnacek <omosnace@redhat.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Christoph Hellwig <hch@infradead.org>,
	Miroslav Benes <mbenes@suse.cz>,
	David Laight <David.Laight@aculab.com>,
	Jessica Yu <jeyu@kernel.org>
Subject: Re: [PATCH RFC] kbuild: Prevent compiler mismatch with external modules
Date: Mon, 1 Feb 2021 15:13:22 -0600	[thread overview]
Message-ID: <20210201211322.t2rxmvnrystc2ky7@treble> (raw)
In-Reply-To: <CAK7LNARE3KO-kqdsXAbt9d9+3EqqutYd6iNki_rU2-Q9GkakbA@mail.gmail.com>

On Fri, Jan 29, 2021 at 08:17:51AM +0900, Masahiro Yamada wrote:
> [3]
> Peterz already pointed out asm-goto as an example of ABI mismatch.
> 
> I remember a trouble reported in the past due
> to the mismatch of -mstack-protector-guard-offset.
> 
> https://bugzilla.kernel.org/show_bug.cgi?id=201891
> 
> This has already been fixed,
> and it will no longer happen though.

This is kind of concerning though.  It would be nice to somehow store
KCLAGS in the config and warn if it changes unexpectedly.

This can be a problem not only for OOT modules, but for regular kernel
builds which have a .config copied from somewhere.

Because of the toolchain-dependent kconfig options, features can
silently disappear if the toolchain doesn't support them, due to a
different compiler version, or even a missing library.

> [2]
> 
> As for this patch, it is wrong to do this check in the Makefile
> parse stage.
> 
> "make M=...  clean"
> "make M=...  help"
> 
> etc. will fail.
> Such targets do not require the compiler in the first place.
> 
> This check must be done before starting building something,
>
> Also, this patch is not applicable.
> gcc-version.sh and clang-version.sh do not exist.
> See linux-next.

Something like so?

diff --git a/Makefile b/Makefile
index 95ab9856f357..10ca621369fb 100644
--- a/Makefile
+++ b/Makefile
@@ -1721,12 +1721,25 @@ KBUILD_MODULES := 1
 
 build-dirs := $(KBUILD_EXTMOD)
 PHONY += modules
-modules: $(MODORDER)
+modules: ext_compiler_check $(MODORDER)
 	$(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
 
 $(MODORDER): descend
 	@:
 
+orig_name   := $(if $(CONFIG_CC_IS_GCC),GCC,CLANG)
+orig_minor  := $(shell expr $(if $(CONFIG_CC_IS_GCC),$(CONFIG_GCC_VERSION),$(CONFIG_CLANG_VERSION)) / 100)
+cur_namever := $(shell $(srctree)/scripts/cc-version.sh $(CC))
+cur_name    := $(word 1,$(cur_namever))
+cur_minor   := $(shell expr $(word 2,$(cur_namever)) / 100)
+PHONY += ext_compiler_check
+ext_compiler_check:
+	@if [ $(orig_name) != $(cur_name) ] || [ $(orig_minor) != $(cur_minor) ]; then \
+		echo >&2 "warning: The compiler differs from the version which was used to build the kernel."; \
+		echo >&2 "warning: Some kernel features are compiler-dependent."; \
+		echo >&2 "warning: It's recommended that you change your compiler to match the version in the .config file."; \
+	fi
+
 PHONY += modules_install
 modules_install: _emodinst_ _emodinst_post
 


  reply	other threads:[~2021-02-01 21:15 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-28 20:08 [PATCH RFC] kbuild: Prevent compiler mismatch with external modules Josh Poimboeuf
2021-01-28 20:24 ` Linus Torvalds
2021-01-28 20:52   ` Josh Poimboeuf
2021-01-28 21:03     ` Linus Torvalds
2021-01-28 21:23       ` Linus Torvalds
2021-01-28 21:34         ` Josh Poimboeuf
2021-01-28 21:45           ` Linus Torvalds
2021-01-28 22:08             ` Josh Poimboeuf
2021-01-28 23:17               ` Masahiro Yamada
2021-02-01 21:13                 ` Josh Poimboeuf [this message]
2021-03-05 16:28                   ` Masahiro Yamada
2021-03-05 19:24                     ` Josh Poimboeuf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210201211322.t2rxmvnrystc2ky7@treble \
    --to=jpoimboe@redhat.com \
    --cc=David.Laight@aculab.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hch@infradead.org \
    --cc=jeyu@kernel.org \
    --cc=jforbes@redhat.com \
    --cc=keescook@chromium.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=masahiroy@kernel.org \
    --cc=mbenes@suse.cz \
    --cc=michal.lkml@markovi.net \
    --cc=omosnace@redhat.com \
    --cc=peterz@infradead.org \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).