[compiler-rt] [tsan]: fix Go race syso build on s390x with GCC (PR #225217)
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Sun Oct 4 17:14:40 PDT 2026
https://github.com/vitalybuka updated https://github.com/llvm/llvm-project/pull/225217
>From 9d874dc5541a13e576a2ba6ae0515839eec4730d Mon Sep 17 00:00:00 2001
From: Mauri de Souza Meneguzzo <mauri870 at gmail.com>
Date: Mon, 21 Sep 2026 19:19:45 -0300
Subject: [PATCH] [tsan]: fix Go race syso build on s390x with GCC
Native GCC on s390x defines __GCC_HAVE_SYNC_COMPARE_AND_SWAP_16, which
causes the SpinMutex func_cas overload for a128 to be skipped. The
generic template emits a __sync_val_compare_and_swap_16 libcall instead
of inlining CDSG (GCC cannot prove alignment) and that symbol
is not available without libatomic, which the Go race syso does not link.
Extend the SpinMutex condition to also cover SANITIZER_GO builds,
regardless of __GCC_HAVE_SYNC_COMPARE_AND_SWAP_16. This is safe since
all atomic accesses in Go go through the TSan trampolines.
Verified with s390x-linux-gnu-g++ (GCC 12): without the fix the syso
contains an unresolved __sync_val_compare_and_swap_16 reference; with
the fix all three __tsan_go_atomic128_* symbols are present and no
libatomic references remain.
---
compiler-rt/lib/tsan/rtl/tsan_interface_atomic.cpp | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/compiler-rt/lib/tsan/rtl/tsan_interface_atomic.cpp b/compiler-rt/lib/tsan/rtl/tsan_interface_atomic.cpp
index 6e6774eacb645f4..2c60e94d37eb618 100644
--- a/compiler-rt/lib/tsan/rtl/tsan_interface_atomic.cpp
+++ b/compiler-rt/lib/tsan/rtl/tsan_interface_atomic.cpp
@@ -112,7 +112,10 @@ T func_cas(volatile T *v, T cmp, T xch) {
// Atomic ops are executed under tsan internal mutex,
// here we assume that the atomic variables are not accessed
// from non-instrumented code.
-#if !defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_16) && __TSAN_HAS_INT128
+// For SANITIZER_GO builds we always use the mutex-based path regardless of
+// __GCC_HAVE_SYNC_COMPARE_AND_SWAP_16 to avoid a libatomic dependency.
+#if __TSAN_HAS_INT128 && \
+ (!defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_16) || SANITIZER_GO)
a128 func_xchg(volatile a128 *v, a128 op) {
SpinMutexLock lock(&mutex128);
a128 cmp = *v;
More information about the llvm-commits
mailing list