blob: 1ce7115aa499b756abb9e713f41adb99b0fb4997 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001# SPDX-License-Identifier: GPL-2.0
Andrey Ryabinin0b24bec2015-02-13 14:39:17 -08002ifdef CONFIG_KASAN
3ifdef CONFIG_KASAN_INLINE
4 call_threshold := 10000
5else
6 call_threshold := 0
7endif
8
Andrey Ryabinin39d114d2015-10-12 18:52:58 +03009KASAN_SHADOW_OFFSET ?= $(CONFIG_KASAN_SHADOW_OFFSET)
10
Andrey Ryabinin0b24bec2015-02-13 14:39:17 -080011CFLAGS_KASAN_MINIMAL := -fsanitize=kernel-address
12
13CFLAGS_KASAN := $(call cc-option, -fsanitize=kernel-address \
Andrey Ryabinin39d114d2015-10-12 18:52:58 +030014 -fasan-shadow-offset=$(KASAN_SHADOW_OFFSET) \
Andrey Ryabininbebf56a2015-02-13 14:40:17 -080015 --param asan-stack=1 --param asan-globals=1 \
Andrey Ryabinin0b24bec2015-02-13 14:39:17 -080016 --param asan-instrumentation-with-call-threshold=$(call_threshold))
17
18ifeq ($(call cc-option, $(CFLAGS_KASAN_MINIMAL) -Werror),)
Andrey Ryabinin6e54aba2015-04-16 12:44:58 -070019 ifneq ($(CONFIG_COMPILE_TEST),y)
Andrey Ryabinin0b24bec2015-02-13 14:39:17 -080020 $(warning Cannot use CONFIG_KASAN: \
21 -fsanitize=kernel-address is not supported by compiler)
Andrey Ryabinin6e54aba2015-04-16 12:44:58 -070022 endif
Andrey Ryabinin0b24bec2015-02-13 14:39:17 -080023else
24 ifeq ($(CFLAGS_KASAN),)
Andrey Ryabinin6e54aba2015-04-16 12:44:58 -070025 ifneq ($(CONFIG_COMPILE_TEST),y)
26 $(warning CONFIG_KASAN: compiler does not support all options.\
27 Trying minimal configuration)
28 endif
Andrey Ryabinin0b24bec2015-02-13 14:39:17 -080029 CFLAGS_KASAN := $(CFLAGS_KASAN_MINIMAL)
30 endif
31endif
Andrey Ryabininc5caf212016-12-12 16:44:59 -080032
33CFLAGS_KASAN += $(call cc-option, -fsanitize-address-use-after-scope)
Andrey Ryabinin0b24bec2015-02-13 14:39:17 -080034endif