[ovs-dev] [RFC PATCH 1/8] configure: add --enable-asan option

Gaetan Rivet grive at u256.net
Thu Apr 22 15:54:26 UTC 2021


Add a configure option to enable ASAN in a simple way.
Adding an AC variable to allow checking for support in the testsuite.

Signed-off-by: Gaetan Rivet <grive at u256.net>
---
 .ci/linux-build.sh |  4 ++--
 NEWS               |  1 +
 acinclude.m4       | 16 ++++++++++++++++
 configure.ac       |  1 +
 tests/atlocal.in   |  1 +
 5 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/.ci/linux-build.sh b/.ci/linux-build.sh
index 977449350..3c58637b4 100755
--- a/.ci/linux-build.sh
+++ b/.ci/linux-build.sh
@@ -229,10 +229,10 @@ fi
 if [ "$ASAN" ]; then
     # This will override default option configured in tests/atlocal.in.
     export ASAN_OPTIONS='detect_leaks=1'
+    EXTRA_OPTS="$EXTRA_OPTS --enable-asan"
     # -O2 generates few false-positive memory leak reports in test-ovsdb
     # application, so lowering optimizations to -O1 here.
-    CLFAGS_ASAN="-O1 -fno-omit-frame-pointer -fno-common -fsanitize=address"
-    CFLAGS_FOR_OVS="${CFLAGS_FOR_OVS} ${CLFAGS_ASAN}"
+    CFLAGS_FOR_OVS="${CFLAGS_FOR_OVS} -O1"
 fi
 
 save_OPTS="${OPTS} $*"
diff --git a/NEWS b/NEWS
index 95cf922aa..57e1f041b 100644
--- a/NEWS
+++ b/NEWS
@@ -9,6 +9,7 @@ Post-v2.15.0
      * New option '--no-record-hostname' to disable hostname configuration
        in ovsdb on startup.
      * New command 'record-hostname-if-not-set' to update hostname in ovsdb.
+   - New --enable-asan configure option enables AddressSanitizer.
 
 
 v2.15.0 - 15 Feb 2021
diff --git a/acinclude.m4 b/acinclude.m4
index 15a54d636..615e7f962 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -58,6 +58,22 @@ AC_DEFUN([OVS_ENABLE_WERROR],
    fi
    AC_SUBST([SPARSE_WERROR])])
 
+dnl OVS_ENABLE_ASAN
+AC_DEFUN([OVS_ENABLE_ASAN],
+  [AC_ARG_ENABLE(
+    [asan],
+    [AC_HELP_STRING([--enable-asan],
+                    [Enable the Address Sanitizer])],
+    [ASAN_ENABLED=yes], [ASAN_ENABLED=no])
+   AC_SUBST([ASAN_ENABLED])
+   AC_CONFIG_COMMANDS_PRE([
+     if test "$ASAN_ENABLED" = "yes"; then
+         OVS_CFLAGS="$OVS_CFLAGS -fno-omit-frame-pointer"
+         OVS_CFLAGS="$OVS_CFLAGS -fno-common -fsanitize=address"
+     fi
+   ])
+  ])
+
 dnl OVS_CHECK_LINUX
 dnl
 dnl Configure linux kernel source tree
diff --git a/configure.ac b/configure.ac
index c077034d4..eec5a9d1b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -182,6 +182,7 @@ OVS_CONDITIONAL_CC_OPTION([-Wno-unused-parameter], [HAVE_WNO_UNUSED_PARAMETER])
 OVS_CONDITIONAL_CC_OPTION([-mavx512f], [HAVE_AVX512F])
 OVS_CHECK_CC_OPTION([-mavx512f], [CFLAGS="$CFLAGS -DHAVE_AVX512F"])
 OVS_ENABLE_WERROR
+OVS_ENABLE_ASAN
 OVS_ENABLE_SPARSE
 OVS_CTAGS_IDENTIFIERS
 OVS_CHECK_DPCLS_AUTOVALIDATOR
diff --git a/tests/atlocal.in b/tests/atlocal.in
index cfca7e192..f61e752bf 100644
--- a/tests/atlocal.in
+++ b/tests/atlocal.in
@@ -220,6 +220,7 @@ export OVS_SYSLOG_METHOD
 OVS_CTL_TIMEOUT=30
 export OVS_CTL_TIMEOUT
 
+ASAN_ENABLED='@ASAN_ENABLED@'
 # Add some default flags to make the tests run better under Address
 # Sanitizer, if it was used for the build.
 #
-- 
2.31.1



More information about the dev mailing list