Skip to content

Commit d31d4d6

Browse files
melverKAGA-KOKO
authored andcommitted
kcsan: Pass option tsan-instrument-read-before-write to Clang
Clang (unlike GCC) removes reads before writes with matching addresses in the same basic block. This is an optimization for TSAN, since writes will always cause conflict if the preceding read would have. However, for KCSAN we cannot rely on this option, because we apply several special rules to writes, in particular when the KCSAN_ASSUME_PLAIN_WRITES_ATOMIC option is selected. To avoid missing potential data races, pass the -tsan-instrument-read-before-write option to Clang if it is available [1]. [1] llvm/llvm-project@151ed6a Signed-off-by: Marco Elver <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Acked-by: Peter Zijlstra (Intel) <[email protected]> Acked-by: Will Deacon <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 75d75b7 commit d31d4d6

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

scripts/Makefile.kcsan

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ endif
1313
# of some options does not break KCSAN nor causes false positive reports.
1414
CFLAGS_KCSAN := -fsanitize=thread \
1515
$(call cc-option,$(call cc-param,tsan-instrument-func-entry-exit=0) -fno-optimize-sibling-calls) \
16+
$(call cc-option,$(call cc-param,tsan-instrument-read-before-write=1)) \
1617
$(call cc-param,tsan-distinguish-volatile=1)
1718

1819
endif # CONFIG_KCSAN

0 commit comments

Comments
 (0)