Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | # SPDX-License-Identifier: GPL-2.0 |
Masahiro Yamada | bb27321 | 2020-09-10 22:44:29 +0900 | [diff] [blame] | 2 | |
| 3 | export CFLAGS_UBSAN := |
| 4 | |
Kees Cook | 0887a7e | 2020-04-06 20:12:27 -0700 | [diff] [blame] | 5 | ifdef CONFIG_UBSAN_ALIGNMENT |
| 6 | CFLAGS_UBSAN += $(call cc-option, -fsanitize=alignment) |
| 7 | endif |
| 8 | |
Kees Cook | 277a108 | 2020-04-06 20:12:31 -0700 | [diff] [blame] | 9 | ifdef CONFIG_UBSAN_BOUNDS |
George Popescu | 6a6155f | 2020-10-15 20:13:38 -0700 | [diff] [blame] | 10 | ifdef CONFIG_CC_IS_CLANG |
| 11 | CFLAGS_UBSAN += -fsanitize=array-bounds |
| 12 | else |
| 13 | CFLAGS_UBSAN += $(call cc-option, -fsanitize=bounds) |
| 14 | endif |
| 15 | endif |
| 16 | |
| 17 | ifdef CONFIG_UBSAN_LOCAL_BOUNDS |
| 18 | CFLAGS_UBSAN += -fsanitize=local-bounds |
Kees Cook | 277a108 | 2020-04-06 20:12:31 -0700 | [diff] [blame] | 19 | endif |
| 20 | |
| 21 | ifdef CONFIG_UBSAN_MISC |
Andrey Ryabinin | c6d3085 | 2016-01-20 15:00:55 -0800 | [diff] [blame] | 22 | CFLAGS_UBSAN += $(call cc-option, -fsanitize=shift) |
| 23 | CFLAGS_UBSAN += $(call cc-option, -fsanitize=integer-divide-by-zero) |
| 24 | CFLAGS_UBSAN += $(call cc-option, -fsanitize=unreachable) |
Andrey Ryabinin | c6d3085 | 2016-01-20 15:00:55 -0800 | [diff] [blame] | 25 | CFLAGS_UBSAN += $(call cc-option, -fsanitize=signed-integer-overflow) |
Andrey Ryabinin | c6d3085 | 2016-01-20 15:00:55 -0800 | [diff] [blame] | 26 | CFLAGS_UBSAN += $(call cc-option, -fsanitize=object-size) |
Andrey Ryabinin | c6d3085 | 2016-01-20 15:00:55 -0800 | [diff] [blame] | 27 | CFLAGS_UBSAN += $(call cc-option, -fsanitize=bool) |
| 28 | CFLAGS_UBSAN += $(call cc-option, -fsanitize=enum) |
Kees Cook | 277a108 | 2020-04-06 20:12:31 -0700 | [diff] [blame] | 29 | endif |
Andrey Ryabinin | c6d3085 | 2016-01-20 15:00:55 -0800 | [diff] [blame] | 30 | |
Kees Cook | 0887a7e | 2020-04-06 20:12:27 -0700 | [diff] [blame] | 31 | ifdef CONFIG_UBSAN_TRAP |
| 32 | CFLAGS_UBSAN += $(call cc-option, -fsanitize-undefined-trap-on-error) |
Andrey Ryabinin | c6d3085 | 2016-01-20 15:00:55 -0800 | [diff] [blame] | 33 | endif |
Christian Borntraeger | 725c4d2 | 2016-09-12 14:37:19 +0200 | [diff] [blame] | 34 | |
Arnd Bergmann | a76bcf5 | 2016-11-10 17:44:44 +0100 | [diff] [blame] | 35 | # -fsanitize=* options makes GCC less smart than usual and |
| 36 | # increase number of 'maybe-uninitialized false-positives |
| 37 | CFLAGS_UBSAN += $(call cc-option, -Wno-maybe-uninitialized) |