Repository navigation
Multi-format loader PR-8: Mach-O fat/universal + arm64e - #67
Merged
Merged
Conversation
…4e spec A fat / universal Mach-O (`0xcafebabe`) wraps several arch slices, and `object::File::parse` is a thin single-arch view that cannot parse a fat header — so a universal binary failed to load at all. This adds the single, canonical slice-selection point at dispatch (`bootstrap_from_object`): a new `s1_loader/macho_fat::select_fat_slice` peels the fat bytes to one arch slice *before* the loader runs, so loadimage + the `__stubs` import walk + entry discovery are all single-arch exactly as for a thin Mach-O. Slice preference: `--slice <arch>` (env `KUNA_MACHO_SLICE`) -> the `--target` arch stem -> the deterministic default (x86-64 -> arm64 -> first present). `macho_stubs`'s own fat arms now delegate to the same selector, so the import walk and the loadimage can never drift onto different slices. arm64e (gated, opt-in, design 3.7): pointer authentication does not change import naming or symbols, only the spec. `object` collapses arm64/arm64e to one `Architecture`, so the cpusubtype is read from a typed re-parse (`macho::is_arm64e`), and `macho::apple_silicon_id` returns `AARCH64:LE:64:AppleSilicon` only when format=Mach-O + arch=AArch64 + the gate is on + the image is arm64e. Spec selection is a load-time decision, so the live gate is the `KUNA_MACHO_ARM64E` env var the CLI exports for `--option macho-arm64e on`; the option is also a registered settable (catalog consistency). Default-off => an arm64e Mach-O loads with the generic v8A spec. Fixtures (no lipo/llvm-lipo in-container): `macho_fat` is a hand-built 2-slice universal wrapping the existing `macho_imports` (x86-64) + `macho_imports_arm64` (arm64) thin slices; `macho_arm64e` is `macho_imports_arm64` with its header cpusubtype flipped to CPU_SUBTYPE_ARM64E (the load + spec-selection path is real; only the cpusubtype is synthesized — a genuine arm64e binary is a follow-up). e2e (`verify_macho_fat.rs`, real load through the built `.sla`): the fat binary loads its default x86-64 slice and names `printf`; `--slice arm64` selects the other slice; arm64e gate-on selects the AppleSilicon spec and still names `printf`; gate-off uses generic v8A; default-off rejects the fat binary. Plus hermetic unit tests for the slice-pref parse, `is_arm64e`, and the gated `apple_silicon_id` mapping. CLI speed: `kuna decompile macho_fat _main --experimental-formats` ~0.34s end-to-end. Default-off => ELF/PE/COFF/thin-Mach-O byte-identical (the slice peel is a pass-through for thin inputs; arm64e gated off). Gates: make test 675/675 PARITY OK, make test-stages 159/159 PARITY OK, make rust-test green, kuna catalog --check OK (settable count 37 -> 38). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01FvRnfTgYKoZvS2TEvdYpWb
…t-arm64e # Conflicts: # decompiler/crates/kuna-decomp/src/p0_knowledge/kuna_stages/tests.rs # decompiler/crates/kuna-decomp/tests/catalog_bytecompat.rs # docs/analysis-port-log.md
…t-arm64e # Conflicts: # decompiler/crates/kuna-cli/src/decompile.rs # decompiler/crates/kuna-decomp/src/infra/architecture.rs # decompiler/crates/kuna-decomp/src/p0_knowledge/kuna_stages/tests.rs # decompiler/crates/kuna-decomp/src/p0_knowledge/options.rs # decompiler/crates/kuna-decomp/stages.toml # decompiler/crates/kuna-decomp/tests/catalog_bytecompat.rs # decompiler/crates/kuna-decomp/tests/fixtures/stage_catalog.json # docs/assertions.md # tests/stages/kuna-catalog.xml
mahaloz
added a commit
that referenced
this pull request
Jun 25, 2026
…3591e (#55) Re-merge after main advanced (PR #67 added the macho-arm64e loader-tier settable). Union the count drift: - 44 settables now (26 stage-model knobs + 15 analysis gates + 3 loader caps: relocobjects/i386_pie_plt/macho-arm64e), surface=91 - kuna_stages/tests.rs + catalog_bytecompat.rs count assertions -> 44; trailing-comma count -> 43 (last row now macho-arm64e) - loopbreak_recovery (DIV-10) provenance unchanged; angr=9, structure-recovery=5 - regenerate stage_catalog fixture, assertions.md, baseline-stages.json (165/165) Gates: catalog OK, make test PARITY OK (675/675), make test-stages PARITY OK (165/165). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01PBrckq3YYAzBLq5k4KpWac
mahaloz
added a commit
that referenced
this pull request
Jun 25, 2026
…57) Union-resolve the registrations for the gotoreduce opt-in option (angr SAILR ReturnDuplicator goto-reduction) against main, which had advanced with the #55 (loopbreak_recovery/DIV-10) and #67 (macho-arm64e) settables: - architecture.rs / seams.rs / options.rs: union reduce_return_gotos with recover_loop_break/fold_call_returns fields, ctors, resets, set_kuna_option arms, KUNA_OPTION_NAMES, seam-copies - s8_structure/mod.rs: union kuna_gotoreduce + kuna_loopbreak_recovery modules - stages.toml: union the gotoreduce settable; 45 settables now (27 stage-model + 15 analysis + 3 loader caps), surface=91 - gotoreduce ElementId 4100 (no collision: dedup 4091, loopbreak 4092) - catalog provenance counts: angr 10, structure-recovery 6 (gotoreduce both) - count assertions (kuna_stages/tests.rs, catalog_bytecompat.rs, xml.rs corpus 137 files) bumped; regenerate stage_catalog fixture, assertions.md, baseline-stages.json (168/168) - gotoreduce is opt-in (default-off) -> no DIV entry Gates: catalog OK, make test PARITY OK (675/675), make test-stages PARITY OK (168/168). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01PBrckq3YYAzBLq5k4KpWac
mahaloz
added a commit
that referenced
this pull request
Jun 25, 2026
Region-structurer foundation (Inc 0) — analysis-only, no new --option. Main had advanced with #55 (loopbreak_recovery/DIV-10), #57 (gotoreduce), #67 (macho-arm64e); the only conflict was docs/baseline-stages.json (data_footer counts), all other region code (s7_regions/kuna_regiongraph.rs, kuna_regionid.rs, kuna_console.rs) and the kuna-regions.xml assertions merged cleanly. Regenerated assertions.md (45 settables, unchanged) and baseline-stages.json (171/171, incl. the 8 KUNA-REGIONS assertions plus main's gotoreduce/loopbreak/catalog ones). Gates: catalog OK, make test PARITY OK (675/675), make test-stages PARITY OK (171/171). Region unit tests: regionid 6/6, regiongraph 18/18 (incl. new build_from_block_graph_*). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01PBrckq3YYAzBLq5k4KpWac
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR-8 of the multi-format-loader expansion (design
docs/multiformat-loader-design.md§3.4 + §3.7 + §8). Builds on the Mach-O headline (#49) and entry-discovery (#63).Fat / universal slice selection (§3.4)
A fat Mach-O (
0xcafebabe) wraps several arch slices, andobject::File::parseis a thin single-arch view that cannot parse a fat header — so a universal binary failed to load at all (only the import walk had per-slice handling). This adds the single, canonical slice-selection point at dispatch:s1_loader/macho_fat::select_fat_slice(bytes, SlicePref)peels a fat binary to one arch slice's sub-bytes (32- and 64-bit fat readers share one arch-preference policy).bootstrap_from_objectcallsselect_macho_slice(bytes, target)right after reading the file, beforeObjectLoadImage::from_bytes— so the loader, the analysis passes, and the deferred-Listing stash all see the same thin slice. A non-fat input passes through verbatim (zero-copy), so ELF / thin-Mach-O / PE / COFF are byte-identical.macho_stubs's own fat arms now delegate to the same selector (the duplicate slice helpers were removed), so the import walk and the loadimage can never drift onto different slices.Override:
--slice <arch>(new CLI flag, envKUNA_MACHO_SLICE) → the--targetarch stem → the deterministic default x86-64 → arm64 → first present.arm64e Apple-Silicon spec (§3.7, gated)
Pointer authentication does not change import naming or symbols — only the spec.
objectcollapses arm64/arm64e to oneArchitecture, so the cpusubtype is read from a typed re-parse (macho::is_arm64e);macho::apple_silicon_idreturnsAARCH64:LE:64:AppleSilicononly when format=Mach-O + arch=AArch64 + the gate on + the image is arm64e. Spec selection is a load-time decision (before any consoleoption), so the live gate is theKUNA_MACHO_ARM64Eenv var the CLI exports for--option macho-arm64e on; the option is also a registered settable (catalog consistency). Default-off ⇒ an arm64e Mach-O loads with the generic v8A spec.Fixtures + e2e
No
lipo/llvm-lipoin-container, so:macho_fatis a hand-built 2-slice universal wrapping the existing thinmacho_imports(x86-64) +macho_imports_arm64(arm64) slices behind a big-endianfat_header+ twofat_archrecords.macho_arm64eismacho_imports_arm64with its header cpusubtype flipped toCPU_SUBTYPE_ARM64E(arm64e is binary-compatible arm64). The load + spec-selection path is real; only the cpusubtype is synthesized — a genuine-arch arm64ebinary is a follow-up.e2e (
verify_macho_fat.rs, real load through the built.sla, ran, not skipped): the fat binary loads its default x86-64 slice and namesprintf;--slice arm64selects the other slice; arm64e gate-on selects the AppleSilicon spec (description asserted) and still namesprintf; gate-off uses generic v8A; default-off rejects the fat binary. Plus hermetic unit tests (slice-pref parse,is_arm64e, the gatedapple_silicon_idmapping). Speed:kuna decompile macho_fat _main --experimental-formats~0.34 s end-to-end (arm64e variant ~0.29 s).Gates
make test— 675/675 PARITY OKmake test-stages— 159/159 PARITY OKmake rust-test— green (250 suites, 3977 tests, 0 failures; incl. the 5 newverify_macho_fate2e + the macho_fat/arm64e unit tests)kuna catalog --check— OK (settable count 37 → 38, themacho-arm64erow)Default-off ⇒ ELF byte-identical; arm64e gated off. The XML datatest path never reaches the object loader, so the parity oracles are structurally untouched.
🤖 Generated with Claude Code
https://claude.ai/code/session_01FvRnfTgYKoZvS2TEvdYpWb