[PATCH] D19961: [LSAN] Fix test swapcontext.cc on MIPS

Sagar Thakur via llvm-commits llvm-commits at lists.llvm.org
Thu May 5 03:25:07 PDT 2016


sagar created this revision.
sagar added reviewers: kcc, samsonov, earthdok.
sagar added subscribers: mohit.bhakkad, jaydeep, llvm-commits.
sagar set the repository for this revision to rL LLVM.
sagar added a project: Sanitizers.
Herald added a subscriber: kubabrecka.

There is no frame validity check in the slow unwinder like there is in the fast unwinder due to which lsan reports a leak even for heap allocated coroutine in the test swapcontext.cc. Since mips/linux uses slow unwindwer instead of fast unwinder, the test fails for mips/linux. Therefore adding the checks before unwinding fixes the test for mips/linux.

Continued from http://reviews.llvm.org/D18690.

Repository:
  rL LLVM

http://reviews.llvm.org/D19961

Files:
  lib/asan/asan_stack.h
  lib/lsan/lsan.h
  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
@@ -110,6 +110,11 @@
   void operator=(const BufferedStackTrace &);
 };
 
+// Check if given pointer points into allocated stack area.
+static inline bool IsValidFrame(uptr frame, uptr stack_top, uptr stack_bottom) {
+  return frame > stack_bottom && frame < stack_top - 2 * sizeof (uhwptr);
+}
+
 }  // namespace __sanitizer
 
 // Use this macro if you want to print stack trace with the caller
Index: lib/sanitizer_common/sanitizer_stacktrace.cc
===================================================================
--- lib/sanitizer_common/sanitizer_stacktrace.cc
+++ lib/sanitizer_common/sanitizer_stacktrace.cc
@@ -40,11 +40,6 @@
   top_frame_bp = 0;
 }
 
-// Check if given pointer points into allocated stack area.
-static inline bool IsValidFrame(uptr frame, uptr stack_top, uptr stack_bottom) {
-  return frame > stack_bottom && frame < stack_top - 2 * sizeof (uhwptr);
-}
-
 // In GCC on ARM bp points to saved lr, not fp, so we should check the next
 // cell in stack to be a saved frame pointer. GetCanonicFrame returns the
 // pointer to saved frame pointer in any case.
Index: lib/lsan/lsan.h
===================================================================
--- lib/lsan/lsan.h
+++ lib/lsan/lsan.h
@@ -15,6 +15,22 @@
 #include "sanitizer_common/sanitizer_flags.h"
 #include "sanitizer_common/sanitizer_stacktrace.h"
 
+#if defined(__mips__)
+#define GET_STACK_TRACE(max_size, fast)                                        \
+  BufferedStackTrace stack;                                                    \
+  {                                                                            \
+    uptr stack_top = 0, stack_bottom = 0;                                      \
+    ThreadContext *t;                                                          \
+    if (t = CurrentThreadContext()) {                                          \
+      stack_top = t->stack_end();                                              \
+      stack_bottom = t->stack_begin();                                         \
+    }                                                                          \
+    if (IsValidFrame(GET_CURRENT_FRAME(), stack_top, stack_bottom)) {          \
+      stack.Unwind(max_size, StackTrace::GetCurrentPc(), GET_CURRENT_FRAME(),  \
+                 /* context */ 0, stack_top, stack_bottom, fast);              \
+    }                                                                          \
+  }
+#else
 #define GET_STACK_TRACE(max_size, fast)                                        \
   BufferedStackTrace stack;                                                    \
   {                                                                            \
@@ -27,6 +43,7 @@
     stack.Unwind(max_size, StackTrace::GetCurrentPc(), GET_CURRENT_FRAME(),    \
                  /* context */ 0, stack_top, stack_bottom, fast);              \
   }
+#endif
 
 #define GET_STACK_TRACE_FATAL \
   GET_STACK_TRACE(kStackTraceMax, common_flags()->fast_unwind_on_fatal)
Index: lib/asan/asan_stack.h
===================================================================
--- lib/asan/asan_stack.h
+++ lib/asan/asan_stack.h
@@ -48,7 +48,14 @@
       uptr stack_top = t->stack_top();
       uptr stack_bottom = t->stack_bottom();
       ScopedUnwinding unwind_scope(t);
+#if defined(__mips__)
+      if (IsValidFrame(bp, stack_top, stack_bottom)) {
+        stack->Unwind(max_depth, pc, bp, context, stack_top, stack_bottom,
+                      fast);
+      }
+#else
       stack->Unwind(max_depth, pc, bp, context, stack_top, stack_bottom, fast);
+#endif
     } else if (!t && !fast) {
       /* If GetCurrentThread() has failed, try to do slow unwind anyways. */
       stack->Unwind(max_depth, pc, bp, context, 0, 0, false);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D19961.56256.patch
Type: text/x-patch
Size: 3954 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160505/dbf23953/attachment.bin>


More information about the llvm-commits mailing list