From 3d20a3974c62a284325f8e6f12b7fbb50b4607b7 Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Sat, 28 Jul 2018 11:17:07 +0100 Subject: Support ASAN and UBSAN in Makefiles --- Makefile | 19 +++++++++++++++++++ Makefile.config.example | 6 ++++++ Makefile.defaults | 5 +++++ test/Makefile | 5 ++++- 4 files changed, 34 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 3109a771c..359b89b5b 100644 --- a/Makefile +++ b/Makefile @@ -575,6 +575,25 @@ CXXFLAGS += -DNETSURF_HOMEPAGE=\"$(NETSURF_HOMEPAGE)\" CFLAGS += -DNETSURF_LOG_LEVEL=$(NETSURF_LOG_LEVEL) CXXFLAGS += -DNETSURF_LOG_LEVEL=$(NETSURF_LOG_LEVEL) +# If we're building the sanitizer goal, override things +ifneq ($(filter-out sanitize,$(MAKECMDGOALS)),$(MAKECMDGOALS)) +override NETSURF_USE_SANITIZER := YES +override NETSURF_RECOVER_SANITIZERS := NO +endif + +# If we're going to use the sanitizer set it up +ifeq ($(NETSURF_USE_SANITIZER),YES) +SAN_FLAGS := -fsanitize=address -fsanitize=undefined +ifeq ($(NETSURF_RECOVER_SANITIZERS),NO) +SAN_FLAGS += -fno-sanitize-recover +endif +else +SAN_FLAGS := +endif +CFLAGS += $(SAN_FLAGS) +CXXFLAGS += $(SAN_FLAGS) +LDFLAGS += $(SAN_FLAGS) + # and the logging filter CFLAGS += -DNETSURF_BUILTIN_LOG_FILTER=\"$(NETSURF_BUILTIN_LOG_FILTER)\" CXXFLAGS += -DNETSURF_BUILTIN_LOG_FILTER=\"$(NETSURF_BUILTIN_LOG_FILTER)\" diff --git a/Makefile.config.example b/Makefile.config.example index aeddc1071..010e89f07 100644 --- a/Makefile.config.example +++ b/Makefile.config.example @@ -33,3 +33,9 @@ ### To change flags to javascript binding generator # GBFLAGS:=-g + +### To enable ASAN and UBSAN support in builds regardless of target +# override NETSURF_USE_SANITIZERS := YES + +### If you're using the sanitizers and you want it to stop on failure... +# override NETSURF_RECOVER_SANITIZERS := NO diff --git a/Makefile.defaults b/Makefile.defaults index 1f9ce5fdf..51090109e 100644 --- a/Makefile.defaults +++ b/Makefile.defaults @@ -109,6 +109,11 @@ NETSURF_USE_LIBICONV_PLUG := YES # Valid options: YES, NO NETSURF_FS_BACKING_STORE := NO +# Enable the ASAN and UBSAN flags regardless of targets +NETSURF_USE_SANITIZERS := NO +# But recover after sanitizer failure +NETSURF_RECOVER_SANITIZERS := YES + # Initial CFLAGS. Optimisation level etc. tend to be target specific. CFLAGS := diff --git a/test/Makefile b/test/Makefile index a5f023bdc..4f9dd22c9 100644 --- a/test/Makefile +++ b/test/Makefile @@ -141,6 +141,7 @@ BASE_TESTCFLAGS := -std=c99 -g \ -D_XOPEN_SOURCE=600 \ -Itest -Iinclude -Icontent/handlers -Ifrontends -I. -I.. \ -Dnsgtk \ + $(SAN_FLAGS) \ $(shell pkg-config --cflags libcurl libparserutils libwapcaplet libdom libnsutils libutf8proc) \ $(LIB_CFLAGS) TESTCFLAGS := $(BASE_TESTCFLAGS) \ @@ -149,6 +150,7 @@ TESTCFLAGS := $(BASE_TESTCFLAGS) \ TESTLDFLAGS := -L$(TESTROOT) \ $(shell pkg-config --libs libcurl libparserutils libwapcaplet libdom libnsutils libutf8proc) -lz \ + $(SAN_FLAGS) \ $(LIB_LDFLAGS)\ $(COV_LDFLAGS) @@ -202,11 +204,12 @@ $(eval $(foreach SOURCE,$(sort $(filter %.c,$(NOCOV_TESTSOURCES))), \ $(call compile_test_nocov_target_c,$(SOURCE),$(subst /,_,$(SOURCE:.c=.o)),$(subst /,_,$(SOURCE:.c=.d))))) -.PHONY:test coverage +.PHONY:test coverage sanitize test: $(TESTROOT)/created $(TESTROOT)/libmalloc_fig.so $(addsuffix _test,$(TESTS)) coverage: test +sanitize: test $(TESTROOT)/created: $(VQ)echo " MKDIR: $(TESTROOT)" -- cgit v1.2.3