Skip to content

Commit 2e22a1d

Browse files
committed
More nitpicks based on feedback from atrosinenko
1 parent 7a12544 commit 2e22a1d

File tree

2 files changed

+9
-19
lines changed

2 files changed

+9
-19
lines changed

bolt/lib/Passes/NonPacProtectedRetAnalysis.cpp

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,6 @@ raw_ostream &operator<<(raw_ostream &OS, const MCInstReference &Ref) {
5656
llvm_unreachable("");
5757
}
5858

59-
raw_ostream &operator<<(raw_ostream &OS, const GeneralDiagnostic &Diag) {
60-
OS << "diag<'" << Diag.Text << "'>";
61-
return OS;
62-
}
63-
6459
namespace NonPacProtectedRetAnalysis {
6560

6661
// The security property that is checked is:
@@ -198,11 +193,13 @@ class PacRetAnalysis
198193
SmallPtrSet<const MCInst *, 4> &lastWritingInsts(State &S,
199194
MCPhysReg Reg) const {
200195
assert(Reg < Reg2StateIdx.size());
196+
assert(isTrackingReg(Reg));
201197
return S.LastInstWritingReg[Reg2StateIdx[Reg]];
202198
}
203199
const SmallPtrSet<const MCInst *, 4> &lastWritingInsts(const State &S,
204200
MCPhysReg Reg) const {
205201
assert(Reg < Reg2StateIdx.size());
202+
assert(isTrackingReg(Reg));
206203
return S.LastInstWritingReg[Reg2StateIdx[Reg]];
207204
}
208205

@@ -412,8 +409,8 @@ void Analysis::runOnFunction(BinaryFunction &BF,
412409
}
413410
}
414411

415-
void printBB(const BinaryContext &BC, const BinaryBasicBlock *BB,
416-
size_t StartIndex = 0, size_t EndIndex = -1) {
412+
static void printBB(const BinaryContext &BC, const BinaryBasicBlock *BB,
413+
size_t StartIndex = 0, size_t EndIndex = -1) {
417414
if (EndIndex == (size_t)-1)
418415
EndIndex = BB->size() - 1;
419416
const BinaryFunction *BF = BB->getFunction();
@@ -445,16 +442,9 @@ static void reportFoundGadgetInSingleBBSingleOverwInst(
445442
}
446443

447444
void Gadget::generateReport(raw_ostream &OS, const BinaryContext &BC) const {
448-
BinaryFunction *BF = RetInst.getFunction();
449-
BinaryBasicBlock *BB = RetInst.getBasicBlock();
445+
GenDiag(RetInst, "non-protected ret found").generateReport(OS, BC);
450446

451-
OS << "\nGS-PACRET: " << "non-protected ret found in function "
452-
<< BF->getPrintName();
453-
if (BB)
454-
OS << ", basic block " << BB->getName();
455-
OS << ", at address " << llvm::format("%x", RetInst.getAddress()) << "\n";
456-
OS << " The return instruction is ";
457-
BC.printInstruction(OS, RetInst, RetInst.getAddress(), BF);
447+
BinaryFunction *BF = RetInst.getFunction();
458448
OS << " The " << OverwritingRetRegInst.size()
459449
<< " instructions that write to the return register after any "
460450
"authentication are:\n";
@@ -485,7 +475,7 @@ void GenDiag::generateReport(raw_ostream &OS, const BinaryContext &BC) const {
485475
BinaryFunction *BF = RetInst.getFunction();
486476
BinaryBasicBlock *BB = RetInst.getBasicBlock();
487477

488-
OS << "\nGS-PACRET: " << "" << Diag.Text;
478+
OS << "\nGS-PACRET: " << Diag.Text;
489479
OS << " in function " << BF->getPrintName();
490480
if (BB)
491481
OS << ", basic block " << BB->getName();
@@ -501,7 +491,7 @@ Error Analysis::runOnFunctions(BinaryContext &BC) {
501491
};
502492

503493
ParallelUtilities::PredicateTy SkipFunc = [&](const BinaryFunction &BF) {
504-
return false; // BF.shouldPreserveNops();
494+
return false;
505495
};
506496

507497
ParallelUtilities::runOnEachFunctionWithUniqueAllocId(

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ f_detect_clobbered_x30_passed_to_other:
192192
// performs a tail call, that x30 might be attacker-controlled.
193193
// CHECK-NOT: function f_detect_clobbered_x30_passed_to_other
194194
b f_tail_called
195-
.size f_callclobbered_x30, .-f_callclobbered_x30
195+
.size f_detect_clobbered_x30_passed_to_other, .-f_detect_clobbered_x30_passed_to_other
196196

197197
.globl f_tail_called
198198
.type f_tail_called,@function

0 commit comments

Comments
 (0)