-# pkg-config probe
-
-if ! has "$pkg_config_exe"; then
- error_exit "pkg-config binary '$pkg_config_exe' not found"
-fi
-
-##########################################
-# glib support probe
-
-# When bumping glib_req_ver, please check also whether we should increase
-# the _WIN32_WINNT setting in osdep.h according to the value from glib
-glib_req_ver=2.56
-glib_modules=gthread-2.0
-if test "$modules" = yes; then
- glib_modules="$glib_modules gmodule-export-2.0"
-elif test "$plugins" = "yes"; then
- glib_modules="$glib_modules gmodule-no-export-2.0"
-fi
-
-for i in $glib_modules; do
- if $pkg_config --atleast-version=$glib_req_ver $i; then
- glib_cflags=$($pkg_config --cflags $i)
- glib_libs=$($pkg_config --libs $i)
- else
- error_exit "glib-$glib_req_ver $i is required to compile QEMU"
- fi
-done
-
-glib_bindir="$($pkg_config --variable=bindir glib-2.0)"
-if test -z "$glib_bindir" ; then
- glib_bindir="$($pkg_config --variable=prefix glib-2.0)"/bin
-fi
-
-# This workaround is required due to a bug in pkg-config file for glib as it
-# doesn't define GLIB_STATIC_COMPILATION for pkg-config --static
-
-if test "$static" = yes && test "$mingw32" = yes; then
- glib_cflags="-DGLIB_STATIC_COMPILATION $glib_cflags"
-fi
-
-# Sanity check that the current size_t matches the
-# size that glib thinks it should be. This catches
-# problems on multi-arch where people try to build
-# 32-bit QEMU while pointing at 64-bit glib headers
-cat > $TMPC <<EOF
-#include <glib.h>
-#include <unistd.h>
-
-#define QEMU_BUILD_BUG_ON(x) \
- typedef char qemu_build_bug_on[(x)?-1:1] __attribute__((unused));
-
-int main(void) {
- QEMU_BUILD_BUG_ON(sizeof(size_t) != GLIB_SIZEOF_SIZE_T);
- return 0;
-}
-EOF
-
-if ! compile_prog "$glib_cflags" "$glib_libs" ; then
- error_exit "sizeof(size_t) doesn't match GLIB_SIZEOF_SIZE_T."\
- "You probably need to set PKG_CONFIG_LIBDIR"\
- "to point to the right pkg-config files for your"\
- "build target"
-fi
-
-# Silence clang warnings triggered by glib < 2.57.2
-cat > $TMPC << EOF
-#include <glib.h>
-typedef struct Foo {
- int i;
-} Foo;
-static void foo_free(Foo *f)
-{
- g_free(f);
-}
-G_DEFINE_AUTOPTR_CLEANUP_FUNC(Foo, foo_free)
-int main(void) { return 0; }
-EOF
-if ! compile_prog "$glib_cflags -Werror" "$glib_libs" ; then
- if cc_has_warning_flag "-Wno-unused-function"; then
- glib_cflags="$glib_cflags -Wno-unused-function"
- CONFIGURE_CFLAGS="$CONFIGURE_CFLAGS -Wno-unused-function"
- fi
-fi
-
-##########################################
-# fdt probe
-
-case "$fdt" in
- auto | enabled | internal)
- # Simpler to always update submodule, even if not needed.
- git_submodules="${git_submodules} dtc"
- ;;
-esac
-
-##########################################
-# check and set a backend for coroutine
-
-# We prefer ucontext, but it's not always possible. The fallback
-# is sigcontext. On Windows the only valid backend is the Windows
-# specific one.
-
-ucontext_works=no
-if test "$darwin" != "yes"; then
- cat > $TMPC << EOF
-#include <ucontext.h>
-#ifdef __stub_makecontext
-#error Ignoring glibc stub makecontext which will always fail
-#endif
-int main(void) { makecontext(0, 0, 0); return 0; }
-EOF
- if compile_prog "" "" ; then
- ucontext_works=yes
- fi
-fi
-
-if test "$coroutine" = ""; then
- if test "$mingw32" = "yes"; then
- coroutine=win32
- elif test "$ucontext_works" = "yes"; then
- coroutine=ucontext
- else
- coroutine=sigaltstack
- fi
-else
- case $coroutine in
- windows)
- if test "$mingw32" != "yes"; then
- error_exit "'windows' coroutine backend only valid for Windows"
- fi
- # Unfortunately the user visible backend name doesn't match the
- # coroutine-*.c filename for this case, so we have to adjust it here.
- coroutine=win32
- ;;
- ucontext)
- if test "$ucontext_works" != "yes"; then
- error_exit "'ucontext' backend requested but makecontext not available"
- fi
- ;;
- sigaltstack)
- if test "$mingw32" = "yes"; then
- error_exit "only the 'windows' coroutine backend is valid for Windows"
- fi
- ;;
- *)
- error_exit "unknown coroutine backend $coroutine"
- ;;
- esac
-fi
-
-##################################################
-# SafeStack
-
-
-if test "$safe_stack" = "yes"; then
-cat > $TMPC << EOF
-int main(void)
-{
-#if ! __has_feature(safe_stack)
-#error SafeStack Disabled
-#endif
- return 0;
-}
-EOF
- flag="-fsanitize=safe-stack"
- # Check that safe-stack is supported and enabled.
- if compile_prog "-Werror $flag" "$flag"; then
- # Flag needed both at compilation and at linking
- QEMU_CFLAGS="$QEMU_CFLAGS $flag"
- QEMU_LDFLAGS="$QEMU_LDFLAGS $flag"
- else
- error_exit "SafeStack not supported by your compiler"
- fi
- if test "$coroutine" != "ucontext"; then
- error_exit "SafeStack is only supported by the coroutine backend ucontext"
- fi
-else
-cat > $TMPC << EOF
-int main(void)
-{
-#if defined(__has_feature)
-#if __has_feature(safe_stack)
-#error SafeStack Enabled
-#endif
-#endif
- return 0;
-}
-EOF
-if test "$safe_stack" = "no"; then
- # Make sure that safe-stack is disabled
- if ! compile_prog "-Werror" ""; then
- # SafeStack was already enabled, try to explicitly remove the feature
- flag="-fno-sanitize=safe-stack"
- if ! compile_prog "-Werror $flag" "$flag"; then
- error_exit "Configure cannot disable SafeStack"
- fi
- QEMU_CFLAGS="$QEMU_CFLAGS $flag"
- QEMU_LDFLAGS="$QEMU_LDFLAGS $flag"
- fi
-else # "$safe_stack" = ""
- # Set safe_stack to yes or no based on pre-existing flags
- if compile_prog "-Werror" ""; then
- safe_stack="no"
- else
- safe_stack="yes"
- if test "$coroutine" != "ucontext"; then
- error_exit "SafeStack is only supported by the coroutine backend ucontext"
- fi
- fi
-fi
-fi
-
-########################################
-# check if ccache is interfering with
-# semantic analysis of macros
-
-unset CCACHE_CPP2
-ccache_cpp2=no
-cat > $TMPC << EOF
-static const int Z = 1;
-#define fn() ({ Z; })
-#define TAUT(X) ((X) == Z)
-#define PAREN(X, Y) (X == Y)
-#define ID(X) (X)
-int main(void)
-{
- int x = 0, y = 0;
- x = ID(x);
- x = fn();
- fn();
- if (PAREN(x, y)) return 0;
- if (TAUT(Z)) return 0;
- return 0;
-}
-EOF
-
-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
-#include <stdlib.h>
-int main(void) {
- void *tmp = malloc(10);
- if (tmp != NULL) {
- return *(int *)(tmp + 2);
- }
- return 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
-
-##########################################