Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
riffraffff opened this issue Nov 4, 2023 · 1 comment
Open

Comments

@riffraffff
Copy link

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
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants