Merge branch 'work.iov_iter' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs
[platform/kernel/linux-starfive.git] / scripts / Makefile.kasan
1 # SPDX-License-Identifier: GPL-2.0
2 ifdef CONFIG_KASAN
3 ifdef CONFIG_KASAN_INLINE
4         call_threshold := 10000
5 else
6         call_threshold := 0
7 endif
8
9 KASAN_SHADOW_OFFSET ?= $(CONFIG_KASAN_SHADOW_OFFSET)
10
11 CFLAGS_KASAN_MINIMAL := -fsanitize=kernel-address
12
13 CFLAGS_KASAN := $(call cc-option, -fsanitize=kernel-address \
14                 -fasan-shadow-offset=$(KASAN_SHADOW_OFFSET) \
15                 --param asan-stack=1 --param asan-globals=1 \
16                 --param asan-instrumentation-with-call-threshold=$(call_threshold))
17
18 ifeq ($(call cc-option, $(CFLAGS_KASAN_MINIMAL) -Werror),)
19    ifneq ($(CONFIG_COMPILE_TEST),y)
20         $(warning Cannot use CONFIG_KASAN: \
21             -fsanitize=kernel-address is not supported by compiler)
22    endif
23 else
24     ifeq ($(CFLAGS_KASAN),)
25         ifneq ($(CONFIG_COMPILE_TEST),y)
26             $(warning CONFIG_KASAN: compiler does not support all options.\
27                 Trying minimal configuration)
28         endif
29         CFLAGS_KASAN := $(CFLAGS_KASAN_MINIMAL)
30     endif
31 endif
32
33 CFLAGS_KASAN += $(call cc-option, -fsanitize-address-use-after-scope)
34 endif