liveBook · Manning

Cargo-call-stack

As explained in Embedded Software with Rust

cargo-call-stack is a Rust analysis tool that estimates program stack usage from compiler-emitted per-function stack-size metadata and call paths.

Embedded firmware has limited RAM, and stack overflow can silently corrupt data. cargo-call-stack estimates whole-program stack usage so you can compare it with the stack region configured in memory.x. section 7.0 section 7.4.2

The analysis uses per-function stack-size metadata emitted by a nightly Rust compiler. Install cargo-call-stack with stable Cargo, add nightly rust-src, and enable fat LTO for the release profile. section 7.4.2

cargo +nightly call-stack --target thumbv7em-none-eabihf --bin myapp > cg.dot
dot -Tsvg cg.dot > cg.svg

Run the analysis on the nightly-built target binary, then render its call-graph output as SVG with Graphviz. section 7.4.2

The report gives per-function maxima and the deepest call path. Treat its estimate as a lower bound: indirect calls may be unknown, and interrupt depths are reported separately. Allow a 25–50% safety margin; flip-link and runtime checks provide additional defenses. section 7.4.2 section 7.5

How Embedded Software with Rust covers it

How deep it goes
Uses per-function stack metadata and call paths, but leaves indirect calls unknown and reports interrupt depths separately.
Examples
Runs analysis on a nightly-built embedded target and renders the call graph with Graphviz.
What it assumes
Configure nightly Rust with rust-src and release fat LTO before running the analysis.
What you can do after
Use its estimate to compare against memory.x and decide whether the stack region needs resizing.
How it connects
Connects stack sizing with LTO, nightly Rust, interrupts, memory.x, and flip-link.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Embedded Software with Rust. The section links point to the parts of the book it draws on.