summaryrefslogtreecommitdiff
path: root/lib/lsan
diff options
context:
space:
mode:
authorDavid Carlier <devnexen@gmail.com>2018-06-20 20:13:25 +0000
committerDavid Carlier <devnexen@gmail.com>2018-06-20 20:13:25 +0000
commit8753f67b54c2fbc6e948d3ced43d16b130fd9104 (patch)
tree39c5dcbd949854e930721363649c1a9e950846e1 /lib/lsan
parentbac6a16525fe4aae2eb66dfd9f34b25ace86e8c9 (diff)
[Lsan] intercept thr_exit on FreeBSD
Intercepts thr_exit call on FreeBSD. Disable pthread key workflow. The pthread key create approach does not function under FreeBSD as the libpthread is not initialised enough at this stage. Reviewers: vitalybuka, krytarowski, dim Reviewed By: vitalybuka Differential Revision: https://reviews.llvm.org/D48268 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@335164 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/lsan')
-rw-r--r--lib/lsan/lsan_interceptors.cc18
1 files changed, 15 insertions, 3 deletions
diff --git a/lib/lsan/lsan_interceptors.cc b/lib/lsan/lsan_interceptors.cc
index aee726f83..fde52e496 100644
--- a/lib/lsan/lsan_interceptors.cc
+++ b/lib/lsan/lsan_interceptors.cc
@@ -302,7 +302,7 @@ INTERCEPTOR(void, _ZdaPvRKSt9nothrow_t, void *ptr, std::nothrow_t const&)
///// Thread initialization and finalization. /////
-#if !SANITIZER_NETBSD
+#if !SANITIZER_NETBSD && !SANITIZER_FREEBSD
static unsigned g_thread_finalize_key;
static void thread_finalize(void *v) {
@@ -329,6 +329,17 @@ INTERCEPTOR(void, _lwp_exit) {
#define LSAN_MAYBE_INTERCEPT__LWP_EXIT
#endif
+#if SANITIZER_INTERCEPT_THR_EXIT
+INTERCEPTOR(void, thr_exit, tid_t *state) {
+ ENSURE_LSAN_INITED;
+ ThreadFinish();
+ REAL(thr_exit)(state);
+}
+#define LSAN_MAYBE_INTERCEPT_THR_EXIT INTERCEPT_FUNCTION(thr_exit)
+#else
+#define LSAN_MAYBE_INTERCEPT_THR_EXIT
+#endif
+
struct ThreadParam {
void *(*callback)(void *arg);
void *param;
@@ -341,7 +352,7 @@ extern "C" void *__lsan_thread_start_func(void *arg) {
void *param = p->param;
// Wait until the last iteration to maximize the chance that we are the last
// destructor to run.
-#if !SANITIZER_NETBSD
+#if !SANITIZER_NETBSD && !SANITIZER_FREEBSD
if (pthread_setspecific(g_thread_finalize_key,
(void*)GetPthreadDestructorIterations())) {
Report("LeakSanitizer: failed to set thread key.\n");
@@ -436,8 +447,9 @@ void InitializeInterceptors() {
INTERCEPT_FUNCTION(_exit);
LSAN_MAYBE_INTERCEPT__LWP_EXIT;
+ LSAN_MAYBE_INTERCEPT_THR_EXIT;
-#if !SANITIZER_NETBSD
+#if !SANITIZER_NETBSD && !SANITIZER_FREEBSD
if (pthread_key_create(&g_thread_finalize_key, &thread_finalize)) {
Report("LeakSanitizer: failed to create thread key.\n");
Die();