Add --enable-sanitizers, fix `make check` with it

It's cleaner if this is an build option rather than being
kludged into the CI layer.

Notably we can't use `LD_PRELOAD` anymore with ASAN, so update
our tests to check for `ASAN_OPTIONS`.
This commit is contained in:
Colin Walters 2021-02-03 14:48:49 +00:00
parent 0485817978
commit d49f3291ad
3 changed files with 15 additions and 12 deletions

View File

@ -5,8 +5,7 @@ set -xeuo pipefail
dn=$(dirname $0) dn=$(dirname $0)
. ${dn}/libbuild.sh . ${dn}/libbuild.sh
export CFLAGS='-fsanitize=address -fsanitize=undefined -fsanitize-undefined-trap-on-error'
# We leak global state in a few places, fixing that is hard. # We leak global state in a few places, fixing that is hard.
export ASAN_OPTIONS='detect_leaks=0' export ASAN_OPTIONS='detect_leaks=0'
${dn}/build.sh build --disable-gtk-doc --with-curl --with-openssl --enable-sanitizers
make check make check

View File

@ -51,16 +51,17 @@ CC_CHECK_FLAGS_APPEND([WARN_CFLAGS], [CFLAGS], [\
])]) ])])
AC_SUBST(WARN_CFLAGS) AC_SUBST(WARN_CFLAGS)
AC_MSG_CHECKING([for -fsanitize=address in CFLAGS]) AC_ARG_ENABLE(sanitizers,
if echo $CFLAGS | grep -q -e -fsanitize=address; then AS_HELP_STRING([--enable-sanitizers],
AC_MSG_RESULT([yes]) [Enable ASAN and UBSAN (default: no)]),,
using_asan=yes [enable_sanitizers=no])
else AM_CONDITIONAL(BUILDOPT_ASAN, [test x$enable_sanitizers != xno])
AC_MSG_RESULT([no]) AM_COND_IF([BUILDOPT_ASAN], [
fi sanitizer_flags="-fsanitize=address -fsanitize=undefined -fsanitize-undefined-trap-on-error"
AM_CONDITIONAL(BUILDOPT_ASAN, [test x$using_asan = xyes]) CFLAGS="$CFLAGS ${sanitizer_flags}"
AM_COND_IF([BUILDOPT_ASAN], CXXFLAGS="$CXXFLAGS ${sanitizer_flags}"
[AC_DEFINE([BUILDOPT_ASAN], 1, [Define if we are building with -fsanitize=address])]) AC_DEFINE([BUILDOPT_ASAN], 1, [Define if we are building with asan and ubsan])
])
AC_MSG_CHECKING([for -fsanitize=thread in CFLAGS]) AC_MSG_CHECKING([for -fsanitize=thread in CFLAGS])
if echo $CFLAGS | grep -q -e -fsanitize=thread; then if echo $CFLAGS | grep -q -e -fsanitize=thread; then

View File

@ -147,6 +147,9 @@ fi
# This is substituted by the build for installed tests # This is substituted by the build for installed tests
BUILT_WITH_ASAN="" BUILT_WITH_ASAN=""
if test -n "${ASAN_OPTIONS:-}"; then
BUILT_WITH_ASAN=1
fi
if test -n "${OT_TESTS_VALGRIND:-}"; then if test -n "${OT_TESTS_VALGRIND:-}"; then
CMD_PREFIX="env G_SLICE=always-malloc OSTREE_SUPPRESS_SYNCFS=1 valgrind -q --error-exitcode=1 --leak-check=full --num-callers=30 --suppressions=${test_srcdir}/glib.supp --suppressions=${test_srcdir}/ostree.supp" CMD_PREFIX="env G_SLICE=always-malloc OSTREE_SUPPRESS_SYNCFS=1 valgrind -q --error-exitcode=1 --leak-check=full --num-callers=30 --suppressions=${test_srcdir}/glib.supp --suppressions=${test_srcdir}/ostree.supp"