3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-12-22 13:02:44 +01:00

build: Add support for various sanitizers

Shamelessly stolen from the ell build system.  Credit goes to:

Mat Martineau <mathew.j.martineau@linux.intel.com>
This commit is contained in:
Denis Kenzior 2019-01-11 11:32:54 -06:00
parent c2189bc67e
commit 3063c4968a
2 changed files with 80 additions and 0 deletions

View File

@ -10,6 +10,42 @@ AC_DEFUN([AC_PROG_CC_PIE], [
])
])
AC_DEFUN([AC_PROG_CC_ASAN], [
AC_CACHE_CHECK([whether ${CC-cc} accepts -fsanitize=address], ac_cv_prog_cc_asan, [
echo 'void f(){}' > conftest.c
if test -z "`${CC-cc} -fsanitize=address -c conftest.c 2>&1`"; then
ac_cv_prog_cc_asan=yes
else
ac_cv_prog_cc_asan=no
fi
rm -rf conftest*
])
])
AC_DEFUN([AC_PROG_CC_LSAN], [
AC_CACHE_CHECK([whether ${CC-cc} accepts -fsanitize=leak], ac_cv_prog_cc_lsan, [
echo 'void f(){}' > conftest.c
if test -z "`${CC-cc} -fsanitize=leak -c conftest.c 2>&1`"; then
ac_cv_prog_cc_lsan=yes
else
ac_cv_prog_cc_lsan=no
fi
rm -rf conftest*
])
])
AC_DEFUN([AC_PROG_CC_UBSAN], [
AC_CACHE_CHECK([whether ${CC-cc} accepts -fsanitize=undefined], ac_cv_prog_cc_ubsan, [
echo 'void f(){}' > conftest.c
if test -z "`${CC-cc} -fsanitize=undefined -c conftest.c 2>&1`"; then
ac_cv_prog_cc_ubsan=yes
else
ac_cv_prog_cc_ubsan=no
fi
rm -rf conftest*
])
])
AC_DEFUN([COMPILER_FLAGS], [
if (test "${CFLAGS}" = ""); then
CFLAGS="-Wall -O2 -fsigned-char -fno-exceptions"

View File

@ -22,6 +22,9 @@ AC_LANG_C
AC_PROG_CC
AC_PROG_CC_PIE
AC_PROG_CC_ASAN
AC_PROG_CC_LSAN
AC_PROG_CC_UBSAN
AC_PROG_INSTALL
AC_PROG_MKDIR_P
AC_PROG_LN_S
@ -55,6 +58,47 @@ AC_ARG_ENABLE(pie, AC_HELP_STRING([--enable-pie],
fi
])
save_LIBS=$LIBS
AC_CHECK_LIB(asan, _init)
LIBS=$save_LIBS
AC_ARG_ENABLE(asan, AC_HELP_STRING([--enable-asan],
[enable linking with address sanitizer]), [
if (test "${enableval}" = "yes" &&
test "${ac_cv_lib_asan__init}" = "yes" &&
test "${ac_cv_prog_cc_asan}" = "yes"); then
CFLAGS="$CFLAGS -fsanitize=address";
LDFLAGS="$LDFLAGS -fsanitize=address"
fi
])
save_LIBS=$LIBS
AC_CHECK_LIB(lsan, _init)
LIBS=$save_LIBS
AC_ARG_ENABLE(lsan, AC_HELP_STRING([--enable-lsan],
[enable linking with leak sanitizer]), [
if (test "${enableval}" = "yes" &&
test "${ac_cv_lib_lsan__init}" = "yes" &&
test "${ac_cv_prog_cc_lsan}" = "yes"); then
CFLAGS="$CFLAGS -fsanitize=leak";
LDFLAGS="$LDFLAGS -fsanitize=leak"
fi
])
save_LIBS=$LIBS
AC_CHECK_LIB(ubsan, _init)
LIBS=$save_LIBS
AC_ARG_ENABLE(ubsan, AC_HELP_STRING([--enable-ubsan],
[enable linking with undefined behavior sanitizer]), [
if (test "${enableval}" = "yes" &&
test "${ac_cv_lib_ubsan__init}" = "yes" &&
test "${ac_cv_prog_cc_ubsan}" = "yes"); then
CFLAGS="$CFLAGS -fsanitize=undefined";
LDFLAGS="$LDFLAGS -fsanitize=undefined"
fi
])
if (test "${prefix}" = "NONE"); then
dnl no prefix and no localstatedir, so default to /var
if (test "$localstatedir" = '${prefix}/var'); then