build: Add support for sanitizer compiler flags
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 6ff42e2..3697f19 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -8,7 +8,7 @@ before_script:
unit-tests:
stage: test
script:
- - ./autogen && ./configure
+ - ./autogen && ./configure --enable-sanitize
- make check
coverage:
diff --git a/configure.ac b/configure.ac
index 11db6c7..1530ecf 100644
--- a/configure.ac
+++ b/configure.ac
@@ -70,6 +70,19 @@ AS_IF([test "$user_CFLAGS" = unset], [
LIBMD_CHECK_COMPILER_FLAG([-Wwrite-strings])
CFLAGS="$LIBMD_COMPILER_FLAGS $CFLAGS"
+
+ AC_ARG_ENABLE([sanitize],
+ [AS_HELP_STRING([--enable-sanitize], [enable compiler sanitizer support])],
+ [
+ LIBMD_COMPILER_FLAGS=''
+
+ LIBMD_CHECK_COMPILER_FLAG([-fsanitize=address])
+ LIBMD_CHECK_COMPILER_FLAG([-fsanitize=leak])
+ LIBMD_CHECK_COMPILER_FLAG([-fsanitize=undefined])
+
+ CFLAGS="$LIBMD_COMPILER_FLAGS $CFLAGS"
+ LDFLAGS="$LIBMD_COMPILER_FLAGS $LDFLAGS"
+ ])
])
# Checks for libraries.