[dfsan] Runtime support for ABI list functionality; can now run integration tests...
authorPeter Collingbourne <peter@pcc.me.uk>
Wed, 14 Aug 2013 18:54:06 +0000 (18:54 +0000)
committerPeter Collingbourne <peter@pcc.me.uk>
Wed, 14 Aug 2013 18:54:06 +0000 (18:54 +0000)
Differential Revision: http://llvm-reviews.chandlerc.com/D1351

llvm-svn: 188401

compiler-rt/lib/dfsan/CMakeLists.txt
compiler-rt/lib/dfsan/dfsan.cc
compiler-rt/lib/dfsan/done_abilist.txt [new file with mode: 0644]
compiler-rt/lib/dfsan/lit_tests/CMakeLists.txt
compiler-rt/lib/dfsan/lit_tests/basic.c
compiler-rt/lib/dfsan/lit_tests/fncall.c
compiler-rt/lib/dfsan/lit_tests/propagate.c

index 3d96c080c739ce31fe5306e5d66c79c86a5e1bda..869797f7264f7022977845559a94dbf13bcb8020 100644 (file)
@@ -26,4 +26,15 @@ if(CAN_TARGET_${arch})
   list(APPEND DFSAN_RUNTIME_LIBRARIES clang_rt.dfsan-${arch})
 endif()
 
+add_custom_target(dfsan_abilist ALL
+                                SOURCES ${CLANG_RESOURCE_DIR}/dfsan_abilist.txt)
+add_custom_command(OUTPUT ${CLANG_RESOURCE_DIR}/dfsan_abilist.txt
+                   VERBATIM
+                   COMMAND
+                     cat ${CMAKE_CURRENT_SOURCE_DIR}/done_abilist.txt
+                         > ${CLANG_RESOURCE_DIR}/dfsan_abilist.txt
+                   DEPENDS done_abilist.txt)
+install(FILES ${CLANG_RESOURCE_DIR}/dfsan_abilist.txt
+        DESTINATION ${LIBCLANG_INSTALL_PATH})
+
 add_subdirectory(lit_tests)
index ba8e8b5112ecbece93c6f6dc8b649fa33224ec3b..71f83d8c1132fc07a22fb45fdf169841bc68d3b6 100644 (file)
@@ -130,6 +130,12 @@ dfsan_label __dfsan_union_load(const dfsan_label *ls, size_t n) {
   return label;
 }
 
+extern "C" SANITIZER_INTERFACE_ATTRIBUTE
+void __dfsan_unimplemented(char *fname) {
+  Report("WARNING: DataFlowSanitizer: call to uninstrumented function %s\n",
+         fname);
+}
+
 // Like __dfsan_union, but for use from the client or custom functions.  Hence
 // the equality comparison is done here before calling __dfsan_union.
 SANITIZER_INTERFACE_ATTRIBUTE dfsan_label
@@ -147,7 +153,6 @@ dfsan_label dfsan_create_label(const char *desc, void *userdata) {
   __dfsan_label_info[label].l1 = __dfsan_label_info[label].l2 = 0;
   __dfsan_label_info[label].desc = desc;
   __dfsan_label_info[label].userdata = userdata;
-  __dfsan_retval_tls = 0;  // Ensures return value is unlabelled in the caller.
   return label;
 }
 
@@ -164,11 +169,14 @@ void dfsan_add_label(dfsan_label label, void *addr, size_t size) {
       *labelp = __dfsan_union(*labelp, label);
 }
 
-SANITIZER_INTERFACE_ATTRIBUTE dfsan_label dfsan_get_label(long data) {
-  // The label for 'data' is implicitly passed by the instrumentation pass in
-  // the first element of __dfsan_arg_tls.  So we can just return it.
-  __dfsan_retval_tls = 0;  // Ensures return value is unlabelled in the caller.
-  return __dfsan_arg_tls[0];
+// Unlike the other dfsan interface functions the behavior of this function
+// depends on the label of one of its arguments.  Hence it is implemented as a
+// custom function.
+extern "C" SANITIZER_INTERFACE_ATTRIBUTE dfsan_label
+__dfsw_dfsan_get_label(long data, dfsan_label data_label,
+                       dfsan_label *ret_label) {
+  *ret_label = 0;
+  return data_label;
 }
 
 SANITIZER_INTERFACE_ATTRIBUTE dfsan_label
@@ -180,12 +188,10 @@ dfsan_read_label(const void *addr, size_t size) {
 
 SANITIZER_INTERFACE_ATTRIBUTE
 const struct dfsan_label_info *dfsan_get_label_info(dfsan_label label) {
-  __dfsan_retval_tls = 0;  // Ensures return value is unlabelled in the caller.
   return &__dfsan_label_info[label];
 }
 
 int dfsan_has_label(dfsan_label label, dfsan_label elem) {
-  __dfsan_retval_tls = 0;  // Ensures return value is unlabelled in the caller.
   if (label == elem)
     return true;
   const dfsan_label_info *info = dfsan_get_label_info(label);
@@ -197,7 +203,6 @@ int dfsan_has_label(dfsan_label label, dfsan_label elem) {
 }
 
 dfsan_label dfsan_has_label_with_desc(dfsan_label label, const char *desc) {
-  __dfsan_retval_tls = 0;  // Ensures return value is unlabelled in the caller.
   const dfsan_label_info *info = dfsan_get_label_info(label);
   if (info->l1 != 0) {
     return dfsan_has_label_with_desc(info->l1, desc) ||
diff --git a/compiler-rt/lib/dfsan/done_abilist.txt b/compiler-rt/lib/dfsan/done_abilist.txt
new file mode 100644 (file)
index 0000000..c156b33
--- /dev/null
@@ -0,0 +1,30 @@
+fun:main=uninstrumented
+fun:main=discard
+
+# DFSan interface functions.
+fun:dfsan_union=uninstrumented
+fun:dfsan_union=discard
+
+fun:dfsan_create_label=uninstrumented
+fun:dfsan_create_label=discard
+
+fun:dfsan_set_label=uninstrumented
+fun:dfsan_set_label=discard
+
+fun:dfsan_add_label=uninstrumented
+fun:dfsan_add_label=discard
+
+fun:dfsan_get_label=uninstrumented
+fun:dfsan_get_label=custom
+
+fun:dfsan_read_label=uninstrumented
+fun:dfsan_read_label=discard
+
+fun:dfsan_get_label_info=uninstrumented
+fun:dfsan_get_label_info=discard
+
+fun:dfsan_has_label=uninstrumented
+fun:dfsan_has_label=discard
+
+fun:dfsan_has_label_with_desc=uninstrumented
+fun:dfsan_has_label_with_desc=discard
index 67888dfb9cfa476050e21d93f498bbba43c4675f..d7c5c82ac3c0fa03cac7478362cb53c6a6a12959 100644 (file)
@@ -9,7 +9,8 @@ if(COMPILER_RT_CAN_EXECUTE_TESTS)
   # Run DFSan tests only if we're sure we may produce working binaries.
   set(DFSAN_TEST_DEPS
     ${SANITIZER_COMMON_LIT_TEST_DEPS}
-    ${DFSAN_RUNTIME_LIBRARIES})
+    ${DFSAN_RUNTIME_LIBRARIES}
+    dfsan_abilist)
   set(DFSAN_TEST_PARAMS
     dfsan_site_config=${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg)
   add_lit_testsuite(check-dfsan "Running the DataFlowSanitizer tests"
index de11bd186e95ff82b7fb1c3f31300416d74c422b..b566c9271d0b47585c30c2cfedd40a100687fd8a 100644 (file)
@@ -1,4 +1,5 @@
 // RUN: %clang_dfsan -m64 %s -o %t && %t
+// RUN: %clang_dfsan -mllvm -dfsan-args-abi -m64 %s -o %t && %t
 
 // Tests that labels are propagated through loads and stores.
 
index 7d4706f709aa778585e4e9daf1cbb6921a0d18bf..15b77bd67902b50ab519587895106a050baf4ac5 100644 (file)
@@ -1,4 +1,5 @@
 // RUN: %clang_dfsan -m64 %s -o %t && %t
+// RUN: %clang_dfsan -mllvm -dfsan-args-abi -m64 %s -o %t && %t
 
 // Tests that labels are propagated through function calls.
 
index 31b65ee72a44c66a23d7ea44279c436bf22ac145..d1e971d418f705bd0dd14876011974dbd37f704f 100644 (file)
@@ -1,4 +1,5 @@
 // RUN: %clang_dfsan -m64 %s -o %t && %t
+// RUN: %clang_dfsan -mllvm -dfsan-args-abi -m64 %s -o %t && %t
 
 // Tests that labels are propagated through computation and that union labels
 // are properly created.