This is an archive of the discontinued LLVM Phabricator instance.

Correct detection of a thread termination
ClosedPublic

Authored by krytarowski on Nov 3 2017, 1:36 PM.

Details

Summary

Stop using the Linux solution with pthread_key_create(3).
This approach does not work on NetBSD, because calling
the thread destructor is not the latest operation on a POSIX
thread entity. NetBSD's libpthread still calls at least
pthread_mutex_lock and pthread_mutex_unlock.

Detect _lwp_exit(2) call as it is really the latest operation
called from a detaching POSIX thread.

This resolves one set of crashes observed in
the Thread Sanitizer execution.

Sponsored by <The NetBSD Foundation>

Diff Detail

Repository
rL LLVM

Event Timeline

krytarowski created this revision.Nov 3 2017, 1:36 PM
vitalybuka accepted this revision.Nov 3 2017, 1:45 PM
This revision is now accepted and ready to land.Nov 3 2017, 1:45 PM
krytarowski closed this revision.Nov 3 2017, 1:48 PM

For the reference: late fixup committed in SVN http://llvm.org/viewvc/llvm-project?rev=317369&view=rev

Index: lib/tsan/rtl/tsan_interceptors.cc
===================================================================
--- lib/tsan/rtl/tsan_interceptors.cc   (wersja 317367)
+++ lib/tsan/rtl/tsan_interceptors.cc   (kopia robocza)
@@ -2451,8 +2451,8 @@
 #if SANITIZER_NETBSD
 TSAN_INTERCEPTOR(void, _lwp_exit) {
   SCOPED_TSAN_INTERCEPTOR(_lwp_exit);
+  DestroyThreadState();
   REAL(_lwp_exit)();
-  DestroyThreadState();
 }
 #define TSAN_MAYBE_INTERCEPT__LWP_EXIT TSAN_INTERCEPT(_lwp_exit)
 #else