Skip to content

Commit 40d0e6f

Browse files
authored
Rollup merge of rust-lang#71364 - Amanieu:zprofile_compiler_builtins, r=cramertj
Ignore -Zprofile when building compiler_builtins rust-lang#70846 made the `compiler_builtins` crate ignore the default codegen-units setting and instead always split each function into a different codegen unit. This unfortunately breaks `-Zprofile` which requires a single codegen unit per crate (see rust-lang#71283). You can notice this when building with `cargo -Zbuild-std` and `RUSTFLAGS` containing `-Zprofile`. This PR works around this issue by just ignoring `-Zprofile` for the `compiler-builtins` crate.
2 parents 6013c23 + 3eb1c43 commit 40d0e6f

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

src/librustc_codegen_ssa/back/write.rs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,12 @@ pub struct ModuleConfig {
119119
}
120120

121121
impl ModuleConfig {
122-
fn new(kind: ModuleKind, sess: &Session, no_builtins: bool) -> ModuleConfig {
122+
fn new(
123+
kind: ModuleKind,
124+
sess: &Session,
125+
no_builtins: bool,
126+
is_compiler_builtins: bool,
127+
) -> ModuleConfig {
123128
// If it's a regular module, use `$regular`, otherwise use `$other`.
124129
// `$regular` and `$other` are evaluated lazily.
125130
macro_rules! if_regular {
@@ -160,7 +165,10 @@ impl ModuleConfig {
160165
passes: if_regular!(
161166
{
162167
let mut passes = sess.opts.cg.passes.clone();
163-
if sess.opts.debugging_opts.profile {
168+
// compiler_builtins overrides the codegen-units settings,
169+
// which is incompatible with -Zprofile which requires that
170+
// only a single codegen unit is used per crate.
171+
if sess.opts.debugging_opts.profile && !is_compiler_builtins {
164172
passes.push("insert-gcov-profiling".to_owned());
165173
}
166174
passes
@@ -406,6 +414,8 @@ pub fn start_async_codegen<B: ExtraBackendMethods>(
406414
let crate_name = tcx.crate_name(LOCAL_CRATE);
407415
let crate_hash = tcx.crate_hash(LOCAL_CRATE);
408416
let no_builtins = attr::contains_name(&tcx.hir().krate().item.attrs, sym::no_builtins);
417+
let is_compiler_builtins =
418+
attr::contains_name(&tcx.hir().krate().item.attrs, sym::compiler_builtins);
409419
let subsystem =
410420
attr::first_attr_value_str_by_name(&tcx.hir().krate().item.attrs, sym::windows_subsystem);
411421
let windows_subsystem = subsystem.map(|subsystem| {
@@ -422,9 +432,12 @@ pub fn start_async_codegen<B: ExtraBackendMethods>(
422432
let linker_info = LinkerInfo::new(tcx);
423433
let crate_info = CrateInfo::new(tcx);
424434

425-
let regular_config = ModuleConfig::new(ModuleKind::Regular, sess, no_builtins);
426-
let metadata_config = ModuleConfig::new(ModuleKind::Metadata, sess, no_builtins);
427-
let allocator_config = ModuleConfig::new(ModuleKind::Allocator, sess, no_builtins);
435+
let regular_config =
436+
ModuleConfig::new(ModuleKind::Regular, sess, no_builtins, is_compiler_builtins);
437+
let metadata_config =
438+
ModuleConfig::new(ModuleKind::Metadata, sess, no_builtins, is_compiler_builtins);
439+
let allocator_config =
440+
ModuleConfig::new(ModuleKind::Allocator, sess, no_builtins, is_compiler_builtins);
428441

429442
let (shared_emitter, shared_emitter_main) = SharedEmitter::new();
430443
let (codegen_worker_send, codegen_worker_receive) = channel();

0 commit comments

Comments
 (0)