Skip to content

Commit

Permalink
add another level of indirection
Browse files Browse the repository at this point in the history
This prevents the compiler from optimzing out __BOOTLOADER_CONFIG_REF
in favor of accessing __BOOTLOADER_CONFIG directly.
  • Loading branch information
Freax13 committed Feb 23, 2024
1 parent 6652010 commit b785b6d
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ macro_rules! 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_REF);
$crate::__force_use(&__BOOTLOADER_CONFIG_REF);

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

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

0 comments on commit b785b6d

Please sign in to comment.