.. | .. |
---|
1 | 1 | # 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 | + |
---|
2 | 13 | ifdef CONFIG_KASAN_GENERIC |
---|
3 | 14 | |
---|
4 | 15 | ifdef CONFIG_KASAN_INLINE |
---|
.. | .. |
---|
7 | 18 | call_threshold := 0 |
---|
8 | 19 | endif |
---|
9 | 20 | |
---|
10 | | -KASAN_SHADOW_OFFSET ?= $(CONFIG_KASAN_SHADOW_OFFSET) |
---|
11 | | - |
---|
12 | 21 | CFLAGS_KASAN_MINIMAL := -fsanitize=kernel-address |
---|
13 | | - |
---|
14 | | -cc-param = $(call cc-option, -mllvm -$(1), $(call cc-option, --param $(1))) |
---|
15 | 22 | |
---|
16 | 23 | # -fasan-shadow-offset fails without -fsanitize |
---|
17 | 24 | CFLAGS_KASAN_SHADOW := $(call cc-option, -fsanitize=kernel-address \ |
---|
.. | .. |
---|
26 | 33 | CFLAGS_KASAN := $(CFLAGS_KASAN_SHADOW) \ |
---|
27 | 34 | $(call cc-param,asan-globals=1) \ |
---|
28 | 35 | $(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)) \ |
---|
30 | 37 | $(call cc-param,asan-instrument-allocas=1) |
---|
31 | 38 | endif |
---|
32 | 39 | |
---|
.. | .. |
---|
35 | 42 | ifdef CONFIG_KASAN_SW_TAGS |
---|
36 | 43 | |
---|
37 | 44 | 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)) |
---|
39 | 46 | else |
---|
40 | | - instrumentation_flags := -mllvm -hwasan-instrument-with-calls=1 |
---|
| 47 | + instrumentation_flags := $(call cc-param,hwasan-instrument-with-calls=1) |
---|
41 | 48 | endif |
---|
42 | 49 | |
---|
43 | 50 | 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) \ |
---|
45 | 53 | $(instrumentation_flags) |
---|
46 | 54 | |
---|
47 | 55 | endif # CONFIG_KASAN_SW_TAGS |
---|
48 | 56 | |
---|
49 | | -ifdef CONFIG_KASAN |
---|
50 | | -CFLAGS_KASAN_NOSANITIZE := -fno-builtin |
---|
51 | | -endif |
---|
| 57 | +export CFLAGS_KASAN CFLAGS_KASAN_NOSANITIZE |
---|