Reputation: 530
I can not get ld to link a very simple program because of a truncated relocation.
(init+0x0): relocation truncated to fit: R_RISCV_PCREL_HI20 against symbol `globalPointer' defined in .bss section in out/bootloader.elf
An example assembly file that creates this issue:
.section init
.global start
.type start, @function
start:
la gp, globalPointer
.end
with the following linker script:
ENTRY(start);
. = 0x80000000;
SECTIONS {
.text : ALIGN(4K) {
*(.init);
*(.text);
}
.bss : ALIGN(4K) {
*(.bss);
PROVIDE(globalPointer = .);
}
.rodata : ALIGN(4K) {
*(.rodata);
}
.data : ALIGN(4K) {
*(.data);
}
}
Assembled and linked with the following commands:
riscv64-elf-as -march=rv64gc source/entry.s -o build/entry.o
riscv64-elf-ld -nostdlib -melf64lriscv -T linker.ld build/entry.o -o out/bootloader.elf
With a toolchain made of up the following tools with --target=riscv64-elf
as a configuration parameter and following the other flags here at OsDev.
binutils: 2.37
gcc: 11.2.0
I have also tried this prebuilt toolchain from kernel.org.
I was also able to trigger the same error in a C file with the following code:
#include <stdint.h>
extern volatile uint64_t* globalPointer;
int kernalMain(void){
*globalPointer = 0;
return 0;
}
So my issue is not isolated to assembly code.
Upvotes: 3
Views: 1361