Skip to content

Commit 4bd1ba4

Browse files
authored
Merge pull request #428 from Freax13/fix/large-code-model-with-large-offset
avoid 32-bit relocation to __BOOTLOADER_CONFIG
2 parents 4f06d47 + d0d10fe commit 4bd1ba4

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

api/src/lib.rs

+7-3
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
}
@@ -135,7 +139,7 @@ macro_rules! entry_point {
135139
}
136140

137141
#[doc(hidden)]
138-
pub fn __force_use(slice: &[u8]) {
139-
let force_use = slice.as_ptr() as usize;
142+
pub fn __force_use(slice: &&[u8; BootloaderConfig::SERIALIZED_LEN]) {
143+
let force_use = slice as *const _ as usize;
140144
unsafe { core::arch::asm!("add {0}, 0", in(reg) force_use, options(nomem, nostack)) };
141145
}

0 commit comments

Comments
 (0)