Support: Clean up TSan annotations.
authorPeter Collingbourne <peter@pcc.me.uk>
Tue, 18 Aug 2015 22:31:24 +0000 (22:31 +0000)
committerPeter Collingbourne <peter@pcc.me.uk>
Tue, 18 Aug 2015 22:31:24 +0000 (22:31 +0000)
Remove support for Valgrind-based TSan, which hasn't been maintained for a
few years. We now use the TSan annotations only if LLVM is compiled with
-fsanitize=thread. We no longer need the weak function definitions as we
are guaranteed that our program is linked directly with the TSan runtime.

Differential Revision: http://reviews.llvm.org/D12121

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@245374 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/PassSupport.h
include/llvm/Support/Compiler.h
include/llvm/Support/ManagedStatic.h
include/llvm/Support/Valgrind.h
lib/Support/ManagedStatic.cpp
lib/Support/Statistic.cpp
lib/Support/Valgrind.cpp

index 6cb6516412e8c750f4a83910b961d60f96077938..7c3d49f02e8fb1f6a0d0f8870e536c4213702161 100644 (file)
@@ -26,7 +26,7 @@
 #include "llvm/PassInfo.h"
 #include "llvm/PassRegistry.h"
 #include "llvm/Support/Atomic.h"
-#include "llvm/Support/Valgrind.h"
+#include "llvm/Support/Compiler.h"
 #include <vector>
 
 namespace llvm {
index 1c0ef75f5298b84383a289a682a21e36aeb60059..9f98bc398fec0b195bc7ca8753740ee26b4f88df 100644 (file)
 # define LLVM_ADDRESS_SANITIZER_BUILD 0
 #endif
 
+/// \macro LLVM_THREAD_SANITIZER_BUILD
+/// \brief Whether LLVM itself is built with ThreadSanitizer instrumentation.
+#if __has_feature(thread_sanitizer) || defined(__SANITIZE_THREAD__)
+# define LLVM_THREAD_SANITIZER_BUILD 1
+#else
+# define LLVM_THREAD_SANITIZER_BUILD 0
+#endif
+
+#if LLVM_THREAD_SANITIZER_BUILD
+// Thread Sanitizer is a tool that finds races in code.
+// See http://code.google.com/p/data-race-test/wiki/DynamicAnnotations .
+// tsan detects these exact functions by name.
+extern "C" {
+void AnnotateHappensAfter(const char *file, int line, const volatile void *cv);
+void AnnotateHappensBefore(const char *file, int line, const volatile void *cv);
+void AnnotateIgnoreWritesBegin(const char *file, int line);
+void AnnotateIgnoreWritesEnd(const char *file, int line);
+}
+
+// This marker is used to define a happens-before arc. The race detector will
+// infer an arc from the begin to the end when they share the same pointer
+// argument.
+# define TsanHappensBefore(cv) AnnotateHappensBefore(__FILE__, __LINE__, cv)
+
+// This marker defines the destination of a happens-before arc.
+# define TsanHappensAfter(cv) AnnotateHappensAfter(__FILE__, __LINE__, cv)
+
+// Ignore any races on writes between here and the next TsanIgnoreWritesEnd.
+# define TsanIgnoreWritesBegin() AnnotateIgnoreWritesBegin(__FILE__, __LINE__)
+
+// Resume checking for racy writes.
+# define TsanIgnoreWritesEnd() AnnotateIgnoreWritesEnd(__FILE__, __LINE__)
+#else
+# define TsanHappensBefore(cv)
+# define TsanHappensAfter(cv)
+# define TsanIgnoreWritesBegin()
+# define TsanIgnoreWritesEnd()
+#endif
+
 /// \brief Mark debug helper function definitions like dump() that should not be
 /// stripped from debug builds.
 // FIXME: Move this to a private config.h as it's not usable in public headers.
index addd34e704bc7a4b8b1a5674951825b9d385bc25..2e131e47177d3c54ad68c0cabccc636b882c840a 100644 (file)
@@ -15,8 +15,8 @@
 #define LLVM_SUPPORT_MANAGEDSTATIC_H
 
 #include "llvm/Support/Atomic.h"
+#include "llvm/Support/Compiler.h"
 #include "llvm/Support/Threading.h"
-#include "llvm/Support/Valgrind.h"
 
 namespace llvm {
 
index cebf75c49c1966ab5b0013e6d2475e43753c7414..12b0dc961daae37d0e43f24df977c3de9b7cb016 100644 (file)
 #include "llvm/Support/Compiler.h"
 #include <stddef.h>
 
-#if LLVM_ENABLE_THREADS != 0 && !defined(NDEBUG)
-// tsan (Thread Sanitizer) is a valgrind-based tool that detects these exact
-// functions by name.
-extern "C" {
-void AnnotateHappensAfter(const char *file, int line, const volatile void *cv);
-void AnnotateHappensBefore(const char *file, int line, const volatile void *cv);
-void AnnotateIgnoreWritesBegin(const char *file, int line);
-void AnnotateIgnoreWritesEnd(const char *file, int line);
-}
-#endif
-
 namespace llvm {
 namespace sys {
   // True if Valgrind is controlling this process.
@@ -39,34 +28,6 @@ namespace sys {
   // Discard valgrind's translation of code in the range [Addr .. Addr + Len).
   // Otherwise valgrind may continue to execute the old version of the code.
   void ValgrindDiscardTranslations(const void *Addr, size_t Len);
-
-#if LLVM_ENABLE_THREADS != 0 && !defined(NDEBUG)
-  // Thread Sanitizer is a valgrind tool that finds races in code.
-  // See http://code.google.com/p/data-race-test/wiki/DynamicAnnotations .
-
-  // This marker is used to define a happens-before arc. The race detector will
-  // infer an arc from the begin to the end when they share the same pointer
-  // argument.
-  #define TsanHappensBefore(cv) \
-    AnnotateHappensBefore(__FILE__, __LINE__, cv)
-
-  // This marker defines the destination of a happens-before arc.
-  #define TsanHappensAfter(cv) \
-    AnnotateHappensAfter(__FILE__, __LINE__, cv)
-
-  // Ignore any races on writes between here and the next TsanIgnoreWritesEnd.
-  #define TsanIgnoreWritesBegin() \
-    AnnotateIgnoreWritesBegin(__FILE__, __LINE__)
-
-  // Resume checking for racy writes.
-  #define TsanIgnoreWritesEnd() \
-    AnnotateIgnoreWritesEnd(__FILE__, __LINE__)
-#else
-  #define TsanHappensBefore(cv)
-  #define TsanHappensAfter(cv)
-  #define TsanIgnoreWritesBegin()
-  #define TsanIgnoreWritesEnd()
-#endif
 }
 }
 
index b8fb2841e5256fdf5b08573b8b4368aecfba490f..9868207b14ff2733ba7c8ea75b81ec6a98b7abe4 100644 (file)
@@ -14,6 +14,7 @@
 #include "llvm/Support/ManagedStatic.h"
 #include "llvm/Config/config.h"
 #include "llvm/Support/Atomic.h"
+#include "llvm/Support/Compiler.h"
 #include "llvm/Support/Mutex.h"
 #include "llvm/Support/MutexGuard.h"
 #include <cassert>
index 56c3b0f5659fa716e7c43cc567b9ac4d5f4bdc7d..ee6c1305cdbe526473b0946c23168b6a6152b67a 100644 (file)
@@ -24,6 +24,7 @@
 #include "llvm/ADT/Statistic.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/Support/CommandLine.h"
+#include "llvm/Support/Compiler.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/Format.h"
 #include "llvm/Support/ManagedStatic.h"
index facf8d927ecd9a453f18ebff2bf13f8203e8cfbc..703448524ed9628afb9b280cefa95a6deda5cf38 100644 (file)
@@ -52,23 +52,3 @@ void llvm::sys::ValgrindDiscardTranslations(const void *Addr, size_t Len) {
 }
 
 #endif  // !HAVE_VALGRIND_VALGRIND_H
-
-// These functions require no implementation, tsan just looks at the arguments
-// they're called with. However, they are required to be weak as some other
-// application or library may already be providing these definitions for the
-// same reason we are.
-extern "C" {
-LLVM_ATTRIBUTE_WEAK void AnnotateHappensAfter(const char *file, int line,
-                                              const volatile void *cv);
-void AnnotateHappensAfter(const char *file, int line, const volatile void *cv) {
-}
-LLVM_ATTRIBUTE_WEAK void AnnotateHappensBefore(const char *file, int line,
-                                               const volatile void *cv);
-void AnnotateHappensBefore(const char *file, int line,
-                           const volatile void *cv) {}
-LLVM_ATTRIBUTE_WEAK void AnnotateIgnoreWritesBegin(const char *file, int line);
-void AnnotateIgnoreWritesBegin(const char *file, int line) {}
-LLVM_ATTRIBUTE_WEAK void AnnotateIgnoreWritesEnd(const char *file, int line);
-void AnnotateIgnoreWritesEnd(const char *file, int line) {}
-}
-