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 | |
Andrey Ryabinin | 1a69e7c | 2018-02-06 15:36:08 -0800 | [diff] [blame] | 13 | cc-param = $(call cc-option, -mllvm -$(1), $(call cc-option, --param $(1))) |
Andrey Ryabinin | 0b24bec | 2015-02-13 14:39:17 -0800 | [diff] [blame] | 14 | |
| 15 | ifeq ($(call cc-option, $(CFLAGS_KASAN_MINIMAL) -Werror),) |
Andrey Ryabinin | 6e54aba | 2015-04-16 12:44:58 -0700 | [diff] [blame] | 16 | ifneq ($(CONFIG_COMPILE_TEST),y) |
Andrey Ryabinin | 0b24bec | 2015-02-13 14:39:17 -0800 | [diff] [blame] | 17 | $(warning Cannot use CONFIG_KASAN: \ |
| 18 | -fsanitize=kernel-address is not supported by compiler) |
Andrey Ryabinin | 6e54aba | 2015-04-16 12:44:58 -0700 | [diff] [blame] | 19 | endif |
Andrey Ryabinin | 0b24bec | 2015-02-13 14:39:17 -0800 | [diff] [blame] | 20 | else |
Andrey Ryabinin | 1a69e7c | 2018-02-06 15:36:08 -0800 | [diff] [blame] | 21 | # -fasan-shadow-offset fails without -fsanitize |
| 22 | CFLAGS_KASAN_SHADOW := $(call cc-option, -fsanitize=kernel-address \ |
| 23 | -fasan-shadow-offset=$(KASAN_SHADOW_OFFSET), \ |
| 24 | $(call cc-option, -fsanitize=kernel-address \ |
| 25 | -mllvm -asan-mapping-offset=$(KASAN_SHADOW_OFFSET))) |
| 26 | |
| 27 | ifeq ($(strip $(CFLAGS_KASAN_SHADOW)),) |
| 28 | CFLAGS_KASAN := $(CFLAGS_KASAN_MINIMAL) |
| 29 | else |
| 30 | # Now add all the compiler specific options that are valid standalone |
| 31 | CFLAGS_KASAN := $(CFLAGS_KASAN_SHADOW) \ |
| 32 | $(call cc-param,asan-globals=1) \ |
| 33 | $(call cc-param,asan-instrumentation-with-call-threshold=$(call_threshold)) \ |
| 34 | $(call cc-param,asan-stack=1) \ |
Paul Lawrence | 342061e | 2018-02-06 15:36:11 -0800 | [diff] [blame] | 35 | $(call cc-param,asan-use-after-scope=1) \ |
| 36 | $(call cc-param,asan-instrument-allocas=1) |
Andrey Ryabinin | 1a69e7c | 2018-02-06 15:36:08 -0800 | [diff] [blame] | 37 | endif |
| 38 | |
Andrey Ryabinin | 0b24bec | 2015-02-13 14:39:17 -0800 | [diff] [blame] | 39 | endif |
Andrey Ryabinin | c5caf21 | 2016-12-12 16:44:59 -0800 | [diff] [blame] | 40 | |
Arnd Bergmann | e7c52b8 | 2018-02-06 15:41:41 -0800 | [diff] [blame^] | 41 | ifdef CONFIG_KASAN_EXTRA |
Andrey Ryabinin | c5caf21 | 2016-12-12 16:44:59 -0800 | [diff] [blame] | 42 | CFLAGS_KASAN += $(call cc-option, -fsanitize-address-use-after-scope) |
Arnd Bergmann | e7c52b8 | 2018-02-06 15:41:41 -0800 | [diff] [blame^] | 43 | endif |
Andrey Konovalov | 0e410e1 | 2018-02-06 15:36:00 -0800 | [diff] [blame] | 44 | |
| 45 | CFLAGS_KASAN_NOSANITIZE := -fno-builtin |
| 46 | |
Andrey Ryabinin | 0b24bec | 2015-02-13 14:39:17 -0800 | [diff] [blame] | 47 | endif |