Skip to content

Commit 0a2f161

Browse files
committed
Omit clobbering info for warnings, simplify
1 parent d0235cf commit 0a2f161

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
@@ -300,6 +300,10 @@ class FunctionAnalysis {
300300
void findUnsafeUses(SmallVector<BriefReport<MCPhysReg>> &Reports);
301301
void augmentUnsafeUseReports(const ArrayRef<BriefReport<MCPhysReg>> Reports);
302302

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

bolt/lib/Passes/PAuthGadgetScanner.cpp

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

525523
std::vector<MCInstReference> Result;
526-
for (const MCInst *Inst : lastWritingInsts(S, *ClobberedReg)) {
524+
for (const MCInst *Inst : lastWritingInsts(S, ClobberedReg)) {
527525
MCInstReference Ref = MCInstReference::get(Inst, BF);
528526
assert(Ref && "Expected Inst to be found");
529527
Result.push_back(Ref);
@@ -871,16 +869,29 @@ void FunctionAnalysis::augmentUnsafeUseReports(
871869
});
872870

873871
// Augment gadget reports.
874-
for (auto Report : Reports) {
872+
for (auto &Report : Reports) {
875873
MCInstReference Location = Report.Issue->Location;
876874
LLVM_DEBUG({ traceInst(BC, "Attaching clobbering info to", Location); });
875+
assert(Report.RequestedDetails &&
876+
"Should be removed by handleSimpleReports");
877877
auto DetailedInfo =
878878
std::make_shared<ClobberingInfo>(Analysis->getLastClobberingInsts(
879-
Location, BF, Report.RequestedDetails));
879+
Location, BF, *Report.RequestedDetails));
880880
Result.Diagnostics.emplace_back(Report.Issue, DetailedInfo);
881881
}
882882
}
883883

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

891902
SmallVector<BriefReport<MCPhysReg>> UnsafeUses;
892903
findUnsafeUses(UnsafeUses);
904+
handleSimpleReports(UnsafeUses);
893905
if (!UnsafeUses.empty())
894906
augmentUnsafeUseReports(UnsafeUses);
895907
}

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)