https://github.com/bgergely0 updated 
https://github.com/llvm/llvm-project/pull/164622

From e0a245ef4263f7b4576ae4365e4f7cf877ef3394 Mon Sep 17 00:00:00 2001
From: Gergely Balint <[email protected]>
Date: Wed, 22 Oct 2025 12:44:37 +0000
Subject: [PATCH 1/6] [BOLT][NFC] Rename Pointer Auth DWARF rewriter passes

Original names were "working titles". After initial patches are merged,
I'd like to rename these passes to names that reflect their intent
better and show their relationship to each other:

InsertNegateRAStatePass renamed to PointerAuthCFIFixup,
MarkRAStates renamed to PointerAuthCFIAnalyzer.
---
 bolt/docs/PacRetDesign.md                     | 23 +++++++--------
 ...arkRAStates.h => PointerAuthCFIAnalyzer.h} | 14 +++++-----
 ...ateRAStatePass.h => PointerAuthCFIFixup.h} | 14 +++++-----
 bolt/lib/Core/Exceptions.cpp                  |  8 +++---
 bolt/lib/Passes/CMakeLists.txt                |  4 +--
 ...AStates.cpp => PointerAuthCFIAnalyzer.cpp} | 16 +++++------
 ...AStatePass.cpp => PointerAuthCFIFixup.cpp} | 28 +++++++++----------
 bolt/lib/Rewrite/BinaryPassManager.cpp        |  8 +++---
 bolt/test/AArch64/negate-ra-state-incorrect.s |  2 +-
 bolt/test/AArch64/negate-ra-state.s           |  8 +++---
 bolt/test/AArch64/pacret-split-funcs.s        |  4 +--
 bolt/unittests/Passes/CMakeLists.txt          |  2 +-
 ...ateRAState.cpp => PointerAuthCFIFixup.cpp} |  6 ++--
 .../gn/secondary/bolt/lib/Passes/BUILD.gn     |  4 +--
 14 files changed, 71 insertions(+), 70 deletions(-)
 rename bolt/include/bolt/Passes/{MarkRAStates.h => PointerAuthCFIAnalyzer.h} 
(63%)
 rename bolt/include/bolt/Passes/{InsertNegateRAStatePass.h => 
PointerAuthCFIFixup.h} (84%)
 rename bolt/lib/Passes/{MarkRAStates.cpp => PointerAuthCFIAnalyzer.cpp} (91%)
 rename bolt/lib/Passes/{InsertNegateRAStatePass.cpp => 
PointerAuthCFIFixup.cpp} (91%)
 rename bolt/unittests/Passes/{InsertNegateRAState.cpp => 
PointerAuthCFIFixup.cpp} (98%)

diff --git a/bolt/docs/PacRetDesign.md b/bolt/docs/PacRetDesign.md
index 2e3cb7b91e0ce..d69b4e65be755 100644
--- a/bolt/docs/PacRetDesign.md
+++ b/bolt/docs/PacRetDesign.md
@@ -104,9 +104,9 @@ negate-ra-state CFIs will become invalid during BasicBlock 
reordering.
 ## Solution design
 
 The implementation introduces two new passes:
-1. `MarkRAStatesPass`: assigns the RA state to each instruction based on the 
CFIs
-    in the input binary
-2. `InsertNegateRAStatePass`: reads those assigned instruction RA states after
+1. `PointerAuthCFIAnalyzer`: assigns the RA state to each instruction based on
+    the CFI in the input binary
+2. `PointerAuthCFIFixup`: reads those assigned instruction RA states after
     optimizations, and emits `DW_CFA_AARCH64_negate_ra_state` CFIs at the 
correct
     places: wherever there is a state change between two consecutive 
instructions
     in the layout order.
@@ -129,7 +129,7 @@ instruction.
 This special case is handled by adding an `initialRAState` bool to each 
BinaryFunction.
 If the `Offset` the CFI refers to is zero, we don't store an annotation, but 
set
 the `initialRAState` in `FillCFIInfoFor`. This information is then used in
-`MarkRAStates`.
+`PointerAuthCFIAnalyzer`.
 
 ### Binaries without DWARF info
 
@@ -146,7 +146,7 @@ In summary:
 - pointer auth is used, and we have DWARF CFIs: passes run, and rewrite the
   negate-ra-state CFI.
 
-### MarkRAStates pass
+### PointerAuthCFIAnalyzer pass
 
 This pass runs before optimizations reorder anything.
 
@@ -173,9 +173,9 @@ what we have before the pass, and after it.
 | autiasp                       | negate-ra-state | signed   |
 | ret                           |                 | unsigned |
 
-##### Error handling in MarkRAState Pass:
+##### Error handling in PointerAuthCFIAnalyzer pass:
 
-Whenever the MarkRAStates pass finds inconsistencies in the current
+Whenever the PointerAuthCFIAnalyzer pass finds inconsistencies in the current
 BinaryFunction, it marks the function as ignored using `BF.setIgnored()`. BOLT
 will not optimize this function but will emit it unchanged in the original 
section
 (`.bolt.org.text`).
@@ -188,16 +188,17 @@ The inconsistencies are as follows:
 Users will be informed about the number of ignored functions in the pass, the
 exact functions ignored, and the found inconsistency.
 
-### InsertNegateRAStatePass
+### PointerAuthCFIFixup
 
-This pass runs after optimizations. It performns the _inverse_ of MarkRAState 
pa s:
+This pass runs after optimizations. It performns the _inverse_ of 
PointerAuthCFIAnalyzer
+pass:
 1. it reads the RA state annotations attached to the instructions, and
 2. whenever the state changes, it adds a PseudoInstruction that holds an
    OpNegateRAState CFI.
 
 ##### Covering newly generated instructions:
 
-Some BOLT passes can add new Instructions. In InsertNegateRAStatePass, we have
+Some BOLT passes can add new Instructions. In PointerAuthCFIFixup, we have
 to know what RA state these have.
 
 > [!important]
@@ -224,7 +225,7 @@ freely. The only special case is function splitting. When a 
function is split,
 the split part becomes a new function in the emitted binary. For unwinding to
 work, it needs to "replay" all CFIs that lead up to the split point. BOLT does
 this for other CFIs. As negate-ra-state is not read (only stored as an 
Annotation),
-we have to do this manually in InsertNegateRAStatePass. Here, if the split part
+we have to do this manually in PointerAuthCFIFixup. Here, if the split part
 starts with an instruction that has Signed RA state, we add a negate-ra-state 
CFI
 to indicate this.
 
diff --git a/bolt/include/bolt/Passes/MarkRAStates.h 
b/bolt/include/bolt/Passes/PointerAuthCFIAnalyzer.h
similarity index 63%
rename from bolt/include/bolt/Passes/MarkRAStates.h
rename to bolt/include/bolt/Passes/PointerAuthCFIAnalyzer.h
index 202f1dda2aad8..54da398f0b2b3 100644
--- a/bolt/include/bolt/Passes/MarkRAStates.h
+++ b/bolt/include/bolt/Passes/PointerAuthCFIAnalyzer.h
@@ -1,4 +1,4 @@
-//===- bolt/Passes/MarkRAStates.cpp ---------------------------------===//
+//===- bolt/Passes/PointerAuthCFIAnalyzer.h 
-------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,11 +6,11 @@
 //
 
//===----------------------------------------------------------------------===//
 //
-// This file implements the MarkRAStates class.
+// This file implements the PointerAuthCFIAnalyzer class.
 //
 
//===----------------------------------------------------------------------===//
-#ifndef BOLT_PASSES_MARK_RA_STATES
-#define BOLT_PASSES_MARK_RA_STATES
+#ifndef BOLT_PASSES_POINTER_AUTH_CFI_ANALYZER
+#define BOLT_PASSES_POINTER_AUTH_CFI_ANALYZER
 
 #include "bolt/Passes/BinaryPasses.h"
 #include <mutex>
@@ -18,15 +18,15 @@
 namespace llvm {
 namespace bolt {
 
-class MarkRAStates : public BinaryFunctionPass {
+class PointerAuthCFIAnalyzer : public BinaryFunctionPass {
   // setIgnored() is not thread-safe, but the pass is running on functions in
   // parallel.
   std::mutex IgnoreMutex;
 
 public:
-  explicit MarkRAStates() : BinaryFunctionPass(false) {}
+  explicit PointerAuthCFIAnalyzer() : BinaryFunctionPass(false) {}
 
-  const char *getName() const override { return "mark-ra-states"; }
+  const char *getName() const override { return "pointer-auth-cfi-analyzer"; }
 
   /// Pass entry point
   Error runOnFunctions(BinaryContext &BC) override;
diff --git a/bolt/include/bolt/Passes/InsertNegateRAStatePass.h 
b/bolt/include/bolt/Passes/PointerAuthCFIFixup.h
similarity index 84%
rename from bolt/include/bolt/Passes/InsertNegateRAStatePass.h
rename to bolt/include/bolt/Passes/PointerAuthCFIFixup.h
index 3f003af96162d..7ec0fc677ce3f 100644
--- a/bolt/include/bolt/Passes/InsertNegateRAStatePass.h
+++ b/bolt/include/bolt/Passes/PointerAuthCFIFixup.h
@@ -1,4 +1,4 @@
-//===- bolt/Passes/InsertNegateRAStatePass.h 
------------------------------===//
+//===- bolt/Passes/PointerAuthCFIFixup.h 
----------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,22 +6,22 @@
 //
 
//===----------------------------------------------------------------------===//
 //
-// This file implements the InsertNegateRAStatePass class.
+// This file implements the PointerAuthCFIFixup class.
 //
 
//===----------------------------------------------------------------------===//
-#ifndef BOLT_PASSES_INSERT_NEGATE_RA_STATE_PASS
-#define BOLT_PASSES_INSERT_NEGATE_RA_STATE_PASS
+#ifndef BOLT_PASSES_POINTER_AUTH_CFI_FIXUP
+#define BOLT_PASSES_POINTER_AUTH_CFI_FIXUP
 
 #include "bolt/Passes/BinaryPasses.h"
 
 namespace llvm {
 namespace bolt {
 
-class InsertNegateRAState : public BinaryFunctionPass {
+class PointerAuthCFIFixup : public BinaryFunctionPass {
 public:
-  explicit InsertNegateRAState() : BinaryFunctionPass(false) {}
+  explicit PointerAuthCFIFixup() : BinaryFunctionPass(false) {}
 
-  const char *getName() const override { return "insert-negate-ra-state-pass"; 
}
+  const char *getName() const override { return "pointer-auth-cfi-fixup"; }
 
   /// Pass entry point
   Error runOnFunctions(BinaryContext &BC) override;
diff --git a/bolt/lib/Core/Exceptions.cpp b/bolt/lib/Core/Exceptions.cpp
index 27656c7b3cadf..9c33a7c648dab 100644
--- a/bolt/lib/Core/Exceptions.cpp
+++ b/bolt/lib/Core/Exceptions.cpp
@@ -572,7 +572,7 @@ bool CFIReaderWriter::fillCFIInfoFor(BinaryFunction 
&Function) const {
       if (Function.getBinaryContext().isAArch64()) {
         // Support for pointer authentication:
         // We need to annotate instructions that modify the RA State, to work
-        // out the state of each instruction in MarkRAStates Pass.
+        // out the state of each instruction in PointerAuthCFIAnalyzer Pass.
         if (Offset != 0)
           Function.setInstModifiesRAState(DW_CFA_remember_state, Offset);
       }
@@ -583,7 +583,7 @@ bool CFIReaderWriter::fillCFIInfoFor(BinaryFunction 
&Function) const {
       if (Function.getBinaryContext().isAArch64()) {
         // Support for pointer authentication:
         // We need to annotate instructions that modify the RA State, to work
-        // out the state of each instruction in MarkRAStates Pass.
+        // out the state of each instruction in PointerAuthCFIAnalyzer Pass.
         if (Offset != 0)
           Function.setInstModifiesRAState(DW_CFA_restore_state, Offset);
       }
@@ -652,7 +652,7 @@ bool CFIReaderWriter::fillCFIInfoFor(BinaryFunction 
&Function) const {
         // BasicBlocks, which changes during optimizations. Instead of adding
         // OpNegateRAState CFIs, an annotation is added to the instruction, to
         // mark that the instruction modifies the RA State. The actual state 
for
-        // instructions are worked out in MarkRAStates based on these
+        // instructions are worked out in PointerAuthCFIAnalyzer based on these
         // annotations.
         if (Offset != 0)
           Function.setInstModifiesRAState(DW_CFA_AARCH64_negate_ra_state,
@@ -660,7 +660,7 @@ bool CFIReaderWriter::fillCFIInfoFor(BinaryFunction 
&Function) const {
         else
           // We cannot Annotate an instruction at Offset == 0.
           // Instead, we save the initial (Signed) state, and push it to
-          // MarkRAStates' RAStateStack.
+          // PointerAuthCFIAnalyzer's RAStateStack.
           Function.setInitialRAState(true);
         break;
       }
diff --git a/bolt/lib/Passes/CMakeLists.txt b/bolt/lib/Passes/CMakeLists.txt
index 3197e62faad21..ec012f05cc498 100644
--- a/bolt/lib/Passes/CMakeLists.txt
+++ b/bolt/lib/Passes/CMakeLists.txt
@@ -17,18 +17,18 @@ add_llvm_library(LLVMBOLTPasses
   IdenticalCodeFolding.cpp
   IndirectCallPromotion.cpp
   Inliner.cpp
-  InsertNegateRAStatePass.cpp
   Instrumentation.cpp
   JTFootprintReduction.cpp
   LongJmp.cpp
   LoopInversionPass.cpp
   LivenessAnalysis.cpp
   MCF.cpp
-  MarkRAStates.cpp
   PatchEntries.cpp
   PAuthGadgetScanner.cpp
   PettisAndHansen.cpp
   PLTCall.cpp
+  PointerAuthCFIAnalyzer.cpp
+  PointerAuthCFIFixup.cpp
   ProfileQualityStats.cpp
   RegAnalysis.cpp
   RegReAssign.cpp
diff --git a/bolt/lib/Passes/MarkRAStates.cpp 
b/bolt/lib/Passes/PointerAuthCFIAnalyzer.cpp
similarity index 91%
rename from bolt/lib/Passes/MarkRAStates.cpp
rename to bolt/lib/Passes/PointerAuthCFIAnalyzer.cpp
index 51075be0e1ac2..91030544d2b88 100644
--- a/bolt/lib/Passes/MarkRAStates.cpp
+++ b/bolt/lib/Passes/PointerAuthCFIAnalyzer.cpp
@@ -1,4 +1,4 @@
-//===- bolt/Passes/MarkRAStates.cpp ---------------------------------===//
+//===- bolt/Passes/PointerAuthCFIAnalyzer.cpp 
-----------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,7 +6,7 @@
 //
 
//===----------------------------------------------------------------------===//
 //
-// This file implements the MarkRAStates class.
+// This file implements the PointerAuthCFIAnalyzer class.
 // Three CFIs have an influence on the RA State of an instruction:
 // - NegateRAState flips the RA State,
 // - RememberState pushes the RA State to a stack,
@@ -16,10 +16,10 @@
 // the RA State of each instruction, and save it as new MCAnnotations. The new
 // annotations are Signing, Signed, Authenticating and Unsigned. After
 // optimizations, .cfi_negate_ra_state CFIs are added to the places where the
-// state changes in InsertNegateRAStatePass.
+// state changes in PointerAuthCFIFixup.
 //
 
//===----------------------------------------------------------------------===//
-#include "bolt/Passes/MarkRAStates.h"
+#include "bolt/Passes/PointerAuthCFIAnalyzer.h"
 #include "bolt/Core/BinaryFunction.h"
 #include "bolt/Core/ParallelUtilities.h"
 #include <cstdlib>
@@ -31,7 +31,7 @@ using namespace llvm;
 namespace llvm {
 namespace bolt {
 
-bool MarkRAStates::runOnFunction(BinaryFunction &BF) {
+bool PointerAuthCFIAnalyzer::runOnFunction(BinaryFunction &BF) {
 
   BinaryContext &BC = BF.getBinaryContext();
 
@@ -110,7 +110,7 @@ bool MarkRAStates::runOnFunction(BinaryFunction &BF) {
   return true;
 }
 
-Error MarkRAStates::runOnFunctions(BinaryContext &BC) {
+Error PointerAuthCFIAnalyzer::runOnFunctions(BinaryContext &BC) {
   std::atomic<uint64_t> FunctionsIgnored{0};
   ParallelUtilities::WorkFuncTy WorkFun = [&](BinaryFunction &BF) {
     if (!runOnFunction(BF)) {
@@ -132,8 +132,8 @@ Error MarkRAStates::runOnFunctions(BinaryContext &BC) {
 
   ParallelUtilities::runOnEachFunction(
       BC, ParallelUtilities::SchedulingPolicy::SP_INST_LINEAR, WorkFun,
-      SkipPredicate, "MarkRAStates");
-  BC.outs() << "BOLT-INFO: MarkRAStates ran on " << Total
+      SkipPredicate, "PointerAuthCFIAnalyzer");
+  BC.outs() << "BOLT-INFO: PointerAuthCFIAnalyzer ran on " << Total
             << " functions. Ignored " << FunctionsIgnored << " functions "
             << format("(%.2lf%%)", (100.0 * FunctionsIgnored) / Total)
             << " because of CFI inconsistencies\n";
diff --git a/bolt/lib/Passes/InsertNegateRAStatePass.cpp 
b/bolt/lib/Passes/PointerAuthCFIFixup.cpp
similarity index 91%
rename from bolt/lib/Passes/InsertNegateRAStatePass.cpp
rename to bolt/lib/Passes/PointerAuthCFIFixup.cpp
index 37004aae94937..aeef944553313 100644
--- a/bolt/lib/Passes/InsertNegateRAStatePass.cpp
+++ b/bolt/lib/Passes/PointerAuthCFIFixup.cpp
@@ -1,4 +1,4 @@
-//===- bolt/Passes/InsertNegateRAStatePass.cpp 
----------------------------===//
+//===- bolt/Passes/PointerAuthCFIFixup.cpp 
--------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,12 +6,12 @@
 //
 
//===----------------------------------------------------------------------===//
 //
-// This file implements the InsertNegateRAStatePass class. It inserts
+// This file implements the PointerAuthCFIFixup class. It inserts
 // OpNegateRAState CFIs to places where the state of two consecutive
 // instructions are different.
 //
 
//===----------------------------------------------------------------------===//
-#include "bolt/Passes/InsertNegateRAStatePass.h"
+#include "bolt/Passes/PointerAuthCFIFixup.h"
 #include "bolt/Core/BinaryFunction.h"
 #include "bolt/Core/ParallelUtilities.h"
 #include <cstdlib>
@@ -23,7 +23,7 @@ namespace bolt {
 
 static bool PassFailed = false;
 
-void InsertNegateRAState::runOnFunction(BinaryFunction &BF) {
+void PointerAuthCFIFixup::runOnFunction(BinaryFunction &BF) {
   if (PassFailed)
     return;
 
@@ -35,7 +35,7 @@ void InsertNegateRAState::runOnFunction(BinaryFunction &BF) {
   if (BF.getState() != BinaryFunction::State::CFG &&
       BF.getState() != BinaryFunction::State::CFG_Finalized) {
     BC.outs() << "BOLT-INFO: no CFG for " << BF.getPrintName()
-              << " in InsertNegateRAStatePass\n";
+              << " in PointerAuthCFIFixup\n";
     return;
   }
 
@@ -74,7 +74,7 @@ void InsertNegateRAState::runOnFunction(BinaryFunction &BF) {
   }
 }
 
-void InsertNegateRAState::inferUnknownStates(BinaryFunction &BF) {
+void PointerAuthCFIFixup::inferUnknownStates(BinaryFunction &BF) {
   BinaryContext &BC = BF.getBinaryContext();
 
   // Fill in missing RAStates in simple cases (inside BBs).
@@ -88,7 +88,7 @@ void InsertNegateRAState::inferUnknownStates(BinaryFunction 
&BF) {
   fillUnknownStubs(BF);
 }
 
-void InsertNegateRAState::coverFunctionFragmentStart(BinaryFunction &BF,
+void PointerAuthCFIFixup::coverFunctionFragmentStart(BinaryFunction &BF,
                                                      FunctionFragment &FF) {
   BinaryContext &BC = BF.getBinaryContext();
   if (FF.empty())
@@ -119,7 +119,7 @@ void 
InsertNegateRAState::coverFunctionFragmentStart(BinaryFunction &BF,
 }
 
 std::optional<bool>
-InsertNegateRAState::getFirstKnownRAState(BinaryContext &BC,
+PointerAuthCFIFixup::getFirstKnownRAState(BinaryContext &BC,
                                           BinaryBasicBlock &BB) {
   for (const MCInst &Inst : BB) {
     if (BC.MIB->isCFI(Inst))
@@ -131,7 +131,7 @@ InsertNegateRAState::getFirstKnownRAState(BinaryContext &BC,
   return std::nullopt;
 }
 
-void InsertNegateRAState::fillUnknownStateInBB(BinaryContext &BC,
+void PointerAuthCFIFixup::fillUnknownStateInBB(BinaryContext &BC,
                                                BinaryBasicBlock &BB) {
 
   auto First = BB.getFirstNonPseudo();
@@ -174,7 +174,7 @@ void 
InsertNegateRAState::fillUnknownStateInBB(BinaryContext &BC,
   }
 }
 
-bool InsertNegateRAState::isUnknownBlock(BinaryContext &BC,
+bool PointerAuthCFIFixup::isUnknownBlock(BinaryContext &BC,
                                          BinaryBasicBlock &BB) {
   for (const MCInst &Inst : BB) {
     if (BC.MIB->isCFI(Inst))
@@ -186,7 +186,7 @@ bool InsertNegateRAState::isUnknownBlock(BinaryContext &BC,
   return true;
 }
 
-void InsertNegateRAState::markUnknownBlock(BinaryContext &BC,
+void PointerAuthCFIFixup::markUnknownBlock(BinaryContext &BC,
                                            BinaryBasicBlock &BB, bool State) {
   // If we call this when an Instruction has either kRASigned or kRAUnsigned
   // annotation, setRASigned or setRAUnsigned would fail.
@@ -199,7 +199,7 @@ void InsertNegateRAState::markUnknownBlock(BinaryContext 
&BC,
   }
 }
 
-void InsertNegateRAState::fillUnknownStubs(BinaryFunction &BF) {
+void PointerAuthCFIFixup::fillUnknownStubs(BinaryFunction &BF) {
   BinaryContext &BC = BF.getBinaryContext();
   bool FirstIter = true;
   MCInst PrevInst;
@@ -242,7 +242,7 @@ void InsertNegateRAState::fillUnknownStubs(BinaryFunction 
&BF) {
   }
 }
 
-Error InsertNegateRAState::runOnFunctions(BinaryContext &BC) {
+Error PointerAuthCFIFixup::runOnFunctions(BinaryContext &BC) {
   std::atomic<uint64_t> FunctionsModified{0};
   ParallelUtilities::WorkFuncTy WorkFun = [&](BinaryFunction &BF) {
     FunctionsModified++;
@@ -259,7 +259,7 @@ Error InsertNegateRAState::runOnFunctions(BinaryContext 
&BC) {
 
   ParallelUtilities::runOnEachFunction(
       BC, ParallelUtilities::SchedulingPolicy::SP_INST_LINEAR, WorkFun,
-      SkipPredicate, "InsertNegateRAStatePass");
+      SkipPredicate, "PointerAuthCFIFixup");
 
   BC.outs() << "BOLT-INFO: rewritten pac-ret DWARF info in "
             << FunctionsModified << " out of " << 
BC.getBinaryFunctions().size()
diff --git a/bolt/lib/Rewrite/BinaryPassManager.cpp 
b/bolt/lib/Rewrite/BinaryPassManager.cpp
index 1a0f6d75d63e8..334643426a802 100644
--- a/bolt/lib/Rewrite/BinaryPassManager.cpp
+++ b/bolt/lib/Rewrite/BinaryPassManager.cpp
@@ -19,15 +19,15 @@
 #include "bolt/Passes/IdenticalCodeFolding.h"
 #include "bolt/Passes/IndirectCallPromotion.h"
 #include "bolt/Passes/Inliner.h"
-#include "bolt/Passes/InsertNegateRAStatePass.h"
 #include "bolt/Passes/Instrumentation.h"
 #include "bolt/Passes/JTFootprintReduction.h"
 #include "bolt/Passes/LongJmp.h"
 #include "bolt/Passes/LoopInversionPass.h"
 #include "bolt/Passes/MCF.h"
-#include "bolt/Passes/MarkRAStates.h"
 #include "bolt/Passes/PLTCall.h"
 #include "bolt/Passes/PatchEntries.h"
+#include "bolt/Passes/PointerAuthCFIAnalyzer.h"
+#include "bolt/Passes/PointerAuthCFIFixup.h"
 #include "bolt/Passes/ProfileQualityStats.h"
 #include "bolt/Passes/RegReAssign.h"
 #include "bolt/Passes/ReorderData.h"
@@ -362,7 +362,7 @@ Error BinaryFunctionPassManager::runAllPasses(BinaryContext 
&BC) {
   BinaryFunctionPassManager Manager(BC);
 
   if (BC.isAArch64())
-    Manager.registerPass(std::make_unique<MarkRAStates>());
+    Manager.registerPass(std::make_unique<PointerAuthCFIAnalyzer>());
 
   Manager.registerPass(
       std::make_unique<EstimateEdgeCounts>(PrintEstimateEdgeCounts));
@@ -524,7 +524,7 @@ Error BinaryFunctionPassManager::runAllPasses(BinaryContext 
&BC) {
     // relocations out of range and crash during linking.
     Manager.registerPass(std::make_unique<LongJmpPass>(PrintLongJmp));
 
-    Manager.registerPass(std::make_unique<InsertNegateRAState>());
+    Manager.registerPass(std::make_unique<PointerAuthCFIFixup>());
   }
 
   // This pass should always run last.*
diff --git a/bolt/test/AArch64/negate-ra-state-incorrect.s 
b/bolt/test/AArch64/negate-ra-state-incorrect.s
index 14d2c384a877d..390b3b824d6bc 100644
--- a/bolt/test/AArch64/negate-ra-state-incorrect.s
+++ b/bolt/test/AArch64/negate-ra-state-incorrect.s
@@ -1,4 +1,4 @@
-# This test checks that MarkRAStates pass ignores functions with
+# This test checks that PointerAuthCFIAnalyzer pass ignores functions with
 # malformed .cfi_negate_ra_state sequences in the input binary.
 
 # The cases checked are:
diff --git a/bolt/test/AArch64/negate-ra-state.s 
b/bolt/test/AArch64/negate-ra-state.s
index 30786d4ef9f70..d3206294a4f7e 100644
--- a/bolt/test/AArch64/negate-ra-state.s
+++ b/bolt/test/AArch64/negate-ra-state.s
@@ -9,13 +9,13 @@
 # RUN: llvm-bolt %t.exe -o %t.exe.bolt --no-threads --print-all | FileCheck %s 
--check-prefix=CHECK-BOLT
 
 # Check that the negate-ra-state at the start of bar is not discarded.
-# If it was discarded, MarkRAState would report bar as having inconsistent 
RAStates.
+# If it was discarded, PointerAuthCFIAnalyzer would report bar as having 
inconsistent RAStates.
 # This is testing the handling of initialRAState on the BinaryFunction.
 # CHECK-BOLT-NOT: BOLT-INFO: inconsistent RAStates in function foo
 # CHECK-BOLT-NOT: BOLT-INFO: inconsistent RAStates in function bar
 
 # Check that OpNegateRAState CFIs are generated correctly.
-# CHECK-BOLT: Binary Function "foo" after insert-negate-ra-state-pass {
+# CHECK-BOLT: Binary Function "foo" after pointer-auth-cfi-fixup {
 # CHECK-BOLT:         paciasp
 # CHECK-BOLT-NEXT:    OpNegateRAState
 
@@ -23,7 +23,7 @@
 # CHECK-BOLT-NEXT:     0:  OpNegateRAState
 # CHECK-BOLT-NEXT: End of Function "foo"
 
-# CHECK-BOLT: Binary Function "bar" after insert-negate-ra-state-pass {
+# CHECK-BOLT: Binary Function "bar" after pointer-auth-cfi-fixup {
 # CHECK-BOLT:         OpNegateRAState
 # CHECK-BOLT-NEXT:    mov     x1, #0x0
 # CHECK-BOLT-NEXT:    mov     x1, #0x1
@@ -37,7 +37,7 @@
 # CHECK-BOLT-NEXT: End of Function "bar"
 
 # End of negate-ra-state insertion logs for foo and bar.
-# CHECK: Binary Function "_start" after insert-negate-ra-state-pass {
+# CHECK: Binary Function "_start" after pointer-auth-cfi-fixup {
 
 # Check that the functions are in the new .text section
 # RUN: llvm-objdump %t.exe.bolt -d -j .text | FileCheck %s 
--check-prefix=CHECK-OBJDUMP
diff --git a/bolt/test/AArch64/pacret-split-funcs.s 
b/bolt/test/AArch64/pacret-split-funcs.s
index 27b3471045523..45eeb9aafc7e2 100644
--- a/bolt/test/AArch64/pacret-split-funcs.s
+++ b/bolt/test/AArch64/pacret-split-funcs.s
@@ -11,7 +11,7 @@
 
 # Checking that we don't see any OpNegateRAState CFIs before the insertion 
pass.
 # CHECK-NOT: OpNegateRAState
-# CHECK: Binary Function "foo" after insert-negate-ra-state-pass
+# CHECK: Binary Function "foo" after pointer-auth-cfi-fixup
 
 # CHECK:       paciasp
 # CHECK-NEXT:  OpNegateRAState
@@ -24,7 +24,7 @@
 # CHECK-NEXT:    OpNegateRAState
 # CHECK-NEXT:    ret
 
-# End of the insert-negate-ra-state-pass logs
+# End of the pointer-auth-cfi-fixup logs
 # CHECK: Binary Function "foo" after finalize-functions
 
   .text
diff --git a/bolt/unittests/Passes/CMakeLists.txt 
b/bolt/unittests/Passes/CMakeLists.txt
index 02dcd2c8417e1..2227b79c4f25e 100644
--- a/bolt/unittests/Passes/CMakeLists.txt
+++ b/bolt/unittests/Passes/CMakeLists.txt
@@ -6,7 +6,7 @@ set(LLVM_LINK_COMPONENTS
   )
 
 add_bolt_unittest(PassTests
-  InsertNegateRAState.cpp
+  PointerAuthCFIFixup.cpp
 
   DISABLE_LLVM_LINK_LLVM_DYLIB
   )
diff --git a/bolt/unittests/Passes/InsertNegateRAState.cpp 
b/bolt/unittests/Passes/PointerAuthCFIFixup.cpp
similarity index 98%
rename from bolt/unittests/Passes/InsertNegateRAState.cpp
rename to bolt/unittests/Passes/PointerAuthCFIFixup.cpp
index 123f6a0f1f767..17704b496450f 100644
--- a/bolt/unittests/Passes/InsertNegateRAState.cpp
+++ b/bolt/unittests/Passes/PointerAuthCFIFixup.cpp
@@ -1,4 +1,4 @@
-//===- bolt/unittest/Passes/InsertNegateRAState.cpp 
-----------------------===//
+//===- bolt/unittest/Passes/PointerAuthCFIFixup.cpp ----------------------===//
 //
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
@@ -14,7 +14,7 @@
 
 #include "bolt/Core/BinaryBasicBlock.h"
 #include "bolt/Core/BinaryFunction.h"
-#include "bolt/Passes/InsertNegateRAStatePass.h"
+#include "bolt/Passes/PointerAuthCFIFixup.h"
 #include "bolt/Rewrite/BinaryPassManager.h"
 #include "bolt/Rewrite/RewriteInstance.h"
 #include "llvm/BinaryFormat/ELF.h"
@@ -83,7 +83,7 @@ struct PassTester : public 
testing::TestWithParam<Triple::ArchType> {
                             BC->MRI.get(), BC->STI.get())));
 
     PassManager = std::make_unique<BinaryFunctionPassManager>(*BC);
-    PassManager->registerPass(std::make_unique<InsertNegateRAState>());
+    PassManager->registerPass(std::make_unique<PointerAuthCFIFixup>());
 
     TextSection = &BC->registerOrUpdateSection(
         ".text", ELF::SHT_PROGBITS, ELF::SHF_ALLOC | ELF::SHF_EXECINSTR,
diff --git a/llvm/utils/gn/secondary/bolt/lib/Passes/BUILD.gn 
b/llvm/utils/gn/secondary/bolt/lib/Passes/BUILD.gn
index a261f2866be47..76647538d100a 100644
--- a/llvm/utils/gn/secondary/bolt/lib/Passes/BUILD.gn
+++ b/llvm/utils/gn/secondary/bolt/lib/Passes/BUILD.gn
@@ -30,18 +30,18 @@ static_library("Passes") {
     "IdenticalCodeFolding.cpp",
     "IndirectCallPromotion.cpp",
     "Inliner.cpp",
-    "InsertNegateRAStatePass.cpp",
     "Instrumentation.cpp",
     "JTFootprintReduction.cpp",
     "LivenessAnalysis.cpp",
     "LongJmp.cpp",
     "LoopInversionPass.cpp",
     "MCF.cpp",
-    "MarkRAStates.cpp",
     "PAuthGadgetScanner.cpp",
     "PLTCall.cpp",
     "PatchEntries.cpp",
     "PettisAndHansen.cpp",
+    "PointerAuthCFIAnalyzer.cpp",
+    "PointerAuthCFIFixup.cpp",
     "ProfileQualityStats.cpp",
     "RegAnalysis.cpp",
     "RegReAssign.cpp",

From a92e1445aa49c324e5d6c69ef2628bb8132a9d53 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gergely=20B=C3=A1lint?= <[email protected]>
Date: Mon, 3 Nov 2025 17:41:17 +0100
Subject: [PATCH 2/6] Update bolt/docs/PacRetDesign.md

Co-authored-by: Paschalis Mpeis <[email protected]>
---
 bolt/docs/PacRetDesign.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/bolt/docs/PacRetDesign.md b/bolt/docs/PacRetDesign.md
index d69b4e65be755..d1d41908e0175 100644
--- a/bolt/docs/PacRetDesign.md
+++ b/bolt/docs/PacRetDesign.md
@@ -190,7 +190,7 @@ exact functions ignored, and the found inconsistency.
 
 ### PointerAuthCFIFixup
 
-This pass runs after optimizations. It performns the _inverse_ of 
PointerAuthCFIAnalyzer
+This pass runs after optimizations. It performs the _inverse_ of 
PointerAuthCFIAnalyzer
 pass:
 1. it reads the RA state annotations attached to the instructions, and
 2. whenever the state changes, it adds a PseudoInstruction that holds an

From 3eaf1a5b14b98e276beb5d998a4b8d933cfd30f8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gergely=20B=C3=A1lint?= <[email protected]>
Date: Mon, 3 Nov 2025 17:42:45 +0100
Subject: [PATCH 3/6] Update PacRetDesign.md

---
 bolt/docs/PacRetDesign.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/bolt/docs/PacRetDesign.md b/bolt/docs/PacRetDesign.md
index d1d41908e0175..fff06d30b8d36 100644
--- a/bolt/docs/PacRetDesign.md
+++ b/bolt/docs/PacRetDesign.md
@@ -105,7 +105,7 @@ negate-ra-state CFIs will become invalid during BasicBlock 
reordering.
 
 The implementation introduces two new passes:
 1. `PointerAuthCFIAnalyzer`: assigns the RA state to each instruction based on
-    the CFI in the input binary
+    the CFIs in the input binary
 2. `PointerAuthCFIFixup`: reads those assigned instruction RA states after
     optimizations, and emits `DW_CFA_AARCH64_negate_ra_state` CFIs at the 
correct
     places: wherever there is a state change between two consecutive 
instructions

From 8759e47df2b4f1c2eae8028f07bd55b435c4ef59 Mon Sep 17 00:00:00 2001
From: Gergely Balint <[email protected]>
Date: Wed, 12 Nov 2025 16:20:59 +0000
Subject: [PATCH 4/6] [BOLT] Add --print flags for PointerAuthCFI* passes

---
 bolt/include/bolt/Passes/PointerAuthCFIAnalyzer.h |  3 ++-
 bolt/include/bolt/Passes/PointerAuthCFIFixup.h    |  3 ++-
 bolt/lib/Rewrite/BinaryPassManager.cpp            | 15 +++++++++++++--
 bolt/unittests/Passes/PointerAuthCFIFixup.cpp     |  8 +++++++-
 4 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/bolt/include/bolt/Passes/PointerAuthCFIAnalyzer.h 
b/bolt/include/bolt/Passes/PointerAuthCFIAnalyzer.h
index 54da398f0b2b3..cc0b27f2593a0 100644
--- a/bolt/include/bolt/Passes/PointerAuthCFIAnalyzer.h
+++ b/bolt/include/bolt/Passes/PointerAuthCFIAnalyzer.h
@@ -24,7 +24,8 @@ class PointerAuthCFIAnalyzer : public BinaryFunctionPass {
   std::mutex IgnoreMutex;
 
 public:
-  explicit PointerAuthCFIAnalyzer() : BinaryFunctionPass(false) {}
+  explicit PointerAuthCFIAnalyzer(const cl::opt<bool> &PrintPass)
+      : BinaryFunctionPass(PrintPass) {}
 
   const char *getName() const override { return "pointer-auth-cfi-analyzer"; }
 
diff --git a/bolt/include/bolt/Passes/PointerAuthCFIFixup.h 
b/bolt/include/bolt/Passes/PointerAuthCFIFixup.h
index 7ec0fc677ce3f..61b3e3c59f0fc 100644
--- a/bolt/include/bolt/Passes/PointerAuthCFIFixup.h
+++ b/bolt/include/bolt/Passes/PointerAuthCFIFixup.h
@@ -19,7 +19,8 @@ namespace bolt {
 
 class PointerAuthCFIFixup : public BinaryFunctionPass {
 public:
-  explicit PointerAuthCFIFixup() : BinaryFunctionPass(false) {}
+  explicit PointerAuthCFIFixup(const cl::opt<bool> &PrintPass)
+      : BinaryFunctionPass(PrintPass) {}
 
   const char *getName() const override { return "pointer-auth-cfi-fixup"; }
 
diff --git a/bolt/lib/Rewrite/BinaryPassManager.cpp 
b/bolt/lib/Rewrite/BinaryPassManager.cpp
index 334643426a802..85f23dceefe26 100644
--- a/bolt/lib/Rewrite/BinaryPassManager.cpp
+++ b/bolt/lib/Rewrite/BinaryPassManager.cpp
@@ -134,6 +134,15 @@ static cl::opt<bool> PrintAArch64Relaxation(
     cl::desc("print functions after ADR/LDR Relaxation pass"), cl::Hidden,
     cl::cat(BoltOptCategory));
 
+cl::opt<bool> PrintPAuthCFIAnalyzer(
+    "print-pointer-auth-cfi-analyzer",
+    cl::desc("print functions after PointerAuthCFIAnalyzer pass"), cl::Hidden,
+    cl::cat(BoltOptCategory));
+static cl::opt<bool> PrintPAuthCFIFixup(
+    "print-pointer-auth-cfi-fixup",
+    cl::desc("print functions after PointerAuthCFIFixup pass"), cl::Hidden,
+    cl::cat(BoltOptCategory));
+
 static cl::opt<bool>
     PrintLongJmp("print-longjmp",
                  cl::desc("print functions after longjmp pass"), cl::Hidden,
@@ -362,7 +371,8 @@ Error BinaryFunctionPassManager::runAllPasses(BinaryContext 
&BC) {
   BinaryFunctionPassManager Manager(BC);
 
   if (BC.isAArch64())
-    Manager.registerPass(std::make_unique<PointerAuthCFIAnalyzer>());
+    Manager.registerPass(
+        std::make_unique<PointerAuthCFIAnalyzer>(PrintPAuthCFIAnalyzer));
 
   Manager.registerPass(
       std::make_unique<EstimateEdgeCounts>(PrintEstimateEdgeCounts));
@@ -524,7 +534,8 @@ Error BinaryFunctionPassManager::runAllPasses(BinaryContext 
&BC) {
     // relocations out of range and crash during linking.
     Manager.registerPass(std::make_unique<LongJmpPass>(PrintLongJmp));
 
-    Manager.registerPass(std::make_unique<PointerAuthCFIFixup>());
+    Manager.registerPass(
+        std::make_unique<PointerAuthCFIFixup>(PrintPAuthCFIFixup));
   }
 
   // This pass should always run last.*
diff --git a/bolt/unittests/Passes/PointerAuthCFIFixup.cpp 
b/bolt/unittests/Passes/PointerAuthCFIFixup.cpp
index 17704b496450f..4b77eeb37e519 100644
--- a/bolt/unittests/Passes/PointerAuthCFIFixup.cpp
+++ b/bolt/unittests/Passes/PointerAuthCFIFixup.cpp
@@ -17,6 +17,7 @@
 #include "bolt/Passes/PointerAuthCFIFixup.h"
 #include "bolt/Rewrite/BinaryPassManager.h"
 #include "bolt/Rewrite/RewriteInstance.h"
+#include "bolt/Utils/CommandLineOpts.h"
 #include "llvm/BinaryFormat/ELF.h"
 #include "llvm/MC/MCDwarf.h"
 #include "llvm/MC/MCInstBuilder.h"
@@ -28,6 +29,10 @@ using namespace llvm::object;
 using namespace llvm::ELF;
 using namespace bolt;
 
+namespace opts {
+extern cl::opt<bool> PrintPAuthCFIAnalyzer;
+} // namespace opts
+
 namespace {
 struct PassTester : public testing::TestWithParam<Triple::ArchType> {
   void SetUp() override {
@@ -83,7 +88,8 @@ struct PassTester : public 
testing::TestWithParam<Triple::ArchType> {
                             BC->MRI.get(), BC->STI.get())));
 
     PassManager = std::make_unique<BinaryFunctionPassManager>(*BC);
-    PassManager->registerPass(std::make_unique<PointerAuthCFIFixup>());
+    PassManager->registerPass(
+        std::make_unique<PointerAuthCFIFixup>(opts::PrintPAuthCFIAnalyzer));
 
     TextSection = &BC->registerOrUpdateSection(
         ".text", ELF::SHT_PROGBITS, ELF::SHF_ALLOC | ELF::SHF_EXECINSTR,

From a7da8c1c85e3d2d46367942192b29b6bee727c94 Mon Sep 17 00:00:00 2001
From: Gergely Balint <[email protected]>
Date: Mon, 17 Nov 2025 10:07:03 +0000
Subject: [PATCH 5/6] [NFC] Rename PAuth tests to have a common prefix

---
 bolt/docs/{PacRetDesign.md => PointerAuthDesign.md}               | 0
 .../AArch64/{negate-ra-state-disallow.s => pacret-cfi-disallow.s} | 0
 .../{negate-ra-state-incorrect.s => pacret-cfi-incorrect.s}       | 0
 .../AArch64/{negate-ra-state-reorder.s => pacret-cfi-reorder.s}   | 0
 bolt/test/AArch64/{negate-ra-state.s => pacret-cfi.s}             | 0
 .../{pacret-function-split.cpp => pacret-eh-function-split.cpp}   | 0
 bolt/test/runtime/AArch64/{negate-ra-state.cpp => pacret-eh.cpp}  | 0
 7 files changed, 0 insertions(+), 0 deletions(-)
 rename bolt/docs/{PacRetDesign.md => PointerAuthDesign.md} (100%)
 rename bolt/test/AArch64/{negate-ra-state-disallow.s => pacret-cfi-disallow.s} 
(100%)
 rename bolt/test/AArch64/{negate-ra-state-incorrect.s => 
pacret-cfi-incorrect.s} (100%)
 rename bolt/test/AArch64/{negate-ra-state-reorder.s => pacret-cfi-reorder.s} 
(100%)
 rename bolt/test/AArch64/{negate-ra-state.s => pacret-cfi.s} (100%)
 rename bolt/test/runtime/AArch64/{pacret-function-split.cpp => 
pacret-eh-function-split.cpp} (100%)
 rename bolt/test/runtime/AArch64/{negate-ra-state.cpp => pacret-eh.cpp} (100%)

diff --git a/bolt/docs/PacRetDesign.md b/bolt/docs/PointerAuthDesign.md
similarity index 100%
rename from bolt/docs/PacRetDesign.md
rename to bolt/docs/PointerAuthDesign.md
diff --git a/bolt/test/AArch64/negate-ra-state-disallow.s 
b/bolt/test/AArch64/pacret-cfi-disallow.s
similarity index 100%
rename from bolt/test/AArch64/negate-ra-state-disallow.s
rename to bolt/test/AArch64/pacret-cfi-disallow.s
diff --git a/bolt/test/AArch64/negate-ra-state-incorrect.s 
b/bolt/test/AArch64/pacret-cfi-incorrect.s
similarity index 100%
rename from bolt/test/AArch64/negate-ra-state-incorrect.s
rename to bolt/test/AArch64/pacret-cfi-incorrect.s
diff --git a/bolt/test/AArch64/negate-ra-state-reorder.s 
b/bolt/test/AArch64/pacret-cfi-reorder.s
similarity index 100%
rename from bolt/test/AArch64/negate-ra-state-reorder.s
rename to bolt/test/AArch64/pacret-cfi-reorder.s
diff --git a/bolt/test/AArch64/negate-ra-state.s 
b/bolt/test/AArch64/pacret-cfi.s
similarity index 100%
rename from bolt/test/AArch64/negate-ra-state.s
rename to bolt/test/AArch64/pacret-cfi.s
diff --git a/bolt/test/runtime/AArch64/pacret-function-split.cpp 
b/bolt/test/runtime/AArch64/pacret-eh-function-split.cpp
similarity index 100%
rename from bolt/test/runtime/AArch64/pacret-function-split.cpp
rename to bolt/test/runtime/AArch64/pacret-eh-function-split.cpp
diff --git a/bolt/test/runtime/AArch64/negate-ra-state.cpp 
b/bolt/test/runtime/AArch64/pacret-eh.cpp
similarity index 100%
rename from bolt/test/runtime/AArch64/negate-ra-state.cpp
rename to bolt/test/runtime/AArch64/pacret-eh.cpp

From d569f73eb3e6b4c2470fc949a8743ceb6f144c89 Mon Sep 17 00:00:00 2001
From: Gergely Balint <[email protected]>
Date: Mon, 17 Nov 2025 10:11:07 +0000
Subject: [PATCH 6/6] [BOLT][doc] Add two resolutions for CFI

---
 bolt/docs/PointerAuthDesign.md | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/bolt/docs/PointerAuthDesign.md b/bolt/docs/PointerAuthDesign.md
index fff06d30b8d36..d10179504b7f9 100644
--- a/bolt/docs/PointerAuthDesign.md
+++ b/bolt/docs/PointerAuthDesign.md
@@ -10,6 +10,10 @@ intended audience is BOLT developers. The document is an 
updated version of the
 in assembly, or `OpNegateRAState` in BOLT sources. In this document, I will use
 **negate-ra-state** as a shorthand.
 
+Note: there are two resolutions for CFI:
+- Call Frame Instruction: individual DWARF instruction, e.g. negate-ra-state
+- Control Flow Integrity: a security mechanism, e.g. pointer authentication.
+
 ## Introduction
 
 ### Pointer Authentication

_______________________________________________
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

Reply via email to