summaryrefslogtreecommitdiff
path: root/Makefile.toolchain
diff options
context:
space:
mode:
authorAllen Webb <allenwebb@google.com>2018-12-05 16:07:49 -0800
committerchrome-bot <chrome-bot@chromium.org>2018-12-11 13:00:58 -0800
commit24d29fb0f5579a18846f2729d40102da9ce0b1b9 (patch)
tree9c8a779a9417ba774d807a794296e070ecd9cc70 /Makefile.toolchain
parente28470f82d0b7da30db435bd451cb3beeb79aa71 (diff)
downloadchrome-ec-24d29fb0f5579a18846f2729d40102da9ce0b1b9.tar.gz
Makefiles: Add support for MSAN and UBSAN.
This adds support for building fuzz targets with memory and undefined behavior sanitizers. BRANCH=None BUG=chromium:911310 TEST=USE="ubsan fuzzer" ./build_packages \ --board=amd64-generic --skip_chroot_upgrade chromeos-ec && (cd ../platform/ec && unset BOARD && make -j buildall buildfuzztests) Change-Id: Ic7f4c1d7fcc1f6347f091b98567167066787cb9c Signed-off-by: Allen Webb <allenwebb@google.com> Reviewed-on: https://chromium-review.googlesource.com/1364326 Reviewed-by: Manoj Gupta <manojgupta@chromium.org> Reviewed-by: Mike Frysinger <vapier@chromium.org>
Diffstat (limited to 'Makefile.toolchain')
-rw-r--r--Makefile.toolchain10
1 files changed, 9 insertions, 1 deletions
diff --git a/Makefile.toolchain b/Makefile.toolchain
index 9ef5ef8699..7473ebc005 100644
--- a/Makefile.toolchain
+++ b/Makefile.toolchain
@@ -16,7 +16,7 @@ $(error ERROR: GNU make version $(min_make_version) or higher required.)
endif
# Default to clang if TEST_ASAN is enabled
-ifneq ($(TEST_ASAN),)
+ifneq ($(TEST_FUZZ)$(TEST_ASAN)$(TEST_MSAN)$(TEST_UBSAN),)
CC=clang
endif
@@ -52,6 +52,10 @@ ifeq ($(cc-name),clang)
# clang is pickier when it comes to packed struct members alignment.
C_WARN+= -Wno-address-of-packed-member
endif
+UBSAN_FLAGS=-fsanitize=array-bounds,vla-bound \
+ -fno-sanitize=vptr \
+ -fno-sanitize-recover=all
+
CFLAGS_WARN = $(COMMON_WARN) $(C_WARN)
CXXFLAGS_WARN = $(COMMON_WARN)
CFLAGS_DEBUG= -g
@@ -64,6 +68,8 @@ CFLAGS_TEST=$(if $(TEST_BUILD),-DTEST_BUILD \
$(if $($(PROJECT)-scale),-DTEST_TIME_SCALE=$($(PROJECT)-scale)) \
-DTEST_$(PROJECT) -DTEST_$(UC_PROJECT) \
$(if $(TEST_ASAN),-fsanitize=address) \
+ $(if $(TEST_MSAN),-fsanitize=memory) \
+ $(if $(TEST_UBSAN),$(UBSAN_FLAGS)) \
$(if $(TEST_FUZZ),-fsanitize=fuzzer-no-link -DTEST_FUZZ)
CFLAGS_COVERAGE=$(if $(TEST_COVERAGE),-fprofile-arcs -ftest-coverage \
-DTEST_COVERAGE,)
@@ -127,6 +133,8 @@ BUILD_LDFLAGS=$(LIBFTDI_LDLIBS)
HOST_TEST_LDFLAGS=-Wl,-T core/host/host_exe.lds -lrt -pthread -rdynamic -lm\
$(if $(TEST_COVERAGE),-fprofile-arcs,) \
$(if $(TEST_ASAN), -fsanitize=address) \
+ $(if $(TEST_MSAN), -fsanitize=memory) \
+ $(if $(TEST_UBSAN), ${UBSAN_FLAGS}) \
$(if $(TEST_FUZZ), -fsanitize=fuzzer)
# utility function to provide overridable defaults