Skip to content

Analysis-tier: _INIT_<i>/_FINI_<i> array-element naming - #17

Merged
mahaloz merged 2 commits into
mainfrom
init-fini-naming
Jun 23, 2026
Merged

mahaloz merged 2 commits into
mainfrom
init-fini-naming

Conversation

@mahaloz

@mahaloz mahaloz commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Give the dynamic INIT/FINI entry points their Ghidra loader names instead of the generic sub_<addr>, faithful to ElfProgramBuilder.createDynamicEntryPoints. This is the one cosmetic follow-up the Increment 15 completeness sweep flagged.

What

Per ElfProgramBuilder.createDynamicEntryPoints:

  • DT_INIT_ARRAY element i → _INIT_<i>
  • DT_FINI_ARRAY element i → _FINI_<i> (Ghidra's baseName + i)
  • single DT_INIT/DT_FINI → _DT_INIT/_DT_FINI (Ghidra's "_" + dynamicEntryType.name)

DT_PREINIT_ARRAY (_PREINIT_<i>) is wired as the faithful seam but emits nothing — kuna does not currently discover preinit-array elements as code entries, and adding that would change the discovery set.

Shape choice — additive overlay (not a reshape)

AnalysisOutput.entries stays Vec<u64>; a new parallel entry_names: Vec<(u64, String)> overlay carries the names. Chosen over reshaping entries to Vec<EntryFact> because it makes the discovery byte-identical property provable:

  • s1_entry::collect_entries is untouched.
  • dynamic_entry_points is now exactly dynamic_entry_points_named(file).map(|(a,_)| a) — a guaranteed-equal projection (unit-tested: dynamic_entry_points_is_named_projection), and the pushed VMAs/order are identical to before.
  • The overlay is filtered to the VMAs that actually survive collection, so a name for a funcsym-covered (dropped) entry is never emitted.
  • The other four oracles + the address-table pass leave the overlay empty → existing sub_<addr> behavior.

The commit seam (engine.rs::commit_analysis_output step 2) consults the overlay by address; a miss falls back to name_function (sub_<addr>) as before. The idempotent find_function no-op is kept, so a non-stripped binary's real .symtab/.dynsym name still wins — only genuinely new, never-symboled array-element starts take the _INIT_<i> names.

Flag. Purely additive on the always-on entry_disc pass — no new option, no settable-count bump. --option entry_disc off disables the whole discovery pass (names and all) as before.

Before / after

On the vendored stripped PIE stripped_dynamic_x86_64 (.symtab stripped; .init_array@0x3d78→0x1240, .fini_array@0x3d80→0x1200, DT_INIT@0x1000, DT_FINI@0x1464):

BEFORE — array elements named generically:

$ kuna decompile stripped_dynamic_x86_64 sub_1240   # resolved
$ kuna decompile stripped_dynamic_x86_64 sub_1200   # resolved

AFTER — Ghidra-faithful names:

$ kuna decompile stripped_dynamic_x86_64 _INIT_0
void _INIT_0(void)
{
  return;
}
$ kuna decompile stripped_dynamic_x86_64 _DT_INIT   # resolves
$ kuna decompile stripped_dynamic_x86_64 _DT_FINI   # resolves
$ kuna decompile stripped_dynamic_x86_64 sub_1240
error: no function "sub_1240" ...                    # now _INIT_0

Tests

  • kuna-analysis +3 unit tests (dynamic_entry_names_stripped, collect_entry_names_matches_collected_entries, dynamic_entry_points_is_named_projection). The existing dynamic_entry_points_stripped / collect_entries_* discovery tests pass unchanged (byte-identical discovery).
  • kuna-console +1 e2e (verify_s1_entry::dynamic_init_fini_elements_get_ghidra_names): _INIT_0/_FINI_0/_DT_INIT/_DT_FINI resolve, _INIT_0 decompiles, sub_1240 no longer resolves.

Gates

  • make test → 675/675 PARITY OK
  • make test-stages → 158/158 PARITY OK
  • make rust-test → green (0 failed)
  • kuna catalog --check → catalog OK (no new option)

🤖 Generated with Claude Code

https://claude.ai/code/session_01FvRnfTgYKoZvS2TEvdYpWb

mahaloz and others added 2 commits June 23, 2026 15:59
Give the dynamic INIT/FINI entry points their Ghidra loader names instead of
the generic sub_<addr>, faithful to ElfProgramBuilder.createDynamicEntryPoints:
DT_INIT_ARRAY[i] -> _INIT_<i>, DT_FINI_ARRAY[i] -> _FINI_<i>, and the single
DT_INIT/DT_FINI -> _DT_INIT/_DT_FINI. The Increment 15 sweep's one cosmetic
follow-up.

Shape: an additive `entry_names: Vec<(u64, String)>` overlay on AnalysisOutput
(NOT a reshape of `entries`). s1_entry::collect_entries is byte-identical, and
dynamic_entry_points is now exactly dynamic_entry_points_named().map(|(a,_)| a)
-- a guaranteed-equal projection -- so WHICH VMAs are discovered provably does
not change. The commit seam (engine.rs step 2) consults the overlay by address;
a miss falls back to name_function (sub_<addr>) as before, and the idempotent
find_function no-op keeps a real .symtab/.dynsym name winning on non-stripped
binaries -- only never-symboled array-element starts take the _INIT_<i> names.
Purely additive under the always-on entry_disc pass (no new option).

DT_PREINIT_ARRAY (_PREINIT_<i>) wired as the faithful seam but emits nothing
(kuna does not currently discover preinit-array elements; that would change the
discovery set).

Proof on stripped_dynamic_x86_64: .init_array[0]->0x1240 and .fini_array[0]->
0x1200 register as _INIT_0/_FINI_0; DT_INIT@0x1000/DT_FINI@0x1464 as _DT_INIT/
_DT_FINI. `kuna decompile ... sub_1240` now errors; `... _INIT_0` decompiles.

Tests: kuna-analysis +3 (names overlay, kept-filter, named-projection equality);
the existing discovery tests pass unchanged. kuna-console +1 e2e
(verify_s1_entry::dynamic_init_fini_elements_get_ghidra_names).

make test 675/675 PARITY OK; make test-stages 158/158 PARITY OK; make rust-test
green; kuna catalog --check OK.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FvRnfTgYKoZvS2TEvdYpWb
@mahaloz
mahaloz merged commit 09c906d into main Jun 23, 2026
@mahaloz
mahaloz deleted the init-fini-naming branch July 29, 2026 08:01
mahaloz added a commit that referenced this pull request Sep 30, 2026
… to keeps printing as the global

A load the binary makes of a global after storing a computed value to it is
left on the global while the value is read sign-sensitively; otherwise the
value and its stores are marked and Merge joins them with the global as before.
Fixtures gain w_realias/w_rephi/w_reboth/w_recopy (store, pointer store, load);
stage assertions #17-#21, and #5/#6/#9 follow the loads the -O0 binary makes.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_011shDTp2k5iNyyj9TCjt6vg
mahaloz added a commit that referenced this pull request Oct 1, 2026
… to keeps printing as the global

A load the binary makes of a global after storing a computed value to it is
left on the global while the value is read sign-sensitively; otherwise the
value and its stores are marked and Merge joins them with the global as before.
Fixtures gain w_realias/w_rephi/w_reboth/w_recopy (store, pointer store, load);
stage assertions #17-#21, and #5/#6/#9 follow the loads the -O0 binary makes.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_011shDTp2k5iNyyj9TCjt6vg
mahaloz added a commit that referenced this pull request Oct 2, 2026
… to keeps printing as the global

A load the binary makes of a global after storing a computed value to it is
left on the global while the value is read sign-sensitively; otherwise the
value and its stores are marked and Merge joins them with the global as before.
Fixtures gain w_realias/w_rephi/w_reboth/w_recopy (store, pointer store, load);
stage assertions #17-#21, and #5/#6/#9 follow the loads the -O0 binary makes.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_011shDTp2k5iNyyj9TCjt6vg
mahaloz added a commit that referenced this pull request Oct 2, 2026
… to keeps printing as the global

A load the binary makes of a global after storing a computed value to it is
left on the global while the value is read sign-sensitively; otherwise the
value and its stores are marked and Merge joins them with the global as before.
Fixtures gain w_realias/w_rephi/w_reboth/w_recopy (store, pointer store, load);
stage assertions #17-#21, and #5/#6/#9 follow the loads the -O0 binary makes.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_011shDTp2k5iNyyj9TCjt6vg
mahaloz added a commit that referenced this pull request Oct 2, 2026
… to keeps printing as the global

A load the binary makes of a global after storing a computed value to it is
left on the global while the value is read sign-sensitively; otherwise the
value and its stores are marked and Merge joins them with the global as before.
Fixtures gain w_realias/w_rephi/w_reboth/w_recopy (store, pointer store, load);
stage assertions #17-#21, and #5/#6/#9 follow the loads the -O0 binary makes.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_011shDTp2k5iNyyj9TCjt6vg
mahaloz added a commit that referenced this pull request Nov 3, 2026
…hat crosses a skipped call

A kept guard's input can be the value from before a skipped call. Merging
copies that input to the global in front of the call when the input and the
guard's output cannot share a variable (Merge::mergeIndirect's snip). With
every guard built the copy stores what the global already holds; across a
skipped call it stores the value from before that call and undoes it.
`if (a & 1) f0(); else f1(); if (h > 17) { f2(); f0(); } else { arr[a & 7] =
g + 8; fi(g); }` (gcc -O2) printed `f2(); g = v1; f0();` under persistcalls on.

- Mark kept guards whose input crosses a skipped call (kuna_persist_stale,
  stale_inputs); a merge copy of such an input or its collapse restarts the
  function with every guard built.
- Count a system call that guards memory as a STORE, so the call before it
  keeps its guard and the system call's own INDIRECT never reads a stale value.
- Funcdata::clear clears the merge engine's state (upstream covermerge.clear()),
  which a restart from merging needs.
- The pass a function runs once its re-flow budget is spent cannot restart, so
  it keeps every guard.

Tests: persistcalls #15-#17 (snip, snipsys in the rebuilt semantic fixture)
fail before this change; unit test for stale_inputs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0179iMKMUBscgGJBW9XHH5hJ
mahaloz added a commit that referenced this pull request Nov 14, 2026
…ister is not a callee input

The callee-first convergence sweep decompiled every function naming a
superseded synthesized struct again, whatever its size. With calleereginputs
on, an AutoIt-compiled image names superseded `this` records in 37 interior
bodies of ~1,500 lines each, and the sweep cost a fifth of the run. The redos
are now admitted shortest first within 5% of the first pass's printed lines
(at least 2,000 lines; bodies of 32 lines or fewer always); a declined body
keeps its superseded, still-defined struct. Every other binary measured stays
under the budget, so its output is unchanged.

calleereginputs' callee walk counted a register as read when a read touched
any byte not yet written, so `mov cx,[eax+0xa]; mov esi,ecx` (the CRT float
formatter) made the callee __thiscall and its callers passed an ECX a previous
call had clobbered. A register now counts only when read before any part of it
is written. Stage test #17 pins it with a new clean-room case.

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 16, 2026
… by-value block

The calleeargs window is what the callee's returns pop or what the caller
removes after the call. For a __cdecl callee that is the caller's cleanup,
or an `add esp` releasing the caller's own locals before its epilogue, and
stating it as the call's pop moved every stack slot after the call: the
caller lost a parameter or read one in place of a local. It also let a
bottom-of-frame local, or a block built for a later call (`f(g(0), t)`
copies t, then calls g), expand into the next call's arguments.

Flow now records what the callee's reached returns pop (`ret 0x20`) on the
call spec, and repframecopy relies on that alone. byvalreuse_pe_i386 gains
cleanup, local and nested; REPFRAMECOPY Noelo-Lab#15-Noelo-Lab#17 fail without this.

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