Skip to content

Commit 340706f

Browse files
[PowerPC] Fix saving of Link Register when using ROP Protect (#123101)
An optimization was added that tries to move the uses of the mflr instruction away from the instruction itself. However, this doesn't work when we are using the hashst instruction because that instruction needs to be run before the stack frame is obtained. This patch disables moving instructions away from the mflr in the case where ROP protection is being used. --------- Co-authored-by: Lei Huang <[email protected]>
1 parent 5895932 commit 340706f

File tree

3 files changed

+348
-345
lines changed

3 files changed

+348
-345
lines changed

llvm/lib/Target/PowerPC/PPCFrameLowering.cpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,7 @@ void PPCFrameLowering::emitPrologue(MachineFunction &MF,
646646
bool HasFP = hasFP(MF);
647647
bool HasBP = RegInfo->hasBasePointer(MF);
648648
bool HasRedZone = isPPC64 || !isSVR4ABI;
649-
bool HasROPProtect = Subtarget.hasROPProtect();
649+
const bool HasROPProtect = Subtarget.hasROPProtect();
650650
bool HasPrivileged = Subtarget.hasPrivileged();
651651

652652
Register SPReg = isPPC64 ? PPC::X1 : PPC::R1;
@@ -908,8 +908,10 @@ void PPCFrameLowering::emitPrologue(MachineFunction &MF,
908908
// in ScratchReg.
909909
// If the offset can not be encoded into the store instruction, we also have
910910
// to save LR here.
911+
// If we are using ROP Protection we need to save the LR here as we cannot
912+
// move the hashst instruction past the point where we get the stack frame.
911913
if (MustSaveLR && !HasFastMFLR &&
912-
(HasSTUX || !isInt<16>(FrameSize + LROffset)))
914+
(HasSTUX || !isInt<16>(FrameSize + LROffset) || HasROPProtect))
913915
SaveLR(LROffset);
914916

915917
// If FrameSize <= TLI.getStackProbeSize(MF), as POWER ABI requires backchain
@@ -1100,7 +1102,8 @@ void PPCFrameLowering::emitPrologue(MachineFunction &MF,
11001102
}
11011103

11021104
// Save the LR now.
1103-
if (!HasSTUX && MustSaveLR && !HasFastMFLR && isInt<16>(FrameSize + LROffset))
1105+
if (!HasSTUX && MustSaveLR && !HasFastMFLR &&
1106+
isInt<16>(FrameSize + LROffset) && !HasROPProtect)
11041107
SaveLR(LROffset + FrameSize);
11051108

11061109
// Add Call Frame Information for the instructions we generated above.

0 commit comments

Comments
 (0)