[PATCH] Pass the non-zero label to __dfsan_nonzero_label (compiler-rt)
Lorenzo Martignoni
martignlo at google.com
Tue Dec 3 05:56:13 PST 2013
Hi pcc,
This is the patch for the compiler-rt to complement D2317.
http://llvm-reviews.chandlerc.com/D2318
Files:
lib/dfsan/dfsan.cc
lib/dfsan/dfsan.h
lib/dfsan/lit_tests/flags.c
Index: lib/dfsan/dfsan.cc
===================================================================
--- lib/dfsan/dfsan.cc
+++ lib/dfsan/dfsan.cc
@@ -139,12 +139,21 @@
fname);
}
-// Use '-mllvm -dfsan-debug-nonzero-labels' and break on this function
-// to try to figure out where labels are being introduced in a nominally
-// label-free program.
-extern "C" SANITIZER_INTERFACE_ATTRIBUTE void __dfsan_nonzero_label() {
- if (flags().warn_nonzero_labels)
- Report("WARNING: DataFlowSanitizer: saw nonzero label\n");
+
+// This function logs statements with non-zero labels. To enable calls to this
+// function, compile with '-mllvm -dfsan-log-nonzero-labels'. This function
+// serves two purposes. First, it can be used to try to figure out where labels
+// are being introduced in a nominally label-free program (set a breakpoint on
+// this function). Second, it can be used to produce a log of statements with
+// operands with non-zero labels (provide your own version of the function).
+extern "C" SANITIZER_INTERFACE_ATTRIBUTE
+#ifdef SANITIZER_SUPPORTS_WEAK_HOOKS
+SANITIZER_WEAK_ATTRIBUTE
+#endif
+void __dfsan_nonzero_label(dfsan_label label) {
+ if (flags().log_nonzero_labels)
+ Report("WARNING: DataFlowSanitizer: saw nonzero label (%u) @ %p\n", label,
+ GET_CALLER_PC());
}
// Like __dfsan_union, but for use from the client or custom functions. Hence
@@ -232,10 +241,10 @@
static void InitializeFlags(Flags &f, const char *env) {
f.warn_unimplemented = true;
- f.warn_nonzero_labels = false;
+ f.log_nonzero_labels = false;
ParseFlag(env, &f.warn_unimplemented, "warn_unimplemented");
- ParseFlag(env, &f.warn_nonzero_labels, "warn_nonzero_labels");
+ ParseFlag(env, &f.log_nonzero_labels, "log_nonzero_labels");
}
#ifdef DFSAN_NOLIBC
Index: lib/dfsan/dfsan.h
===================================================================
--- lib/dfsan/dfsan.h
+++ lib/dfsan/dfsan.h
@@ -53,8 +53,8 @@
struct Flags {
// Whether to warn on unimplemented functions.
bool warn_unimplemented;
- // Whether to warn on non-zero labels.
- bool warn_nonzero_labels;
+ // Whether to log non-zero labels.
+ bool log_nonzero_labels;
};
extern Flags flags_data;
Index: lib/dfsan/lit_tests/flags.c
===================================================================
--- lib/dfsan/lit_tests/flags.c
+++ lib/dfsan/lit_tests/flags.c
@@ -1,24 +1,29 @@
-// RUN: %clang_dfsan -m64 %s -fsanitize-blacklist=%S/Inputs/flags_abilist.txt -mllvm -dfsan-debug-nonzero-labels -o %t && %t 2>&1 | FileCheck %s
-// RUN: %clang_dfsan -m64 %s -fsanitize-blacklist=%S/Inputs/flags_abilist.txt -mllvm -dfsan-debug-nonzero-labels -o %t && DFSAN_OPTIONS=warn_unimplemented=0 %t 2>&1 | count 0
-// RUN: %clang_dfsan -m64 %s -fsanitize-blacklist=%S/Inputs/flags_abilist.txt -mllvm -dfsan-debug-nonzero-labels -o %t && DFSAN_OPTIONS=warn_nonzero_labels=1 %t 2>&1 | FileCheck --check-prefix=CHECK-NONZERO %s
-
-// Tests that flags work correctly.
+// RUN: %clang_dfsan -m64 %s -fsanitize-blacklist=%S/Inputs/flags_abilist.txt -mllvm -dfsan-log-nonzero-labels -o %t && %t 2>&1 | FileCheck %s
+// RUN: %clang_dfsan -m64 %s -fsanitize-blacklist=%S/Inputs/flags_abilist.txt -mllvm -dfsan-log-nonzero-labels -o %t && DFSAN_OPTIONS=warn_unimplemented=0 %t 2>&1 | count 0
+// RUN: %clang_dfsan -m64 %s -fsanitize-blacklist=%S/Inputs/flags_abilist.txt -mllvm -dfsan-log-nonzero-labels -o %t && DFSAN_OPTIONS=log_nonzero_labels=1 %t 2>&1 | FileCheck --check-prefix=CHECK-NONZERO %s
#include <sanitizer/dfsan_interface.h>
+#include <stdio.h>
-int f(int i) {
+int f(int i, int j) {
return i;
}
int main(void) {
int i = 1;
dfsan_label i_label = dfsan_create_label("i", 0);
dfsan_set_label(i_label, &i, sizeof(i));
+ int j = 1;
+ dfsan_label j_label = dfsan_create_label("j", 0);
+ dfsan_set_label(j_label, &j, sizeof(j));
+
// CHECK: WARNING: DataFlowSanitizer: call to uninstrumented function f
- // CHECK-NOT: WARNING: DataFlowSanitizer: saw nonzero label
- // CHECK-NONZERO: WARNING: DataFlowSanitizer: saw nonzero label
- f(i);
+ // CHECK-NOT: WARNING: DataFlowSanitizer: saw nonzero label (1) @
+ // CHECK-NONZERO: WARNING: DataFlowSanitizer: saw nonzero label (1) @
+ // CHECK-NOT: WARNING: DataFlowSanitizer: saw nonzero label (2) @
+ // CHECK-NONZERO: WARNING: DataFlowSanitizer: saw nonzero label (2) @
+ f(i, j);
return 0;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D2318.1.patch
Type: text/x-patch
Size: 4397 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20131203/e0561fb4/attachment.bin>
More information about the llvm-commits
mailing list