Marco Elver | dfd402a | 2019-11-14 19:02:54 +0100 | [diff] [blame] | 1 | # SPDX-License-Identifier: GPL-2.0 |
Marco Elver | 17168f5 | 2020-05-21 16:20:38 +0200 | [diff] [blame] | 2 | # GCC and Clang accept backend options differently. Do not wrap in cc-option, |
| 3 | # because Clang accepts "--param" even if it is unused. |
| 4 | ifdef CONFIG_CC_IS_CLANG |
| 5 | cc-param = -mllvm -$(1) |
| 6 | else |
Marco Elver | e68dcd8 | 2020-06-18 11:31:16 +0200 | [diff] [blame] | 7 | cc-param = --param $(1) |
Marco Elver | 17168f5 | 2020-05-21 16:20:38 +0200 | [diff] [blame] | 8 | endif |
| 9 | |
Marco Elver | 75d75b7 | 2020-05-21 16:20:39 +0200 | [diff] [blame] | 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. |
Marco Elver | 69562e4 | 2021-08-05 14:57:45 +0200 | [diff] [blame] | 12 | kcsan-cflags := -fsanitize=thread -fno-optimize-sibling-calls \ |
Marco Elver | 14e2ac8 | 2020-07-24 09:00:01 +0200 | [diff] [blame] | 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))) \ |
Marco Elver | 75d75b7 | 2020-05-21 16:20:39 +0200 | [diff] [blame] | 14 | $(call cc-param,tsan-distinguish-volatile=1) |
Marco Elver | 69562e4 | 2021-08-05 14:57:45 +0200 | [diff] [blame] | 15 | |
Marco Elver | 116af35 | 2021-11-30 12:44:20 +0100 | [diff] [blame] | 16 | ifdef CONFIG_CC_IS_GCC |
| 17 | # GCC started warning about operations unsupported by the TSan runtime. But |
| 18 | # KCSAN != TSan, so just ignore these warnings. |
| 19 | kcsan-cflags += -Wno-tsan |
| 20 | endif |
| 21 | |
Marco Elver | 69562e4 | 2021-08-05 14:57:45 +0200 | [diff] [blame] | 22 | ifndef CONFIG_KCSAN_WEAK_MEMORY |
| 23 | kcsan-cflags += $(call cc-option,$(call cc-param,tsan-instrument-func-entry-exit=0)) |
| 24 | endif |
| 25 | |
| 26 | export CFLAGS_KCSAN := $(kcsan-cflags) |