-
Notifications
You must be signed in to change notification settings - Fork 35
Open
Description
With -Z emit-stack-sizes we can get the stack sizes of each function in the final firmware. This could be used to analyze stack usage to fix stack-overflows. This could be made into a small util. Currently this issue will be used to document the (hacky) process:
Steps:
- use nightly
- add to the linker script
SECTIONS(need to be added torunners/embedded/ld/cortex-m-rt_0.6.15_link.x):
/* `INFO` makes the section not allocatable so it won't be loaded into memory */
.stack_sizes (INFO) :
{
KEEP(*(.stack_sizes));
}
- add
strip = falseto release profile - compile with
RUSTFLAGS="-Z emit-stack-sizes" make flash-develop EXTRA_FEATURES=...(fromutils/nrf-builder) - use the following script to get the functions (path may need to be adjusted):
#!/usr/bin/env cargo
//! ```cargo
//! [package]
//! edition = "2021"
//! [dependencies]
//! stack-sizes = "0.5.0"
//! ```
use std::fs::read;
use stack_sizes::analyze_executable;
fn main() {
let path = "../nitrokey-3-firmware/target/thumbv7em-none-eabihf/release/nrf52_runner";
let data = read(path).unwrap();
let functions = analyze_executable(&data).unwrap();
let mut sorted: Vec<_> = functions.defined.into_values().collect();
sorted.sort_by_key(|f| f.stack().unwrap_or(0));
println!("{sorted:#?}");
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels