[compiler-rt] r335164 - [Lsan] intercept thr_exit on FreeBSD

David Carlier via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 20 13:13:26 PDT 2018


Author: devnexen
Date: Wed Jun 20 13:13:25 2018
New Revision: 335164

URL: http://llvm.org/viewvc/llvm-project?rev=335164&view=rev
Log:
[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

Modified:
    compiler-rt/trunk/lib/lsan/lsan_interceptors.cc
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h

Modified: compiler-rt/trunk/lib/lsan/lsan_interceptors.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/lsan/lsan_interceptors.cc?rev=335164&r1=335163&r2=335164&view=diff
==============================================================================
--- compiler-rt/trunk/lib/lsan/lsan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/lsan/lsan_interceptors.cc Wed Jun 20 13:13:25 2018
@@ -302,7 +302,7 @@ INTERCEPTOR(void, _ZdaPvRKSt9nothrow_t,
 
 ///// 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_fun
   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();

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h?rev=335164&r1=335163&r2=335164&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h Wed Jun 20 13:13:25 2018
@@ -349,6 +349,7 @@
   (SI_LINUX_NOT_ANDROID || SI_SOLARIS)
 #define SANITIZER_INTERCEPT_PTHREAD_BARRIERATTR_GETPSHARED \
   (SI_LINUX_NOT_ANDROID && !SI_NETBSD && !SI_OPENBSD)
+#define SANITIZER_INTERCEPT_THR_EXIT SI_FREEBSD
 #define SANITIZER_INTERCEPT_TMPNAM SI_POSIX
 #define SANITIZER_INTERCEPT_TMPNAM_R SI_LINUX_NOT_ANDROID || SI_SOLARIS
 #define SANITIZER_INTERCEPT_TTYNAME_R SI_POSIX




More information about the llvm-commits mailing list