[compiler-rt] r291173 - [asan] Fix comparison in BufferedStackTrace::LocatePcInTrace

Vitaly Buka via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 5 13:04:47 PST 2017


Author: vitalybuka
Date: Thu Jan  5 15:04:47 2017
New Revision: 291173

URL: http://llvm.org/viewvc/llvm-project?rev=291173&view=rev
Log:
[asan] Fix comparison in BufferedStackTrace::LocatePcInTrace

Summary:
Debug builds can have larger distance between stack trace and PC on that stack.
If we assume that PC is always correct we can snap it to the nearest trace.

Reviewers: eugenis

Subscribers: llvm-commits, kubabrecka

Differential Revision: https://reviews.llvm.org/D28342

Modified:
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace.cc

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace.cc?rev=291173&r1=291172&r2=291173&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace.cc Thu Jan  5 15:04:47 2017
@@ -106,10 +106,6 @@ void BufferedStackTrace::FastUnwindStack
   }
 }
 
-static bool MatchPc(uptr cur_pc, uptr trace_pc, uptr threshold) {
-  return cur_pc - trace_pc <= threshold || trace_pc - cur_pc <= threshold;
-}
-
 void BufferedStackTrace::PopStackFrames(uptr count) {
   CHECK_LT(count, size);
   size -= count;
@@ -118,15 +114,14 @@ void BufferedStackTrace::PopStackFrames(
   }
 }
 
+static uptr Distance(uptr a, uptr b) { return a < b ? b - a : a - b; }
+
 uptr BufferedStackTrace::LocatePcInTrace(uptr pc) {
-  // Use threshold to find PC in stack trace, as PC we want to unwind from may
-  // slightly differ from return address in the actual unwinded stack trace.
-  const int kPcThreshold = 350;
-  for (uptr i = 0; i < size; ++i) {
-    if (MatchPc(pc, trace[i], kPcThreshold))
-      return i;
+  uptr best = 0;
+  for (uptr i = 1; i < size; ++i) {
+    if (Distance(trace[i], pc) < Distance(trace[best], pc)) best = i;
   }
-  return 0;
+  return best;
 }
 
 }  // namespace __sanitizer




More information about the llvm-commits mailing list