[compiler-rt] 0099316 - [DFSan] Add custom wrapper for pthread_join.

Matt Morehouse via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 10 13:41:45 PST 2020


Author: Matt Morehouse
Date: 2020-12-10T13:41:24-08:00
New Revision: 009931644a9d2cecdc6e5bf71ed83d59b776eaa3

URL: https://github.com/llvm/llvm-project/commit/009931644a9d2cecdc6e5bf71ed83d59b776eaa3
DIFF: https://github.com/llvm/llvm-project/commit/009931644a9d2cecdc6e5bf71ed83d59b776eaa3.diff

LOG: [DFSan] Add custom wrapper for pthread_join.

The wrapper clears shadow for retval.

Reviewed By: stephan.yichao.zhao

Differential Revision: https://reviews.llvm.org/D93047

Added: 
    

Modified: 
    compiler-rt/lib/dfsan/dfsan_custom.cpp
    compiler-rt/lib/dfsan/done_abilist.txt
    compiler-rt/test/dfsan/custom.cpp

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/dfsan/dfsan_custom.cpp b/compiler-rt/lib/dfsan/dfsan_custom.cpp
index 259bec4207dd..0da66c7a440d 100644
--- a/compiler-rt/lib/dfsan/dfsan_custom.cpp
+++ b/compiler-rt/lib/dfsan/dfsan_custom.cpp
@@ -427,6 +427,18 @@ SANITIZER_INTERFACE_ATTRIBUTE int __dfsw_pthread_create(
   return rv;
 }
 
+SANITIZER_INTERFACE_ATTRIBUTE int __dfsw_pthread_join(pthread_t thread,
+                                                      void **retval,
+                                                      dfsan_label thread_label,
+                                                      dfsan_label retval_label,
+                                                      dfsan_label *ret_label) {
+  int ret = pthread_join(thread, retval);
+  if (ret == 0 && retval)
+    dfsan_set_label(0, retval, sizeof(*retval));
+  *ret_label = 0;
+  return ret;
+}
+
 struct dl_iterate_phdr_info {
   int (*callback_trampoline)(void *callback, struct dl_phdr_info *info,
                              size_t size, void *data, dfsan_label info_label,

diff  --git a/compiler-rt/lib/dfsan/done_abilist.txt b/compiler-rt/lib/dfsan/done_abilist.txt
index 5d3d31f2e162..513c9ea13de3 100644
--- a/compiler-rt/lib/dfsan/done_abilist.txt
+++ b/compiler-rt/lib/dfsan/done_abilist.txt
@@ -319,6 +319,10 @@ fun:pthread_setspecific=discard
 # Functions that take a callback (wrap the callback manually).
 fun:pthread_create=custom
 
+# Functions that produce output does not depend on the input (need to zero the
+# shadow manually).
+fun:pthread_join=custom
+
 ###############################################################################
 # libffi/libgo
 ###############################################################################

diff  --git a/compiler-rt/test/dfsan/custom.cpp b/compiler-rt/test/dfsan/custom.cpp
index 14cddd8e2a3c..e21f35426cf0 100644
--- a/compiler-rt/test/dfsan/custom.cpp
+++ b/compiler-rt/test/dfsan/custom.cpp
@@ -792,8 +792,12 @@ void test_pthread_create() {
   pthread_t pt;
   pthread_create(&pt, 0, pthread_create_test_cb, (void *)1);
   void *cbrv;
-  pthread_join(pt, &cbrv);
+  dfsan_set_label(i_label, &cbrv, sizeof(cbrv));
+  int ret = pthread_join(pt, &cbrv);
+  assert(ret == 0);
   assert(cbrv == (void *)2);
+  ASSERT_ZERO_LABEL(ret);
+  ASSERT_ZERO_LABEL(cbrv);
 }
 
 int dl_iterate_phdr_test_cb(struct dl_phdr_info *info, size_t size,


        


More information about the llvm-commits mailing list