[compiler-rt] r192442 - [sanitizer] Move the PTHREAD_DESTRUCTOR_ITERATIONS constant to sanitizer_linux.h.

Sergey Matveev earthdok at google.com
Fri Oct 11 05:09:49 PDT 2013


Author: smatveev
Date: Fri Oct 11 07:09:49 2013
New Revision: 192442

URL: http://llvm.org/viewvc/llvm-project?rev=192442&view=rev
Log:
[sanitizer] Move the PTHREAD_DESTRUCTOR_ITERATIONS constant to sanitizer_linux.h.

Add a test.

Modified:
    compiler-rt/trunk/lib/lsan/lsan_interceptors.cc
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.h
    compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_linux_test.cc
    compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc

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=192442&r1=192441&r2=192442&view=diff
==============================================================================
--- compiler-rt/trunk/lib/lsan/lsan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/lsan/lsan_interceptors.cc Fri Oct 11 07:09:49 2013
@@ -192,9 +192,6 @@ struct ThreadParam {
   atomic_uintptr_t tid;
 };
 
-// PTHREAD_DESTRUCTOR_ITERATIONS from glibc.
-const uptr kPthreadDestructorIterations = 4;
-
 extern "C" void *__lsan_thread_start_func(void *arg) {
   ThreadParam *p = (ThreadParam*)arg;
   void* (*callback)(void *arg) = p->callback;

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.h?rev=192442&r1=192441&r2=192442&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.h Fri Oct 11 07:09:49 2013
@@ -77,6 +77,8 @@ void CacheBinaryName();
 // Call cb for each region mapped by map.
 void ForEachMappedRegion(link_map *map, void (*cb)(const void *, uptr));
 
+// PTHREAD_DESTRUCTOR_ITERATIONS from glibc.
+const uptr kPthreadDestructorIterations = 4;
 }  // namespace __sanitizer
 
 #endif  // SANITIZER_LINUX

Modified: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_linux_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_linux_test.cc?rev=192442&r1=192441&r2=192442&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_linux_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_linux_test.cc Fri Oct 11 07:09:49 2013
@@ -255,6 +255,42 @@ TEST(SanitizerCommon, LibraryNameIs) {
     }
 }
 
+pthread_key_t key;
+bool destructor_executed;
+
+extern "C"
+void destructor(void *arg) {
+  uptr iter = reinterpret_cast<uptr>(arg);
+  if (iter > 1) {
+    ASSERT_EQ(0, pthread_setspecific(key, reinterpret_cast<void *>(iter - 1)));
+    return;
+  }
+  destructor_executed = true;
+}
+
+extern "C"
+void *thread_func(void *arg) {
+  return reinterpret_cast<void*>(pthread_setspecific(key, arg));
+}
+
+void SpawnThread(uptr iteration) {
+  destructor_executed = false;
+  pthread_t tid;
+  ASSERT_EQ(0, pthread_create(&tid, 0, &thread_func,
+                              reinterpret_cast<void *>(iteration)));
+  void *retval;
+  ASSERT_EQ(0, pthread_join(tid, &retval));
+  ASSERT_EQ(0, retval);
+}
+
+TEST(SanitizerCommon, PthreadDestructorIterations) {
+  ASSERT_EQ(0, pthread_key_create(&key, &destructor));
+  SpawnThread(kPthreadDestructorIterations);
+  EXPECT_TRUE(destructor_executed);
+  SpawnThread(kPthreadDestructorIterations + 1);
+  EXPECT_FALSE(destructor_executed);
+}
+
 }  // namespace __sanitizer
 
 #endif  // SANITIZER_LINUX

Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc?rev=192442&r1=192441&r2=192442&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc Fri Oct 11 07:09:49 2013
@@ -853,7 +853,8 @@ extern "C" void *__tsan_thread_start_fun
   {
     ThreadState *thr = cur_thread();
     ScopedInRtl in_rtl;
-    if (pthread_setspecific(g_thread_finalize_key, (void*)4)) {
+    if (pthread_setspecific(g_thread_finalize_key,
+                            (void *)kPthreadDestructorIterations)) {
       Printf("ThreadSanitizer: failed to set thread key\n");
       Die();
     }





More information about the llvm-commits mailing list