blob: 19f693b68a968f7a23c7eae0631c73d0f8e0a6af [file] [log] [blame]
Marco Elverdfd402a2019-11-14 19:02:54 +01001# SPDX-License-Identifier: GPL-2.0
Marco Elver17168f52020-05-21 16:20:38 +02002# 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
Marco Elvere68dcd82020-06-18 11:31:16 +02007cc-param = --param $(1)
Marco Elver17168f52020-05-21 16:20:38 +02008endif
9
Marco Elver75d75b72020-05-21 16:20:39 +020010# 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.
Marco Elver69562e42021-08-05 14:57:45 +020012kcsan-cflags := -fsanitize=thread -fno-optimize-sibling-calls \
Marco Elver14e2ac82020-07-24 09:00:01 +020013 $(call cc-option,$(call cc-param,tsan-compound-read-before-write=1),$(call cc-option,$(call cc-param,tsan-instrument-read-before-write=1))) \
Marco Elver75d75b72020-05-21 16:20:39 +020014 $(call cc-param,tsan-distinguish-volatile=1)
Marco Elver69562e42021-08-05 14:57:45 +020015
Marco Elver116af352021-11-30 12:44:20 +010016ifdef CONFIG_CC_IS_GCC
17# GCC started warning about operations unsupported by the TSan runtime. But
18# KCSAN != TSan, so just ignore these warnings.
19kcsan-cflags += -Wno-tsan
20endif
21
Marco Elver69562e42021-08-05 14:57:45 +020022ifndef CONFIG_KCSAN_WEAK_MEMORY
23kcsan-cflags += $(call cc-option,$(call cc-param,tsan-instrument-func-entry-exit=0))
24endif
25
26export CFLAGS_KCSAN := $(kcsan-cflags)