liveBook · Manning

Static analysis

As explained in Embedded Software with Rust

Static analysis is the examination of program properties from source or compiled artifacts without executing the program.

Static analysis examines program properties without executing the program. For embedded Rust, it can estimate worst-case stack usage before firmware runs—a useful first defense against stack overflow, which can silently corrupt nearby memory. section 7.4 section 7.4.2

A practical estimation workflow:

  • Build with stack-size metadata and release link-time optimization, then use cargo-call-stack to estimate per-function usage and the deepest call path. section 7.4.2
  • Compare the reported worst case with the stack region in memory.x. Treat the estimate as a lower bound: indirect calls may be unknown, and interrupt depths must be added to the paths they preempt. section 7.4.2
  • Allow a 25–50% safety margin; combine estimation with link-time layout choices, runtime checks, or hardware enforcement rather than relying on the estimate alone. section 7.4 section 7.4.2

Estimate a call path

Install cargo-call-stack with stable Cargo, add rust-src to nightly, enable fat LTO for release, then run the analysis on the nightly-built target binary. The output can be rendered as an SVG call graph with Graphviz. section 7.4.2

Figure 7.4 Example call-graph output from cargo-call-stack, rendered to SVG via Graphviz
CH07 F04 Cabanis

Inspect an example call-graph visualization to see how the analysis reports deepest call paths. section 7.4.2

How Embedded Software with Rust covers it

How deep it goes
Details a tool workflow and its limits, but treats estimates as lower bounds rather than guarantees.
Examples
Uses cargo-call-stack, release LTO, a memory.x comparison, and a Graphviz-rendered call graph.
What it assumes
Assumes an embedded Rust build; analysis requires nightly, rust-src, and release LTO, while tool installation uses stable Cargo.
What you can do after
Apply cargo-call-stack to estimate stack usage and compare its deepest path with the allocated stack region.
How it connects
Connects stack estimation to linker layout, link-time optimization, interrupts, function pointers, and runtime or hardware safeguards.

Also explained in

Compare how 11 books explain static analysis →

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.