From: Arran Cudbard-Bell Date: Wed, 5 Jul 2017 17:36:55 +0000 (-0400) Subject: Enable LLVM's address sanitizer for clang builds X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=526a93d75963f3ffc0a7d4fdae1e4c53feade719;p=thirdparty%2Ffreeradius-server.git Enable LLVM's address sanitizer for clang builds --- diff --git a/configure b/configure index ae703ba00b3..2107741c562 100755 --- a/configure +++ b/configure @@ -739,6 +739,7 @@ enable_developer enable_largefile enable_strict_dependencies enable_werror +enable_llvm_address_sanitizer enable_openssl_version_check with_rlm_FOO_lib_dir with_rlm_FOO_include_dir @@ -1415,6 +1416,9 @@ Optional Features: --disable-largefile omit support for large files --enable-strict-dependencies fail configure on lack of module dependancy. --enable-werror causes the build to fail if any warnings are generated. + --enable-llvm-address-sanitizer + build with support for LLVM's address sanitizer (if + building with clang). --disable-openssl-version-check disable vulnerable OpenSSL version check @@ -5232,6 +5236,19 @@ if test "${enable_werror+set}" = set; then : fi +# Check whether --enable-llvm-address-sanitizer was given. +if test "${enable_llvm_address_sanitizer+set}" = set; then : + enableval=$enable_llvm_address_sanitizer; case "$enableval" in + no) + llvm_address_sanitizer=no + ;; + *) + llvm_address_sanitizer=yes + esac + +fi + + # Check whether --enable-openssl-version-check was given. if test "${enable_openssl_version_check+set}" = set; then : enableval=$enable_openssl_version_check; @@ -12442,12 +12459,19 @@ $as_echo "$ax_cv_cc_weverything_flag" >&6; } fi fi + if test "x$llvm_address_sanitizer" = "xyes" && test "x$ax_cv_cc_clang" = "xyes"; then + devcflags="$devcflags -fsanitize=address -fno-omit-frame-pointer" + devldflags="$devldflags -fsanitize=address" + fi + { $as_echo "$as_me:${as_lineno-$LINENO}: Developer CFLAGS are \"$devcflags\"" >&5 $as_echo "$as_me: Developer CFLAGS are \"$devcflags\"" >&6;} { $as_echo "$as_me:${as_lineno-$LINENO}: Developer LDFLAGS are \"$devldflags\"" >&5 $as_echo "$as_me: Developer LDFLAGS are \"$devldflags\"" >&6;} CFLAGS="$CFLAGS $devcflags" + LDFLAGS="$LDFLAGS $devldflags" + if test "x$EXPERIMENTAL" != "xno"; then { $as_echo "$as_me:${as_lineno-$LINENO}: is developer build, enabling experimental modules implicitly, disable with --without-experimental-modules" >&5 $as_echo "$as_me: is developer build, enabling experimental modules implicitly, disable with --without-experimental-modules" >&6;} diff --git a/configure.ac b/configure.ac index 952854191b7..f6f7919fb41 100644 --- a/configure.ac +++ b/configure.ac @@ -238,6 +238,22 @@ AC_ARG_ENABLE(werror, esac ] ) +dnl # +dnl # Enable the -fsanitize=address and link in the address sanitizer +dnl # libraries. +dnl # +AC_ARG_ENABLE(llvm-address-sanitizer, +[AS_HELP_STRING([--enable-llvm-address-sanitizer], + [build with support for LLVM's address sanitizer (if building with clang).])], +[ case "$enableval" in + no) + llvm_address_sanitizer=no + ;; + *) + llvm_address_sanitizer=yes + esac ] +) + dnl # dnl # extra argument: --disable-openssl-version-check dnl # @@ -1535,10 +1551,20 @@ if test "x$developer" = "xyes"; then fi fi + dnl # + dnl # If running with clang, add in ASAN + dnl # + if test "x$llvm_address_sanitizer" = "xyes" && test "x$ax_cv_cc_clang" = "xyes"; then + devcflags="$devcflags -fsanitize=address -fno-omit-frame-pointer" + devldflags="$devldflags -fsanitize=address" + fi + AC_MSG_NOTICE([Developer CFLAGS are "$devcflags"]) AC_MSG_NOTICE([Developer LDFLAGS are "$devldflags"]) CFLAGS="$CFLAGS $devcflags" + LDFLAGS="$LDFLAGS $devldflags" + dnl # dnl # Enable experimental modules (we want to know if code changes breaks one of them) dnl # diff --git a/scripts/travis/build.sh b/scripts/travis/build.sh index c49a8aea74b..f98332ad082 100755 --- a/scripts/travis/build.sh +++ b/scripts/travis/build.sh @@ -1,5 +1,7 @@ #!/bin/sh -e +enable_llvm_address_sanitizer="" + # # If this Travis matrix element does not require the build, we still need to run # configure to make sure any autoconf generated files (tls-h et al) are still @@ -11,15 +13,25 @@ if [ "${DO_BUILD}" = 'no' ]; then exit 0 fi +# +# Enable address sanitizer for the clang builds +# +if $CC -v 2>&1 | grep clang > /dev/null; then + enable_address_sanitizer="--enable-llvm-address-sanitizer" +else + enable_address_sanitizer="" +fi + # # Configure the server as per the build matrix # -# We specify -with-rlm-python-bin because Otherwise travis picks up +# We specify -with-rlm-python-bin because Otherwise travis picks up # /opt/python, which doesn't have .so available # echo "Performing full configuration" CFLAGS="${BUILD_CFLAGS}" ./configure -C \ --enable-werror \ + $enable_address_sanitizer \ --prefix=$HOME/freeradius \ --with-shared-libs=$LIBS_SHARED \ --with-threads=$LIBS_OPTIONAL \