Makefile.kcsan 1004 B

1234567891011121314151617181920212223242526
  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.
  4. ifdef CONFIG_CC_IS_CLANG
  5. cc-param = -mllvm -$(1)
  6. else
  7. cc-param = --param $(1)
  8. endif
  9. # Keep most options here optional, to allow enabling more compilers if absence
  10. # of some options does not break KCSAN nor causes false positive reports.
  11. kcsan-cflags := -fsanitize=thread -fno-optimize-sibling-calls \
  12. $(call cc-option,$(call cc-param,tsan-compound-read-before-write=1),$(call cc-option,$(call cc-param,tsan-instrument-read-before-write=1))) \
  13. $(call cc-param,tsan-distinguish-volatile=1)
  14. ifdef CONFIG_CC_IS_GCC
  15. # GCC started warning about operations unsupported by the TSan runtime. But
  16. # KCSAN != TSan, so just ignore these warnings.
  17. kcsan-cflags += -Wno-tsan
  18. endif
  19. ifndef CONFIG_KCSAN_WEAK_MEMORY
  20. kcsan-cflags += $(call cc-option,$(call cc-param,tsan-instrument-func-entry-exit=0))
  21. endif
  22. export CFLAGS_KCSAN := $(kcsan-cflags)