162306a36Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0
262306a36Sopenharmony_ci# GCC and Clang accept backend options differently. Do not wrap in cc-option,
362306a36Sopenharmony_ci# because Clang accepts "--param" even if it is unused.
462306a36Sopenharmony_ciifdef CONFIG_CC_IS_CLANG
562306a36Sopenharmony_cicc-param = -mllvm -$(1)
662306a36Sopenharmony_cielse
762306a36Sopenharmony_cicc-param = --param $(1)
862306a36Sopenharmony_ciendif
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ci# Keep most options here optional, to allow enabling more compilers if absence
1162306a36Sopenharmony_ci# of some options does not break KCSAN nor causes false positive reports.
1262306a36Sopenharmony_cikcsan-cflags := -fsanitize=thread -fno-optimize-sibling-calls \
1362306a36Sopenharmony_ci	$(call cc-option,$(call cc-param,tsan-compound-read-before-write=1),$(call cc-option,$(call cc-param,tsan-instrument-read-before-write=1))) \
1462306a36Sopenharmony_ci	$(call cc-param,tsan-distinguish-volatile=1)
1562306a36Sopenharmony_ci
1662306a36Sopenharmony_ciifdef CONFIG_CC_IS_GCC
1762306a36Sopenharmony_ci# GCC started warning about operations unsupported by the TSan runtime. But
1862306a36Sopenharmony_ci# KCSAN != TSan, so just ignore these warnings.
1962306a36Sopenharmony_cikcsan-cflags += -Wno-tsan
2062306a36Sopenharmony_ciendif
2162306a36Sopenharmony_ci
2262306a36Sopenharmony_ciifndef CONFIG_KCSAN_WEAK_MEMORY
2362306a36Sopenharmony_cikcsan-cflags += $(call cc-option,$(call cc-param,tsan-instrument-func-entry-exit=0))
2462306a36Sopenharmony_ciendif
2562306a36Sopenharmony_ci
2662306a36Sopenharmony_ciexport CFLAGS_KCSAN := $(kcsan-cflags)
27