Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ICE: Can't combine functions in the same CGU that reference both a static and an extern static with the same name #66464

Closed
rinon opened this issue Nov 16, 2019 · 1 comment · Fixed by #66534
Labels
A-codegen Area: Code generation A-linkage Area: linking into static, shared libraries and binaries C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-high High priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@rinon
Copy link
Contributor

rinon commented Nov 16, 2019

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");
}
@rinon rinon changed the title ICE: Can't combine functions in the same CGI that reference both a static and an extern static with the same name ICE: Can't combine functions in the same CGU that reference both a static and an extern static with the same name Nov 16, 2019
@jonas-schievink jonas-schievink added A-codegen Area: Code generation A-linkage Area: linking into static, shared libraries and binaries C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. I-nominated labels Nov 16, 2019
@pnkfelix
Copy link
Member

triage: has PR; P-high, removing nomination

@pnkfelix pnkfelix added P-high High priority and removed I-nominated labels Nov 21, 2019
rinon added a commit to immunant/c2rust-testsuite that referenced this issue Nov 23, 2019
Reorg also works for nginx and python2, but the rust compiler ICEs when
compiling the resulting code, see rust-lang/rust#66464
tmandry added a commit to tmandry/rust that referenced this issue Nov 27, 2019
…ddyb

Allow global references via ForeignItem and Item for the same symbol name during LLVM codegen

Combining CGUs can result in code that references a static variable through both
an Item and a ForeignItem with the same name. We don't care that the global was
already created by a ForeignItem reference when we see the Item reference, as
long as the LLVM types of the ForeignItem and Item match.

Fixes rust-lang#66464
@bors bors closed this as completed in 32168a3 Nov 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-codegen Area: Code generation A-linkage Area: linking into static, shared libraries and binaries C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-high High priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
3 participants