[lkml]   [2020]   [May]   [22]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
Patch in this message
Subject[tip: locking/kcsan] kcsan: Avoid inserting __tsan_func_entry/exit if possible
The following commit has been merged into the locking/kcsan branch of tip:

Commit-ID: 3bc9e5b0725b353b921feaf2c10bb4a9f932646f
Author: Marco Elver <>
AuthorDate: Thu, 21 May 2020 16:20:38 +02:00
Committer: Borislav Petkov <>
CommitterDate: Fri, 22 May 2020 14:36:19 +02:00

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

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 <>
Signed-off-by: Borislav Petkov <>
Acked-by: Will Deacon <>
Acked-by: Peter Zijlstra (Intel) <>
scripts/Makefile.kcsan | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/scripts/Makefile.kcsan b/scripts/Makefile.kcsan
index caf1111..20337a7 100644
--- a/scripts/Makefile.kcsan
+++ b/scripts/Makefile.kcsan
@@ -1,6 +1,15 @@
# SPDX-License-Identifier: GPL-2.0

-CFLAGS_KCSAN := -fsanitize=thread
+# GCC and Clang accept backend options differently. Do not wrap in cc-option,
+# because Clang accepts "--param" even if it is unused.
+cc-param = -mllvm -$(1)
+cc-param = --param -$(1)
+CFLAGS_KCSAN := -fsanitize=thread \
+ $(call cc-option,$(call cc-param,tsan-instrument-func-entry-exit=0) -fno-optimize-sibling-calls)

 \ /
  Last update: 2020-05-22 18:09    [W:0.151 / U:0.008 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site