Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1 | # SPDX-License-Identifier: GPL-2.0 |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame] | 2 | |
| 3 | export CFLAGS_UBSAN := |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 4 | |
| 5 | ifdef CONFIG_UBSAN_ALIGNMENT |
| 6 | CFLAGS_UBSAN += $(call cc-option, -fsanitize=alignment) |
| 7 | endif |
| 8 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame] | 9 | ifdef CONFIG_UBSAN_BOUNDS |
| 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 |
| 19 | endif |
| 20 | |
| 21 | ifdef CONFIG_UBSAN_MISC |
| 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) |
| 25 | CFLAGS_UBSAN += $(call cc-option, -fsanitize=signed-integer-overflow) |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame] | 26 | CFLAGS_UBSAN += $(call cc-option, -fsanitize=bool) |
| 27 | CFLAGS_UBSAN += $(call cc-option, -fsanitize=enum) |
| 28 | endif |
| 29 | |
| 30 | ifdef CONFIG_UBSAN_TRAP |
| 31 | CFLAGS_UBSAN += $(call cc-option, -fsanitize-undefined-trap-on-error) |
| 32 | endif |
| 33 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 34 | # -fsanitize=* options makes GCC less smart than usual and |
| 35 | # increase number of 'maybe-uninitialized false-positives |
| 36 | CFLAGS_UBSAN += $(call cc-option, -Wno-maybe-uninitialized) |