@@ -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-
6459namespace 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
447444void 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 << " \n GS-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 << " \n GS-PACRET: " << " " << Diag.Text ;
478+ OS << " \n GS-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 (
0 commit comments