rust-lang / rust-lang/rust

Code model other than medium does not work with lto on riscv64

Open
#139,479 14 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-LLVM A-LTO C-bug O-riscv P-low regression-from-stable-to-stable S-has-mcve
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

I tried this code:

// hello.rs
fn main() {
    println!("Hello, world!");
}
// command on riscv64
rustc -C code-model=large -C lto hello.rs
// command on x86_64
rustc --target riscv64gc-unknown-linux-gnu -C code-model=large -C lto hello.rs

I expected to see this happen: code compiles without error

Instead, this happened: failed to load bitcode of module "addr2line-*"

on riscv64, archrv rust:

$ rustc -C code-model=large -C lto hello.rs
warning: linking module flags 'Code Model': IDs have conflicting values in '' and 'hello.8b1675587fc60370-cgu.0'

error: failed to load bitcode of module "addr2line-4a5a0cf02a84c587.addr2line.d0fbcb35ed0a8d23-cgu.0.rcgu.o": 

error: aborting due to 1 previous error; 1 warning emitted

On x86_64, latest stable from rustup:

rustc --target riscv64gc-unknown-linux-gnu -C code-model=large -C lto hello.rs
warning: linking module flags 'Code Model': IDs have conflicting values in '' and 'hello.eea8546ba018bd24-cgu.0'

error: failed to load bitcode of module "addr2line-28336428312034c6.addr2line.134ee917f0cf37e1-cgu.0.rcgu.o": 

error: aborting due to 1 previous error; 1 warning emitted

On x86_64, Nightly:

rustc +nightly --target riscv64gc-unknown-linux-gnu -C code-model=large -C lto hello.rs
warning: linking module flags 'Code Model': IDs have conflicting values: 'i32 3' from , and 'i32 4' from hello.4a3c48060548947b-cgu.0

error: failed to load bitcode of module "addr2line-62ef9fdb0627a182.addr2line.746071221f6a6099-cgu.0.rcgu.o": 

error: aborting due to 1 previous error; 1 warning emitted
Meta

rustc --version --verbose:

rustc 1.85.1 (4eb161250 2025-03-15) (Arch Linux rust 1:1.85.1-1)
binary: rustc
commit-hash: 4eb161250e340c8f48f66e2b929ef4a5bed7c181
commit-date: 2025-03-15
host: riscv64gc-unknown-linux-gnu
release: 1.85.1
LLVM version: 19.1.7
rustc 1.86.0 (05f9846f8 2025-03-31)
binary: rustc
commit-hash: 05f9846f893b09a1be1fc8560e33fc3c815cfecb
commit-date: 2025-03-31
host: x86_64-unknown-linux-gnu
release: 1.86.0
LLVM version: 19.1.7
rustc 1.88.0-nightly (5e17a2a91 2025-04-05)
binary: rustc
commit-hash: 5e17a2a91dd7dbefd8b4a1087c2e42257457deeb
commit-date: 2025-04-05
host: x86_64-unknown-linux-gnu
release: 1.88.0-nightly
LLVM version: 20.1.2

This is specific to RISC-V. The same code works fine for x86_64 and aarch64 target. e.g.

rustc +nightly --target aarch64-unknown-linux-gnu -C code-model=large -C lto hello.rs -C linker=/bin/aarch64-linux-gnu-gcc 

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with rustc using -C code-model=large and -C lto on the riscv64gc-unknown-linux-gnu target, then compare the conflicting Code Model warnings and failed addr2line bitcode loading across stable and nightly. Investigate the compiler and LLVM interaction described in the report. Done means the hello.rs example compiles without the bitcode-loading error.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.