@@ -197,34 +197,8 @@ where
197
197
198
198
let instrument_dead_code =
199
199
tcx. sess . instrument_coverage ( ) && !tcx. sess . instrument_coverage_except_unused_functions ( ) ;
200
-
201
200
if instrument_dead_code {
202
- assert ! (
203
- codegen_units. len( ) > 0 ,
204
- "There must be at least one CGU that code coverage data can be generated in."
205
- ) ;
206
-
207
- // Find the smallest CGU that has exported symbols and put the dead
208
- // function stubs in that CGU. We look for exported symbols to increase
209
- // the likelihood the linker won't throw away the dead functions.
210
- // FIXME(#92165): In order to truly resolve this, we need to make sure
211
- // the object file (CGU) containing the dead function stubs is included
212
- // in the final binary. This will probably require forcing these
213
- // function symbols to be included via `-u` or `/include` linker args.
214
- let mut cgus: Vec < _ > = codegen_units. iter_mut ( ) . collect ( ) ;
215
- cgus. sort_by_key ( |cgu| cgu. size_estimate ( ) ) ;
216
-
217
- let dead_code_cgu =
218
- if let Some ( cgu) = cgus. into_iter ( ) . rev ( ) . find ( |cgu| {
219
- cgu. items ( ) . iter ( ) . any ( |( _, ( linkage, _) ) | * linkage == Linkage :: External )
220
- } ) {
221
- cgu
222
- } else {
223
- // If there are no CGUs that have externally linked items,
224
- // then we just pick the first CGU as a fallback.
225
- & mut codegen_units[ 0 ]
226
- } ;
227
- dead_code_cgu. make_code_coverage_dead_code_cgu ( ) ;
201
+ mark_code_coverage_dead_code_cgu ( & mut codegen_units) ;
228
202
}
229
203
230
204
// Ensure CGUs are sorted by name, so that we get deterministic results.
@@ -545,6 +519,33 @@ fn internalize_symbols<'tcx>(
545
519
}
546
520
}
547
521
522
+ fn mark_code_coverage_dead_code_cgu < ' tcx > ( codegen_units : & mut [ CodegenUnit < ' tcx > ] ) {
523
+ assert ! ( !codegen_units. is_empty( ) ) ;
524
+
525
+ // Find the smallest CGU that has exported symbols and put the dead
526
+ // function stubs in that CGU. We look for exported symbols to increase
527
+ // the likelihood the linker won't throw away the dead functions.
528
+ // FIXME(#92165): In order to truly resolve this, we need to make sure
529
+ // the object file (CGU) containing the dead function stubs is included
530
+ // in the final binary. This will probably require forcing these
531
+ // function symbols to be included via `-u` or `/include` linker args.
532
+ let mut cgus: Vec < & mut CodegenUnit < ' tcx > > = codegen_units. iter_mut ( ) . collect ( ) ;
533
+ cgus. sort_by_key ( |cgu| cgu. size_estimate ( ) ) ;
534
+
535
+ let dead_code_cgu = if let Some ( cgu) = cgus
536
+ . into_iter ( )
537
+ . rev ( )
538
+ . find ( |cgu| cgu. items ( ) . iter ( ) . any ( |( _, ( linkage, _) ) | * linkage == Linkage :: External ) )
539
+ {
540
+ cgu
541
+ } else {
542
+ // If there are no CGUs that have externally linked items,
543
+ // then we just pick the first CGU as a fallback.
544
+ & mut codegen_units[ 0 ]
545
+ } ;
546
+ dead_code_cgu. make_code_coverage_dead_code_cgu ( ) ;
547
+ }
548
+
548
549
fn characteristic_def_id_of_mono_item < ' tcx > (
549
550
tcx : TyCtxt < ' tcx > ,
550
551
mono_item : MonoItem < ' tcx > ,
0 commit comments