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

LTO, alloc and debug compilation problem #109934

Closed
kaczmarczyck opened this issue Apr 4, 2023 · 3 comments · Fixed by #111167
Closed

LTO, alloc and debug compilation problem #109934

kaczmarczyck opened this issue Apr 4, 2023 · 3 comments · Fixed by #111167
Assignees
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@kaczmarczyck
Copy link

kaczmarczyck commented Apr 4, 2023

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.

@kaczmarczyck kaczmarczyck added the C-bug Category: This is a bug. label Apr 4, 2023
@nikic
Copy link
Contributor

nikic commented Apr 4, 2023

Initial reduction for llc -filetype=obj: https://gist.github.com/nikic/6f60958ed4295f0bcd48797b5e541aba

@nikic
Copy link
Contributor

nikic commented Apr 4, 2023

Filed llvm/llvm-project#61932.

@nikic nikic added the A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. label Apr 4, 2023
@Nilstrieb Nilstrieb added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Apr 5, 2023
@cuviper
Copy link
Member

cuviper commented May 3, 2023

In https://reviews.llvm.org/D147620, dblaikie suggests that rustc ought to separate the type-method declaration from the function definition, and I think I have that working. It passes the reproducer here, at least...

@rustbot claim

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue May 6, 2023
…michaelwoerister

debuginfo: split method declaration and definition

When we're adding a method to a type DIE, we only want a DW_AT_declaration
there, because LLVM LTO can't unify type definitions when a child DIE is a
full subprogram definition. Now the subprogram definition gets added at the
CU level with a specification link back to the abstract declaration.

Both GCC and Clang write debuginfo this way for C++ class methods.

Fixes rust-lang#109730.
Fixes rust-lang#109934.
@bors bors closed this as completed in f440999 May 6, 2023
ia0 referenced this issue in google/OpenSK Sep 18, 2023
* Removes redundant entries from Cargo.toml

This also fixes a compilation problem we have in debug mode with LTO
enabled.

* fix output-path triple dash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants