[compiler-rt] r347336 - [tsan] Add __cxa_guard_acquire hooks to support cooperative scheduling
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 20 10:21:43 PST 2018
Author: vitalybuka
Date: Tue Nov 20 10:21:42 2018
New Revision: 347336
URL: http://llvm.org/viewvc/llvm-project?rev=347336&view=rev
Log:
[tsan] Add __cxa_guard_acquire hooks to support cooperative scheduling
Reviewers: dvyukov
Subscribers: krytarowski, kubamracek, llvm-commits
Differential Revision: https://reviews.llvm.org/D54664
Added:
compiler-rt/trunk/test/tsan/cxa_guard_acquire.cc
Modified:
compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc
Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc?rev=347336&r1=347335&r2=347336&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc Tue Nov 20 10:21:42 2018
@@ -228,6 +228,16 @@ void InitializeLibIgnore() {
libignore()->OnLibraryLoaded(0);
}
+// The following two hooks can be used by for cooperative scheduling when
+// locking.
+#ifdef TSAN_EXTERNAL_HOOKS
+void OnPotentiallyBlockingRegionBegin();
+void OnPotentiallyBlockingRegionEnd();
+#else
+SANITIZER_WEAK_CXX_DEFAULT_IMPL void OnPotentiallyBlockingRegionBegin() {}
+SANITIZER_WEAK_CXX_DEFAULT_IMPL void OnPotentiallyBlockingRegionEnd() {}
+#endif
+
} // namespace __tsan
static ThreadSignalContext *SigCtx(ThreadState *thr) {
@@ -866,6 +876,8 @@ TSAN_INTERCEPTOR(int, posix_memalign, vo
// Used in thread-safe function static initialization.
STDCXX_INTERCEPTOR(int, __cxa_guard_acquire, atomic_uint32_t *g) {
SCOPED_INTERCEPTOR_RAW(__cxa_guard_acquire, g);
+ OnPotentiallyBlockingRegionBegin();
+ auto on_exit = at_scope_exit(&OnPotentiallyBlockingRegionEnd);
for (;;) {
u32 cmp = atomic_load(g, memory_order_acquire);
if (cmp == 0) {
Added: compiler-rt/trunk/test/tsan/cxa_guard_acquire.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/cxa_guard_acquire.cc?rev=347336&view=auto
==============================================================================
--- compiler-rt/trunk/test/tsan/cxa_guard_acquire.cc (added)
+++ compiler-rt/trunk/test/tsan/cxa_guard_acquire.cc Tue Nov 20 10:21:42 2018
@@ -0,0 +1,25 @@
+// RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
+
+#include <stdio.h>
+
+namespace __tsan {
+
+void OnPotentiallyBlockingRegionBegin() {
+ printf("Enter __cxa_guard_acquire\n");
+}
+
+void OnPotentiallyBlockingRegionEnd() { printf("Exit __cxa_guard_acquire\n"); }
+
+} // namespace __tsan
+
+int main(int argc, char **argv) {
+ // CHECK: Enter main
+ printf("Enter main\n");
+ // CHECK-NEXT: Enter __cxa_guard_acquire
+ // CHECK-NEXT: Exit __cxa_guard_acquire
+ static int s = argc;
+ (void)s;
+ // CHECK-NEXT: Exit main
+ printf("Exit main\n");
+ return 0;
+}
More information about the llvm-commits
mailing list