Makefile.kasan 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. ifdef CONFIG_KASAN
  2. ifdef CONFIG_KASAN_INLINE
  3. call_threshold := 10000
  4. else
  5. call_threshold := 0
  6. endif
  7. KASAN_SHADOW_OFFSET ?= $(CONFIG_KASAN_SHADOW_OFFSET)
  8. CFLAGS_KASAN_MINIMAL := -fsanitize=kernel-address
  9. cc-param = $(call cc-option, -mllvm -$(1), $(call cc-option, --param $(1)))
  10. ifeq ($(call cc-option, $(CFLAGS_KASAN_MINIMAL) -Werror),)
  11. ifneq ($(CONFIG_COMPILE_TEST),y)
  12. $(warning Cannot use CONFIG_KASAN: \
  13. -fsanitize=kernel-address is not supported by compiler)
  14. endif
  15. else
  16. # -fasan-shadow-offset fails without -fsanitize
  17. CFLAGS_KASAN_SHADOW := $(call cc-option, -fsanitize=kernel-address \
  18. -fasan-shadow-offset=$(KASAN_SHADOW_OFFSET), \
  19. $(call cc-option, -fsanitize=kernel-address \
  20. -mllvm -asan-mapping-offset=$(KASAN_SHADOW_OFFSET)))
  21. ifeq ($(strip $(CFLAGS_KASAN_SHADOW)),)
  22. CFLAGS_KASAN := $(CFLAGS_KASAN_MINIMAL)
  23. else
  24. # Now add all the compiler specific options that are valid standalone
  25. CFLAGS_KASAN := $(CFLAGS_KASAN_SHADOW) \
  26. $(call cc-param,asan-globals=1) \
  27. $(call cc-param,asan-instrumentation-with-call-threshold=$(call_threshold)) \
  28. $(call cc-param,asan-stack=1) \
  29. $(call cc-param,asan-use-after-scope=1) \
  30. $(call cc-param,asan-instrument-allocas=1)
  31. endif
  32. endif
  33. CFLAGS_KASAN_NOSANITIZE := -fno-builtin
  34. endif