Skip to content

Commit a05ee35

Browse files
committed
[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.
1 parent 1ee52ed commit a05ee35

File tree

10 files changed

+63
-62
lines changed

10 files changed

+63
-62
lines changed

bolt/docs/PacRetDesign.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ negate-ra-state CFIs will become invalid during BasicBlock reordering.
104104
## Solution design
105105

106106
The implementation introduces two new passes:
107-
1. `MarkRAStatesPass`: assigns the RA state to each instruction based on the CFIs
108-
in the input binary
109-
2. `InsertNegateRAStatePass`: reads those assigned instruction RA states after
107+
1. `PointerAuthCFIAnalyzer`: assigns the RA state to each instruction based on
108+
the CFI in the input binary
109+
2. `PointerAuthCFIFixup`: reads those assigned instruction RA states after
110110
optimizations, and emits `DW_CFA_AARCH64_negate_ra_state` CFIs at the correct
111111
places: wherever there is a state change between two consecutive instructions
112112
in the layout order.
@@ -129,7 +129,7 @@ instruction.
129129
This special case is handled by adding an `initialRAState` bool to each BinaryFunction.
130130
If the `Offset` the CFI refers to is zero, we don't store an annotation, but set
131131
the `initialRAState` in `FillCFIInfoFor`. This information is then used in
132-
`MarkRAStates`.
132+
`PointerAuthCFIAnalyzer`.
133133

134134
### Binaries without DWARF info
135135

@@ -146,7 +146,7 @@ In summary:
146146
- pointer auth is used, and we have DWARF CFIs: passes run, and rewrite the
147147
negate-ra-state CFI.
148148

149-
### MarkRAStates pass
149+
### PointerAuthCFIAnalyzer pass
150150

151151
This pass runs before optimizations reorder anything.
152152

@@ -173,9 +173,9 @@ what we have before the pass, and after it.
173173
| autiasp | negate-ra-state | signed |
174174
| ret | | unsigned |
175175

176-
##### Error handling in MarkRAState Pass:
176+
##### Error handling in PointerAuthCFIAnalyzer pass:
177177

178-
Whenever the MarkRAStates pass finds inconsistencies in the current
178+
Whenever the PointerAuthCFIAnalyzer pass finds inconsistencies in the current
179179
BinaryFunction, it marks the function as ignored using `BF.setIgnored()`. BOLT
180180
will not optimize this function but will emit it unchanged in the original section
181181
(`.bolt.org.text`).
@@ -188,16 +188,17 @@ The inconsistencies are as follows:
188188
Users will be informed about the number of ignored functions in the pass, the
189189
exact functions ignored, and the found inconsistency.
190190

191-
### InsertNegateRAStatePass
191+
### PointerAuthCFIFixup
192192

193-
This pass runs after optimizations. It performns the _inverse_ of MarkRAState pa s:
193+
This pass runs after optimizations. It performns the _inverse_ of PointerAuthCFIAnalyzer
194+
pass:
194195
1. it reads the RA state annotations attached to the instructions, and
195196
2. whenever the state changes, it adds a PseudoInstruction that holds an
196197
OpNegateRAState CFI.
197198

198199
##### Covering newly generated instructions:
199200

200-
Some BOLT passes can add new Instructions. In InsertNegateRAStatePass, we have
201+
Some BOLT passes can add new Instructions. In PointerAuthCFIFixup, we have
201202
to know what RA state these have.
202203

203204
> [!important]
@@ -230,7 +231,7 @@ freely. The only special case is function splitting. When a function is split,
230231
the split part becomes a new function in the emitted binary. For unwinding to
231232
work, it needs to "replay" all CFIs that lead up to the split point. BOLT does
232233
this for other CFIs. As negate-ra-state is not read (only stored as an Annotation),
233-
we have to do this manually in InsertNegateRAStatePass. Here, if the split part
234+
we have to do this manually in PointerAuthCFIFixup. Here, if the split part
234235
starts with an instruction that has Signed RA state, we add a negate-ra-state CFI
235236
to indicate this.
236237

bolt/include/bolt/Passes/MarkRAStates.h renamed to bolt/include/bolt/Passes/PointerAuthCFIAnalyzer.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
1-
//===- bolt/Passes/MarkRAStates.cpp ---------------------------------===//
1+
//===- bolt/Passes/PointerAuthCFIAnalyzer.h -------------------------------===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
//===----------------------------------------------------------------------===//
88
//
9-
// This file implements the MarkRAStates class.
9+
// This file implements the PointerAuthCFIAnalyzer class.
1010
//
1111
//===----------------------------------------------------------------------===//
12-
#ifndef BOLT_PASSES_MARK_RA_STATES
13-
#define BOLT_PASSES_MARK_RA_STATES
12+
#ifndef BOLT_PASSES_POINTER_AUTH_CFI_ANALYZER
13+
#define BOLT_PASSES_POINTER_AUTH_CFI_ANALYZER
1414

1515
#include "bolt/Passes/BinaryPasses.h"
1616

1717
namespace llvm {
1818
namespace bolt {
1919

20-
class MarkRAStates : public BinaryFunctionPass {
20+
class PointerAuthCFIAnalyzer : public BinaryFunctionPass {
2121
public:
22-
explicit MarkRAStates() : BinaryFunctionPass(false) {}
22+
explicit PointerAuthCFIAnalyzer() : BinaryFunctionPass(false) {}
2323

24-
const char *getName() const override { return "mark-ra-states"; }
24+
const char *getName() const override { return "pointer-auth-cfi-analyzer"; }
2525

2626
/// Pass entry point
2727
Error runOnFunctions(BinaryContext &BC) override;

bolt/include/bolt/Passes/InsertNegateRAStatePass.h renamed to bolt/include/bolt/Passes/PointerAuthCFIFixup.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
1-
//===- bolt/Passes/InsertNegateRAStatePass.h ------------------------------===//
1+
//===- bolt/Passes/PointerAuthCFIFixup.h ----------------------------------===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
//===----------------------------------------------------------------------===//
88
//
9-
// This file implements the InsertNegateRAStatePass class.
9+
// This file implements the PointerAuthCFIFixup class.
1010
//
1111
//===----------------------------------------------------------------------===//
12-
#ifndef BOLT_PASSES_INSERT_NEGATE_RA_STATE_PASS
13-
#define BOLT_PASSES_INSERT_NEGATE_RA_STATE_PASS
12+
#ifndef BOLT_PASSES_POINTER_AUTH_CFI_FIXUP
13+
#define BOLT_PASSES_POINTER_AUTH_CFI_FIXUP
1414

1515
#include "bolt/Passes/BinaryPasses.h"
1616

1717
namespace llvm {
1818
namespace bolt {
1919

20-
class InsertNegateRAState : public BinaryFunctionPass {
20+
class PointerAuthCFIFixup : public BinaryFunctionPass {
2121
public:
22-
explicit InsertNegateRAState() : BinaryFunctionPass(false) {}
22+
explicit PointerAuthCFIFixup() : BinaryFunctionPass(false) {}
2323

24-
const char *getName() const override { return "insert-negate-ra-state-pass"; }
24+
const char *getName() const override { return "pointer-auth-cfi-fixup"; }
2525

2626
/// Pass entry point
2727
Error runOnFunctions(BinaryContext &BC) override;

bolt/lib/Passes/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,18 @@ add_llvm_library(LLVMBOLTPasses
1717
IdenticalCodeFolding.cpp
1818
IndirectCallPromotion.cpp
1919
Inliner.cpp
20-
InsertNegateRAStatePass.cpp
2120
Instrumentation.cpp
2221
JTFootprintReduction.cpp
2322
LongJmp.cpp
2423
LoopInversionPass.cpp
2524
LivenessAnalysis.cpp
2625
MCF.cpp
27-
MarkRAStates.cpp
2826
PatchEntries.cpp
2927
PAuthGadgetScanner.cpp
3028
PettisAndHansen.cpp
3129
PLTCall.cpp
30+
PointerAuthCFIAnalyzer.cpp
31+
PointerAuthCFIFixup.cpp
3232
ProfileQualityStats.cpp
3333
RegAnalysis.cpp
3434
RegReAssign.cpp

bolt/lib/Passes/MarkRAStates.cpp renamed to bolt/lib/Passes/PointerAuthCFIAnalyzer.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
//===- bolt/Passes/MarkRAStates.cpp ---------------------------------===//
1+
//===- bolt/Passes/PointerAuthCFIAnalyzer.cpp -----------------------------===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
//===----------------------------------------------------------------------===//
88
//
9-
// This file implements the MarkRAStates class.
9+
// This file implements the PointerAuthCFIAnalyzer class.
1010
// Three CFIs have an influence on the RA State of an instruction:
1111
// - NegateRAState flips the RA State,
1212
// - RememberState pushes the RA State to a stack,
@@ -16,10 +16,10 @@
1616
// the RA State of each instruction, and save it as new MCAnnotations. The new
1717
// annotations are Signing, Signed, Authenticating and Unsigned. After
1818
// optimizations, .cfi_negate_ra_state CFIs are added to the places where the
19-
// state changes in InsertNegateRAStatePass.
19+
// state changes in PointerAuthCFIFixup.
2020
//
2121
//===----------------------------------------------------------------------===//
22-
#include "bolt/Passes/MarkRAStates.h"
22+
#include "bolt/Passes/PointerAuthCFIAnalyzer.h"
2323
#include "bolt/Core/BinaryFunction.h"
2424
#include "bolt/Core/ParallelUtilities.h"
2525
#include <cstdlib>
@@ -31,7 +31,7 @@ using namespace llvm;
3131
namespace llvm {
3232
namespace bolt {
3333

34-
bool MarkRAStates::runOnFunction(BinaryFunction &BF) {
34+
bool PointerAuthCFIAnalyzer::runOnFunction(BinaryFunction &BF) {
3535

3636
BinaryContext &BC = BF.getBinaryContext();
3737

@@ -107,7 +107,7 @@ bool MarkRAStates::runOnFunction(BinaryFunction &BF) {
107107
return true;
108108
}
109109

110-
Error MarkRAStates::runOnFunctions(BinaryContext &BC) {
110+
Error PointerAuthCFIAnalyzer::runOnFunctions(BinaryContext &BC) {
111111
std::atomic<uint64_t> FunctionsIgnored{0};
112112
ParallelUtilities::WorkFuncTy WorkFun = [&](BinaryFunction &BF) {
113113
if (!runOnFunction(BF)) {
@@ -129,8 +129,8 @@ Error MarkRAStates::runOnFunctions(BinaryContext &BC) {
129129

130130
ParallelUtilities::runOnEachFunction(
131131
BC, ParallelUtilities::SchedulingPolicy::SP_INST_LINEAR, WorkFun,
132-
SkipPredicate, "MarkRAStates");
133-
BC.outs() << "BOLT-INFO: MarkRAStates ran on " << Total
132+
SkipPredicate, "PointerAuthCFIAnalyzer");
133+
BC.outs() << "BOLT-INFO: PointerAuthCFIAnalyzer ran on " << Total
134134
<< " functions. Ignored " << FunctionsIgnored << " functions "
135135
<< format("(%.2lf%%)", (100.0 * FunctionsIgnored) / Total)
136136
<< " because of CFI inconsistencies\n";

bolt/lib/Passes/InsertNegateRAStatePass.cpp renamed to bolt/lib/Passes/PointerAuthCFIFixup.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
//===- bolt/Passes/InsertNegateRAStatePass.cpp ----------------------------===//
1+
//===- bolt/Passes/PointerAuthCFIFixup.cpp --------------------------------===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
//===----------------------------------------------------------------------===//
88
//
9-
// This file implements the InsertNegateRAStatePass class. It inserts
9+
// This file implements the PointerAuthCFIFixup class. It inserts
1010
// OpNegateRAState CFIs to places where the state of two consecutive
1111
// instructions are different.
1212
//
1313
//===----------------------------------------------------------------------===//
14-
#include "bolt/Passes/InsertNegateRAStatePass.h"
14+
#include "bolt/Passes/PointerAuthCFIFixup.h"
1515
#include "bolt/Core/BinaryFunction.h"
1616
#include "bolt/Core/ParallelUtilities.h"
1717
#include <cstdlib>
@@ -21,7 +21,7 @@ using namespace llvm;
2121
namespace llvm {
2222
namespace bolt {
2323

24-
void InsertNegateRAState::runOnFunction(BinaryFunction &BF) {
24+
void PointerAuthCFIFixup::runOnFunction(BinaryFunction &BF) {
2525
BinaryContext &BC = BF.getBinaryContext();
2626

2727
if (BF.getState() == BinaryFunction::State::Empty)
@@ -30,7 +30,7 @@ void InsertNegateRAState::runOnFunction(BinaryFunction &BF) {
3030
if (BF.getState() != BinaryFunction::State::CFG &&
3131
BF.getState() != BinaryFunction::State::CFG_Finalized) {
3232
BC.outs() << "BOLT-INFO: no CFG for " << BF.getPrintName()
33-
<< " in InsertNegateRAStatePass\n";
33+
<< " in PointerAuthCFIFixup\n";
3434
return;
3535
}
3636

@@ -71,7 +71,7 @@ void InsertNegateRAState::runOnFunction(BinaryFunction &BF) {
7171
}
7272
}
7373

74-
void InsertNegateRAState::inferUnknownStates(BinaryFunction &BF) {
74+
void PointerAuthCFIFixup::inferUnknownStates(BinaryFunction &BF) {
7575
BinaryContext &BC = BF.getBinaryContext();
7676

7777
// Fill in missing RAStates in simple cases (inside BBs).
@@ -85,7 +85,7 @@ void InsertNegateRAState::inferUnknownStates(BinaryFunction &BF) {
8585
fillUnknownBlocksInCFG(BF);
8686
}
8787

88-
void InsertNegateRAState::coverFunctionFragmentStart(BinaryFunction &BF,
88+
void PointerAuthCFIFixup::coverFunctionFragmentStart(BinaryFunction &BF,
8989
FunctionFragment &FF) {
9090
BinaryContext &BC = BF.getBinaryContext();
9191
if (FF.empty())
@@ -117,7 +117,7 @@ void InsertNegateRAState::coverFunctionFragmentStart(BinaryFunction &BF,
117117
}
118118

119119
std::optional<bool>
120-
InsertNegateRAState::getFirstKnownRAState(BinaryContext &BC,
120+
PointerAuthCFIFixup::getFirstKnownRAState(BinaryContext &BC,
121121
BinaryBasicBlock &BB) {
122122
for (const MCInst &Inst : BB) {
123123
if (BC.MIB->isCFI(Inst))
@@ -129,7 +129,7 @@ InsertNegateRAState::getFirstKnownRAState(BinaryContext &BC,
129129
return std::nullopt;
130130
}
131131

132-
void InsertNegateRAState::fillUnknownStateInBB(BinaryContext &BC,
132+
void PointerAuthCFIFixup::fillUnknownStateInBB(BinaryContext &BC,
133133
BinaryBasicBlock &BB) {
134134

135135
auto First = BB.getFirstNonPseudo();
@@ -171,7 +171,7 @@ void InsertNegateRAState::fillUnknownStateInBB(BinaryContext &BC,
171171
}
172172
}
173173

174-
bool InsertNegateRAState::isUnknownBlock(BinaryContext &BC,
174+
bool PointerAuthCFIFixup::isUnknownBlock(BinaryContext &BC,
175175
BinaryBasicBlock &BB) {
176176
for (const MCInst &Inst : BB) {
177177
if (BC.MIB->isCFI(Inst))
@@ -183,7 +183,7 @@ bool InsertNegateRAState::isUnknownBlock(BinaryContext &BC,
183183
return true;
184184
}
185185

186-
void InsertNegateRAState::markUnknownBlock(BinaryContext &BC,
186+
void PointerAuthCFIFixup::markUnknownBlock(BinaryContext &BC,
187187
BinaryBasicBlock &BB, bool State) {
188188
// If we call this when an Instruction has either kRASigned or kRAUnsigned
189189
// annotation, setRASigned or setRAUnsigned would fail.
@@ -196,7 +196,7 @@ void InsertNegateRAState::markUnknownBlock(BinaryContext &BC,
196196
}
197197
}
198198

199-
std::optional<bool> InsertNegateRAState::getRAStateByCFG(BinaryBasicBlock &BB,
199+
std::optional<bool> PointerAuthCFIFixup::getRAStateByCFG(BinaryBasicBlock &BB,
200200
BinaryFunction &BF) {
201201
BinaryContext &BC = BF.getBinaryContext();
202202

@@ -242,7 +242,7 @@ std::optional<bool> InsertNegateRAState::getRAStateByCFG(BinaryBasicBlock &BB,
242242
return NeighborRAState;
243243
}
244244

245-
void InsertNegateRAState::fillUnknownStubs(BinaryFunction &BF) {
245+
void PointerAuthCFIFixup::fillUnknownStubs(BinaryFunction &BF) {
246246
BinaryContext &BC = BF.getBinaryContext();
247247
bool FirstIter = true;
248248
MCInst PrevInst;
@@ -281,7 +281,7 @@ void InsertNegateRAState::fillUnknownStubs(BinaryFunction &BF) {
281281
}
282282
}
283283
}
284-
void InsertNegateRAState::fillUnknownBlocksInCFG(BinaryFunction &BF) {
284+
void PointerAuthCFIFixup::fillUnknownBlocksInCFG(BinaryFunction &BF) {
285285
BinaryContext &BC = BF.getBinaryContext();
286286

287287
auto fillUnknowns = [&](BinaryFunction &BF) -> std::pair<int, bool> {
@@ -317,7 +317,7 @@ void InsertNegateRAState::fillUnknownBlocksInCFG(BinaryFunction &BF) {
317317
}
318318
}
319319

320-
Error InsertNegateRAState::runOnFunctions(BinaryContext &BC) {
320+
Error PointerAuthCFIFixup::runOnFunctions(BinaryContext &BC) {
321321
std::atomic<uint64_t> FunctionsModified{0};
322322
ParallelUtilities::WorkFuncTy WorkFun = [&](BinaryFunction &BF) {
323323
FunctionsModified++;
@@ -334,7 +334,7 @@ Error InsertNegateRAState::runOnFunctions(BinaryContext &BC) {
334334

335335
ParallelUtilities::runOnEachFunction(
336336
BC, ParallelUtilities::SchedulingPolicy::SP_INST_LINEAR, WorkFun,
337-
SkipPredicate, "InsertNegateRAStatePass");
337+
SkipPredicate, "PointerAuthCFIFixup");
338338

339339
BC.outs() << "BOLT-INFO: rewritten pac-ret DWARF info in "
340340
<< FunctionsModified << " out of " << BC.getBinaryFunctions().size()

bolt/lib/Rewrite/BinaryPassManager.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@
1919
#include "bolt/Passes/IdenticalCodeFolding.h"
2020
#include "bolt/Passes/IndirectCallPromotion.h"
2121
#include "bolt/Passes/Inliner.h"
22-
#include "bolt/Passes/InsertNegateRAStatePass.h"
2322
#include "bolt/Passes/Instrumentation.h"
2423
#include "bolt/Passes/JTFootprintReduction.h"
2524
#include "bolt/Passes/LongJmp.h"
2625
#include "bolt/Passes/LoopInversionPass.h"
2726
#include "bolt/Passes/MCF.h"
28-
#include "bolt/Passes/MarkRAStates.h"
2927
#include "bolt/Passes/PLTCall.h"
3028
#include "bolt/Passes/PatchEntries.h"
29+
#include "bolt/Passes/PointerAuthCFIAnalyzer.h"
30+
#include "bolt/Passes/PointerAuthCFIFixup.h"
3131
#include "bolt/Passes/ProfileQualityStats.h"
3232
#include "bolt/Passes/RegReAssign.h"
3333
#include "bolt/Passes/ReorderData.h"
@@ -362,7 +362,7 @@ Error BinaryFunctionPassManager::runAllPasses(BinaryContext &BC) {
362362
BinaryFunctionPassManager Manager(BC);
363363

364364
if (BC.isAArch64())
365-
Manager.registerPass(std::make_unique<MarkRAStates>());
365+
Manager.registerPass(std::make_unique<PointerAuthCFIAnalyzer>());
366366

367367
Manager.registerPass(
368368
std::make_unique<EstimateEdgeCounts>(PrintEstimateEdgeCounts));
@@ -524,7 +524,7 @@ Error BinaryFunctionPassManager::runAllPasses(BinaryContext &BC) {
524524
// relocations out of range and crash during linking.
525525
Manager.registerPass(std::make_unique<LongJmpPass>(PrintLongJmp));
526526

527-
Manager.registerPass(std::make_unique<InsertNegateRAState>());
527+
Manager.registerPass(std::make_unique<PointerAuthCFIFixup>());
528528
}
529529

530530
// This pass should always run last.*

0 commit comments

Comments
 (0)