From: Paul Cercueil Date: Sun, 19 Nov 2023 11:50:39 +0000 (+0100) Subject: Makefile: Enable address sanitizer with DEBUG_ASAN=1 X-Git-Tag: r24~50 X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?p=pcsx_rearmed.git;a=commitdiff_plain;h=36c76c861a26d2d2ce6118df1b20a389b8f3afb1 Makefile: Enable address sanitizer with DEBUG_ASAN=1 The Address Sanitizer (built in GCC and LLVM) is an extremely powerful tool, moreso than e.g. Valgrind for detecting memory issues. It is not available on every architecture/OS combination (see https://github.com/google/sanitizers/wiki/AddressSanitizer), so it can only be enabled by compiling with DEBUG_ASAN=1. Signed-off-by: Paul Cercueil --- diff --git a/Makefile b/Makefile index af3e1ab6..6ded0df0 100644 --- a/Makefile +++ b/Makefile @@ -6,6 +6,9 @@ CFLAGS += -Wall -ggdb -Iinclude -ffast-math ifndef DEBUG CFLAGS += -O2 -DNDEBUG endif +ifeq ($(DEBUG_ASAN), 1) +CFLAGS += -fsanitize=address +endif CFLAGS += -DP_HAVE_MMAP=$(if $(NO_MMAP),0,1) \ -DP_HAVE_PTHREAD=$(if $(NO_PTHREAD),0,1) \ -DP_HAVE_POSIX_MEMALIGN=$(if $(NO_POSIX_MEMALIGN),0,1) \ @@ -36,6 +39,9 @@ endif CC_LINK ?= $(CC) CC_AS ?= $(CC) LDFLAGS += $(MAIN_LDFLAGS) +ifeq ($(DEBUG_ASAN), 1) +LDFLAGS += -static-libasan +endif EXTRA_LDFLAGS ?= -Wl,-Map=$@.map LDLIBS += $(MAIN_LDLIBS) ifdef PCNT