Repository navigation
Conversation
angr cleanly structures fmt/main's option-parsing loop; kuna emits INVALID C because main has an irreducible (multi-entry) loop (the -WIDTH first-arg goto jumps into the getopt_long loop body). Closing the gap needs new S7/S8/S9 condition-based structuring infrastructure (or promoting the read-only kuna_regiongraph port to drive emit), not a single artifact-manufacturing Action like loweredswitch. Scope-decider verdict: large -> proposal fork. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Contributor
Author
|
Closing — folded into the loop-refinement follow-up (PR #95 landed the parity-safe infra; the goto-win for these irreducible/multi-exit loops is documented as Inc-6 in docs/region-structurer-roadmap.md: acyclic-schema completion + SAILR continuation hoisting). |
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.
[PROPOSAL] angr-fmt0-main-85c389: structure irreducible (multi-entry) loops
Status: draft proposal — awaiting human go/no-go. Do not implement before approval.
test_decompiling_fmt0_main :: main/home/mahaloz/github/angr-dev/binaries/tests/x86_64/fmt_0(GNU coreutilsfmt),main@0x4019b0, x86_64irreducibleloops(change_kind:structure-recovery)record.json)The problem
kuna emits syntactically invalid C for
fmt'smainbecausemaincontains anirreducible (multi-entry) loop: the
-WIDTHfirst-arg special casegotos into thegetopt_longoption-parsing loop body. kuna's Ghidra collapse-based structurer resolvesirreducibility only by emitting gotos, and additionally produces a while-block whose
condition carries side-effecting multi-statements that the S9 printer renders as incomplete
while (...lines. angr recovers a clean, validwhile(true){ ...; if(v==-1) break; ... }.Full evidence:
analysis.md, side-by-side:angr-vs-kuna.txt.angr reference
angr/analyses/decompiler/region_identifier.py—RegionIdentifier(already ported,read-only, as kuna
kuna_regionid/kuna_regiongraphunders7_regions/).angr/analyses/decompiler/structuring/— the SAILR/Phoenix condition-based structurer(
PhoenixStructurer) with_refine_cyclic/ goto-and-loop refinement that handlesmulti-entry loops by node duplication / condition recovery. Not yet ported.
Why this is not a single Action/Rule
loweredswitchworks by manufacturing a missing S2JumpTablethat the existingstructurer already consumes. Here the structurer itself is wrong on irreducible loops —
there is no artifact to pre-build. Closing the gap requires new structuring infrastructure
across S7 (region structuring), S8 (
blockaction.rs), and S9 (printc.rs), > 3 anchorfiles and > 1 new module. The decider verdict (verbatim in
record.json):Proposed multi-step implementation plan
kuna_regiongraph/kuna_regionidfrom read-only to emit-capable. Add aSAILR/Phoenix-style condition-based structuring + goto/loop-refinement layer on top of the
existing
RegionIdentifierso it yields a structured tree (proper loops withbreak/continue, recovered if-conditions, labeled gotos only for residual irreducible
edges) — not just a region dump.
sblocks(BlockGraph) — or into asibling structured representation consumable by a new printer path.
printc.rs::emitBlock*) for the new node kinds soprint Cwalks it and emits valid C (proper
while/break, labeled gotos for true irreducibility).option irreducibleloops on, default OFF. Onlyfunctions whose region tree is detected cyclic and multi-entry route through the new
path; everything else keeps the collapse structurer and byte-identical default output.
tests/stages/ghangr-fmt0-main-85c389.xml(off = currentinvalid rendering / fix = valid
while(true)loop) and record the per-function decompilewall-time off vs on for
main.Speed / risk assessment
function; cost is bounded to detected irreducible functions but must be measured (the
pipeline speed budget is +5% default; if over, ship default-OFF opt-in).
reduced irreducible-loop subset of it) and a new printer path — multi-PR, the largest of the
angr-port surfaces. Recommend scoping a minimal first cut: handle only single-extra-entry
loops via node duplication of the entry block (the
fmtshape), behind the option, beforeattempting the general SAILR structurer.
Recommendation
Approve as a multi-PR effort, or de-scope to "duplicate the single extra loop-entry block so
the collapse structurer sees a reducible loop" as a first, smaller PR (still > 1 anchor file
in S8, hence still proposal-gated). Either way: human go/no-go before any implementation
worker is spent.