When I build an image, I met this problem “relocation truncated to fit: R_RISCV_HI20”.
As far as I know, this is caused when the relocated symbols referenced by the functions are far away and beyond 0x7FFFFFFF.
But I check the link script, it seems to be close enough and map file also gives the evidence.
This is part of the map file:
.text.blink1 0x000000008000034a 0x38 …/app/libapp.a(main.c.obj)
0x000000008000034a blink1
The default code model, medlow, can only access addresses below 0x80000000 on a 64-bit part, or the entire memory on a 32-bit part due to wraparound. If you want to access memory above 2GB on a 64-bit part, you have to use the medany code model, via the -mcmodel=medany compiler option. If you are linking with libraries, like the C library, then those libraries must also be compiled with medany. It you are building your own toolchain, this works best if you use --with-cmodel=medany when configuring. The toolchains on the SiFive web site are configured this way.