summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile6
-rw-r--r--Makefile.rules3
-rw-r--r--Makefile.toolchain10
3 files changed, 17 insertions, 2 deletions
diff --git a/Makefile b/Makefile
index 232f0cd6de..dabe3e9b20 100644
--- a/Makefile
+++ b/Makefile
@@ -44,6 +44,12 @@ BOOTBLOCK ?=
# the EC image (if no touchpad firmware is provided, just output blank hashes).
TOUCHPAD_FW ?=
+# If TEST_FUZZ is set make sure at least one sanitizer is enabled.
+ifeq ($(TEST_FUZZ)_$(TEST_ASAN)$(TEST_MSAN)$(TEST_UBSAN),y_)
+$(warning No sanitizer was specified defaulting to address sanitization.)
+override TEST_ASAN:=y
+endif
+
include Makefile.toolchain
# Define the traditional first target. The dependencies of this are near the
diff --git a/Makefile.rules b/Makefile.rules
index e3d6e3164a..5a7ac71688 100644
--- a/Makefile.rules
+++ b/Makefile.rules
@@ -344,7 +344,8 @@ $(fuzz-test-targets): host-%:
$(call quiet,host_test,BUILD )
.PHONY: buildfuzztests
-buildfuzztests: TEST_FLAG=TEST_FUZZ=y TEST_ASAN=y
+buildfuzztests: TEST_FLAG=TEST_FUZZ=y TEST_ASAN=$(TEST_ASAN) \
+ TEST_MSAN=$(TEST_MSAN) TEST_UBSAN=$(TEST_UBSAN)
buildfuzztests: $(fuzz-test-targets)
$(out)/libec.a: $(ro-objs)
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