You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For fun (and profit) I'm trying to reduce the .bss usage of a rust embedded program down to zero, relying only on the stack for memory.
Actually the only users of .bss apart from the stack are the singleton guards of the stm32l4r5::CorePeripherals and stm32l4r5::Peripherals structs.
And by replacing take with steal, since I'm sure that main will only be called "once", these should have been eliminated, however for some weird reason DEVICE_PERIPHERALS persisted.
The reason for that is outlined in the short snippet below:
// Type your code here, or load an example.#![no_std]#![no_main]use core::panic::PanicInfo;#[panic_handler]fnpanic(_panic:&PanicInfo<'_>) -> ! {loop{}}// As of Rust 1.75, small functions are automatically// marked as `#[inline]` so they will not show up in// the output when compiling with optimisations. Use// `#[no_mangle]` or `#[inline(never)]` to work around// this issue.// See https://github.com/compiler-explorer/compiler-explorer/issues/5939// If you use `main()`, declare it as `pub` to see it in the output:// pub fn main() { ... }#[no_mangle]staticmutUSED1:bool = false;staticmutUSED2:bool = false;#[inline(never)]pubfnmain() -> (){unsafe{USED1 = true};unsafe{USED2 = true};loop{}}
When using the steal method, LLVM is then actually smart enough to completely eliminate the variable that's written only once, like #151 (comment) thought.
The text was updated successfully, but these errors were encountered:
For fun (and profit) I'm trying to reduce the
.bss
usage of a rust embedded program down to zero, relying only on the stack for memory.Actually the only users of
.bss
apart from the stack are the singleton guards of thestm32l4r5::CorePeripherals
andstm32l4r5::Peripherals
structs.And by replacing
take
withsteal
, since I'm sure thatmain
will only be called "once", these should have been eliminated, however for some weird reasonDEVICE_PERIPHERALS
persisted.The reason for that is outlined in the short snippet below:
godbolt
Only
USED1
appears in the output,USED2
is optimized away.Maybe you could also use
no_mangle
in the same waycortex-m
does ?https://docs.rs/cortex-m/latest/src/cortex_m/peripheral/mod.rs.html#156-162
When using the
steal
method, LLVM is then actually smart enough to completely eliminate the variable that's written only once, like #151 (comment) thought.The text was updated successfully, but these errors were encountered: