diff options
author | Allen Webb <allenwebb@google.com> | 2018-12-05 16:07:49 -0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-12-11 13:00:58 -0800 |
commit | 24d29fb0f5579a18846f2729d40102da9ce0b1b9 (patch) | |
tree | 9c8a779a9417ba774d807a794296e070ecd9cc70 | |
parent | e28470f82d0b7da30db435bd451cb3beeb79aa71 (diff) | |
download | chrome-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>
-rw-r--r-- | Makefile | 6 | ||||
-rw-r--r-- | Makefile.rules | 3 | ||||
-rw-r--r-- | Makefile.toolchain | 10 |
3 files changed, 17 insertions, 2 deletions
@@ -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 |