Relocation truncated to fit: R_RISCV_HI20

Hi,

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

.bss._kernel 0x0000000080004398 0x70 kernel/libkernel.a(sched.c.obj)
0x0000000080004398 _kernel

And link script is here, and please notice CONFIG_XIP is not defined.

link script

BR,
Peng

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.

This is helpful! Thanks Jim. And is there any more introduction about code model? I would like to study it.

Palmer did a blog series about the toolchain. Part four talks about code models.


You might be interested in reading the entire series from the beginning

Yeah, thank you!