From mboxrd@z Thu Jan 1 00:00:00 1970 From: Will Deacon Subject: [PATCH v2 01/10] compiler/gcc: Emit build-time warning for GCC prior to version 4.8 Date: Thu, 23 Jan 2020 15:33:32 +0000 Message-ID: <20200123153341.19947-2-will@kernel.org> References: <20200123153341.19947-1-will@kernel.org> Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Return-path: In-Reply-To: <20200123153341.19947-1-will@kernel.org> Sender: linux-kernel-owner@vger.kernel.org To: linux-kernel@vger.kernel.org Cc: linux-arch@vger.kernel.org, kernel-team@android.com, Will Deacon , Michael Ellerman , Peter Zijlstra , Linus Torvalds , Segher Boessenkool , Christian Borntraeger , Luc Van Oostenryck , Arnd Bergmann , Peter Oberparleiter , Masahiro Yamada , Nick Desaulniers List-Id: linux-arch.vger.kernel.org Prior to version 4.8, GCC may miscompile READ_ONCE() by erroneously discarding the 'volatile' qualifier: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58145 We've been working around this using some nasty hacks which make READ_ONCE() both horribly complicated and also prevent us from enforcing that it is only used on scalar types. Since GCC 4.8 is pretty old for kernel builds now, emit a warning if we detect it during the build. Suggested-by: Linus Torvalds Cc: Peter Zijlstra Cc: Michael Ellerman Cc: Arnd Bergmann Cc: Christian Borntraeger Cc: Masahiro Yamada Signed-off-by: Will Deacon --- init/Kconfig | 4 ++-- scripts/Kconfig.include | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/init/Kconfig b/init/Kconfig index a34064a031a5..bdc2f1b1667b 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -10,11 +10,11 @@ config DEFCONFIG_LIST default "arch/$(ARCH)/defconfig" config CC_IS_GCC - def_bool $(success,$(CC) --version | head -n 1 | grep -q gcc) + def_bool $(cc-is-gcc) config GCC_VERSION int - default $(shell,$(srctree)/scripts/gcc-version.sh $(CC)) if CC_IS_GCC + default $(gcc-version) if CC_IS_GCC default 0 config CC_IS_CLANG diff --git a/scripts/Kconfig.include b/scripts/Kconfig.include index d4adfbe42690..4e645a798b56 100644 --- a/scripts/Kconfig.include +++ b/scripts/Kconfig.include @@ -40,3 +40,9 @@ $(error-if,$(success, $(LD) -v | grep -q gold), gold linker '$(LD)' not supporte # gcc version including patch level gcc-version := $(shell,$(srctree)/scripts/gcc-version.sh $(CC)) + +# Return y if the compiler is GCC, n otherwise +cc-is-gcc := $(success,$(CC) --version | head -n 1 | grep -q gcc) + +# Warn if the compiler is GCC prior to 4.8 +$(warning-if,$(if-success,[ $(gcc-version) -lt 40800 ],$(cc-is-gcc),n),"Your compiler is old and may miscompile the kernel due to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58145 - please upgrade it.") -- 2.25.0.341.g760bfbb309-goog From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.kernel.org ([198.145.29.99]:51508 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726232AbgAWPdy (ORCPT ); Thu, 23 Jan 2020 10:33:54 -0500 From: Will Deacon Subject: [PATCH v2 01/10] compiler/gcc: Emit build-time warning for GCC prior to version 4.8 Date: Thu, 23 Jan 2020 15:33:32 +0000 Message-ID: <20200123153341.19947-2-will@kernel.org> In-Reply-To: <20200123153341.19947-1-will@kernel.org> References: <20200123153341.19947-1-will@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-arch-owner@vger.kernel.org List-ID: To: linux-kernel@vger.kernel.org Cc: linux-arch@vger.kernel.org, kernel-team@android.com, Will Deacon , Michael Ellerman , Peter Zijlstra , Linus Torvalds , Segher Boessenkool , Christian Borntraeger , Luc Van Oostenryck , Arnd Bergmann , Peter Oberparleiter , Masahiro Yamada , Nick Desaulniers Message-ID: <20200123153332.O49p6S7tYZEChFXK2KmkvyJ_TsdQdQm49dj6qe8VVmo@z> Prior to version 4.8, GCC may miscompile READ_ONCE() by erroneously discarding the 'volatile' qualifier: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58145 We've been working around this using some nasty hacks which make READ_ONCE() both horribly complicated and also prevent us from enforcing that it is only used on scalar types. Since GCC 4.8 is pretty old for kernel builds now, emit a warning if we detect it during the build. Suggested-by: Linus Torvalds Cc: Peter Zijlstra Cc: Michael Ellerman Cc: Arnd Bergmann Cc: Christian Borntraeger Cc: Masahiro Yamada Signed-off-by: Will Deacon --- init/Kconfig | 4 ++-- scripts/Kconfig.include | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/init/Kconfig b/init/Kconfig index a34064a031a5..bdc2f1b1667b 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -10,11 +10,11 @@ config DEFCONFIG_LIST default "arch/$(ARCH)/defconfig" config CC_IS_GCC - def_bool $(success,$(CC) --version | head -n 1 | grep -q gcc) + def_bool $(cc-is-gcc) config GCC_VERSION int - default $(shell,$(srctree)/scripts/gcc-version.sh $(CC)) if CC_IS_GCC + default $(gcc-version) if CC_IS_GCC default 0 config CC_IS_CLANG diff --git a/scripts/Kconfig.include b/scripts/Kconfig.include index d4adfbe42690..4e645a798b56 100644 --- a/scripts/Kconfig.include +++ b/scripts/Kconfig.include @@ -40,3 +40,9 @@ $(error-if,$(success, $(LD) -v | grep -q gold), gold linker '$(LD)' not supporte # gcc version including patch level gcc-version := $(shell,$(srctree)/scripts/gcc-version.sh $(CC)) + +# Return y if the compiler is GCC, n otherwise +cc-is-gcc := $(success,$(CC) --version | head -n 1 | grep -q gcc) + +# Warn if the compiler is GCC prior to 4.8 +$(warning-if,$(if-success,[ $(gcc-version) -lt 40800 ],$(cc-is-gcc),n),"Your compiler is old and may miscompile the kernel due to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58145 - please upgrade it.") -- 2.25.0.341.g760bfbb309-goog