Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RAM restricted to offset 0. #1

Open
tobygomersall opened this issue Mar 30, 2022 · 0 comments
Open

RAM restricted to offset 0. #1

tobygomersall opened this issue Mar 30, 2022 · 0 comments

Comments

@tobygomersall
Copy link

tobygomersall commented Mar 30, 2022

I have been learning how to compile rust for a PicoRV32 running on an FPGA with a simple hello world project.

The build system depends on this crate (picorv32-rt) and works correctly if I specify the RAM offset in memory.x to be 0x00000000. However, If I try to build with the RAM offset set to anything other than 0x00000000 then I get the following error:

error: linking with `rust-lld` failed: exit status: 1
  |
  = note: "rust-lld" "-flavor" "gnu" "/home/toby/SmartAcoustics/development/Coucal/coucal-examples/hello_world/target/riscv32imc-unknown-none-elf/release/deps/hello_world-d4686bcf81ebe3fc.hello_world.4b9de73c-cgu.0.rcgu.o" "/home/toby/SmartAcoustics/development/Coucal/coucal-examples/hello_world/target/riscv32imc-unknown-none-elf/release/deps/hello_world-d4686bcf81ebe3fc.hello_world.4b9de73c-cgu.1.rcgu.o" "/home/toby/SmartAcoustics/development/Coucal/coucal-examples/hello_world/target/riscv32imc-unknown-none-elf/release/deps/hello_world-d4686bcf81ebe3fc.hello_world.4b9de73c-cgu.2.rcgu.o" "--as-needed" "-L" "/home/toby/SmartAcoustics/development/Coucal/coucal-examples/hello_world/target/riscv32imc-unknown-none-elf/release/deps" "-L" "/home/toby/SmartAcoustics/development/Coucal/coucal-examples/hello_world/target/release/deps" "-L" "/home/toby/SmartAcoustics/development/Coucal/coucal-examples/hello_world/target/riscv32imc-unknown-none-elf/release/build/hello-world-afce2ada90003271/out" "-L" "/home/toby/SmartAcoustics/development/Coucal/coucal-examples/hello_world/target/riscv32imc-unknown-none-elf/release/build/picorv32-rt-09e83ab27c5016e1/out" "-L" "/home/toby/SmartAcoustics/development/Coucal/coucal-examples/hello_world/target/riscv32imc-unknown-none-elf/release/build/picorv32-rt-09e83ab27c5016e1/out" "-L" "/home/toby/SmartAcoustics/development/Coucal/coucal-examples/hello_world/target/riscv32imc-unknown-none-elf/release/build/picorv32-b61a8cc3c2e7815b/out" "-L" "/home/toby/SmartAcoustics/development/Coucal/coucal-examples/hello_world/target/riscv32imc-unknown-none-elf/release/build/riscv-3a3b4c9fe2d93f17/out" "-L" "/home/toby/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/riscv32imc-unknown-none-elf/lib" "--start-group" "-Bstatic" "/home/toby/SmartAcoustics/development/Coucal/coucal-examples/hello_world/target/riscv32imc-unknown-none-elf/release/deps/libpanic_halt-aea83376b0334f55.rlib" "/home/toby/SmartAcoustics/development/Coucal/coucal-examples/hello_world/target/riscv32imc-unknown-none-elf/release/deps/libpicorv32_rt-5008630363f2bd7b.rlib" "/home/toby/SmartAcoustics/development/Coucal/coucal-examples/hello_world/target/riscv32imc-unknown-none-elf/release/deps/libpicorv32-1b73dced3ca29185.rlib" "/home/toby/SmartAcoustics/development/Coucal/coucal-examples/hello_world/target/riscv32imc-unknown-none-elf/release/deps/libriscv-3402687458f5892a.rlib" "/home/toby/SmartAcoustics/development/Coucal/coucal-examples/hello_world/target/riscv32imc-unknown-none-elf/release/deps/libbit_field-e25dfa1160590cf0.rlib" "/home/toby/SmartAcoustics/development/Coucal/coucal-examples/hello_world/target/riscv32imc-unknown-none-elf/release/deps/libbare_metal-ff4fa36d97cf66d9.rlib" "/home/toby/SmartAcoustics/development/Coucal/coucal-examples/hello_world/target/riscv32imc-unknown-none-elf/release/deps/libr0-d835aacd4e55ffe9.rlib" "/home/toby/SmartAcoustics/development/Coucal/coucal-examples/hello_world/target/riscv32imc-unknown-none-elf/release/deps/libfixedvec-0ead9ae3dec59c6d.rlib" "/home/toby/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/riscv32imc-unknown-none-elf/lib/librustc_std_workspace_core-1ca50dceae486887.rlib" "/home/toby/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/riscv32imc-unknown-none-elf/lib/libcore-452968c43ebb50a5.rlib" "--end-group" "/home/toby/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/riscv32imc-unknown-none-elf/lib/libcompiler_builtins-997a38c6b1cb6cd6.rlib" "-Bdynamic" "-znoexecstack" "-L" "/home/toby/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/riscv32imc-unknown-none-elf/lib" "-o" "/home/toby/SmartAcoustics/development/Coucal/coucal-examples/hello_world/target/riscv32imc-unknown-none-elf/release/deps/hello_world-d4686bcf81ebe3fc" "--gc-sections" "-O1" "-Tlink.x"
  = note: rust-lld: error: section '.stack' will not fit in region 'RAM': overflowed by 4096 bytes
          rust-lld: error: section '.stack' will not fit in region 'RAM': overflowed by 4096 bytes
          

error: could not compile `hello-world` due to previous error

I have fixed this by copying picorv32-rt/link.x into my project and modifying it in the following way (which I copied from the riscv-rt/link.x):

diff --git a/link.x b/link.x
index c2ffb9b..322d145 100644
--- a/link.x
+++ b/link.x
@@ -55,7 +55,7 @@ SECTIONS
   PROVIDE(_heap_size = 0);
 
   /* fictitious region that represents the memory available for the heap */
-  .heap (INFO) :
+  .heap (NOLOAD) :
   {
     _sheap = .;
     . += _heap_size;
@@ -64,7 +64,7 @@ SECTIONS
   } > RAM
 
   /* fictitious region that represents the memory available for the stack */
-  .stack (INFO) :
+  .stack (NOLOAD) :
   {
     _estack = .;
     . = _stack_start;

Can we fix this in the crate? I'm complete linker script beginner so I apologize if I'm doing something stupid or have set my build system up incorrectly.

@tobygomersall tobygomersall changed the title Stack restricted to offset 0. RAM restricted to offset 0. Mar 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant