Skip to content

Commit 982c342

Browse files
committed
[BOLT] Add --print flags for PointerAuthCFI* passes
1 parent 3c50b29 commit 982c342

File tree

4 files changed

+24
-5
lines changed

4 files changed

+24
-5
lines changed

bolt/include/bolt/Passes/PointerAuthCFIAnalyzer.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ class PointerAuthCFIAnalyzer : public BinaryFunctionPass {
2424
std::mutex IgnoreMutex;
2525

2626
public:
27-
explicit PointerAuthCFIAnalyzer() : BinaryFunctionPass(false) {}
27+
explicit PointerAuthCFIAnalyzer(const cl::opt<bool> &PrintPass)
28+
: BinaryFunctionPass(PrintPass) {}
2829

2930
const char *getName() const override { return "pointer-auth-cfi-analyzer"; }
3031

bolt/include/bolt/Passes/PointerAuthCFIFixup.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ namespace bolt {
1919

2020
class PointerAuthCFIFixup : public BinaryFunctionPass {
2121
public:
22-
explicit PointerAuthCFIFixup() : BinaryFunctionPass(false) {}
22+
explicit PointerAuthCFIFixup(const cl::opt<bool> &PrintPass)
23+
: BinaryFunctionPass(PrintPass) {}
2324

2425
const char *getName() const override { return "pointer-auth-cfi-fixup"; }
2526

bolt/lib/Rewrite/BinaryPassManager.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,15 @@ static cl::opt<bool> PrintAArch64Relaxation(
134134
cl::desc("print functions after ADR/LDR Relaxation pass"), cl::Hidden,
135135
cl::cat(BoltOptCategory));
136136

137+
cl::opt<bool> PrintPAuthCFIAnalyzer(
138+
"print-pointer-auth-cfi-analyzer",
139+
cl::desc("print functions after PointerAuthCFIAnalyzer pass"), cl::Hidden,
140+
cl::cat(BoltOptCategory));
141+
static cl::opt<bool> PrintPAuthCFIFixup(
142+
"print-pointer-auth-cfi-fixup",
143+
cl::desc("print functions after PointerAuthCFIFixup pass"), cl::Hidden,
144+
cl::cat(BoltOptCategory));
145+
137146
static cl::opt<bool>
138147
PrintLongJmp("print-longjmp",
139148
cl::desc("print functions after longjmp pass"), cl::Hidden,
@@ -362,7 +371,8 @@ Error BinaryFunctionPassManager::runAllPasses(BinaryContext &BC) {
362371
BinaryFunctionPassManager Manager(BC);
363372

364373
if (BC.isAArch64())
365-
Manager.registerPass(std::make_unique<PointerAuthCFIAnalyzer>());
374+
Manager.registerPass(
375+
std::make_unique<PointerAuthCFIAnalyzer>(PrintPAuthCFIAnalyzer));
366376

367377
Manager.registerPass(
368378
std::make_unique<EstimateEdgeCounts>(PrintEstimateEdgeCounts));
@@ -524,7 +534,8 @@ Error BinaryFunctionPassManager::runAllPasses(BinaryContext &BC) {
524534
// relocations out of range and crash during linking.
525535
Manager.registerPass(std::make_unique<LongJmpPass>(PrintLongJmp));
526536

527-
Manager.registerPass(std::make_unique<PointerAuthCFIFixup>());
537+
Manager.registerPass(
538+
std::make_unique<PointerAuthCFIFixup>(PrintPAuthCFIFixup));
528539
}
529540

530541
// This pass should always run last.*

bolt/unittests/Passes/PointerAuthCFIFixup.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "bolt/Passes/PointerAuthCFIFixup.h"
1818
#include "bolt/Rewrite/BinaryPassManager.h"
1919
#include "bolt/Rewrite/RewriteInstance.h"
20+
#include "bolt/Utils/CommandLineOpts.h"
2021
#include "llvm/BinaryFormat/ELF.h"
2122
#include "llvm/MC/MCDwarf.h"
2223
#include "llvm/MC/MCInstBuilder.h"
@@ -28,6 +29,10 @@ using namespace llvm::object;
2829
using namespace llvm::ELF;
2930
using namespace bolt;
3031

32+
namespace opts {
33+
extern cl::opt<bool> PrintPAuthCFIAnalyzer;
34+
} // namespace opts
35+
3136
namespace {
3237
struct PassTester : public testing::TestWithParam<Triple::ArchType> {
3338
void SetUp() override {
@@ -83,7 +88,8 @@ struct PassTester : public testing::TestWithParam<Triple::ArchType> {
8388
BC->MRI.get(), BC->STI.get())));
8489

8590
PassManager = std::make_unique<BinaryFunctionPassManager>(*BC);
86-
PassManager->registerPass(std::make_unique<PointerAuthCFIFixup>());
91+
PassManager->registerPass(
92+
std::make_unique<PointerAuthCFIFixup>(opts::PrintPAuthCFIAnalyzer));
8793

8894
TextSection = &BC->registerOrUpdateSection(
8995
".text", ELF::SHT_PROGBITS, ELF::SHF_ALLOC | ELF::SHF_EXECINSTR,

0 commit comments

Comments
 (0)