[PATCH] D46004: Be more accurate when calculating the previous instruction address on Arm.

Igor Kudrin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 24 04:58:23 PDT 2018


ikudrin created this revision.
ikudrin added a reviewer: kcc.
ikudrin added a project: Sanitizers.
Herald added subscribers: chrib, kristof.beyls, kubamracek.
Herald added a reviewer: javed.absar.

Right now, we report backtraces with uneven addresses on Arm32 and Arm64.


Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D46004

Files:
  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
@@ -75,10 +75,11 @@
 ALWAYS_INLINE
 uptr StackTrace::GetPreviousInstructionPc(uptr pc) {
 #if defined(__arm__)
-  // Cancel Thumb bit.
-  pc = pc & (~1);
-#endif
-#if defined(__powerpc__) || defined(__powerpc64__)
+  // T32 (Thumb) branch instructions might be 16 or 32 bit long,
+  // so we return (pc-2) in that case in order to be safe.
+  // For A32 mode we return (pc-4) because all instructions are 32 bit long.
+  return (pc - 3) & (~1);
+#elif defined(__powerpc__) || defined(__powerpc64__) || defined(__aarch64__)
   // PCs are always 4 byte aligned.
   return pc - 4;
 #elif defined(__sparc__) || defined(__mips__)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D46004.143710.patch
Type: text/x-patch
Size: 840 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180424/b99888dd/attachment.bin>


More information about the llvm-commits mailing list