[llvm] [AArch64] Codegen for AArch64 Return Address Signing Hardening (PR #176187)

Daniil Kovalev via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 9 06:08:39 PST 2026


================
@@ -276,5 +285,86 @@ bool AArch64PointerAuth::runOnMachineFunction(MachineFunction &MF) {
     Modified = true;
   }
 
+  Modified |= emitSignReturnAddressHardening(MF);
+
+  return Modified;
+}
+
+bool AArch64PointerAuth::emitSignReturnAddressHardening(MachineFunction &MF) {
+  const auto *FI = MF.getInfo<AArch64FunctionInfo>();
+  assert(FI && "FI can't be null");
+  if (!FI->shouldSignReturnAddress(MF) || !FI->shouldHardenSignReturnAddress())
+    return false;
+  assert(Subtarget && "Subtarget must be initialized");
+
+  RegScavenger RS;
+  bool Modified = false;
+  for (MachineBasicBlock &MBB : MF) {
+    if (!MBB.isReturnBlock())
+      continue;
+
+    MachineBasicBlock::iterator MBBI = MBB.getFirstTerminator();
+
+    if (MBBI == MBB.end() || MBBI->getOpcode() != AArch64::RET)
+      continue;
+
+    RS.enterBasicBlockEnd(*MBBI->getParent());
+    Register XReg = RS.scavengeRegisterBackwards(
+        AArch64::GPR64RegClass, MBBI,
+        /*RestoreAfter=*/false, /*SPAdj=*/0, /*AllowSpill=*/false);
+    if (XReg == AArch64::NoRegister)
+      // Couldn't find a free register to use for the hardening. Skip.
----------------
kovdan01 wrote:

It looks like that this code path is not covered by a test (please refer me to a one if I'm wrong). Would it be possible to implement a corresponding test or is this case just so unrealistic that we can't even reliably test that?

https://github.com/llvm/llvm-project/pull/176187


More information about the llvm-commits mailing list