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
This commit is contained in:
Marc-André Lureau 2018-03-06 11:38:45 -05:00 committed by Lioncash
parent a78892c2f5
commit 001a86f02d
No known key found for this signature in database
GPG key ID: 4E3C3CC1031BA9C7

34
qemu/configure vendored
View file

@ -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"