Hi everyone, I’m working on a RISC-V embedded project using Rust and encountered linker errors with `rust-lld` during `cargo build -r`. The errors indicate undefined symbols such as `_max_hart_id`, `_hart_stack_size`, and `_stack_start`. Here’s the specific error message: ``` ❯ cargo build -r Compiling riscv_blink v0.1.0 (/Users/IKL2KOR/Imran_Bosch/riscv_blink) error: linking with `rust-lld` failed: exit status: 1 | = note: LC_ALL="C" PATH="/Users/IKL2KOR/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/bin:/Users/IKL2KOR/Downloads/riscv64-unknown-elf-toolchain-10.2.0-2020.12.8-x86_64-apple-darwin/bin:/usr/local/opt/gnu-sed/libexec/gnubin:/opt/riscv/bin:/opt/homebrew/opt/riscv-tools/bin:/opt/homebrew/opt/python/libexec/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Users/IKL2KOR/Downloads/riscv64-unknown-elf-toolchain-10.2.0-2020.12.8-x86_64-apple-darwin/bin:/usr/local/opt/gnu-sed/libexec/gnubin:/opt/riscv/bin:/opt/homebrew/opt/riscv-tools/bin:/opt/homebrew/opt/python/libexec/bin:/Users/IKL2KOR/.cargo/bin:/Users/IKL2KOR/Library/Application Support/Code/User/globalStorage/github.copilot-chat/debugCommand" VSLANG="1033" "rust-lld" "-flavor" "gnu" "/var/folders/bn/73c2thl17734d902lypvxbpc0000gn/T/rustci6SSng/symbols.o" "<1 object files omitted>" "--as-needed" "-Bstatic" "/Users/IKL2KOR/Imran_Bosch/riscv_blink/target/riscv32imac-unknown-none-elf/release/deps/{libriscv_rt-a434d7a1d48c4fe6.rlib,libriscv-2a53d3ed2b6052a0.rlib,libcritical_section-685b6a1271633d88.rlib,libriscv_pac-3ff7f185b985f890.rlib,libembedded_hal-b23f0f49f43a05f2.rlib,libpanic_halt-27a79ef7891ae251.rlib}" "/Users/IKL2KOR/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/riscv32imac-unknown-none-elf/lib/{librustc_std_workspace_core-d0b7d3b6bcdc7dfb.rlib,libcore-ffb7e29a93e07f2c.rlib,libcompiler_builtins-78ef6be9ff417eef.rlib}" "-Bdynamic" "-z" "noexecstack" "-L" "/Users/IKL2KOR/Imran_Bosch/riscv_blink/target/riscv32imac-unknown-none-elf/release/build/riscv_blink-495ec9ba0be43c91/out" "-L" "/Users/IKL2KOR/Imran_Bosch/riscv_blink/target/riscv32imac-unknown-none-elf/release/build/riscv-rt-150c437fe81aae91/out" "-o" "/Users/IKL2KOR/Imran_Bosch/riscv_blink/target/riscv32imac-unknown-none-elf/release/deps/riscv_blink-a99b84e3b4751055" "--gc-sections" "-O1" "--strip-debug" "-Tmemory.x" = note: some arguments are omitted. use `--verbose` to show all linker arguments = note: rust-lld: error: undefined symbol: _max_hart_id >>> referenced by riscv_rt.cc2560d3c7fe4270-cgu.0 >>> riscv_rt-a434d7a1d48c4fe6.riscv_rt.cc2560d3c7fe4270-cgu.0.rcgu.o:(.init+0x98) in archive /Users/IKL2KOR/Imran_Bosch/riscv_blink/target/riscv32imac-unknown-none-elf/release/deps/libriscv_rt-a434d7a1d48c4fe6.rlib >>> referenced by riscv_rt.cc2560d3c7fe4270-cgu.0 >>> riscv_rt-a434d7a1d48c4fe6.riscv_rt.cc2560d3c7fe4270-cgu.0.rcgu.o:(.init+0x9C) in archive /Users/IKL2KOR/Imran_Bosch/riscv_blink/target/riscv32imac-unknown-none-elf/release/deps/libriscv_rt-a434d7a1d48c4fe6.rlib rust-lld: error: undefined symbol: _hart_stack_size >>> referenced by riscv_rt.cc2560d3c7fe4270-cgu.0 >>> riscv_rt-a434d7a1d48c4fe6.riscv_rt.cc2560d3c7fe4270-cgu.0.rcgu.o:(.init+0xA8) in archive /Users/IKL2KOR/Imran_Bosch/riscv_blink/target/riscv32imac-unknown-none-elf/release/deps/libriscv_rt-a434d7a1d48c4fe6.rlib >>> referenced by riscv_rt.cc2560d3c7fe4270-cgu.0 >>> riscv_rt-a434d7a1d48c4fe6.riscv_rt.cc2560d3c7fe4270-cgu.0.rcgu.o:(.init+0xAC) in archive /Users/IKL2KOR/Imran_Bosch/riscv_blink/target/riscv32imac-unknown-none-elf/release/deps/libriscv_rt-a434d7a1d48c4fe6.rlib rust-lld: error: undefined symbol: _stack_start >>> referenced by riscv_rt.cc2560d3c7fe4270-cgu.0 >>> riscv_rt-a434d7a1d48c4fe6.riscv_rt.cc2560d3c7fe4270-cgu.0.rcgu.o:(.init+0xB4) in archive /Users/IKL2KOR/Imran_Bosch/riscv_blink/target/riscv32imac-unknown-none-elf/release/deps/libriscv_rt-a434d7a1d48c4fe6.rlib rust-lld: error: undefined symbol: _sdata >>> referenced by riscv_rt.cc2560d3c7fe4270-cgu.0 >>> riscv_rt-a434d7a1d48c4fe6.riscv_rt.cc2560d3c7fe4270-cgu.0.rcgu.o:(.init+0xF4) in archive /Users/IKL2KOR/Imran_Bosch/riscv_blink/target/riscv32imac-unknown-none-elf/release/deps/libriscv_rt-a434d7a1d48c4fe6.rlib rust-lld: error: undefined symbol: _sidata >>> referenced by riscv_rt.cc2560d3c7fe4270-cgu.0 >>> riscv_rt-a434d7a1d48c4fe6.riscv_rt.cc2560d3c7fe4270-cgu.0.rcgu.o:(.init+0x104) in archive /Users/IKL2KOR/Imran_Bosch/riscv_blink/target/riscv32imac-unknown-none-elf/release/deps/libriscv_rt-a434d7a1d48c4fe6.rlib rust-lld: error: undefined symbol: _sbss >>> referenced by riscv_rt.cc2560d3c7fe4270-cgu.0 >>> riscv_rt-a434d7a1d48c4fe6.riscv_rt.cc2560d3c7fe4270-cgu.0.rcgu.o:(.init+0x124) in archive /Users/IKL2KOR/Imran_Bosch/riscv_blink/target/riscv32imac-unknown-none-elf/release/deps/libriscv_rt-a434d7a1d48c4fe6.rlib rust-lld: error: undefined symbol: _ebss >>> referenced by riscv_rt.cc2560d3c7fe4270-cgu.0 >>> riscv_rt-a434d7a1d48c4fe6.riscv_rt.cc2560d3c7fe4270-cgu.0.rcgu.o:(.init+0x12C) in archive /Users/IKL2KOR/Imran_Bosch/riscv_blink/target/riscv32imac-unknown-none-elf/release/deps/libriscv_rt-a434d7a1d48c4fe6.rlib rust-lld: error: undefined symbol: InstructionMisaligned >>> referenced by riscv_rt.cc2560d3c7fe4270-cgu.0 >>> riscv_rt-a434d7a1d48c4fe6.riscv_rt.cc2560d3c7fe4270-cgu.0.rcgu.o:(__EXCEPTIONS) in archive /Users/IKL2KOR/Imran_Bosch/riscv_blink/target/riscv32imac-unknown-none-elf/release/deps/libriscv_rt-a434d7a1d48c4fe6.rlib rust-lld: error: undefined symbol: InstructionFault >>> referenced by riscv_rt.cc2560d3c7fe4270-cgu.0 >>> riscv_rt-a434d7a1d48c4fe6.riscv_rt.cc2560d3c7fe4270-cgu.0.rcgu.o:(__EXCEPTIONS) in archive /Users/IKL2KOR/Imran_Bosch/riscv_blink/target/riscv32imac-unknown-none-elf/release/deps/libriscv_rt-a434d7a1d48c4fe6.rlib rust-lld: error: undefined symbol: IllegalInstruction >>> referenced by riscv_rt.cc2560d3c7fe4270-cgu.0 >>> riscv_rt-a434d7a1d48c4fe6.riscv_rt.cc2560d3c7fe4270-cgu.0.rcgu.o:(__EXCEPTIONS) in archive /Users/IKL2KOR/Imran_Bosch/riscv_blink/target/riscv32imac-unknown-none-elf/release/deps/libriscv_rt-a434d7a1d48c4fe6.rlib rust-lld: error: undefined symbol: Breakpoint >>> referenced by riscv_rt.cc2560d3c7fe4270-cgu.0 >>> riscv_rt-a434d7a1d48c4fe6.riscv_rt.cc2560d3c7fe4270-cgu.0.rcgu.o:(__EXCEPTIONS) in archive /Users/IKL2KOR/Imran_Bosch/riscv_blink/target/riscv32imac-unknown-none-elf/release/deps/libriscv_rt-a434d7a1d48c4fe6.rlib rust-lld: error: undefined symbol: LoadMisaligned >>> referenced by riscv_rt.cc2560d3c7fe4270-cgu.0 >>> riscv_rt-a434d7a1d48c4fe6.riscv_rt.cc2560d3c7fe4270-cgu.0.rcgu.o:(__EXCEPTIONS) in archive /Users/IKL2KOR/Imran_Bosch/riscv_blink/target/riscv32imac-unknown-none-elf/release/deps/libriscv_rt-a434d7a1d48c4fe6.rlib rust-lld: error: undefined symbol: LoadFault >>> referenced by riscv_rt.cc2560d3c7fe4270-cgu.0 >>> riscv_rt-a434d7a1d48c4fe6.riscv_rt.cc2560d3c7fe4270-cgu.0.rcgu.o:(__EXCEPTIONS) in archive /Users/IKL2KOR/Imran_Bosch/riscv_blink/target/riscv32imac-unknown-none-elf/release/deps/libriscv_rt-a434d7a1d48c4fe6.rlib rust-lld: error: undefined symbol: StoreMisaligned >>> referenced by riscv_rt.cc2560d3c7fe4270-cgu.0 >>> riscv_rt-a434d7a1d48c4fe6.riscv_rt.cc2560d3c7fe4270-cgu.0.rcgu.o:(__EXCEPTIONS) in archive /Users/IKL2KOR/Imran_Bosch/riscv_blink/target/riscv32imac-unknown-none-elf/release/deps/libriscv_rt-a434d7a1d48c4fe6.rlib rust-lld: error: undefined symbol: StoreFault >>> referenced by riscv_rt.cc2560d3c7fe4270-cgu.0 >>> riscv_rt-a434d7a1d48c4fe6.riscv_rt.cc2560d3c7fe4270-cgu.0.rcgu.o:(__EXCEPTIONS) in archive /Users/IKL2KOR/Imran_Bosch/riscv_blink/target/riscv32imac-unknown-none-elf/release/deps/libriscv_rt-a434d7a1d48c4fe6.rlib rust-lld: error: undefined symbol: UserEnvCall >>> referenced by riscv_rt.cc2560d3c7fe4270-cgu.0 >>> riscv_rt-a434d7a1d48c4fe6.riscv_rt.cc2560d3c7fe4270-cgu.0.rcgu.o:(__EXCEPTIONS) in archive /Users/IKL2KOR/Imran_Bosch/riscv_blink/target/riscv32imac-unknown-none-elf/release/deps/libriscv_rt-a434d7a1d48c4fe6.rlib rust-lld: error: undefined symbol: SupervisorEnvCall >>> referenced by riscv_rt.cc2560d3c7fe4270-cgu.0 >>> riscv_rt-a434d7a1d48c4fe6.riscv_rt.cc2560d3c7fe4270-cgu.0.rcgu.o:(__EXCEPTIONS) in archive /Users/IKL2KOR/Imran_Bosch/riscv_blink/target/riscv32imac-unknown-none-elf/release/deps/libriscv_rt-a434d7a1d48c4fe6.rlib rust-lld: error: undefined symbol: MachineEnvCall >>> referenced by riscv_rt.cc2560d3c7fe4270-cgu.0 >>> riscv_rt-a434d7a1d48c4fe6.riscv_rt.cc2560d3c7fe4270-cgu.0.rcgu.o:(__EXCEPTIONS) in archive /Users/IKL2KOR/Imran_Bosch/riscv_blink/target/riscv32imac-unknown-none-elf/release/deps/libriscv_rt-a434d7a1d48c4fe6.rlib rust-lld: error: undefined symbol: InstructionPageFault >>> referenced by riscv_rt.cc2560d3c7fe4270-cgu.0 >>> riscv_rt-a434d7a1d48c4fe6.riscv_rt.cc2560d3c7fe4270-cgu.0.rcgu.o:(__EXCEPTIONS) in archive /Users/IKL2KOR/Imran_Bosch/riscv_blink/target/riscv32imac-unknown-none-elf/release/deps/libriscv_rt-a434d7a1d48c4fe6.rlib rust-lld: error: undefined symbol: LoadPageFault >>> referenced by riscv_rt.cc2560d3c7fe4270-cgu.0 >>> riscv_rt-a434d7a1d48c4fe6.riscv_rt.cc2560d3c7fe4270-cgu.0.rcgu.o:(__EXCEPTIONS) in archive /Users/IKL2KOR/Imran_Bosch/riscv_blink/target/riscv32imac-unknown-none-elf/release/deps/libriscv_rt-a434d7a1d48c4fe6.rlib rust-lld: error: too many errors emitted, stopping now (use --error-limit=0 to see all errors) error: could not compile `riscv_blink` (bin "riscv_blink") due to 1 previous error ``` ### My setup: - **Rust nightly** - **Target**: `riscv32imac-unknown-none-elf` - **OS**: macOS (M1) - **Using**: `riscv-rt` and a `memory.x` file I’ve ensured the toolchain paths are correct, `memory.x` is included, and I’ve reviewed the `riscv-rt` documentation, but the issue persists. ### Configurations `Config.toml`: ```toml [target.riscv32imac-unknown-none-elf] rustflags = [ "-C", "link-arg=-Tmemory.x", # "-C", "link-arg=-Tlink.x", ] [build] target = "riscv32imac-unknown-none-elf" ``` `Cargo.toml`: ```toml [package] name = "riscv_blink" version = "0.1.0" edition = "2021" [dependencies] riscv-pac= { path = "../../Desktop/riscv_pac"} riscv-rt = "0.13.0" panic-halt = "1.0.0" ``` `memory.x`: ``` MEMORY { RAM : ORIGIN = 0x80000000, LENGTH = 128K } REGION_ALIAS("REGION_TEXT", RAM); REGION_ALIAS("REGION_RODATA", RAM); REGION_ALIAS("REGION_DATA", RAM); REGION_ALIAS("REGION_BSS", RAM); REGION_ALIAS("REGION_HEAP", RAM); REGION_ALIAS("REGION_STACK", RAM); ``` ### Code snippets `main.rs`: ```rust #![no_std] #![no_main] use core::arch::asm; use riscv_rt::entry; extern crate panic_halt; const GPIO_DIR_REG: usize = 0x0004_0200; const GPIO_DATA_REG: usize = 0x0004_0208; const LED0_R: u32 = 1 << 18; fn pin_output(pinctrl: u32) { unsafe { let x = core::ptr::read_volatile(GPIO_DIR_REG as *mut u32); core::ptr::write_volatile(GPIO_DIR_REG as *mut u32, x | pinctrl); } } fn led_on(pinctrl: u32) { unsafe { let x = core::ptr::read_volatile(GPIO_DATA_REG as *mut u32); core::ptr::write_volatile(GPIO_DATA_REG as *mut u32, x | pinctrl); } } fn led_off(pinctrl: u32) { unsafe { let x = core::ptr::read_volatile(GPIO_DATA_REG as *mut u32); core::ptr::write_volatile(GPIO_DATA_REG as *mut u32, x & !pinctrl); } } fn delay() { let mut x = 100_000_u32; while x > 0 { x -= 1; // We build in release mode, this is required to prevent // LLVM from optimizing away the loop. unsafe { asm!("addi zero, zero, 0"); } } } #[entry] fn main() -> ! { pin_output(LED0_R); loop { led_off(LED0_R); delay(); led_on(LED0_R); delay(); } } ``` `build.rs`: ```rust use std::env; use std::fs::File; use std::io::Write; use std::path::Path; /// Put the linker script somewhere the linker can find it. fn main() { let out_dir = env::var("OUT_DIR").expect("No out dir"); let dest_path = Path::new(&out_dir); let mut f = File::create(&dest_path.join("memory.x")) .expect("Could not create file"); f.write_all(include_bytes!("memory.x")) .expect("Could not write file"); println!("cargo:rustc-link-search={}", dest_path.display()); println!("cargo:rerun-if-changed=memory.x"); println!("cargo:rerun-if-changed=build.rs"); } ``` Despite this setup, the linker fails to find the specified symbols. Has anyone encountered a similar issue or can suggest what I might be missing? Thanks in advance for your help!