blob: 2156e18391a3f93db931d267b51e47371e9f6f2b [file] [log] [blame]
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001# SPDX-License-Identifier: GPL-2.0
Olivier Deprez157378f2022-04-04 15:47:50 +02002
3export CFLAGS_UBSAN :=
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00004
5ifdef CONFIG_UBSAN_ALIGNMENT
6 CFLAGS_UBSAN += $(call cc-option, -fsanitize=alignment)
7endif
8
Olivier Deprez157378f2022-04-04 15:47:50 +02009ifdef 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)
Olivier Deprez157378f2022-04-04 15:47:50 +020026 CFLAGS_UBSAN += $(call cc-option, -fsanitize=bool)
27 CFLAGS_UBSAN += $(call cc-option, -fsanitize=enum)
28endif
29
30ifdef CONFIG_UBSAN_TRAP
31 CFLAGS_UBSAN += $(call cc-option, -fsanitize-undefined-trap-on-error)
32endif
33
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000034 # -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)