Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1# SPDX-License-Identifier: GPL-2.0
2
3export CFLAGS_UBSAN :=
4
5ifdef CONFIG_UBSAN_ALIGNMENT
6 CFLAGS_UBSAN += $(call cc-option, -fsanitize=alignment)
7endif
8
9ifdef 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
15endif
16
17ifdef CONFIG_UBSAN_LOCAL_BOUNDS
18 CFLAGS_UBSAN += -fsanitize=local-bounds
19endif
20
21ifdef 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)
26 CFLAGS_UBSAN += $(call cc-option, -fsanitize=object-size)
27 CFLAGS_UBSAN += $(call cc-option, -fsanitize=bool)
28 CFLAGS_UBSAN += $(call cc-option, -fsanitize=enum)
29endif
30
31ifdef CONFIG_UBSAN_TRAP
32 CFLAGS_UBSAN += $(call cc-option, -fsanitize-undefined-trap-on-error)
33endif
34
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)