Skip to content

Commit 17168f5

Browse files
melverKAGA-KOKO
authored andcommitted
kcsan: Avoid inserting __tsan_func_entry/exit if possible
To avoid inserting __tsan_func_{entry,exit}, add option if supported by compiler. Currently only Clang can be told to not emit calls to these functions. It is safe to not emit these, since KCSAN does not rely on them. Note that, if we disable __tsan_func_{entry,exit}(), we need to disable tail-call optimization in sanitized compilation units, as otherwise we may skip frames in the stack trace; in particular when the tail called function is one of the KCSAN's runtime functions, and a report is generated, we might miss the function where the actual access occurred. Since __tsan_func_{entry,exit}() insertion effectively disabled tail-call optimization, there should be no observable change. This was caught and confirmed with kcsan-test & UNWINDER_ORC. Signed-off-by: Marco Elver <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Acked-by: Will Deacon <[email protected]> Acked-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent ea91a1d commit 17168f5

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

scripts/Makefile.kcsan

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
# SPDX-License-Identifier: GPL-2.0
22
ifdef CONFIG_KCSAN
33

4-
CFLAGS_KCSAN := -fsanitize=thread
4+
# GCC and Clang accept backend options differently. Do not wrap in cc-option,
5+
# because Clang accepts "--param" even if it is unused.
6+
ifdef CONFIG_CC_IS_CLANG
7+
cc-param = -mllvm -$(1)
8+
else
9+
cc-param = --param -$(1)
10+
endif
11+
12+
CFLAGS_KCSAN := -fsanitize=thread \
13+
$(call cc-option,$(call cc-param,tsan-instrument-func-entry-exit=0) -fno-optimize-sibling-calls)
514

615
endif # CONFIG_KCSAN

0 commit comments

Comments
 (0)