I am trying to build a 64-bit executable RISC-V ELF using the RISC-V toolchain with newlib and a linker script that places the text section at 0x100 and the data section starting at 0x100000000 (greater than the 2 GB limit). However, I get the following error:
relocation truncated to fit: R_RISCV_HI20 against symbol `__global_pointer$' defined in .sdata section in a.out
collect2: error: ld returned 1 exit status
I noticed that the RISC-V options specify these two --mcmodel options:
-mcmodel=medlow
Generate code for the medium-low code model. The program and its statically defined symbols must lie within a single 2 GiB address range and must lie between absolute addresses -2 GiB and +2 GiB. Programs can be statically or dynamically linked. This is the default code model.
-mcmodel=medany
Generate code for the medium-any code model. The program and its statically defined symbols must be within any single 2 GiB address range. Programs can be statically or dynamically linked.
However, I am confused why even with 64-bit registers, why cannot use the entire 64-bit address space within my executable. Any clarification would be greatly appreciated.