Skip to content

[AUTOMATED] Recover validated A32 frame inventories by default - #1108

Merged
mahaloz merged 11 commits into
Noelo-Lab:mainfrom
mgostIH:fix/arm-discovery
Oct 17, 2026
Merged

mahaloz merged 11 commits into
Noelo-Lab:mainfrom
mgostIH:fix/arm-discovery

Conversation

@mgostIH

@mgostIH mgostIH commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

Stripped A32 firmware loses hundreds of functions that only a disconnected stack frame reaches: no call reference, no symbol, no vector entry. armframes already recovers them, but only as an opt-in that also turns on full Thumb recovery and the expensive reference-query expansion. This adds an inventory value, A32 frames for the function inventory only, and makes it the default.

DecBench's public U-Boot (O2-noinline) shows it:

curl -fL 'https://huggingface.co/datasets/noelo-lab/decbench-dataset/resolve/815eb96f130b6d2ef7fa600e04669bf20139bf27/binaries/O2-noinline/u-boot/u-boot' -o /tmp/u-boot.bin
llvm-strip --strip-all -o /tmp/u-boot /tmp/u-boot.bin
kuna decompile-all /tmp/u-boot --jobs 1 --json > /tmp/u-boot.json

Main 4aac7a27 emits 2,352 functions; this branch emits 2,816. --option armframes off reproduces main's JSON byte for byte.

On the DecBench 96-binary samples, scored with the nightly scorer against main 2a298195 (nothing that touches ARM discovery has merged since):

Preset Bodies found Bodies lost Missing bodies GED-perfect Type-perfect
optimized (O2-noinline) +770 0 1,162 → 392 9,336 → 9,533 1,515 → 1,536
inlined (O2) +362 0 677 → 315 6,706 → 6,777 866 → 873
unoptimized (O0) 0 0 174 → 174 unchanged unchanged

All gains are U-Boot functions whose ground-truth start was missing; no function covered on main is lost in any preset, and no previously perfect GED or type score changes.

Cost. The extra time is the cost of decompiling the extra functions, not a slowdown of the existing ones:

Binary (stripped, O2-noinline) Functions Instructions Instructions per function Peak RSS
U-Boot 2,352 → 2,816 +24.9% 77.8 M → 81.2 M (+4.3%) −4.1%
Betaflight, Crazyflie CF2, NuttX (output unchanged) same +0.04% to +0.06% flat

The per-function cost stays inside the 5% speed budget; the total grows because U-Boot now has 20% more functions to decompile. Binaries where no frame validates pay only the scan.

  • armframes takes inventory | on | off, default inventory. inventory validates LR-saving A32 frames in undefined executable code and adds them to the function inventory. on keeps its previous meaning (also Thumb frames and independent ARM reference queries, the part that once doubled a BusyBox query); off restores the previous inventory.
  • Frame-prefix reconciliation now applies aifpoolslide literal evidence from the original Listing and the validated frames, so a prefix that begins inside a literal pool word no longer replaces the true entry. The reconciled prefix keeps its validated instruction records.
  • Catalog, docs/options.md and docs/spec/01-program-prep.md describe the new value and default.

Tests: tests/stages/kuna-arm-frame-inventory.xml (two-pass: the disconnected frame appears only by default, the literal-guarded caller starts at its own address and keeps its incoming value, and disabling the guard reproduces the literal entry), new AIF unit cases for retained prefix records, and CLI fixtures arm_frame_pool_le32 / arm_frame_retain_le32 with their generator. make test passes 675/675 and make test-stages 2906/2906 (PARITY OK); kuna catalog --check passes and docs/options.md is regenerated.

mgostIH and others added 3 commits October 14, 2026 22:56
Add the inventory value to armframes: recover disconnected A32 inventory roots while keeping full Thumb and independent reference expansion explicit. Apply literal-pool evidence to frame prefixes and retain reconciled prefix instruction records.

Verified focused AIF and CLI regressions, 24 stage assertions, catalog byte compatibility, and spec anchors. Full corpus and workspace checks remain deferred under the task workspace policy. Paired U-Boot coverage gains 770 bodies with zero losses; Betaflight coverage is unchanged.
Resolve conflicts with main: keep the bejoin evidence note in modes.rs,
take main's catalog row count (306/312) with this branch's armframes
assertions, bump the stage corpus count to 549, keep both fixture README
entries, and re-record docs/baseline-stages.json (2975 keys).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01RVkhSR3PZKoRmKDbGHjfqH
Resolve conflicts with main: take main's catalog row count (307/313)
with this branch's armframes assertions, bump the stage corpus count to
551, and re-record docs/baseline-stages.json (2987 keys).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01RVkhSR3PZKoRmKDbGHjfqH
@mahaloz

mahaloz commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

[AUTOMATED] Merged current main into this branch to clear the conflicts (catalog row count, stage corpus count, fixture README) and re-recorded docs/baseline-stages.json; no change to the feature itself.

@mahaloz

mahaloz commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

[AUTOMATED] Holding this one for now — the accuracy gain is real, but the default-ON speed cost is beyond what kuna accepts for a default flip.

What was measured on this branch (merged with current main as cbdd00d0c, all gates green):

  • Accuracy (U-Boot O2-noinline, stripped, scored against the unstripped symbols): 2352 → 2816 functions; recall 62.0% → 91.9%, precision 74.8% → 92.6%; no real function lost (all 525 dropped starts were false). U-Boot O2 is similar. Thumb-only firmware (betaflight, cf2, nuttx, CMSIS-DAP) is byte-identical.
  • Discovery latency on A32 images (not in the body's cost table): kuna functions / disassemble on U-Boot 1.0 → 5.1–5.4 s (RSS 48 → 146 MB), samba 2.0 → 9.1 s (51 → 240 MB), proftpd 1.0 → 3.3 s, busybox 1.1 → 2.9 s. This is the existing frame-recovery cost (--option armframes on on base already takes 4.46 s on U-Boot).
  • decompile-all: U-Boot +20% (--jobs 1), and --jobs 8 5.3 → 14.1 s wall because every worker reruns frame recovery when it loads; samba 23 → 84 s (2.4× more functions found).
  • New false splits: 18 U-Boot functions newly cut short, mostly at A32 jump-table case blocks (ldrls pc,[pc,r3,lsl#2]) that discovery doesn't follow — e.g. parse_label (0x60804444) is cut at 0x608045ac and case 9 falls into case 10; malloc (0x6081cc04) is also cut short. 55 previously-broken functions are fixed.

Paths forward: cut the recovery cost (e.g. share the frame inventory with --jobs workers instead of recomputing it, and bound the per-image work) and treat jump-table case blocks as non-entries, or keep armframes opt-in and enable it per mode.

@mgostIH

mgostIH commented Oct 15, 2026

Copy link
Copy Markdown
Contributor Author

[Human]
Of note, many of my recent PRs have been targeting memory efficiency and speedups for this exact purpose. I'd like the agent reviewing this to consider that when enabling these options. Check out my open PRs, the closed ones, anything mentioning efficiency and weigh in their advantage compared to this. Overall accuracy gains are definitely worth the cost imo, expecially if we can regain it elsewhere. If the total performance remains similar after those gains and this patch I think far more accuracy is worth it.

mahaloz and others added 7 commits October 17, 2026 00:46
Re-derived the stage corpus count (558) and the catalog row count
(310 rows, 316 matches), and re-recorded docs/baseline-stages.json.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016pSwXZADyVQwR4kf1NErrA
…eir functions

With frame recovery on by default, the AIF fingerprint histogram is drawn
from the whole program, so A32 switch case blocks the Listing never decoded
started passing as function entries and cut their dispatchers apart
(U-Boot parse_label at 0x608045ac). A frame root a few instructions into a
shrink-wrapped routine also stayed an entry next to the real one (malloc).

- The Listing walk now follows guarded A32 jump tables (ldrls pc,[pc,rN,lsl
  Noelo-Lab#2] word tables and addls pc,pc,rN,lsl Noelo-Lab#2 branch tables) when armframes is
  enabled, reading the case count from the cmp guard as the Thumb tbb reader
  does. Thumb-only images are unaffected.
- A frame root that the frame-expanded Listing enters by straight-line flow
  from a function entry or branch target is withdrawn, like a root whose mode
  is contradicted; a run that starts after a call stays speculative.
- A retained prior entry reached by a jump-table dispatch is contradicted.

Stripped U-Boot O2-noinline against its own symbols: recall 91.9% -> 92.0%,
precision 92.6% -> 98.6%; O2: recall 91.05% -> 91.25%, precision 91.4% ->
97.3%. On A32 binaries that keep a symbol table no true function is lost
and precision rises (hostapd 72.3% -> 86.0%, libpcap 49.8% -> 77.7%).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016pSwXZADyVQwR4kf1NErrA
Inventory frame recovery decoded the same image many times over: frame
validation, the prior inventory's AIF walk, every prefix reconciliation,
the post-frame AIF walk and each Listing rebuild of its fixpoint loop. On
stripped U-Boot that was five full Listing builds and six gap scans.

One recovery now shares a decode memo. A decode is kept only when SLEIGH
certifies it context-free (the existing one_instruction_reusable
certificate), together with the effective context words it read, and is
reused only while its address still reads those words, so a reused record
is exactly the record a fresh decode makes and reports no context commits.
The inventory never replays a frame body into a reference walk, so its
records keep no p-code; reference walks (armframes on) keep theirs.

Output is byte-identical to the previous commit (U-Boot O2 and
O2-noinline, all 24 Thumb firmware images, and the CLI fixtures). `kuna
functions` on stripped U-Boot O2-noinline drops to about half the time.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016pSwXZADyVQwR4kf1NErrA
Every `decompile-all --jobs N` worker loads the image again, and with
frame recovery on by default each one re-ran the whole search: on stripped
U-Boot `--jobs 8` went from 5.3 s to 14.1 s wall. Turning the recovery off
in workers is not an option, because its final Listing also decides decode
modes, no-return facts and call returns (548 U-Boot functions changed).

The search now leaves a record of what it decided: the final frame roots,
code-pointer and AIF entries, and the retained prior entries
(`AnalysisOutput::arm_frames`, kept on the program). The pool writes it next
to the worker inventory, and a worker that skips discovery hands it to its
analysis commit, which builds only the final Listing from it. That is the
parent's Listing, because every discarded round of the search ran in a
rolled-back decode context. `--jobs-full-load` still runs the full search.

`decompile-all --jobs 8 --option protoorder off` on stripped U-Boot is
byte-identical to `--jobs 1` and to `--jobs-full-load`; a new CLI test
checks the same on the authored switch fixture.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016pSwXZADyVQwR4kf1NErrA
The decode memo held one hash-map entry per decode with its own mnemonic,
operand and flow-target allocations. On a large stripped A32 image that is
most of the image at once: Samba's 475,000 records cost about 130 MB,
lifting `kuna functions` from 251 MB without the memo to 382 MB.

Records are now 16-byte slots, one per halfword of each executable range,
allocated per range on first use, with their text and flow targets in two
shared arenas and the flow type packed into 16 bits. A decode a slot cannot
hold (an odd address, a field that does not fit) is simply not kept.

Output is unchanged. `kuna functions` on stripped Samba: 7.35 s and 382 MB
before, 6.04 s and 272 MB after (main: 1.7 s, 50 MB); on stripped U-Boot:
2.05 s and 152 MB before, 1.78 s and 124 MB after (main: 0.6 s, 48 MB).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016pSwXZADyVQwR4kf1NErrA
Following A32 jump tables decodes switch cases, and a routine reached only
by a tail branch from a case is then walked as part of the switch, as the
Listing walk already treats any tail-branch target. On stripped U-Boot
O2-noinline that merges 6 of the 2,836 true functions into their callers
(one on O2); `--option tailcallentry on` splits all of them off again.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016pSwXZADyVQwR4kf1NErrA
Re-derived the stage corpus count (560) and the catalog row count
(311 rows, 317 matches), and re-recorded docs/baseline-stages.json.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016pSwXZADyVQwR4kf1NErrA
@mahaloz

mahaloz commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

[AUTOMATED] Pushed fixes on top of a merge of current main (counts re-derived, stage baseline re-recorded):

  • 3b9b3201b The Listing walk follows guarded A32 jump tables (ldrls pc,[pc,rN,lsl #2], addls pc,pc,rN,lsl #2), and a frame root the expanded Listing enters by straight-line flow is withdrawn. parse_label and malloc are whole again. Stripped U-Boot O2-noinline is now at 92.0% recall and 98.6% precision, up from 91.9% and 92.6% on this branch before. Six tail-called routines are absorbed into a switch; --option tailcallentry on recovers them.
  • 31e68affd, 5beb9e32f One frame recovery shares context-certified decodes, in fixed-size slots, across its passes and rebuilds. Output is unchanged.
  • ca6f600b9 --jobs workers replay the parent's recovery record instead of searching again. The output is byte-identical to --jobs-full-load, and to --jobs 1 under --option protoorder off.

Cost against main, as medians of interleaved, pinned runs:

  • kuna functions: U-Boot 0.59 → 1.79 s and 48 → 122 MB (this branch before: 3.9 s, 146 MB). Samba 1.8 → 6.4 s and 50 → 265 MB (before: 7.7 s, 240 MB).
  • decompile-all --jobs 8: U-Boot 5.2 → 5.8 s wall (before: 11.7 s).
  • decompile-all --jobs 1: within a few percent of main on U-Boot, BusyBox and ProFTPD. Samba takes about 4× as long, because it now decompiles 2.1× the functions.
  • Thumb-only firmware is byte-identical to main.

…absorbs

The spec said every U-Boot routine the switch walk absorbs is a tail-branch
target of a case. Four are (`pointer`'s cases); `memalign_simple`,
`efi_process_event_queue` and `malloc_trim` are tail-branch targets of
`memalign`, `efi_queue_event` and `free`, which the walk now reaches through a
followed case. `malloc_trim` was found by frame recovery alone, so the count
is 7, not 6.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016pSwXZADyVQwR4kf1NErrA
@mahaloz

mahaloz commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

[AUTOMATED] Pushed b28b099db (spec text only): the switch-following paragraph in docs/spec/01-program-prep.md said every U-Boot routine it absorbs is a tail-branch target of a case. Four are (pointer's cases). memalign_simple, efi_process_event_queue and malloc_trim are tail-branch targets of memalign, efi_queue_event and free, which the walk now reaches through a followed case. With malloc_trim, which frame recovery alone also finds, the count is 7 rather than 6. No code changed.

@mahaloz
mahaloz merged commit 69b9f85 into Noelo-Lab:main Oct 17, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants