Skip to content

[AUTOMATED] feat(p8): itecondlist - re-roll every diamond in a chain, not every other (DIV-56) - #253

Merged
mahaloz merged 1 commit into
mainfrom
feat/decbench-itecondlist
Aug 3, 2026
Merged

mahaloz merged 1 commit into
mainfrom
feat/decbench-itecondlist

Conversation

@mahaloz

@mahaloz mahaloz commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

What

kuna re-rolls only every other ternary in a chain. In a run of N structurally
identical two-arm assignment diamonds, iteregion/iteboolean recover exactly
ceil(N/2) of them; the rest print as if (c) V = A; else { V = B; }. Which ones
are missed depends on the neighbouring structure, not on the diamond itself.

option itecondlist on|off (default ON, DIV-56) closes it: in the condition
position only
, the two matchers now descend a multi-component BlockList to its
last component before applying their usual leaf test.

Analysis: docs/features/itecondlist/analysis.md.
Design + the option decision: plan.md.

The driving case — decbench:O0-bash-bash-shell_initialize (IDA pool, margin 105)

The source has three occurrences of one identical 4-clause || chain, all in
argument position. Before, 1 of 3 re-rolled:

  v1 = shell_is_restricted(shell_name);
  if (((privileged_mode) || (restricted)) || ((v1 || (dat_172330))))
    v4 = 1;
  else {
    v4 = 0;
  }
  initialize_shell_variables(shell_environment,v4);
  initialize_job_control(jobs_m_flag);
  initialize_bash_input();
  initialize_flags();
  v2 = (((privileged_mode) || (restricted)) || ((v1 || (dat_172330))));
  initialize_shell_options(v2);
  if (((privileged_mode) || (restricted)) || ((v1 || (dat_172330))))
    v2 = 1;
  else {
    v2 = 0;
  }
  initialize_bashopts(v2);

After, 3 of 3, statement-for-statement with the source:

  v1 = shell_is_restricted(shell_name);
  v4 = (((privileged_mode) || (restricted)) || ((v1 || (dat_172330))));
  initialize_shell_variables(shell_environment,v4);
  initialize_job_control(jobs_m_flag);
  initialize_bash_input();
  initialize_flags();
  v2 = (((privileged_mode) || (restricted)) || ((v1 || (dat_172330))));
  initialize_shell_options(v2);
  v2 = (((privileged_mode) || (restricted)) || ((v1 || (dat_172330))));
  initialize_bashopts(v2);

GED 46 -> 24 (-48%), ~/.virtualenvs/decbench/bin/python -m scripts.decbench.rescore.
The O2-noinline sibling was already GED 0 and is unmoved (at -O2 gcc computes the
boolean without a materialization diamond).

The N-sweep

gcc -O0 -c on N chained identical diamonds in one function:

N 1 2 3 4 5 6 7 8
ternaries, before 1 1 2 2 3 3 4 4
ternaries, after 1 2 3 4 5 6 7 8

Exactly ceil(N/2) becomes exactly N.

Mechanism, and why it is sound

iteregion and iteboolean both reach the condition component through
kuna_iteregion.rs (leaf_bblock), which descends a BlockList of one
component but bails on a list of two or more. The collapse structurer concatenates
a just-collapsed predecessor together with the following condition block into a
two-component BlockList, and that list becomes component 0 of the next
BlockIf — so a chain alternates between the two shapes.

Confirmed by instrumenting match_ite_assignment on the N = 3 reproducer:

node=BlockId(14v1) cond_ty=Copy         cbr=true    armT=true armE=true   <- folds
node=BlockId(16v1) cond_ty=Ls cond_sz=2 cbr=false   armT=true armE=true   <- declines
node=BlockId(12v1) cond_ty=Copy         cbr=true    armT=true armE=true   <- folds
  (all six arms: ops=[CPUI_COPY] dest=stack:-0xc:4)

Both arms of the declined diamond pass every other test; the only failing
predicate is the condition-leaf descent.

The rewrite is print-only, and the printer already renders this shape:
PrintC::emit_block_if emits the condition component twice — once under
NO_BRANCH (its statements) and once under ONLY_BRANCH (its branch condition) —
and PrintC::emit_block_ls emits every component under NO_BRANCH but only the
last
under ONLY_BRANCH. The leading components therefore already print exactly
once, ahead of the if header, and emit_block_if_ite/emit_block_if_bool do the
same two emissions on the same block. The arms keep the strict single-statement
match, the labelled-goto-target guard still applies to the descended leaf, and the
match struct keeps the outer list as its cond_block.

BlockGraph is deliberately excluded from the descent: emit_block_graph
ignores ONLY_BRANCH and emits every component, so descending one would make the
emitters print the whole graph twice.

The iteboolean descent sits at the BlockType::Condition gate, not inside
cond_terminal_cbranch — that function's leaf arm is only ever reached for the
individual clauses of an already-identified chain, so a descent there can never
fire on the outer list.

New option, not an unflagged widening

iteexpr is the standing precedent: a broadening of the same matcher shipped as
its own option (it widens iteregion's arm match; this widens the
condition match). The new flag is also what buys a two-pass stage test that
pins the exact ceil(N/2) defect — turning iteregion off removes all
ternaries, so it cannot express "every other one is missing".
tests/stages/ghdec-itecondlist.xml folds 2 of 3 with the option off and 3 of 3
with it on, over the same bytes.

It is a strictly narrower match than the two options it widens, so
option itecondlist off can only ever fold fewer diamonds, never different
ones, and is byte-identical to the pre-DIV-56 render.

Breadth + regression sweep (12,241 functions)

decompile-all --mode reliable, option off vs on:

binary functions changed diamonds gained ternaries iteboolean
coreutils ls (O0) 613 3 +5 21 -> 24 23 -> 24
iproute2 ip (O0) 1,962 3 +3 95 -> 97 2 -> 2
bash (O0) 3,278 15 +17 124 -> 135 99 -> 108
betaflight STM32F405 (O2-noinline, ARM) 6,388 32 +34 141 -> 178 0 -> 0
total 12,241 53 (0.43%) +59 381 -> 434 124 -> 134

That is ~5% of the residual declined diamonds in the corpus; the rest are the
separate same_storage defect and the arm-shape declines iteexpr covers.

Every diff hunk was audited mechanically
(audit.py): each must be either a header
comment whose ternary/re-roll count went up, or a removed
if (C) V = A; else { V = B; } replaced by exactly one added
V = (C) ? A : B; / V = (C); / V = !(C); with the same destination,
same condition and same arm expressions in order.

52 header-only hunks, 59 folded diamonds, 0 problems. The two hunks the audit
could not classify automatically were hand-checked and are benign (a bash
comma-expression condition the arm regex cannot parse; and one function whose two
accumulated iteboolean warning lines collapse into one with a byte-identical
body). Error/diagnostic line counts are unchanged in every binary — no function
starts or stops producing output.

Ablation, speed, gates

Ablation with the option default-ON: 0/675 datatest assertions change. No
re-pin of docs/baseline.json, and no per-test opt-out was needed anywhere.

Speed (scripts.pipeline.timeit, target function, 7 samples):
356.33 -> 354.28 ms, -0.58% — inside the +5% budget. Interleaved whole-binary
medians of 5 pairs (decompile-all --mode reliable): coreutils ls
7,193 -> 7,220 ms (+0.38%), gzip 2,881 -> 2,873 ms (-0.28%). The predicate is one
extra pointer chase per candidate BlockIf and mutates no p-code.

Gate Result
make test datatests: 675/675 assertions passed — PARITY OK
make test-stages datatests: 381/381 assertions passed — PARITY OK
make rust-test passed=4424 failed=0 ignored=37, exit 0
make check-spec check-spec OK (lenient mode) / check-spec OK (strict mode)
kuna catalog --check catalog OK: documents exactly the registered kuna options

Not fixed here (deliberately)

The same_storage decline — two arms writing different raw storage (a register
vs a unique, or a unique vs a stack slot) that render as one variable. That is
a second, larger defect; it is what blocks
O2-noinline-betaflight-...-mavlinkSendRCChannelsAndRSSI (4 of its 6 misses) and
most register-resident diamonds. One PR, one feature.

Rebase note (DIV-55 -> DIV-56)

Rebased onto #252 (1b6d4db4, DIV-55, returncopysplit), which was dispatched
concurrently and merged first — DIV numbers are claimed on merge, so this row
is DIV-56. Both rows are kept; they are unrelated mechanisms.

Shared counters resolved on the merged base: xml.rs corpus count 189 (both
PRs moved 187 -> 188), and docs/baseline-stages.json re-recorded rather than
hand-merged (381 = 369 + 6 for #252 + 6 for this PR; the auto-merge had left a
stale 375 in data_footer). The catalog fixture was re-captured on the rebased
tree and is byte-identical — #252 adds no option, so settables stay at 86.

Every number above was re-measured on the rebased tree, not carried forward.
#252 changes emitted C, so the OFF arm of all four sweep binaries was regenerated
and diffed against the pre-rebase OFF arm: 0 lines differ in any of them
(#252's witnesses are O2-noinline ip/sshd; this sweep's ip is O0). The
breadth table, the 53 changed functions, the N-sweep and the 0-problem mechanical
audit all reproduce exactly; the ablation is 0/675 again with the option
default-ON; GED re-measures at 46 -> 24 on the rebased commit. Only the
timings moved, as expected on a shared box.

🤖 Generated with Claude Code

… not every other (DIV-56)

In a run of N structurally identical two-arm assignment diamonds, `iteregion`
and `iteboolean` recovered exactly ceil(N/2) of them (measured N=1..8:
1 1 2 2 3 3 4 4). Which ones were missed depended on the NEIGHBOURING
structure, not on the diamond itself: an immediately preceding structured `if`
suppressed the very next one.

Both matchers reach the diamond's condition component through one helper,
`kuna_iteregion.rs (leaf_bblock)`, which descends a `BlockList` of ONE
component but bails on a list of two or more -- and the collapse structurer
concatenates a just-collapsed predecessor together with the following
condition block into a two-component `BlockList` that becomes component 0 of
the NEXT `BlockIf`. Confirmed by instrumenting `match_ite_assignment`: the
folded diamonds report `cond_ty=Copy cbr=true`, the declined one
`cond_ty=Ls cond_sz=2 cbr=false`, with both arms passing every other test.

New option `itecondlist on|off` (default ON, DIV-56, ELEM 4121) descends a
condition-position `BlockList` to its LAST component before the leaf test.
Print-only and sound because the printer already renders that shape:
`emit_block_if` emits the condition component once under NO_BRANCH (its
statements) and once under ONLY_BRANCH (its branch), while `emit_block_ls`
emits every component under NO_BRANCH but only the LAST under ONLY_BRANCH.
`BlockGraph` is excluded -- `emit_block_graph` ignores ONLY_BRANCH.

Driving case decbench:O0-bash-bash-shell_initialize: GED 46 -> 24, all three
source-identical `x = a||b||c||d;` call arguments now one statement each.
Breadth over 4 binaries / 12,241 functions: 53 functions change text (0.43%),
59 additional diamonds fold, 0 problems in a mechanical audit of every hunk.
Ablation 0/675 with the flip; speed -1.07% on the target function.

Rebased onto #252 (1b6d4db, DIV-55, returncopysplit), which was dispatched
concurrently and merged first -- DIV numbers are claimed on merge, so this row
renumbered 55 -> 56. Both PRs moved the xml.rs corpus count 187 -> 188, so it
resolves to 189, and docs/baseline-stages.json was re-recorded on the merged
base (381 keys) rather than hand-merged. Every measurement was re-taken on the
rebased tree: #252 moves the OFF arm of all four sweep binaries by 0 lines, so
the breadth, changed-function, N-sweep and audit numbers reproduce exactly.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_017dPFaKJanfLSf7mWGhkzkL
@mahaloz
mahaloz force-pushed the feat/decbench-itecondlist branch from ec147d1 to b29d93e Compare August 3, 2026 09:53
@mahaloz mahaloz changed the title [AUTOMATED] feat(p8): itecondlist - re-roll every diamond in a chain, not every other (DIV-55) [AUTOMATED] feat(p8): itecondlist - re-roll every diamond in a chain, not every other (DIV-56) Aug 3, 2026
@mahaloz
mahaloz merged commit 6554346 into main Aug 3, 2026
9 checks passed
@mahaloz
mahaloz deleted the feat/decbench-itecondlist branch August 3, 2026 10:01
mahaloz added a commit that referenced this pull request Aug 3, 2026
… to its import (DIV-57)

A PE reaches its imports through an Import Address Table slot, which is *data*,
so `call dword ptr [slot]` lifts to a CALLIND through a global. The only pass
that resolves such a target - ActionDeindirect - gates on `Varnode::externref`,
and that flag was set NOWHERE in the workspace: Ghidra sets it from an
ExternRefSymbol (`Scope::addExternalRef`) the port never carried. So every
Windows API call in every PE stayed an unnamed `(*dat_4112c4)(0)` with no name,
no prototype and no no-return flow effect - a function ending in ExitThread kept
its fall-through and swallowed the whole of the next function.

Three parts behind one option (`peimportcall`, P1, default-ON, DIV-57):

1. A new PE/COFF-only analysis pass reports one `[slot, slot+ptr)` range per
   import-descriptor entry and the commit ORs `Varnode::externref` over each in
   the symbol-table property map - the same `set_property_range` the loader's
   read-only ranges use. No second symbol is mapped: kuna's `query_function`
   keys on the varnode's own address where upstream indirects through
   `ExternRefSymbol::refaddr`, and the import FunctionSymbol's 1-byte map entry
   never covers a pointer-width read, so `queryProperties` always takes the
   property branch.
2. `build_global_query` now carries the callee's no-return flag into
   `GlobalEntry`, which `query_function` puts on the prototype handed to
   ActionDeindirect. Without it `deindirect` took its lateRestriction success
   path and never scheduled the restart whose re-flow plants the artificial
   halt, so the boundary stayed wrong even once the call was named.
3. Upstream's PE-only `PEFunctionsThatDoNotReturn` is vendored verbatim and
   matched against a PE/COFF object only - kuna merged the PE and Mach-O name
   sets where upstream keeps them separate, and these names are Windows-only.

ActionDeindirect and FuncCallSpecs::deindirect are unchanged consumers. The
mechanism the triage record filed (a new P2 pass matching the CALLIND shape) was
refuted first: at that seam the target is a free unique temp and raw flow IR
carries no def-use links, so the backward walk it needs is unavailable.

Measurements: decbench `O0-mydoom-mydoom-mmsender_th` GED 37 -> 0 (perfect) and
its un-triaged sibling `sync_visual_th` 39 -> 0 (perfect); over both corpus PEs
927 unnamed IAT-slot calls -> 8 with 71/90 distinct Win32 API names recovered,
8 boundary overruns fixed, no function gained or lost, gotos never increase;
ELF/Mach-O byte-identical; timeit -1.9%, whole-binary -7.2% / -2.1%.

Rebased onto 6554346 (after #252/DIV-55 and #253/DIV-56): corpus file count 190,
settables 87 (transform tier 41, live-value 29), phase_catalog.json re-captured and
docs/baseline-stages.json re-recorded (386 keys) on the rebased tree rather than
hand-merged. Every measurement above re-run on that base; the PE and ELF witnesses are
bit-for-bit unchanged by either merge.

Gates: make test 675/675 PARITY OK (no re-pin, no per-test opt-out);
make test-stages 386/386 PARITY OK; make rust-test green;
make check-spec OK (lenient + strict); kuna catalog --check OK.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_017dPFaKJanfLSf7mWGhkzkL
mahaloz added a commit that referenced this pull request Aug 3, 2026
… to its import (DIV-57) (#254)

A PE reaches its imports through an Import Address Table slot, which is *data*,
so `call dword ptr [slot]` lifts to a CALLIND through a global. The only pass
that resolves such a target - ActionDeindirect - gates on `Varnode::externref`,
and that flag was set NOWHERE in the workspace: Ghidra sets it from an
ExternRefSymbol (`Scope::addExternalRef`) the port never carried. So every
Windows API call in every PE stayed an unnamed `(*dat_4112c4)(0)` with no name,
no prototype and no no-return flow effect - a function ending in ExitThread kept
its fall-through and swallowed the whole of the next function.

Three parts behind one option (`peimportcall`, P1, default-ON, DIV-57):

1. A new PE/COFF-only analysis pass reports one `[slot, slot+ptr)` range per
   import-descriptor entry and the commit ORs `Varnode::externref` over each in
   the symbol-table property map - the same `set_property_range` the loader's
   read-only ranges use. No second symbol is mapped: kuna's `query_function`
   keys on the varnode's own address where upstream indirects through
   `ExternRefSymbol::refaddr`, and the import FunctionSymbol's 1-byte map entry
   never covers a pointer-width read, so `queryProperties` always takes the
   property branch.
2. `build_global_query` now carries the callee's no-return flag into
   `GlobalEntry`, which `query_function` puts on the prototype handed to
   ActionDeindirect. Without it `deindirect` took its lateRestriction success
   path and never scheduled the restart whose re-flow plants the artificial
   halt, so the boundary stayed wrong even once the call was named.
3. Upstream's PE-only `PEFunctionsThatDoNotReturn` is vendored verbatim and
   matched against a PE/COFF object only - kuna merged the PE and Mach-O name
   sets where upstream keeps them separate, and these names are Windows-only.

ActionDeindirect and FuncCallSpecs::deindirect are unchanged consumers. The
mechanism the triage record filed (a new P2 pass matching the CALLIND shape) was
refuted first: at that seam the target is a free unique temp and raw flow IR
carries no def-use links, so the backward walk it needs is unavailable.

Measurements: decbench `O0-mydoom-mydoom-mmsender_th` GED 37 -> 0 (perfect) and
its un-triaged sibling `sync_visual_th` 39 -> 0 (perfect); over both corpus PEs
927 unnamed IAT-slot calls -> 8 with 71/90 distinct Win32 API names recovered,
8 boundary overruns fixed, no function gained or lost, gotos never increase;
ELF/Mach-O byte-identical; timeit -1.9%, whole-binary -7.2% / -2.1%.

Rebased onto 6554346 (after #252/DIV-55 and #253/DIV-56): corpus file count 190,
settables 87 (transform tier 41, live-value 29), phase_catalog.json re-captured and
docs/baseline-stages.json re-recorded (386 keys) on the rebased tree rather than
hand-merged. Every measurement above re-run on that base; the PE and ELF witnesses are
bit-for-bit unchanged by either merge.

Gates: make test 675/675 PARITY OK (no re-pin, no per-test opt-out);
make test-stages 386/386 PARITY OK; make rust-test green;
make check-spec OK (lenient + strict); kuna catalog --check OK.


Claude-Session: https://claude.ai/code/session_017dPFaKJanfLSf7mWGhkzkL

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
mahaloz added a commit that referenced this pull request Aug 3, 2026
…n entries on containment evidence

Step 2 of the approved ARM entry-recall sequence ([PROPOSAL] #239) and the one it
called the prize: 1,671 missed function entries, 56.8% of the whole ARM
entry-recall gap, every one of them reachable only through a code-pointer word
that `aif::code_pointer_table_seeds` already finds and then throws away.

The shipped Stage-3 scan requires a pointer's target to open with a Thumb
stack-frame prologue and to disassemble into more than two instructions. On
bare-metal firmware that is the wrong population: 93.3% of the missed entries
establish no frame at all and 41% are <= 8-byte leaves (`movs r0,#0; bx lr`, or a
bare `bx lr`, which is a valid Cortex-M exception handler every rival recovers).
Those two predicates reject 1,632 of the 1,671.

Deleting them is not shippable - the proposal measured the naive relaxation at 62%
ground truth with 21% of the new entries splitting a real function body, a failure
mode decbench structurally cannot see. So the whole of this change is the precision
model, and the model is CONTAINMENT rather than shape: reject a target when any
word that references it overlaps a decoded instruction (it is operand bytes, not a
table slot) or lies in the same discovered function as the target itself (that
pairing IS the `ldr pc,[pc,r]` switch table). Measured over 3,462 validated
candidates the two guards take splits from 1,261 to 0 for 17 ground-truth entries.
The `MIN_SUBROUTINE_INSNS` floor is replaced, not deleted, by a terminating-routine
check: the same speculative walk with the strict escape policy and no minimum
length.

This is kuna's form of the line Ghidra draws between `OperandReferenceAnalyzer`
(creates functions, from instruction operands) and `DataOperandReferenceAnalyzer`,
which overrides `createFunctions` to a no-op - "don't ever create a function from a
data pointer". kuna cannot use Ghidra's version directly because the Listing tier
records only control-flow references, so the containment pair recovers the same
discrimination from the code/data partition the walk leaves behind.

Measured on the 48-image decbench Cortex-M corpus (41,378 DWARF ground-truth
addresses), `kuna functions`:

  recall 38,238 (92.4%) -> 39,851 (96.3%), +1,613
  1,694 new entries, 1,613 ground truth (95.2%)
  0 splitting a real function body, 81 outside any DWARF body
  0 entries lost, 0 ground-truth entries lost

`--option listing off` is structurally inert (ptrentry is a Listing consumer): 0
new, 0 lost. Whole-binary `decompile-all --json` is sha256-identical off vs on for
x86-64, ARM Linux and the Cortex-M images with no admissible candidate.

Two things the proposal asked for that measurement rejected, both built and
measured rather than argued (tables in docs/features/ptrentry/):

  - table-run corroboration: a switch table IS a run, so it removes no additional
    split, and it costs 311 ground-truth functions (1,302 vs 1,613);
  - re-seeding the recursive-descent walk (what Stages 2-3 do): +13 ground-truth
    entries but 974 split bodies and 734 dropped entries, through the same
    tail-call absorption that constrained step 1. The pass therefore emits entry
    facts only, which makes "never removes an entry" a property of the wiring
    rather than of a heuristic. That also settles the proposal's optional AIF
    gap-start re-walk fold-in: closing it IS a walk re-seed, so it stays with
    step 3.

Default-OFF and not auto-injected by any driver: it discovers more functions, so it
changes emitted C by construction, and the precision numbers want a human read
before a flip. No DIV row (default output is byte-identical).

Tests: `kuna-console/tests/verify_ptrentry.rs` is the two-pass e2e over a new
hand-assembled fixture carrying both shapes - the pointer-only leaf that must be
recovered and the switch-table case that must stay rejected with the option ON -
plus three unit tests and a superset-property pin. No `tests/stages/*.xml`: the
harness embeds raw `<bytechunk>`s and never builds a load image or a Listing, the
same reason every sibling analysis-tier discovery flag ships a cross-crate
`verify_*` gate.

Gates on the rebased tree (origin/main 208bb15, after #252/#253/#254): make test
PARITY OK 675/675; make test-stages PARITY OK 386/386; make rust-test green
(295/295 result blocks); make check-spec green in strict mode; kuna catalog
--check OK.

Every shared counter is derived from a fresh `phase catalog` capture and a green
run on the rebased tree, not by arithmetic: settables 87 -> 88, analysis tier
26 -> 27, catalog JSON rows 86 -> 87, bytecompat fixture 87 -> 88, and the
live-value count stays at 29 because this row declares no codegen live_field.
The `kuna-base/src/xml.rs` corpus count was verified by counting the files (83
datatests + 107 stages = 190, unchanged), and `docs/baseline-stages.json` is
untouched because this PR adds no stages XML. The recall/precision table and the
off-vs-on sha256 ablation were re-measured on the rebased build and are
unchanged, with 0 of 48 per-binary entry sets differing from the pre-rebase run.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_017dPFaKJanfLSf7mWGhkzkL
mahaloz added a commit that referenced this pull request Aug 3, 2026
…n entries on containment evidence (#255)

Step 2 of the approved ARM entry-recall sequence ([PROPOSAL] #239) and the one it
called the prize: 1,671 missed function entries, 56.8% of the whole ARM
entry-recall gap, every one of them reachable only through a code-pointer word
that `aif::code_pointer_table_seeds` already finds and then throws away.

The shipped Stage-3 scan requires a pointer's target to open with a Thumb
stack-frame prologue and to disassemble into more than two instructions. On
bare-metal firmware that is the wrong population: 93.3% of the missed entries
establish no frame at all and 41% are <= 8-byte leaves (`movs r0,#0; bx lr`, or a
bare `bx lr`, which is a valid Cortex-M exception handler every rival recovers).
Those two predicates reject 1,632 of the 1,671.

Deleting them is not shippable - the proposal measured the naive relaxation at 62%
ground truth with 21% of the new entries splitting a real function body, a failure
mode decbench structurally cannot see. So the whole of this change is the precision
model, and the model is CONTAINMENT rather than shape: reject a target when any
word that references it overlaps a decoded instruction (it is operand bytes, not a
table slot) or lies in the same discovered function as the target itself (that
pairing IS the `ldr pc,[pc,r]` switch table). Measured over 3,462 validated
candidates the two guards take splits from 1,261 to 0 for 17 ground-truth entries.
The `MIN_SUBROUTINE_INSNS` floor is replaced, not deleted, by a terminating-routine
check: the same speculative walk with the strict escape policy and no minimum
length.

This is kuna's form of the line Ghidra draws between `OperandReferenceAnalyzer`
(creates functions, from instruction operands) and `DataOperandReferenceAnalyzer`,
which overrides `createFunctions` to a no-op - "don't ever create a function from a
data pointer". kuna cannot use Ghidra's version directly because the Listing tier
records only control-flow references, so the containment pair recovers the same
discrimination from the code/data partition the walk leaves behind.

Measured on the 48-image decbench Cortex-M corpus (41,378 DWARF ground-truth
addresses), `kuna functions`:

  recall 38,238 (92.4%) -> 39,851 (96.3%), +1,613
  1,694 new entries, 1,613 ground truth (95.2%)
  0 splitting a real function body, 81 outside any DWARF body
  0 entries lost, 0 ground-truth entries lost

`--option listing off` is structurally inert (ptrentry is a Listing consumer): 0
new, 0 lost. Whole-binary `decompile-all --json` is sha256-identical off vs on for
x86-64, ARM Linux and the Cortex-M images with no admissible candidate.

Two things the proposal asked for that measurement rejected, both built and
measured rather than argued (tables in docs/features/ptrentry/):

  - table-run corroboration: a switch table IS a run, so it removes no additional
    split, and it costs 311 ground-truth functions (1,302 vs 1,613);
  - re-seeding the recursive-descent walk (what Stages 2-3 do): +13 ground-truth
    entries but 974 split bodies and 734 dropped entries, through the same
    tail-call absorption that constrained step 1. The pass therefore emits entry
    facts only, which makes "never removes an entry" a property of the wiring
    rather than of a heuristic. That also settles the proposal's optional AIF
    gap-start re-walk fold-in: closing it IS a walk re-seed, so it stays with
    step 3.

Default-OFF and not auto-injected by any driver: it discovers more functions, so it
changes emitted C by construction, and the precision numbers want a human read
before a flip. No DIV row (default output is byte-identical).

Tests: `kuna-console/tests/verify_ptrentry.rs` is the two-pass e2e over a new
hand-assembled fixture carrying both shapes - the pointer-only leaf that must be
recovered and the switch-table case that must stay rejected with the option ON -
plus three unit tests and a superset-property pin. No `tests/stages/*.xml`: the
harness embeds raw `<bytechunk>`s and never builds a load image or a Listing, the
same reason every sibling analysis-tier discovery flag ships a cross-crate
`verify_*` gate.

Gates on the rebased tree (origin/main 208bb15, after #252/#253/#254): make test
PARITY OK 675/675; make test-stages PARITY OK 386/386; make rust-test green
(295/295 result blocks); make check-spec green in strict mode; kuna catalog
--check OK.

Every shared counter is derived from a fresh `phase catalog` capture and a green
run on the rebased tree, not by arithmetic: settables 87 -> 88, analysis tier
26 -> 27, catalog JSON rows 86 -> 87, bytecompat fixture 87 -> 88, and the
live-value count stays at 29 because this row declares no codegen live_field.
The `kuna-base/src/xml.rs` corpus count was verified by counting the files (83
datatests + 107 stages = 190, unchanged), and `docs/baseline-stages.json` is
untouched because this PR adds no stages XML. The recall/precision table and the
off-vs-on sha256 ablation were re-measured on the rebased build and are
unchanged, with 0 of 48 per-binary entry sets differing from the pre-rebase run.


Claude-Session: https://claude.ai/code/session_017dPFaKJanfLSf7mWGhkzkL

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
mahaloz added a commit that referenced this pull request Aug 3, 2026
…cost this round

Docs-only. No .rs, no phases.toml, no baselines, no tests.

Round 2 shipped, and the benchmark signal was refreshed on 2026-08-03 (all three
opt levels re-decompiled from pinned kuna 9623dc2). Several documented claims
were provably stale and several hard-won operational facts existed only in agent
transcripts. Both fixed, every number re-verified against the live tree.

docs/decbench-loop.md
- Standings replaced and widened: GED ida 36.06 / kuna 35.93 / angr 34.20,
  overall ida 38.01 / kuna 37.91 / angr 36.98, byte_match kuna 3.41 (first).
  Stated plainly that kuna's column is current while the rivals' are from their
  own last runs, so the tree is a MINING INSTRUMENT, not a leaderboard.
- Recall pool: 6,540 (7.3%) -> 1,420 vs angr / 1,552 vs ida, 0 whole-binary
  failures, now almost entirely embedded ARM Cortex-M. All three named causes
  corrected: "u-boot 100% / freertos 100%" was a decbench .text-filter artifact
  and never a kuna discovery failure (angr and ida score nothing there);
  "betaflight 22%" is 6.0%; the coreutils `main` empty-body/panic is fixed
  (comm/join/timeout/uniq all produce full bodies today).
- The `--mode auto` degrades-to-fast warning is moot for this corpus: the
  largest stripped binary is O0 bash at 1,513,904 B (1.44 MiB), so all 803
  binaries resolve 768 aggressive / 35 reliable / 0 fast. The aggressive-vs-
  reliable distinction is kept and sharpened; the stale 21-of-24 default-off
  count is now 20 of 25, with the five exclusions named.
- Two operational traps recorded for the first time:
  (a) byte_match RECOMPILES with an arch-matched toolchain and this box has
      neither arm-none-eabi-gcc nor MinGW, so deleting kuna's (never
      auto-invalidated) checkpoints destroys kuna's ARM/PE scores while every
      rival keeps theirs. The coverage guard caught 34 slices; O2 and
      O2-noinline are still damaged from an earlier DECBENCH_ALLOW_DROPS=1 run
      with no surviving copy. Rule: never pass DECBENCH_ALLOW_DROPS=1 without
      reading every [guard] line.
  (b) The pools store a PE address as an RVA where kuna uses the VA, so
      scripts.decbench.rescore fails on every PE case (119 across the three
      pools). Recorded with a fix direction.
- Pointed at the durable refresh recipe at ~/decbench-campaign-state/ and its
  two pinning rules, plus the non-obvious one: the GED baseline must drop kuna's
  published scores for EVERY re-decompiled opt level, not just the one being
  refreshed (an O0-only baseline died with "cannot reproduce published fallback
  58.0" on an O2 slice).

Method corrections (decbench-loop.md + improvement-pipeline.md standing rules)
- "Not a no-op" is not "correct". On paramcopyhoist a refuter proved the
  proposed hook reached the printer and it was still the wrong site: it deleted
  an assignment, lost an early return, and made another function return the
  wrong parameter. The refute brief now carries an explicit "would this produce
  WRONG output?" axis.
- Diff every changed function, not the witness. Those designs all passed on
  their witness. Round 2's PRs swept 3,031 / 12,241 / 14,720 / 15,386 functions;
  two caught real problems that way.
- The tally, honestly: round 1's filed mechanisms were 2-for-5, round 2's
  refuters overturned the filed diagnosis on 3 of 8, and the symptom stood in
  every case.

docs/decbench/features.md
- Round-1 menu replaced by round-2 outcomes, keeping the file's shape and its
  rank-by-correctness thesis: #248 cortexmvectors, #249 funcptralign,
  #250 paramcopyhoist, #251 subright, #252 returncopysplit, #253 itecondlist
  (merged) and #254 peimportcall (IN FLIGHT), each with its measured effect.
- Named the structural finding that outlives them: three separate ported passes
  were dead -- RuleSubRight (stub body), RuleFuncPtrEncoding (live body, stubbed
  input) and ActionDeindirect (live body, a gate bit set nowhere). Each was
  invisible to every test and each had large breadth, so "grep for
  registered-but-unreachable passes" is now a mining route of its own.
- Carried forward what did not ship: undefname-leak (283 functions, 221 with
  uninitialised reads) and catalog-upstream-options (38 upstream-inherited
  ArchOptions invisible to `kuna catalog`).

Re-mined pool tables regenerated against the refreshed tree (snapshot
2026-08-03): backlog.md, backlog-ida.md, novel.md, triage-queue*.json.

Gates: make check-spec OK (lenient and strict); make test 675/675 PARITY OK;
make test-stages 381/381 PARITY OK.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_017dPFaKJanfLSf7mWGhkzkL
mahaloz added a commit that referenced this pull request Aug 3, 2026
…cost this round

Docs-only. No .rs, no phases.toml, no baselines, no tests.
Rebased onto origin/main 4c2b59b (after #254, #255 and #257).

Round 2 shipped, and the benchmark signal was refreshed on 2026-08-03 (all three
opt levels re-decompiled from pinned kuna 9623dc2). Several documented claims
were provably stale and several hard-won operational facts existed only in agent
transcripts. Both fixed, every number re-verified against the live tree.

docs/decbench-loop.md
- Standings replaced and widened: GED ida 36.06 / kuna 35.93 / angr 34.20,
  overall ida 38.01 / kuna 37.91 / angr 36.98, byte_match kuna 3.41 (first).
  Stated plainly that kuna's column is current while the rivals' are from their
  own last runs, so the tree is a MINING INSTRUMENT, not a leaderboard.
- Recall pool: 6,540 (7.3%) -> 1,420 vs angr / 1,552 vs ida, 0 whole-binary
  failures, now almost entirely embedded ARM Cortex-M. All three named causes
  corrected: "u-boot 100% / freertos 100%" was a decbench .text-filter artifact
  and never a kuna discovery failure (angr and ida score nothing there);
  "betaflight 22%" is 6.0%; the coreutils `main` empty-body/panic is fixed
  (comm/join/timeout/uniq all produce full bodies today).
- The `--mode auto` degrades-to-fast warning is moot for this corpus: the
  largest stripped binary is O0 bash at 1,513,904 B (1.44 MiB), so all 803
  binaries resolve 768 aggressive / 35 reliable / 0 fast. The aggressive-vs-
  reliable distinction is kept and sharpened; the stale 21-of-24 default-off
  count is now 20 of 25, with the five exclusions named.
- Two operational traps recorded for the first time:
  (a) byte_match RECOMPILES with an arch-matched toolchain and this box has
      neither arm-none-eabi-gcc nor MinGW, so deleting kuna's (never
      auto-invalidated) checkpoints destroys kuna's ARM/PE scores while every
      rival keeps theirs. The coverage guard caught 34 slices; O2 and
      O2-noinline are still damaged from an earlier DECBENCH_ALLOW_DROPS=1 run
      with no surviving copy. Rule: never pass DECBENCH_ALLOW_DROPS=1 without
      reading every [guard] line.
  (b) The pools store a PE address as an RVA where kuna uses the VA, so
      scripts.decbench.rescore fails on every PE case (119 across the three
      pools). Recorded with a fix direction.
- Pointed at the durable refresh recipe at ~/decbench-campaign-state/ and its
  two pinning rules, plus the non-obvious one: the GED baseline must drop kuna's
  published scores for EVERY re-decompiled opt level, not just the one being
  refreshed (an O0-only baseline died with "cannot reproduce published fallback
  58.0" on an O2 slice).

Method corrections (decbench-loop.md + improvement-pipeline.md standing rules)
- "Not a no-op" is not "correct". On paramcopyhoist a refuter proved the
  proposed hook reached the printer and it was still the wrong site: it deleted
  an assignment, lost an early return, and made another function return the
  wrong parameter. The refute brief now carries an explicit "would this produce
  WRONG output?" axis.
- Diff every changed function, not the witness. Those designs all passed on
  their witness. Round 2's PRs swept 3,031 / 12,241 / 14,720 / 15,386 functions;
  two caught real problems that way.
- The tally, honestly: round 1's filed mechanisms were 2-for-5, round 2's
  refuters overturned the filed diagnosis on 3 of 8, and the symptom stood in
  every case.

Shared counters in a busy queue (decbench-loop.md + improvement-pipeline.md)
- Round 2 ran up to four output-changing PRs over the same hard-coded counters
  and produced three failure shapes, only one of which announced itself: a
  conflict (#257's DIV number raced 55 -> 56 -> 57 -> 58); a SILENT
  identical-edit auto-merge (catalog_bytecompat.rs kept 86 because both sides
  made the same 85 -> 86 edit); and a SILENT keep-both auto-merge (a stale
  baseline-stages.json data_footer, and five rounds of keep-both duplicating a
  row in tests/stages/README.md).
- Rules written down: derive every shared counter from a fresh capture and a
  green run on the rebased tree, never by arithmetic; diff every keep-both
  resolution against main asserting you removed nothing and added nothing twice;
  DIV numbers are claimed on merge; re-run the gates AFTER the rebase.
- New standing requirement 9: re-measure after every rebase, never carry a
  number forward. #257's placeholder count moved 2,143 -> 2,142 because #254
  landed underneath it, caught only by re-measuring.

docs/decbench/features.md
- Round-1 menu replaced by round-2 outcomes, keeping the file's shape and its
  rank-by-correctness thesis. NINE merged PRs: #248 cortexmvectors,
  #249 funcptralign, #250 paramcopyhoist, #251 subright, #252 returncopysplit,
  #253 itecondlist, #254 peimportcall (DIV-57), #255 ptrentry and #257 undefname
  (DIV-58) -- seven of the eight round-2 candidates plus steps 1 and 2 of the
  ARM entry-recall sequence (#239). Only three of the nine move GED on a mined
  case; four are correctness fixes the metric cannot see and two are recall.
- The dead-pass finding is now three DISTINCT shapes to grep for, not one
  anecdote: stub body (RuleSubRight), live body with a permanently-zero input
  (RuleFuncPtrEncoding's hard-coded funcptr_align() = 0), and live body with a
  gate bit that has no writer anywhere (ActionDeindirect / externref). The third
  had a second gap in the same chain -- GlobalEntry::func_no_return never copied
  the callee's no-return flag into the snapshot -- so one dead gate can hide
  another.
- The ARM sequence is cross-referenced to the live table on PR #239 rather than
  duplicated here, so it cannot go stale in-repo.
- Carried forward as the one still-open candidate: catalog-upstream-options
  (38 upstream-inherited ArchOptions invisible to `kuna catalog`).

Re-mined pool tables regenerated against the refreshed tree (snapshot
2026-08-03): backlog.md, backlog-ida.md, novel.md, triage-queue*.json.

Gates on the rebased base: make check-spec OK (lenient and strict);
make test 675/675 PARITY OK; make test-stages 394/394 PARITY OK.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_017dPFaKJanfLSf7mWGhkzkL
mahaloz added a commit that referenced this pull request Aug 3, 2026
…cost this round (#256)

Docs-only. No .rs, no phases.toml, no baselines, no tests.
Rebased onto origin/main 4c2b59b (after #254, #255 and #257).

Round 2 shipped, and the benchmark signal was refreshed on 2026-08-03 (all three
opt levels re-decompiled from pinned kuna 9623dc2). Several documented claims
were provably stale and several hard-won operational facts existed only in agent
transcripts. Both fixed, every number re-verified against the live tree.

docs/decbench-loop.md
- Standings replaced and widened: GED ida 36.06 / kuna 35.93 / angr 34.20,
  overall ida 38.01 / kuna 37.91 / angr 36.98, byte_match kuna 3.41 (first).
  Stated plainly that kuna's column is current while the rivals' are from their
  own last runs, so the tree is a MINING INSTRUMENT, not a leaderboard.
- Recall pool: 6,540 (7.3%) -> 1,420 vs angr / 1,552 vs ida, 0 whole-binary
  failures, now almost entirely embedded ARM Cortex-M. All three named causes
  corrected: "u-boot 100% / freertos 100%" was a decbench .text-filter artifact
  and never a kuna discovery failure (angr and ida score nothing there);
  "betaflight 22%" is 6.0%; the coreutils `main` empty-body/panic is fixed
  (comm/join/timeout/uniq all produce full bodies today).
- The `--mode auto` degrades-to-fast warning is moot for this corpus: the
  largest stripped binary is O0 bash at 1,513,904 B (1.44 MiB), so all 803
  binaries resolve 768 aggressive / 35 reliable / 0 fast. The aggressive-vs-
  reliable distinction is kept and sharpened; the stale 21-of-24 default-off
  count is now 20 of 25, with the five exclusions named.
- Two operational traps recorded for the first time:
  (a) byte_match RECOMPILES with an arch-matched toolchain and this box has
      neither arm-none-eabi-gcc nor MinGW, so deleting kuna's (never
      auto-invalidated) checkpoints destroys kuna's ARM/PE scores while every
      rival keeps theirs. The coverage guard caught 34 slices; O2 and
      O2-noinline are still damaged from an earlier DECBENCH_ALLOW_DROPS=1 run
      with no surviving copy. Rule: never pass DECBENCH_ALLOW_DROPS=1 without
      reading every [guard] line.
  (b) The pools store a PE address as an RVA where kuna uses the VA, so
      scripts.decbench.rescore fails on every PE case (119 across the three
      pools). Recorded with a fix direction.
- Pointed at the durable refresh recipe at ~/decbench-campaign-state/ and its
  two pinning rules, plus the non-obvious one: the GED baseline must drop kuna's
  published scores for EVERY re-decompiled opt level, not just the one being
  refreshed (an O0-only baseline died with "cannot reproduce published fallback
  58.0" on an O2 slice).

Method corrections (decbench-loop.md + improvement-pipeline.md standing rules)
- "Not a no-op" is not "correct". On paramcopyhoist a refuter proved the
  proposed hook reached the printer and it was still the wrong site: it deleted
  an assignment, lost an early return, and made another function return the
  wrong parameter. The refute brief now carries an explicit "would this produce
  WRONG output?" axis.
- Diff every changed function, not the witness. Those designs all passed on
  their witness. Round 2's PRs swept 3,031 / 12,241 / 14,720 / 15,386 functions;
  two caught real problems that way.
- The tally, honestly: round 1's filed mechanisms were 2-for-5, round 2's
  refuters overturned the filed diagnosis on 3 of 8, and the symptom stood in
  every case.

Shared counters in a busy queue (decbench-loop.md + improvement-pipeline.md)
- Round 2 ran up to four output-changing PRs over the same hard-coded counters
  and produced three failure shapes, only one of which announced itself: a
  conflict (#257's DIV number raced 55 -> 56 -> 57 -> 58); a SILENT
  identical-edit auto-merge (catalog_bytecompat.rs kept 86 because both sides
  made the same 85 -> 86 edit); and a SILENT keep-both auto-merge (a stale
  baseline-stages.json data_footer, and five rounds of keep-both duplicating a
  row in tests/stages/README.md).
- Rules written down: derive every shared counter from a fresh capture and a
  green run on the rebased tree, never by arithmetic; diff every keep-both
  resolution against main asserting you removed nothing and added nothing twice;
  DIV numbers are claimed on merge; re-run the gates AFTER the rebase.
- New standing requirement 9: re-measure after every rebase, never carry a
  number forward. #257's placeholder count moved 2,143 -> 2,142 because #254
  landed underneath it, caught only by re-measuring.

docs/decbench/features.md
- Round-1 menu replaced by round-2 outcomes, keeping the file's shape and its
  rank-by-correctness thesis. NINE merged PRs: #248 cortexmvectors,
  #249 funcptralign, #250 paramcopyhoist, #251 subright, #252 returncopysplit,
  #253 itecondlist, #254 peimportcall (DIV-57), #255 ptrentry and #257 undefname
  (DIV-58) -- seven of the eight round-2 candidates plus steps 1 and 2 of the
  ARM entry-recall sequence (#239). Only three of the nine move GED on a mined
  case; four are correctness fixes the metric cannot see and two are recall.
- The dead-pass finding is now three DISTINCT shapes to grep for, not one
  anecdote: stub body (RuleSubRight), live body with a permanently-zero input
  (RuleFuncPtrEncoding's hard-coded funcptr_align() = 0), and live body with a
  gate bit that has no writer anywhere (ActionDeindirect / externref). The third
  had a second gap in the same chain -- GlobalEntry::func_no_return never copied
  the callee's no-return flag into the snapshot -- so one dead gate can hide
  another.
- The ARM sequence is cross-referenced to the live table on PR #239 rather than
  duplicated here, so it cannot go stale in-repo.
- Carried forward as the one still-open candidate: catalog-upstream-options
  (38 upstream-inherited ArchOptions invisible to `kuna catalog`).

Re-mined pool tables regenerated against the refreshed tree (snapshot
2026-08-03): backlog.md, backlog-ida.md, novel.md, triage-queue*.json.

Gates on the rebased base: make check-spec OK (lenient and strict);
make test 675/675 PARITY OK; make test-stages 394/394 PARITY OK.


Claude-Session: https://claude.ai/code/session_017dPFaKJanfLSf7mWGhkzkL

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
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