diff options
| author | Wesley Wiser <wesleywiser@microsoft.com> | 2021-12-20 20:15:29 -0500 |
|---|---|---|
| committer | Wesley Wiser <wesleywiser@microsoft.com> | 2021-12-27 14:07:05 -0500 |
| commit | ebc0d0d2a849ebf4cdca5f8cd4ce52d67a725bf6 (patch) | |
| tree | 79ce1aaa1c61d66e37db670fc4833067fc0b6db2 /compiler/rustc_monomorphize/src | |
| parent | ef57f249a2244634a5c98d431d3bbfd715bd9c89 (diff) | |
| download | rust-ebc0d0d2a849ebf4cdca5f8cd4ce52d67a725bf6.tar.gz rust-ebc0d0d2a849ebf4cdca5f8cd4ce52d67a725bf6.zip | |
Address review comments
Diffstat (limited to 'compiler/rustc_monomorphize/src')
| -rw-r--r-- | compiler/rustc_monomorphize/src/partitioning/mod.rs | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/compiler/rustc_monomorphize/src/partitioning/mod.rs b/compiler/rustc_monomorphize/src/partitioning/mod.rs index 463c2135364..67597a0d7b4 100644 --- a/compiler/rustc_monomorphize/src/partitioning/mod.rs +++ b/compiler/rustc_monomorphize/src/partitioning/mod.rs @@ -205,17 +205,33 @@ pub fn partition<'tcx>( tcx.sess.instrument_coverage() && !tcx.sess.instrument_coverage_except_unused_functions(); if instrument_dead_code { + assert!( + post_inlining.codegen_units.len() > 0, + "There must be at least one CGU that code coverage data can be generated in." + ); + // Find the smallest CGU that has exported symbols and put the dead // function stubs in that CGU. We look for exported symbols to increase - // the likelyhood the linker won't throw away the dead functions. - let mut cgus_with_exported_symbols: Vec<_> = post_inlining - .codegen_units - .iter_mut() + // the likelihood the linker won't throw away the dead functions. + // FIXME(#92165): In order to truly resolve this, we need to make sure + // the object file (CGU) containing the dead function stubs is included + // in the final binary. This will probably require forcing these + // function symbols to be included via `-u` or `/include` linker args. + let mut cgus: Vec<_> = post_inlining.codegen_units.iter_mut().collect(); + cgus.sort_by_key(|cgu| cgu.size_estimate()); + + let dead_code_cgu = if let Some(cgu) = cgus + .into_iter() + .rev() .filter(|cgu| cgu.items().iter().any(|(_, (linkage, _))| *linkage == Linkage::External)) - .collect(); - cgus_with_exported_symbols.sort_by_key(|cgu| cgu.size_estimate()); - - let dead_code_cgu = cgus_with_exported_symbols.last_mut().unwrap(); + .next() + { + cgu + } else { + // If there are no CGUs that have externally linked items, + // then we just pick the first CGU as a fallback. + &mut post_inlining.codegen_units[0] + }; dead_code_cgu.make_code_coverage_dead_code_cgu(); } |
