Repository navigation
Description
Motivation
fbuild bloat's graph shows callers as translation units (e.g. main.cpp.o) on the backward side, because the data source is ld --cref which is fundamentally archive-member-granular. Users (and AI optimization passes) consuming the graph have to guess which function inside main.cpp.o actually called the root symbol — that's a real signal loss vs. the forward side, which is per-symbol.
The data to fix this is already produced and then thrown away. run_objdump_and_attribute parses objdump -d into caller_symbol → [callee_symbols] for references_to; inverting that yields callee_symbol → [caller_symbols] at per-symbol granularity for free. callgraph::invert() already exists (tested at callgraph.rs:201) — we just don't populate it onto the symbol or use it in the graph.
Proposal
This is new behavior — no backwards-compatibility deference. Do the right thing.
1. Schema (FineGrainedSymbol)
Add one new field:
/// Symbols that call this one — the per-symbol inverse of
/// `references_to`. Populated by inverting the objdump-derived
/// call graph in `run_objdump_and_attribute`. Empty when objdump
/// wasn't available; the graph then falls back to TU-level
/// `referenced_by`.
#[serde(default)]
pub called_by: Vec<String>,referenced_by (TU-level cref data) stays — it catches indirect calls (vtable dispatch, function-pointer tables, SCT/DMA callbacks) that objdump -d can't resolve from the disassembly alone.
2. Analyzer
In run_objdump_and_attribute:
let forward = parse_disasm(&result.stdout);
let backward = invert(&forward);
for sym in &mut map.symbols {
if let Some(callees) = forward.get(&sym.mangled) {
sym.references_to = callees.clone();
}
if let Some(callers) = backward.get(&sym.mangled) {
sym.called_by = callers.clone();
}
}Two passes through map.symbols instead of one. Zero extra subprocess cost — objdump was already running.
3. Graph walker
New NodeKind::Caller { demangled, size } symmetric to NodeKind::Callee. The backward walker prefers called_by (per-symbol) when populated and falls back to referenced_by (TU-level) when it isn't.
Crucially: when both are populated for the root, render both side-by-side. Per-symbol catches direct calls; TU-level catches indirect dispatch the disassembler missed. The two views are complementary, not redundant:
- Direct call from
setup()toFastLED::show(): per-symbol sees it assetup → FastLED::show. TU sees it asmain.cpp.o references libFastLED.a(fl.cpp.o). - Indirect call through
vtable[3](): per-symbol sees nothing (no annotation on theblx r3). TU still seesmain.cpp.o references libFastLED.a(fl.cpp.o)because the linker pulled the TU in via the vtable's static initializer.
The graph should surface BOTH so users see the union, with edge styling distinguishing them (solid arrow for per-symbol direct call, dashed gray for "TU-only — likely indirect").
4. Markdown sub-table
The existing "Top callees (dual ranking)" sub-table grows a sibling "Top callers (dual ranking)" — heaviest callers (caller's flash bytes) + most-prolific callers (count of distinct callees). Same (… and N more) overflow row. Both ranked from the per-symbol called_by.
5. DOT rendering
- Caller nodes: solid box with the demangled function name (same style as Callee on the forward side).
- Per-symbol back-edge: solid arrow with
callslabel. - TU-only back-edge (when per-symbol view doesn't include this caller TU): dashed gray arrow with
references (indirect?)label so the eye picks out the cases where the disassembly didn't yield a per-symbol caller.
Out of scope (deliberately)
- Cross-archive call resolution.
objdump -don a single firmware ELF resolves every call site to its actual destination in that ELF. No need forobjdump -rover per-TU.ofiles (which fbuild deletes post-link anyway). - LTO inlining recovery. Inlined helpers don't appear in disassembly; the missing edge is a real signal that the call site was inlined, not a tool limitation. Document but don't try to recover.
- Backwards compatibility with old
report.json. This is new behavior — the schema change is additive but the graph rendering changes shape. Old reports will simply not show the per-symbol caller side becausecalled_byis empty. That's correct.
Acceptance
FineGrainedSymbol.called_bypopulated for every symbol inobjdump-built reports.- The bidirectional graph in
report.mdshows per-symbol callers when available, with TU-level callers rendered as a distinct edge style when they extend the per-symbol view. - The new "Top callers" sub-table appears next to "Top callees" with both rankings.
- Regression test pins the
objdump→invert→called_bypipeline against a fixture with a deliberatecaller → calleepair from each architecture flavour the existingcallgraph::testscovers.
Related
- feat(bloat): graphviz
.dotback-reference graphs (Part 2 of #459) #463 — back-reference graph walker. - feat(bloat): per-symbol forward refs + bidirectional graph + dual-rank sub-table #470 — forward refs + bidirectional graph + dual-rank sub-table (the per-symbol forward side this PR mirrors on the back side).
- refactor(symbol_analysis): split graph.rs + fix rustdoc broken link #474 / refactor(symbol_analyzer): split into mod/markdown/tests submodule #475 — recent file-split refactors, so the touch is in
symbol_analysis::graph::walker+symbol_analyzer::markdown.
🤖 Filed via Claude Code based on user request.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsTriage
Activity
zackees commentedon Jun 7, 2026
Addendum: single-symbol query
Also folding in: a CLI / API path for "give me the bloat row for one specific demangled name" so users + AI agents can answer "how big is
fl::ChannelXYZ::show()and what does it touch?" without grepping the wholereport.json.CLI surface
Output: a focused per-symbol block:
Matching rules
--symbol-mangledbecause mangled names are unambiguous.Programmatic API
FineGrainedSymbolMap::find_symbol(query: &SymbolQuery) -> Option<&FineGrainedSymbol>whereSymbolQueryisExactDemangled(&str) | SubstringDemangled(&str) | ExactMangled(&str). Returns the resolved row. Multi-match returnsErr(Vec<&FineGrainedSymbol>)so the caller can disambiguate.Composes with the rest of #478
The single-symbol view is the natural per-symbol drill-down for the per-symbol caller/callee data the rest of this issue adds. The CLI output above pulls directly from
called_by(new) andreferences_to(existing), with the dual-rank sub-table inline.Acceptance addendum
fbuild bloat . --symbol '<demangled>'returns one focused symbol block on stdout (or JSON via--json).find_symbol()API exposed onFineGrainedSymbolMap.fl::symbol from a fixture report by exact demangled, exact mangled, substring, and ambiguous substring; assert correct dispatch in each.feat(bloat): per-symbol back-references + single-symbol lookup (#478) (…
fix(bloat): drop intra-function jump labels from call graph (#484) (#486