[PATCH] D14656: [sanitizer] Stop unwinding the stack when a close-to-zero PC is found

Kuba Brecka via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 13 07:02:08 PST 2015


kubabrecka created this revision.
kubabrecka added reviewers: kcc, samsonov, glider, dvyukov.
kubabrecka added subscribers: llvm-commits, zaks.anna, ismailp.

On OS X, we often get stack trace in a report that ends with a 0x0 frame:

    =================================================================
    ==56615==ERROR: AddressSanitizer: heap-use-after-free on address 0x60200000eed0 at pc 0x00010aa33359 bp 0x7fff552057f0 sp 0x7fff552023a0
    READ of size 2 at 0x60200000eed0 thread T0
    #0 0x10aa33358 in printf_common(void*, char const*, __va_list_tag*) sanitizer_common_interceptors_format.inc:545
    #1 0x10aa31e24 in wrap_vprintf sanitizer_common_interceptors.inc:1099
    #2 0x7fff8c4375ac in start (libdyld.dylib+0x35ac)
    #3 0x0  (<unknown module>)

To get rid of it, let's trim the stack trace when we find a close-to-zero value, which is obviously not a valid PC.

http://reviews.llvm.org/D14656

Files:
  lib/sanitizer_common/sanitizer_stacktrace.cc
  lib/sanitizer_common/sanitizer_stacktrace.h

Index: lib/sanitizer_common/sanitizer_stacktrace.h
===================================================================
--- lib/sanitizer_common/sanitizer_stacktrace.h
+++ lib/sanitizer_common/sanitizer_stacktrace.h
@@ -18,6 +18,7 @@
 namespace __sanitizer {
 
 static const u32 kStackTraceMax = 256;
+static const uptr kMinStackFramePcValue = 0x1000;
 
 #if SANITIZER_LINUX &&  (defined(__sparc__) || defined(__mips__))
 # define SANITIZER_CAN_FAST_UNWIND 0
Index: lib/sanitizer_common/sanitizer_stacktrace.cc
===================================================================
--- lib/sanitizer_common/sanitizer_stacktrace.cc
+++ lib/sanitizer_common/sanitizer_stacktrace.cc
@@ -95,6 +95,8 @@
 #else
     uhwptr pc1 = frame[1];
 #endif
+    if (pc1 < kMinStackFramePcValue)
+      break;
     if (pc1 != pc) {
       trace_buffer[size++] = (uptr) pc1;
     }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D14656.40148.patch
Type: text/x-patch
Size: 860 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151113/68d029ff/attachment.bin>


More information about the llvm-commits mailing list