Repository navigation
riscv32imac-unknown-xous-elf: rust-lld gives offset is outside the section errors #103949
Description
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
xobs commentedon Nov 4, 2022
I managed to link the project using
riscv32-esp-elf-gccand it worked just fine, so this seems like a regression withrust-lld.loader: fix build with gcc-ld
apiraino commentedon Nov 9, 2022
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
xobs commentedon Nov 9, 2022
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 #104101Note that this crate can be linked with
ld.I've verified that
gam-crashfails on both Windows and Linux. Furthermore, removingdebug=trueORcodegen-units=1fromCargo.tomlmakes it no longer fail.I'm following these steps:
cargo +nightly build --release --target riscv32imac-unknown-xous-elfGiven 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_sigpipetoinit(), it may not be too difficult to to the bisect even with our wonky build system. I'll need to learn how to usecargo-bisect-rustcthough.xobs commentedon Nov 10, 2022
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-lldand goes away when I replace it withld. I'm sure it'd work just fine if I transplantedrust-lldfrom 1.64.0 into 1.65.0.What's the next step?
apiraino commentedon Nov 10, 2022
thanks @xobs for the help! I'll mention #99464 cc: @nikic for more context
Squashed commit of the following:
Squashed commit of the following:
workingjubilee commentedon Jun 13, 2025
@xobs Hello xobs, I'm trying to triage the linker issues. How's things with rust-lld? Still giving you beef?
xobs commentedon Jun 13, 2025
No, I haven't seen it in a while. Given that, I will simply close this issue. Thank you for following up.