-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add stack analysis tool #313
Comments
Other tools that can help make the output more readable: |
Branch stack-sizes contains the hacks used. |
I've improved output format, env call for #!/usr/bin/env -S cargo +nightly -Zscript
//! ```cargo
//! [package]
//! edition = "2021"
//! [dependencies]
//! stack-sizes = "0.5.0"
//!```
use std::io::Read;
use std::io;
use stack_sizes::analyze_executable;
fn main() {
let mut stdin = io::stdin().lock();
let mut buffer = Vec::new();
stdin.read_to_end(&mut buffer).unwrap();
let functions = analyze_executable(&buffer).unwrap();
let mut sorted: Vec<_> = functions.defined.into_values().collect();
sorted.sort_by_key(|f| f.stack().unwrap_or(0));
for f in sorted {
println!("{:5?} {:5} {:?}", f.stack(), f.size(), f.names() );
}
} |
Next iteration:
#!/usr/bin/env -S cargo +nightly -Zscript
//! ```cargo
//! [package]
//! edition = "2021"
//! [dependencies]
//! stack-sizes = "0.5.0"
//! symbolic = { version = "12.4.1", features = ["demangle"] }
//!```
use std::io::Read;
use std::io;
use stack_sizes::analyze_executable;
use symbolic::demangle;
fn main() {
let mut stdin = io::stdin().lock();
let mut buffer = Vec::new();
stdin.read_to_end(&mut buffer).unwrap();
let functions = analyze_executable(&buffer).unwrap();
let mut sorted: Vec<_> = functions.defined.into_values().collect();
sorted.sort_by_key(|f| f.stack().unwrap_or(0));
for f in sorted.into_iter().rev() {
if let Some(stack) = f.stack() {
print!("{:6}", stack);
} else {
print!("None");
}
print!(" {:6} ", f.size());
for (i, name) in f.names().into_iter().enumerate() {
if i > 0 {
print!(", ");
}
print!("{}", demangle::demangle(name));
}
println!();
}
} Example output:
|
robin-nitrokey
added a commit
that referenced
this issue
Mar 11, 2024
This patch adds a CI job that prints the stack sizes for the functions in the stable NK3 firmware as well as the necessary tooling. Fixes: #313
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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:
SECTIONS
(need to be added torunners/embedded/ld/cortex-m-rt_0.6.15_link.x
):strip = false
to release profileRUSTFLAGS="-Z emit-stack-sizes" make flash-develop EXTRA_FEATURES=...
(fromutils/nrf-builder
)The text was updated successfully, but these errors were encountered: