Skip to content

Commit

Permalink
Merge pull request #428 from Freax13/fix/large-code-model-with-large-…
Browse files Browse the repository at this point in the history
…offset

avoid 32-bit relocation to __BOOTLOADER_CONFIG
  • Loading branch information
Freax13 authored Mar 14, 2024
2 parents 4f06d47 + d0d10fe commit 4bd1ba4
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,17 @@ macro_rules! entry_point {
config.serialize()
};

// Workaround for https://github.com/rust-osdev/bootloader/issues/427
static __BOOTLOADER_CONFIG_REF: &[u8; $crate::BootloaderConfig::SERIALIZED_LEN] =
&__BOOTLOADER_CONFIG;

#[export_name = "_start"]
pub extern "C" fn __impl_start(boot_info: &'static mut $crate::BootInfo) -> ! {
// validate the signature of the program entry point
let f: fn(&'static mut $crate::BootInfo) -> ! = $path;

// ensure that the config is used so that the linker keeps it
$crate::__force_use(&__BOOTLOADER_CONFIG);
$crate::__force_use(&__BOOTLOADER_CONFIG_REF);

f(boot_info)
}
Expand All @@ -135,7 +139,7 @@ macro_rules! entry_point {
}

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

Check failure on line 144 in api/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (macos-latest)

invalid operand for instruction
}

0 comments on commit 4bd1ba4

Please sign in to comment.