1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

make: add initial ubsan support

This commit is contained in:
Kaspar Schleiser 2019-01-16 14:45:46 +01:00
parent 726c461cb5
commit ba0f8a7429
2 changed files with 39 additions and 0 deletions

View File

@ -503,6 +503,9 @@ include $(RIOTMAKE)/toolchain/$(TOOLCHAIN).inc.mk
# overriding the core ldscripts
LINKFLAGS += -L$(RIOTBASE)/core/ldscripts
# include undefined behaviour sanitizer (UBSAN) support
include $(RIOTMAKE)/ubsan.inc.mk
# Tell ccache to pass the original file to the compiler, instead of passing the
# preprocessed code. Without this setting, the compilation will fail with
# -Wimplicit-fallthrough warnings even when the fall through case is properly

36
makefiles/ubsan.inc.mk Normal file
View File

@ -0,0 +1,36 @@
# Copyright (C) 2019 Kaspar Schleiser <kaspar@schleiser.de>
#
# This file contains support for UBSan, the undefined behaviour sanitizer
# provided by gcc and clang.
#
# Please see doc/doxygen/src/debugging-aids.md for more info.
# trap, msg_exit, msg_recover
UBSAN_MODE ?= msg_exit
CFLAGS_UBSAN = -fsanitize=undefined
ifeq (gnu,$(TOOLCHAIN))
ifeq (native,$(BOARD))
ifneq (,$(filter msg_%,$(UBSAN_MODE)))
LINKFLAGS_UBSAN += -lubsan
ifneq (msg_recover,$(UBSAN_MODE))
CFLAGS_UBSAN += -fno-sanitize-recover=undefined
endif
else
CFLAGS_UBSAN += -fsanitize-undefined-trap-on-error
endif
else
# on real hardware, there's currently no runtime support.
# so just crash when undefined behaviour is triggered.
CFLAGS_UBSAN += -fsanitize-undefined-trap-on-error
endif
else
# libubsan doesn't link properly when using clang.
# thus when using llvm as toolchain, always generate traps.
CFLAGS_UBSAN += -fsanitize-trap=undefined
endif
all-ubsan: CFLAGS += $(CFLAGS_UBSAN)
all-ubsan: LINKFLAGS += $(LINKFLAGS_UBSAN)
all-ubsan: all