[compiler-rt] r189503 - [dfsan] Add custom function for dl_iterate_phdr.

Peter Collingbourne peter at pcc.me.uk
Wed Aug 28 13:18:25 PDT 2013


Author: pcc
Date: Wed Aug 28 15:18:25 2013
New Revision: 189503

URL: http://llvm.org/viewvc/llvm-project?rev=189503&view=rev
Log:
[dfsan] Add custom function for dl_iterate_phdr.

Differential Revision: http://llvm-reviews.chandlerc.com/D1505

Modified:
    compiler-rt/trunk/lib/dfsan/dfsan_custom.cc
    compiler-rt/trunk/lib/dfsan/done_abilist.txt
    compiler-rt/trunk/lib/dfsan/lit_tests/custom.c

Modified: compiler-rt/trunk/lib/dfsan/dfsan_custom.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/dfsan/dfsan_custom.cc?rev=189503&r1=189502&r2=189503&view=diff
==============================================================================
--- compiler-rt/trunk/lib/dfsan/dfsan_custom.cc (original)
+++ compiler-rt/trunk/lib/dfsan/dfsan_custom.cc Wed Aug 28 15:18:25 2013
@@ -19,6 +19,7 @@
 
 #include <ctype.h>
 #include <dlfcn.h>
+#include <link.h>
 #include <pthread.h>
 #include <stdlib.h>
 #include <string.h>
@@ -306,4 +307,36 @@ SANITIZER_INTERFACE_ATTRIBUTE int __dfsw
   return rv;
 }
 
+struct dl_iterate_phdr_info {
+  int (*callback_trampoline)(void *callback, struct dl_phdr_info *info,
+                             size_t size, void *data, dfsan_label info_label,
+                             dfsan_label size_label, dfsan_label data_label,
+                             dfsan_label *ret_label);
+  void *callback;
+  void *data;
+};
+
+int dl_iterate_phdr_cb(struct dl_phdr_info *info, size_t size, void *data) {
+  dl_iterate_phdr_info *dipi = (dl_iterate_phdr_info *)data;
+  dfsan_set_label(0, *info);
+  dfsan_set_label(0, (void *)info->dlpi_name, strlen(info->dlpi_name) + 1);
+  dfsan_set_label(0, (void *)info->dlpi_phdr,
+                  sizeof(*info->dlpi_phdr) * info->dlpi_phnum);
+  dfsan_label ret_label;
+  return dipi->callback_trampoline(dipi->callback, info, size, dipi->data, 0, 0,
+                                   0, &ret_label);
+}
+
+SANITIZER_INTERFACE_ATTRIBUTE int __dfsw_dl_iterate_phdr(
+    int (*callback_trampoline)(void *callback, struct dl_phdr_info *info,
+                               size_t size, void *data, dfsan_label info_label,
+                               dfsan_label size_label, dfsan_label data_label,
+                               dfsan_label *ret_label),
+    void *callback, void *data, dfsan_label callback_label,
+    dfsan_label data_label, dfsan_label *ret_label) {
+  dl_iterate_phdr_info dipi = { callback_trampoline, callback, data };
+  *ret_label = 0;
+  return dl_iterate_phdr(dl_iterate_phdr_cb, &dipi);
+}
+
 }

Modified: compiler-rt/trunk/lib/dfsan/done_abilist.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/dfsan/done_abilist.txt?rev=189503&r1=189502&r2=189503&view=diff
==============================================================================
--- compiler-rt/trunk/lib/dfsan/done_abilist.txt (original)
+++ compiler-rt/trunk/lib/dfsan/done_abilist.txt Wed Aug 28 15:18:25 2013
@@ -103,6 +103,7 @@ fun:read=custom
 fun:pread=custom
 fun:clock_gettime=custom
 fun:pthread_create=custom
+fun:dl_iterate_phdr=custom
 
 # TODO: custom
 fun:snprintf=discard

Modified: compiler-rt/trunk/lib/dfsan/lit_tests/custom.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/dfsan/lit_tests/custom.c?rev=189503&r1=189502&r2=189503&view=diff
==============================================================================
--- compiler-rt/trunk/lib/dfsan/lit_tests/custom.c (original)
+++ compiler-rt/trunk/lib/dfsan/lit_tests/custom.c Wed Aug 28 15:18:25 2013
@@ -3,8 +3,10 @@
 
 // Tests custom implementations of various libc functions.
 
+#define _GNU_SOURCE
 #include <sanitizer/dfsan_interface.h>
 #include <assert.h>
+#include <link.h>
 #include <pthread.h>
 #include <string.h>
 #include <stdlib.h>
@@ -19,6 +21,14 @@ void *ptcb(void *p) {
   return (void *)2;
 }
 
+int dlcb(struct dl_phdr_info *info, size_t size, void *data) {
+  assert(data == (void *)3);
+  assert(dfsan_get_label((uintptr_t)info) == 0);
+  assert(dfsan_get_label(size) == 0);
+  assert(dfsan_get_label((uintptr_t)data) == 0);
+  return 0;
+}
+
 int main(void) {
   int i = 1;
   dfsan_label i_label = dfsan_create_label("i", 0);
@@ -138,5 +148,7 @@ int main(void) {
   pthread_join(pt, &cbrv);
   assert(cbrv == (void *)2);
 
+  dl_iterate_phdr(dlcb, (void *)3);
+
   return 0;
 }





More information about the llvm-commits mailing list