From 5569d2ddc275ea21a1b0513f24e4531abfa12a6a Mon Sep 17 00:00:00 2001 From: Christian Prochaska Date: Thu, 6 Dec 2018 00:52:22 +0100 Subject: [PATCH] mk: add 'SANITIZE_UNDEFINED' option 'SANITIZE_UNDEFINED = yes' in 'target.mk' adds the '-fsanitize=undefined' compiler flag and links the program with libubsan and libsanitizer_common. Issue #3072 --- repos/base/mk/dep_prg.mk | 7 +++++++ repos/base/mk/global.mk | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/repos/base/mk/dep_prg.mk b/repos/base/mk/dep_prg.mk index 0bc776a9f9..190dd92aa1 100644 --- a/repos/base/mk/dep_prg.mk +++ b/repos/base/mk/dep_prg.mk @@ -23,6 +23,13 @@ ifeq ($(COVERAGE),yes) LIBS += libgcov endif +# +# Add libraries for undefined behavior sanitizer if requested +# +ifeq ($(SANITIZE_UNDEFINED),yes) +LIBS += libubsan libsanitizer_common +endif + # # Include lib-import description files # diff --git a/repos/base/mk/global.mk b/repos/base/mk/global.mk index 5118ba1324..c297afce61 100644 --- a/repos/base/mk/global.mk +++ b/repos/base/mk/global.mk @@ -119,6 +119,13 @@ endif CC_OPT += -fprofile-arcs -ftest-coverage -fprofile-dir=$(PROFILE_DIR) endif +# +# Enable the undefined behavior sanitizer if requested +# +ifeq ($(SANITIZE_UNDEFINED),yes) +CC_OPT += -fsanitize=undefined +endif + # # Default optimization and warning levels #