Skip to content

riscv32imac-unknown-xous-elf: rust-lld gives offset is outside the section errors #103949

Closed

Description

@xobs

Version it worked on

It most recently worked on: Rust 1.64.0

Version with regression

rustc --version --verbose:

rustc 1.65.0 (897e37553 2022-11-02)
binary: rustc
commit-hash: 897e37553bba8b42751c67658967889d11ecd120
commit-date: 2022-11-02
host: x86_64-pc-windows-msvc
release: 1.65.0
LLVM version: 15.0.0

Description

Building crates for the riscv32imac-unknown-xous-elf target sometimes results in a link error. This began with Rust 1.65.0. For example:

error: linking with `rust-lld` failed: exit code: 1
  |
  = note: "rust-lld" "-flavor" "gnu" "C:\\Users\\Sean\\AppData\\Local\\Temp\\rustcR77RGd\\symbols.o" "E:\\Code\\Xous\\Core\\target\\riscv32imac-unknown-xous-elf\\release\\deps\\pddb-8aba67b084ba8fc1.pddb-b3f235aec8c95441.n927u1iqdxcieg4.rcgu.o.rcgu.o" "--as-needed" "-L" "E:\\Code\\Xous\\Core\\target\\riscv32imac-unknown-xous-elf\\release\\deps" "-L" "E:\\Code\\Xous\\Core\\target\\release\\deps" "-L" "E:\\Code\\Xous\\Core\\target\\riscv32imac-unknown-xous-elf\\release\\build\\xous-08f083a692e5c29b\\out" "-L" "C:\\Users\\Sean\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\riscv32imac-unknown-xous-elf\\lib" "-Bstatic" "C:\\Users\\Sean\\AppData\\Local\\Temp\\rustcR77RGd\\libxous-26655dcc7bb206b6.rlib" "C:\\Users\\Sean\\AppData\\Local\\Temp\\rustcR77RGd\\libxous-d175a8531300a7f7.rlib" "C:\\Users\\Sean\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\riscv32imac-unknown-xous-elf\\lib\\libcompiler_builtins-67716ddc427f4546.rlib" "-Bdynamic" "--eh-frame-hdr" "-znoexecstack" "-L" "C:\\Users\\Sean\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\riscv32imac-unknown-xous-elf\\lib" "-o" "E:\\Code\\Xous\\Core\\target\\riscv32imac-unknown-xous-elf\\release\\deps\\pddb-8aba67b084ba8fc1" "--gc-sections" "-O1"
  = note: rust-lld: error: E:\Code\Xous\Core\target\riscv32imac-unknown-xous-elf\release\deps\pddb-8aba67b084ba8fc1.pddb-b3f235aec8c95441.n927u1iqdxcieg4.rcgu.o.rcgu.o:(.rodata.cst32): offset is outside the section


error: could not compile `pddb` due to previous error

Background

We build a custom libstd for the riscv32imac-unknown-xous-elf target, which is a Tier-3 target. This repository is at https://github.com/betrusted-io/rust. We are working on preparing patches for upstream that do not add any external dependencies, but this work is taking time. As a result, we generally forward-port our patchset every six weeks once the stable build is released.

When building packages for the Betrusted platform, our build system compiles around 27 packages. Many of these packages succeed, but with Rust 1.65.0 we have three packages fail.

This target does not have a linker script, and instead relies on the default one provided by rust-lld.

Activity

  1. added
    C-bugCategory: This is a bug.
    regression-untriagedUntriaged performance or correctness regression.
    on Nov 4, 2022
  2. added
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Nov 4, 2022
  3. xobs commented on Nov 4, 2022

    @xobs
    ContributorAuthor

    I managed to link the project using riscv32-esp-elf-gcc and it worked just fine, so this seems like a regression with rust-lld.

  4. added a commit that references this issue on Nov 4, 2022
  5. apiraino commented on Nov 9, 2022

    @apiraino
    Contributor

    WG-prioritization assigning priority (Zulip discussion)

    @xobs can you provide an example of a crate failing to build? Could be interesting to bisect where this started. We usually use https://github.com/rust-lang/cargo-bisect-rustc for bisecting (if anyone has some time to help).

    @rustbot label -I-prioritize +P-low e-needs-mcve e-needs-bisection

  6. added
    E-needs-bisectionCall for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc
    E-needs-mcveCall for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example
    P-lowLow priority
    and removed
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Nov 9, 2022
  7. xobs commented on Nov 9, 2022

    @xobs
    ContributorAuthor

    This issue is what caused me to submit #104101 to get our libstd upstream. Until now it's been out-of-tree.

    I did put up an example of the crash at https://github.com/xobs/gam-crash. This crate is buildable provided you have support for riscv32imac-unknown-xous-elf. This patchset is available in #104101

    Note that this crate can be linked with ld.

    I've verified that gam-crash fails on both Windows and Linux. Furthermore, removing debug=true OR codegen-units=1 from Cargo.toml makes it no longer fail.

    I'm following these steps:

    1. Building the libstd in Add initial libstd support for Xous #104101
    2. Running cargo +nightly build --release --target riscv32imac-unknown-xous-elf

    Given that the difference between 1.65.0 and 1.64.0 wasn't too great -- the only changes were to the arguments to read_buf() and the addition of _sigpipe to init(), it may not be too difficult to to the bisect even with our wonky build system. I'll need to learn how to use cargo-bisect-rustc though.

  8. xobs commented on Nov 10, 2022

    @xobs
    ContributorAuthor

    Using nothing but the choices of chewing gums, the finest of balling wire, and the crudest of scripts https://gist.github.com/xobs/2ae7231284a58df6600b2c0d758ed5f0 I narrowed it down to e2b52ff as the source of the crash.

    Which makes sense, because the crash is in rust-lld and goes away when I replace it with ld. I'm sure it'd work just fine if I transplanted rust-lld from 1.64.0 into 1.65.0.

    What's the next step?

  9. apiraino commented on Nov 10, 2022

    @apiraino
    Contributor

    thanks @xobs for the help! I'll mention #99464 cc: @nikic for more context

  10. removed
    E-needs-bisectionCall for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc
    E-needs-mcveCall for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example
    on Nov 11, 2022
  11. added
    A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.
    on Nov 11, 2022
  12. added
    O-xousOS: A microkernel OS for privacy in computing
    regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.
    and removed
    regression-untriagedUntriaged performance or correctness regression.
    on Feb 26, 2023
  13. added
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Apr 5, 2023
  14. workingjubilee commented on Jun 13, 2025

    @workingjubilee
    Member

    @xobs Hello xobs, I'm trying to triage the linker issues. How's things with rust-lld? Still giving you beef?

  15. xobs commented on Jun 13, 2025

    @xobs
    ContributorAuthor

    No, I haven't seen it in a while. Given that, I will simply close this issue. Thank you for following up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.C-bugCategory: This is a bug.O-xousOS: A microkernel OS for privacy in computingP-lowLow priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-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