[PATCH v2 0/7] set clang minimum version to 10.0.1

9 views
Skip to first unread message

Nick Desaulniers

unread,
Aug 31, 2020, 8:18:30 PM8/31/20
to Andrew Morton, Kees Cook, Miguel Ojeda, Nathan Chancellor, Sedat Dilek, Marco Elver, Andrey Konovalov, Masahiro Yamada, clang-bu...@googlegroups.com, Daniel Borkmann, Alexei Starovoitov, Will Deacon, Vincenzo Frascino, Nick Desaulniers
Adds a compile time #error to compiler-clang.h setting the effective
minimum supported version to clang 10.0.1. A separate patch has already
been picked up into the Documentation/ tree also confirming the version.

Next are a series of reverts. One for 32b arm is a partial revert.

Then Marco suggested fixes to KASAN docs.

Finally, improve the warning for GCC too as per Kees.

Patches after 001 are new for v2.

Marco Elver (1):
kasan: Remove mentions of unsupported Clang versions

Nick Desaulniers (6):
compiler-clang: add build check for clang 10.0.1
Revert "kbuild: disable clang's default use of -fmerge-all-constants"
Revert "arm64: bti: Require clang >= 10.0.1 for in-kernel BTI support"
Revert "arm64: vdso: Fix compilation with clang older than 8"
Partial revert "ARM: 8905/1: Emit __gnu_mcount_nc when using Clang
10.0.0 or newer"
compiler-gcc: improve version warning

Documentation/dev-tools/kasan.rst | 4 ++--
Makefile | 9 ---------
arch/arm/Kconfig | 2 +-
arch/arm64/Kconfig | 2 --
arch/arm64/kernel/vdso/Makefile | 7 -------
include/linux/compiler-clang.h | 8 ++++++++
include/linux/compiler-gcc.h | 2 +-
lib/Kconfig.kasan | 9 ++++-----
8 files changed, 16 insertions(+), 27 deletions(-)

--
2.28.0.402.g5ffc5be6b7-goog

Nick Desaulniers

unread,
Aug 31, 2020, 8:18:36 PM8/31/20
to Andrew Morton, Kees Cook, Miguel Ojeda, Nathan Chancellor, Sedat Dilek, Marco Elver, Andrey Konovalov, Masahiro Yamada, clang-bu...@googlegroups.com, Daniel Borkmann, Alexei Starovoitov, Will Deacon, Vincenzo Frascino, Nick Desaulniers
During Plumbers 2020, we voted to just support the latest release of
Clang for now. Add a compile time check for this.

We plan to remove workarounds for older versions now, which will break
in subtle and not so subtle ways.

Link: https://github.com/ClangBuiltLinux/linux/issues/9
Link: https://github.com/ClangBuiltLinux/linux/issues/941
Suggested-by: Sedat Dilek <sedat...@gmail.com>
Suggested-by: Nathan Chancellor <natecha...@gmail.com>
Suggested-by: Kees Cook <kees...@chromium.org>
Acked-by: Marco Elver <el...@google.com>
Acked-by: Nathan Chancellor <natecha...@gmail.com>
Acked-by: Sedat Dilek <sedat...@gmail.com>
Reviewed-by: Kees Cook <kees...@chromium.org>
Reviewed-by: Miguel Ojeda <miguel.oje...@gmail.com>
Signed-off-by: Nick Desaulniers <ndesau...@google.com>
---
Changes V1 -> V2:
* use a more informational error, as per Kees.
* collect tags.

include/linux/compiler-clang.h | 8 ++++++++
1 file changed, 8 insertions(+)

diff --git a/include/linux/compiler-clang.h b/include/linux/compiler-clang.h
index cee0c728d39a..230604e7f057 100644
--- a/include/linux/compiler-clang.h
+++ b/include/linux/compiler-clang.h
@@ -3,6 +3,14 @@
#error "Please don't include <linux/compiler-clang.h> directly, include <linux/compiler.h> instead."
#endif

+#define CLANG_VERSION (__clang_major__ * 10000 \
+ + __clang_minor__ * 100 \
+ + __clang_patchlevel__)
+
+#if CLANG_VERSION < 100001
+# error Sorry, your version of Clang is too old - please use 10.0.1 or newer.
+#endif
+
/* Compiler specific definitions for Clang compiler */

/* same as gcc, this was present in clang-2.6 so we can assume it works
--
2.28.0.402.g5ffc5be6b7-goog

Nick Desaulniers

unread,
Aug 31, 2020, 8:18:39 PM8/31/20
to Andrew Morton, Kees Cook, Miguel Ojeda, Nathan Chancellor, Sedat Dilek, Marco Elver, Andrey Konovalov, Masahiro Yamada, clang-bu...@googlegroups.com, Daniel Borkmann, Alexei Starovoitov, Will Deacon, Vincenzo Frascino, Nick Desaulniers
This reverts commit 87e0d4f0f37fb0c8c4aeeac46fff5e957738df79.

This was fixed in clang-6; the minimum supported version of clang in the
kernel is clang-10 (10.0.1).

Link: https://reviews.llvm.org/rL329300.
Link: https://github.com/ClangBuiltLinux/linux/issues/9
Suggested-by: Nathan Chancellor <natecha...@gmail.com>
Signed-off-by: Nick Desaulniers <ndesau...@google.com>
---
Makefile | 9 ---------
1 file changed, 9 deletions(-)

diff --git a/Makefile b/Makefile
index 37739ee53f27..144ac6a073ff 100644
--- a/Makefile
+++ b/Makefile
@@ -932,15 +932,6 @@ KBUILD_CFLAGS += $(call cc-disable-warning, maybe-uninitialized)
# disable invalid "can't wrap" optimizations for signed / pointers
KBUILD_CFLAGS += $(call cc-option,-fno-strict-overflow)

-# clang sets -fmerge-all-constants by default as optimization, but this
-# is non-conforming behavior for C and in fact breaks the kernel, so we
-# need to disable it here generally.
-KBUILD_CFLAGS += $(call cc-option,-fno-merge-all-constants)
-
-# for gcc -fno-merge-all-constants disables everything, but it is fine
-# to have actual conforming behavior enabled.
-KBUILD_CFLAGS += $(call cc-option,-fmerge-constants)
-
# Make sure -fstack-check isn't enabled (like gentoo apparently did)
KBUILD_CFLAGS += $(call cc-option,-fno-stack-check,)

--
2.28.0.402.g5ffc5be6b7-goog

Nick Desaulniers

unread,
Aug 31, 2020, 8:18:41 PM8/31/20
to Andrew Morton, Kees Cook, Miguel Ojeda, Nathan Chancellor, Sedat Dilek, Marco Elver, Andrey Konovalov, Masahiro Yamada, clang-bu...@googlegroups.com, Daniel Borkmann, Alexei Starovoitov, Will Deacon, Vincenzo Frascino, Nick Desaulniers
This reverts commit b9249cba25a5dce5de87e5404503a5e11832c2dd.

The minimum supported version of clang is now 10.0.1.

Suggested-by: Nathan Chancellor <natecha...@gmail.com>
Signed-off-by: Nick Desaulniers <ndesau...@google.com>
---
arch/arm64/Kconfig | 2 --
1 file changed, 2 deletions(-)

diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index 6d232837cbee..2a70b85b1a61 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -1630,8 +1630,6 @@ config ARM64_BTI_KERNEL
depends on CC_HAS_BRANCH_PROT_PAC_RET_BTI
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94697
depends on !CC_IS_GCC || GCC_VERSION >= 100100
- # https://reviews.llvm.org/rGb8ae3fdfa579dbf366b1bb1cbfdbf8c51db7fa55
- depends on !CC_IS_CLANG || CLANG_VERSION >= 100001
depends on !(CC_IS_CLANG && GCOV_KERNEL)
depends on (!FUNCTION_GRAPH_TRACER || DYNAMIC_FTRACE_WITH_REGS)
help
--
2.28.0.402.g5ffc5be6b7-goog

Nick Desaulniers

unread,
Aug 31, 2020, 8:18:43 PM8/31/20
to Andrew Morton, Kees Cook, Miguel Ojeda, Nathan Chancellor, Sedat Dilek, Marco Elver, Andrey Konovalov, Masahiro Yamada, clang-bu...@googlegroups.com, Daniel Borkmann, Alexei Starovoitov, Will Deacon, Vincenzo Frascino, Nick Desaulniers
This reverts commit 3acf4be235280f14d838581a750532219d67facc.

The minimum supported version of clang is clang 10.0.1.

Suggested-by: Nathan Chancellor <natecha...@gmail.com>
Signed-off-by: Nick Desaulniers <ndesau...@google.com>
---
arch/arm64/kernel/vdso/Makefile | 7 -------
1 file changed, 7 deletions(-)

diff --git a/arch/arm64/kernel/vdso/Makefile b/arch/arm64/kernel/vdso/Makefile
index 45d5cfe46429..04021a93171c 100644
--- a/arch/arm64/kernel/vdso/Makefile
+++ b/arch/arm64/kernel/vdso/Makefile
@@ -43,13 +43,6 @@ ifneq ($(c-gettimeofday-y),)
CFLAGS_vgettimeofday.o += -include $(c-gettimeofday-y)
endif

-# Clang versions less than 8 do not support -mcmodel=tiny
-ifeq ($(CONFIG_CC_IS_CLANG), y)
- ifeq ($(shell test $(CONFIG_CLANG_VERSION) -lt 80000; echo $$?),0)
- CFLAGS_REMOVE_vgettimeofday.o += -mcmodel=tiny
- endif
-endif
-
# Disable gcov profiling for VDSO code
GCOV_PROFILE := n

--
2.28.0.402.g5ffc5be6b7-goog

Nick Desaulniers

unread,
Aug 31, 2020, 8:18:44 PM8/31/20
to Andrew Morton, Kees Cook, Miguel Ojeda, Nathan Chancellor, Sedat Dilek, Marco Elver, Andrey Konovalov, Masahiro Yamada, clang-bu...@googlegroups.com, Daniel Borkmann, Alexei Starovoitov, Will Deacon, Vincenzo Frascino, Nick Desaulniers
This partially reverts commit b0fe66cf095016e0b238374c10ae366e1f087d11.

The minimum supported version of clang is now clang 10.0.1. We still
want to pass -meabi=gnu.

Suggested-by: Nathan Chancellor <natecha...@gmail.com>
Signed-off-by: Nick Desaulniers <ndesau...@google.com>
---
arch/arm/Kconfig | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 82c197a248dd..09a7669eea1d 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -83,7 +83,7 @@ config ARM
select HAVE_FAST_GUP if ARM_LPAE
select HAVE_FTRACE_MCOUNT_RECORD if !XIP_KERNEL
select HAVE_FUNCTION_GRAPH_TRACER if !THUMB2_KERNEL && !CC_IS_CLANG
- select HAVE_FUNCTION_TRACER if !XIP_KERNEL && (CC_IS_GCC || CLANG_VERSION >= 100000)
+ select HAVE_FUNCTION_TRACER if !XIP_KERNEL
select HAVE_GCC_PLUGINS
select HAVE_HW_BREAKPOINT if PERF_EVENTS && (CPU_V6 || CPU_V6K || CPU_V7)
select HAVE_IDE if PCI || ISA || PCMCIA
--
2.28.0.402.g5ffc5be6b7-goog

Nick Desaulniers

unread,
Aug 31, 2020, 8:18:47 PM8/31/20
to Andrew Morton, Kees Cook, Miguel Ojeda, Nathan Chancellor, Sedat Dilek, Marco Elver, Andrey Konovalov, Masahiro Yamada, clang-bu...@googlegroups.com, Daniel Borkmann, Alexei Starovoitov, Will Deacon, Vincenzo Frascino, Nick Desaulniers
From: Marco Elver <el...@google.com>

Since the kernel now requires at least Clang 10.0.1, remove any mention
of old Clang versions and simplify the documentation.

Reviewed-by: Andrey Konovalov <andre...@google.com>
Signed-off-by: Marco Elver <el...@google.com>
Signed-off-by: Nick Desaulniers <ndesau...@google.com>
---
Documentation/dev-tools/kasan.rst | 4 ++--
lib/Kconfig.kasan | 9 ++++-----
2 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/Documentation/dev-tools/kasan.rst b/Documentation/dev-tools/kasan.rst
index 38fd5681fade..4abc84b1798c 100644
--- a/Documentation/dev-tools/kasan.rst
+++ b/Documentation/dev-tools/kasan.rst
@@ -13,10 +13,10 @@ KASAN uses compile-time instrumentation to insert validity checks before every
memory access, and therefore requires a compiler version that supports that.

Generic KASAN is supported in both GCC and Clang. With GCC it requires version
-8.3.0 or later. With Clang it requires version 7.0.0 or later, but detection of
+8.3.0 or later. Any supported Clang version is compatible, but detection of
out-of-bounds accesses for global variables is only supported since Clang 11.

-Tag-based KASAN is only supported in Clang and requires version 7.0.0 or later.
+Tag-based KASAN is only supported in Clang.

Currently generic KASAN is supported for the x86_64, arm64, xtensa, s390 and
riscv architectures, and tag-based KASAN is supported only for arm64.
diff --git a/lib/Kconfig.kasan b/lib/Kconfig.kasan
index 047b53dbfd58..033a5bc67ac4 100644
--- a/lib/Kconfig.kasan
+++ b/lib/Kconfig.kasan
@@ -54,9 +54,9 @@ config KASAN_GENERIC
Enables generic KASAN mode.

This mode is supported in both GCC and Clang. With GCC it requires
- version 8.3.0 or later. With Clang it requires version 7.0.0 or
- later, but detection of out-of-bounds accesses for global variables
- is supported only since Clang 11.
+ version 8.3.0 or later. Any supported Clang version is compatible,
+ but detection of out-of-bounds accesses for global variables is
+ supported only since Clang 11.

This mode consumes about 1/8th of available memory at kernel start
and introduces an overhead of ~x1.5 for the rest of the allocations.
@@ -78,8 +78,7 @@ config KASAN_SW_TAGS
Enables software tag-based KASAN mode.

This mode requires Top Byte Ignore support by the CPU and therefore
- is only supported for arm64. This mode requires Clang version 7.0.0
- or later.
+ is only supported for arm64. This mode requires Clang.

This mode consumes about 1/16th of available memory at kernel start
and introduces an overhead of ~20% for the rest of the allocations.
--
2.28.0.402.g5ffc5be6b7-goog

Nick Desaulniers

unread,
Aug 31, 2020, 8:18:48 PM8/31/20
to Andrew Morton, Kees Cook, Miguel Ojeda, Nathan Chancellor, Sedat Dilek, Marco Elver, Andrey Konovalov, Masahiro Yamada, clang-bu...@googlegroups.com, Daniel Borkmann, Alexei Starovoitov, Will Deacon, Vincenzo Frascino, Nick Desaulniers
As Kees suggests, do so provides developers with two useful pieces of
information:
- The kernel build was attempting to use GCC.
(Maybe they accidentally poked the wrong configs in a CI.)
- They need 4.9 or better.
("Upgrade to what version?" doesn't need to be dug out of documentation,
headers, etc.)

Suggested-by: Kees Cook <kees...@chromium.org>
Signed-off-by: Nick Desaulniers <ndesau...@google.com>
---
include/linux/compiler-gcc.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h
index 7a3769040d7d..d1e3c6896b71 100644
--- a/include/linux/compiler-gcc.h
+++ b/include/linux/compiler-gcc.h
@@ -12,7 +12,7 @@

/* https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58145 */
#if GCC_VERSION < 40900
-# error Sorry, your compiler is too old - please upgrade it.
+# error Sorry, your version of GCC is too old - please use 4.9 or newer.
#endif

/* Optimization barrier */
--
2.28.0.402.g5ffc5be6b7-goog

Nick Desaulniers

unread,
Aug 31, 2020, 8:22:59 PM8/31/20
to Andrew Morton, Kees Cook, Miguel Ojeda, Nathan Chancellor, Sedat Dilek, Marco Elver, Andrey Konovalov, Masahiro Yamada, clang-built-linux, Daniel Borkmann, Alexei Starovoitov, Will Deacon, Vincenzo Frascino
And I forgot to cc LKML...sorry for the spam, resending the series.
--
Thanks,
~Nick Desaulniers

Nick Desaulniers

unread,
Aug 31, 2020, 8:23:32 PM8/31/20
to Andrew Morton, Kees Cook, Miguel Ojeda, Nathan Chancellor, Sedat Dilek, Marco Elver, Andrey Konovalov, Masahiro Yamada, clang-bu...@googlegroups.com, Daniel Borkmann, Alexei Starovoitov, Will Deacon, Vincenzo Frascino, linux-...@vger.kernel.org, Nick Desaulniers

Nick Desaulniers

unread,
Aug 31, 2020, 8:23:34 PM8/31/20
to Andrew Morton, Kees Cook, Miguel Ojeda, Nathan Chancellor, Sedat Dilek, Marco Elver, Andrey Konovalov, Masahiro Yamada, clang-bu...@googlegroups.com, Daniel Borkmann, Alexei Starovoitov, Will Deacon, Vincenzo Frascino, linux-...@vger.kernel.org, Nick Desaulniers
During Plumbers 2020, we voted to just support the latest release of
Clang for now. Add a compile time check for this.

We plan to remove workarounds for older versions now, which will break
in subtle and not so subtle ways.

Link: https://github.com/ClangBuiltLinux/linux/issues/9
Link: https://github.com/ClangBuiltLinux/linux/issues/941
Suggested-by: Sedat Dilek <sedat...@gmail.com>
Suggested-by: Nathan Chancellor <natecha...@gmail.com>
Suggested-by: Kees Cook <kees...@chromium.org>
Acked-by: Marco Elver <el...@google.com>
Acked-by: Nathan Chancellor <natecha...@gmail.com>
Acked-by: Sedat Dilek <sedat...@gmail.com>
Reviewed-by: Kees Cook <kees...@chromium.org>
Reviewed-by: Miguel Ojeda <miguel.oje...@gmail.com>
Signed-off-by: Nick Desaulniers <ndesau...@google.com>
---

Nick Desaulniers

unread,
Aug 31, 2020, 8:23:36 PM8/31/20
to Andrew Morton, Kees Cook, Miguel Ojeda, Nathan Chancellor, Sedat Dilek, Marco Elver, Andrey Konovalov, Masahiro Yamada, clang-bu...@googlegroups.com, Daniel Borkmann, Alexei Starovoitov, Will Deacon, Vincenzo Frascino, linux-...@vger.kernel.org, Nick Desaulniers
This reverts commit 87e0d4f0f37fb0c8c4aeeac46fff5e957738df79.

This was fixed in clang-6; the minimum supported version of clang in the
kernel is clang-10 (10.0.1).

Link: https://reviews.llvm.org/rL329300.
Link: https://github.com/ClangBuiltLinux/linux/issues/9
Suggested-by: Nathan Chancellor <natecha...@gmail.com>
Signed-off-by: Nick Desaulniers <ndesau...@google.com>
---

Nick Desaulniers

unread,
Aug 31, 2020, 8:23:38 PM8/31/20
to Andrew Morton, Kees Cook, Miguel Ojeda, Nathan Chancellor, Sedat Dilek, Marco Elver, Andrey Konovalov, Masahiro Yamada, clang-bu...@googlegroups.com, Daniel Borkmann, Alexei Starovoitov, Will Deacon, Vincenzo Frascino, linux-...@vger.kernel.org, Nick Desaulniers
This reverts commit b9249cba25a5dce5de87e5404503a5e11832c2dd.

The minimum supported version of clang is now 10.0.1.

Suggested-by: Nathan Chancellor <natecha...@gmail.com>
Signed-off-by: Nick Desaulniers <ndesau...@google.com>
---

Nick Desaulniers

unread,
Aug 31, 2020, 8:23:40 PM8/31/20
to Andrew Morton, Kees Cook, Miguel Ojeda, Nathan Chancellor, Sedat Dilek, Marco Elver, Andrey Konovalov, Masahiro Yamada, clang-bu...@googlegroups.com, Daniel Borkmann, Alexei Starovoitov, Will Deacon, Vincenzo Frascino, linux-...@vger.kernel.org, Nick Desaulniers
This reverts commit 3acf4be235280f14d838581a750532219d67facc.

The minimum supported version of clang is clang 10.0.1.

Suggested-by: Nathan Chancellor <natecha...@gmail.com>
Signed-off-by: Nick Desaulniers <ndesau...@google.com>
---

Nick Desaulniers

unread,
Aug 31, 2020, 8:23:41 PM8/31/20
to Andrew Morton, Kees Cook, Miguel Ojeda, Nathan Chancellor, Sedat Dilek, Marco Elver, Andrey Konovalov, Masahiro Yamada, clang-bu...@googlegroups.com, Daniel Borkmann, Alexei Starovoitov, Will Deacon, Vincenzo Frascino, linux-...@vger.kernel.org, Nick Desaulniers
This partially reverts commit b0fe66cf095016e0b238374c10ae366e1f087d11.

The minimum supported version of clang is now clang 10.0.1. We still
want to pass -meabi=gnu.

Suggested-by: Nathan Chancellor <natecha...@gmail.com>
Signed-off-by: Nick Desaulniers <ndesau...@google.com>
---
arch/arm/Kconfig | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

Nick Desaulniers

unread,
Aug 31, 2020, 8:23:43 PM8/31/20
to Andrew Morton, Kees Cook, Miguel Ojeda, Nathan Chancellor, Sedat Dilek, Marco Elver, Andrey Konovalov, Masahiro Yamada, clang-bu...@googlegroups.com, Daniel Borkmann, Alexei Starovoitov, Will Deacon, Vincenzo Frascino, linux-...@vger.kernel.org, Nick Desaulniers
From: Marco Elver <el...@google.com>

Since the kernel now requires at least Clang 10.0.1, remove any mention
of old Clang versions and simplify the documentation.

Reviewed-by: Andrey Konovalov <andre...@google.com>
Signed-off-by: Marco Elver <el...@google.com>
Signed-off-by: Nick Desaulniers <ndesau...@google.com>
---

Nick Desaulniers

unread,
Aug 31, 2020, 8:23:45 PM8/31/20
to Andrew Morton, Kees Cook, Miguel Ojeda, Nathan Chancellor, Sedat Dilek, Marco Elver, Andrey Konovalov, Masahiro Yamada, clang-bu...@googlegroups.com, Daniel Borkmann, Alexei Starovoitov, Will Deacon, Vincenzo Frascino, linux-...@vger.kernel.org, Nick Desaulniers
As Kees suggests, do so provides developers with two useful pieces of
information:
- The kernel build was attempting to use GCC.
(Maybe they accidentally poked the wrong configs in a CI.)
- They need 4.9 or better.
("Upgrade to what version?" doesn't need to be dug out of documentation,
headers, etc.)

Suggested-by: Kees Cook <kees...@chromium.org>
Signed-off-by: Nick Desaulniers <ndesau...@google.com>
---
include/linux/compiler-gcc.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

Nathan Chancellor

unread,
Sep 1, 2020, 12:55:19 AM9/1/20
to Nick Desaulniers, Andrew Morton, Kees Cook, Miguel Ojeda, Sedat Dilek, Marco Elver, Andrey Konovalov, Masahiro Yamada, clang-bu...@googlegroups.com, Daniel Borkmann, Alexei Starovoitov, Will Deacon, Vincenzo Frascino, linux-...@vger.kernel.org
On Mon, Aug 31, 2020 at 05:23:21PM -0700, Nick Desaulniers wrote:
> This reverts commit 87e0d4f0f37fb0c8c4aeeac46fff5e957738df79.
>
> This was fixed in clang-6; the minimum supported version of clang in the
> kernel is clang-10 (10.0.1).
>
> Link: https://reviews.llvm.org/rL329300.
> Link: https://github.com/ClangBuiltLinux/linux/issues/9
> Suggested-by: Nathan Chancellor <natecha...@gmail.com>
> Signed-off-by: Nick Desaulniers <ndesau...@google.com>

Reviewed-by: Nathan Chancellor <natecha...@gmail.com>

Nathan Chancellor

unread,
Sep 1, 2020, 12:55:48 AM9/1/20
to Nick Desaulniers, Andrew Morton, Kees Cook, Miguel Ojeda, Sedat Dilek, Marco Elver, Andrey Konovalov, Masahiro Yamada, clang-bu...@googlegroups.com, Daniel Borkmann, Alexei Starovoitov, Will Deacon, Vincenzo Frascino, linux-...@vger.kernel.org
On Mon, Aug 31, 2020 at 05:23:22PM -0700, Nick Desaulniers wrote:
> This reverts commit b9249cba25a5dce5de87e5404503a5e11832c2dd.
>
> The minimum supported version of clang is now 10.0.1.
>
> Suggested-by: Nathan Chancellor <natecha...@gmail.com>
> Signed-off-by: Nick Desaulniers <ndesau...@google.com>

Reviewed-by: Nathan Chancellor <natecha...@gmail.com>

Nathan Chancellor

unread,
Sep 1, 2020, 12:56:04 AM9/1/20
to Nick Desaulniers, Andrew Morton, Kees Cook, Miguel Ojeda, Sedat Dilek, Marco Elver, Andrey Konovalov, Masahiro Yamada, clang-bu...@googlegroups.com, Daniel Borkmann, Alexei Starovoitov, Will Deacon, Vincenzo Frascino, linux-...@vger.kernel.org
On Mon, Aug 31, 2020 at 05:23:23PM -0700, Nick Desaulniers wrote:
> This reverts commit 3acf4be235280f14d838581a750532219d67facc.
>
> The minimum supported version of clang is clang 10.0.1.
>
> Suggested-by: Nathan Chancellor <natecha...@gmail.com>
> Signed-off-by: Nick Desaulniers <ndesau...@google.com>

Reviewed-by: Nathan Chancellor <natecha...@gmail.com>

Nathan Chancellor

unread,
Sep 1, 2020, 12:57:07 AM9/1/20
to Nick Desaulniers, Andrew Morton, Kees Cook, Miguel Ojeda, Sedat Dilek, Marco Elver, Andrey Konovalov, Masahiro Yamada, clang-bu...@googlegroups.com, Daniel Borkmann, Alexei Starovoitov, Will Deacon, Vincenzo Frascino, linux-...@vger.kernel.org
Nit: Partially in commit message?

On Mon, Aug 31, 2020 at 05:23:24PM -0700, Nick Desaulniers wrote:
> This partially reverts commit b0fe66cf095016e0b238374c10ae366e1f087d11.
>
> The minimum supported version of clang is now clang 10.0.1. We still
> want to pass -meabi=gnu.

Thank you for calling this out.

> Suggested-by: Nathan Chancellor <natecha...@gmail.com>
> Signed-off-by: Nick Desaulniers <ndesau...@google.com>

Reviewed-by: Nathan Chancellor <natecha...@gmail.com>

Nathan Chancellor

unread,
Sep 1, 2020, 12:57:56 AM9/1/20
to Nick Desaulniers, Andrew Morton, Kees Cook, Miguel Ojeda, Sedat Dilek, Marco Elver, Andrey Konovalov, Masahiro Yamada, clang-bu...@googlegroups.com, Daniel Borkmann, Alexei Starovoitov, Will Deacon, Vincenzo Frascino, linux-...@vger.kernel.org
On Mon, Aug 31, 2020 at 05:23:25PM -0700, Nick Desaulniers wrote:
> From: Marco Elver <el...@google.com>
>
> Since the kernel now requires at least Clang 10.0.1, remove any mention
> of old Clang versions and simplify the documentation.
>
> Reviewed-by: Andrey Konovalov <andre...@google.com>
> Signed-off-by: Marco Elver <el...@google.com>
> Signed-off-by: Nick Desaulniers <ndesau...@google.com>

Reviewed-by: Nathan Chancellor <natecha...@gmail.com>

Nathan Chancellor

unread,
Sep 1, 2020, 1:00:12 AM9/1/20
to Nick Desaulniers, Andrew Morton, Kees Cook, Miguel Ojeda, Sedat Dilek, Marco Elver, Andrey Konovalov, Masahiro Yamada, clang-bu...@googlegroups.com, Daniel Borkmann, Alexei Starovoitov, Will Deacon, Vincenzo Frascino, linux-...@vger.kernel.org
On Mon, Aug 31, 2020 at 05:23:26PM -0700, Nick Desaulniers wrote:
> As Kees suggests, do so provides developers with two useful pieces of
> information:
> - The kernel build was attempting to use GCC.
> (Maybe they accidentally poked the wrong configs in a CI.)
> - They need 4.9 or better.
> ("Upgrade to what version?" doesn't need to be dug out of documentation,
> headers, etc.)
>
> Suggested-by: Kees Cook <kees...@chromium.org>
> Signed-off-by: Nick Desaulniers <ndesau...@google.com>

Reviewed-by: Nathan Chancellor <natecha...@gmail.com>

It would be nice if there was some easy way to link the documentation
here so that patches like commit 0bddd227f3dc ("Documentation: update
for gcc 4.9 requirement") did not need to happen or be remembered.

Miguel Ojeda

unread,
Sep 1, 2020, 4:12:52 AM9/1/20
to Nick Desaulniers, Andrew Morton, Kees Cook, Nathan Chancellor, Sedat Dilek, Marco Elver, Andrey Konovalov, Masahiro Yamada, clang-built-linux, Daniel Borkmann, Alexei Starovoitov, Will Deacon, Vincenzo Frascino, linux-kernel
On Tue, Sep 1, 2020 at 2:23 AM Nick Desaulniers <ndesau...@google.com> wrote:
>
> do so provides developers

"doing so"? "to do so"?

> include/linux/compiler-gcc.h | 2 +-

Reviewed-by: Miguel Ojeda <miguel.oje...@gmail.com>

Cheers,
Miguel

Sedat Dilek

unread,
Sep 1, 2020, 9:52:05 AM9/1/20
to Nick Desaulniers, Andrew Morton, Kees Cook, Miguel Ojeda, Nathan Chancellor, Marco Elver, Andrey Konovalov, Masahiro Yamada, Clang-Built-Linux ML, Daniel Borkmann, Alexei Starovoitov, Will Deacon, Vincenzo Frascino, linux-...@vger.kernel.org
On Tue, Sep 1, 2020 at 2:23 AM Nick Desaulniers <ndesau...@google.com> wrote:
>
> During Plumbers 2020, we voted to just support the latest release of
> Clang for now. Add a compile time check for this.
>
> We plan to remove workarounds for older versions now, which will break
> in subtle and not so subtle ways.
>
> Link: https://github.com/ClangBuiltLinux/linux/issues/9
> Link: https://github.com/ClangBuiltLinux/linux/issues/941
> Suggested-by: Sedat Dilek <sedat...@gmail.com>
> Suggested-by: Nathan Chancellor <natecha...@gmail.com>
> Suggested-by: Kees Cook <kees...@chromium.org>
> Acked-by: Marco Elver <el...@google.com>
> Acked-by: Nathan Chancellor <natecha...@gmail.com>
> Acked-by: Sedat Dilek <sedat...@gmail.com>
> Reviewed-by: Kees Cook <kees...@chromium.org>
> Reviewed-by: Miguel Ojeda <miguel.oje...@gmail.com>
> Signed-off-by: Nick Desaulniers <ndesau...@google.com>

Reviewed-by: Sedat Dilek <sedat...@gmail.com>
Tested-by: Sedat Dilek <sedat...@gmail.com>

- Sedat -

Sedat Dilek

unread,
Sep 1, 2020, 9:52:49 AM9/1/20
to Nick Desaulniers, Andrew Morton, Kees Cook, Miguel Ojeda, Nathan Chancellor, Marco Elver, Andrey Konovalov, Masahiro Yamada, Clang-Built-Linux ML, Daniel Borkmann, Alexei Starovoitov, Will Deacon, Vincenzo Frascino
On Tue, Sep 1, 2020 at 2:18 AM Nick Desaulniers <ndesau...@google.com> wrote:
>
> As Kees suggests, do so provides developers with two useful pieces of
> information:
> - The kernel build was attempting to use GCC.
> (Maybe they accidentally poked the wrong configs in a CI.)
> - They need 4.9 or better.
> ("Upgrade to what version?" doesn't need to be dug out of documentation,
> headers, etc.)
>
> Suggested-by: Kees Cook <kees...@chromium.org>
> Signed-off-by: Nick Desaulniers <ndesau...@google.com>

Reviewed-by: Sedat Dilek <sedat...@gmail.com>
Tested-by: Sedat Dilek <sedat...@gmail.com>

- Sedat -

Sedat Dilek

unread,
Sep 1, 2020, 9:55:53 AM9/1/20
to Nick Desaulniers, Andrew Morton, Kees Cook, Miguel Ojeda, Nathan Chancellor, Marco Elver, Andrey Konovalov, Masahiro Yamada, Clang-Built-Linux ML, Daniel Borkmann, Alexei Starovoitov, Will Deacon, Vincenzo Frascino, linux-...@vger.kernel.org
On Tue, Sep 1, 2020 at 2:23 AM Nick Desaulniers <ndesau...@google.com> wrote:
>
> Adds a compile time #error to compiler-clang.h setting the effective
> minimum supported version to clang 10.0.1. A separate patch has already
> been picked up into the Documentation/ tree also confirming the version.
>
> Next are a series of reverts. One for 32b arm is a partial revert.
>
> Then Marco suggested fixes to KASAN docs.
>
> Finally, improve the warning for GCC too as per Kees.
>
> Patches after 001 are new for v2.
>
> Marco Elver (1):
> kasan: Remove mentions of unsupported Clang versions
>
> Nick Desaulniers (6):
> compiler-clang: add build check for clang 10.0.1
> Revert "kbuild: disable clang's default use of -fmerge-all-constants"
> Revert "arm64: bti: Require clang >= 10.0.1 for in-kernel BTI support"
> Revert "arm64: vdso: Fix compilation with clang older than 8"
> Partial revert "ARM: 8905/1: Emit __gnu_mcount_nc when using Clang
> 10.0.0 or newer"
> compiler-gcc: improve version warning
>

I have tested theses 7 patches together with v2 of "Documentation: add
minimum clang/llvm version".

- Sedat -

Fangrui Song

unread,
Sep 1, 2020, 12:56:04 PM9/1/20
to Nathan Chancellor, Nick Desaulniers, Andrew Morton, Kees Cook, Miguel Ojeda, Sedat Dilek, Marco Elver, Andrey Konovalov, Masahiro Yamada, clang-bu...@googlegroups.com, Daniel Borkmann, Alexei Starovoitov, Will Deacon, Vincenzo Frascino, linux-...@vger.kernel.org


On 2020-08-31, Nathan Chancellor wrote:
>On Mon, Aug 31, 2020 at 05:23:21PM -0700, Nick Desaulniers wrote:
>> This reverts commit 87e0d4f0f37fb0c8c4aeeac46fff5e957738df79.
>>
>> This was fixed in clang-6; the minimum supported version of clang in the
>> kernel is clang-10 (10.0.1).
>>
>> Link: https://reviews.llvm.org/rL329300.
>> Link: https://github.com/ClangBuiltLinux/linux/issues/9
>> Suggested-by: Nathan Chancellor <natecha...@gmail.com>
>> Signed-off-by: Nick Desaulniers <ndesau...@google.com>
>
>Reviewed-by: Nathan Chancellor <natecha...@gmail.com>

How about expanding "This was fixed in clang-6" to be
-fno-merge-all-constants has been the default since clang-6?

(Both gcc|clang -fmerge-all-constants can cause an assertion failure for
the example on https://bugs.llvm.org/show_bug.cgi?id=18538 )

Reviewed-by: Fangrui Song <mas...@google.com>

>> ---
>> Makefile | 9 ---------
>> 1 file changed, 9 deletions(-)
>>
>> diff --git a/Makefile b/Makefile
>> index 37739ee53f27..144ac6a073ff 100644
>> --- a/Makefile
>> +++ b/Makefile
>> @@ -932,15 +932,6 @@ KBUILD_CFLAGS += $(call cc-disable-warning, maybe-uninitialized)
>> # disable invalid "can't wrap" optimizations for signed / pointers
>> KBUILD_CFLAGS += $(call cc-option,-fno-strict-overflow)
>>
>> -# clang sets -fmerge-all-constants by default as optimization, but this
>> -# is non-conforming behavior for C and in fact breaks the kernel, so we
>> -# need to disable it here generally.
>> -KBUILD_CFLAGS += $(call cc-option,-fno-merge-all-constants)
>> -
>> -# for gcc -fno-merge-all-constants disables everything, but it is fine
>> -# to have actual conforming behavior enabled.
>> -KBUILD_CFLAGS += $(call cc-option,-fmerge-constants)
>> -
>> # Make sure -fstack-check isn't enabled (like gentoo apparently did)
>> KBUILD_CFLAGS += $(call cc-option,-fno-stack-check,)
>>
>> --
>> 2.28.0.402.g5ffc5be6b7-goog
>>
>
>--
>You received this message because you are subscribed to the Google Groups "Clang Built Linux" group.
>To unsubscribe from this group and stop receiving emails from it, send an email to clang-built-li...@googlegroups.com.
>To view this discussion on the web visit https://groups.google.com/d/msgid/clang-built-linux/20200901045516.GA1561318%40ubuntu-n2-xlarge-x86.

Sedat Dilek

unread,
Sep 1, 2020, 1:36:36 PM9/1/20
to Nick Desaulniers, Andrew Morton, Kees Cook, Miguel Ojeda, Nathan Chancellor, Marco Elver, Andrey Konovalov, Masahiro Yamada, Clang-Built-Linux ML, Daniel Borkmann, Alexei Starovoitov, Will Deacon, Vincenzo Frascino, linux-...@vger.kernel.org
On Tue, Sep 1, 2020 at 2:23 AM Nick Desaulniers <ndesau...@google.com> wrote:
>
> This reverts commit 87e0d4f0f37fb0c8c4aeeac46fff5e957738df79.
>
> This was fixed in clang-6; the minimum supported version of clang in the
> kernel is clang-10 (10.0.1).
>
> Link: https://reviews.llvm.org/rL329300.
> Link: https://github.com/ClangBuiltLinux/linux/issues/9
> Suggested-by: Nathan Chancellor <natecha...@gmail.com>
> Signed-off-by: Nick Desaulniers <ndesau...@google.com>

Reviewed-by: Sedat Dilek <sedat...@gmail.com>
Tested-by: Sedat Dilek <sedat...@gmail.com>

- Sedat -

Kees Cook

unread,
Sep 1, 2020, 4:01:28 PM9/1/20
to Nick Desaulniers, Andrew Morton, Miguel Ojeda, Nathan Chancellor, Sedat Dilek, Marco Elver, Andrey Konovalov, Masahiro Yamada, clang-bu...@googlegroups.com, Daniel Borkmann, Alexei Starovoitov, Will Deacon, Vincenzo Frascino, linux-...@vger.kernel.org
On Mon, Aug 31, 2020 at 05:23:19PM -0700, Nick Desaulniers wrote:
> Adds a compile time #error to compiler-clang.h setting the effective
> minimum supported version to clang 10.0.1. A separate patch has already
> been picked up into the Documentation/ tree also confirming the version.
>
> Next are a series of reverts. One for 32b arm is a partial revert.
>
> Then Marco suggested fixes to KASAN docs.
>
> Finally, improve the warning for GCC too as per Kees.
> [...]
> 8 files changed, 16 insertions(+), 27 deletions(-)

A nice simplification!

Reviewed-by: Kees Cook <kees...@chromium.org>

(I do note that for Ubuntu 20.04, they're going to need to do an LLVM
10.0.0 -> 10.0.1 bump to do kernel builds for their latest LTS...)

--
Kees Cook

Nick Desaulniers

unread,
Sep 2, 2020, 3:28:21 PM9/2/20
to Kees Cook, Andrew Morton, Miguel Ojeda, Nathan Chancellor, Sedat Dilek, Marco Elver, Andrey Konovalov, Masahiro Yamada, clang-built-linux, Daniel Borkmann, Alexei Starovoitov, Will Deacon, Vincenzo Frascino, LKML
I'll collect relevant tags and fixup feedback and send akpm a v3,
maybe this afternoon. Thanks everyone for the reviews+feedback.

--
Thanks,
~Nick Desaulniers

Nick Desaulniers

unread,
Sep 2, 2020, 6:59:18 PM9/2/20
to Andrew Morton, Kees Cook, Miguel Ojeda, Nathan Chancellor, Sedat Dilek, Marco Elver, Andrey Konovalov, Masahiro Yamada, clang-bu...@googlegroups.com, Daniel Borkmann, Alexei Starovoitov, Will Deacon, Vincenzo Frascino, linux-...@vger.kernel.org, Nick Desaulniers
Adds a compile time #error to compiler-clang.h setting the effective
minimum supported version to clang 10.0.1. A separate patch has already
been picked up into the Documentation/ tree also confirming the version.

Next are a series of reverts. One for 32b arm is a partial revert.

Then Marco suggested fixes to KASAN docs.

Finally, improve the warning for GCC too as per Kees.

Patches after 001 are new for v2.

v3 just collects tags and fixes typos in a few commit messages.

Marco Elver (1):
kasan: Remove mentions of unsupported Clang versions

Nick Desaulniers (6):
compiler-clang: add build check for clang 10.0.1
Revert "kbuild: disable clang's default use of -fmerge-all-constants"
Revert "arm64: bti: Require clang >= 10.0.1 for in-kernel BTI support"
Revert "arm64: vdso: Fix compilation with clang older than 8"
Partially revert "ARM: 8905/1: Emit __gnu_mcount_nc when using Clang
10.0.0 or newer"
compiler-gcc: improve version error

Documentation/dev-tools/kasan.rst | 4 ++--
Makefile | 9 ---------
arch/arm/Kconfig | 2 +-
arch/arm64/Kconfig | 2 --
arch/arm64/kernel/vdso/Makefile | 7 -------
include/linux/compiler-clang.h | 8 ++++++++
include/linux/compiler-gcc.h | 2 +-
lib/Kconfig.kasan | 9 ++++-----
8 files changed, 16 insertions(+), 27 deletions(-)

--
2.28.0.402.g5ffc5be6b7-goog

Nick Desaulniers

unread,
Sep 2, 2020, 6:59:23 PM9/2/20
to Andrew Morton, Kees Cook, Miguel Ojeda, Nathan Chancellor, Sedat Dilek, Marco Elver, Andrey Konovalov, Masahiro Yamada, clang-bu...@googlegroups.com, Daniel Borkmann, Alexei Starovoitov, Will Deacon, Vincenzo Frascino, linux-...@vger.kernel.org, Nick Desaulniers
During Plumbers 2020, we voted to just support the latest release of
Clang for now. Add a compile time check for this.

We plan to remove workarounds for older versions now, which will break
in subtle and not so subtle ways.

Suggested-by: Sedat Dilek <sedat...@gmail.com>
Suggested-by: Nathan Chancellor <natecha...@gmail.com>
Suggested-by: Kees Cook <kees...@chromium.org>
Signed-off-by: Nick Desaulniers <ndesau...@google.com>
Tested-by: Sedat Dilek <sedat...@gmail.com>
Reviewed-by: Kees Cook <kees...@chromium.org>
Reviewed-by: Miguel Ojeda <miguel.oje...@gmail.com>
Reviewed-by: Sedat Dilek <sedat...@gmail.com>
Acked-by: Marco Elver <el...@google.com>
Acked-by: Nathan Chancellor <natecha...@gmail.com>
Acked-by: Sedat Dilek <sedat...@gmail.com>
---

Nick Desaulniers

unread,
Sep 2, 2020, 6:59:25 PM9/2/20
to Andrew Morton, Kees Cook, Miguel Ojeda, Nathan Chancellor, Sedat Dilek, Marco Elver, Andrey Konovalov, Masahiro Yamada, clang-bu...@googlegroups.com, Daniel Borkmann, Alexei Starovoitov, Will Deacon, Vincenzo Frascino, linux-...@vger.kernel.org, Nick Desaulniers, Fangrui Song
This reverts commit 87e0d4f0f37fb0c8c4aeeac46fff5e957738df79.

-fno-merge-all-constants has been the default since clang-6; the minimum
supported version of clang in the kernel is clang-10 (10.0.1).

Suggested-by: Nathan Chancellor <natecha...@gmail.com>
Signed-off-by: Nick Desaulniers <ndesau...@google.com>
Tested-by: Sedat Dilek <sedat...@gmail.com>
Reviewed-by: Fangrui Song <mas...@google.com>
Reviewed-by: Nathan Chancellor <natecha...@gmail.com>
Reviewed-by: Sedat Dilek <sedat...@gmail.com>
Reviewed-by: Kees Cook <kees...@chromium.org>
---
Makefile | 9 ---------
1 file changed, 9 deletions(-)

diff --git a/Makefile b/Makefile
index 1cfa5029fd2f..e475650c9599 100644

Nick Desaulniers

unread,
Sep 2, 2020, 6:59:27 PM9/2/20
to Andrew Morton, Kees Cook, Miguel Ojeda, Nathan Chancellor, Sedat Dilek, Marco Elver, Andrey Konovalov, Masahiro Yamada, clang-bu...@googlegroups.com, Daniel Borkmann, Alexei Starovoitov, Will Deacon, Vincenzo Frascino, linux-...@vger.kernel.org, Nick Desaulniers
This reverts commit b9249cba25a5dce5de87e5404503a5e11832c2dd.

The minimum supported version of clang is now 10.0.1.

Suggested-by: Nathan Chancellor <natecha...@gmail.com>
Signed-off-by: Nick Desaulniers <ndesau...@google.com>
Reviewed-by: Kees Cook <kees...@chromium.org>

Nick Desaulniers

unread,
Sep 2, 2020, 6:59:29 PM9/2/20
to Andrew Morton, Kees Cook, Miguel Ojeda, Nathan Chancellor, Sedat Dilek, Marco Elver, Andrey Konovalov, Masahiro Yamada, clang-bu...@googlegroups.com, Daniel Borkmann, Alexei Starovoitov, Will Deacon, Vincenzo Frascino, linux-...@vger.kernel.org, Nick Desaulniers
This reverts commit 3acf4be235280f14d838581a750532219d67facc.

The minimum supported version of clang is clang 10.0.1.

Suggested-by: Nathan Chancellor <natecha...@gmail.com>
Signed-off-by: Nick Desaulniers <ndesau...@google.com>
Reviewed-by: Kees Cook <kees...@chromium.org>
Reviewed-by: Nathan Chancellor <natecha...@gmail.com>
---

Nick Desaulniers

unread,
Sep 2, 2020, 6:59:31 PM9/2/20
to Andrew Morton, Kees Cook, Miguel Ojeda, Nathan Chancellor, Sedat Dilek, Marco Elver, Andrey Konovalov, Masahiro Yamada, clang-bu...@googlegroups.com, Daniel Borkmann, Alexei Starovoitov, Will Deacon, Vincenzo Frascino, linux-...@vger.kernel.org, Nick Desaulniers
This partially reverts commit b0fe66cf095016e0b238374c10ae366e1f087d11.

The minimum supported version of clang is now clang 10.0.1. We still
want to pass -meabi=gnu.

Suggested-by: Nathan Chancellor <natecha...@gmail.com>
Signed-off-by: Nick Desaulniers <ndesau...@google.com>
Reviewed-by: Kees Cook <kees...@chromium.org>
Reviewed-by: Nathan Chancellor <natecha...@gmail.com>
---
arch/arm/Kconfig | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

Nick Desaulniers

unread,
Sep 2, 2020, 6:59:33 PM9/2/20
to Andrew Morton, Kees Cook, Miguel Ojeda, Nathan Chancellor, Sedat Dilek, Marco Elver, Andrey Konovalov, Masahiro Yamada, clang-bu...@googlegroups.com, Daniel Borkmann, Alexei Starovoitov, Will Deacon, Vincenzo Frascino, linux-...@vger.kernel.org, Nick Desaulniers
From: Marco Elver <el...@google.com>

Since the kernel now requires at least Clang 10.0.1, remove any mention
of old Clang versions and simplify the documentation.

Signed-off-by: Marco Elver <el...@google.com>
Signed-off-by: Nick Desaulniers <ndesau...@google.com>
Reviewed-by: Andrey Konovalov <andre...@google.com>
Reviewed-by: Kees Cook <kees...@chromium.org>
Reviewed-by: Nathan Chancellor <natecha...@gmail.com>
---

Nick Desaulniers

unread,
Sep 2, 2020, 6:59:34 PM9/2/20
to Andrew Morton, Kees Cook, Miguel Ojeda, Nathan Chancellor, Sedat Dilek, Marco Elver, Andrey Konovalov, Masahiro Yamada, clang-bu...@googlegroups.com, Daniel Borkmann, Alexei Starovoitov, Will Deacon, Vincenzo Frascino, linux-...@vger.kernel.org, Nick Desaulniers
As Kees suggests, doing so provides developers with two useful pieces of
information:
- The kernel build was attempting to use GCC.
(Maybe they accidentally poked the wrong configs in a CI.)
- They need 4.9 or better.
("Upgrade to what version?" doesn't need to be dug out of documentation,
headers, etc.)

Reviewed-by: Kees Cook <kees...@chromium.org>
Reviewed-by: Miguel Ojeda <miguel.oje...@gmail.com>
Reviewed-by: Nathan Chancellor <natecha...@gmail.com>
Reviewed-by: Sedat Dilek <sedat...@gmail.com>
Suggested-by: Kees Cook <kees...@chromium.org>
Tested-by: Sedat Dilek <sedat...@gmail.com>
Signed-off-by: Nick Desaulniers <ndesau...@google.com>
---
include/linux/compiler-gcc.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

Sedat Dilek

unread,
Sep 3, 2020, 10:06:56 AM9/3/20
to Nick Desaulniers, Andrew Morton, Kees Cook, Miguel Ojeda, Nathan Chancellor, Marco Elver, Andrey Konovalov, Masahiro Yamada, Clang-Built-Linux ML, Daniel Borkmann, Alexei Starovoitov, Will Deacon, Vincenzo Frascino, linux-...@vger.kernel.org
On Thu, Sep 3, 2020 at 12:59 AM Nick Desaulniers
<ndesau...@google.com> wrote:
>
> Adds a compile time #error to compiler-clang.h setting the effective
> minimum supported version to clang 10.0.1. A separate patch has already
> been picked up into the Documentation/ tree also confirming the version.
>
> Next are a series of reverts. One for 32b arm is a partial revert.
>
> Then Marco suggested fixes to KASAN docs.
>
> Finally, improve the warning for GCC too as per Kees.
>
> Patches after 001 are new for v2.
>
> v3 just collects tags and fixes typos in a few commit messages.
>

Through which Git tree is this patch-series going through?
Do the new LLVM/Clang maintainers already have their own Git tree @
git.kernel.org?

Is this patch-series material for Linux v5.9 or v5.10?

- Sedat -

Nathan Chancellor

unread,
Sep 3, 2020, 1:28:51 PM9/3/20
to Sedat Dilek, Nick Desaulniers, Andrew Morton, Kees Cook, Miguel Ojeda, Marco Elver, Andrey Konovalov, Masahiro Yamada, Clang-Built-Linux ML, Daniel Borkmann, Alexei Starovoitov, Will Deacon, Vincenzo Frascino, linux-...@vger.kernel.org
On Thu, Sep 03, 2020 at 04:06:43PM +0200, Sedat Dilek wrote:
> On Thu, Sep 3, 2020 at 12:59 AM Nick Desaulniers
> <ndesau...@google.com> wrote:
> >
> > Adds a compile time #error to compiler-clang.h setting the effective
> > minimum supported version to clang 10.0.1. A separate patch has already
> > been picked up into the Documentation/ tree also confirming the version.
> >
> > Next are a series of reverts. One for 32b arm is a partial revert.
> >
> > Then Marco suggested fixes to KASAN docs.
> >
> > Finally, improve the warning for GCC too as per Kees.
> >
> > Patches after 001 are new for v2.
> >
> > v3 just collects tags and fixes typos in a few commit messages.
> >
>
> Through which Git tree is this patch-series going through?
> Do the new LLVM/Clang maintainers already have their own Git tree @
> git.kernel.org?

I would say this should go through either Andrew or Masahiro. We do not
have a formal git tree plus I believe there are other things that need
to happen before we can push stuff to Linus.

> Is this patch-series material for Linux v5.9 or v5.10?
>
> - Sedat -

Given that this is not a regression or a bug fix, it should go into 5.10
in my opinion.

Cheers,
Nathan

Miguel Ojeda

unread,
Sep 4, 2020, 1:42:31 AM9/4/20
to Nathan Chancellor, Sedat Dilek, Nick Desaulniers, Andrew Morton, Kees Cook, Marco Elver, Andrey Konovalov, Masahiro Yamada, Clang-Built-Linux ML, Daniel Borkmann, Alexei Starovoitov, Will Deacon, Vincenzo Frascino, linux-kernel
On Thu, Sep 3, 2020 at 7:28 PM Nathan Chancellor
<natecha...@gmail.com> wrote:
>
> I would say this should go through either Andrew or Masahiro. We do not
> have a formal git tree plus I believe there are other things that need
> to happen before we can push stuff to Linus.

Note that a git.kernel.org repo/account isn't required to send PRs.
The hard requirement is getting your keys signed. Putting stuff into
-next is also important.

> Given that this is not a regression or a bug fix, it should go into 5.10
> in my opinion.

It is a bit late, yeah.

Cheers,
Miguel

Arvind Sankar

unread,
Sep 7, 2020, 12:12:33 PM9/7/20
to Nick Desaulniers, Andrew Morton, Kees Cook, Miguel Ojeda, Nathan Chancellor, Sedat Dilek, Marco Elver, Andrey Konovalov, Masahiro Yamada, clang-bu...@googlegroups.com, Daniel Borkmann, Alexei Starovoitov, Will Deacon, Vincenzo Frascino, linux-...@vger.kernel.org
On Wed, Sep 02, 2020 at 03:59:04PM -0700, Nick Desaulniers wrote:
> Adds a compile time #error to compiler-clang.h setting the effective
> minimum supported version to clang 10.0.1. A separate patch has already
> been picked up into the Documentation/ tree also confirming the version.
>

Is 10.0.1 actually required or could it just check major version? I have
10.0.0 currently and at least x86 seems to be building fine.

Thanks.

Will Deacon

unread,
Sep 7, 2020, 5:25:31 PM9/7/20
to Nick Desaulniers, Andrew Morton, Kees Cook, Miguel Ojeda, Nathan Chancellor, Sedat Dilek, Marco Elver, Andrey Konovalov, Masahiro Yamada, clang-bu...@googlegroups.com, Daniel Borkmann, Alexei Starovoitov, Vincenzo Frascino, linux-...@vger.kernel.org
On Wed, Sep 02, 2020 at 03:59:11PM -0700, Nick Desaulniers wrote:
> As Kees suggests, doing so provides developers with two useful pieces of
> information:

I struggle to parse this. "doing so" what? These things are supposed to
be in the imperative.

Will

Will Deacon

unread,
Sep 7, 2020, 5:26:32 PM9/7/20
to Nick Desaulniers, Andrew Morton, Kees Cook, Miguel Ojeda, Nathan Chancellor, Sedat Dilek, Marco Elver, Andrey Konovalov, Masahiro Yamada, clang-bu...@googlegroups.com, Daniel Borkmann, Alexei Starovoitov, Vincenzo Frascino, linux-...@vger.kernel.org
On Wed, Sep 02, 2020 at 03:59:04PM -0700, Nick Desaulniers wrote:
> Adds a compile time #error to compiler-clang.h setting the effective
> minimum supported version to clang 10.0.1. A separate patch has already
> been picked up into the Documentation/ tree also confirming the version.

Modulo my horrible grammar nit on the last patch:

Acked-by: Will Deacon <wi...@kernel.org>

Thanks!

Will

Nathan Chancellor

unread,
Sep 8, 2020, 12:42:21 AM9/8/20
to Arvind Sankar, Nick Desaulniers, Andrew Morton, Kees Cook, Miguel Ojeda, Sedat Dilek, Marco Elver, Andrey Konovalov, Masahiro Yamada, clang-bu...@googlegroups.com, Daniel Borkmann, Alexei Starovoitov, Will Deacon, Vincenzo Frascino, linux-...@vger.kernel.org
There was a decent amount of effort put in to testing LLVM 10.0.1 and
making sure that it could handle the kernel. I know of a few backend
errors that were fixed and backported to 10.0.1:

https://github.com/ClangBuiltLinux/linux/issues/944
https://github.com/ClangBuiltLinux/linux/issues/954

Plus there was this rather nasty ld.lld crash in 10.0.0 that just
x86_64_defconfig triggers with mainline:

https://github.com/ClangBuiltLinux/linux/issues/962

I do not have any strong opinions around checking just major version but
I would prefer that we stick with 10.0.1 because it has been tested
against several kernel configs unlike 10.0.0. However, I know that Kees
mentioned that Ubuntu 20.04 shipped clang 10.0.0 and there is no 10.0.1
available yet. Presumably it is coming down the pipeline from Debian
since 10.0.1 appears to be in testing? I suppose if 10.0.0 is shipped in
multiple places without an easy upgrade path to 10.0.1, we should
consider softening up this version check, at least for the time being. I
just worry about duplicate reports.

Cheers,
Nathan

Jarkko Sakkinen

unread,
Nov 2, 2020, 11:55:29 PM11/2/20
to Nick Desaulniers, Andrew Morton, Kees Cook, Miguel Ojeda, Nathan Chancellor, Sedat Dilek, Marco Elver, Andrey Konovalov, Masahiro Yamada, clang-bu...@googlegroups.com, Daniel Borkmann, Alexei Starovoitov, Will Deacon, Vincenzo Frascino, linux-...@vger.kernel.org
I'm trying to compile a BPF enabled test kernel for a live system and I
get this error even though I have much newer clang:

➜ ~ (master) ✔ clang --version
Ubuntu clang version 11.0.0-2
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

Tried to Google for troubleshooter tips but this patch is basically the
only hit I get :-)


> +
> /* Compiler specific definitions for Clang compiler */
>
> /* same as gcc, this was present in clang-2.6 so we can assume it works
> --
> 2.28.0.402.g5ffc5be6b7-goog
>

/Jarkko

Nathan Chancellor

unread,
Nov 3, 2020, 1:38:18 AM11/3/20
to Jarkko Sakkinen, Nick Desaulniers, Andrew Morton, Kees Cook, Miguel Ojeda, Sedat Dilek, Marco Elver, Andrey Konovalov, Masahiro Yamada, clang-bu...@googlegroups.com, Daniel Borkmann, Alexei Starovoitov, Will Deacon, Vincenzo Frascino, linux-...@vger.kernel.org
Do you have a .config and command to reproduce the error?

Cheers,
Nathan

Jarkko Sakkinen

unread,
Nov 3, 2020, 4:00:23 AM11/3/20
to Nathan Chancellor, Nick Desaulniers, Andrew Morton, Kees Cook, Miguel Ojeda, Sedat Dilek, Marco Elver, Andrey Konovalov, Masahiro Yamada, clang-bu...@googlegroups.com, Daniel Borkmann, Alexei Starovoitov, Will Deacon, Vincenzo Frascino, linux-...@vger.kernel.org
Attached.

> Cheers,
> Nathan

/Jarkko
config

Nick Desaulniers

unread,
Nov 3, 2020, 1:48:39 PM11/3/20
to Jarkko Sakkinen, Andrew Morton, Kees Cook, Miguel Ojeda, Nathan Chancellor, Sedat Dilek, Marco Elver, Andrey Konovalov, Masahiro Yamada, clang-built-linux, Daniel Borkmann, Alexei Starovoitov, Will Deacon, Vincenzo Frascino, LKML
To check the values of the above preprocessor defines, please run:
$ clang -dM -E - < /dev/null | grep -e __clang_m -e __clang_p

If you have multiple versions of clang installed, you might not be
running the version you think you are. Particularly, if you're using
bcc, idk if it includes a copy of clang? If that's the case, we may
have to work out how we can support older versions of clang for the
express purposes of bpf.
--
Thanks,
~Nick Desaulniers

Jarkko Sakkinen

unread,
Nov 3, 2020, 7:38:33 PM11/3/20
to Nick Desaulniers, Andrew Morton, Kees Cook, Miguel Ojeda, Nathan Chancellor, Sedat Dilek, Marco Elver, Andrey Konovalov, Masahiro Yamada, clang-built-linux, Daniel Borkmann, Alexei Starovoitov, Will Deacon, Vincenzo Frascino, LKML
➜ ~ (master) ✔ clang -dM -E - < /dev/null | grep -e __clang_m -e __clang_p
#define __clang_major__ 11
#define __clang_minor__ 0
#define __clang_patchlevel__ 0

I'm compiling the kernel itself with GCC.

Here's an example BPF script that fails on me:

struct sgx_enclave_add_pages {
unsigned long src;
unsigned long offset;
unsigned long length;
unsigned long secinfo;
unsigned long flags;
unsigned long count;
};

kprobe:sgx_ioctl
{
if (arg1 == 0xc030a401) {
printf("sgx_ioctl: %d, %lu\n", pid, ((struct sgx_enclave_add_pages *)(arg2))->offset);
}

}
Note that it relies on code not yet in the mainline.

If I don't declare structs, things work just fine. E.g. the following
works:

kprobe:sgx_encl_get_backing
{
printf("%s\n", func)
}

BTW, I don't really understand how scripts/clang-version.sh is even
supposed to work, if you compile the kernel itself with GCC. In that
case there would be no output, right? And thus version gets set to
zero...

> --
> Thanks,
> ~Nick Desaulniers

/Jarkko

Nick Desaulniers

unread,
Nov 3, 2020, 8:18:50 PM11/3/20
to Jarkko Sakkinen, Andrew Morton, Kees Cook, Miguel Ojeda, Nathan Chancellor, Sedat Dilek, Marco Elver, Andrey Konovalov, Masahiro Yamada, clang-built-linux, Daniel Borkmann, Alexei Starovoitov, Will Deacon, Vincenzo Frascino, LKML
That script is only used by KBUILD. include/linux/compiler-clang.h is
what's included into include/linux/compiler_types.h and causes the
error. The eBFP tools must be including kernel headers and defining
`__clang__`. Forgive my complete ignorance of eBPF, but how do you
build that script? I assume the tool is using Clang, since eBPF
relies on the LLVM backend (not sure if the GCC eBPF backend is good
to go quite yet), and that version of clang is older.

I wonder if we should guard the version check with __BPF_TRACING__
similar to arch/x86/include/asm/cpufeature.h? Care to test:
```
diff --git a/include/linux/compiler-clang.h
b/include/linux/compiler-clang.h
index dd7233c48bf3..98cff1b4b088 100644
--- a/include/linux/compiler-clang.h
+++ b/include/linux/compiler-clang.h
@@ -8,8 +8,10 @@
+ __clang_patchlevel__)

#if CLANG_VERSION < 100001
+#ifndef __BPF_TRACING__
# error Sorry, your version of Clang is too old - please use 10.0.1 or newer.
#endif
+#endif

/* Compiler specific definitions for Clang compiler */
```
--
Thanks,
~Nick Desaulniers

Jarkko Sakkinen

unread,
Nov 3, 2020, 8:34:54 PM11/3/20
to Nick Desaulniers, Jarkko Sakkinen, Andrew Morton, Kees Cook, Miguel Ojeda, Nathan Chancellor, Sedat Dilek, Marco Elver, Andrey Konovalov, Masahiro Yamada, clang-built-linux, Daniel Borkmann, Alexei Starovoitov, Will Deacon, Vincenzo Frascino, LKML
Thanks a lot for helping with this :-)

I'm using bpftrace as the frontend.

> relies on the LLVM backend (not sure if the GCC eBPF backend is good
> to go quite yet), and that version of clang is older.
>
> I wonder if we should guard the version check with __BPF_TRACING__
> similar to arch/x86/include/asm/cpufeature.h? Care to test:


Before I received this response, I did git revert for this commit
and things started working again.

> ```
> diff --git a/include/linux/compiler-clang.h
> b/include/linux/compiler-clang.h
> index dd7233c48bf3..98cff1b4b088 100644
> --- a/include/linux/compiler-clang.h
> +++ b/include/linux/compiler-clang.h
> @@ -8,8 +8,10 @@
> + __clang_patchlevel__)
>
> #if CLANG_VERSION < 100001
> +#ifndef __BPF_TRACING__
> # error Sorry, your version of Clang is too old - please use 10.0.1 or newer.
> #endif
> +#endif
>
> /* Compiler specific definitions for Clang compiler */
> ```
> --

Shouldn't "#ifndef" be before the whole version check? Otherwise,
LGTM. Please CC me once there is a properly formed patch to try out.

> Thanks,
> ~Nick Desaulniers

/Jarkko

Jarkko Sakkinen

unread,
Nov 3, 2020, 8:37:02 PM11/3/20
to Nick Desaulniers, Jarkko Sakkinen, Andrew Morton, Kees Cook, Miguel Ojeda, Nathan Chancellor, Sedat Dilek, Marco Elver, Andrey Konovalov, Masahiro Yamada, clang-built-linux, Daniel Borkmann, Alexei Starovoitov, Will Deacon, Vincenzo Frascino, LKML
On Wed, Nov 04, 2020 at 03:34:49AM +0200, Jarkko Sakkinen wrote:
> Shouldn't "#ifndef" be before the whole version check? Otherwise,
> LGTM. Please CC me once there is a properly formed patch to try out.

(to my kernel org address).

/Jarkko

John Hubbard

unread,
Nov 16, 2020, 10:04:55 PM11/16/20
to jarkko....@iki.fi, ak...@linux-foundation.org, andre...@google.com, a...@kernel.org, clang-bu...@googlegroups.com, dan...@iogearbox.net, el...@google.com, jar...@kernel.org, kees...@chromium.org, linux-...@vger.kernel.org, masa...@kernel.org, miguel.oje...@gmail.com, natecha...@gmail.com, ndesau...@google.com, sedat...@gmail.com, vincenzo...@arm.com, wi...@kernel.org, John Hubbard
Hi,

I just ran into this and it's a real pain to figure out, because even
with the very latest Fedora 33 on my test machine, which provides clang
version 11.0.0:

$ clang --version
clang version 11.0.0 (Fedora 11.0.0-2.fc33)
Target: x86_64-unknown-linux-gnu

...the bpftrace program still chokes on some, but not all commands, in
ways that invisible to normal debugging. For example:

$ sudo bpftrace -e 'tracepoint:syscalls:sys_enter_vmsplice { @[kstack()]
= count(); }'
/lib/modules/5.10.0-rc4-hubbard-github+/source/include/linux/compiler-clang.h:12:3:
error: Sorry, your version of Clang is too old - please use 10.0.1 or
newer.

But Jarkko's recommended fix works! In other words, applying the diff
below fixes it for me. So I'm replying in order to note that the problem
is real and hoping that the fix is applied soon.


diff --git a/include/linux/compiler-clang.h b/include/linux/compiler-clang.h
index dd7233c48bf3..c2228b957fd7 100644
--- a/include/linux/compiler-clang.h
+++ b/include/linux/compiler-clang.h
@@ -7,9 +7,11 @@
+ __clang_minor__ * 100 \
+ __clang_patchlevel__)

+#ifndef __BPF_TRACING__
#if CLANG_VERSION < 100001
# error Sorry, your version of Clang is too old - please use 10.0.1 or newer.
#endif
+#endif

/* Compiler specific definitions for Clang compiler */



thanks,
--
John Hubbard
NVIDIA

Nick Desaulniers

unread,
Nov 17, 2020, 1:46:41 PM11/17/20
to John Hubbard, Andrew Morton, jarkko....@iki.fi, Andrey Konovalov, Alexei Starovoitov, clang-built-linux, Daniel Borkmann, Marco Elver, Jarkko Sakkinen, Kees Cook, LKML, Masahiro Yamada, Miguel Ojeda, Nathan Chancellor, Sedat Dilek, Vincenzo Frascino, Will Deacon
On Mon, Nov 16, 2020 at 7:04 PM John Hubbard <jhub...@nvidia.com> wrote:
>
> Hi,
>
> I just ran into this and it's a real pain to figure out, because even
> with the very latest Fedora 33 on my test machine, which provides clang
> version 11.0.0:

Hi John,
Thanks for the report. The patch was picked up by AKPM and is in the -mm tree:
https://ozlabs.org/~akpm/mmots/broken-out/compiler-clang-remove-version-check-for-bpf-tracing.patch
--
Thanks,
~Nick Desaulniers

Nathan Chancellor

unread,
Nov 17, 2020, 9:31:22 PM11/17/20
to Nick Desaulniers, Andrew Morton, John Hubbard, jarkko....@iki.fi, Andrey Konovalov, Alexei Starovoitov, clang-built-linux, Daniel Borkmann, Marco Elver, Jarkko Sakkinen, Kees Cook, LKML, Masahiro Yamada, Miguel Ojeda, Sedat Dilek, Vincenzo Frascino, Will Deacon
This should probably go to Linus as a regression fix in the next wave,
if that is possible.

Cheers,
Nathan

Andrew Morton

unread,
Nov 17, 2020, 9:37:35 PM11/17/20
to Nathan Chancellor, Nick Desaulniers, John Hubbard, jarkko....@iki.fi, Andrey Konovalov, Alexei Starovoitov, clang-built-linux, Daniel Borkmann, Marco Elver, Jarkko Sakkinen, Kees Cook, LKML, Masahiro Yamada, Miguel Ojeda, Sedat Dilek, Vincenzo Frascino, Will Deacon
Yes, I'll sent it along later this week.
Reply all
Reply to author
Forward
0 new messages