[compiler-rt] r214245 - [UBSan] Get pc/bp for stack unwinding as early as possible.

Alexey Samsonov vonosmas at gmail.com
Tue Jul 29 16:22:41 PDT 2014


Author: samsonov
Date: Tue Jul 29 18:22:41 2014
New Revision: 214245

URL: http://llvm.org/viewvc/llvm-project?rev=214245&view=rev
Log:
[UBSan] Get pc/bp for stack unwinding as early as possible.

This will ensure that stack frames in error reports will not
contain internal UBSan failures, and frame #0 will be the
actual place in the program where the error happens.

Modified:
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace.h
    compiler-rt/trunk/lib/ubsan/ubsan_diag.h
    compiler-rt/trunk/lib/ubsan/ubsan_handlers_cxx.cc

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace.h?rev=214245&r1=214244&r2=214245&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_stacktrace.h Tue Jul 29 18:22:41 2014
@@ -88,6 +88,10 @@ struct StackTrace {
   uptr local_stack;                           \
   uptr sp = (uptr)&local_stack
 
+#define GET_CALLER_PC_BP \
+  uptr bp = GET_CURRENT_FRAME();              \
+  uptr pc = GET_CALLER_PC();
+
 // Use this macro if you want to print stack trace with the current
 // function in the top frame.
 #define GET_CURRENT_PC_BP_SP \

Modified: compiler-rt/trunk/lib/ubsan/ubsan_diag.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/ubsan_diag.h?rev=214245&r1=214244&r2=214245&view=diff
==============================================================================
--- compiler-rt/trunk/lib/ubsan/ubsan_diag.h (original)
+++ compiler-rt/trunk/lib/ubsan/ubsan_diag.h Tue Jul 29 18:22:41 2014
@@ -206,12 +206,6 @@ public:
 
 void MaybePrintStackTrace(uptr pc, uptr bp);
 
-#define MAYBE_PRINT_STACK_TRACE() do { \
-  GET_CALLER_PC_BP_SP; \
-  (void)sp; \
-  MaybePrintStackTrace(pc, bp); \
-} while (0)
-
 } // namespace __ubsan
 
 #endif // UBSAN_DIAG_H

Modified: compiler-rt/trunk/lib/ubsan/ubsan_handlers_cxx.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/ubsan_handlers_cxx.cc?rev=214245&r1=214244&r2=214245&view=diff
==============================================================================
--- compiler-rt/trunk/lib/ubsan/ubsan_handlers_cxx.cc (original)
+++ compiler-rt/trunk/lib/ubsan/ubsan_handlers_cxx.cc Tue Jul 29 18:22:41 2014
@@ -28,7 +28,7 @@ namespace __ubsan {
 
 static void HandleDynamicTypeCacheMiss(
     DynamicTypeCacheMissData *Data, ValueHandle Pointer, ValueHandle Hash,
-    bool Abort) {
+    bool Abort, uptr pc, uptr bp) {
   if (checkDynamicType((void*)Pointer, Data->TypeInfo, Hash))
     // Just a cache miss. The type matches after all.
     return;
@@ -60,16 +60,18 @@ static void HandleDynamicTypeCacheMiss(
       << MangledName(DTI.getSubobjectTypeName())
       << Range(Pointer, Pointer + sizeof(uptr), "vptr for %2 base class of %1");
 
-  MAYBE_PRINT_STACK_TRACE();
+  MaybePrintStackTrace(pc, bp);
   if (Abort)
     Die();
 }
 
 void __ubsan::__ubsan_handle_dynamic_type_cache_miss(
     DynamicTypeCacheMissData *Data, ValueHandle Pointer, ValueHandle Hash) {
-  HandleDynamicTypeCacheMiss(Data, Pointer, Hash, false);
+  GET_CALLER_PC_BP;
+  HandleDynamicTypeCacheMiss(Data, Pointer, Hash, false, pc, bp);
 }
 void __ubsan::__ubsan_handle_dynamic_type_cache_miss_abort(
     DynamicTypeCacheMissData *Data, ValueHandle Pointer, ValueHandle Hash) {
-  HandleDynamicTypeCacheMiss(Data, Pointer, Hash, true);
+  GET_CALLER_PC_BP;
+  HandleDynamicTypeCacheMiss(Data, Pointer, Hash, true, pc, bp);
 }





More information about the llvm-commits mailing list