Repository navigation
[AUTOMATED] fix(p2): drop a jump table when its BRANCHIND is swept - #234
Merged
Merged
Conversation
`main` in coreutils comm/join/uniq produced no output at all: the decompile
pipeline panicked at `p2_lift/jumptable.rs:1811` and the whole function came back
as a warning shell. Six functions -- comm/join/uniq `main`, at -O0 and at
-O2-noinline -- every one of them the getopt_long dispatch.
The chain. `loweredswitch` (P2, default-on) rewires a comparison cascade's head
into a synthetic BRANCHIND and then sweeps the orphaned compare spine with
`removeUnreachableBlocks`. In these binaries the cascade is only half the
dispatch: the short options ('1'/'2'/'3' and the negative help/version sentinels)
go through the cascade, while the dense long-option range (0x7a, 0x80..0x83) goes
through a genuine GCC PIC relative-offset jump table (`3e ff e0 notrack jmp rax`
at comm 0x3aed, table in .rodata at 0x9800). Severing the cascade head's
out-edges strands that table's block, and the sweep destroys its ops -- including
the real BRANCHIND. The ported `blockRemoveInternal` did NOT drop the table
(`funcdata_block.rs:1369` was `// JumpTable *jt = findJumpTable(op); ... --
STUB(W4)`), so a labelless table survived in `jumpvec`. `ActionSwitchNorm` then
re-recovered its model and `JumpBasic::findDeterminingVarnodes` unwrapped
`inrefs[0]` of a `pcodeop_flags::dead` op.
Two parts, both strict bug fixes, so no option:
1. Parity + crash-proofing. `Funcdata::remove_jump_table` (C++
`Funcdata::removeJumpTable`, `funcdata_block.cc:470`) is ported and
`block_remove_internal` uses it via the existing `find_jump_table_index`,
exactly as `funcdata_block.cc:272` does. `ActionSwitchNorm::apply` gains the
liveness guard `install_switch_defaults` already had (skip a table whose
indirect op is absent / dead / parentless), and
`JumpBasic::find_determining_varnodes` returns `KunaResult<()>` instead of
unwrapping, so a stale table abandons its own recovery rather than the run.
2. Quality. Part 1 alone stops the panic but leaves the real table's block
destroyed: comm `main` then rendered a 60-line body whose switch carried only
the cascade's cases and had silently lost 'z', --check-order, --nocheck-order,
--output-delimiter and --total. So `kuna_install_lowered_switch` now declines
when its rewiring would strand a block whose tail BRANCHIND already owns a
recovered `JumpTable` (`kuna_lowered_switch_strands_table` walks reachability
from the entry over the post-surgery successor relation, before any edit). Its
existing guard only checked for a table at the head's own branch address, which
never matches here -- the cascade head and the real BRANCHIND are different
instructions. This narrows when an existing option fires, so it lives inside
`loweredswitch` rather than behind a new flag.
`tests/stages/ghangr-loweredswitch-mv.xml` (mv -O2, a cascade with no
downstream table) still installs, so the decline is not over-broad.
All six functions now render identically to `--option loweredswitch off`, which
is the shape Ghidra emits (comm `main`: 97 lines, `switch(v1) { case 0x7a ...
case 0x80 ... case 0x83 ... default }`).
Corpus sweep, `kuna decompile-all --json --mode reliable` over 16 stripped
binaries (coreutils/grep/gzip/diffutils, O0 + O2-noinline), 6130 functions: error
records 6 -> 0, all six the `jumptable.rs:1811` panic. The
`ruleaction_2.rs:96`/`ruleaction_3.rs:125` opcode-whitelist family is 0 both
before and after on this base (it landed on main in #227) and is not touched
here.
Speed: no regression. Wall-clock `decompile-all` over 5 binaries, 6 reps each:
before min 35.48 s / median 35.62 s, after min 33.51 s / median 34.83 s.
`python3 -m scripts.pipeline.timeit --option loweredswitch` on comm sub_3994:
off 256.2 ms, on 228.8 ms, delta -10.69% (budget 5.0%) -> within budget.
Gates: make test PARITY OK (675/675), make test-stages PARITY OK (323/323),
make rust-test green, make check-spec OK, kuna catalog --check OK. No baseline
re-pin of docs/baseline.json. Spec prose in docs/spec/02-lift-and-flow.md (table
lifetime and the install decline); regression test
tests/stages/ghdec-stalejumptable.xml (two-pass over the real comm bytes: 0/5
assertions before, 5/5 after). The new stage XML bumps the hard-coded corpus
file count in decompiler/crates/kuna-base/src/xml.rs (177 -> 178).
inspiration = "decbench:cases-missing pool; coreutils comm/join/uniq main"
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_011RXVU58TKJxb518oViChwo
…emoval # Conflicts: # decompiler/crates/kuna-base/src/xml.rs # docs/baseline-stages.json # tests/stages/README.md
mahaloz
added a commit
that referenced
this pull request
Aug 1, 2026
…timating it (#237) The recall pool was the campaign's headline claim and it was carrying an unverified number. Measured properly it is 7,354, not 6,540 -- the smaller figure could not be reproduced under any rival-subset or filter variant. Where it actually goes, and most of this contradicts what the campaign believed: 63 (0.9%) genuinely recovered by the 2026-08-01 fix wave 1,994 (27.1%) already fixed BEFORE the wave -- the stored kuna artifacts were 12-16 days old, so the pool was measuring staleness 3,233 (44.0%) decbench's .text filter, never kuna's fault 2,061 (28.0%) still missing, real kuna gap So the wave's benchmark-visible recall gain is small and the campaign should say so. Two corrections in the other direction: #224 recovered 256 freertos functions decbench structurally cannot score, and both #227 and #234 under-claimed (19 -> measured 50; 6 -> measured 13). 98.3% of the live remainder is function-entry granularity on embedded ARM -- kuna emits a body for code CONTAINING the DWARF low_pc but does not start a function AT it, median 24 bytes away. That is one gap, not two thousand. Highest-value remaining bug: rename_recurse / "Overlapping input varnodes" on gnulib's rpl_fcntl, hard-failing one function in 48 of 213 optimized x86-64 binaries, -O2 only. Method notes worth keeping: matching is by address, never by name; PE targets report ImageBase+RVA where the rival artifacts record RVAs, and uncorrected that fabricates 181 fake gaps.
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.
The bug
mainin coreutilscomm,joinanduniqproduced no output at all: thedecompile pipeline panicked at
p2_lift/jumptable.rs:1811and the whole functioncame back as a warning shell. Six functions, at
-O0and at-O2-noinline,every one of them the
getopt_longdispatch.The chain
loweredswitch(P2, default-on) rewires a comparison cascade's head into asynthetic
BRANCHINDand then sweeps the orphaned compare spine withremoveUnreachableBlocks. In these binaries the cascade is only half thedispatch: the short options (
'1'/'2'/'3'plus the negative help/versionsentinels) go through the cascade, while the dense long-option range
(
0x7a,0x80..0x83) goes through a genuine GCC PIC relative-offset jump table(
3e ff e0 notrack jmp raxat comm0x3aed, table in.rodataat0x9800).Severing the cascade head's out-edges strands that table's block, and the sweep
destroys its ops - including the real
BRANCHIND. The portedblockRemoveInternaldid not drop the table:so a labelless table survived in
jumpvec.ActionSwitchNormre-recovered itsmodel and
JumpBasic::findDeterminingVarnodesunwrappedinrefs[0]of apcodeop_flags::deadop.The fix - two parts, both strict bug fixes (no new option)
1. Parity + crash-proofing.
Funcdata::remove_jump_table(C++Funcdata::removeJumpTable,funcdata_block.cc:470) is ported andblock_remove_internaluses it through the existingfind_jump_table_index,exactly as
funcdata_block.cc:272does.ActionSwitchNorm::applygains theliveness guard
install_switch_defaultsalready had (skip a table whose indirectop is absent / dead / parentless), and
JumpBasic::find_determining_varnodesreturns
KunaResult<()>instead of unwrapping, so a stale table abandons its ownrecovery rather than the run.
2. Quality - and yes, part 2 was needed. Part 1 alone stops the panic but
leaves the real table's block destroyed. comm
mainthen rendered a 60-linebody whose
switchcarried only the cascade's cases and had silently lost-z,--check-order,--nocheck-order,--output-delimiterand--total- strictlyworse than
--option loweredswitch off. Sokuna_install_lowered_switchnowdeclines when its rewiring would strand a block whose tail
BRANCHINDalready owns a recovered
JumpTable(
kuna_lowered_switch_strands_tablewalks reachability from the entry over thepost-surgery successor relation, before any edit). The pre-existing guard only
checked for a table at the head's own branch address, which never matches here -
the cascade head and the real
BRANCHINDare different instructions. Thisnarrows when an existing option fires, so it lives inside
loweredswitchrather than behind a new flag;
tests/stages/ghangr-loweredswitch-mv.xml(mv
-O2, a cascade with no downstream table) still installs.Before / after - comm
main(0x3994,--mode reliable)Before (9 lines, exit 1):
With part 1 only (60 lines - no panic, but the real switch is gone; note the
default arm goes straight to
usage(1)and0x7a/0x80..0x83have vanished):After (97 lines - identical to
--option loweredswitch off, and the sameshape Ghidra emits):
All six functions (
comm/join/uniqmain,-O0and-O2-noinline) are nowbyte-identical to their
--option loweredswitch offrendering. Checked againstthe source (
comm.ccases'1','2','3','z',CHECK_ORDER_OPTION,NOCHECK_ORDER_OPTION,OUTPUT_DELIMITER_OPTION,TOTAL_OPTION) and againstthe stored ghidra/ida panes -
uniqmain's recovered case set (0x30..0x39,0x44,0x66,0x69,0x73,0x75,0x77,0x7a,0x80) matches Ghidra'sexactly, and
joinmainmatches Ghidra's 13 cases.Corpus sweep
kuna decompile-all --json --mode reliableover 16 stripped binaries(coreutils/grep/gzip/diffutils, O0 + O2-noinline), 6130 functions:
p2_lift/jumptable.rs:1811(this PR)ruleaction_2.rs:96/ruleaction_3.rs:125(opcode whitelist, other PR)The opcode-whitelist family already landed on
mainin #227, so it reads 0 onboth sides of this branch. On the pre-#227 base the same sweep read 11 (6 + 5).
(before/after measured on
676ae487; theaftersweep re-run after rebasingonto
1e7b04cdis also 0/6130, and all six functions still render identically totheir
--option loweredswitch offreference there.)Speed
No regression. Wall-clock
decompile-allover 5 binaries, 6 reps each:before min 35.48 s / median 35.62 s, after min 33.51 s / median 34.83 s.
python3 -m scripts.pipeline.timeit --option loweredswitchon commsub_3994:off=256.2 ms on=228.8 ms delta=-10.69% (budget 5.0%) -> within budget.Gates
make test-> PARITY OK (675/675) (nodocs/baseline.jsonre-pin)make test-stages-> PARITY OK (323/323)make rust-test-> greenmake check-spec-> OKkuna catalog --check-> OKDocs + test
docs/spec/02-lift-and-flow.md: a Table lifetime paragraphin the switch-recovery section and the install decline in the
lowered-cascade section.
tests/stages/ghdec-stalejumptable.xml: two-pass over the real comm bytes(pass 1 = default pipeline, pass 2 =
option loweredswitch offas thereference). 0/5 assertions before the fix, 5/5 after.
inspiration = "decbench:cases-missing pool; coreutils comm/join/uniq main"🤖 Generated with Claude Code
https://claude.ai/code/session_011RXVU58TKJxb518oViChwo