[llvm-commits] PATCH: Change X86 function prologue/epilogue in case the stack is realigned

Alexey Samsonov samsonov at google.com
Thu Jul 12 09:02:56 PDT 2012


Hi!

This patch is intended to fix the exception handling in case of realigned
stack (see more details in recent discussion with mcrosier@ on r160002).

Before this change, the prologue and epilogue looks like this:
push %rbp
mov %rsp, %rbp
and $alignment %rsp   <--- align stack
push %reg1   <----- save regs on stack
push %reg2
sub $size %rsp
<...>
add $size %rsp
pop %reg2  <------- restore regs
pop %reg1
mov %rbp, %rsp <--- restore rsp
pop %rbp

The problem is: the register values are incorrectly restored in exception
handling - emiited call frame information gives offsets of registers from
frame pointer (%rbp),
which is wrong, as their actual locations depend on the alignment result.

I suggest to modify the prologue in the following way:
push %rbp
mov %rsp, %rbp
push %reg1   <----- save regs on stack
push %reg2
and $alignment %rsp   <--- align stack
sub $size %rsp
<...>
mov %rbp, %rsp
sub $total_size_of_saved_regs, %rsp
pop %reg2  <------- restore regs
pop %reg1
pop %rbp

In this way the offsets from %rbp will be valid, and the EH won't be
broken. (you may also see the emiited asm in the tests).

Code review: http://codereview.appspot.com/6352105/

-- 
Alexey Samsonov, MSK
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20120712/d69ad3d2/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: zdiff.pr11468
Type: application/octet-stream
Size: 8050 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20120712/d69ad3d2/attachment.obj>


More information about the llvm-commits mailing list