Skip to content

LTO, alloc and debug compilation problem #109934

Closed
@kaczmarczyck

Description

@kaczmarczyck

If you combine LTO, anything that uses alloc and debug compilation mode, the compiler fails.
The minimum example to reproduce is this src/lib.rs:

extern crate alloc;

#[cfg(test)]
mod tests {
    #[test]
    fn something_alloc() {
        assert_eq!(Vec::<u32>::new(), Vec::<u32>::new());
    }
}

With this Cargo.toml:

[package]
name = "lto_bug"
version = "0.0.1"
edition = "2018"

[profile.dev]
lto = true

[profile.release]
lto = true

To reproduce, run (or just use +nightly):

cargo +nightly-2023-03-26 test

You should see this error:

error: Cannot represent a difference across sections

The above error does not reproduce for other compiler versions or options, all of the below work:

cargo +nightly test --release
cargo +nightly-2023-03-25 test
cargo +stable test

I found #109730 reporting something similar, but for them --release is throwing the error, so I opened a new issue instead.

Metadata

Metadata

Assignees

Labels

A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.C-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions