qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] configure: Disable thread-safety warnings on macOS


From: Kevin Wolf
Subject: Re: [PATCH] configure: Disable thread-safety warnings on macOS
Date: Wed, 1 Mar 2023 14:31:45 +0100

Am 01.03.2023 um 12:34 hat Thomas Huth geschrieben:
> The enablement of -Wthread-safety broke compilation on macOS (if
> -Werror is enabled, like in our CI). Disable it there by default
> until the problems are resolved.
> 
> Signed-off-by: Thomas Huth <thuth@redhat.com>

This is simpler than what I attempted (test compiling something using
the same TSA features as the failing code), but didn't actually work.
Since I don't have access to macOS, it's hard for me to improve the
configure test. So I'm fine with just doing this instead.

Acked-by: Kevin Wolf <kwolf@redhat.com>

For reference, below my failed alternative attempt at a configure patch,
which somehow still enabled TSA on macOS and therefore still fails to
build.

Kevin


diff --git a/configure b/configure
index 2a8a9be8a1..970ee31889 100755
--- a/configure
+++ b/configure
@@ -228,6 +228,7 @@ cross_prefix=""
 host_cc="cc"
 stack_protector=""
 safe_stack=""
+tsa=""
 use_containers="yes"
 gdb_bin=$(command -v "gdb-multiarch" || command -v "gdb")

@@ -854,6 +855,10 @@ for opt do
   ;;
   --disable-safe-stack) safe_stack="no"
   ;;
+  --enable-tsa) tsa="yes"
+  ;;
+  --disable-tsa) tsa="no"
+  ;;
   --enable-cfi)
       cfi="true";
       meson_option_add -Db_lto=true
@@ -1023,6 +1028,7 @@ Advanced options (experts only):
   --with-devices-ARCH=NAME override default configs/devices
   --enable-debug           enable common debug build options
   --enable-sanitizers      enable default sanitizers
+  --enable-tsa             enable TSA (Thread Safety Analysis)
   --enable-tsan            enable thread sanitizer
   --disable-werror         disable compilation abort on warning
   --disable-stack-protector disable compiler-provided stack protection
@@ -1230,7 +1236,6 @@ add_to warn_flags -Wendif-labels
 add_to warn_flags -Wexpansion-to-defined
 add_to warn_flags -Wimplicit-fallthrough=2
 add_to warn_flags -Wmissing-format-attribute
-add_to warn_flags -Wthread-safety

 nowarn_flags=
 add_to nowarn_flags -Wno-initializer-overrides
@@ -1308,6 +1313,28 @@ EOF
   fi
 fi

+if test "$tsa" != "no"; then
+  cat > $TMPC << EOF
+typedef int __attribute__((capability("mutex"))) Lock;
+Lock lock;
+static void __attribute__((assert_capability(lock))) assert_lock(void) {}
+static void __attribute__((requires_capability(lock))) require_lock(void) {}
+int main(void)
+{
+    assert_lock();
+    require_lock();
+    return 0;
+}
+EOF
+  flag="-Wthread-safety"
+  if compile_object "-Werror $flag"; then
+    QEMU_CFLAGS="$QEMU_CFLAGS $flag"
+    tsa="yes"
+  elif test "$tsa" = yes; then
+    error_exit "Thread Safety Analysis not supported"
+  fi
+fi
+
 # Our module code doesn't support Windows
 if test "$modules" = "yes" && test "$mingw32" = "yes" ; then
   error_exit "Modules are not available for Windows"
@@ -2378,6 +2405,9 @@ if test "$have_asan_iface_fiber" = "yes" ; then
     echo "CONFIG_ASAN_IFACE_FIBER=y" >> $config_host_mak
 fi

+if test "$tsa" = "yes"; then
+    echo "CONFIG_TSA=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
diff --git a/meson.build b/meson.build
index 77d2ae87e4..a793eaacc5 100644
--- a/meson.build
+++ b/meson.build
@@ -3842,6 +3842,7 @@ else
 endif
 summary_info += {'gprof':             gprof_info}
 summary_info += {'gcov':              get_option('b_coverage')}
+summary_info += {'thread safety analysis (TSA)': 
config_host.has_key('CONFIG_TSA')}
 summary_info += {'thread sanitizer':  config_host.has_key('CONFIG_TSAN')}
 summary_info += {'CFI support':       get_option('cfi')}
 if get_option('cfi')




reply via email to

[Prev in Thread] Current Thread [Next in Thread]