[ICE]: CG Profile module flag mismatch when combining Cross-Language LTO and PGO (Bypasses PR #133250)
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
Description
When compiling a project that links against C-code (e.g. openssl-sys or <sysroot> compiler_builtins) using Cross-Language LTO (-C linker-plugin-lto) and Profile-Guided Optimization (-C profile-use), ld.lld crashes with an ICE: module flag identifiers must be unique !"CG Profile".
Note to developers: This appears to be a gap in PR #133250 (which previously closed #115344 and #117220). While that PR fixed the CG Profile ICE for pure-Rust cdylibs, it does not handle the Cross-Language LTO boundary. When PGO-tagged Rust bitcode is merged with un-instrumented C-bitcode from the sysroot or external crates, the LTO linker detects the mismatched tags and panics.
I originally thought I could bypass this crash by recompiling the standard library from scratch using -Zbuild-std=std,panic_abort (and RUSTC_BOOTSTRAP=1), hoping that compiler_builtins would inherit my PGO tags and align with the rest of the bitcode. But that didnt help.
I'm guessing this is because when compiler builtin is rebuilt with Z build-std=std, it doesnt inherit its flags from CFLAGS, but it instead takes from RUSTFLAGS, thats probably how -Cprofile-generate/-Cprofile-use got dropped
I also tried explicitly passing -fprofile-generate and -fprofile-use into CFLAGS to ensure the C-code dependencies were properly instrumented and reading from the exact same .profdata profile. No luck with this approach as well.
Code
This can be consistently reproduced using the uutils/coreutils repository, which provides a native PGO script.
git clone https://github.com/uutils/coreutils
cd coreutils
# 1. Generate the PGO training profile using Clang
CC=clang CXX=clang++ ./util/build-pgo.sh --train-only --features "feat_os_unix_musl,openssl"
# 2. Attempt the final optimized build with Cross-Language LTO
CC=clang CXX=clang++ RUSTFLAGS="-C target-cpu=native -C opt-level=3 -C linker=clang -Clink-arg=-fuse-ld=lld -C linker-plugin-lto -C profile-use=$(pwd)/target/coreutils-pgo/coreutils.profdata" cargo build --release --features "feat_os_unix_musl,openssl"
Meta
rustc --version --verbose:
rustc 1.98.1 (48a229cea 2026-09-01) (Arch Linux rust 1:1.98.1-1.1)
binary: rustc
commit-hash: 48a229ceaefd4985c50990b14116b6d856af0985
commit-date: 2026-09-01
host: x86_64-unknown-linux-gnu
release: 1.98.1
LLVM version: 22.1.8
Error output
error: linking with `clang` failed: exit status: 1
|
= note: "clang" "-m64" "<1 object files omitted>" "-Wl,--as-needed" "-Wl,-Bstatic" "/home/elseawhy/Git/coreutils/target/release/deps/rustcAkanTO/{libopenssl_sys-ac172d1f43374587,libblake3-5c04a81a78a831a8}.rlib" "<sysroot>/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-*.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-L" "/home/elseawhy/Git/coreutils/target/release/deps/rustcAkanTO/raw-dylibs" "-Wl,--eh-frame-hdr" "-Wl,-z,noexecstack" "-Wl,-plugin-opt=O3,-plugin-opt=mcpu=znver3" "-L" "/home/elseawhy/Git/coreutils/target/release/build/blake3-76f3001f371640dd/out" "-L" "/home/elseawhy/Git/coreutils/target/release/build/openssl-sys-d73ae4983a91140b/out/openssl-build/install/lib" "-L" "<sysroot>/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "/home/elseawhy/Git/coreutils/target/release/deps/coreutils-8c86373a7a3fec71" "-Wl,--gc-sections" "-pie" "-Wl,-z,relro,-z,now" "-Wl,-O1" "-Wl,--strip-debug" "-nodefaultlibs" "-fuse-ld=lld"
= note: some arguments are omitted. use `--verbose` to show all linker arguments
= note: module flag identifiers must be unique (or of 'require' type)
!"CG Profile"
LLVM ERROR: Broken module found, compilation aborted!
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and instructions to reproduce the bug.
Backtrace
Stack dump:
0. Program arguments: /usr/bin/ld.lld --hash-style=gnu --build-id --eh-frame-hdr -m elf_x86_64 -pie -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o /home/elseawhy/Git/coreutils/target/release/deps/coreutils-8c86373a7a3fec71 /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/16/../../../../lib64/Scrt1.o /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/16/../../../../lib64/crti.o /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/16/crtbeginS.o -L/home/elseawhy/Git/coreutils/target/release/deps/rustcAkanTO/raw-dylibs -L/home/elseawhy/Git/coreutils/target/release/build/blake3-76f3001f371640dd/out -L/home/elseawhy/Git/coreutils/target/release/build/openssl-sys-d73ae4983a91140b/out/openssl-build/install/lib -L/usr/lib/rustlib/x86_64-unknown-linux-gnu/lib -L/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/16 -L/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/16/../../../../lib64 -L/lib/../lib64 -L/usr/lib64 -L/lib -L/usr/lib /home/elseawhy/Git/coreutils/target/release/deps/coreutils-8c86373a7a3fec71.coreutils.8796f4b63ffd8884-cgu.0.rcgu.o --as-needed -Bstatic /home/elseawhy/Git/coreutils/target/release/deps/rustcAkanTO/libopenssl_sys-ac172d1f43374587.rlib /home/elseawhy/Git/coreutils/target/release/deps/rustcAkanTO/libblake3-5c04a81a78a831a8.rlib /usr/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-6279323f4be9bcf8.rlib -Bdynamic -lgcc_s -lutil -lrt -lpthread -lm -ldl -lc --eh-frame-hdr -z noexecstack -plugin-opt=O3 -plugin-opt=mcpu=znver3 --gc-sections -z relro -z now -O1 --strip-debug /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/16/crtendS.o /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/16/../../../../lib64/crtn.o
1. Running pass "verify" on module "ld-temp.o"
#0 0x00007f655f59143a llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /usr/src/debug/llvm/llvm-project-22.1.8.src/llvm/lib/Support/Unix/Signals.inc:846:8
#1 0x00007f655f4f6b7c RunSignalHandlers /usr/src/debug/llvm/llvm-project-22.1.8.src/llvm/lib/Support/Signals.cpp:109:18
#2 0x00007f655f4f6b7c SignalHandler /usr/src/debug/llvm/llvm-project-22.1.8.src/llvm/lib/Support/Unix/Signals.inc:412:3
#3 0x00007f6556a44e70 (/usr/lib/libc.so.6+0x44e70)
#4 0x00007f6556aaeceb __pthread_kill_implementation /usr/src/debug/glibc/glibc/nptl/pthread_kill.c:44:76
#11 0x00007f655bf9ae32 (/usr/lib/libLLVM.so.22.1+0x4d9ae32)
#12 0x00007f655b8b0887 llvm::report_fatal_error(char const*, bool) /usr/src/debug/llvm/llvm-project-22.1.8.src/llvm/lib/Support/ErrorHandling.cpp:0:3
#18 0x00007f655dc0c338 llvm::lto::opt(llvm::lto::Config const&, llvm::TargetMachine*, unsigned int, llvm::Module&, bool, llvm::ModuleSummaryIndex*, llvm::ModuleSummaryIndex const*, std::vector<unsigned char, std::allocator<unsigned char>> const&) /usr/src/debug/llvm/llvm-project-22.1.8.src/llvm/lib/LTO/LTOBackend.cpp:394:5
#24 0x00007f656057b64f lld::elf::BitcodeCompiler::compile() (/usr/lib/liblldELF.so.22.1+0x17b64f)
#27 0x00007f65604bcf38 lld::elf::link(llvm::ArrayRef<char const*>, llvm::raw_ostream&, llvm::raw_ostream&, bool, bool) (/usr/lib/liblldELF.so.22.1+0xbcf38)
#29 0x0000556665ed2a04 lld_main(int, char**, llvm::ToolContext const&) (/usr/bin/ld.lld+0x2a04)
clang: error: unable to execute command: Aborted (core dumped)
clang: error: linker command failed due to signal (use -v to see invocation)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the failure with the uutils/coreutils PGO commands and inspect PR #133250, focusing on the Cross-Language LTO and PGO boundary described in the report. Use the displayed ld.lld error as the baseline; done means the build no longer aborts with duplicate "CG Profile" module flags and the regression is covered.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers, performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100