[compiler-rt] r271085 - [sanitizers] introduce a common run-time option dedup_token_length to help with report deduplication, off by default for now. See https://github.com/google/sanitizers/issues/684

Kostya Serebryany via llvm-commits llvm-commits at lists.llvm.org
Fri May 27 18:25:45 PDT 2016


Author: kcc
Date: Fri May 27 20:25:44 2016
New Revision: 271085

URL: http://llvm.org/viewvc/llvm-project?rev=271085&view=rev
Log:
[sanitizers] introduce a common run-time option dedup_token_length to help with report deduplication, off by default for now. See https://github.com/google/sanitizers/issues/684

Added:
    compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/dedup_token_length_test.cc
Modified:
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.inc
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace_libcdep.cc

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.inc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.inc?rev=271085&r1=271084&r2=271085&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.inc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_flags.inc Fri May 27 20:25:44 2016
@@ -165,6 +165,11 @@ COMMON_FLAG(bool, symbolize_inline_frame
 COMMON_FLAG(bool, symbolize_vs_style, false,
             "Print file locations in Visual Studio style (e.g: "
             " file(10,42): ...")
+COMMON_FLAG(int, dedup_token_length, 0,
+            "If positive, after printing a stack trace also print a short "
+            "string token based on this number of frames that will simplify "
+            "deduplication of the reports. "
+            "Example: 'DEDUP_TOKEN: foo-bar-main'. Default is 0.")
 COMMON_FLAG(const char *, stack_trace_format, "DEFAULT",
             "Format string used to render stack frames. "
             "See sanitizer_stacktrace_printer.h for the format description. "

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace_libcdep.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace_libcdep.cc?rev=271085&r1=271084&r2=271085&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace_libcdep.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace_libcdep.cc Fri May 27 20:25:44 2016
@@ -25,6 +25,8 @@ void StackTrace::Print() const {
     return;
   }
   InternalScopedString frame_desc(GetPageSizeCached() * 2);
+  InternalScopedString dedup_token(GetPageSizeCached());
+  int dedup_frames = common_flags()->dedup_token_length;
   uptr frame_num = 0;
   for (uptr i = 0; i < size && trace[i]; i++) {
     // PCs in stack traces are actually the return addresses, that is,
@@ -38,11 +40,18 @@ void StackTrace::Print() const {
                   cur->info, common_flags()->symbolize_vs_style,
                   common_flags()->strip_path_prefix);
       Printf("%s\n", frame_desc.data());
+      if (dedup_frames-- > 0) {
+        if (dedup_token.length())
+          dedup_token.append("--");
+        dedup_token.append(cur->info.function);
+      }
     }
     frames->ClearAll();
   }
   // Always print a trailing empty line after stack trace.
   Printf("\n");
+  if (dedup_token.length())
+    Printf("DEDUP_TOKEN: %s\n", dedup_token.data());
 }
 
 void BufferedStackTrace::Unwind(u32 max_depth, uptr pc, uptr bp, void *context,

Added: compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/dedup_token_length_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/dedup_token_length_test.cc?rev=271085&view=auto
==============================================================================
--- compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/dedup_token_length_test.cc (added)
+++ compiler-rt/trunk/test/sanitizer_common/TestCases/Posix/dedup_token_length_test.cc Fri May 27 20:25:44 2016
@@ -0,0 +1,40 @@
+// Test dedup_token_length
+// RUN: %clangxx -O0 %s -o %t
+// RUN: env %tool_options=''                    not %run %t 2>&1   | FileCheck %s --check-prefix=CHECK0
+// RUN: env %tool_options='dedup_token_length=0' not %run %t 2>&1   | FileCheck %s --check-prefix=CHECK0
+// RUN: env %tool_options='dedup_token_length=1' not %run %t 2>&1   | FileCheck %s --check-prefix=CHECK1
+// RUN: env %tool_options='dedup_token_length=2' not %run %t 2>&1   | FileCheck %s --check-prefix=CHECK2
+// RUN: env %tool_options='dedup_token_length=3' not %run %t 2>&1   | FileCheck %s --check-prefix=CHECK3
+
+// REQUIRES: stable-runtime
+// FIXME: implement SEGV handler in other sanitizers, not just asan.
+// XFAIL: msan
+// XFAIL: lsan
+// XFAIL: tsan
+
+volatile int *null = 0;
+
+namespace Xyz {
+  template<class A, class B> void Abc() {
+    *null = 0;
+  }
+}
+
+extern "C" void bar() {
+  Xyz::Abc<int, int>();
+}
+
+void FOO() {
+  bar();
+}
+
+int main(int argc, char **argv) {
+  FOO();
+}
+
+// CHECK0-NOT: DEDUP_TOKEN:
+// CHECK1: DEDUP_TOKEN: void Xyz::Abc<int, int>()
+// CHECK1-NOT: bar
+// CHECK2: DEDUP_TOKEN: void Xyz::Abc<int, int>()--bar
+// CHECK2-NOT: FOO
+// CHECK3: DEDUP_TOKEN: void Xyz::Abc<int, int>()--bar--FOO()




More information about the llvm-commits mailing list