Skip to content

[AUTOMATED] Read catalog in-process by default - #1065

Merged
mahaloz merged 11 commits into
Noelo-Lab:mainfrom
TsingShui:fix/catalog-in-process-default
Oct 15, 2026
Merged

mahaloz merged 11 commits into
Noelo-Lab:mainfrom
TsingShui:fix/catalog-in-process-default

Conversation

@TsingShui

Copy link
Copy Markdown
Contributor

[AUTOMATED]

Problem

A standalone kuna cannot discover its own options without a sibling decomp_dbg:

mkdir -p /tmp/kuna-catalog-only
cp decompiler/target/release/kuna /tmp/kuna-catalog-only/
(cd /tmp/kuna-catalog-only && env -u KUNA_DECOMP_DBG KUNA_ROOT=/tmp/kuna-catalog-only ./kuna catalog --check)

Before: error: decomp_dbg not found in /tmp/kuna-catalog-only, /tmp/kuna-catalog-only/decompiler/target/release …
After: catalog OK: documents exactly the registered kuna options

Fix

  • Read the linked engine's static catalog by default; no console or specs needed.
  • Preserve external queries selected by --decomp-dbg or non-empty KUNA_DECOMP_DBG, including precedence, diagnostics and legacy flags.
  • Keep text/JSON rendering, tier filters and Markdown behavior unchanged. Check the selected catalog against this CLI build's registrations.

Tests

Cover standalone installs, an unselected sibling that must not run, byte-identical local/external output, missing overrides, flag precedence and external catalog drift.

The full workspace suite is not green on macOS: mmap/RSS/ELF execution/linking cases, native C round-trips and a missing UPX fixture fail. Linux verification is left to CI.

TsingShui and others added 5 commits October 13, 2026 16:50
Retain external console queries selected by --decomp-dbg or KUNA_DECOMP_DBG, with existing rendering, diagnostics and compatibility flags. Cover standalone discovery, byte compatibility, override precedence and external drift; document the two routes.
[AUTOMATED] Resolve conflicts with the single-binary console (Noelo-Lab#1067): the
explicit external route now runs the resolved decomp_dbg Program, and the
docs describe the in-process catalog beside the built-in console.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01RVkhSR3PZKoRmKDbGHjfqH
The tests copy kuna and write a fake console, then execute them. Inside
the shared integration binary another test's fork could inherit the
writable descriptor until exec, failing the run with ETXTBSY (seen in CI).
Give them their own [[test]] and serialize writes and spawns, as
docs_cli and single_binary_cli do.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01RVkhSR3PZKoRmKDbGHjfqH
…oelo-Lab#1022)

The alias-only analysis emits the caller's saved XMM lanes as live stack locals even though the helper updates a separate caller-owned rectangle. The same Clang `-O0` input produces:

```c
/* before */
unsigned int v18; // stack - 0x48 | xmm6_da
/* ... */
unsigned int v33; // stack - 0xc | xmm9_dd
/* after */
Rect v1 [2]; // stack - 0x68 | xmm0_da
fixture_copy_rect(v1,&rect_source);
return v1[0].x + v1[0].y;
```

The [neutral fixture, build command, and decompile assertions](https://github.com/mgostIH/kuna/blob/fix/lifetime-private-spills/docs/features/lifetimes/README.md#reproducing-disjoint-private-spills) reproduce this output.

- Retain exact pointer-width private spills only when every summarized write is disjoint from every retained cell at the call site.
- Protect frame-derived return-target reads from stores overlapping the ABI return slot, and preserve frame provenance through flag-only scratch.
- The saved-XMM regression checks the native result and all sixteen lanes, observer controls, and generated-C round trips; focused callee tests cover unknown and partial aliases, flag publication, and return-slot cases.

Validation: `cargo test --manifest-path decompiler/Cargo.toml -p kuna-cli --test integration saved_xmm_msabi::` and `cargo test --manifest-path decompiler/Cargo.toml -p kuna-decomp --lib kuna_callee`.

Both focused checks pass (183 selected unit tests and the native/generated-C regression).
…elo-Lab#1023)

With stack views enabled, a detached frame value can keep an integer declaration while a later member operation uses it as a node pointer. The unpatched output fails C compilation:

```text
v1 = v3->sentinel;
error: invalid type argument of ‘->’ (have ‘uint8’ {aka ‘unsigned long’})
```

The patched expression is `v1 = ((Node *)v3)->sentinel;`. For a pointer-slot access it similarly changes `&v5->left` to `&((Node *)v5)->left`, casting only the member base.

The standalone repro is in `docs/features/lifetimes/README.md` (Reproducing detached member emission). The [CLI regression](https://github.com/Noelo-Lab/kuna/blob/main/decompiler/crates/kuna-cli/tests/stack_object_lifetimes.rs) validates the fix; run it with:

```sh
cargo test --manifest-path decompiler/Cargo.toml -p kuna-cli --test integration stack_object_lifetimes::tree_range_members_use_the_pointer_type_of_each_native_access
```

- The member base is cast only when its same-width declaration disagrees with the operation’s pointer type; stored snapshots and byte arithmetic keep their existing representations.
- The focused test passes 1/1. Its native and emitted-C checks cover GCC and Clang at `-O0`/`-O2`, with stack views enabled and disabled. In the same-fixture A/B probe with stack views enabled, GCC and Clang reject the refreshed baseline at both optimization levels; the candidate compiles and runs all four combinations.
@mahaloz

mahaloz commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

[AUTOMATED] Pushed two commits to bring this up to date:

  • e768851 merges main. Since [AUTOMATED] Ship kuna as one self-contained binary #1067, a lone kuna runs itself as the console, so the "Before" error in the description no longer reproduces on main. What this PR still changes is that catalog no longer starts a subprocess: strace -f -e trace=execve kuna catalog --check shows 2 execs on main and 1 here, and catalog --json takes about 23 ms instead of 33 ms. The explicit route now runs main's resolved console. docs/cli.md is reconciled with the built-in-console text.
  • e80c547 fixes the red workspace suite: catalog_cli failed with Text file busy. It copies kuna and writes a fake console, then executes them. In the shared integration binary, another test's fork could still hold the file open for writing. It now has its own [[test]], with writes and spawns serialized as in docs_cli/single_binary_cli.

Output of catalog (table, --json, --markdown, --check, --option, --tier, unknown option) is byte-identical across main, this branch, and this branch with KUNA_DECOMP_DBG/--decomp-dbg set.

mgostIH and others added 6 commits October 15, 2026 02:43
…Lab#1047)

Building a Listing currently parses each instruction again to capture its assembly. Using the existing combined translator API preserves the text and p-code while reducing decoder work.

```sh
python3 decompiler/crates/kuna-analysis/tests/fixtures/listing_fallthrough.py aarch64 200000 /tmp/listing.elf
kuna decompile-all /tmp/listing.elf --mode reliable --functions _start --jobs 1 --json
```

Three fresh-process pairs against main `ccdf0844` measured median CPU reductions of 25.5% on a varied ARM64 fixture and 27.7% on repeated x86. These are decoder-heavy controls, not estimates for overall decompilation speed; complete JSON matched.

- Capture Listing assembly through the combined API added in Noelo-Lab#924.
- Preserve generic translator fallback, context/delay handling and public String/Vec fields.
- Do not render assembly after a failed lift.

On current main `939ab703`, 110 Listing tests and five serial/parallel decode checks pass, including image-read and failure regressions. Spec/layout checks and the release build pass. The full workspace and stage suites also pass in fork PR CI.
…oelo-Lab#1048)

Large Listings retain less address-index memory while keeping exact, ordered and range queries unchanged. Three fresh-process pairs against main `ccdf0844` reduced median peak RSS from 337.39 to 316.96 MiB on a generated million-row x86 control; complete JSON matched.

```sh
python3 decompiler/crates/kuna-analysis/tests/fixtures/listing_fallthrough.py x86_64 1000000 /tmp/listing.elf
/usr/bin/time -f '%U user %S system %M KiB peak' kuna decompile-all /tmp/listing.elf --mode reliable --functions _start --jobs 1 --json > /tmp/listing.json
```

- Group sorted address/row pairs into private 4 KiB address buckets.
- Restrict range iteration to relevant buckets and boundary rows.
- Preserve indexed keys when a record's address field is mutated, replacement behavior, reverse iteration and public field types.

On current main `939ab703`, all 112 Listing tests pass, including a BTreeMap range oracle and extreme/sparse bounds. Spec/layout checks and the release build pass. The full workspace and stage suites also pass in fork PR CI.
…oelo-Lab#1049)

ARM frame recovery can retain duplicate instruction payloads while rebuilding a Listing. Three fresh-process pairs against main `ccdf0844` reduced median peak RSS from 151.67 to 113.80 MiB on a scaled A32 inventory, and from 174.94 to 161.29 MiB on a firmware inventory. Complete inventory JSON matched; U-Boot's process peak stayed flat.

This existing fixture exercises the rebuild:

```sh
python3 decompiler/crates/kuna-analysis/tests/fixtures/arm_frame_retain.py /tmp/frame.elf
kuna functions /tmp/frame.elf --json --jobs 1 --mode reliable --option armframes on
```

- Share immutable 1,024-row chunks between store snapshots.
- Copy only a touched chunk before mutation, replacement or partial-tail append.
- Preserve snapshot independence and bounded capacity; the address index is still copied, and public field types stay unchanged.

On current main `939ab703`, 109 Listing tests pass, including nested clones and payload isolation. Spec/layout checks and the release build pass. ARM frame recovery remains default-off. The full workspace and stage suites also pass in fork PR CI.
…oelo-Lab#1052)

No-return analysis avoids temporary per-function instruction-reference lists and address indexes. Three fresh-process pairs against main `939ab703` reduced median peak RSS from 337.81 to 319.03 MiB on a generated million-row x86 control; complete JSON matched.

```sh
python3 decompiler/crates/kuna-analysis/tests/fixtures/listing_fallthrough.py x86_64 1000000 /tmp/listing.elf
/usr/bin/time -f '%U user %S system %M KiB peak' kuna decompile-all /tmp/listing.elf --mode reliable --functions _start --jobs 1 --json > /tmp/listing.json
```

- Borrow bounded instruction ranges for argument and reachability scans.
- Preserve conservative clobber handling, function boundaries and contiguous fall-through requirements; argument scans retain their existing handling of address gaps.
- Leave public field types unchanged.

On current main `939ab703`, 17 analyzer regressions and three console checks pass, including gaps, boundary isolation and argument clobbers. Spec/layout checks and the release build pass. Complete paired JSON matches. The full workspace and stage suites also pass in fork PR CI.
…#1056)

Region construction makes fewer temporary allocations while preserving its traversal order and dominators. On the pinned `crond` sample, separate heaptrack runs counted 5,948,267 → 5,510,184 whole-process allocation calls (438,083 fewer). Three ordinary pairs against main `939ab703` changed median CPU from 3.125 to 2.979 seconds (-4.67%), with identical JSON and nearly flat RSS.

After building Kuna and its specs, run this on main and this branch. Use heaptrack separately to count allocations:

```sh
curl -fL 'https://huggingface.co/datasets/noelo-lab/decbench-dataset/resolve/815eb96f130b6d2ef7fa600e04669bf20139bf27/binaries/O2-noinline/cronie/crond' -o /tmp/crond.bin
strip --strip-all -o /tmp/crond.stripped /tmp/crond.bin
export KUNA_SPECS="$PWD/specs"
tag=main # use tag=pr in the other checkout
/usr/bin/time -f '%U user %S system %M KiB peak' decompiler/target/release/kuna decompile-all /tmp/crond.stripped --jobs 1 --json --max-fn-seconds 60 > "/tmp/crond-$tag.json"
heaptrack --record-only -o "/tmp/crond-$tag.heap" decompiler/target/release/kuna decompile-all /tmp/crond.stripped --jobs 1 --json --max-fn-seconds 60 > "/tmp/crond-$tag-heap.json"
heaptrack_print -f "/tmp/crond-$tag.heap.zst" -n 1
```

- Reuse sorted successor scratch and borrow predecessor slices.
- Keep dominator state in graph-local reachable-node order; preserve the caller's ordered map and unrelated entries.
- Use hash tables only for lookup/membership state, preserving deterministic output ordering.

This complements Noelo-Lab#1035's structurer retry fix. On current main `939ab703`, 20 graph tests pass, including an independent path-removal dominator oracle over cyclic graphs and reversed edge order. Spec/layout checks and the release build pass. Complete paired JSON matches. Full workspace and stage suites are deferred to fork PR CI.
@mahaloz
mahaloz merged commit ce4b864 into Noelo-Lab:main Oct 15, 2026
2 checks passed
@TsingShui
TsingShui deleted the fix/catalog-in-process-default branch October 15, 2026 04:52
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.

3 participants