mit-pdos / xv6-riscv

Xv6 for RISC-V
Other
6.52k stars 2.37k forks source link

Truncation of relocation to fit: R_RISCV_PCREL_L012_I against '.L0 #212

Open riffraffff opened 8 months ago

riffraffff commented 8 months ago

when I execute the command 'make qemu' I meet the error is that "Truncation of relocation to fit: R_RISCV_PCREL_L012_I against '.L0" I've commented out the code in the corresponding file, but similar errors still occur in other files. Can someone help me? I deployed the project on the Linux virtual machine(Ubuntu 18.04.6)

Kingxukai commented 3 months ago

Hi there, I resolved it last year, and I finally added "mcmodel=medany," and it worked. Simply put, "mcmodel" is an instruction that guides the compiler on how to produce the access instructions for global variables. As you may know, the accessible address of a variable is PC-relative (PC ± 2G), so using "medany" instructs the compiler to generate Position Independent Code.

You might be confused about why your variables have exceeded 2G. That's because the .text is at 0x8000_0000, which is 2^(32-1) = 2G. You can test this by modifying the number in the linker script, changing it to 0x4000_0000. It compiles successfully, but RISC-V64 won't actually run it.