Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | # SPDX-License-Identifier: GPL-2.0 |
Andrey Ryabinin | 0b24bec | 2015-02-13 14:39:17 -0800 | [diff] [blame] | 2 | ifdef CONFIG_KASAN |
| 3 | ifdef CONFIG_KASAN_INLINE |
| 4 | call_threshold := 10000 |
| 5 | else |
| 6 | call_threshold := 0 |
| 7 | endif |
| 8 | |
Andrey Ryabinin | 39d114d | 2015-10-12 18:52:58 +0300 | [diff] [blame] | 9 | KASAN_SHADOW_OFFSET ?= $(CONFIG_KASAN_SHADOW_OFFSET) |
| 10 | |
Andrey Ryabinin | 0b24bec | 2015-02-13 14:39:17 -0800 | [diff] [blame] | 11 | CFLAGS_KASAN_MINIMAL := -fsanitize=kernel-address |
| 12 | |
| 13 | CFLAGS_KASAN := $(call cc-option, -fsanitize=kernel-address \ |
Andrey Ryabinin | 39d114d | 2015-10-12 18:52:58 +0300 | [diff] [blame] | 14 | -fasan-shadow-offset=$(KASAN_SHADOW_OFFSET) \ |
Andrey Ryabinin | bebf56a | 2015-02-13 14:40:17 -0800 | [diff] [blame] | 15 | --param asan-stack=1 --param asan-globals=1 \ |
Andrey Ryabinin | 0b24bec | 2015-02-13 14:39:17 -0800 | [diff] [blame] | 16 | --param asan-instrumentation-with-call-threshold=$(call_threshold)) |
| 17 | |
| 18 | ifeq ($(call cc-option, $(CFLAGS_KASAN_MINIMAL) -Werror),) |
Andrey Ryabinin | 6e54aba | 2015-04-16 12:44:58 -0700 | [diff] [blame] | 19 | ifneq ($(CONFIG_COMPILE_TEST),y) |
Andrey Ryabinin | 0b24bec | 2015-02-13 14:39:17 -0800 | [diff] [blame] | 20 | $(warning Cannot use CONFIG_KASAN: \ |
| 21 | -fsanitize=kernel-address is not supported by compiler) |
Andrey Ryabinin | 6e54aba | 2015-04-16 12:44:58 -0700 | [diff] [blame] | 22 | endif |
Andrey Ryabinin | 0b24bec | 2015-02-13 14:39:17 -0800 | [diff] [blame] | 23 | else |
| 24 | ifeq ($(CFLAGS_KASAN),) |
Andrey Ryabinin | 6e54aba | 2015-04-16 12:44:58 -0700 | [diff] [blame] | 25 | ifneq ($(CONFIG_COMPILE_TEST),y) |
| 26 | $(warning CONFIG_KASAN: compiler does not support all options.\ |
| 27 | Trying minimal configuration) |
| 28 | endif |
Andrey Ryabinin | 0b24bec | 2015-02-13 14:39:17 -0800 | [diff] [blame] | 29 | CFLAGS_KASAN := $(CFLAGS_KASAN_MINIMAL) |
| 30 | endif |
| 31 | endif |
Andrey Ryabinin | c5caf21 | 2016-12-12 16:44:59 -0800 | [diff] [blame] | 32 | |
| 33 | CFLAGS_KASAN += $(call cc-option, -fsanitize-address-use-after-scope) |
Andrey Ryabinin | 0b24bec | 2015-02-13 14:39:17 -0800 | [diff] [blame] | 34 | endif |