Skip to content

[AUTOMATED] fix(p1): noreturn_discstrict — a decode failure is not evidence that a callee never returns (DIV-92) - #344

Merged
mahaloz merged 1 commit into
mainfrom
feat/noreturn-discstrict
Aug 27, 2026
Merged

mahaloz merged 1 commit into
mainfrom
feat/noreturn-discstrict

Conversation

@mahaloz

@mahaloz mahaloz commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Closes #312.

noreturn_disc concludes a callee never returns once ≥3 of its call sites "show no
valid fall-through". Three arms implemented that test, tried in order:

let Some(fall) = insn.fall_through else { return true; };                 // terminal
if !listing.is_instruction_start(fall) { return true; }                   // arm 1
if listing.is_data(fall) { return true; }                                 // arm 2
if fall != callee && listing.function_at(fall).is_some() { return true; } // arm 3

Arm 1 does not mean what its name says, and the issue understates it. listing/walk.rs
pushes every call's fall-through onto the per-function instruction worklist
unconditionally (walk.rs:167-170), and that worklist drains before the function is left,
so a call's successor is always attempted. It fails to become an instruction start in
exactly three ways: decode_one returned Err (walk.rs:129-132, the error dropped on
the floor), the decode was zero-length, or the address is outside every executable range.
The Listing keeps no decode-outcome record — CodeUnit is only
Instruction/Data/Undefined, and code_unit_at derives Undefined from "in an exec
range and not covered" — so a failed decode and an unvisited byte are indistinguishable.

Arm 1 is therefore precisely and only a decode-failure detector: a fact about kuna's
SLEIGH coverage, feeding a rule that removes code. And since is_data(fall) implies
!is_instruction_start(fall), arm 2 has been unreachable since the pass shipped.

I verified both claims in code and by running: instrumenting the pass to compute the two
tallies side by side over 975 real binaries shows arm 1 casting one vote in all of
them (see below), and the new fixture shows it casting exactly 3 and forging a verdict.

The bug, minimal

retseven is mov $7,%eax ; ret. Three callers follow their call retseven with the
single byte 0x06 (push %es, invalid in 64-bit mode). Three decode failures = three
votes = the threshold:

$ kuna decompile-all noreturn_discstrict_x86_64 --option noreturn_discstrict off
unsigned long retseven(void) { return 7; }
...
void usesret(void)            <-- live code deleted
{
  retseven(); // no-return
}
void _start(void)             <-- and the forged fact propagates through rule 2
{
  gap1(); // no-return
}

$ kuna decompile-all noreturn_discstrict_x86_64          # default, this PR
int usesret(void)
{
  return retseven() + 3;
}
unsigned long _start(void) { gap1(); gap2(); gap3(); usesret(); syscall(); return 0x3c; }

The change

New option noreturn_discstrict (on|off, default ON, tier transform, DIV-90),
gating the narrowed predicate in
kuna-analysis/src/analyzers/noreturn_disc/kuna_discstrict.rs. It keeps the terminal arm
(a property of the call instruction: a tail jump lowered to a call) and the two
positive arms — the successor is data (outside every executable range, so the compiler
emitted nothing to fall into), or the successor is another function's entry (the compiler
left the caller no tail) — and drops arm 1. off restores the legacy three-arm order
verbatim. Dropping arm 1 is also what makes arm 2 reachable for the first time.

strict ⟹ legacy at every call site, so the change can only ever remove a no-return
conclusion, never add one.

No decode-outcome record was added to the Listing, deliberately. Recording why an
address has no instruction would make arm 1 honest, but it would remain a statement about
the decoder: a SLEIGH gap on Thumb/MIPS16/PPC VLE would still vote to delete a caller's
code. noreturn_propagate (no threshold, seeded from the Known list) already covers the
padding-tail wrapper shape the tally was reaching for.

It ships as an option rather than a bare bug fix because it narrows a default-ON,
code-removing analyzer — AGENTS.md's "when in doubt, gate it".

Measurement — this is what decided the default

Instrumented A/B inside one process (both tallies computed over the same Listing, the
fact sets diffed by address), --mode aggressive so the Listing is on for every surface.

corpus Listing-on binaries legacy concluded strict concluded lost gained arm-1 votes cast most arm-1-only votes at one callee
decbench x86-64 stripped, --mode aggressive 693 766 766 0 0 0 0
decbench x86-64 stripped, shipped auto 660 581 581 0 0 — —
decbench non-x86-64 stripped (98 ARM32 + 12 i386 PE) 110 0 0 0 0 1 1 (threshold is 3)
/usr/bin ELF binaries 168 — — 0 0 0 0
clang/LLVM-14 built (FileCheck-14, clang-14, llvm-nm, llvm-strings) 4 0 0 0 0 0 0

975 real binaries, one arm-1 vote in all of them, zero conclusions changed.

  1. How many callees depend on the weak arm alone → 0 of 766. Not "0 net": arm 1 cast
    zero votes at any call site on the entire x86-64 corpus and on every system binary. The
    single vote in the whole non-x86-64 corpus is on O2-noinline/u-boot, at a callee that
    needs three.

  2. The non-x86-64 slice is the risk the scout named, and it is inverted. kuna's decoder
    gaps are widest on ARM/Thumb/MIPS/PPC — but on fixed-width RISC ISAs almost every bit
    pattern decodes as something, so decode_one rarely errors and arm 1 rarely fires.
    noreturn_disc concludes nothing at all on all 110 of those binaries under either
    tally, so there is no genuine conclusion there to lose. No mitigation was needed.
    (Instrument validated in both directions on the two fixtures: the forge shows
    NRDS-WEAK ... weak_only=3, the genuine-die() fixture shows sites=0 and identical
    conclusions.)

  3. Emitted-C collateral — decompile-all --json | jq -r '.functions[].code', off vs on,
    18 binaries, 0 changed lines out of 382,515, // no-return count identical in every
    pane:

tests/bug-repro/grep                    lines 17526   changed=0   no-return on=83  off=83
tests/bug-repro/sort                    lines 11202   changed=0   no-return on=56  off=56
tests/bug-repro/faillog                 lines 1048    changed=0   no-return on=14  off=14
tests/bug-repro/libselinux.so.1         lines 16522   changed=0   no-return on=12  off=12
tests/bug-repro/betaflight_STM32F405.elf lines 127077 changed=0   no-return on=0   off=0
/usr/bin/FileCheck-14                   lines 64308   changed=0   no-return on=102 off=102
decbench O0/dpkg/dpkg                   lines 20259   changed=0   no-return on=516 off=516
decbench O0/dpkg/dpkg-divert            lines 11037   changed=0   no-return on=285 off=285
decbench O0/bzip2/bzip2                 lines 6791    changed=0   no-return on=67  off=67
decbench O0/coreutils/sort              lines 9154    changed=0   no-return on=108 off=108
decbench O0/findutils/find              lines 19400   changed=0   no-return on=180 off=180
decbench O0/gzip/gzip                   lines 6422    changed=0   no-return on=60  off=60
decbench O0/openssh-portable/scp        lines 15006   changed=0   no-return on=246 off=246
decbench O0/diffutils/diff              lines 12265   changed=0   no-return on=104 off=104
decbench O0/grep/grep                   lines 13959   changed=0   no-return on=71  off=71
decbench O0/coreutils/csplit            lines 3715    changed=0   no-return on=45  off=45
decbench O0/gnutls/certtool             lines 20329   changed=0   no-return on=451 off=451
decbench O0/iproute2/rtmon              lines 6495    changed=0   no-return on=38  off=38

The 12 decbench targets are the highest-conclusion-count binaries in the corpus, so this
is the sample most likely to move, not a random one. The only hunk anywhere is the new
fixture's, shown above.

  1. /usr/bin/FileCheck-14 (the [AUTOMATED] std::__throw_* family missing from the ELF no-return list: dead code after libstdc++ throw helpers #273 clang binary from the issue's provenance story):
    102 // no-return annotations in both panes, 64,308 lines byte-identical, 0 arm-1 votes.
    The std::__throw_* family it turns on is already covered by name post-DIV-78.

  2. Speed — interleaved min-of-8 with the arm order alternated per rep, on a box at
    load 10–18 shared with several other agents:

functions --mode aggressive dpkg : min-of-8  on=0.862s  off=0.995s  -13.30%
decompile-all grep               : min-of-8  on=8.329s  off=8.658s   -3.80%
decompile-all grep (same-order)  : min-of-6  on=9.031s  off=8.803s   +2.58%   <- ordering artifact

The sign flips with arm ordering, so the number is noise-dominated and I claim none of
them. What is structural: the strict path performs strictly fewer Listing lookups per
call site, and on every binary measured the emitted C is byte-identical, so the decompile
work is unchanged. Well inside the 5% budget in the only direction that matters.

Tests

  • kuna-console/tests/verify_noreturn_discstrict.rs — 4 cross-crate tests over the new
    checked-in fixture noreturn_discstrict_x86_64, built reproducibly from checked-in
    assembly by the one-line gcc command in its header (nothing byte-patched):
    default keeps return retseven() + 3 and marks nothing no-return; off restores the
    forged // no-return form and the truncated _start; retseven is return 7 under
    both; and — the no-regression half — the pre-existing noreturn_disc_x86_64 fixture's
    genuine die() wrapper is still concluded no-return under the default with
    noreturn_propagate forced off, because all four of its call sites take their evidence
    from the surviving arm 3.
  • tests/stages/kuna-noreturn-discstrict.xml — wiring only, and that is a tier limit,
    not an omission: the Listing is built solely on the real-object bootstrap path, so an
    off=bug/on=fix datatest is not constructible on the XML <binaryimage> path. Same split
    ghangr-noreturn-error.xml + verify_noreturn_error.rs already use. Corpus 215 → 216
    files, docs/baseline-stages.json re-recorded (539 keys, one newly passing).

Gates

########## GATE 1: make test ##########
datatests: 675/675 assertions passed
exit: 0

=== baseline parity ===
PARITY OK

########## GATE 2: make test-stages ##########
datatests: 539/539 assertions passed
exit: 0

=== baseline parity ===
PARITY OK

########## GATE 3: make rust-test ##########
324 suites: 4838 passed, 0 failed, 38 ignored, 0 failure blocks, 0 `error` lines

########## GATE 4: make check-spec ##########
check-spec OK (lenient mode)
check-spec OK (strict mode)

########## kuna catalog --check ##########
catalog OK: documents exactly the registered kuna options

Both parity gates are vacuous here and are stated as such in the DIV row: every fixture
in tests/datatests/ and tests/stages/ is a symbol-less <bytechunk> and the Listing is
real-object-only, so "675/675 unchanged" is true and proves nothing about this change. The
evidence is the 975-binary A/B above plus the new fixture.

Counts bumped

where old → new
kuna_phases/tests.rs kuna_num_settables() / SETTABLE_TABLE.len() 119 → 120
kuna_phases/tests.rs tier counts (core, transform, analysis) (26, 50, 43) → (26, 51, 43)
kuna_phases/tests.rs catalog JSON row-comma count 118 → 119
catalog_bytecompat.rs "option":/"tier":/"symptoms": 119 → 120
kuna-base/src/xml.rs corpus file count 215 → 216
tests/fixtures/phase_catalog.json regenerated
docs/options.md regenerated

tests/stages/kuna-catalog.xml needed no change: its min/max assertions are on
source_decompiler: "angr" (32), change_kind: "structure-recovery" (26) and
change_kind: "opt-in-tool" (15); this row is kuna / correctness-fix, and the two
use_when/change_kind presence assertions have max=160.

DIV number: claimed DIV-90 (highest on main is DIV-89). Siblings may claim 90..93 —
if one merges first, renumber the row in docs/history.md and its references in
architecture.rs, options.rs, phases.toml, docs/options.md (regenerate),
docs/spec/01-program-prep.md and kuna_phases/tests.rs.

🤖 Generated with Claude Code

https://claude.ai/code/session_011KpG7qK6BDFZyPnyo4r1c1

…a callee never returns (DIV-92)

[AUTOMATED]

`noreturn_disc` concludes a callee no-return once >=3 of its call sites "show no
valid fall-through", and one of the three arms implementing that test is
`!listing.is_instruction_start(fall)`. That arm does not mean what its name says.
`listing/walk.rs` pushes EVERY call's fall-through onto the per-function
instruction worklist unconditionally, and that worklist drains before the
function is left, so a call's successor is always ATTEMPTED; it fails to become
an instruction start in exactly three ways -- `decode_one` returned `Err`, the
decode was zero-length, or the address is outside every executable range. The
Listing records no decode outcome (a failed decode and an unvisited byte are the
same `Undefined` code unit), so the arm is precisely and only a DECODE-FAILURE
DETECTOR: a fact about kuna's SLEIGH coverage, feeding a rule that removes code.
Three undecodable bytes are enough to conclude that `mov $7,%eax ; ret` never
returns, after which the flow layer deletes the live tail of every caller.

`noreturn_discstrict` (on|off, default ON) keeps the terminal arm (a call with no
fall-through VMA at all -- a tail jump lowered to a call, a property of the call
instruction) and the two POSITIVE arms (the successor is data, so it is outside
every executable range; the successor is another function's entry) and drops the
bare one. `off` restores the legacy three-arm order verbatim. Dropping it also
makes the data arm reachable for the first time -- `is_data` implies
`!is_instruction_start`, so the legacy order consumed every site it would have
caught. `strict` evidence is a subset of `legacy` evidence at every call site, so
the change can only remove a no-return conclusion, never add one.

No decode-outcome record was added to the Listing, deliberately: recording WHY an
address has no instruction would make the arm honest but leave it a statement
about the decoder, so a spec gap on Thumb/MIPS16/PPC VLE would still vote to
delete a caller's code.

Measured, instrumented A/B inside one process over 975 real binaries: 693
stripped x86-64 decbench binaries (aggressive) legacy 766 conclusions vs strict
766, 0 lost, and the dropped arm cast 0 votes at any call site; 110 stripped
non-x86-64 (98 ARM32 + 12 i386 PE) legacy 0 vs strict 0 with 1 arm vote in the
whole corpus; 168 /usr/bin ELF binaries 0 arm votes; 4 clang/LLVM-14 binaries 0.
Emitted C off vs on is byte-identical over 18 binaries / 382,515 lines.

Closes #312.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_011KpG7qK6BDFZyPnyo4r1c1
@mahaloz
mahaloz force-pushed the feat/noreturn-discstrict branch from 93b0f39 to 96c2d03 Compare August 27, 2026 19:43
@mahaloz mahaloz changed the title [AUTOMATED] fix(p1): noreturn_discstrict — a decode failure is not evidence that a callee never returns (DIV-90) [AUTOMATED] fix(p1): noreturn_discstrict — a decode failure is not evidence that a callee never returns (DIV-92) Aug 27, 2026
@mahaloz
mahaloz merged commit a1683bb into main Aug 27, 2026
9 checks passed
@mahaloz
mahaloz deleted the feat/noreturn-discstrict branch August 27, 2026 19:57
mahaloz added a commit that referenced this pull request Aug 27, 2026
[AUTOMATED] DIV-90/91/92 were claimed by #341/#342/#344 while this branch was
in flight; the row and every reference move to DIV-93.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_011KpG7qK6BDFZyPnyo4r1c1
mahaloz added a commit that referenced this pull request Aug 27, 2026
…e aggressive preset (DIV-93) (#345)

* feat(modes): the four ARM entry-discovery options join the aggressive preset (DIV-90)

cortexmvectors (#248), ptrentry (#255), tailcallentry (#259) and poolentry (#278)
all shipped default-OFF and sat on the UNEVALUATED list in modes.rs, so they were
absent from AGGRESSIVE_OVERRIDES. `auto` resolves to `aggressive` under 500 KiB,
and the preset is what the whole-binary surfaces actually run, so all four were
INERT on every default path -- the DIV-64 itaniumrtti trap, four times over. The
default path's stripped-ARM entry recall had not moved since they merged.

They are flipped jointly because they compose, which is exactly what the
UNEVALUATED comment demanded before any flip.

Measured over the 110 stripped non-x86-64 decbench twins against their unstripped
twins' symbol tables (50,724 ground-truth function starts), --mode aggressive:

  arm       entries   exact   midbody   recall     added  added_exact  lost_exact
  base        55006   44957      8333   88.63%         -            -           -
  cortexm     55142   45093      8333   88.90%       136          136           0
  ptr         56594   46522      8333   91.72%      1588         1565           0
  tail        55655   45602      8337   89.90%       649          645           0
  pool        53956   45122      7116   88.96%       167          165           0
  all4        56188   47330      7117   93.31%      2402         2373           0

Recall and precision improve together: +2,373 real entries (98.8% of everything
added is a real function start) while mid-body false entries FALL 8,333 -> 7,117.
No ground-truth entry is lost by any arm -- poolentry's 1,217 removals contain
zero ground-truth addresses. 0 of 110 binaries lose recall.

Restricted to the 105 binaries `auto` actually sends to `aggressive` (< 500 KiB),
the default-path number is 90.92% -> 96.06%. The 5 images at/over the threshold
resolve to `reliable` and are disclosed in the DIV row rather than papered over.

Non-ARM inertness is measured: identical entry sets over 90 x86-64 twins and the
12 i386 PE images in the ARM corpus, byte-identical emitted C over 8 x86-64
binaries. Speed, interleaved min-of-4: decompile-all cf2.elf -5.8% (a speedup),
nuttx +3.5%, x86-64 controls at noise; discovery-only `kuna functions` +6.2%,
which is more work for more output on the one surface that only does discovery.

The 0/675 ablation is proven, not asserted: a throwaway build with all four forced
ON as engine defaults -- strictly stronger than preset membership, which the XML
harness never applies -- still reports 675/675 and 538/538 PARITY OK.

Also lands PR #239's two doc corrections, repointed at the shipped feature docs
rather than at its unshipped-proposal directory: the recall-measurement.md
mechanism/noise correction and the missing-ghidra-analyses.md
OperandReferenceAnalyzer row (its "function creation is subsumed by entry-disc"
claim is what ptrentry disproved).

[AUTOMATED] Generated by Claude Code.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_011KpG7qK6BDFZyPnyo4r1c1

* docs(decbench): retire the two round-ledger claims DIV-90 falsifies

features-round4.md Rank 6 was a filed, still-open recommendation to flip
`tailcallentry` into the preset ("aggressive does not carry it"); DIV-90 does
exactly that, so it is marked SHIPPED with the sweep it asked for. features.md
still called step 3 "in flight" and did not know about step 5 (`poolentry`, #278).

[AUTOMATED] Generated by Claude Code.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_011KpG7qK6BDFZyPnyo4r1c1

* docs: state the ARM restriction precisely -- poolentry has no arch gate

cortexmvectors/ptrentry/tailcallentry each early-return on
`object::Architecture::Arm`; poolentry does not, and is ARM-only in EFFECT
because it keys on PC-relative literal pools. The measured inertness is the same
either way (identical entry sets on 90 x86-64 twins and 12 i386 PE images), but
"all four are ARM-gated" overstated the mechanism for one of them.

[AUTOMATED] Generated by Claude Code.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_011KpG7qK6BDFZyPnyo4r1c1

* docs(history): add the leave-one-out direction to the DIV-90 evidence

Dropping each option from the combination loses 27 / 1427 / 645 / 136 ground-truth
entries respectively, and dropping poolentry is the only one that also raises
mid-body false entries (7117 -> 8337). No option is redundant given the others.

[AUTOMATED] Generated by Claude Code.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_011KpG7qK6BDFZyPnyo4r1c1

* docs: renumber the ARM-preset divergence to DIV-93

[AUTOMATED] DIV-90/91/92 were claimed by #341/#342/#344 while this branch was
in flight; the row and every reference move to DIV-93.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_011KpG7qK6BDFZyPnyo4r1c1

---------

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.

[AUTOMATED] noreturn_disc: an undecodable fall-through must not count as no-return evidence

1 participant