diff options
author | Luiz Augusto von Dentz <luiz.von.dentz@intel.com> | 2021-12-20 15:49:45 -0800 |
---|---|---|
committer | Luiz Augusto von Dentz <luiz.von.dentz@intel.com> | 2021-12-22 15:16:30 -0800 |
commit | 4839b1135d68adca9d58a0226734cac4a9793071 (patch) | |
tree | 2af91e251f27f0f6ae401d7e145755bd9f808dfc /acinclude.m4 | |
parent | 32a006f92a0f3cd3ce95d4df61e887e0d702a151 (diff) | |
download | bluez-4839b1135d68adca9d58a0226734cac4a9793071.tar.gz |
build: Add sanitizer options
Build using Address Sanitizer (asan), Leak Sanitizer (lsan), or
Undefined Behavior Sanitizer (ubsan) by using one of these options for
the configure script:
--enable-asan
--enable-lsan
--enable-ubsan
For each of these to work, the compiler must support the requested
sanitizer and the requisite libraries must be installed (libasan,
liblsan, libubsan).
Diffstat (limited to 'acinclude.m4')
-rw-r--r-- | acinclude.m4 | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/acinclude.m4 b/acinclude.m4 index 529848357..b388dfc11 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -10,6 +10,45 @@ 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(){}' > asan.c + if test -z "`${CC-cc} -fsanitize=address -c asan.c 2>&1`"; then + ac_cv_prog_cc_asan=yes + else + ac_cv_prog_cc_asan=no + fi + rm -rf asan* + ]) +]) + +AC_DEFUN([AC_PROG_CC_LSAN], [ + AC_CACHE_CHECK([whether ${CC-cc} accepts -fsanitize=leak], + ac_cv_prog_cc_lsan, [ + echo 'void f(){}' > lsan.c + if test -z "`${CC-cc} -fsanitize=leak -c lsan.c 2>&1`"; then + ac_cv_prog_cc_lsan=yes + else + ac_cv_prog_cc_lsan=no + fi + rm -rf lsan* + ]) +]) + +AC_DEFUN([AC_PROG_CC_UBSAN], [ + AC_CACHE_CHECK([whether ${CC-cc} accepts -fsanitize=undefined], + ac_cv_prog_cc_ubsan, [ + echo 'void f(){}' > ubsan.c + if test -z "`${CC-cc} -fsanitize=undefined -c ubsan.c 2>&1`"; then + ac_cv_prog_cc_ubsan=yes + else + ac_cv_prog_cc_ubsan=no + fi + rm -rf ubsan* + ]) +]) + AC_DEFUN([COMPILER_FLAGS], [ with_cflags="" if (test "$USE_MAINTAINER_MODE" = "yes"); then @@ -38,6 +77,44 @@ AC_DEFUN([MISC_FLAGS], [ misc_cflags="$misc_cflags -O0" fi ]) + AC_ARG_ENABLE(asan, AC_HELP_STRING([--enable-asan], + [enable linking with address sanitizer]), [ + save_LIBS=$LIBS + AC_CHECK_LIB(asan, _init) + LIBS=$save_LIBS + if (test "${enableval}" = "yes" && + test "${ac_cv_lib_asan__init}" = "yes" && + test "${ac_cv_prog_cc_asan}" = "yes"); then + misc_cflags="$misc_cflags -fsanitize=address"; + misc_ldflags="$misc_ldflags -fsanitize=address" + AC_SUBST([ASAN_LIB], ${ac_cv_lib_asan__init}) + fi + ]) + AC_ARG_ENABLE(lsan, AC_HELP_STRING([--enable-lsan], + [enable linking with address sanitizer]), [ + save_LIBS=$LIBS + AC_CHECK_LIB(lsan, _init) + LIBS=$save_LIBS + if (test "${enableval}" = "yes" && + test "${ac_cv_lib_lsan__init}" = "yes" && + test "${ac_cv_prog_cc_lsan}" = "yes"); then + misc_cflags="$misc_cflags -fsanitize=leak"; + misc_ldflags="$misc_ldflags -fsanitize=leak" + AC_SUBST([ASAN_LIB], ${ac_cv_lib_lsan__init}) + fi + ]) + AC_ARG_ENABLE(ubsan, AC_HELP_STRING([--enable-ubsan], + [enable linking with address sanitizer]), [ + save_LIBS=$LIBS + AC_CHECK_LIB(ubsan, _init) + LIBS=$save_LIBS + if (test "${enableval}" = "yes" && + test "${ac_cv_lib_ubsan__init}" = "yes" && + test "${ac_cv_prog_cc_ubsan}" = "yes"); then + misc_cflags="$misc_cflags -fsanitize=undefined"; + misc_ldflags="$misc_ldflags -fsanitize=undefined"; + fi + ]) AC_ARG_ENABLE(debug, AC_HELP_STRING([--enable-debug], [enable compiling with debugging information]), [ if (test "${enableval}" = "yes" && |