- 
                Notifications
    You must be signed in to change notification settings 
- Fork 13.9k
Closed
Labels
A-codegenArea: Code generationArea: Code generationA-linkageArea: linking into static, shared libraries and binariesArea: linking into static, shared libraries and binariesC-bugCategory: This is a bug.Category: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️P-highHigh priorityHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
The following code, when compiled in release mode with -C codegen-units=2 ICEs with the error below (I initially found this with the default 16 CGUs on a much larger codebase). I'm not entirely sure that the check at https://github.com/rust-lang/rust/blob/master/src/librustc_codegen_llvm/consts.rs#L236 is needed. However, if we're moving a reference to a static to a different CGU, we shouldn't define the static at all, but only declare it. Can we get rid of the match across Item or ForeignItem and treat all references to a static in a different CGU as if it were foreign, regardless of whether it was foreign in HIR?
error: internal compiler error: src/librustc_codegen_llvm/consts.rs:237: Conflicting symbol names for static?
--> src/main.rs:26:5
   |
26 |     pub static mut external: u32 = 0;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
mod a {
    extern "C" {
        #[no_mangle]
        pub static mut external: u32;
    }
    #[no_mangle]
    pub fn foo() {
        unsafe { dbg!(&external as *const u32); }
    }
}
mod b {
    mod c {
        #[no_mangle]
        pub fn bar() {
            unsafe { dbg!(&external as *const u32); }
        }
        use super::external;
    }
    pub use c::bar;
    #[no_mangle]
    pub static mut external: u32 = 0;
}
fn main() {
    a::foo();
    b::bar();
    chonky_func();
    chonky_func2();
}
fn chonky_func() {
    println!("We need to make the main module big enough");
    println!("so it forces c and a to get combined");
}
fn chonky_func2() {
    println!("Here's more stuff to print");
    println!("And more");
}Metadata
Metadata
Assignees
Labels
A-codegenArea: Code generationArea: Code generationA-linkageArea: linking into static, shared libraries and binariesArea: linking into static, shared libraries and binariesC-bugCategory: This is a bug.Category: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️P-highHigh priorityHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.