-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Combining LTO + PGO + lib/cdylib crashes on LLVM assertion #117220
Comments
@rustbot label T-compiler A-lto A-llvm I-crash |
I can reproduce the issue either with the # Cargo.toml
[package]
name = "hello"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
clap = { version = "=4.3.24" , default-features = false, features = ["std"]}
[profile.release]
lto = "thin"
[lib]
crate-type = ["lib", "cdylib"] Cargo.lock
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "anstyle"
version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "038dfcf04a5feb68e9c60b21c9625a54c2c0616e79b72b0fd87075a056ae1d1b"
[[package]]
name = "clap"
version = "4.3.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fb690e81c7840c0d7aade59f242ea3b41b9bc27bcd5997890e7702ae4b32e487"
dependencies = [
"clap_builder",
]
[[package]]
name = "clap_builder"
version = "4.3.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5ed2e96bc16d8d740f6f48d663eddf4b8a0983e79210fd55479b7bcd0a69860e"
dependencies = [
"anstyle",
"clap_lex",
]
[[package]]
name = "clap_lex"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cd7cc57abe963c6d3b9d8be5b06ba7c8957a930305ca90304f24ef040aa6f961"
[[package]]
name = "hello"
version = "0.1.0"
dependencies = [
"clap",
] |
Minimal ReproductionFirst, let me provide a minimal reproduction: # Cargo.toml
[package]
name = "hello"
version = "0.1.0"
edition = "2021"
[profile.release]
lto = "fat" # "thin" is also ok.
[lib]
crate-type = ["lib", "cdylib"] // src/lib.rs
pub fn foo() {
let mut v = Vec::new();
v.push(1);
} // src/main.rs
fn main() {
hello::foo();
} Next, run the PGO script similar to the one described in the issue. WhyWhat LLVM DidThe LLVM error indicates that we created two This happens because every time we effectively run A simple example: https://llvm.godbolt.org/z/5bzeh6e77. For me, running it multiple times might lead to unexpected behavior, and I'm not sure if the data can be merged or ignored here. cc @nikic What rustc/cargo DidThe key point now is understanding why we are running rustc src/lib.rs --crate-type lib --crate-type cdylib -Cprofile-use=merged.profdata
rustc src/main.rs --crate-type bin -C lto=fat --extern hello=/path/libhello.rlib -Cprofile-use=merged.profdata
Because we did not pass How to FixI believe the key is that
Perhaps we should split this into two separate Discovery Process
A brief description:
|
It seems to be happening with sccache Using:
Rust version: 1.81.0-nightly (6b0f4b5 2024-06-24) |
Yes. That is rust-lang/cargo#9672. |
So do we have to execute multiple crate types in the one command? What about compile time? Can we split it into multiple commands when encountering unsupported parameter scenarios? |
I can't reproduce it with the following command. Do you have more detailed reproduction steps? rustup install nightly-2024-06-25
rustup +nightly-2024-06-25 component add llvm-tools
cargo +nightly-2024-06-25 pgo instrument build -- --no-default-features
./target/x86_64-unknown-linux-gnu/release/sccache --show-stats
cargo +nightly-2024-06-25 pgo optimize build -- --no-default-features |
Thanks, this seems feasible. However, I've reconsidered the issue. Since rustc allows passing multiple crate types, it should support passing the corresponding parameters. |
@DianQK I'm sorry for the delay. I got angry trying to make LTO + PGO work and ended up deleting the folder with the scripts to reproduce it. But I have found that the problem with finding duplicated !"CG Profile" module flag identifier can sometimes be avoided by using thin LTO. See my post below. |
Ruff LTO + PGO + CODEGEN UNITS 1 works only if LTO is Thin LTO. FULL Linker-plugin-based LTO + PGO + CODEGEN UNITS 1. LLVM error indicating duplicated !"CG Profile" module flag identifier:
THIN Linker-plugin-based LTO + PGO + CODEGEN UNITS 1. Successful build:
|
Using |
Thank you for your response. Based on https://github.com/astral-sh/ruff/blob/4cc7bc9d32047b4f47b944636af449a9d24cbaac/crates/ruff_wasm/Cargo.toml#L15, I believe this is the same issue. |
Could be... I'm going to test later, but I'm almost sure that ruff_wasm is the library for exposing Ruff functionality to the web (as a wasm module) (https://play.ruff.rs/) and does not get built when |
@insilications did you manage to investigate any future about this error? |
[WIP] The embedded bitcode should always be prepared for LTO/ThinLTO Fixes rust-lang#115344. Fixes rust-lang#117220. r? ghost
[WIP] The embedded bitcode should always be prepared for LTO/ThinLTO Fixes rust-lang#115344. Fixes rust-lang#117220. r? ghost
When compiling a cargo project with:
LTO=thin/fat
)-Cprofile-use
)lib
anddylib
targets for its libraryReproducer
There also needs to be an empty
src/lib.rs
file. Here is a reproducer script for PGO:I expected to see this happen: the project compiles.
Instead, compilation fails with the following error:
This was originally found in #115344, which contains many examples of this problem in the wild. Here I sent a minimal example, I wasn't able to minimize it further (removing LTO, PGO, clap or lib/dylib) fixes the problem.
Meta
rustc --version --verbose
:I managed to reproduce this all the way back to
1.60.0
(although this specific example requires at least1.70.0
due toclap
).The text was updated successfully, but these errors were encountered: