[llvm-branch-commits] [compiler-rt] c8bb66d - [tsan] Fix buildgo.sh on FreeBSD/NetBSD (#213047)

Tobias Hieta via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Jul 30 23:58:46 PDT 2026


Author: Rainer Orth
Date: 2026-07-31T08:58:38+02:00
New Revision: c8bb66dd4f48747f67a5e25df946ef5db30b185e

URL: https://github.com/llvm/llvm-project/commit/c8bb66dd4f48747f67a5e25df946ef5db30b185e
DIFF: https://github.com/llvm/llvm-project/commit/c8bb66dd4f48747f67a5e25df946ef5db30b185e.diff

LOG: [tsan] Fix buildgo.sh on FreeBSD/NetBSD (#213047)

This patch fixes the remaining compile errors when running `ninja
check-all` on FreeBSD and NetBSD:

- `sanitizer_linux.cpp` doesn't compile on NetBSD, so this patch adds a
cast:
  ```
sanitizer_common/sanitizer_linux.cpp:2492:10: error: format specifies
type 'unsigned long long' but the argument has type '__greg_t' (aka
'unsigned long') [-Werror,-Wformat]
   ```

- `tsan_interface_atomic.cpp` doesn't compile on both FreeBSD and
NetBSD, so this patch disables the warning:
  ```
tsan_interface_atomic.cpp:353:12: error: unused function template
'NoTsanAtomic' [-Werror,-Wunused-template]
tsan_interface_atomic.cpp:358:12: error: unused function template
'Atomic' [-Werror,-Wunused-template]
tsan_interface_atomic.cpp:389:12: error: unused function template
'NoTsanAtomic' [-Werror,-Wunused-template]
tsan_interface_atomic.cpp:394:12: error: unused function template
'Atomic' [-Werror,-Wunused-template]
tsan_interface_atomic.cpp:401:12: error: unused function template
'NoTsanAtomic' [-Werror,-Wunused-template]
tsan_interface_atomic.cpp:406:12: error: unused function template
'Atomic' [-Werror,-Wunused-template]
  ```

- `sanitizer_linux_libcdep.cpp` doesn't compile on NetBSD:
  ```
sanitizer_linux_libcdep.cpp:527:27: error: use of undeclared identifier
'__lwp_getprivate_fast'; did you mean '_lwp_getprivate'?
  ```
This is the same issue already handled in `tsan_platform_linux.cpp`: to
expose the `__lwp_getprivate_fast` definition in `<machine/mcontext.h>`,
`_RTLD_SOURCE` needs to be defined before `<machine/mcontext.h>` is
included (indirectly from `<signal.h>` in this case). It also needs to
include `<sys/types.h>` to get a definition of the `__aligned` macro.

Tested on `amd64-pc-freebsd15.1` and `amd64-pc-netbsd10.1`.

(cherry picked from commit 6e92d6d0577cbe102bd48f396301ea5cd0ebf247)

Added: 
    

Modified: 
    compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
    compiler-rt/lib/tsan/go/buildgo.sh
    compiler-rt/lib/tsan/rtl/tsan_platform_linux.cpp

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
index 6f0259f31dbf5..b4047bdd84c20 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
@@ -2489,7 +2489,7 @@ static void DumpSingleReg(ucontext_t *ctx, int RegNum) {
 #      if SANITIZER_LINUX
          ctx->uc_mcontext.gregs[RegNum]
 #      elif SANITIZER_NETBSD
-         ctx->uc_mcontext.__gregs[RegNum]
+         (unsigned long long)ctx->uc_mcontext.__gregs[RegNum]
 #      endif
   );
 #    elif defined(__i386__)

diff  --git a/compiler-rt/lib/tsan/go/buildgo.sh b/compiler-rt/lib/tsan/go/buildgo.sh
index 1340071819fcb..edfd55075e1e0 100755
--- a/compiler-rt/lib/tsan/go/buildgo.sh
+++ b/compiler-rt/lib/tsan/go/buildgo.sh
@@ -127,7 +127,7 @@ elif [ "$GOOS" = "freebsd" ]; then
 	# We removed this dependency for Go runtime for other OSes,
 	# and we should remove it for FreeBSD as well, but there is no pressing need.
 	DEPENDS_ON_LIBC=1
-	OSCFLAGS="-fno-strict-aliasing -fPIC -Werror"
+	OSCFLAGS="-fno-strict-aliasing -fPIC -Werror -Wno-unused-template"
 	ARCHCFLAGS="-m64"
 	OSLDFLAGS="-lpthread -fPIC -fpie"
 	SRCS="
@@ -147,7 +147,7 @@ elif [ "$GOOS" = "netbsd" ]; then
 	# We removed this dependency for Go runtime for other OSes,
 	# and we should remove it for NetBSD as well, but there is no pressing need.
 	DEPENDS_ON_LIBC=1
-	OSCFLAGS="-fno-strict-aliasing -fPIC -Werror"
+	OSCFLAGS="-fno-strict-aliasing -fPIC -Werror -Wno-unused-template"
 	ARCHCFLAGS="-m64"
 	OSLDFLAGS="-lpthread -fPIC -fpie"
 	SRCS="

diff  --git a/compiler-rt/lib/tsan/rtl/tsan_platform_linux.cpp b/compiler-rt/lib/tsan/rtl/tsan_platform_linux.cpp
index c974f549acbcb..b0296a0756f3b 100644
--- a/compiler-rt/lib/tsan/rtl/tsan_platform_linux.cpp
+++ b/compiler-rt/lib/tsan/rtl/tsan_platform_linux.cpp
@@ -27,6 +27,18 @@
 #include "tsan_platform.h"
 #include "tsan_rtl.h"
 
+#if SANITIZER_NETBSD
+#  // for __lwp_gettcb_fast() / __lwp_getprivate_fast()
+#  define _RTLD_SOURCE
+#  include <sys/types.h>
+#  include <machine/mcontext.h>
+#  undef _RTLD_SOURCE
+#  include <sys/param.h>
+#  if __NetBSD_Version__ >= 1099001200
+#    include <machine/lwp_private.h>
+#  endif
+#endif
+
 #include <fcntl.h>
 #include <pthread.h>
 #include <signal.h>


        


More information about the llvm-branch-commits mailing list