Closed
Description
When compiling a cargo project with:
- LTO enabled (
LTO=thin/fat
) - PGO (
-Cprofile-use
) - Both
lib
anddylib
targets for its library
Reproducer
// src/main.rs
use clap::Command;
fn main() {
Command::new("a").about("a");
}
# 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"]
There also needs to be an empty src/lib.rs
file. Here is a reproducer script for PGO:
#!/bin/bash
set -e
VERSION=${1:-1.71}
rustup install ${VERSION}
rustup component add llvm-tools-preview --toolchain ${VERSION}
rm -rf target
rm -rf /tmp/pgo
RUSTFLAGS="-Cprofile-generate=/tmp/pgo" cargo +${VERSION} build --release
./target/release/hello /tmp
`rustc +${VERSION} --print=sysroot`/lib/rustlib/x86_64-unknown-linux-gnu/bin/llvm-profdata merge -o merged-${VERSION}.profdata /tmp/pgo/*
RUSTFLAGS="-Cprofile-use=${PWD}/merged-${VERSION}.profdata" cargo +${VERSION} build --release
I expected to see this happen: the project compiles.
Instead, compilation fails with the following error:
module flag identifiers must be unique (or of 'require' type)
!"CG Profile"
LLVM ERROR: Broken module found, compilation aborted!
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
:
rustc 1.73.0 (cc66ad468 2023-10-03)
binary: rustc
commit-hash: cc66ad468955717ab92600c770da8c1601a4ff33
commit-date: 2023-10-03
host: x86_64-unknown-linux-gnu
release: 1.73.0
LLVM version: 17.0.2
I managed to reproduce this all the way back to 1.60.0
(although this specific example requires at least 1.70.0
due to clap
).
Metadata
Metadata
Assignees
Labels
Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Area: Link-time optimization (LTO)Category: This is a bug.Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.Relevant to the compiler team, which will review and decide on the PR/issue.