Skip to contentSkip to conversation

configure: Disable thread-safety warnings on macOS

PATCH In review Thomas Huth 3 participants 3 messages Mar 1, 2023 – Mar 4, 2023 Arm/Amlogic Meson SoC support

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 configure: Disable thread-safety warnings on macOS

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.

---
 configure | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
configure +4 -1
index 2a8a9be8a1..9a0f8cdb4e 100755
@@ -1230,7 +1230,10 @@ 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
+
+if test "$targetos" != "darwin"; then
+    add_to warn_flags -Wthread-safety
+fi
 
 nowarn_flags=
 add_to nowarn_flags -Wno-initializer-overrides
Signature · 1 line
2.31.1
Acked-by on v1 1/1
#1 lore raw

Am 01.03.2023 um 12:34 hat Thomas Huth geschrieben:

Quoted 5 lines

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.

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.

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

configure +31 -1
index 2a8a9be8a1..970ee31889 100755
@@ -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
meson.build +1 -0
index 77d2ae87e4..a793eaacc5 100644
@@ -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')
#2 lore raw
Quoted 6 lines · Kevin Wolf

Am 01.03.2023 um 12:34 hat Thomas Huth geschrieben:

Quoted 4 lines

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.

Quoted 8 lines
Quoted 1 line

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.

I've applied this to master because it fixes the CI job, but we should probably look more closely at what's going on, because it seems plausible to me that it's something that we could hit on Linux too with either a newer or older version of clang.

thanks
-- PMM