From da6dcc5d926cb7481ff28b127c5e67da4501a99c Mon Sep 17 00:00:00 2001 From: Reid Kleckner Date: Thu, 10 Sep 2015 22:00:02 +0000 Subject: [WinEH] Push and pop EBP for 32-bit funclets The Win32 EH runtime caller does not preserve EBP, even though it does preserve the CSRs (EBX, ESI, EDI) for us. The result was that each finally funclet call would leave the frame pointer off by 12 bytes. llvm-svn: 247348 --- llvm/lib/Target/X86/X86FrameLowering.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'llvm/lib/Target') diff --git a/llvm/lib/Target/X86/X86FrameLowering.cpp b/llvm/lib/Target/X86/X86FrameLowering.cpp index 032e003fe47..05ab69cb870 100644 --- a/llvm/lib/Target/X86/X86FrameLowering.cpp +++ b/llvm/lib/Target/X86/X86FrameLowering.cpp @@ -702,6 +702,11 @@ void X86FrameLowering::emitPrologue(MachineFunction &MF, // Set up the FramePtr and BasePtr physical registers using the address // passed as EBP or RDX by the MSVC EH runtime. if (STI.is32Bit()) { + // PUSH32r %ebp + BuildMI(MBB, MBBI, DL, TII.get(X86::PUSH32r)) + .addReg(MachineFramePtr, RegState::Kill) + .setMIFlag(MachineInstr::FrameSetup); + // Reset EBP / ESI to something good. MBBI = restoreWin32EHFrameAndBasePtr(MBB, MBBI, DL); } else { // FIXME: Add SEH directives. @@ -715,7 +720,7 @@ void X86FrameLowering::emitPrologue(MachineFunction &MF, .addReg(RDX) .setMIFlag(MachineInstr::FrameSetup); // PUSH64r %rbp - BuildMI(MBB, MBBI, DL, TII.get(Is64Bit ? X86::PUSH64r : X86::PUSH32r)) + BuildMI(MBB, MBBI, DL, TII.get(X86::PUSH64r)) .addReg(MachineFramePtr, RegState::Kill) .setMIFlag(MachineInstr::FrameSetup); // MOV64rr %rdx, %rbp @@ -1066,13 +1071,11 @@ void X86FrameLowering::emitEpilogue(MachineFunction &MF, if (isFuncletReturnInstr(MBBI)) { NumBytes = MFI->getMaxCallFrameSize(); + assert(hasFP(MF) && "win64 EH funclets without FP not yet implemented"); - if (Is64Bit) { - assert(hasFP(MF) && "win64 EH funclets without FP not yet implemented"); - // POP64r %rbp - BuildMI(MBB, MBBI, DL, TII.get(Is64Bit ? X86::POP64r : X86::POP32r), - MachineFramePtr); - } + // Pop EBP. + BuildMI(MBB, MBBI, DL, TII.get(Is64Bit ? X86::POP64r : X86::POP32r), + MachineFramePtr); } else if (hasFP(MF)) { // Calculate required stack adjustment. uint64_t FrameSize = StackSize - SlotSize; -- cgit v1.2.3