Skip to content

Commit bbec9f8

Browse files
committed
Omit clobbering info for warnings, simplify
1 parent ec437a4 commit bbec9f8

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

bolt/include/bolt/Passes/PAuthGadgetScanner.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,10 @@ class FunctionAnalysis {
302302
void findUnsafeUses(SmallVector<BriefReport<MCPhysReg>> &Reports);
303303
void augmentUnsafeUseReports(const ArrayRef<BriefReport<MCPhysReg>> Reports);
304304

305+
/// Process the reports which do not have to be augmented, and remove them
306+
/// from Reports.
307+
void handleSimpleReports(SmallVector<BriefReport<MCPhysReg>> &Reports);
308+
305309
public:
306310
FunctionAnalysis(BinaryFunction &BF, MCPlusBuilder::AllocatorIdTy AllocatorId,
307311
bool PacRetGadgetsOnly)

bolt/lib/Passes/PAuthGadgetScanner.cpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -518,13 +518,11 @@ class SrcSafetyAnalysis {
518518
public:
519519
std::vector<MCInstReference>
520520
getLastClobberingInsts(const MCInst &Inst, BinaryFunction &BF,
521-
std::optional<MCPhysReg> ClobberedReg) const {
522-
if (!ClobberedReg || RegsToTrackInstsFor.empty())
523-
return {};
521+
MCPhysReg ClobberedReg) const {
524522
const SrcState &S = getStateBefore(Inst);
525523

526524
std::vector<MCInstReference> Result;
527-
for (const MCInst *Inst : lastWritingInsts(S, *ClobberedReg)) {
525+
for (const MCInst *Inst : lastWritingInsts(S, ClobberedReg)) {
528526
MCInstReference Ref = MCInstReference::get(Inst, BF);
529527
assert(Ref && "Expected Inst to be found");
530528
Result.push_back(Ref);
@@ -868,16 +866,29 @@ void FunctionAnalysis::augmentUnsafeUseReports(
868866
});
869867

870868
// Augment gadget reports.
871-
for (auto Report : Reports) {
869+
for (auto &Report : Reports) {
872870
MCInstReference Location = Report.Issue->Location;
873871
LLVM_DEBUG({ traceInst(BC, "Attaching clobbering info to", Location); });
872+
assert(Report.RequestedDetails &&
873+
"Should be removed by handleSimpleReports");
874874
auto DetailedInfo =
875875
std::make_shared<ClobberingInfo>(Analysis->getLastClobberingInsts(
876-
Location, BF, Report.RequestedDetails));
876+
Location, BF, *Report.RequestedDetails));
877877
Result.Diagnostics.emplace_back(Report.Issue, DetailedInfo);
878878
}
879879
}
880880

881+
void FunctionAnalysis::handleSimpleReports(
882+
SmallVector<BriefReport<MCPhysReg>> &Reports) {
883+
// Before re-running the detailed analysis, process the reports which do not
884+
// need any additional details to be attached.
885+
for (auto &Report : Reports) {
886+
if (!Report.RequestedDetails)
887+
Result.Diagnostics.emplace_back(Report.Issue, nullptr);
888+
}
889+
llvm::erase_if(Reports, [](const auto &R) { return !R.RequestedDetails; });
890+
}
891+
881892
void FunctionAnalysis::run() {
882893
LLVM_DEBUG({
883894
dbgs() << "Analyzing function " << BF.getPrintName()
@@ -887,6 +898,7 @@ void FunctionAnalysis::run() {
887898

888899
SmallVector<BriefReport<MCPhysReg>> UnsafeUses;
889900
findUnsafeUses(UnsafeUses);
901+
handleSimpleReports(UnsafeUses);
890902
if (!UnsafeUses.empty())
891903
augmentUnsafeUseReports(UnsafeUses);
892904
}

bolt/test/binary-analysis/AArch64/gs-pacret-autiasp.s

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ f_callclobbered_calleesaved:
217217
f_unreachable_instruction:
218218
// CHECK-LABEL: GS-PAUTH: Warning: unreachable instruction found in function f_unreachable_instruction, basic block {{[0-9a-zA-Z.]+}}, at address
219219
// CHECK-NEXT: The instruction is {{[0-9a-f]+}}: add x0, x1, x2
220+
// CHECK-NOT: instructions that write to the affected registers after any authentication are:
220221
b 1f
221222
add x0, x1, x2
222223
1:

0 commit comments

Comments
 (0)