]>
Commit | Line | Data |
---|---|---|
b2441318 | 1 | # SPDX-License-Identifier: GPL-2.0 |
34b5560d MR |
2 | CFLAGS_KASAN_NOSANITIZE := -fno-builtin |
3 | KASAN_SHADOW_OFFSET ?= $(CONFIG_KASAN_SHADOW_OFFSET) | |
34b5560d | 4 | |
2bd926b4 AK |
5 | ifdef CONFIG_KASAN_GENERIC |
6 | ||
0b24becc AR |
7 | ifdef CONFIG_KASAN_INLINE |
8 | call_threshold := 10000 | |
9 | else | |
10 | call_threshold := 0 | |
11 | endif | |
12 | ||
13 | CFLAGS_KASAN_MINIMAL := -fsanitize=kernel-address | |
14 | ||
1a69e7ce | 15 | cc-param = $(call cc-option, -mllvm -$(1), $(call cc-option, --param $(1))) |
0b24becc | 16 | |
2bd926b4 AK |
17 | # -fasan-shadow-offset fails without -fsanitize |
18 | CFLAGS_KASAN_SHADOW := $(call cc-option, -fsanitize=kernel-address \ | |
1a69e7ce AR |
19 | -fasan-shadow-offset=$(KASAN_SHADOW_OFFSET), \ |
20 | $(call cc-option, -fsanitize=kernel-address \ | |
21 | -mllvm -asan-mapping-offset=$(KASAN_SHADOW_OFFSET))) | |
22 | ||
2bd926b4 AK |
23 | ifeq ($(strip $(CFLAGS_KASAN_SHADOW)),) |
24 | CFLAGS_KASAN := $(CFLAGS_KASAN_MINIMAL) | |
25 | else | |
26 | # Now add all the compiler specific options that are valid standalone | |
27 | CFLAGS_KASAN := $(CFLAGS_KASAN_SHADOW) \ | |
28 | $(call cc-param,asan-globals=1) \ | |
29 | $(call cc-param,asan-instrumentation-with-call-threshold=$(call_threshold)) \ | |
6baec880 | 30 | $(call cc-param,asan-stack=$(CONFIG_KASAN_STACK)) \ |
2bd926b4 | 31 | $(call cc-param,asan-instrument-allocas=1) |
0b24becc | 32 | endif |
c5caf21a | 33 | |
2bd926b4 | 34 | endif # CONFIG_KASAN_GENERIC |
0e410e15 | 35 | |
2bd926b4 AK |
36 | ifdef CONFIG_KASAN_SW_TAGS |
37 | ||
38 | ifdef CONFIG_KASAN_INLINE | |
39 | instrumentation_flags := -mllvm -hwasan-mapping-offset=$(KASAN_SHADOW_OFFSET) | |
40 | else | |
41 | instrumentation_flags := -mllvm -hwasan-instrument-with-calls=1 | |
42 | endif | |
43 | ||
44 | CFLAGS_KASAN := -fsanitize=kernel-hwaddress \ | |
cae9dc35 AK |
45 | -mllvm -hwasan-instrument-stack=$(CONFIG_KASAN_STACK) \ |
46 | -mllvm -hwasan-use-short-granules=0 \ | |
2bd926b4 AK |
47 | $(instrumentation_flags) |
48 | ||
49 | endif # CONFIG_KASAN_SW_TAGS | |
bb273211 MY |
50 | |
51 | export CFLAGS_KASAN CFLAGS_KASAN_NOSANITIZE |