xref: /openbmc/linux/scripts/Makefile.kcsan (revision 69562e49)
1# SPDX-License-Identifier: GPL-2.0
2# GCC and Clang accept backend options differently. Do not wrap in cc-option,
3# because Clang accepts "--param" even if it is unused.
4ifdef CONFIG_CC_IS_CLANG
5cc-param = -mllvm -$(1)
6else
7cc-param = --param $(1)
8endif
9
10# Keep most options here optional, to allow enabling more compilers if absence
11# of some options does not break KCSAN nor causes false positive reports.
12kcsan-cflags := -fsanitize=thread -fno-optimize-sibling-calls \
13	$(call cc-option,$(call cc-param,tsan-compound-read-before-write=1),$(call cc-option,$(call cc-param,tsan-instrument-read-before-write=1))) \
14	$(call cc-param,tsan-distinguish-volatile=1)
15
16ifndef CONFIG_KCSAN_WEAK_MEMORY
17kcsan-cflags += $(call cc-option,$(call cc-param,tsan-instrument-func-entry-exit=0))
18endif
19
20export CFLAGS_KCSAN := $(kcsan-cflags)
21