Update ABIMacOSX_arm::PrepareTrivialCall to correctly align the
authorJason Molenda <jmolenda@apple.com>
Wed, 27 Sep 2017 02:49:18 +0000 (02:49 +0000)
committerJason Molenda <jmolenda@apple.com>
Wed, 27 Sep 2017 02:49:18 +0000 (02:49 +0000)
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.

llvm-svn: 314265

lldb/source/Plugins/ABI/MacOSX-arm/ABIMacOSX_arm.cpp

index fd5ee6e..1bd1c1b 100644 (file)
@@ -1413,10 +1413,6 @@ bool ABIMacOSX_arm::PrepareTrivialCall(Thread &thread, addr_t sp,
   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(Thread &thread, addr_t sp,
   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;