hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/scripts/Makefile.kasan
....@@ -1,4 +1,15 @@
11 # SPDX-License-Identifier: GPL-2.0
2
+CFLAGS_KASAN_NOSANITIZE := -fno-builtin
3
+KASAN_SHADOW_OFFSET ?= $(CONFIG_KASAN_SHADOW_OFFSET)
4
+
5
+cc-param = $(call cc-option, -mllvm -$(1), $(call cc-option, --param $(1)))
6
+
7
+ifdef CONFIG_KASAN_STACK
8
+ stack_enable := 1
9
+else
10
+ stack_enable := 0
11
+endif
12
+
213 ifdef CONFIG_KASAN_GENERIC
314
415 ifdef CONFIG_KASAN_INLINE
....@@ -7,11 +18,7 @@
718 call_threshold := 0
819 endif
920
10
-KASAN_SHADOW_OFFSET ?= $(CONFIG_KASAN_SHADOW_OFFSET)
11
-
1221 CFLAGS_KASAN_MINIMAL := -fsanitize=kernel-address
13
-
14
-cc-param = $(call cc-option, -mllvm -$(1), $(call cc-option, --param $(1)))
1522
1623 # -fasan-shadow-offset fails without -fsanitize
1724 CFLAGS_KASAN_SHADOW := $(call cc-option, -fsanitize=kernel-address \
....@@ -26,7 +33,7 @@
2633 CFLAGS_KASAN := $(CFLAGS_KASAN_SHADOW) \
2734 $(call cc-param,asan-globals=1) \
2835 $(call cc-param,asan-instrumentation-with-call-threshold=$(call_threshold)) \
29
- $(call cc-param,asan-stack=$(CONFIG_KASAN_STACK)) \
36
+ $(call cc-param,asan-stack=$(stack_enable)) \
3037 $(call cc-param,asan-instrument-allocas=1)
3138 endif
3239
....@@ -35,17 +42,16 @@
3542 ifdef CONFIG_KASAN_SW_TAGS
3643
3744 ifdef CONFIG_KASAN_INLINE
38
- instrumentation_flags := -mllvm -hwasan-mapping-offset=$(KASAN_SHADOW_OFFSET)
45
+ instrumentation_flags := $(call cc-param,hwasan-mapping-offset=$(KASAN_SHADOW_OFFSET))
3946 else
40
- instrumentation_flags := -mllvm -hwasan-instrument-with-calls=1
47
+ instrumentation_flags := $(call cc-param,hwasan-instrument-with-calls=1)
4148 endif
4249
4350 CFLAGS_KASAN := -fsanitize=kernel-hwaddress \
44
- -mllvm -hwasan-instrument-stack=0 \
51
+ $(call cc-param,hwasan-instrument-stack=$(stack_enable)) \
52
+ $(call cc-param,hwasan-use-short-granules=0) \
4553 $(instrumentation_flags)
4654
4755 endif # CONFIG_KASAN_SW_TAGS
4856
49
-ifdef CONFIG_KASAN
50
-CFLAGS_KASAN_NOSANITIZE := -fno-builtin
51
-endif
57
+export CFLAGS_KASAN CFLAGS_KASAN_NOSANITIZE