Skip to content

[PowerPC] Fix saving of Link Register when using ROP Protect #123101

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions llvm/lib/Target/PowerPC/PPCFrameLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ void PPCFrameLowering::emitPrologue(MachineFunction &MF,
bool HasFP = hasFP(MF);
bool HasBP = RegInfo->hasBasePointer(MF);
bool HasRedZone = isPPC64 || !isSVR4ABI;
bool HasROPProtect = Subtarget.hasROPProtect();
const bool HasROPProtect = Subtarget.hasROPProtect();
bool HasPrivileged = Subtarget.hasPrivileged();

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

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

// Save the LR now.
if (!HasSTUX && MustSaveLR && !HasFastMFLR && isInt<16>(FrameSize + LROffset))
if (!HasSTUX && MustSaveLR && !HasFastMFLR &&
isInt<16>(FrameSize + LROffset) && !HasROPProtect)
SaveLR(LROffset + FrameSize);

// Add Call Frame Information for the instructions we generated above.
Expand Down
Loading
Loading