blob: 9716dab06bc7a9f6012555f8b2d4e8e29e472b6d [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001# SPDX-License-Identifier: GPL-2.0
Masahiro Yamadabb273212020-09-10 22:44:29 +09002
3export CFLAGS_UBSAN :=
4
Kees Cook0887a7e2020-04-06 20:12:27 -07005ifdef CONFIG_UBSAN_ALIGNMENT
6 CFLAGS_UBSAN += $(call cc-option, -fsanitize=alignment)
7endif
8
Kees Cook277a1082020-04-06 20:12:31 -07009ifdef CONFIG_UBSAN_BOUNDS
George Popescu6a6155f2020-10-15 20:13:38 -070010 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
Kees Cook277a1082020-04-06 20:12:31 -070019endif
20
21ifdef CONFIG_UBSAN_MISC
Andrey Ryabininc6d30852016-01-20 15:00:55 -080022 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 Ryabininc6d30852016-01-20 15:00:55 -080025 CFLAGS_UBSAN += $(call cc-option, -fsanitize=signed-integer-overflow)
Andrey Ryabininc6d30852016-01-20 15:00:55 -080026 CFLAGS_UBSAN += $(call cc-option, -fsanitize=object-size)
Andrey Ryabininc6d30852016-01-20 15:00:55 -080027 CFLAGS_UBSAN += $(call cc-option, -fsanitize=bool)
28 CFLAGS_UBSAN += $(call cc-option, -fsanitize=enum)
Kees Cook277a1082020-04-06 20:12:31 -070029endif
Andrey Ryabininc6d30852016-01-20 15:00:55 -080030
Kees Cook0887a7e2020-04-06 20:12:27 -070031ifdef CONFIG_UBSAN_TRAP
32 CFLAGS_UBSAN += $(call cc-option, -fsanitize-undefined-trap-on-error)
Andrey Ryabininc6d30852016-01-20 15:00:55 -080033endif
Christian Borntraeger725c4d22016-09-12 14:37:19 +020034
Arnd Bergmanna76bcf52016-11-10 17:44:44 +010035 # -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)