Skip to content

[RISCV] Code model other than medium does not work with lto #139479

Open
@kxxt

Description

@kxxt

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 

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.A-LTOArea: Link-time optimization (LTO)C-bugCategory: This is a bug.I-prioritizeIssue: Indicates that prioritization has been requested for this issue.O-riscvTarget: RISC-V architectureS-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueregression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions