@@ -31,10 +31,7 @@ using namespace llvm;
3131namespace llvm {
3232namespace bolt {
3333
34- void MarkRAStates::runOnFunction (BinaryFunction &BF) {
35-
36- if (BF.isIgnored ())
37- return ;
34+ bool MarkRAStates::runOnFunction (BinaryFunction &BF) {
3835
3936 BinaryContext &BC = BF.getBinaryContext ();
4037
@@ -49,10 +46,9 @@ void MarkRAStates::runOnFunction(BinaryFunction &BF) {
4946 // annotation.
5047 BF.setIgnored ();
5148 BC.outs () << " BOLT-INFO: inconsistent RAStates in function "
52- << BF.getPrintName () << " \n " ;
53- BC.outs ()
54- << " BOLT-INFO: ptr sign/auth inst without .cfi_negate_ra_state\n " ;
55- return ;
49+ << BF.getPrintName ()
50+ << " : ptr sign/auth inst without .cfi_negate_ra_state\n " ;
51+ return false ;
5652 }
5753 }
5854 }
@@ -72,11 +68,10 @@ void MarkRAStates::runOnFunction(BinaryFunction &BF) {
7268 if (RAState) {
7369 // RA signing instructions should only follow unsigned RA state.
7470 BC.outs () << " BOLT-INFO: inconsistent RAStates in function "
75- << BF.getPrintName () << " \n " ;
76- BC.outs () << " BOLT-INFO: ptr signing inst encountered in Signed RA "
77- " state.\n " ;
71+ << BF.getPrintName ()
72+ << " : ptr signing inst encountered in Signed RA state\n " ;
7873 BF.setIgnored ();
79- return ;
74+ return false ;
8075 }
8176 // The signing instruction itself is unsinged, but the next will be
8277 // signed.
@@ -85,11 +80,11 @@ void MarkRAStates::runOnFunction(BinaryFunction &BF) {
8580 if (!RAState) {
8681 // RA authenticating instructions should only follow signed RA state.
8782 BC.outs () << " BOLT-INFO: inconsistent RAStates in function "
88- << BF.getPrintName () << " \n " ;
89- BC. outs () << " BOLT-INFO : ptr authenticating inst encountered in "
90- " Unsigned RA state. \n " ;
83+ << BF.getPrintName ()
84+ << " : ptr authenticating inst encountered in Unsigned RA "
85+ " state\n " ;
9186 BF.setIgnored ();
92- return ;
87+ return false ;
9388 }
9489 // The authenticating instruction itself is signed, but the next will be
9590 // unsigned.
@@ -120,23 +115,36 @@ void MarkRAStates::runOnFunction(BinaryFunction &BF) {
120115 }
121116 }
122117 }
118+ return true ;
123119}
124120
125121Error MarkRAStates::runOnFunctions (BinaryContext &BC) {
126122 ParallelUtilities::WorkFuncTy WorkFun = [&](BinaryFunction &BF) {
127- if (BF.containedNegateRAState ()) {
123+ if (BF.containedNegateRAState () && !BF. isIgnored () ) {
128124 // We can skip functions which did not include negate-ra-state CFIs. This
129125 // includes code using pac-ret hardening as well, if the binary is
130126 // compiled with `-fno-exceptions -fno-unwind-tables
131127 // -fno-asynchronous-unwind-tables`
132- runOnFunction (BF);
128+ if (!runOnFunction (BF)) {
129+ FunctionsIgnored++;
130+ }
133131 }
134132 };
135133
136134 ParallelUtilities::runOnEachFunction (
137135 BC, ParallelUtilities::SchedulingPolicy::SP_TRIVIAL, WorkFun, nullptr ,
138136 " MarkRAStates" );
139137
138+ int Total = llvm::count_if (
139+ BC.getBinaryFunctions (),
140+ [&](std::pair<const unsigned long , BinaryFunction> &P) {
141+ return P.second .containedNegateRAState () && !P.second .isIgnored ();
142+ });
143+ BC.outs () << " BOLT-INFO: MarkRAStates ran on " << Total
144+ << " functions. Ignored " << FunctionsIgnored << " functions "
145+ << format (" (%.2lf%%)" , (100.0 * FunctionsIgnored) / Total)
146+ << " because of CFI inconsistencies.\n " ;
147+
140148 return Error::success ();
141149}
142150
0 commit comments