@@ -230,12 +230,11 @@ struct SrcState {
230230 bool operator !=(const SrcState &RHS) const { return !((*this ) == RHS); }
231231};
232232
233- static void
234- printLastInsts (raw_ostream &OS,
235- ArrayRef<SmallPtrSet<const MCInst *, 4 >> LastInstWritingReg) {
233+ static void printInstsShort (raw_ostream &OS,
234+ ArrayRef<SmallPtrSet<const MCInst *, 4 >> Insts) {
236235 OS << " Insts: " ;
237- for (unsigned I = 0 ; I < LastInstWritingReg .size (); ++I) {
238- auto &Set = LastInstWritingReg [I];
236+ for (unsigned I = 0 ; I < Insts .size (); ++I) {
237+ auto &Set = Insts [I];
239238 OS << " [" << I << " ](" ;
240239 for (const MCInst *MCInstP : Set)
241240 OS << MCInstP << " " ;
@@ -250,7 +249,7 @@ raw_ostream &operator<<(raw_ostream &OS, const SrcState &S) {
250249 } else {
251250 OS << " SafeToDerefRegs: " << S.SafeToDerefRegs << " , " ;
252251 OS << " TrustedRegs: " << S.TrustedRegs << " , " ;
253- printLastInsts (OS, S.LastInstWritingReg );
252+ printInstsShort (OS, S.LastInstWritingReg );
254253 }
255254 OS << " >" ;
256255 return OS;
@@ -279,7 +278,7 @@ void SrcStatePrinter::print(raw_ostream &OS, const SrcState &S) const {
279278 OS << " , TrustedRegs: " ;
280279 RegStatePrinter.print (OS, S.TrustedRegs );
281280 OS << " , " ;
282- printLastInsts (OS, S.LastInstWritingReg );
281+ printInstsShort (OS, S.LastInstWritingReg );
283282 }
284283 OS << " >" ;
285284}
@@ -752,7 +751,7 @@ SrcSafetyAnalysis::create(BinaryFunction &BF,
752751struct DstState {
753752 // / The set of registers whose values cannot be inspected by an attacker in
754753 // / a way usable as an authentication oracle. The results of authentication
755- // / instructions should be written to such registers.
754+ // / instructions should only be written to such registers.
756755 BitVector CannotEscapeUnchecked;
757756
758757 std::vector<SmallPtrSet<const MCInst *, 4 >> FirstInstLeakingReg;
@@ -770,6 +769,9 @@ struct DstState {
770769 return (*this = StateIn);
771770
772771 CannotEscapeUnchecked &= StateIn.CannotEscapeUnchecked ;
772+ for (unsigned I = 0 ; I < FirstInstLeakingReg.size (); ++I)
773+ for (const MCInst *J : StateIn.FirstInstLeakingReg [I])
774+ FirstInstLeakingReg[I].insert (J);
773775 return *this ;
774776 }
775777
@@ -778,7 +780,8 @@ struct DstState {
778780 bool empty () const { return CannotEscapeUnchecked.empty (); }
779781
780782 bool operator ==(const DstState &RHS) const {
781- return CannotEscapeUnchecked == RHS.CannotEscapeUnchecked ;
783+ return CannotEscapeUnchecked == RHS.CannotEscapeUnchecked &&
784+ FirstInstLeakingReg == RHS.FirstInstLeakingReg ;
782785 }
783786 bool operator !=(const DstState &RHS) const { return !((*this ) == RHS); }
784787};
@@ -788,7 +791,8 @@ raw_ostream &operator<<(raw_ostream &OS, const DstState &S) {
788791 if (S.empty ()) {
789792 OS << " empty" ;
790793 } else {
791- OS << " CannotEscapeUnchecked: " << S.CannotEscapeUnchecked ;
794+ OS << " CannotEscapeUnchecked: " << S.CannotEscapeUnchecked << " , " ;
795+ printInstsShort (OS, S.FirstInstLeakingReg );
792796 }
793797 OS << " >" ;
794798 return OS;
@@ -808,10 +812,13 @@ void DstStatePrinter::print(raw_ostream &OS, const DstState &S) const {
808812 OS << " dst-state<" ;
809813 if (S.empty ()) {
810814 assert (S.CannotEscapeUnchecked .empty ());
815+ assert (S.FirstInstLeakingReg .empty ());
811816 OS << " empty" ;
812817 } else {
813818 OS << " CannotEscapeUnchecked: " ;
814819 RegStatePrinter.print (OS, S.CannotEscapeUnchecked );
820+ OS << " , " ;
821+ printInstsShort (OS, S.FirstInstLeakingReg );
815822 }
816823 OS << " >" ;
817824}
@@ -841,6 +848,7 @@ class DstSafetyAnalysis {
841848 const unsigned NumRegs;
842849
843850 const TrackedRegisters RegsToTrackInstsFor;
851+
844852 // / Stores information about the detected instruction sequences emitted to
845853 // / check an authenticated pointer. Specifically, if such sequence is detected
846854 // / in a basic block, it maps the first instruction of that sequence to the
@@ -897,7 +905,6 @@ class DstSafetyAnalysis {
897905 const BitVector &LeakedRegs,
898906 const DstState &Cur) const {
899907 SmallVector<MCPhysReg> Regs;
900- const MCPhysReg NoReg = BC.MIB ->getNoRegister ();
901908
902909 // A pointer can be checked, or
903910 if (auto CheckedReg =
@@ -911,7 +918,7 @@ class DstSafetyAnalysis {
911918 bool IsAuthenticated;
912919 MCPhysReg BranchDestReg =
913920 BC.MIB ->getRegUsedAsIndirectBranchDest (Inst, IsAuthenticated);
914- assert (BranchDestReg != NoReg );
921+ assert (BranchDestReg != BC. MIB -> getNoRegister () );
915922 if (!IsAuthenticated)
916923 Regs.push_back (BranchDestReg);
917924 }
0 commit comments