mirror of
https://github.com/torvalds/linux.git
synced 2024-11-27 06:31:52 +00:00
d31d4d6bb2
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] 151ed6aa38
Signed-off-by: Marco Elver <elver@google.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: Will Deacon <will@kernel.org>
Link: https://lkml.kernel.org/r/20200521142047.169334-5-elver@google.com
20 lines
706 B
Makefile
20 lines
706 B
Makefile
# SPDX-License-Identifier: GPL-2.0
|
|
ifdef CONFIG_KCSAN
|
|
|
|
# GCC and Clang accept backend options differently. Do not wrap in cc-option,
|
|
# because Clang accepts "--param" even if it is unused.
|
|
ifdef CONFIG_CC_IS_CLANG
|
|
cc-param = -mllvm -$(1)
|
|
else
|
|
cc-param = --param -$(1)
|
|
endif
|
|
|
|
# Keep most options here optional, to allow enabling more compilers if absence
|
|
# of some options does not break KCSAN nor causes false positive reports.
|
|
CFLAGS_KCSAN := -fsanitize=thread \
|
|
$(call cc-option,$(call cc-param,tsan-instrument-func-entry-exit=0) -fno-optimize-sibling-calls) \
|
|
$(call cc-option,$(call cc-param,tsan-instrument-read-before-write=1)) \
|
|
$(call cc-param,tsan-distinguish-volatile=1)
|
|
|
|
endif # CONFIG_KCSAN
|