[compiler-rt] r266991 - [sanitizer] Use pthread_threadid_np as thread ID on OS X

Kuba Brecka via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 21 07:38:41 PDT 2016


Author: kuba.brecka
Date: Thu Apr 21 09:38:41 2016
New Revision: 266991

URL: http://llvm.org/viewvc/llvm-project?rev=266991&view=rev
Log:
[sanitizer] Use pthread_threadid_np as thread ID on OS X

Let's use pthread_threadid_np which returns a more reasonable ID than pthread_self (which is actually a stack pointer). The numbers from pthread_threadid_np are already used in other tools, e.g. in LLDB, and often appear in logs, so it's much more useful than pthread_self.

Differential Revision: http://reviews.llvm.org/D18951


Modified:
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc?rev=266991&r1=266990&r2=266991&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc Thu Apr 21 09:38:41 2016
@@ -230,7 +230,10 @@ bool FileExists(const char *filename) {
 }
 
 uptr GetTid() {
-  return reinterpret_cast<uptr>(pthread_self());
+  // FIXME: This can potentially get truncated on 32-bit, where uptr is 4 bytes.
+  uint64_t tid;
+  pthread_threadid_np(nullptr, &tid);
+  return tid;
 }
 
 void GetThreadStackTopAndBottom(bool at_initialization, uptr *stack_top,




More information about the llvm-commits mailing list