relocation truncated to fit (in arm64 baremetal program)

In my aarch64 baremetal program, this line causes an error.

printf("axpu_kernel_binary = %p, axpu_kernel_binary_len = %x\n", axpu_kernel_binary, axpu_kernel_binary_len);

By the linker script, the .axpudata_kernel_binary section is located at 0x100a00000 and the axpu_kernel_binary which is an address was given a section attribute for .axpudata_kernel_binary section. So the array sits at 0x100a00000 (which is above 4GB, needing more than 32 bits address).
The error message during the compile/link is like this.

/baremetal_bm.c:179:(.text.startup+0x8c): relocation truncated to fit:
R_AARCH64_ADR_PREL_PG_HI21 against symbol `axpu_kernel_binary’ defined
in .axpudata_kernel_binary section in aarch64/cvp_earth/telechips_baremetal/baremetal_bm.o

Is it because I didn’t specify the amount of memory in the linker script? (I tried searching the GNU ld manual for this error and found for two architectures there is –relax option to enable trampolin for long jump but not for arm64).

  • This sounds like “pointer difference is too big to be encoded as ADRP instruction”. Is your bare metal binary loaded at address 0x0?

    – 

  • @Siguza Hi, yes I guess so. The program is loaded at 0x80000000. So the difference is 0x1_00a00000 – (approx) 0x80000000 = (approx. 0x80a00000).

    – 

  • 1

    Hmm, that should be fine though. That’s an offset of less than 4GB.

    – 

Leave a Comment