0

I'm trying to build a GCC/newlib cross compilation toolchain targeting an embedded OS on RISC-V. For this purpose, I need to modify the virtual addresses that binaries are linked at.

One way to achieve this is to modify the default linker script that ships with the toolchain. I'm trying to find the best location in the involved components (newlib, binutils, gcc) where I can tweak the default linker script that is shipped with the toolchain.

For some platforms, newlib already provides partial or complete linker scripts. It seems for RISC-V the default linker script produced by binutils is used.

I'm fine with patching binutils, but I can't find how the RISC-V linker script is actually built or how I would modify anything in it. Any pointers are appreciated!

Julian Stecklina
  • 1,271
  • 1
  • 10
  • 24

1 Answers1

1

The different linker scripts for riscv are build from :
binutils/ld/scripttempl/elf.sc
binutils/ld/emulparams/elf32lriscv*
binutils/ld/emulparams/elf64lriscv*

You will need to modifiy these files or create your own and modify the Makefiles.

yflelion
  • 1,698
  • 2
  • 5
  • 16
  • Correct, i can append only: afaik by default it starts from 0x0000 and because of this in generators in bootrom section in rocket-chip lays custom LD script starts from 0x80000000, and also you can view current LD script via printing "riscv64-unknown-elf-ld --verbose". If you need custom memory location, you should manually set it in these files, or provide custom ld script. – Alexy Khilaev Jan 13 '21 at 12:25