Arm cortex-m4 #[inline(never)] creates bigger firmware size?
โ Rust ๐ 2025-08-02 ๐ค surdeus ๐๏ธ 11I have this one shot timer function from Discovery book stm32f3 discovery:
#[inline(never)]
fn delay(tim6: &tim6::RegisterBlock, ms: u16) {
// Set the timer to go off in `ms` ticks
// 1 tick = 1 ms
tim6.arr.write(|w| w.arr().bits(ms));
// CEN: Enable the counter
tim6.cr1.modify(|_, w| w.cen().set_bit());
// Wait until the alarm goes off (until the update event occurs)
while !tim6.sr.read().uif().bit_is_set() {}
// Clear the update event flag
tim6.sr.modify(|_, w| w.uif().clear_bit());
}
This function then gets called repeatedly and infinitely from the main loop.
When I check its size with GNU binutils size command. Release size:
text data bss dec hex filename
5916 0 4 5920 1720 target/thumbv7em-none-eabihf/release/clocks-and-timers
When I remove #[inline(never)], release size:
text data bss dec hex filename
5828 0 4 5832 16c8 target/thumbv7em-none-eabihf/release/clocks-and-timers
So itโs optimized slightly better without inline never?
4 posts - 3 participants
๐ท๏ธ Rust_feed