Skip to content

Listing/xref tier PR6: discovered-no-return consumer (the payoff) - #29

Merged
mahaloz merged 2 commits into
mainfrom
listing-tier-noreturn-disc
Jun 24, 2026
Merged

mahaloz merged 2 commits into
mainfrom
listing-tier-noreturn-disc

Conversation

@mahaloz

@mahaloz mahaloz commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

The first analyzer built on the Listing/xref model — the kuna analog of Ghidra's FindNoReturnFunctionsAnalyzer ("Non-Returning Functions — Discovered"). It finds custom no-return wrappers the static name-lists cannot catch (a local die() that tail-calls exit) by flow evidence over the program-wide Listing, and marks them no-return through the existing NoReturnFact commit seam. Default-OFF.

PART A — the build-timing fix (the mechanism)

PR2 flagged it: the live CLI emits option listing on after load file, but the analysis driver (run_default_analyses_per_pass) runs at load, so a Listing gated on arch.analysis_listing never builds through the CLI (the flag is still default-off at load).

The fix mirrors the Increment 13 deferred-commit precedent. At load, bootstrap_from_elf now stashes the image bytes + path on ConsoleProgram (analysis_image); the build of the Listing — and the run of any Listing-consumer pass — is deferred to commit_pending_analysis (reached at read symbols, AFTER the CLI's option lines). There, gated on arch.analysis_listing (now in effect), the stashed bytes are re-parsed, the Listing is built (funcsym names + Known-no-return seed metadata via Listing::with_noreturn_seeds), the new passes::run_listing_consumers runs the consumer over it, and its (per-pass gated) facts merge into the same AnalysisOutput the deferred commit already commits — through the unchanged commit_analysis_output no-return arm (find_function_across_scopes/query_global_function → set_function_no_return). Flow-repair / dead-code elimination is inherited from the engine. Default (listing off) ⇒ the whole deferred block is skipped ⇒ byte-identical to today; the XML path stashes no image ⇒ structural no-op.

PART B — the consumer (s1_noreturn_disc, id noreturn_disc, default-OFF)

A new gated AnalysisPass whose run short-circuits to empty when ctx.listing.is_none(). The evidence-tally fixpoint over the Listing:

  • Rule 1 (call-site evidence): a callee is no-return when ≥3 of its call sites (refs_to(callee) Call edges) show no valid fall-through — the byte after call is not a decoded instruction start (!is_instruction_start), or is data (is_data), or is another function's entry (function_at(fall)), or the call has no fall-through at all. (Ghidra's evidence threshold = 3.)
  • Rule 2 (fixpoint promotion): a function whose every terminal path is a call to an already-discovered-no-return function, with no returning path, is itself no-return (wrapper-of-a-wrapper convergence).
  • Skips callees already modeled no-return (function_at(t).has_no_return, seeded from the Known pass) or call-fixup'd. Emits NoReturnFact { addr, name } — no new commit arm.

The END-TO-END before/after (real, not faked)

Fixture noreturn_disc_x86_64 (+.c), gcc -O1 -no-pie -fno-pic: a static void die(const char*) that fprintfs then exit(1), not __attribute__((noreturn)), called from four functions (compute_a/b/c/d). At -O1 gcc emits nothing after each call die — the byte after the call is the next function's entry — so all four call sites show no-valid-fall-through (≥3).

compute_a, BEFORE (default, flags off) — die is treated as returning, so the decompiler follows the fall-through past call die through compute_b/compute_c/compute_d into main (massive merged dead code):

undefined16 compute_a(int4 a0,void *a1,unsigned long a2)
{ ...
  if (0 <= a0) { ...; return v3; }
  v13 = 0x40200f;
  die();                       /* treated as returning */
  if (v13 != 0) { ... return v9; }
  v14 = "b: zero"; die("b: zero");
  ...                          /* compute_c / compute_d / main bodies inlined */
  v5 = compute_a(); ... __printf_chk(1,"%d %d %d %d\n",...); return v2 << 0x40; }

compute_a, AFTER (--option listing on --option noreturn_disc on) — die is concluded no-return; the engine's inherited repair eliminates the dead code:

int4 compute_a(int4 a0)
{
  if (0 <= a0) {
    return a0 * 2;
  }
                    /* WARNING: Subroutine does not return */
  die("a: negative");
}

Gating invariants (the parity proof). Verified directly: noreturn_disc on + listing off ⇒ identical to default (no Listing to read); listing on + noreturn_disc off ⇒ identical to default (Listing built, consumer gated off). Only both flags on changes output ⇒ the default path is byte-identical to today.

Wiring

settable_count 35 → 36 (the noreturn_disc gate): stages.toml row + header count, KUNA_OPTION_NAMES, architecture.rs field/default/reset/set_kuna_option, engine.rs analysis_pass_enabled arm, the count-fixture ripple (kuna_stages settable_count_is_36 / …suppressed_for_14 / …brackets_and_commas / catalog_bytecompat / stage_catalog.json), docs/assertions.md regenerated.

Gates

  • make test — 675/675 PARITY OK
  • make test-stages — 159/159 PARITY OK
  • make rust-test — green
  • kuna catalog --check — catalog OK
  • new e2e verify_noreturn_disc.rs — 3/3, ran (not skipped)

Do not merge.

🤖 Generated with Claude Code

https://claude.ai/code/session_01FvRnfTgYKoZvS2TEvdYpWb

mahaloz and others added 2 commits June 24, 2026 21:52
The first analyzer built on the Listing/xref model — the kuna analog of Ghidra's
FindNoReturnFunctionsAnalyzer ("Non-Returning Functions — Discovered"). It finds
CUSTOM no-return wrappers the static name-lists cannot catch (a local die() that
tail-calls exit) by flow evidence over the program-wide Listing, and marks them
no-return through the EXISTING NoReturnFact commit seam. Two parts:

PART A — the build-timing fix. PR2 flagged it: the live CLI emits `option listing
on` AFTER `load file`, but the analysis driver runs at load, so a Listing gated on
arch.analysis_listing never builds through the CLI. Following the Increment-13
deferred-commit precedent, bootstrap_from_elf now stashes the image bytes+path on
ConsoleProgram (analysis_image), and the Listing build + Listing-consumer run is
DEFERRED into commit_pending_analysis (reached at `read symbols`, after the option
lines). Gated on arch.analysis_listing (now in effect), the stashed bytes are
re-parsed, the Listing built (funcsym names + Known-no-return seed metadata via
Listing::with_noreturn_seeds), passes::run_listing_consumers runs the consumer,
and its per-pass-gated facts merge into the same AnalysisOutput the deferred commit
already commits — through the UNCHANGED no-return commit arm. Default (listing off)
⇒ the whole block is skipped ⇒ byte-identical to today; XML path stashes no image
⇒ structural no-op.

PART B — the consumer (s1_noreturn_disc, id noreturn_disc, default-OFF, its own
flag + full wiring). run short-circuits to empty when ctx.listing is None. The
evidence-tally fixpoint over the Listing: (1) a callee is no-return when ≥3 of its
call sites show no valid fall-through (byte after `call` is not an instruction
start / is data / is another function's entry); (2) fixpoint promotion — a function
whose every terminal path is a call to an already-discovered-no-return function,
with no returning path, is itself no-return. Skips callees already modeled
no-return / call-fixup'd. Emits NoReturnFact (no new commit arm); flow-repair is
inherited from the engine.

END-TO-END (real, not faked). Fixture noreturn_disc_x86_64 (+.c), gcc -O1 -no-pie:
a static die() that fprintf+exit(1), NOT noreturn-marked, called from 4 functions;
at -O1 gcc emits nothing after each `call die` (the next byte is the next
function's entry). compute_a:
  BEFORE (default): die treated as returning ⇒ the decompiler falls through past
  `call die` through compute_b/c/d into main (massive merged dead code).
  AFTER (--option listing on --option noreturn_disc on): die concluded no-return ⇒
  `int4 compute_a(int4 a0) { if (0 <= a0) return a0 * 2;
   /* WARNING: Subroutine does not return */ die("a: negative"); }`
Gating invariants verified: noreturn_disc-on+listing-off and listing-on+
noreturn_disc-off both equal the default; only BOTH flags change output.

settable_count 35 → 36 (the noreturn_disc gate); stages.toml row + header,
KUNA_OPTION_NAMES, architecture.rs field/default/reset/set_kuna_option,
engine.rs analysis_pass_enabled arm, the count-fixture ripple (kuna_stages tests,
catalog_bytecompat, stage_catalog.json), docs/assertions.md regenerated.

Gates: make test 675/675 PARITY OK; make test-stages 159/159 PARITY OK;
make rust-test green; kuna catalog --check OK. New e2e verify_noreturn_disc.rs
(3/3, ran not skipped).

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

# Conflicts:
#	docs/analysis-port-log.md
@mahaloz
mahaloz merged commit 399a286 into main Jun 24, 2026
@mahaloz
mahaloz deleted the listing-tier-noreturn-disc branch July 29, 2026 08:01
mahaloz added a commit to borancar/kuna that referenced this pull request Nov 14, 2026
…t, a wide reload or ECX, and from reusing walks across the option

Three lost-read shapes the stack-address tracking still missed each dropped a
real argument: a local's address stored over the callee's own argument slot
and loaded back, a slot holding one copied by an 8-byte move, and a stack
address a nested call leaves in ECX. A store of a stack address to a stack
location whose slot is not followed now leaves the extent unstated, a load is
lost when it overlaps any followed slot, and every caller-saved register a
returning callee leaves a stack address in is lost.

The walk summaries are cached on the architecture, and the tracking only runs
with calleeargs on, so turning the option on in a session that had walked a
callee with it off reused the untracked walk and dropped the arguments again.
The cache now drops its walks when the option changes.

Stage cases CALLEEARGS Noelo-Lab#26-Noelo-Lab#29 (calleelost_pe_i386 extended, recipe in its
header) fail on the previous head and pass now; the 62-binary i386 corpus is
byte-identical to the previous head.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
mahaloz added a commit to borancar/kuna that referenced this pull request Nov 14, 2026
…load

Comparing values lets `mov ecx,esi; mov eax,[esi]; call [eax+k]` pass the
object in ECX, since ECX holds it at the call; the vcall fixture gains
ecxcopy for it (stage Noelo-Lab#28, Noelo-Lab#29, the custom test) and spec 04 says so.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0179iMKQeLQDThvbHGNoGw8h
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