Skip to content

Commit 12dce30

Browse files
committed
Omit clobbering info for warnings, simplify
1 parent 499d329 commit 12dce30

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
@@ -516,13 +516,11 @@ class SrcSafetyAnalysis {
516516
public:
517517
std::vector<MCInstReference>
518518
getLastClobberingInsts(const MCInst &Inst, BinaryFunction &BF,
519-
std::optional<MCPhysReg> ClobberedReg) const {
520-
if (!ClobberedReg || RegsToTrackInstsFor.empty())
521-
return {};
519+
MCPhysReg ClobberedReg) const {
522520
const SrcState &S = getStateBefore(Inst);
523521

524522
std::vector<MCInstReference> Result;
525-
for (const MCInst *Inst : lastWritingInsts(S, *ClobberedReg)) {
523+
for (const MCInst *Inst : lastWritingInsts(S, ClobberedReg)) {
526524
MCInstReference Ref = MCInstReference::get(Inst, BF);
527525
assert(Ref && "Expected Inst to be found");
528526
Result.push_back(Ref);
@@ -866,16 +864,29 @@ void FunctionAnalysis::augmentUnsafeUseReports(
866864
});
867865

868866
// Augment gadget reports.
869-
for (auto Report : Reports) {
867+
for (auto &Report : Reports) {
870868
MCInstReference Location = Report.Issue->Location;
871869
LLVM_DEBUG({ traceInst(BC, "Attaching clobbering info to", Location); });
870+
assert(Report.RequestedDetails &&
871+
"Should be removed by handleSimpleReports");
872872
auto DetailedInfo =
873873
std::make_shared<ClobberingInfo>(Analysis->getLastClobberingInsts(
874-
Location, BF, Report.RequestedDetails));
874+
Location, BF, *Report.RequestedDetails));
875875
Result.Diagnostics.emplace_back(Report.Issue, DetailedInfo);
876876
}
877877
}
878878

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

886897
SmallVector<BriefReport<MCPhysReg>> UnsafeUses;
887898
findUnsafeUses(UnsafeUses);
899+
handleSimpleReports(UnsafeUses);
888900
if (!UnsafeUses.empty())
889901
augmentUnsafeUseReports(UnsafeUses);
890902
}

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)