[Lldb-commits] [lldb] r314265 - Update ABIMacOSX_arm::PrepareTrivialCall to correctly align the

Jason Molenda via lldb-commits lldb-commits at lists.llvm.org
Tue Sep 26 19:49:18 PDT 2017

Author: jmolenda
Date: Tue Sep 26 19:49:18 2017
New Revision: 314265

URL: http://llvm.org/viewvc/llvm-project?rev=314265&view=rev
Update ABIMacOSX_arm::PrepareTrivialCall to correctly align the
stack pointer for apple's armv7 ABI.  When in a frameless function
or in a prologue/epilogue where sp wasn't properly aligned, we could
try to make function calls with an unaligned sp; the expression
would crash.


Modified: lldb/trunk/source/Plugins/ABI/MacOSX-arm/ABIMacOSX_arm.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ABI/MacOSX-arm/ABIMacOSX_arm.cpp?rev=314265&r1=314264&r2=314265&view=diff
--- lldb/trunk/source/Plugins/ABI/MacOSX-arm/ABIMacOSX_arm.cpp (original)
+++ lldb/trunk/source/Plugins/ABI/MacOSX-arm/ABIMacOSX_arm.cpp Tue Sep 26 19:49:18 2017
@@ -1413,10 +1413,6 @@ bool ABIMacOSX_arm::PrepareTrivialCall(T
   if (!reg_ctx->WriteRegisterFromUnsigned(ra_reg_num, return_addr))
     return false;
-  // Set "sp" to the requested value
-  if (!reg_ctx->WriteRegisterFromUnsigned(sp_reg_num, sp))
-    return false;
   // If bit zero or 1 is set, this must be a thumb function, no need to figure
   // this out from the symbols.
   so_addr.SetLoadAddress(function_addr, target_sp.get());
@@ -1441,6 +1437,11 @@ bool ABIMacOSX_arm::PrepareTrivialCall(T
   function_addr &=
       ~1ull; // clear bit zero since the CPSR will take care of the mode for us
+  // Update the sp - stack pointer - to be aligned to 16-bytes
+  sp &= ~(0xfull);
+  if (!reg_ctx->WriteRegisterFromUnsigned(sp_reg_num, sp))
+    return false;
   // Set "pc" to the address requested
   if (!reg_ctx->WriteRegisterFromUnsigned(pc_reg_num, function_addr))
     return false;

More information about the lldb-commits mailing list