summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2018-07-28 10:32:58 +0100
committerDaniel Silverstone <dsilvers@digital-scurf.org>2018-07-28 10:32:58 +0100
commitf2720449b3ede0299da61dfaff9fce6b8db78f75 (patch)
tree24b1aae845d817230b0db04a5db27e974597b378
parent0d348add42028c233efead8ea6ce45503fe29c35 (diff)
downloadbuildsystem-f2720449b3ede0299da61dfaff9fce6b8db78f75.tar.gz
buildsystem-f2720449b3ede0299da61dfaff9fce6b8db78f75.tar.bz2
Enable sanitize target for new gccs and clang
-rw-r--r--makefiles/Makefile.clang11
-rw-r--r--makefiles/Makefile.gcc11
-rw-r--r--makefiles/Makefile.tools19
-rw-r--r--makefiles/Makefile.top6
4 files changed, 47 insertions, 0 deletions
diff --git a/makefiles/Makefile.clang b/makefiles/Makefile.clang
index 4006a92..2a11a5b 100644
--- a/makefiles/Makefile.clang
+++ b/makefiles/Makefile.clang
@@ -28,6 +28,17 @@ ARFLG := cru
# Definitions of various attributes
CFLAGS := $(CFLAGS) -D_ALIGNED="__attribute__((aligned))"
+# Extensions for sanitize target
+ifeq ($(MAKECMDGOALS),sanitize)
+ SANCFLAGS ?= -fsanitize=address -fsanitize=undefined -fno-sanitize-recover
+ SANCXXFLAGS ?= -fsanitize=address -fsanitize=undefined -fno-sanitize-recover
+ SANLDFLAGS ?= -fsanitize=address -fsanitize=undefined -fno-sanitize-recover
+
+ CFLAGS := $(CFLAGS) $(SANCFLAGS)
+ CXXFLAGS := $(CXXFLAGS) $(SANCXXFLAGS)
+ LDFLAGS := $(LDFLAGS) $(SANLDFLAGS)
+endif
+
###############################################################################
# Mac OS X Universal Binaries
###############################################################################
diff --git a/makefiles/Makefile.gcc b/makefiles/Makefile.gcc
index 5f2bd4d..6ca7ba1 100644
--- a/makefiles/Makefile.gcc
+++ b/makefiles/Makefile.gcc
@@ -49,6 +49,17 @@ ifeq ($(MAKECMDGOALS),profile)
LDFLAGS := $(LDFLAGS) $(PROFLDFLAGS)
endif
+# Extensions for sanitize target
+ifeq ($(MAKECMDGOALS),sanitize)
+ SANCFLAGS ?= -fsanitize=address -fsanitize=undefined -fno-sanitize-recover
+ SANCXXFLAGS ?= -fsanitize=address -fsanitize=undefined -fno-sanitize-recover
+ SANLDFLAGS ?= -fsanitize=address -fsanitize=undefined -fno-sanitize-recover
+
+ CFLAGS := $(CFLAGS) $(SANCFLAGS)
+ CXXFLAGS := $(CXXFLAGS) $(SANCXXFLAGS)
+ LDFLAGS := $(LDFLAGS) $(SANLDFLAGS)
+endif
+
# RISC OS module extensions
ifeq ($(COMPONENT_TYPE),riscos-module)
ifneq ($(HOST),arm-unknown-riscos)
diff --git a/makefiles/Makefile.tools b/makefiles/Makefile.tools
index 86fac4c..33d6add 100644
--- a/makefiles/Makefile.tools
+++ b/makefiles/Makefile.tools
@@ -399,6 +399,25 @@ ifeq ($(toolchain),)
$(error Unable to detect toolchain)
endif
+# Detect if the toolchain ought to support sanitizers
+SANITIZE_OK=no
+ifeq ($(toolchain),gcc)
+ GCC_VERSION := $(shell $(CC) -dumpversion)
+ GCC_MAJOR := $(word 1,$(subst ., ,$(GCC_VERSION)))
+ ifeq ($(shell expr $(GCC_MAJOR) \>= 6),1)
+ SANITIZE_OK=yes
+ endif
+else ifeq ($(toolchain),clang)
+ SANITIZE_OK=yes
+endif
+
+# And fail if we can't sanitize and yet the user asked for it
+ifeq ($(MAKECMDGOALS),sanitize)
+ ifeq ($(SANITIZE_OK),no)
+ $(error Unable to build with sanitizers enabled, compiler not compatible
+ endif
+endif
+
# TODO: It would be nice to avoid this hard-coded path
include $(NSBUILD)/Makefile.$(toolchain)
diff --git a/makefiles/Makefile.top b/makefiles/Makefile.top
index 9d3c680..caac166 100644
--- a/makefiles/Makefile.top
+++ b/makefiles/Makefile.top
@@ -48,6 +48,7 @@
# test Build and run test suite, using current settings.
# coverage Determine test suite coverage (requires lcov)
# profile Build with profiling support enabled (requires gprof)
+# sanitize Build and run test suite, using ASAN and UBSAN
# docs Produce documentation (requires doxygen)
# dist Produce release tarball from latest git tag
# clean Clean the build
@@ -123,6 +124,8 @@ else ifeq ($(MAKECMDGOALS),profile)
WANT_TEST := yes
else ifeq ($(MAKECMDGOALS),coverage)
WANT_TEST := yes
+else ifeq ($(MAKECMDGOALS),sanitize)
+ WANT_TEST := yes
else
WANT_TEST := no
endif
@@ -231,6 +234,9 @@ coverage: __precov test
$(Q)$(GENHTML) -o $(COVERAGEDIR) --num-spaces 2 \
$(COVERAGEDIR)/$(COMPONENT).info
+# Build and test sanitizers
+sanitize: test
+
# Build for profiling
profile: __partial_clean test