Repository navigation
taildup: SAILR tail duplication goto reduction - #103
Merged
Merged
Conversation
The third SAILR goto-reduction pass (angr ReturnDuplicatorLow / ReturnDuplicatorBase max_calls_in_regions). Fills the gap between the two merged siblings, both of which decline the morton my_message_callback shape: * gotoreduce (#57): return tail, but REJECTS any CALL in the tail, so it cannot handle a `free(p); return;` epilogue; * crossjumprevert (#92): permits a call but only for a NON-return fall-through tail; it explicitly declines a tail that ends in `return`. The morton epilogue is a return tail CONTAINING a call (`free(v6); return;`) reached by a `BlockGoto` arm (`if (c) { ...; goto label; }`), which lands in neither. ActionTailDup (option `taildup`, default-OFF) duplicates exactly that: a bounded (<=3 blocks / <=12 printed ops / <=2 calls, no STORE) return-call tail, inlined in place of the goto. Two source shapes handled — a bare `BlockIf` if-goto (gotoreduce's kuna_inline_return_tail surgery) and a `BlockGoto` arm (crossjumprevert's kuna_inline_crossjump_tail surgery). Sound because the tail returns (closed path: the duplicated call is reached on exactly one structured path, never both — no convergence precondition needed). Each duplication is logged via Funcdata::warning. Verified distinct: with BOTH gotoreduce AND crossjumprevert on, the morton goto+label remain; only taildup removes them (0 goto / 0 label, matching angr). Fully registered: stages.toml settable row + count 60->61, options.rs name, architecture flag (field/ctor/reset/option-set/seam-copy), seams.rs field, universalaction.rs registration (after gotoreduce), ElementId 4106. kuna-catalog.xml bounds + baseline-stages.json regenerated (222->225), docs/assertions.md regenerated. catalog --check OK. Gates: make test PARITY OK (675/675, default-off byte-identical to upstream); make test-stages PARITY OK (225/225, +3 morton taildup two-pass assertions on a loadable x86-64 ELF bytechunk). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01PBrckq3YYAzBLq5k4KpWac
Wire the new `taildup` option/action through the cross-checking tests:
* kuna-base xml.rs: corpus file count 151->152 (the new stages XML).
* kuna_stages tests: no-live-reader allowlist += taildup; catalog row
trailing-comma count 59->60.
* catalog_bytecompat: fixture settable count 60->61; recaptured
tests/fixtures/stage_catalog.json (taildup row after crossjumprevert).
* universalaction action-dump oracle + verify_w8_fw_universalaction:
nonblank 263->264, the structuring tail now
finalstructure -> gotoreduce -> taildup -> ifelseflatten -> crossjumprevert.
Ablation: with `option taildup on` forced across all 83 datatest files, the
corpus stays 675/675 and the rendered C is byte-identical (the upstream Ghidra
regression corpus has no shared `free();return;`-via-goto epilogue, so the pass
never fires there) — 0/675 change. Kept default-OFF to match its two siblings
(gotoreduce, crossjumprevert), per the proposal's "expected to ship default-OFF
opt-in even if correct" (tail duplication changes rendering on real functions).
Speed: no measurable impact (cheap post-structuring scan) — morton single-func
~0.17s off/on; full datatest corpus 6.8s off vs 6.7s on (within noise).
All three gates green: make test PARITY OK (675/675), make test-stages PARITY
OK (225/225), make rust-test 0 failures (258 ok). catalog --check OK.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01PBrckq3YYAzBLq5k4KpWac
Reconcile the taildup feature with main after the FID PRs (#97-#101) and switchmultipred (#102) landed: - ElementId: taildup collided with switchsharedcase (both 4106 on the merged tree). Renumbered taildup -> 4108 (next free above ifelseflatten's 4107). - Count unions (taildup +1 settable, switchmultipred +1, fid +1 vs merge-base): settable 60 -> 63, surface stays 97 (taildup adds no surface row), corpus files 151 -> 153, universalaction leaves -> 264 (252 C++ + 5 kuna), bytecompat fixture 63, stages.toml header counts. - kuna-catalog.xml provenance: source_decompiler angr 22, structure-recovery 12 (+taildup), opt-in-tool 11 (+switchmultipred), use_when/change_kind max 64 (settables + returnpair double-count in `stage catalog`). - Regenerated docs/assertions.md (no change) and docs/baseline-stages.json (230 passing keys). Gates: catalog --check OK; make test PARITY OK 675/675 (baseline.json untouched); make test-stages PARITY OK 230/230; make rust-test green.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Implements proposal #54 — angr SAILR goto-reduction by return-tail
duplication when the tail contains a call. New
ActionTailDup(optiontaildup, default-OFF), the third SAILR goto-reduction pass.This is the genuinely distinct shape the proposal targets (
mortonmy_message_callback): a shared epiloguefree(v6); return;reached by agotofrom each command arm. angr emits zero gotos by duplicating that epilogue into
each arm.
Why it is NOT covered by the two merged siblings
gotoreduce(#57)crossjumprevert(#92)taildup(this)The morton epilogue is a return tail containing a call — it falls in the gap
between the two. Verified: with BOTH
gotoreduce onANDcrossjumprevert on,the morton
goto+labelremain; onlytaildup onremoves them (1 goto / 1 label→ 0 / 0, matching angr). It mirrors angr
ReturnDuplicatorBase, whose budget iscalls (
max_calls_in_regions = 2), not call-rejection(
angr/analyses/decompiler/optimization_passes/return_duplicator_{base,low}.py).Before / after (morton my_message_callback,
option taildup on)How
Runs once after
ActionFinalStructure(right aftergotoreduce). Finds anunstructured
goto Twhere T is a bounded single-successor bb chain ending inreturn(≤3 blocks / ≤12 printed ops / ≤2 calls, no STORE), and inlines thetail. Two source shapes, each with the matching existing surgery:
BlockIfif (cond) goto T→if (cond) { <tail> }(
kuna_inline_return_tail, gotoreduce's helper);BlockGotoarm{ stmts; goto T }→{ stmts; <tail> }(
kuna_inline_crossjump_tail, crossjumprevert's helper) — the morton case.The tail is fresh
BlockCopyleaves over the same bblocks (print-treeduplication: no p-code cloned, SSA/def-use untouched). Sound because the tail
returns — a closed path, so the duplicated call is reached on exactly one
structured path (the early-return arm), never both; no convergence precondition
needed (unlike crossjumprevert). Each duplication is logged via
Funcdata::warning(taildup: duplicated return-call tail to remove goto).Fully registered:
stages.tomlsettable row (count 60→61),options.rsname,architecture flag (field/ctor/reset/option-set/seam-copy),
seams.rsfield,universalaction.rsregistration, ElementId 4106. Catalog fixture +kuna-catalog.xmlbounds +baseline-stages.json(222→225) +docs/assertions.md+ action-dump oracle all updated.Default + speed
option taildup onforced across all 83 datatest files keeps the corpus 675/675 and therendered C byte-identical — the upstream regression corpus has no
shared-
free();return;-via-goto epilogue, so it never fires there (0/675change). Per the proposal, tail duplication changes rendering on real functions,
so default-OFF is the safe, sibling-consistent choice even though it is correct.
single-func ~0.17 s off/on; full datatest corpus 6.8 s off vs 6.7 s on (noise).
Tests / gates
tests/stages/ghangr-morton-my-message-callback-bfd2fa.xmlon a loadable x86-64ELF (morton) bytechunk: pass 1 (off) = 1 goto + 1 label (bug); pass 2 (on) = 0
goto / 0 label, tail duplicated.
make testPARITY OK (675/675 — default-off byte-identical to upstream).make test-stagesPARITY OK (225/225, +3 morton assertions).make rust-test0 failures (258 ok — incl. catalog byte-compat, actionorder, golden,
.slaparity).kuna catalog --checkOK;docs/assertions.mdregenerated.Does not touch
docs/baseline.json.🤖 Generated with Claude Code
https://claude.ai/code/session_01PBrckq3YYAzBLq5k4KpWac