[compiler-rt] 3c92eb4 - tsan: ignore interceptors in few more places

Dmitry Vyukov via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 23 00:12:50 PDT 2021


Author: Dmitry Vyukov
Date: 2021-07-23T09:12:46+02:00
New Revision: 3c92eb44d4cbe3f86bc35f79435864bc31f61596

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

LOG: tsan: ignore interceptors in few more places

This is preparation to switching to the sanitizer_common Mutex.
Without this change after the switch we will start failing
on existing from the runtime with runtime mutexes held.
Previously it worked because CheckNoLocks did not see sanitizer_common mutexes.

Depends on D106547.

Reviewed By: vitalybuka, melver

Differential Revision: https://reviews.llvm.org/D106558

Added: 
    

Modified: 
    compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp
    compiler-rt/lib/tsan/tests/unit/tsan_sync_test.cpp

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp b/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp
index 6636ce6383d71..c7ba686e7c83d 100644
--- a/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp
+++ b/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp
@@ -434,6 +434,9 @@ static int setup_at_exit_wrapper(ThreadState *thr, uptr pc, void(*f)(),
 
     // Ensure thread-safety.
     BlockingMutexLock l(&interceptor_ctx()->atexit_mu);
+    // __cxa_atexit calls calloc. If we don't ignore interceptors, we will fail
+    // due to atexit_mu held on exit from the calloc interceptor.
+    ScopedIgnoreInterceptors ignore;
 
     res = REAL(__cxa_atexit)((void (*)(void *a))at_exit_wrapper, 0, 0);
     // Push AtExitCtx on the top of the stack of callback functions

diff  --git a/compiler-rt/lib/tsan/tests/unit/tsan_sync_test.cpp b/compiler-rt/lib/tsan/tests/unit/tsan_sync_test.cpp
index 825cc0943e87f..751cd46f129b7 100644
--- a/compiler-rt/lib/tsan/tests/unit/tsan_sync_test.cpp
+++ b/compiler-rt/lib/tsan/tests/unit/tsan_sync_test.cpp
@@ -48,6 +48,9 @@ TEST(MetaMap, FreeRange) {
 }
 
 TEST(MetaMap, Sync) {
+  // EXPECT can call memset/etc. Disable interceptors to prevent
+  // them from detecting that we exit runtime with mutexes held.
+  ScopedIgnoreInterceptors ignore;
   ThreadState *thr = cur_thread();
   MetaMap *m = &ctx->metamap;
   u64 block[4] = {};  // fake malloc block
@@ -71,6 +74,7 @@ TEST(MetaMap, Sync) {
 }
 
 TEST(MetaMap, MoveMemory) {
+  ScopedIgnoreInterceptors ignore;
   ThreadState *thr = cur_thread();
   MetaMap *m = &ctx->metamap;
   u64 block1[4] = {};  // fake malloc block
@@ -108,6 +112,7 @@ TEST(MetaMap, MoveMemory) {
 }
 
 TEST(MetaMap, ResetSync) {
+  ScopedIgnoreInterceptors ignore;
   ThreadState *thr = cur_thread();
   MetaMap *m = &ctx->metamap;
   u64 block[1] = {};  // fake malloc block


        


More information about the llvm-commits mailing list