mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-31 20:51:52 +01:00
[WinEH] Insert the catchpad return before CSR restoration
x64 catchpads use rax to inform the unwinder where control should go next. However, we must initialize rax before the epilogue sequence so as to not perturb the unwinder. llvm-svn: 249910
This commit is contained in:
parent
8f98b3dd2c
commit
f5bab94d5d
@ -1058,6 +1058,7 @@ void X86FrameLowering::emitEpilogue(MachineFunction &MF,
|
||||
bool NeedsWinCFI =
|
||||
IsWin64Prologue && MF.getFunction()->needsUnwindTableEntry();
|
||||
bool IsFunclet = isFuncletReturnInstr(MBBI);
|
||||
MachineBasicBlock *RestoreMBB = nullptr;
|
||||
|
||||
// Get the number of bytes to allocate from the FrameInfo.
|
||||
uint64_t StackSize = MFI->getStackSize();
|
||||
@ -1082,7 +1083,7 @@ void X86FrameLowering::emitEpilogue(MachineFunction &MF,
|
||||
}
|
||||
|
||||
// For 32-bit, create a new block for the restore code.
|
||||
MachineBasicBlock *RestoreMBB = TargetMBB;
|
||||
RestoreMBB = TargetMBB;
|
||||
if (STI.is32Bit()) {
|
||||
RestoreMBB = MF.CreateMachineBasicBlock(MBB.getBasicBlock());
|
||||
MF.insert(TargetMBB, RestoreMBB);
|
||||
@ -1092,23 +1093,6 @@ void X86FrameLowering::emitEpilogue(MachineFunction &MF,
|
||||
MBBI->getOperand(0).setMBB(RestoreMBB);
|
||||
}
|
||||
|
||||
// Fill EAX/RAX with the address of the target block.
|
||||
unsigned ReturnReg = STI.is64Bit() ? X86::RAX : X86::EAX;
|
||||
if (STI.is64Bit()) {
|
||||
// LEA64r RestoreMBB(%rip), %rax
|
||||
BuildMI(MBB, MBBI, DL, TII.get(X86::LEA64r), ReturnReg)
|
||||
.addReg(X86::RIP)
|
||||
.addImm(0)
|
||||
.addReg(0)
|
||||
.addMBB(RestoreMBB)
|
||||
.addReg(0);
|
||||
} else {
|
||||
// MOV32ri $RestoreMBB, %eax
|
||||
BuildMI(MBB, MBBI, DL, TII.get(X86::MOV32ri))
|
||||
.addReg(ReturnReg)
|
||||
.addMBB(RestoreMBB);
|
||||
}
|
||||
|
||||
// Pop EBP.
|
||||
BuildMI(MBB, MBBI, DL, TII.get(Is64Bit ? X86::POP64r : X86::POP32r),
|
||||
MachineFramePtr)
|
||||
@ -1161,6 +1145,25 @@ void X86FrameLowering::emitEpilogue(MachineFunction &MF,
|
||||
}
|
||||
MachineBasicBlock::iterator FirstCSPop = MBBI;
|
||||
|
||||
if (RestoreMBB) {
|
||||
// Fill EAX/RAX with the address of the target block.
|
||||
unsigned ReturnReg = STI.is64Bit() ? X86::RAX : X86::EAX;
|
||||
if (STI.is64Bit()) {
|
||||
// LEA64r RestoreMBB(%rip), %rax
|
||||
BuildMI(MBB, FirstCSPop, DL, TII.get(X86::LEA64r), ReturnReg)
|
||||
.addReg(X86::RIP)
|
||||
.addImm(0)
|
||||
.addReg(0)
|
||||
.addMBB(RestoreMBB)
|
||||
.addReg(0);
|
||||
} else {
|
||||
// MOV32ri $RestoreMBB, %eax
|
||||
BuildMI(MBB, FirstCSPop, DL, TII.get(X86::MOV32ri))
|
||||
.addReg(ReturnReg)
|
||||
.addMBB(RestoreMBB);
|
||||
}
|
||||
}
|
||||
|
||||
if (MBBI != MBB.end())
|
||||
DL = MBBI->getDebugLoc();
|
||||
|
||||
|
@ -123,6 +123,8 @@ catchendblock: ; preds = %catch,
|
||||
; X64: movq %rdx, 16(%rsp)
|
||||
; X64: pushq %rbp
|
||||
; X64: .seh_pushreg 5
|
||||
; X64: pushq %rsi
|
||||
; X64: .seh_pushreg 6
|
||||
; X64: subq $32, %rsp
|
||||
; X64: .seh_stackalloc 32
|
||||
; X64: leaq 32(%rdx), %rbp
|
||||
@ -131,6 +133,7 @@ catchendblock: ; preds = %catch,
|
||||
; X64: callq f
|
||||
; X64: leaq [[contbb]](%rip), %rax
|
||||
; X64: addq $32, %rsp
|
||||
; X64: popq %rsi
|
||||
; X64: popq %rbp
|
||||
; X64: retq
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user