tsan: add OpenBSD support for Go
authorDmitry Vyukov <dvyukov@google.com>
Mon, 8 Jun 2020 14:45:39 +0000 (16:45 +0200)
committerDmitry Vyukov <dvyukov@google.com>
Mon, 8 Jun 2020 14:47:13 +0000 (16:47 +0200)
With the race_debug_openbsd_amd64.syso file created via this diff,
Go's race detector is able to detect a race in the example code
link: https://golang.org/doc/articles/race_detector.html
Reviewed-in: https://reviews.llvm.org/D80469
Author: qbit (Aaron Bieber)

compiler-rt/lib/tsan/go/buildgo.sh
compiler-rt/lib/tsan/rtl/tsan_platform_linux.cpp

index 9e21b77..2238caf 100755 (executable)
@@ -108,6 +108,27 @@ elif [ "`uname -a | grep NetBSD`" != "" ]; then
                ../../sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cpp
                ../../sanitizer_common/sanitizer_stoptheworld_netbsd_libcdep.cpp
        "
+elif [ "`uname -a | grep OpenBSD`" != "" ]; then
+       # The resulting object still depends on libc.
+       # We removed this dependency for Go runtime for other OSes,
+       # and we should remove it for OpenBSD as well, but there is no pressing need.
+       DEPENDS_ON_LIBC=1
+       SUFFIX="openbsd_amd64"
+       OSCFLAGS="-fno-strict-aliasing -fPIC -Werror"
+       ARCHCFLAGS="-m64"
+       OSLDFLAGS="-pthread -fPIC -fpie"
+       SRCS="
+               $SRCS
+               ../rtl/tsan_platform_linux.cpp
+               ../../sanitizer_common/sanitizer_posix.cpp
+               ../../sanitizer_common/sanitizer_posix_libcdep.cpp
+               ../../sanitizer_common/sanitizer_procmaps_bsd.cpp
+               ../../sanitizer_common/sanitizer_procmaps_common.cpp
+               ../../sanitizer_common/sanitizer_linux.cpp
+               ../../sanitizer_common/sanitizer_linux_libcdep.cpp
+               ../../sanitizer_common/sanitizer_openbsd.cpp
+               ../../sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cpp
+       "
 elif [ "`uname -a | grep Darwin`" != "" ]; then
        SUFFIX="darwin_amd64"
        OSCFLAGS="-fPIC -Wno-unused-const-variable -Wno-unknown-warning-option -mmacosx-version-min=10.7"
index 33fa586..645152a 100644 (file)
@@ -8,25 +8,26 @@
 //
 // This file is a part of ThreadSanitizer (TSan), a race detector.
 //
-// Linux- and FreeBSD-specific code.
+// Linux- and BSD-specific code.
 //===----------------------------------------------------------------------===//
 
-
 #include "sanitizer_common/sanitizer_platform.h"
-#if SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD
+#if SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD || \
+    SANITIZER_OPENBSD
 
 #include "sanitizer_common/sanitizer_common.h"
 #include "sanitizer_common/sanitizer_libc.h"
 #include "sanitizer_common/sanitizer_linux.h"
 #include "sanitizer_common/sanitizer_platform_limits_netbsd.h"
+#include "sanitizer_common/sanitizer_platform_limits_openbsd.h"
 #include "sanitizer_common/sanitizer_platform_limits_posix.h"
 #include "sanitizer_common/sanitizer_posix.h"
 #include "sanitizer_common/sanitizer_procmaps.h"
-#include "sanitizer_common/sanitizer_stoptheworld.h"
 #include "sanitizer_common/sanitizer_stackdepot.h"
+#include "sanitizer_common/sanitizer_stoptheworld.h"
+#include "tsan_flags.h"
 #include "tsan_platform.h"
 #include "tsan_rtl.h"
-#include "tsan_flags.h"
 
 #include <fcntl.h>
 #include <pthread.h>
@@ -512,4 +513,5 @@ void cur_thread_finalize() {
 
 }  // namespace __tsan
 
-#endif  // SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD
+#endif  // SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD ||
+        // SANITIZER_OPENBSD