Repository navigation
Conversation
…ion (tail duplication) angr emits 0 gotos on my_message_callback where kuna emits 1 goto + 1 label to a shared `free(v6); return;` epilogue. Closing this requires a new S8 goto-reduction pass (epilogue tail-duplication) touching the verbatim CollapseStructure engine — large per Hard rule 7. Analysis + proposal + partial record only; no implementation. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Closing — implemented by #103 (
|
| proposal-era kuna | today, defaults | angr 9.2.213 | |
|---|---|---|---|
| gotos | 1 | 0 | 0 |
| labels | 1 | 0 | 0 |
| ifs | 9 | 9 | 9 |
| switches | 0 | 0 | 0 |
The exact construct is gone. The strcmp(v2,"UV") != 0 arm now ends with an inlined free(v5); return; early return carrying an explicit marker, and there is no label_41d6: anywhere in the output:
/* WARNING: taildup: duplicated return-call tail to remove goto */Ablation isolates the responsible feature. --option taildup off reproduces this proposal's baseline verbatim — 1 goto (goto label_41d6;) / 1 label (label_41d6:) / 9 ifs. --option gotoreduce off alone changes nothing (still 0/0); taildup off + gotoreduce off gives 1/1. So taildup — not the gotoreduce name this proposal suggested — is the option that actually closes it.
Why #103 is this proposal's implementation. #103 ("taildup: SAILR tail duplication goto reduction") implements exactly the transform specified here: duplicate a small, bounded, side-effect-limited return tail into the goto source so the cross-edge becomes a structured early return. It mirrors angr ReturnDuplicatorBase, whose budget is calls (max_calls_in_regions=2) rather than call-rejection — which is precisely why it handles the free(p); return; epilogue that gotoreduce (rejects all calls) and crossjumprevert (non-return fall-through tails) both decline. docs/options.md records the win verbatim: "morton my_message_callback: 1 goto -> 0". The bounds this proposal asked for shipped too (≤3 blocks / ≤12 printed ops / ≤2 calls, no STORE).
One deviation worth recording: it landed default-on (DIV-14, #110), not the default-off opt-in this proposal expected. That was decided on ablation evidence, and docs/options.md documents the flip-off case (many early-exit error checks sharing one cleanup epilogue — the C goto out; idiom).
[PROPOSAL] angr-morton-my-message-callback: SAILR-style goto-reduction by epilogue tail-duplication
Status: draft proposal — needs human go/no-go before an implementation worker is spent.
Scope: large (per Hard rule 7 and the recorded decider verdict).
The problem
On
my_message_callbackinmorton(x86_64, @0x403de7) the only structuraldifference between angr and kuna is a single residual
goto+label::kuna:
angr (zero gotos) — it duplicates the shared
free(ptr); return;epilogue into eacharm that reaches it, so the cross-edge becomes a structured early return:
See
analysis.mdandangr-vs-kuna.txtfor the full side-by-side.The angr reference pass / class
This is angr's goto-reduction via tail duplication (the Phoenix/SAILR family in
angr.analyses.decompiler— the region-simplification +DuplicationOptimizer/GotoSimplifierstyle transforms). angr's structurer is allowed to duplicate small,side-effect-bounded tails (a
return, afree(x); return) to eliminate an unstructurededge; its quality metric explicitly trades a few duplicated statements for zero gotos.
Why this is large (owning stage: S8 structuring)
The goto is produced by
decompiler/crates/kuna-decomp/src/s8_structure/blockaction.rs,the verbatim port of Ghidra's
CollapseStructure/TraceDAG/BlockTrace. Itsheader states the schema-precedence order and the DAG bad-edge scoring are
"output-determining ... transcribed verbatim" — they choose which edge becomes a goto.
Ghidra has no schema that duplicates a tail to avoid a goto; that transform simply
does not exist in the collapse algorithm.
Matching angr therefore requires a new structuring transform, not a gated
Actionthat manufactures an artifact for the existing structurer (the way
kuna_loweredswitch.rsmanufactures an S2 BRANCHIND/JumpTable). Concretely it must:
CollapseStructurewhose target is asmall epilogue block (statement-count ≤ threshold, no incoming side effects that would
change semantics if duplicated, e.g. a
free(p); return;);BlockGraphmutation— clone the
BlockBasic, its ops, and rewire edges), then drop the unstructured edge;as a structured early return;
free/returnare real p-code ops, sothis is not a pure print-time rewrite).
That is a new pass type touching S8 structuring/region code beyond a single gated
early-return — two independent triggers of Hard rule 7. The decider verdict (recorded in
record.json) isscope: large.Proposed implementation plan (multi-step — for the approved worker)
kuna_gotoreduce.rs(S8) — a post-CollapseStructureAction,option-gated, default-OFF.
// (kuna)): register the action inuniversalaction.rs/the relevant
coreaction*registration; option flag on the architecture struct(reset-default off);
options.rs;stages.tomlsettableTablerow.BlockGraphhelper to clone aBlockCopy/BlockBasictailand rewire the floating edge (this is the genuinely new, risky piece — it mutates the
structured block tree the verbatim engine produced).
ends in
return), bail on any block with multiple non-goto predecessors that wouldchange semantics, mirroring loweredswitch's fail-safe cap.
tests/stages/ghangr-morton-my-message-callback-bfd2fa.xmltwo-pass(off=goto present, on=goto gone); plus a synthetic minimal CFG fixture.
Speed / risk assessment
Incorrect duplication can change semantics (duplicating a block with side effects reached
by more than the goto source) or desync def/use. The bounds above contain it but need
careful adversarial testing across the datatest corpus.
functions that currently use a clean shared-epilogue goto, so this is expected to ship
default-OFF opt-in even if correct.
must be measured against the +5% budget on the target.
so kuna grows one coherent goto-reduction layer rather than point fixes.
Proposed option name
gotoreduce(change_kind = structure-recovery,source_decompiler = angr,inspiration = test_decompiling_morton_my_message_callback; SAILR/Phoenix goto-reduction (tail duplication); my_message_callback).Recommendation
Go if the team wants kuna to start matching angr/SAILR on goto count (high-value,
broadly applicable, but real structuring risk) — staff it as a deliberate S8 effort with a
full adversarial test pass. No-go / defer if structuring-quality parity with angr is
out of scope right now; the gap is cosmetic (one goto, semantics already correct) and the
implementation cost/risk is disproportionate to this single function.