Commit ebf1e015 by Nicolas Capens

Fix calling stack probe through a register on Win64.

The __chkstk function can be at a greater than 4 GiB offset from our generated function. Fix derived from https://reviews.llvm.org/D7267 Change-Id: Ife87dcd42541676828c4a0ca77dcded6649ce278 Reviewed-on: https://swiftshader-review.googlesource.com/8932Reviewed-by: 's avatarNicolas Capens <capn@google.com> Tested-by: 's avatarNicolas Capens <capn@google.com>
parent 2d03c8d2
...@@ -850,12 +850,24 @@ void X86FrameLowering::emitPrologue(MachineFunction &MF) const { ...@@ -850,12 +850,24 @@ void X86FrameLowering::emitPrologue(MachineFunction &MF) const {
.setMIFlag(MachineInstr::FrameSetup); .setMIFlag(MachineInstr::FrameSetup);
} }
BuildMI(MBB, MBBI, DL, if (Is64Bit && MF.getTarget().getCodeModel() == CodeModel::Large) {
TII.get(Is64Bit ? X86::W64ALLOCA : X86::CALLpcrel32)) // For the large code model, we have to call through a register. Use R11,
.addExternalSymbol(StackProbeSymbol) // as it is unused and clobbered by all probe functions.
.addReg(StackPtr, RegState::Define | RegState::Implicit) BuildMI(MBB, MBBI, DL, TII.get(X86::MOV64ri), X86::R11)
.addReg(X86::EFLAGS, RegState::Define | RegState::Implicit) .addExternalSymbol(StackProbeSymbol);
.setMIFlag(MachineInstr::FrameSetup); BuildMI(MBB, MBBI, DL, TII.get(X86::CALL64r))
.addReg(X86::R11)
.addReg(StackPtr, RegState::Define | RegState::Implicit)
.addReg(X86::EFLAGS, RegState::Define | RegState::Implicit)
.setMIFlag(MachineInstr::FrameSetup);
} else {
BuildMI(MBB, MBBI, DL,
TII.get(STI.is64Bit() ? X86::CALL64pcrel32 : X86::CALLpcrel32))
.addExternalSymbol(StackProbeSymbol)
.addReg(StackPtr, RegState::Define | RegState::Implicit)
.addReg(X86::EFLAGS, RegState::Define | RegState::Implicit)
.setMIFlag(MachineInstr::FrameSetup);
}
// MSVC x64's __chkstk needs to adjust %rsp. // MSVC x64's __chkstk needs to adjust %rsp.
// FIXME: %rax preserves the offset and should be available. // FIXME: %rax preserves the offset and should be available.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment