diff --git a/Common.mak b/Common.mak index 8f00c1889..1ff37e2aa 100644 --- a/Common.mak +++ b/Common.mak @@ -585,21 +585,27 @@ ifneq ($(ALLOCACHE_AS_MALLOC),0) COMPILERFLAGS += -DDEBUG_ALLOCACHE_AS_MALLOC endif -# See http://clang.llvm.org/docs/UsersManual.html#controlling-code-generation -# for a list of possible UBSan options. -# Clang 3.2 does only supports -fsanitize=address for the AddressSanitizer -CLANG_DEBUG_FLAGS := -fsanitize=address -fsanitize=bounds,enum,float-cast-overflow,object-size -#CLANG_DEBUG_FLAGS := $(CLANG_DEBUG_FLAGS),signed-integer-overflow -#CLANG_DEBUG_FLAGS := $(CLANG_DEBUG_FLAGS),unsigned-integer-overflow -#CLANG_DEBUG_FLAGS := $(CLANG_DEBUG_FLAGS) -fsanitize-undefined-trap-on-error +# See https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html +# and https://gcc.gnu.org/onlinedocs/gcc/Instrumentation-Options.html +# for a list of possible ASan and UBsan options. + +ASAN_FLAGS := -fsanitize=address -fsanitize=bounds,enum,float-cast-overflow +ASAN_FLAGS := $(ASAN_FLAGS),signed-integer-overflow,unsigned-integer-overflow +ASAN_FLAGS := $(ASAN_FLAGS),undefined,return,null,pointer-overflow,float-divide-by-zero +#ASAN_FLAGS := $(ASAN_FLAGS) -fsanitize-undefined-trap-on-error ifeq (0,$(FORCEDEBUG)) COMPILERFLAGS += -DNDEBUG else COMPILERFLAGS += -DDEBUGGINGAIDS=$(FORCEDEBUG) - ifneq (0,$(CLANG)) - ifeq (2,$(FORCEDEBUG)) - COMMONFLAGS += $(CLANG_DEBUG_FLAGS) + + ifeq (2,$(FORCEDEBUG)) + ifneq (0,$(CLANG)) + COMMONFLAGS += $(ASAN_FLAGS) + else ifneq (,$(filter 1 2 3 4 5 6,$(GCC_MAJOR))) + ifneq (,$(filter 0 1,$(GCC_MINOR))) + COMMONFLAGS += $(ASAN_FLAGS) + endif endif endif endif diff --git a/GNUmakefile b/GNUmakefile index 2fa91b43e..cd40abdd0 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -955,7 +955,7 @@ $(foreach i,$(components),$(eval $(call OBJECTRULES,$i))) # Comment out the following rule to debug a-c.o $(engine_obj)/a-c.$o: $(engine_src)/a-c.cpp | $(engine_obj) $(COMPILE_STATUS) - $(RECIPE_IF) $(subst -O$(OPTLEVEL),-O2,$(subst $(CLANG_DEBUG_FLAGS),,$(COMPILER_CXX))) $(engine_cflags) -c $< -o $@ $(RECIPE_RESULT_COMPILE) + $(RECIPE_IF) $(subst -O$(OPTLEVEL),-O2,$(subst $(ASAN_FLAGS),,$(COMPILER_CXX))) $(engine_cflags) -c $< -o $@ $(RECIPE_RESULT_COMPILE) $(engine_obj)/rev.$o: $(engine_src)/rev.cpp | $(engine_obj) $(COMPILE_STATUS)