Skip to content

Commit 6652010

Browse files
committed
avoid 32-bit relocation to __BOOTLOADER_CONFIG
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.
1 parent b394598 commit 6652010

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

api/src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,17 @@ macro_rules! entry_point {
120120
config.serialize()
121121
};
122122

123+
// Workaround for https://github.com/rust-osdev/bootloader/issues/427
124+
static __BOOTLOADER_CONFIG_REF: &[u8; $crate::BootloaderConfig::SERIALIZED_LEN] =
125+
&__BOOTLOADER_CONFIG;
126+
123127
#[export_name = "_start"]
124128
pub extern "C" fn __impl_start(boot_info: &'static mut $crate::BootInfo) -> ! {
125129
// validate the signature of the program entry point
126130
let f: fn(&'static mut $crate::BootInfo) -> ! = $path;
127131

128132
// ensure that the config is used so that the linker keeps it
129-
$crate::__force_use(&__BOOTLOADER_CONFIG);
133+
$crate::__force_use(__BOOTLOADER_CONFIG_REF);
130134

131135
f(boot_info)
132136
}

0 commit comments

Comments
 (0)