Skip to content

Commit c8b83ba

Browse files
committed
Keep codegen units unmerged when building compiler builtins
1 parent 733f104 commit c8b83ba

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

src/librustc_mir/monomorphize/partitioning.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -455,11 +455,18 @@ fn default_visibility(tcx: TyCtxt<'_>, id: DefId, is_generic: bool) -> Visibilit
455455
fn merge_codegen_units<'tcx>(
456456
tcx: TyCtxt<'tcx>,
457457
initial_partitioning: &mut PreInliningPartitioning<'tcx>,
458-
target_cgu_count: usize,
458+
mut target_cgu_count: usize,
459459
) {
460460
assert!(target_cgu_count >= 1);
461461
let codegen_units = &mut initial_partitioning.codegen_units;
462462

463+
if tcx.is_compiler_builtins(LOCAL_CRATE) {
464+
// Compiler builtins require some degree of control over how mono items
465+
// are partitioned into compilation units. Provide it by keeping the
466+
// original partitioning when compiling the compiler builtins crate.
467+
target_cgu_count = codegen_units.len();
468+
}
469+
463470
// Note that at this point in time the `codegen_units` here may not be in a
464471
// deterministic order (but we know they're deterministically the same set).
465472
// We want this merging to produce a deterministic ordering of codegen units
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Verifies that during compiler_builtins compilation the codegen units are kept
2+
// unmerged. Even when only a single codegen unit is requested with -Ccodegen-units=1.
3+
//
4+
// compile-flags: -Zprint-mono-items=eager -Ccodegen-units=1
5+
6+
#![compiler_builtins]
7+
#![crate_type="lib"]
8+
#![feature(compiler_builtins)]
9+
10+
mod atomics {
11+
//~ MONO_ITEM fn compiler_builtins::atomics[0]::sync_1[0] @@ compiler_builtins-cgu.0[External]
12+
#[no_mangle]
13+
pub extern "C" fn sync_1() {}
14+
15+
//~ MONO_ITEM fn compiler_builtins::atomics[0]::sync_2[0] @@ compiler_builtins-cgu.0[External]
16+
#[no_mangle]
17+
pub extern "C" fn sync_2() {}
18+
19+
//~ MONO_ITEM fn compiler_builtins::atomics[0]::sync_3[0] @@ compiler_builtins-cgu.0[External]
20+
#[no_mangle]
21+
pub extern "C" fn sync_3() {}
22+
}
23+
24+
mod x {
25+
//~ MONO_ITEM fn compiler_builtins::x[0]::x[0] @@ compiler_builtins-cgu.1[External]
26+
#[no_mangle]
27+
pub extern "C" fn x() {}
28+
}
29+
30+
mod y {
31+
//~ MONO_ITEM fn compiler_builtins::y[0]::y[0] @@ compiler_builtins-cgu.2[External]
32+
#[no_mangle]
33+
pub extern "C" fn y() {}
34+
}
35+
36+
mod z {
37+
//~ MONO_ITEM fn compiler_builtins::z[0]::z[0] @@ compiler_builtins-cgu.3[External]
38+
#[no_mangle]
39+
pub extern "C" fn z() {}
40+
}

0 commit comments

Comments
 (0)