From 3c92eb44d4cbe3f86bc35f79435864bc31f61596 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Thu, 22 Jul 2021 16:32:55 +0200 Subject: [PATCH] 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 --- compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp | 3 +++ compiler-rt/lib/tsan/tests/unit/tsan_sync_test.cpp | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp b/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp index 6636ce6..c7ba686 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 825cc09..751cd46 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 -- 2.7.4