From 1a970759e200130f3caa4f7365facfdb128fc546 Mon Sep 17 00:00:00 2001 From: Paul Cercueil Date: Sun, 19 Nov 2023 12:50:39 +0100 Subject: [PATCH] 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 --- Makefile | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Makefile b/Makefile index be943918..57fee2fc 100644 --- a/Makefile +++ b/Makefile @@ -12,6 +12,9 @@ else CFLAGS += -O2 -DNDEBUG endif 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) \ @@ -45,6 +48,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 -- 2.39.5