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/8932
Reviewed-by: Nicolas Capens <capn@google.com>
Tested-by: Nicolas Capens <capn@google.com>
diff --git a/third_party/LLVM/lib/Target/X86/X86FrameLowering.cpp b/third_party/LLVM/lib/Target/X86/X86FrameLowering.cpp
index d54f4ae..d751a32 100644
--- a/third_party/LLVM/lib/Target/X86/X86FrameLowering.cpp
+++ b/third_party/LLVM/lib/Target/X86/X86FrameLowering.cpp
@@ -850,12 +850,24 @@
.setMIFlag(MachineInstr::FrameSetup);
}
- BuildMI(MBB, MBBI, DL,
- TII.get(Is64Bit ? X86::W64ALLOCA : X86::CALLpcrel32))
- .addExternalSymbol(StackProbeSymbol)
- .addReg(StackPtr, RegState::Define | RegState::Implicit)
- .addReg(X86::EFLAGS, RegState::Define | RegState::Implicit)
- .setMIFlag(MachineInstr::FrameSetup);
+ if (Is64Bit && MF.getTarget().getCodeModel() == CodeModel::Large) {
+ // For the large code model, we have to call through a register. Use R11,
+ // as it is unused and clobbered by all probe functions.
+ BuildMI(MBB, MBBI, DL, TII.get(X86::MOV64ri), X86::R11)
+ .addExternalSymbol(StackProbeSymbol);
+ 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.
// FIXME: %rax preserves the offset and should be available.