Skip to content

crossjumprevert: revert cross-jump tail condensing (angr CrossJumpReverter) - #92

Merged
mahaloz merged 2 commits into
mainfrom
feat/crossjumpreverter
Jun 26, 2026
Merged

mahaloz merged 2 commits into
mainfrom
feat/crossjumpreverter

Conversation

@mahaloz

@mahaloz mahaloz commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

What

Ports angr's SAILR CrossJumpReverter (Basque et al., USENIX Security 2024) as a
new S8 goto-reduction pass, gated by a new --option crossjumprevert (default-OFF,
opt-in). It reverts compiler Irreducible Statement Condensing (cross jumping): when a
non-return tail block is shared by several predecessors and reached by a goto, the pass
duplicates that tail back into the goto source so both paths fall straight through and
the goto/label vanish.

This is the sibling of the existing gotoreduce option: gotoreduce duplicates return
tails (a closed path); crossjumprevert duplicates a non-return, fall-through tail,
which additionally requires a convergence precondition.

The gap (proposal #89, who.o::scan_entries)

kuna emits one residual goto label_4012b5 in scan_entries; angr's full preset emits
zero. The need_deadprocs && v1 == 8 case and the skip/else path share an identical
v1 = *a1; reload tail that the compiler condensed into one block reached by a goto. With
crossjumprevert on, kuna duplicates the tail back into the deadprocs arm
(print_deadprocs(a1); v1 = *a1;), the goto/label disappear, and the function reaches
zero gotos — matching angr.

Target fn: who.o::scan_entries (x86-64). ON-vs-OFF goto delta: 1 -> 0.

How

A new ActionCrossJumpReverter (s8_structure/kuna_crossjumpreverter.rs) runs after
ActionFinalStructure and after ActionGotoReduce (per the angr docstring,
CrossJumpReverter is the last deoptimization). Over the structured (sblocks) tree it finds
every unstructured BlockGoto whose target is:

  1. a single-successor non-return BlockCopy tail (angr out_degree(T) == 1), bounded
    (one tail block, <=8 printed ops, no STORE, <=1 call — angr max_call_duplications),
    counting only printed ops so SSA MULTIEQUAL/INDIRECT markers don't inflate the bound;
  2. convergent — the place flow reaches after the goto's body completes
    (BlockGraph::next_flow_after, the structured-tree post-dominance primitive) is exactly
    the tail's own fall-through successor. This is the correctness-critical precondition: it
    guarantees goto T; T; -> S and the inlined T; -> S' land on the same successor
    (S == S'). The pass declines on any doubt (e.g. when the goto is nested such that
    removing it would fall into a sibling case).

The surgery (BlockGraph::kuna_inline_crossjump_tail) appends fresh BlockCopy leaves
(re-emitting the same ops — no p-code cloned, SSA/def-use untouched) after the goto's body
and switches the node kind from Goto to Ls (plain list), so the goto/label vanish. Each
duplication is logged via Funcdata::warning (crossjumprevert: duplicated cross-jump tail to remove goto). Edges are not rewired (this runs after final structuring; the C
printer walks components/copy pointers, not edges).

Default decision

Default-OFF, opt-in. Per the standing rule (default-ON only if 0/675 and within
budget): the option leaves all 675 datatests byte-identical (default-off early-return), so
docs/baseline.json is untouched. Cross-jump duplication is a structure-altering
de-optimization with a correctness-critical precondition; shipping it opt-in (like its
sibling gotoreduce and branchflip) is the conservative choice until a clean default-ON
ablation is proven.

Validation / gates

  • make test — PARITY OK, 675/675 (default-off => byte-identical, baseline untouched).
  • make test-stages — PARITY OK, 207/207 (new
    tests/stages/ghangr-who-condensing-opt-reversion-72e518.xml: a minimal hand-assembled
    x86-64 bytechunk faithful to scan_entries' CFG; pass 1 off => the cross-jump goto + label,
    pass 2 on => duplicated tail + the log + zero gotos).
  • make rust-test — green (action-tree leaf-count/order oracle + catalog byte-compat
    fixture updated for the new leaf/settable; settable count 49 -> 50).
  • kuna catalog --check — OK; docs/assertions.md regenerated.
  • Speed: the pass is a bounded post-structuring tree walk; no measurable decompile-time
    change on scan_entries (timings dominated by subprocess spawn, OFF/ON in the same range).

Registration (standing-rules checklist)

New crossjumprevert option fully wired: stages.toml row + count, options.rs
KUNA_OPTION_NAMES, architecture flag + ctor + reset_defaults + set_kuna_option arm +
seam copy in build_arch_handle + seams.rs field/default; ElementId 4101 (4000+
range); action registered in universalaction.rs.

🤖 Generated with Claude Code

https://claude.ai/code/session_01PBrckq3YYAzBLq5k4KpWac

…erter)

Port angr's SAILR CrossJumpReverter (Basque et al., USENIX Security 2024) as a
new S8 goto-reduction pass, gated by `--option crossjumprevert` (default-OFF,
opt-in). It reverts compiler Irreducible Statement Condensing (cross jumping):
when a non-return tail block is shared by several predecessors and reached by a
goto, the pass duplicates that tail back into the goto source so both paths fall
straight through and the goto/label vanish.

Sibling of the existing `gotoreduce` option: gotoreduce duplicates *return* tails
(a closed path); crossjumprevert duplicates a *non-return, fall-through* tail,
which additionally requires a convergence precondition.

The gap (proposal #89, who.o::scan_entries): kuna emits one residual
`goto label_4012b5`; angr emits zero. The `need_deadprocs && v1 == 8` case and the
skip/else path share an identical `v1 = *a1;` reload tail condensed into one block
reached by a goto. With crossjumprevert on, kuna duplicates the tail back into the
deadprocs arm, the goto/label disappear, and scan_entries reaches zero gotos.

Implementation (s8_structure/kuna_crossjumpreverter.rs, runs after gotoreduce per
the angr docstring): over the structured tree, find every unstructured BlockGoto
whose target is a single-successor non-return BlockCopy tail (angr out_degree==1),
bounded (one tail block, <=8 printed ops, no STORE, <=1 call), counting only
printed ops so SSA MULTIEQUAL/INDIRECT markers don't inflate the bound. The
correctness-critical convergence precondition uses BlockGraph::next_flow_after (the
structured-tree post-dominance primitive): the place flow reaches after the goto's
body must be exactly the tail's own fall-through successor, so goto-T-then-S and the
inlined-T-then-S' land on the same successor. Declines on any doubt. The surgery
(BlockGraph::kuna_inline_crossjump_tail) appends fresh BlockCopy leaves (no p-code
cloned, SSA untouched) after the goto body and switches the node kind Goto->Ls.
Each duplication is logged via Funcdata::warning.

Default-OFF: leaves all 675 datatests byte-identical (baseline untouched). New
option fully registered (stages.toml row + count 49->50, options.rs, architecture
flag + ctor + reset_defaults + set_kuna_option + seam copy + seams.rs; ElementId
4103; action in universalaction.rs). New two-pass stage test
ghangr-who-condensing-opt-reversion-72e518.xml (off: cross-jump goto+label; on:
duplicated tail + log + zero gotos). docs/assertions.md regenerated; catalog/
action-tree/corpus-count test oracles updated for the new leaf/settable.

Gates: make test PARITY OK (675/675); make test-stages PARITY OK (207/207);
kuna catalog --check OK; make rust-test green except the pre-existing unrelated
constseq should-panic test.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01PBrckq3YYAzBLq5k4KpWac
Union-resolve so crossjumprevert (opt-in default-off) coexists with #90's
noreturn_extern and #91's noreturn_externmatch on main. Deconflicted:
- ElementId 4103 -> 4105 (4103=noreturn_extern, 4104=noreturn_externmatch on main)
- stages.toml header surface=95, settable=57 (34 stage-model knobs); +1 settable
- kuna_stages/tests.rs: settable 57, surface 95, json-comma 56, live-value 25
  (crossjumprevert has no live reader, in the suppressed allowlist);
  test fns renamed (settable_count_is_57 / live_value_present_for_25_suppressed_for_32)
- catalog_bytecompat.rs: fixture_has_all_57_settables
- kuna-base/xml.rs corpus count 148 (83 datatests + 65 stage tests)
- kuna-catalog.xml: source_decompiler angr 17, change_kind structure-recovery 9
  (both add crossjumprevert)
- verify_w8_fw_universalaction.rs auto-merged: 262 leaves (252 C++ + branchflip
  + gotoreduce + crossjumprevert + 7 headers); universalaction/seams/architecture/block
  wiring of revert_cross_jumps preserved alongside the noreturn_extern* additions
- regenerated stage_catalog.json fixture, docs/assertions.md, baseline-stages.json (212 keys)

Gates green: kuna catalog --check OK; make test 675/675 PARITY OK;
make test-stages 212/212 PARITY OK.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01PBrckq3YYAzBLq5k4KpWac
@mahaloz
mahaloz merged commit cd34c4c into main Jun 26, 2026
@mahaloz
mahaloz deleted the feat/crossjumpreverter branch July 29, 2026 08:01
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.

1 participant