[compiler-rt] 6430707 - Revert "tsan: fix leak of ThreadSignalContext for fibers"
Jonas Devlieghere via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 25 19:34:59 PDT 2020
Author: Jonas Devlieghere
Date: 2020-03-25T19:18:38-07:00
New Revision: 6430707196b96639cd1997df676b1c8e7c5c5d2e
URL: https://github.com/llvm/llvm-project/commit/6430707196b96639cd1997df676b1c8e7c5c5d2e
DIFF: https://github.com/llvm/llvm-project/commit/6430707196b96639cd1997df676b1c8e7c5c5d2e.diff
LOG: Revert "tsan: fix leak of ThreadSignalContext for fibers"
Temporarily revert "tsan: fix leak of ThreadSignalContext for fibers"
because it breaks the LLDB bot on GreenDragon.
This reverts commit 93f7743851b7a01a8c8f54b3753b6e5cd5591e15.
This reverts commit d8a0f76de7bd98dc7a271bc15b39a4cdbfdf6ecb.
Added:
Modified:
compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp
compiler-rt/lib/tsan/rtl/tsan_platform.h
compiler-rt/lib/tsan/rtl/tsan_platform_linux.cpp
compiler-rt/lib/tsan/rtl/tsan_platform_mac.cpp
compiler-rt/lib/tsan/rtl/tsan_rtl_thread.cpp
Removed:
compiler-rt/test/tsan/fiber_cleanup.cpp
################################################################################
diff --git a/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp b/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp
index ad5db792182d..a623f4fe589d 100644
--- a/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp
+++ b/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp
@@ -885,21 +885,19 @@ STDCXX_INTERCEPTOR(void, __cxa_guard_abort, atomic_uint32_t *g) {
}
namespace __tsan {
-void PlatformThreadFinished(ThreadState *thr) {
+void DestroyThreadState() {
+ ThreadState *thr = cur_thread();
+ Processor *proc = thr->proc();
+ ThreadFinish(thr);
+ ProcUnwire(proc, thr);
+ ProcDestroy(proc);
ThreadSignalContext *sctx = thr->signal_ctx;
if (sctx) {
- thr->signal_ctx = nullptr;
+ thr->signal_ctx = 0;
UnmapOrDie(sctx, sizeof(*sctx));
}
-
- if (thr->tctx->thread_type != ThreadType::Fiber) {
- CHECK_EQ(thr, cur_thread());
- Processor *proc = thr->proc();
- ProcUnwire(proc, thr);
- ProcDestroy(proc);
- DTLS_Destroy();
- cur_thread_finalize();
- }
+ DTLS_Destroy();
+ cur_thread_finalize();
}
} // namespace __tsan
@@ -914,7 +912,7 @@ static void thread_finalize(void *v) {
}
return;
}
- ThreadFinish(cur_thread());
+ DestroyThreadState();
}
#endif
@@ -2553,7 +2551,7 @@ TSAN_INTERCEPTOR(void *, __tls_get_addr, void *arg) {
#if SANITIZER_NETBSD
TSAN_INTERCEPTOR(void, _lwp_exit) {
SCOPED_TSAN_INTERCEPTOR(_lwp_exit);
- ThreadFinish(cur_thread());
+ DestroyThreadState();
REAL(_lwp_exit)();
}
#define TSAN_MAYBE_INTERCEPT__LWP_EXIT TSAN_INTERCEPT(_lwp_exit)
@@ -2564,7 +2562,7 @@ TSAN_INTERCEPTOR(void, _lwp_exit) {
#if SANITIZER_FREEBSD
TSAN_INTERCEPTOR(void, thr_exit, tid_t *state) {
SCOPED_TSAN_INTERCEPTOR(thr_exit, state);
- ThreadFinish(cur_thread());
+ DestroyThreadState();
REAL(thr_exit(state));
}
#define TSAN_MAYBE_INTERCEPT_THR_EXIT TSAN_INTERCEPT(thr_exit)
diff --git a/compiler-rt/lib/tsan/rtl/tsan_platform.h b/compiler-rt/lib/tsan/rtl/tsan_platform.h
index 66c2ab37aff5..63eb14fcd340 100644
--- a/compiler-rt/lib/tsan/rtl/tsan_platform.h
+++ b/compiler-rt/lib/tsan/rtl/tsan_platform.h
@@ -1020,7 +1020,7 @@ int call_pthread_cancel_with_cleanup(int(*fn)(void *c, void *m,
void *abstime), void *c, void *m, void *abstime,
void(*cleanup)(void *arg), void *arg);
-void PlatformThreadFinished(ThreadState *thr);
+void DestroyThreadState();
} // namespace __tsan
diff --git a/compiler-rt/lib/tsan/rtl/tsan_platform_linux.cpp b/compiler-rt/lib/tsan/rtl/tsan_platform_linux.cpp
index 84f5619c37bc..33fa586ca1b0 100644
--- a/compiler-rt/lib/tsan/rtl/tsan_platform_linux.cpp
+++ b/compiler-rt/lib/tsan/rtl/tsan_platform_linux.cpp
@@ -460,7 +460,7 @@ void ReplaceSystemMalloc() { }
#if !SANITIZER_GO
#if SANITIZER_ANDROID
// On Android, one thread can call intercepted functions after
-// ThreadFinish(), so add a fake thread state for "dead" threads.
+// DestroyThreadState(), so add a fake thread state for "dead" threads.
static ThreadState *dead_thread_state = nullptr;
ThreadState *cur_thread() {
diff --git a/compiler-rt/lib/tsan/rtl/tsan_platform_mac.cpp b/compiler-rt/lib/tsan/rtl/tsan_platform_mac.cpp
index 7d4bbe3dc73b..fdda7013fe5c 100644
--- a/compiler-rt/lib/tsan/rtl/tsan_platform_mac.cpp
+++ b/compiler-rt/lib/tsan/rtl/tsan_platform_mac.cpp
@@ -226,7 +226,7 @@ static void my_pthread_introspection_hook(unsigned int event, pthread_t thread,
if (thread == pthread_self()) {
ThreadState *thr = cur_thread();
if (thr->tctx) {
- ThreadFinish(thr);
+ DestroyThreadState();
}
}
}
diff --git a/compiler-rt/lib/tsan/rtl/tsan_rtl_thread.cpp b/compiler-rt/lib/tsan/rtl/tsan_rtl_thread.cpp
index 107eabd8d830..98beb5aad644 100644
--- a/compiler-rt/lib/tsan/rtl/tsan_rtl_thread.cpp
+++ b/compiler-rt/lib/tsan/rtl/tsan_rtl_thread.cpp
@@ -144,7 +144,6 @@ void ThreadContext::OnFinished() {
thr->clock.ResetCached(&thr->proc()->clock_cache);
#if !SANITIZER_GO
thr->last_sleep_clock.ResetCached(&thr->proc()->clock_cache);
- PlatformThreadFinished(thr);
#endif
thr->~ThreadState();
#if TSAN_COLLECT_STATS
diff --git a/compiler-rt/test/tsan/fiber_cleanup.cpp b/compiler-rt/test/tsan/fiber_cleanup.cpp
deleted file mode 100644
index 55503682f28a..000000000000
--- a/compiler-rt/test/tsan/fiber_cleanup.cpp
+++ /dev/null
@@ -1,88 +0,0 @@
-// RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
-// REQUIRES: linux
-#include "test.h"
-
-//#include <fstream>
-//#include <sstream>
-//#include <string>
-
-#include <pthread.h>
-#include <sys/types.h>
-#include <unistd.h>
-
-//long count_memory_mappings() {
-// pid_t my_pid = getpid();
-// std::ifstream proc_file{"/proc/" + std::to_string(my_pid) + "/maps"};
-//
-// std::string line;
-// long line_count{0};
-// while (std::getline(proc_file, line)) {
-// line_count++;
-// }
-//
-// return line_count;
-//}
-
-long count_memory_mappings() {
- pid_t my_pid = getpid();
- char proc_file_name[128];
- snprintf(proc_file_name, sizeof(proc_file_name), "/proc/%ld/maps", my_pid);
-
- FILE *proc_file = fopen(proc_file_name, "r");
- long line_count = 0;
- char c;
- do {
- c = fgetc(proc_file);
- if (c == '\n') {
- line_count++;
- }
- } while (c != EOF);
- fclose(proc_file);
-
- return line_count;
-}
-
-void fiber_iteration() {
- void *orig_fiber = __tsan_get_current_fiber();
- void *fiber = __tsan_create_fiber(0);
-
- pthread_mutex_t mutex;
- pthread_mutex_init(&mutex, NULL);
-
- // Running some code on the fiber that triggers handling of pending signals.
- __tsan_switch_to_fiber(fiber, 0);
- pthread_mutex_lock(&mutex);
- pthread_mutex_unlock(&mutex);
- __tsan_switch_to_fiber(orig_fiber, 0);
-
- // We expect the fiber to clean up all resources (here the sigcontext) when destroyed.
- __tsan_destroy_fiber(fiber);
-}
-
-// Magic-Number for some warmup iterations,
-// as tsan maps some memory for the first runs.
-const size_t num_warmup = 100;
-
-int main() {
- for (size_t i = 0; i < num_warmup; i++) {
- fiber_iteration();
- }
-
- long memory_mappings_before = count_memory_mappings();
- fiber_iteration();
- fiber_iteration();
- long memory_mappings_after = count_memory_mappings();
-
- // Is there a better way to detect a resource leak in the
- // ThreadState object? (i.e. a mmap not being freed)
- if (memory_mappings_before == memory_mappings_after) {
- fprintf(stderr, "PASS\n");
- } else {
- fprintf(stderr, "FAILED\n");
- }
-
- return 0;
-}
-
-// CHECK-NOT: WARNING: ThreadSanitizer:
-// CHECK: PASS
More information about the llvm-commits
mailing list