-
Notifications
You must be signed in to change notification settings - Fork 214
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
avoid 32-bit relocation to __BOOTLOADER_CONFIG #428
avoid 32-bit relocation to __BOOTLOADER_CONFIG #428
Conversation
As explained in my comment in rust-osdev#427, the compiler seems to have trouble emitting relocations for references to global variables in custom sections. For custom sections, it always emits 32-bit relocations even when a 64-bit relocation would be required. This patch works around that by never referencing the global in the custom section directly from code, but only through a pointer from another global variable in the non-custom .data section. The relocation used for the pointer in the global variable will always use a 64-bit relocation.
Unfortunately this fix only works for me in debug mode ( |
Maybe the section could be renamed to |
That doesn't help if the compiler already optimized the indirection away. In that case the compiler will still emit the relocation in question. |
By the way, why are you using |
If I understand correctly, the reference to the section could be removed entirely if it's renamed to
I'd like to use |
This prevents the compiler from optimzing out __BOOTLOADER_CONFIG_REF in favor of accessing __BOOTLOADER_CONFIG directly.
I fixed this by adding another level of indirection. |
The medium code model still uses the small code model for addresses inside the .text section. This won't work because you're base address |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for debugging and fixing this!
Unfortunately the second fix still doesn't work for me. The error can be reproduced using the following code:
I'm compiling with |
Here's the workaround I've been using in the meantime: jxors@b16e341 |
We want to avoid directly accessing the data in the .bootloader-config section and slice::as_ptr gets a pointer to that data. Instead we cast a reference to a reference to the data in .bootloader-config to an address and pass that to the asm! block. The problem with as_ptr was that it's a method on the slice and not the reference and so by calling slice::as_ptr, we once again directly accessed the slice when we only meant to access the reference to the reference to the data.
Thanks for testing and thanks for providing the code for reproducing! I just pushed another commit that should fix the issue. |
It is now working for me. Thanks! |
As explained in my comment in #427, the compiler seems to have trouble emitting relocations for references to global variables in custom sections. For custom sections, it always emits 32-bit relocations even when a 64-bit relocation would be required. This patch works around that by never referencing the global in the custom section directly from code, but only through a pointer from another global variable in the non-custom .data section. The relocation used for the pointer in the global variable will always use a 64-bit relocation.
I tested the patch with these changes applied on top of this repo:
Considering that there aren't many people using such an odd image base, I didn't add a test for this, but feel free to tell me if you want one.
Closes #427