Back to home page

OSCL-LXR

 
 

    


0001 # SPDX-License-Identifier: GPL-2.0
0002 CFLAGS_KASAN_NOSANITIZE := -fno-builtin
0003 KASAN_SHADOW_OFFSET ?= $(CONFIG_KASAN_SHADOW_OFFSET)
0004 
0005 cc-param = $(call cc-option, -mllvm -$(1), $(call cc-option, --param $(1)))
0006 
0007 ifdef CONFIG_KASAN_STACK
0008         stack_enable := 1
0009 else
0010         stack_enable := 0
0011 endif
0012 
0013 ifdef CONFIG_KASAN_GENERIC
0014 
0015 ifdef CONFIG_KASAN_INLINE
0016         call_threshold := 10000
0017 else
0018         call_threshold := 0
0019 endif
0020 
0021 CFLAGS_KASAN_MINIMAL := -fsanitize=kernel-address
0022 
0023 # -fasan-shadow-offset fails without -fsanitize
0024 CFLAGS_KASAN_SHADOW := $(call cc-option, -fsanitize=kernel-address \
0025                         -fasan-shadow-offset=$(KASAN_SHADOW_OFFSET), \
0026                         $(call cc-option, -fsanitize=kernel-address \
0027                         -mllvm -asan-mapping-offset=$(KASAN_SHADOW_OFFSET)))
0028 
0029 ifeq ($(strip $(CFLAGS_KASAN_SHADOW)),)
0030         CFLAGS_KASAN := $(CFLAGS_KASAN_MINIMAL)
0031 else
0032         # Now add all the compiler specific options that are valid standalone
0033         CFLAGS_KASAN := $(CFLAGS_KASAN_SHADOW) \
0034          $(call cc-param,asan-globals=1) \
0035          $(call cc-param,asan-instrumentation-with-call-threshold=$(call_threshold)) \
0036          $(call cc-param,asan-instrument-allocas=1)
0037 endif
0038 
0039 CFLAGS_KASAN += $(call cc-param,asan-stack=$(stack_enable))
0040 
0041 endif # CONFIG_KASAN_GENERIC
0042 
0043 ifdef CONFIG_KASAN_SW_TAGS
0044 
0045 ifdef CONFIG_KASAN_INLINE
0046     instrumentation_flags := $(call cc-param,hwasan-mapping-offset=$(KASAN_SHADOW_OFFSET))
0047 else
0048     instrumentation_flags := $(call cc-param,hwasan-instrument-with-calls=1)
0049 endif
0050 
0051 CFLAGS_KASAN := -fsanitize=kernel-hwaddress \
0052                 $(call cc-param,hwasan-instrument-stack=$(stack_enable)) \
0053                 $(call cc-param,hwasan-use-short-granules=0) \
0054                 $(call cc-param,hwasan-inline-all-checks=0) \
0055                 $(instrumentation_flags)
0056 
0057 endif # CONFIG_KASAN_SW_TAGS
0058 
0059 export CFLAGS_KASAN CFLAGS_KASAN_NOSANITIZE