Fix cross crate static duplicate codegen
This commit is contained in:
parent
2a20cc0b94
commit
ce860e5fde
4 changed files with 13 additions and 2 deletions
|
@ -529,3 +529,5 @@ pub macro line() { /* compiler built-in */ }
|
|||
#[rustc_builtin_macro]
|
||||
#[rustc_macro_transparency = "semitransparent"]
|
||||
pub macro cfg() { /* compiler built-in */ }
|
||||
|
||||
pub static A_STATIC: u8 = 42;
|
||||
|
|
|
@ -261,4 +261,7 @@ fn main() {
|
|||
let f2 = -1000.0;
|
||||
assert_eq!(f2 as i8, -128);
|
||||
assert_eq!(f2 as u8, 0);
|
||||
|
||||
static ANOTHER_STATIC: &u8 = &A_STATIC;
|
||||
assert_eq!(*ANOTHER_STATIC, 42);
|
||||
}
|
||||
|
|
|
@ -297,6 +297,10 @@ fn define_all_allocs(
|
|||
read_target_uint(endianness, bytes).unwrap()
|
||||
};
|
||||
|
||||
// Don't inline `reloc_target_alloc` into the match. That would cause `tcx.alloc_map`
|
||||
// to be locked for the duration of the match. `data_id_for_static` however may try
|
||||
// to lock `tcx.alloc_map` itself while calculating the layout of the target static.
|
||||
// This would cause a panic in single threaded rustc and a deadlock for parallel rustc.
|
||||
let reloc_target_alloc = tcx.alloc_map.lock().get(reloc).unwrap();
|
||||
let data_id = match reloc_target_alloc {
|
||||
GlobalAlloc::Function(instance) => {
|
||||
|
@ -311,7 +315,9 @@ fn define_all_allocs(
|
|||
data_id_for_alloc_id(module, reloc, alloc.align)
|
||||
}
|
||||
GlobalAlloc::Static(def_id) => {
|
||||
cx.todo.insert(TodoItem::Static(def_id));
|
||||
// Don't push a `TodoItem::Static` here, as it will cause statics used by
|
||||
// multiple crates to be duplicated between them. It isn't necessary anyway,
|
||||
// as it will get pushed by `codegen_static` when necessary.
|
||||
let linkage = crate::linkage::get_static_ref_linkage(tcx, def_id);
|
||||
data_id_for_static(tcx, module, def_id, linkage)
|
||||
}
|
||||
|
|
2
test.sh
2
test.sh
|
@ -26,7 +26,7 @@ rm -r target/out || true
|
|||
mkdir -p target/out/clif
|
||||
|
||||
echo "[BUILD] mini_core"
|
||||
$RUSTC example/mini_core.rs --crate-name mini_core --crate-type dylib
|
||||
$RUSTC example/mini_core.rs --crate-name mini_core --crate-type lib,dylib
|
||||
|
||||
echo "[BUILD] example"
|
||||
$RUSTC example/example.rs --crate-type lib
|
||||
|
|
Loading…
Add table
Reference in a new issue