ubsan, kcsan: don't combine sanitizer with kcov
Subsystems (3)
PATCH 1/1 ubsan, kcsan: don't combine sanitizer with kcov
Clang does not allow -fsanitize-coverage=trace-{pc,cmp} together with -fsanitize=bounds or with ubsan:
clang: error: argument unused during compilation: '-fsanitize-coverage=trace-pc' [-Werror,-Wunused-command-line-argument]
clang: error: argument unused during compilation: '-fsanitize-coverage=trace-cmp' [-Werror,-Wunused-command-line-argument]
To avoid that case, add a Kconfig dependency. The dependency could go either way, disabling CONFIG_KCOV or CONFIG_UBSAN_BOUNDS when the other is set. I picked the second option here as this seems to have a smaller impact on the resulting kernel.
--- lib/Kconfig.kcsan | 2 +- lib/Kconfig.ubsan | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)
lib/Kconfig.kcsan +1 -1
@@ -5,7 +5,7 @@ config HAVE_ARCH_KCSAN menuconfig KCSAN bool "KCSAN: dynamic data race detector" - depends on HAVE_ARCH_KCSAN && DEBUG_KERNEL && !KASAN + depends on HAVE_ARCH_KCSAN && DEBUG_KERNEL && !KASAN && !KCOV select STACKTRACE help The Kernel Concurrency Sanitizer (KCSAN) is a dynamic
lib/Kconfig.ubsan +1 -0
@@ -29,6 +29,7 @@ config UBSAN_TRAP config UBSAN_BOUNDS bool "Perform array index bounds checking" default UBSAN + depends on !(CC_IS_CLANG && KCOV) help This option enables detection of directly indexed out of bounds array accesses, where the array size is known at compile time.
Signature · 1 line
2.26.0
Marco Elver
maintainerQuoted 23 lines · Arnd Bergmann
Clang does not allow -fsanitize-coverage=trace-{pc,cmp} together with -fsanitize=bounds or with ubsan:
clang: error: argument unused during compilation: '-fsanitize-coverage=trace-pc' [-Werror,-Wunused-command-line-argument]
clang: error: argument unused during compilation: '-fsanitize-coverage=trace-cmp' [-Werror,-Wunused-command-line-argument]To avoid that case, add a
Kconfigdependency. The dependency could go either way, disablingCONFIG_KCOVorCONFIG_UBSAN_BOUNDSwhen the other is set. I picked the second option here as this seems to have a smaller impact on the resulting kernel.Signed-off-by Arnd Bergmann <[email protected]>--- lib/Kconfig.kcsan | 2 +- lib/Kconfig.ubsan | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)lib/Kconfig.kcsan +0
-0
lib/Kconfig.kcsan config HAVE_ARCH_KCSAN · line 8
Quoted 5 lines
lib/Kconfig.kcsan +1
-1@@ -5,7 +5,7 @@ config HAVE_ARCH_KCSAN menuconfig KCSAN bool "KCSAN: dynamic data race detector" - depends on HAVE_ARCH_KCSAN && DEBUG_KERNEL && !KASAN + depends on HAVE_ARCH_KCSAN && DEBUG_KERNEL && !KASAN && !KCOV
This also disables KCOV with GCC. Why does this not work with KCSAN?
This is a huge problem for us, since syzbot requires KCOV. In fact I've always been building KCSAN kernels with CONFIG_KCOV=y (with GCC or Clang) and cannot reproduce the problem.
lib/Kconfig.ubsan config UBSAN_TRAP · line 32
Quoted 12 lines
lib/Kconfig.kcsan +0
-0select STACKTRACE help The Kernel Concurrency Sanitizer (KCSAN) is a dynamiclib/Kconfig.ubsan +1
-0@@ -29,6 +29,7 @@ config UBSAN_TRAP config UBSAN_BOUNDS bool "Perform array index bounds checking" default UBSAN + depends on !(CC_IS_CLANG && KCOV)
Ditto, we really need KCOV for all sanitizers. I also just tried to reproduce the problem but can't.
Which version of clang is causing this? I'm currently using Clang 9. My guess is that we should not fix this by disallowing KCOV, but rather make Clang work with these configs.
Dmitry, can you comment?
Thanks,
-- Marco
Quoted 6 lines
lib/Kconfig.ubsan +0
-1help This option enables detection of directly indexed out of bounds array accesses, where the array size is known at compile time. --2.26.0
Dmitry Vyukov
reviewerQuoted 50 lines · Marco Elver
Quoted 22 lines
Clang does not allow -fsanitize-coverage=trace-{pc,cmp} together with -fsanitize=bounds or with ubsan:
clang: error: argument unused during compilation: '-fsanitize-coverage=trace-pc' [-Werror,-Wunused-command-line-argument]
clang: error: argument unused during compilation: '-fsanitize-coverage=trace-cmp' [-Werror,-Wunused-command-line-argument]To avoid that case, add a
Kconfigdependency. The dependency could go either way, disablingCONFIG_KCOVorCONFIG_UBSAN_BOUNDSwhen the other is set. I picked the second option here as this seems to have a smaller impact on the resulting kernel.Signed-off-by Arnd Bergmann <[email protected]>--- lib/Kconfig.kcsan | 2 +- lib/Kconfig.ubsan | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)lib/Kconfig.kcsan +0
-0lib/Kconfig.kcsan config HAVE_ARCH_KCSAN · line 8
Quoted 5 lines
lib/Kconfig.kcsan +1
-1@@ -5,7 +5,7 @@ config HAVE_ARCH_KCSAN menuconfig KCSAN bool "KCSAN: dynamic data race detector" - depends on HAVE_ARCH_KCSAN && DEBUG_KERNEL && !KASAN + depends on HAVE_ARCH_KCSAN && DEBUG_KERNEL && !KASAN && !KCOVThis also disables KCOV with GCC. Why does this not work with KCSAN?
This is a huge problem for us, since syzbot requires KCOV. In fact I've always been building KCSAN kernels with
CONFIG_KCOV=y(with GCC or Clang) and cannot reproduce the problem.lib/Kconfig.ubsan config UBSAN_TRAP · line 32
Quoted 12 lines
lib/Kconfig.kcsan +0
-0select STACKTRACE help The Kernel Concurrency Sanitizer (KCSAN) is a dynamiclib/Kconfig.ubsan +1
-0@@ -29,6 +29,7 @@ config UBSAN_TRAP config UBSAN_BOUNDS bool "Perform array index bounds checking" default UBSAN + depends on !(CC_IS_CLANG && KCOV)Ditto, we really need KCOV for all sanitizers. I also just tried to reproduce the problem but can't.
Quoted 5 lines
Which version of clang is causing this? I'm currently using Clang 9. My guess is that we should not fix this by disallowing KCOV, but rather make Clang work with these configs.
Dmitry, can you comment?
FWIW I can reproduce both with clang:
$ clang /tmp/test.c -c -fsanitize-coverage=trace-pc -fsanitize=bounds clang-11: warning: argument unused during compilation: '-fsanitize-coverage=trace-pc' [-Wunused-command-line-argument]
$ clang /tmp/test.c -c -fsanitize-coverage=trace-pc -fsanitize=thread clang-11: warning: argument unused during compilation: '-fsanitize-coverage=trace-pc' [-Wunused-command-line-argument]
with both my disto's 9.0.1 and fresher 11.0.0
(7b80cb7cf45faf462d6193cc41c2cb7ad556600d.
But both work with gcc
$ gcc /tmp/test.c -c -fsanitize-coverage=trace-pc -fsanitize=thread $ gcc /tmp/test.c -c -fsanitize-coverage=trace-pc -fsanitize=bounds
Is it a known issue in clang?
Can we somehow disable it only for clang and not gcc?
This will immediately break KCSAN on syzbot as it enables KCSAN and KCOV:
https://syzkaller.appspot.com/upstream?manager=ci2-upstream-kcsan-gce
Quoted 7 lines · Dmitry Vyukov' via Clang Built Linux
Quoted 6 lines · Marco Elver
Quoted 6 lines
Clang does not allow -fsanitize-coverage=trace-{pc,cmp} together with -fsanitize=bounds or with ubsan:
clang: error: argument unused during compilation: '-fsanitize-coverage=trace-pc' [-Werror,-Wunused-command-line-argument]
clang: error: argument unused during compilation: '-fsanitize-coverage=trace-cmp' [-Werror,-Wunused-command-line-argument]
Quoted 6 lines
Quoted 6 lines
Review
Quoted 4 lines
menuconfig KCSAN
bool "KCSAN: dynamic data race detector"(quoted diff) +1
-1- depends on HAVE_ARCH_KCSAN && DEBUG_KERNEL && !KASAN + depends on HAVE_ARCH_KCSAN && DEBUG_KERNEL && !KASAN && !KCOVThis also disables KCOV with GCC. Why does this not work with KCSAN?
My mistake, this should be kept enabled for gcc. If we can get the combination to work in clang, that's something that should also get enabled.
Quoted 3 lines
Quoted 3 lines
This is a huge problem for us, since syzbot requires KCOV. In fact I've always been building KCSAN kernels with
CONFIG_KCOV=y(with GCC or Clang) and cannot reproduce the problem.
I have some local patches that change the way we pick the warning options for each compiler, and enable more of the warnings that are normally disabled.
Maybe -Wunused-command-line-argument is disabled by default?
I only started seeing this problem recently. It's also possible that there are some other options that interact with it so only Kcov+FOO leads to KCSAN being ignored.
Quoted 27 lines
Quoted 8 lines
Ditto, we really need KCOV for all sanitizers. I also just tried to reproduce the problem but can't.
Which version of clang is causing this? I'm currently using Clang 9. My guess is that we should not fix this by disallowing KCOV, but rather make Clang work with these configs.
Dmitry, can you comment?
FWIW I can reproduce both with clang:
$ clang /tmp/test.c -c -fsanitize-coverage=trace-pc -fsanitize=bounds clang-11: warning: argument unused during compilation: '-fsanitize-coverage=trace-pc' [-Wunused-command-line-argument]$ clang /tmp/test.c -c -fsanitize-coverage=trace-pc -fsanitize=thread clang-11: warning: argument unused during compilation: '-fsanitize-coverage=trace-pc' [-Wunused-command-line-argument]with both my disto's 9.0.1 and fresher 11.0.0
(7b80cb7cf45faf462d6193cc41c2cb7ad556600d.But both work with gcc
$ gcc /tmp/test.c -c -fsanitize-coverage=trace-pc -fsanitize=thread $ gcc /tmp/test.c -c -fsanitize-coverage=trace-pc -fsanitize=bounds
Quoted 6 lines
Is it a known issue in clang?
Can we somehow disable it only for clang and not gcc?
This will immediately break KCSAN on syzbot as it enables KCSAN and KCOV:
https://syzkaller.appspot.com/upstream?manager=ci2-upstream-kcsan-gce
I can respin the patch with this fixup if you like:
lib/Kconfig.kcsan +1 -1
@@ -5,7 +5,7 @@ config HAVE_ARCH_KCSAN menuconfig KCSAN bool "KCSAN: dynamic data race detector" - depends on HAVE_ARCH_KCSAN && DEBUG_KERNEL && !KASAN && !KCOV + depends on HAVE_ARCH_KCSAN && DEBUG_KERNEL && !KASAN && !(KCOV
&& CC_IS_CLANG)
select STACKTRACE
help
The Kernel Concurrency Sanitizer (KCSAN) is a dynamic
As you both say, the combination seems to be quite important, so maybe there is something else that can be to also enable it with clang.
Arnd
Marco Elver
maintainerQuoted 15 lines · Arnd Bergmann
Quoted 12 lines · Dmitry Vyukov' via Clang Built Linux
Quoted 11 lines · Marco Elver
Quoted 10 lines
Clang does not allow -fsanitize-coverage=trace-{pc,cmp} together with -fsanitize=bounds or with ubsan:
clang: error: argument unused during compilation: '-fsanitize-coverage=trace-pc' [-Werror,-Wunused-command-line-argument]
clang: error: argument unused during compilation: '-fsanitize-coverage=trace-cmp' [-Werror,-Wunused-command-line-argument]menuconfig KCSAN
bool "KCSAN: dynamic data race detector"(quoted diff) +1
-1- depends on HAVE_ARCH_KCSAN && DEBUG_KERNEL && !KASAN + depends on HAVE_ARCH_KCSAN && DEBUG_KERNEL && !KASAN && !KCOV
Quoted 4 lines
Quoted 1 line
Quoted 1 line
This also disables KCOV with GCC. Why does this not work with KCSAN?
My mistake, this should be kept enabled for gcc. If we can get the combination to work in clang, that's something that should also get enabled.
See my suggestion below how we might dynamically determine if the combination is supported.
Quoted 11 lines
Quoted 3 lines
Quoted 3 lines
This is a huge problem for us, since syzbot requires KCOV. In fact I've always been building KCSAN kernels with
CONFIG_KCOV=y(with GCC or Clang) and cannot reproduce the problem.I have some local patches that change the way we pick the warning options for each compiler, and enable more of the warnings that are normally disabled.
Maybe -Wunused-command-line-argument is disabled by default?
I only started seeing this problem recently. It's also possible that there are some other options that interact with it so only Kcov+FOO leads to KCSAN being ignored.
I see. It certainly seems quite bad if one or the other option is effectively ignored.
Quoted 39 lines
Quoted 27 lines
Quoted 8 lines
Ditto, we really need KCOV for all sanitizers. I also just tried to reproduce the problem but can't.
Which version of clang is causing this? I'm currently using Clang 9. My guess is that we should not fix this by disallowing KCOV, but rather make Clang work with these configs.
Dmitry, can you comment?
FWIW I can reproduce both with clang:
$ clang /tmp/test.c -c -fsanitize-coverage=trace-pc -fsanitize=bounds clang-11: warning: argument unused during compilation: '-fsanitize-coverage=trace-pc' [-Wunused-command-line-argument]$ clang /tmp/test.c -c -fsanitize-coverage=trace-pc -fsanitize=thread clang-11: warning: argument unused during compilation: '-fsanitize-coverage=trace-pc' [-Wunused-command-line-argument]with both my disto's 9.0.1 and fresher 11.0.0
(7b80cb7cf45faf462d6193cc41c2cb7ad556600d.But both work with gcc
$ gcc /tmp/test.c -c -fsanitize-coverage=trace-pc -fsanitize=thread $ gcc /tmp/test.c -c -fsanitize-coverage=trace-pc -fsanitize=boundsQuoted 6 lines
Is it a known issue in clang?
Can we somehow disable it only for clang and not gcc?
This will immediately break KCSAN on syzbot as it enables KCSAN and KCOV:
https://syzkaller.appspot.com/upstream?manager=ci2-upstream-kcsan-gceI can respin the patch with this fixup if you like:
lib/Kconfig.kcsan config HAVE_ARCH_KCSAN · line 9
Quoted 6 lines
lib/Kconfig.kcsan +1
-1@@ -5,7 +5,7 @@ config HAVE_ARCH_KCSAN menuconfig KCSAN bool "KCSAN: dynamic data race detector" - depends on HAVE_ARCH_KCSAN && DEBUG_KERNEL && !KASAN && !KCOV + depends on HAVE_ARCH_KCSAN && DEBUG_KERNEL && !KASAN && !(KCOV && CC_IS_CLANG)
I wonder if we can just add this: depends on !(KCOV && !$(cc-option,-Werror -fsanitize=thread -fsanitize-coverage=trace-pc))
Similarly for UBSAN.
That way, once Clang supports this combination, we don't need another patch to fix it.
Thanks,
-- Marco
Quoted 8 lines
lib/Kconfig.kcsan +0
-0select STACKTRACE helpThe Kernel Concurrency Sanitizer (KCSAN) is a dynamic
As you both say, the combination seems to be quite important, so maybe there is something else that can be to also enable it with clang.
Arnd
Quoted 13 lines · Marco Elver' via Clang Built Linux
lib/Kconfig.kcsan config HAVE_ARCH_KCSAN · line 9
Quoted 9 lines
lib/Kconfig.kcsan +1
-1@@ -5,7 +5,7 @@ config HAVE_ARCH_KCSAN menuconfig KCSAN bool "KCSAN: dynamic data race detector" - depends on HAVE_ARCH_KCSAN && DEBUG_KERNEL && !KASAN && !KCOV + depends on HAVE_ARCH_KCSAN && DEBUG_KERNEL && !KASAN && !(KCOV && CC_IS_CLANG)I wonder if we can just add this: depends on !(KCOV && !$(cc-option,-Werror -fsanitize=thread -fsanitize-coverage=trace-pc))
Quoted 4 lines
Similarly for UBSAN.
That way, once Clang supports this combination, we don't need another patch to fix it.
Good idea. It probably get a little more complicated because kcov uses different flags depending on other options:
kcov-flags-$(CONFIG_CC_HAS_SANCOV_TRACE_PC) += -fsanitize-coverage=trace-pc kcov-flags-$(CONFIG_KCOV_ENABLE_COMPARISONS) += -fsanitize-coverage=trace-cmp kcov-flags-$(CONFIG_GCC_PLUGIN_SANCOV) +=
-fplugin=$(objtree)/scripts/gcc-plugins/sancov_plugin.so
Do you have any preference on whether we should make KCSAN or KCOV conditional in this case? It may be easier to move the compiletime check into CONFIG_KCOV_ENABLE_COMPARISONS and CONFIG_CC_HAS_SANCOV_TRACE_PC.
Arnd
Marco Elver
maintainerQuoted 28 lines · Arnd Bergmann
Quoted 13 lines · Marco Elver' via Clang Built Linux
lib/Kconfig.kcsan config HAVE_ARCH_KCSAN · line 9
Quoted 9 lines
lib/Kconfig.kcsan +1
-1@@ -5,7 +5,7 @@ config HAVE_ARCH_KCSAN menuconfig KCSAN bool "KCSAN: dynamic data race detector" - depends on HAVE_ARCH_KCSAN && DEBUG_KERNEL && !KASAN && !KCOV + depends on HAVE_ARCH_KCSAN && DEBUG_KERNEL && !KASAN && !(KCOV && CC_IS_CLANG)I wonder if we can just add this: depends on !(KCOV && !$(cc-option,-Werror -fsanitize=thread -fsanitize-coverage=trace-pc))
Quoted 4 lines
Similarly for UBSAN.
That way, once Clang supports this combination, we don't need another patch to fix it.
Good idea. It probably get a little more complicated because kcov uses different flags depending on other options:
kcov-flags-$(CONFIG_CC_HAS_SANCOV_TRACE_PC) += -fsanitize-coverage=trace-pc kcov-flags-$(CONFIG_KCOV_ENABLE_COMPARISONS) += -fsanitize-coverage=trace-cmp kcov-flags-$(CONFIG_GCC_PLUGIN_SANCOV) +=
Quoted 6 lines
-fplugin=$(objtree)/scripts/gcc-plugins/sancov_plugin.so
Do you have any preference on whether we should make KCSAN or KCOV conditional in this case? It may be easier to move the compiletime check into
CONFIG_KCOV_ENABLE_COMPARISONSandCONFIG_CC_HAS_SANCOV_TRACE_PC.
Whichever is easier. I think if we have a config that tries to set both, but then one gets silently disabled, it likely already breaks the usecase. It'd be nice if there was a way to warn about only one being selected so that a developer can then go back and choose the one they're most interested in (or change compiler).
Thanks,
-- Marco
PATCH v2 1/1 ubsan, kcsan: don't combine sanitizer with kcov on clang
Clang does not allow -fsanitize-coverage=trace-{pc,cmp} together with -fsanitize=bounds or with ubsan:
clang: error: argument unused during compilation: '-fsanitize-coverage=trace-pc' [-Werror,-Wunused-command-line-argument]
clang: error: argument unused during compilation: '-fsanitize-coverage=trace-cmp' [-Werror,-Wunused-command-line-argument]
To avoid the warning, check whether clang can handle this correctly or disallow ubsan and kcsan when kcov is enabled.
---
v2: this implements Marco's suggestion to check what the compiler actually supports, and references the bug report I now opened.
Let's wait for replies on that bug report before this gets applied, in case the feedback there changes the conclusion.
--- lib/Kconfig.kcsan | 11 +++++++++++ lib/Kconfig.ubsan | 11 +++++++++++ 2 files changed, 22 insertions(+)
lib/Kconfig.kcsan +11 -0
@@ -3,9 +3,20 @@ config HAVE_ARCH_KCSAN bool +config KCSAN_KCOV_BROKEN + def_bool KCOV && CC_HAS_SANCOV_TRACE_PC + depends on CC_IS_CLANG + depends on !$(cc-option,-Werror=unused-command-line-argument -fsanitize=thread -fsanitize-coverage=trace-pc) + help + Some versions of clang support either KCSAN and KCOV but not the + combination of the two. + See https://bugs.llvm.org/show_bug.cgi?id=45831 for the status + in newer releases. + menuconfig KCSAN bool "KCSAN: dynamic data race detector" depends on HAVE_ARCH_KCSAN && DEBUG_KERNEL && !KASAN + depends on !KCSAN_KCOV_BROKEN select STACKTRACE help The Kernel Concurrency Sanitizer (KCSAN) is a dynamic
lib/Kconfig.ubsan +11 -0
@@ -26,9 +26,20 @@ config UBSAN_TRAP the system. For some system builders this is an acceptable trade-off. +config UBSAN_KCOV_BROKEN + def_bool KCOV && CC_HAS_SANCOV_TRACE_PC + depends on CC_IS_CLANG + depends on !$(cc-option,-Werror=unused-command-line-argument -fsanitize=bounds -fsanitize-coverage=trace-pc) + help + Some versions of clang support either UBSAN or KCOV but not the + combination of the two. + See https://bugs.llvm.org/show_bug.cgi?id=45831 for the status + in newer releases. + config UBSAN_BOUNDS bool "Perform array index bounds checking" default UBSAN + depends on !UBSAN_KCOV_BROKEN help This option enables detection of directly indexed out of bounds array accesses, where the array size is known at compile time.
Signature · 1 line
2.26.0
Re: [PATCH] [v2] ubsan, kcsan: don't combine sanitizer with kcov on clang
Quoted 13 lines · Arnd Bergmann
Clang does not allow -fsanitize-coverage=trace-{pc,cmp} together with -fsanitize=bounds or with ubsan:
clang: error: argument unused during compilation: '-fsanitize-coverage=trace-pc' [-Werror,-Wunused-command-line-argument]
clang: error: argument unused during compilation: '-fsanitize-coverage=trace-cmp' [-Werror,-Wunused-command-line-argument]To avoid the warning, check whether clang can handle this correctly or disallow ubsan and kcsan when kcov is enabled.
Quoted 6 lines
---
v2: this implements Marco's suggestion to check what the compiler actually supports, and references the bug report I now opened.Let's wait for replies on that bug report before this gets applied, in case the feedback there changes the conclusion.
Waiting makes sense, if this is not very urgent.
Thank you!
Quoted 58 lines
--- lib/Kconfig.kcsan | 11 +++++++++++ lib/Kconfig.ubsan | 11 +++++++++++ 2 files changed, 22 insertions(+)lib/Kconfig.kcsan +11
-0@@ -3,9 +3,20 @@ config HAVE_ARCH_KCSAN bool +config KCSAN_KCOV_BROKEN + def_bool KCOV && CC_HAS_SANCOV_TRACE_PC + depends on CC_IS_CLANG + depends on !$(cc-option,-Werror=unused-command-line-argument -fsanitize=thread -fsanitize-coverage=trace-pc) + help + Some versions of clang support either KCSAN and KCOV but not the + combination of the two. + See https://bugs.llvm.org/show_bug.cgi?id=45831 for the status + in newer releases. + menuconfig KCSAN bool "KCSAN: dynamic data race detector" depends on HAVE_ARCH_KCSAN && DEBUG_KERNEL && !KASAN + depends on !KCSAN_KCOV_BROKEN select STACKTRACE help The Kernel Concurrency Sanitizer (KCSAN) is a dynamiclib/Kconfig.ubsan +11
-1@@ -26,9 +26,20 @@ config UBSAN_TRAP the system. For some system builders this is an acceptable trade-off. +config UBSAN_KCOV_BROKEN + def_bool KCOV && CC_HAS_SANCOV_TRACE_PC + depends on CC_IS_CLANG + depends on !$(cc-option,-Werror=unused-command-line-argument -fsanitize=bounds -fsanitize-coverage=trace-pc) + help + Some versions of clang support either UBSAN or KCOV but not the + combination of the two. + See https://bugs.llvm.org/show_bug.cgi?id=45831 for the status + in newer releases. + config UBSAN_BOUNDS bool "Perform array index bounds checking" default UBSAN + depends on !UBSAN_KCOV_BROKEN help This option enables detection of directly indexed out of bounds array accesses, where the array size is known at compile time. --2.26.0
Re: [PATCH] [v2] ubsan, kcsan: don't combine sanitizer with kcov on clang
In reply to Arnd BergmannQuoted 6 lines · Arnd Bergmann
Clang does not allow -fsanitize-coverage=trace-{pc,cmp} together with -fsanitize=bounds or with ubsan:
clang: error: argument unused during compilation: '-fsanitize-coverage=trace-pc' [-Werror,-Wunused-command-line-argument]
clang: error: argument unused during compilation: '-fsanitize-coverage=trace-cmp' [-Werror,-Wunused-command-line-argument]
Quoted 6 lines
To avoid the warning, check whether clang can handle this correctly or disallow ubsan and kcsan when kcov is enabled.
Applied for v5.9 and pushed, thank you!
Thanx, Paul
Quoted 64 lines
---
v2: this implements Marco's suggestion to check what the compiler actually supports, and references the bug report I now opened.Let's wait for replies on that bug report before this gets applied, in case the feedback there changes the conclusion.
--- lib/Kconfig.kcsan | 11 +++++++++++ lib/Kconfig.ubsan | 11 +++++++++++ 2 files changed, 22 insertions(+)lib/Kconfig.kcsan +11
-0@@ -3,9 +3,20 @@ config HAVE_ARCH_KCSAN bool +config KCSAN_KCOV_BROKEN + def_bool KCOV && CC_HAS_SANCOV_TRACE_PC + depends on CC_IS_CLANG + depends on !$(cc-option,-Werror=unused-command-line-argument -fsanitize=thread -fsanitize-coverage=trace-pc) + help + Some versions of clang support either KCSAN and KCOV but not the + combination of the two. + See https://bugs.llvm.org/show_bug.cgi?id=45831 for the status + in newer releases. + menuconfig KCSAN bool "KCSAN: dynamic data race detector" depends on HAVE_ARCH_KCSAN && DEBUG_KERNEL && !KASAN + depends on !KCSAN_KCOV_BROKEN select STACKTRACE help The Kernel Concurrency Sanitizer (KCSAN) is a dynamiclib/Kconfig.ubsan +11
-0@@ -26,9 +26,20 @@ config UBSAN_TRAP the system. For some system builders this is an acceptable trade-off. +config UBSAN_KCOV_BROKEN + def_bool KCOV && CC_HAS_SANCOV_TRACE_PC + depends on CC_IS_CLANG + depends on !$(cc-option,-Werror=unused-command-line-argument -fsanitize=bounds -fsanitize-coverage=trace-pc) + help + Some versions of clang support either UBSAN or KCOV but not the + combination of the two. + See https://bugs.llvm.org/show_bug.cgi?id=45831 for the status + in newer releases. + config UBSAN_BOUNDS bool "Perform array index bounds checking" default UBSAN + depends on !UBSAN_KCOV_BROKEN help This option enables detection of directly indexed out of bounds array accesses, where the array size is known at compile time.Signature · 1 line
2.26.0
[tip: locking/kcsan] ubsan, kcsan: Don't combine sanitizer with kcov on clang
In reply to Arnd BergmannThe following commit has been merged into the locking/kcsan branch of tip:
The following commit has been merged into the locking/kcsan branch of tip:
Commit-ID: e87c5783e9e43ec8bd5c0a1cf7cfa4add33603b0 Gitweb: https://git.kernel.org/tip/e87c5783e9e43ec8bd5c0a1cf7cfa4add33603b0 Author: Arnd Bergmann <[email protected]> AuthorDate: Thu, 21 May 2020 16:20:37 +02:00 Committer: Borislav Petkov <[email protected]> CommitterDate: Fri, 22 May 2020 14:34:26 +02:00
ubsan, kcsan: Don't combine sanitizer with kcov on clang
Clang does not allow -fsanitize-coverage=trace-{pc,cmp} together with -fsanitize=bounds or with ubsan:
clang: error: argument unused during compilation: '-fsanitize-coverage=trace-pc' [-Werror,-Wunused-command-line-argument]
clang: error: argument unused during compilation: '-fsanitize-coverage=trace-cmp' [-Werror,-Wunused-command-line-argument]
To avoid the warning, check whether clang can handle this correctly or disallow ubsan and kcsan when kcov is enabled.
--- lib/Kconfig.kcsan | 11 +++++++++++ lib/Kconfig.ubsan | 11 +++++++++++ 2 files changed, 22 insertions(+)
lib/Kconfig.kcsan +11 -0
@@ -3,9 +3,20 @@ config HAVE_ARCH_KCSAN bool +config KCSAN_KCOV_BROKEN + def_bool KCOV && CC_HAS_SANCOV_TRACE_PC + depends on CC_IS_CLANG + depends on !$(cc-option,-Werror=unused-command-line-argument -fsanitize=thread -fsanitize-coverage=trace-pc) + help + Some versions of clang support either KCSAN and KCOV but not the + combination of the two. + See https://bugs.llvm.org/show_bug.cgi?id=45831 for the status + in newer releases. + menuconfig KCSAN bool "KCSAN: dynamic data race detector" depends on HAVE_ARCH_KCSAN && DEBUG_KERNEL && !KASAN + depends on !KCSAN_KCOV_BROKEN select STACKTRACE help The Kernel Concurrency Sanitizer (KCSAN) is a dynamic
lib/Kconfig.ubsan +11 -0
@@ -26,9 +26,20 @@ config UBSAN_TRAP the system. For some system builders this is an acceptable trade-off. +config UBSAN_KCOV_BROKEN + def_bool KCOV && CC_HAS_SANCOV_TRACE_PC + depends on CC_IS_CLANG + depends on !$(cc-option,-Werror=unused-command-line-argument -fsanitize=bounds -fsanitize-coverage=trace-pc) + help + Some versions of clang support either UBSAN or KCOV but not the + combination of the two. + See https://bugs.llvm.org/show_bug.cgi?id=45831 for the status + in newer releases. + config UBSAN_BOUNDS bool "Perform array index bounds checking" default UBSAN + depends on !UBSAN_KCOV_BROKEN help This option enables detection of directly indexed out of bounds array accesses, where the array size is known at compile time.