It's now possible to enable AddressSanitizer by passing the parameter
`ASAN=1` on the "make" command line.

Signed-off-by: Martin Wilck <[email protected]>
---
 .github/actions/spelling/expect.txt | 3 +++
 Makefile.inc                        | 7 +++++--
 README.md                           | 3 +++
 3 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/.github/actions/spelling/expect.txt 
b/.github/actions/spelling/expect.txt
index 0b680aa..29ca8e8 100644
--- a/.github/actions/spelling/expect.txt
+++ b/.github/actions/spelling/expect.txt
@@ -6,6 +6,7 @@ alloc
 alltgpt
 alua
 aptpl
+ASAN
 ascq
 ata
 autoconfig
@@ -78,6 +79,7 @@ getrlimit
 getuid
 github
 gitlab
+google
 GPT
 hbtl
 hds
@@ -197,6 +199,7 @@ rpmbuild
 rport
 rtpi
 rtprio
+sanitizer
 sas
 sbp
 scsi
diff --git a/Makefile.inc b/Makefile.inc
index 539415d..8356254 100644
--- a/Makefile.inc
+++ b/Makefile.inc
@@ -9,6 +9,9 @@
 # Uncomment to disable dmevents polling support
 # ENABLE_DMEVENTS_POLL = 0
 #
+# Use ASAN=1 on make command line to enable address sanitizer
+ASAN := 
+#
 # Readline library to use, libedit, libreadline, or empty
 # Caution: Using libreadline may make the multipathd binary undistributable,
 # see https://github.com/opensvc/multipath-tools/issues/36
@@ -122,11 +125,11 @@ CPPFLAGS  := $(FORTIFY_OPT) $(CPPFLAGS) $(D_URCU_VERSION) 
$(D_CMOCKA_VERSION) \
                   -DWSTRINGOP_TRUNCATION=$(if $(WSTRINGOP_TRUNCATION),1,0) \
                   -MMD -MP
 CFLAGS         := -std=$(C_STD) $(CFLAGS) $(OPTFLAGS) $(WARNFLAGS) -pipe \
-                  -fexceptions -fno-strict-aliasing
+                  -fexceptions -fno-strict-aliasing $(if 
$(ASAN),-fsanitize=address)
 BIN_CFLAGS     := -fPIE -DPIE
 LIB_CFLAGS     := -fPIC
 SHARED_FLAGS   := -shared
-LDFLAGS                := $(LDFLAGS) -Wl,-z,relro -Wl,-z,now -Wl,-z,defs
+LDFLAGS                := $(LDFLAGS) -Wl,-z,relro -Wl,-z,now -Wl,-z,defs $(if 
$(ASAN),-lasan)
 BIN_LDFLAGS    := -pie
 
 # Source code directories. Don't modify.
diff --git a/README.md b/README.md
index 530caed..8ff139c 100644
--- a/README.md
+++ b/README.md
@@ -107,6 +107,9 @@ See "Passing standard compiler flags" below for an 
exception.
 The following variables can be passed to the `make` command line:
 
  * `V=1`: enable verbose build.
+ * `ASAN=1`: Enable
+   
[AddressSanitizer](https://github.com/google/sanitizers/wiki/AddressSanitizerLeakSanitizer)
+   during build for debugging memory allocation. This is off by default.
  * `plugindir="/some/path"`: directory where libmultipath plugins (path
    checkers, prioritizers, and foreign multipath support) will be looked up.
    This used to be the run-time option `multipath_dir` in earlier versions.
-- 
2.52.0


Reply via email to