kcsan: Re-add GCC support, and compiler flags improvements
Subsystems (5)
Marco Elver
maintainercover kcsan: Re-add GCC support, and compiler flags improvements
Re-add GCC as a supported compiler and clean up compiler flags.
To use KCSAN with GCC before GCC 11 is released, the following will get a stable GCC 10 and cherry-pick the patches required for KCSAN support:
git clone git://gcc.gnu.org/git/gcc.git && cd gcc git checkout -b gcc-10-for-kcsan releases/gcc-10.1.0 git cherry-pick \ 4089df8ef4a63126b0774c39b6638845244c20d2 \ ab2789ec507a94f1a75a6534bca51c7b39037ce0 \ 06712fc68dc9843d9af7c7ac10047f49d305ad76 ./configure --prefix <your-prefix> --enable-languages=c,c++ make -j$(nproc) && make install
Marco Elver (3):
kcsan: Re-add GCC as a supported compiler
kcsan: Simplify compiler flags
kcsan: Disable branch tracing in core runtime
Documentation/dev-tools/kcsan.rst | 3 ++- kernel/kcsan/Makefile | 4 ++-- lib/Kconfig.kcsan | 3 ++- scripts/Makefile.kcsan | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-)
Signature · 1 line
2.27.0.290.gba653c62da-goog
Marco Elver
maintainerPATCH 1/3 kcsan: Re-add GCC as a supported compiler
GCC version 11 recently implemented all requirements to correctly support KCSAN:
1. Correct no_sanitize-attribute inlining behaviour:
https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=4089df8ef4a63126b0774c39b6638845244c20d2
2. --param=tsan-distinguish-volatile
https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=ab2789ec507a94f1a75a6534bca51c7b39037ce0
3. --param=tsan-instrument-func-entry-exit
https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=06712fc68dc9843d9af7c7ac10047f49d305ad76
Therefore, we can re-enable GCC for KCSAN, and document the new compiler requirements.
---
For anyone interested to try it out before GCC 11 is released, I'd recommend building a stable GCC 10 with the patches applied:
git clone git://gcc.gnu.org/git/gcc.git && cd gcc git checkout -b gcc-10-for-kcsan releases/gcc-10.1.0 git cherry-pick \ 4089df8ef4a63126b0774c39b6638845244c20d2 \ ab2789ec507a94f1a75a6534bca51c7b39037ce0 \ 06712fc68dc9843d9af7c7ac10047f49d305ad76 ./configure --prefix <your-prefix> --enable-languages=c,c++ make -j$(nproc) && make install --- Documentation/dev-tools/kcsan.rst | 3 ++- lib/Kconfig.kcsan | 3 ++- scripts/Makefile.kcsan | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-)
Documentation/dev-tools/kcsan.rst +2 -1
@@ -8,7 +8,8 @@ approach to detect races. KCSAN's primary purpose is to detect `data races`_. Usage ----- -KCSAN requires Clang version 11 or later. +KCSAN is supported by both GCC and Clang. With GCC we require version 11 or +later, and with Clang also require version 11 or later. To enable KCSAN configure the kernel with::
lib/Kconfig.kcsan +2 -1
@@ -4,7 +4,8 @@ config HAVE_ARCH_KCSAN bool config HAVE_KCSAN_COMPILER - def_bool CC_IS_CLANG && $(cc-option,-fsanitize=thread -mllvm -tsan-distinguish-volatile=1) + def_bool (CC_IS_CLANG && $(cc-option,-fsanitize=thread -mllvm -tsan-distinguish-volatile=1)) || \ + (CC_IS_GCC && $(cc-option,-fsanitize=thread --param tsan-distinguish-volatile=1)) help For the list of compilers that support KCSAN, please see <file:Documentation/dev-tools/kcsan.rst>.
scripts/Makefile.kcsan +1 -1
@@ -6,7 +6,7 @@ ifdef CONFIG_KCSAN ifdef CONFIG_CC_IS_CLANG cc-param = -mllvm -$(1) else -cc-param = --param -$(1) +cc-param = --param $(1) endif # Keep most options here optional, to allow enabling more compilers if absence
Signature · 1 line
2.27.0.290.gba653c62da-goog
Marco Elver
maintainerPATCH 2/3 kcsan: Simplify compiler flags
In reply to Marco ElverSimplify the set of compiler flags for the runtime by removing cc-option from -fno-stack-protector, because all supported compilers support it. This saves us one compiler invocation during build.
--- kernel/kcsan/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/kcsan/Makefile +2 -2
@@ -7,8 +7,8 @@ CFLAGS_REMOVE_core.o = $(CC_FLAGS_FTRACE) CFLAGS_REMOVE_debugfs.o = $(CC_FLAGS_FTRACE) CFLAGS_REMOVE_report.o = $(CC_FLAGS_FTRACE) -CFLAGS_core.o := $(call cc-option,-fno-conserve-stack,) \ - $(call cc-option,-fno-stack-protector,) +CFLAGS_core.o := $(call cc-option,-fno-conserve-stack) \ + -fno-stack-protector obj-y := core.o debugfs.o report.o obj-$(CONFIG_KCSAN_SELFTEST) += selftest.o
Signature · 1 line
2.27.0.290.gba653c62da-goog
Marco Elver
maintainerPATCH 3/3 kcsan: Disable branch tracing in core runtime
In reply to Marco ElverDisable branch tracing in core KCSAN runtime if branches are being traced (TRACE_BRANCH_PROFILING). This it to avoid its performance impact, but also avoid recursion in case KCSAN is enabled for the branch tracing runtime.
The latter had already been a problem for KASAN:
https://lore.kernel.org/lkml/CANpmjNOeXmD5E3O50Z3MjkiuCYaYOPyi+1rq=GZvEKwBvLR0Ug@mail.gmail.com/
--- kernel/kcsan/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/kcsan/Makefile +1 -1
@@ -8,7 +8,7 @@ CFLAGS_REMOVE_debugfs.o = $(CC_FLAGS_FTRACE) CFLAGS_REMOVE_report.o = $(CC_FLAGS_FTRACE) CFLAGS_core.o := $(call cc-option,-fno-conserve-stack) \ - -fno-stack-protector + -fno-stack-protector -DDISABLE_BRANCH_PROFILING obj-y := core.o debugfs.o report.o obj-$(CONFIG_KCSAN_SELFTEST) += selftest.o
Signature · 1 line
2.27.0.290.gba653c62da-goog
Quoted 5 lines · Marco Elver
Re-add GCC as a supported compiler and clean up compiler flags.
To use KCSAN with GCC before GCC 11 is released, the following will get a stable GCC 10 and cherry-pick the patches required for KCSAN support:
Quoted 8 lines
git clone git://gcc.gnu.org/git/gcc.git && cd gcc git checkout -b gcc-10-for-kcsan releases/gcc-10.1.0 git cherry-pick \ 4089df8ef4a63126b0774c39b6638845244c20d2 \ ab2789ec507a94f1a75a6534bca51c7b39037ce0 \ 06712fc68dc9843d9af7c7ac10047f49d305ad76 ./configure --prefix <your-prefix> --enable-languages=c,c++ make -j$(nproc) && make install
Unless there are objections, I will pull this in Friday (tomorrow) afternoon, Pacific Time.
Thanx, Paul
Quoted 14 lines
Marco Elver (3):
kcsan: Re-add GCC as a supported compiler
kcsan: Simplify compiler flags
kcsan: Disable branch tracing in core runtimeDocumentation/dev-tools/kcsan.rst | 3 ++- kernel/kcsan/Makefile | 4 ++-- lib/Kconfig.kcsan | 3 ++- scripts/Makefile.kcsan | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-)Signature · 1 line
2.27.0.290.gba653c62da-goog
Quoted 15 lines · Paul E. McKenney
Quoted 5 lines · Marco Elver
Re-add GCC as a supported compiler and clean up compiler flags.
To use KCSAN with GCC before GCC 11 is released, the following will get a stable GCC 10 and cherry-pick the patches required for KCSAN support:
Quoted 8 lines
git clone git://gcc.gnu.org/git/gcc.git && cd gcc git checkout -b gcc-10-for-kcsan releases/gcc-10.1.0 git cherry-pick \ 4089df8ef4a63126b0774c39b6638845244c20d2 \ ab2789ec507a94f1a75a6534bca51c7b39037ce0 \ 06712fc68dc9843d9af7c7ac10047f49d305ad76 ./configure --prefix <your-prefix> --enable-languages=c,c++ make -j$(nproc) && make install
Quoted 2 lines
Unless there are objections, I will pull this in Friday (tomorrow) afternoon, Pacific Time.
Hearing no objections, queued and pushd, thank you!
Thanx, Paul
Quoted 14 lines
Quoted 14 lines
Marco Elver (3):
kcsan: Re-add GCC as a supported compiler
kcsan: Simplify compiler flags
kcsan: Disable branch tracing in core runtimeDocumentation/dev-tools/kcsan.rst | 3 ++- kernel/kcsan/Makefile | 4 ++-- lib/Kconfig.kcsan | 3 ++- scripts/Makefile.kcsan | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-)Signature · 1 line
2.27.0.290.gba653c62da-goog