#include "sanitizer/dfsan_interface.h"
#include "sanitizer_common/sanitizer_atomic.h"
#include "sanitizer_common/sanitizer_common.h"
+#include "sanitizer_common/sanitizer_flags.h"
#include "sanitizer_common/sanitizer_libc.h"
#include "dfsan/dfsan.h"
static atomic_dfsan_label __dfsan_last_label;
static dfsan_label_info __dfsan_label_info[kNumLabels];
+Flags __dfsan::flags_data;
+
SANITIZER_INTERFACE_ATTRIBUTE THREADLOCAL dfsan_label __dfsan_retval_tls;
SANITIZER_INTERFACE_ATTRIBUTE THREADLOCAL dfsan_label __dfsan_arg_tls[64];
extern "C" SANITIZER_INTERFACE_ATTRIBUTE
void __dfsan_unimplemented(char *fname) {
- Report("WARNING: DataFlowSanitizer: call to uninstrumented function %s\n",
- fname);
+ if (flags().warn_unimplemented)
+ Report("WARNING: DataFlowSanitizer: call to uninstrumented function %s\n",
+ 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() {}
+extern "C" SANITIZER_INTERFACE_ATTRIBUTE void __dfsan_nonzero_label() {
+ if (flags().warn_nonzero_labels)
+ Report("WARNING: DataFlowSanitizer: saw nonzero label\n");
+}
// Like __dfsan_union, but for use from the client or custom functions. Hence
// the equality comparison is done here before calling __dfsan_union.
}
}
+static void InitializeFlags(Flags &f, const char *env) {
+ f.warn_unimplemented = true;
+ f.warn_nonzero_labels = false;
+
+ ParseFlag(env, &f.warn_unimplemented, "warn_unimplemented");
+ ParseFlag(env, &f.warn_nonzero_labels, "warn_nonzero_labels");
+}
+
#ifdef DFSAN_NOLIBC
extern "C" void dfsan_init() {
#else
if (!(init_addr >= kUnusedAddr && init_addr < kAppAddr))
Mprotect(kUnusedAddr, kAppAddr - kUnusedAddr);
+ InitializeFlags(flags(), GetEnv("DFSAN_OPTIONS"));
+
InitializeInterceptors();
}
--- /dev/null
+// 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.
+
+#include <sanitizer/dfsan_interface.h>
+
+int f(int i) {
+ 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));
+
+ // CHECK: WARNING: DataFlowSanitizer: call to uninstrumented function f
+ // CHECK-NOT: WARNING: DataFlowSanitizer: saw nonzero label
+ // CHECK-NONZERO: WARNING: DataFlowSanitizer: saw nonzero label
+ f(i);
+
+ return 0;
+}