<div>Hi!</div><div><br></div><div>This patch is intended to fix the exception handling in case of realigned stack (see more details in recent discussion with mcrosier@ on r160002).</div><div><br></div><div>Before this change, the prologue and epilogue looks like this:</div>
<div>push %rbp</div><div>mov %rsp, %rbp</div><div>and $alignment %rsp   <--- align stack</div><div>push %reg1   <----- save regs on stack</div><div>push %reg2</div><div>sub $size %rsp</div><div><...></div><div>
add $size %rsp</div><div>pop %reg2  <------- restore regs</div><div>pop %reg1</div><div>mov %rbp, %rsp <--- restore rsp</div><div>pop %rbp</div><div><br></div><div>The problem is: the register values are incorrectly restored in exception handling - emiited call frame information gives offsets of registers from frame pointer (%rbp),</div>
<div>which is wrong, as their actual locations depend on the alignment result.</div><div><br></div><div>I suggest to modify the prologue in the following way:</div><div>push %rbp</div><div><div>mov %rsp, %rbp</div><div>push %reg1   <----- save regs on stack</div>
<div>push %reg2</div></div><div>and $alignment %rsp   <--- align stack</div><div><div>sub $size %rsp</div><div><...></div><div>mov %rbp, %rsp</div><div>sub $total_size_of_saved_regs, %rsp</div><div>pop %reg2  <------- restore regs</div>
<div>pop %reg1</div><div>pop %rbp</div></div><div><br></div><div>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).</div><div><br></div>Code review: <a href="http://codereview.appspot.com/6352105/">http://codereview.appspot.com/6352105/</a><br clear="all">
<div><br></div>-- <br><div>Alexey Samsonov, MSK</div><br>