How to fix rust-lld error SBREL relocation to xxx without static base with rwpi relocation model?

Viewed 152

For research purpose, I'm trying to build an image for my cortex-m4 microcontroller with rwpi relocation model. However, during linking stage, lld throws me the error:

rust-lld: error: SBREL relocation to __sbss without static base

Below is an easy way to reproduce this error. This follows the tutorial in The Embedded Rust Book.

  1. cargo install cargo-generate to install an handy tool.
  2. cargo generate --git https://github.com/rust-embedded/cortex-m-quickstart to download the example code.
  3. cd into the cloned directory. Modify .cargo/config. Add "-C", "relocation-model=rwpi" to rustflags.
  4. Run cargo build.

The example code in main.rs uses the cortex-m-rt crate, which during compile time will generate a link script for the linker. The generated link script can be found at ./target/thumbv7m-none-eabi/debug/build/cortex-m-rt-xxxxxxxxxxxxxxxx/out/link.x. I suppose that some information is missing for the linker. What should I do to resolve the issue?

0 Answers
Related