From 001a86f02dd7a19dfe32dda38f2c47a2f93e5668 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Tue, 6 Mar 2018 11:38:45 -0500 Subject: [PATCH] build-sys: add --enable-sanitizers Typical slowdown introduced by AddressSanitizer is 2x. UBSan shouldn't have much impact on runtime cost. Enable it by default when --enable-debug, unless --disable-sanitizers. Backports commit 247724cb302af5d70c8853154b640dfabf2bbb56 from qemu --- qemu/configure | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/qemu/configure b/qemu/configure index 8ae8b7a4..4b336af9 100755 --- a/qemu/configure +++ b/qemu/configure @@ -161,6 +161,7 @@ unset target_list debug_tcg="no" debug="no" +sanitizers="no" strip_opt="yes" tcg_interpreter="no" bigendian="no" @@ -199,6 +200,10 @@ for opt do ;; --disable-debug-info) debug_info="no" ;; + --enable-sanitizers) sanitizers="yes" + ;; + --disable-sanitizers) sanitizers="no" + ;; esac done # OS specific @@ -656,6 +661,7 @@ Advanced options (experts only): --enable-debug-info enable debugging information (default) --disable-debug-info disable debugging information --enable-debug enable common debug build options + --enable-sanitizers enable default sanitizers --disable-strip disable stripping binaries --disable-werror disable compilation abort on warning --disable-stack-protector disable compiler-provided stack protection @@ -1129,6 +1135,34 @@ if compile_prog "" "" ; then atomic64=yes fi +########################################## +# checks for sanitizers + +write_c_skeleton + +have_asan=no +have_ubsan=no + +if test "$sanitizers" = "yes" ; then + if compile_prog "$CPU_CFLAGS -Werror -fsanitize=address" ""; then + have_asan=yes + fi + if compile_prog "$CPU_CFLAGS -Werror -fsanitize=undefined" ""; then + have_ubsan=yes + fi +fi + +########################################## +# End of CC checks +# After here, no more $cc or $ld runs + +if test "$have_asan" = "yes"; then + CFLAGS="-fsanitize=address $CFLAGS" +fi +if test "$have_ubsan" = "yes"; then + CFLAGS="-fsanitize=undefined $CFLAGS" +fi + # Now we've finished running tests it's OK to add -Werror to the compiler flags if test "$werror" = "yes"; then QEMU_CFLAGS="-Werror $QEMU_CFLAGS"