mirror of
https://github.com/xemu-project/xemu.git
synced 2025-02-25 07:02:38 +00:00
build: move sanitizer tests to meson
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
d67212d47f
commit
34f983d86f
147
configure
vendored
147
configure
vendored
@ -275,9 +275,6 @@ EXTRA_OBJCFLAGS=""
|
||||
EXTRA_LDFLAGS=""
|
||||
|
||||
debug_tcg="no"
|
||||
sanitizers="no"
|
||||
tsan="no"
|
||||
fortify_source="yes"
|
||||
docs="auto"
|
||||
EXESUF=""
|
||||
prefix="/usr/local"
|
||||
@ -416,14 +413,6 @@ EOF
|
||||
compile_object
|
||||
}
|
||||
|
||||
check_include() {
|
||||
cat > $TMPC <<EOF
|
||||
#include <$1>
|
||||
int main(void) { return 0; }
|
||||
EOF
|
||||
compile_object
|
||||
}
|
||||
|
||||
write_c_skeleton() {
|
||||
cat > $TMPC <<EOF
|
||||
int main(void) { return 0; }
|
||||
@ -806,15 +795,6 @@ for opt do
|
||||
meson_option_parse --enable-debug-graph-lock ""
|
||||
meson_option_parse --enable-debug-mutex ""
|
||||
meson_option_add -Doptimization=0
|
||||
fortify_source="no"
|
||||
;;
|
||||
--enable-sanitizers) sanitizers="yes"
|
||||
;;
|
||||
--disable-sanitizers) sanitizers="no"
|
||||
;;
|
||||
--enable-tsan) tsan="yes"
|
||||
;;
|
||||
--disable-tsan) tsan="no"
|
||||
;;
|
||||
--disable-tcg) tcg="disabled"
|
||||
plugins="no"
|
||||
@ -1025,8 +1005,6 @@ Advanced options (experts only):
|
||||
desired devices in configs/devices/)
|
||||
--with-devices-ARCH=NAME override default configs/devices
|
||||
--enable-debug enable common debug build options
|
||||
--enable-sanitizers enable default sanitizers
|
||||
--enable-tsan enable thread sanitizer
|
||||
--disable-werror disable compilation abort on warning
|
||||
--disable-stack-protector disable compiler-provided stack protection
|
||||
--cpu=CPU Build for host CPU [$cpu]
|
||||
@ -1633,87 +1611,6 @@ if ! compile_object "-Werror"; then
|
||||
ccache_cpp2=yes
|
||||
fi
|
||||
|
||||
#################################################
|
||||
# clang does not support glibc + FORTIFY_SOURCE.
|
||||
|
||||
if test "$fortify_source" != "no"; then
|
||||
if echo | $cc -dM -E - | grep __clang__ > /dev/null 2>&1 ; then
|
||||
fortify_source="no";
|
||||
elif test -n "$cxx" && has $cxx &&
|
||||
echo | $cxx -dM -E - | grep __clang__ >/dev/null 2>&1 ; then
|
||||
fortify_source="no";
|
||||
else
|
||||
fortify_source="yes"
|
||||
fi
|
||||
fi
|
||||
|
||||
##########################################
|
||||
# checks for sanitizers
|
||||
|
||||
have_asan=no
|
||||
have_ubsan=no
|
||||
have_asan_iface_h=no
|
||||
have_asan_iface_fiber=no
|
||||
|
||||
if test "$sanitizers" = "yes" ; then
|
||||
write_c_skeleton
|
||||
if compile_prog "$CPU_CFLAGS -Werror -fsanitize=address" ""; then
|
||||
have_asan=yes
|
||||
fi
|
||||
|
||||
# we could use a simple skeleton for flags checks, but this also
|
||||
# detect the static linking issue of ubsan, see also:
|
||||
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84285
|
||||
cat > $TMPC << EOF
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
return argc + 1;
|
||||
}
|
||||
EOF
|
||||
if compile_prog "$CPU_CFLAGS -Werror -fsanitize=undefined" ""; then
|
||||
have_ubsan=yes
|
||||
fi
|
||||
|
||||
if check_include "sanitizer/asan_interface.h" ; then
|
||||
have_asan_iface_h=yes
|
||||
fi
|
||||
|
||||
cat > $TMPC << EOF
|
||||
#include <sanitizer/asan_interface.h>
|
||||
int main(void) {
|
||||
__sanitizer_start_switch_fiber(0, 0, 0);
|
||||
return 0;
|
||||
}
|
||||
EOF
|
||||
if compile_prog "$CPU_CFLAGS -Werror -fsanitize=address" "" ; then
|
||||
have_asan_iface_fiber=yes
|
||||
fi
|
||||
fi
|
||||
|
||||
# Thread sanitizer is, for now, much noisier than the other sanitizers;
|
||||
# keep it separate until that is not the case.
|
||||
if test "$tsan" = "yes" && test "$sanitizers" = "yes"; then
|
||||
error_exit "TSAN is not supported with other sanitiziers."
|
||||
fi
|
||||
have_tsan=no
|
||||
have_tsan_iface_fiber=no
|
||||
if test "$tsan" = "yes" ; then
|
||||
write_c_skeleton
|
||||
if compile_prog "$CPU_CFLAGS -Werror -fsanitize=thread" "" ; then
|
||||
have_tsan=yes
|
||||
fi
|
||||
cat > $TMPC << EOF
|
||||
#include <sanitizer/tsan_interface.h>
|
||||
int main(void) {
|
||||
__tsan_create_fiber(0);
|
||||
return 0;
|
||||
}
|
||||
EOF
|
||||
if compile_prog "$CPU_CFLAGS -Werror -fsanitize=thread" "" ; then
|
||||
have_tsan_iface_fiber=yes
|
||||
fi
|
||||
fi
|
||||
|
||||
##########################################
|
||||
# functions to probe cross compilers
|
||||
|
||||
@ -2139,42 +2036,6 @@ case "$vfio_user_server" in
|
||||
;;
|
||||
esac
|
||||
|
||||
##########################################
|
||||
# End of CC checks
|
||||
# After here, no more $cc or $ld runs
|
||||
|
||||
write_c_skeleton
|
||||
|
||||
if test "$fortify_source" = "yes" ; then
|
||||
QEMU_CFLAGS="-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 $QEMU_CFLAGS"
|
||||
fi
|
||||
|
||||
if test "$have_asan" = "yes"; then
|
||||
QEMU_CFLAGS="-fsanitize=address $QEMU_CFLAGS"
|
||||
QEMU_LDFLAGS="-fsanitize=address $QEMU_LDFLAGS"
|
||||
if test "$have_asan_iface_h" = "no" ; then
|
||||
echo "ASAN build enabled, but ASAN header missing." \
|
||||
"Without code annotation, the report may be inferior."
|
||||
elif test "$have_asan_iface_fiber" = "no" ; then
|
||||
echo "ASAN build enabled, but ASAN header is too old." \
|
||||
"Without code annotation, the report may be inferior."
|
||||
fi
|
||||
fi
|
||||
if test "$have_tsan" = "yes" ; then
|
||||
if test "$have_tsan_iface_fiber" = "yes" ; then
|
||||
QEMU_CFLAGS="-fsanitize=thread $QEMU_CFLAGS"
|
||||
QEMU_LDFLAGS="-fsanitize=thread $QEMU_LDFLAGS"
|
||||
else
|
||||
error_exit "Cannot enable TSAN due to missing fiber annotation interface."
|
||||
fi
|
||||
elif test "$tsan" = "yes" ; then
|
||||
error_exit "Cannot enable TSAN due to missing sanitize thread interface."
|
||||
fi
|
||||
if test "$have_ubsan" = "yes"; then
|
||||
QEMU_CFLAGS="-fsanitize=undefined $QEMU_CFLAGS"
|
||||
QEMU_LDFLAGS="-fsanitize=undefined $QEMU_LDFLAGS"
|
||||
fi
|
||||
|
||||
#######################################
|
||||
# cross-compiled firmware targets
|
||||
|
||||
@ -2299,14 +2160,6 @@ fi
|
||||
|
||||
echo "CONFIG_COROUTINE_BACKEND=$coroutine" >> $config_host_mak
|
||||
|
||||
if test "$have_asan_iface_fiber" = "yes" ; then
|
||||
echo "CONFIG_ASAN_IFACE_FIBER=y" >> $config_host_mak
|
||||
fi
|
||||
|
||||
if test "$have_tsan" = "yes" && test "$have_tsan_iface_fiber" = "yes" ; then
|
||||
echo "CONFIG_TSAN=y" >> $config_host_mak
|
||||
fi
|
||||
|
||||
if test "$plugins" = "yes" ; then
|
||||
echo "CONFIG_PLUGIN=y" >> $config_host_mak
|
||||
fi
|
||||
|
@ -91,10 +91,6 @@ developers in checking for system features:
|
||||
``check_define $NAME``
|
||||
Determine if the macro $NAME is defined by the system C compiler
|
||||
|
||||
``check_include $NAME``
|
||||
Determine if the include $NAME file is available to the system C
|
||||
compiler. The replacement in Meson is ``cc.has_header()``.
|
||||
|
||||
``write_c_skeleton``
|
||||
Write a minimal C program main() function to the temporary file
|
||||
indicated by $TMPC
|
||||
|
56
meson.build
56
meson.build
@ -211,6 +211,35 @@ if get_option('prefer_static')
|
||||
qemu_ldflags += get_option('b_pie') ? '-static-pie' : '-static'
|
||||
endif
|
||||
|
||||
if get_option('sanitizers')
|
||||
if cc.has_argument('-fsanitize=address')
|
||||
qemu_cflags = ['-fsanitize=address'] + qemu_cflags
|
||||
qemu_ldflags = ['-fsanitize=address'] + qemu_ldflags
|
||||
endif
|
||||
|
||||
# Detect static linking issue with ubsan - https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84285
|
||||
if cc.links('int main(int argc, char **argv) { return argc + 1; }',
|
||||
args: [qemu_ldflags, '-fsanitize=undefined'])
|
||||
qemu_cflags = ['-fsanitize=undefined'] + qemu_cflags
|
||||
qemu_ldflags = ['-fsanitize=undefined'] + qemu_ldflags
|
||||
endif
|
||||
endif
|
||||
|
||||
# Thread sanitizer is, for now, much noisier than the other sanitizers;
|
||||
# keep it separate until that is not the case.
|
||||
if get_option('tsan')
|
||||
if get_option('sanitizers')
|
||||
error('TSAN is not supported with other sanitizers')
|
||||
endif
|
||||
if not cc.has_function('__tsan_create_fiber',
|
||||
args: '-fsanitize=thread',
|
||||
prefix: '#include <sanitizer/tsan_interface.h>')
|
||||
error('Cannot enable TSAN due to missing fiber annotation interface')
|
||||
endif
|
||||
qemu_cflags = ['-fsanitize=thread'] + qemu_cflags
|
||||
qemu_ldflags = ['-fsanitize=thread'] + qemu_ldflags
|
||||
endif
|
||||
|
||||
# Detect support for PT_GNU_RELRO + DT_BIND_NOW.
|
||||
# The combination is known as "full relro", because .got.plt is read-only too.
|
||||
qemu_ldflags += cc.get_supported_link_arguments('-Wl,-z,relro', '-Wl,-z,now')
|
||||
@ -221,7 +250,7 @@ if targetos == 'windows'
|
||||
endif
|
||||
|
||||
# Exclude --warn-common with TSan to suppress warnings from the TSan libraries.
|
||||
if targetos != 'sunos' and not config_host.has_key('CONFIG_TSAN')
|
||||
if targetos != 'sunos' and not get_option('tsan')
|
||||
qemu_ldflags += cc.get_supported_link_arguments('-Wl,--warn-common')
|
||||
endif
|
||||
|
||||
@ -284,6 +313,16 @@ if 'cpp' in all_languages
|
||||
endif
|
||||
endif
|
||||
|
||||
# clang does not support glibc + FORTIFY_SOURCE (is it still true?)
|
||||
if get_option('optimization') != '0' and targetos == 'linux'
|
||||
if cc.get_id() == 'gcc'
|
||||
qemu_cflags += ['-U_FORTIFY_SOURCE', '-D_FORTIFY_SOURCE=2']
|
||||
endif
|
||||
if 'cpp' in all_languages and cxx.get_id() == 'gcc'
|
||||
qemu_cxxflags += ['-U_FORTIFY_SOURCE', '-D_FORTIFY_SOURCE=2']
|
||||
endif
|
||||
endif
|
||||
|
||||
add_project_arguments(qemu_cflags, native: false, language: 'c')
|
||||
add_project_arguments(qemu_cxxflags, native: false, language: 'cpp')
|
||||
add_project_arguments(qemu_objcflags, native: false, language: 'objc')
|
||||
@ -1920,6 +1959,7 @@ if seccomp.found()
|
||||
endif
|
||||
config_host_data.set('CONFIG_SNAPPY', snappy.found())
|
||||
config_host_data.set('CONFIG_TPM', have_tpm)
|
||||
config_host_data.set('CONFIG_TSAN', get_option('tsan'))
|
||||
config_host_data.set('CONFIG_USB_LIBUSB', libusb.found())
|
||||
config_host_data.set('CONFIG_VDE', vde.found())
|
||||
config_host_data.set('CONFIG_VHOST_NET', have_vhost_net)
|
||||
@ -2051,6 +2091,18 @@ if rdma.found()
|
||||
prefix: '#include <infiniband/verbs.h>'))
|
||||
endif
|
||||
|
||||
have_asan_fiber = false
|
||||
if get_option('sanitizers') and \
|
||||
not cc.has_function('__sanitizer_start_switch_fiber',
|
||||
args: '-fsanitize=address',
|
||||
prefix: '#include <sanitizer/asan_interface.h>')
|
||||
warning('Missing ASAN due to missing fiber annotation interface')
|
||||
warning('Without code annotation, the report may be inferior.')
|
||||
else
|
||||
have_asan_fiber = true
|
||||
endif
|
||||
config_host_data.set('CONFIG_ASAN_IFACE_FIBER', have_asan_fiber)
|
||||
|
||||
# has_header_symbol
|
||||
config_host_data.set('CONFIG_BLKZONED',
|
||||
cc.has_header_symbol('linux/blkzoned.h', 'BLKOPENZONE'))
|
||||
@ -3898,7 +3950,7 @@ else
|
||||
endif
|
||||
summary_info += {'gprof': gprof_info}
|
||||
summary_info += {'gcov': get_option('b_coverage')}
|
||||
summary_info += {'thread sanitizer': config_host.has_key('CONFIG_TSAN')}
|
||||
summary_info += {'thread sanitizer': get_option('tsan')}
|
||||
summary_info += {'CFI support': get_option('cfi')}
|
||||
if get_option('cfi')
|
||||
summary_info += {'CFI debug support': get_option('cfi_debug')}
|
||||
|
@ -82,6 +82,10 @@ option('tcg', type: 'feature', value: 'enabled',
|
||||
description: 'TCG support')
|
||||
option('tcg_interpreter', type: 'boolean', value: false,
|
||||
description: 'TCG with bytecode interpreter (slow)')
|
||||
option('sanitizers', type: 'boolean', value: false,
|
||||
description: 'enable default sanitizers')
|
||||
option('tsan', type: 'boolean', value: false,
|
||||
description: 'enable thread sanitizer')
|
||||
option('cfi', type: 'boolean', value: false,
|
||||
description: 'Control-Flow Integrity (CFI)')
|
||||
option('cfi_debug', type: 'boolean', value: false,
|
||||
|
@ -41,11 +41,13 @@ meson_options_help() {
|
||||
printf "%s\n" ' --enable-profiler profiler support'
|
||||
printf "%s\n" ' --enable-rng-none dummy RNG, avoid using /dev/(u)random and'
|
||||
printf "%s\n" ' getrandom()'
|
||||
printf "%s\n" ' --enable-sanitizers enable default sanitizers'
|
||||
printf "%s\n" ' --enable-strip Strip targets on install'
|
||||
printf "%s\n" ' --enable-tcg-interpreter TCG with bytecode interpreter (slow)'
|
||||
printf "%s\n" ' --enable-trace-backends=CHOICES'
|
||||
printf "%s\n" ' Set available tracing backends [log] (choices:'
|
||||
printf "%s\n" ' dtrace/ftrace/log/nop/simple/syslog/ust)'
|
||||
printf "%s\n" ' --enable-tsan enable thread sanitizer'
|
||||
printf "%s\n" ' --firmwarepath=VALUES search PATH for firmware files [share/qemu-'
|
||||
printf "%s\n" ' firmware]'
|
||||
printf "%s\n" ' --iasl=VALUE Path to ACPI disassembler'
|
||||
@ -408,6 +410,8 @@ _meson_option_parse() {
|
||||
--disable-replication) printf "%s" -Dreplication=disabled ;;
|
||||
--enable-rng-none) printf "%s" -Drng_none=true ;;
|
||||
--disable-rng-none) printf "%s" -Drng_none=false ;;
|
||||
--enable-sanitizers) printf "%s" -Dsanitizers=true ;;
|
||||
--disable-sanitizers) printf "%s" -Dsanitizers=false ;;
|
||||
--enable-sdl) printf "%s" -Dsdl=enabled ;;
|
||||
--disable-sdl) printf "%s" -Dsdl=disabled ;;
|
||||
--enable-sdl-image) printf "%s" -Dsdl_image=enabled ;;
|
||||
@ -446,6 +450,8 @@ _meson_option_parse() {
|
||||
--disable-tpm) printf "%s" -Dtpm=disabled ;;
|
||||
--enable-trace-backends=*) quote_sh "-Dtrace_backends=$2" ;;
|
||||
--with-trace-file=*) quote_sh "-Dtrace_file=$2" ;;
|
||||
--enable-tsan) printf "%s" -Dtsan=true ;;
|
||||
--disable-tsan) printf "%s" -Dtsan=false ;;
|
||||
--enable-u2f) printf "%s" -Du2f=enabled ;;
|
||||
--disable-u2f) printf "%s" -Du2f=disabled ;;
|
||||
--enable-usb-redir) printf "%s" -Dusb_redir=enabled ;;
|
||||
|
@ -2,7 +2,7 @@ if not have_tools or targetos == 'windows' or get_option('gprof')
|
||||
subdir_done()
|
||||
endif
|
||||
|
||||
foreach cflag: config_host['QEMU_CFLAGS'].split()
|
||||
foreach cflag: qemu_ldflags
|
||||
if cflag.startswith('-fsanitize') and \
|
||||
not cflag.contains('safe-stack') and not cflag.contains('cfi-icall')
|
||||
message('Sanitizers are enabled ==> Disabled the qemu-iotests.')
|
||||
|
@ -147,7 +147,7 @@ if have_system
|
||||
# Some tests: test-char, test-qdev-global-props, and test-qga,
|
||||
# are not runnable under TSan due to a known issue.
|
||||
# https://github.com/google/sanitizers/issues/1116
|
||||
if 'CONFIG_TSAN' not in config_host
|
||||
if not get_option('tsan')
|
||||
if 'CONFIG_POSIX' in config_host
|
||||
tests += {
|
||||
'test-char': ['socket-helpers.c', qom, io, chardev]
|
||||
|
Loading…
x
Reference in New Issue
Block a user