Skip to content

[AUTOMATED] feat(analysis): datasyms - import ELF OBJECT symbols so libc globals render by name (DIV-76) - #305

Merged
mahaloz merged 1 commit into
mainfrom
fix/i184-elf-data-symbols
Aug 16, 2026
Merged

mahaloz merged 1 commit into
mainfrom
fix/i184-elf-data-symbols

Conversation

@mahaloz

@mahaloz mahaloz commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

Fixes #184

What this PR does

Completes GH-184 end-to-end. The core mechanism the issue asked for — reading the data half (STT_OBJECT) of the .symtab/.dynsym walks and installing each defined, named, non-zero-st_size entry as a named undefined<size> global — already landed on main in 7517e39 (DIV-26), which shipped flagless with the rationale "kuna has never made 'name what the symbol table names' optional". That left the issue open against the repo's standing requirements: no settable option, no catalog row, no faillog-witness tests, and two docs (docs/spec/01-program-prep.md explicitly saying "carries no flag", docs/missing-ghidra-analyses.md §2 still functions-only). This PR closes those gaps:

  • New settable option datasyms (P1/external-refinement, analysis tier, default-ON, DIV-76) gating the loader data-symbol commit arm. Off restores the pre-DIV-26 raw dat_<addr> rendering exactly.
  • Gate shape — no env bridge needed: unlike relocobjects/i386_pie_plt (which gate load-time layout), the data-symbol stream is collected at load file but committed at read symbols (commit_analysis_output, arm 4a), which runs after the CLI's option lines on both paths. The gate is the plain Architecture::analysis_datasyms flag consulted at the commit — the same stash-at-load/gate-at-commit shape as cppproto and the analysis-pass gates. The stash is drained either way so a second read symbols cannot re-commit.
  • Tests (no stage XML is possible — the XML datatest path never constructs an ObjectLoadImage, so the cargo suite is the gate):
    • kuna-analysis unit test faillog_data_symbols_carry_the_copy_reloc_externs over a vendored copy of tests/bug-repro/faillog (datasyms_faillog_x86_64, md5 3bab801d856c5fdb175fecf069c2b4f5, identical bytes): asserts the emitted facts are exactly stdout@0x6160/8, stderr@0x61a0/8, optind@0x6168/4, optarg@0x6180/8 — no zero-size linker markers, no UND placeholders, no @VERSION leakage.
    • kuna-console e2e faillog_stderr_renders_by_name_by_default + option_datasyms_off_restores_dat_addr (in verify_loader_data_symbols.rs): decompile tests/bug-repro/faillog @ 0x3320 in-process; default asserts stderr and no dat_61a0, the off arm asserts dat_61a0 and no stderr — the two-pass bug/fix pair the standing requirements ask for, hosted in the suite instead of a stage XML.
  • Docs: docs/spec/01-program-prep.md re-worded to describe the datasyms gate; docs/missing-ghidra-analyses.md §2 records the data-symbol half now covered; docs/history.md gains the DIV-76 row and DIV-26's row is annotated; docs/options.md regenerated.

Root cause (of the original issue)

The loader's .symtab and .dynsym walks both filtered SymbolKind::Text, so no ELF data (STT_OBJECT) symbol was ever imported; the only producer of named data globals was the DWARF pass, which structurally cannot reach a copy-relocated (R_X86_64_COPY) libc extern — it has a real .bss address and a .dynsym entry but no DIE in the program's own .debug_info. Every libc global (stderr, stdout, stdin, optind, optarg, __progname) and every stripped/DWARF-less binary's own statics rendered dat_<addr> where all four rival decompilers print the name.

Before / after (the issue's vendored witness)

kuna decompile-all tests/bug-repro/faillog --addr 0x3320, both call sites:

// --option datasyms off  (= the pre-DIV-26 bug, now reproducible on demand)
__fprintf_chk(dat_61a0,1,dcgettext(NULL,v5,5),v1,a0 & 0xffffffff);

// default
__fprintf_chk(stderr,1,dcgettext(NULL,v5,5),v1,a0 & 0xffffffff);

Whole-binary spot-checks (default): grep names stderr×11, optarg×27, __progname×1; sort names stderr×12, optarg×23, optind×14, __progname×1. The issue's second witness (iproute2 ip @ 0x5c180) is not vendored in-repo and was not re-run.

On/off proof on BOTH CLI paths

  • In-process: kuna decompile-all tests/bug-repro/faillog --addr 0x3320 → 2× stderr; ... --option datasyms off → 2× dat_61a0, 0× stderr.
  • Subprocess (decomp_dbg script): kuna decompile tests/bug-repro/faillog 0x3320 --addr → 2× stderr; ... --option datasyms off → 2× dat_61a0, 0× stderr. (The script emits option lines before read symbols, where the commit consults the flag — verified, no decompile.rs change needed.)

Collateral audit

Base (origin/main 2b5117f release binary) vs this branch, decompile-all --json at default, byte-compared: tests/bug-repro/faillog, grep, sort, libselinux.so.1 — all four IDENTICAL. Expected: the gate is default-ON over an unchanged mechanism, so the default output is a structural no-op; the off arm is the only behavior change and is opt-in.

Datatest evidence

Trivially 0/675 (and 0/460 stages): the XML datatest path bypasses the ELF loader entirely (<binaryimage> never constructs an ObjectLoadImage), so no baseline is touched. No re-pin.

Gates

  • make test — PARITY OK (675/675)
  • make test-stages — PARITY OK (460/460)
  • make rust-test — green (this is an internal-branch PR, so CI skips the workspace suite; it was run locally)
  • make check-spec — OK
  • kuna catalog --check — OK ("documents exactly the registered kuna options")

Counters re-derived from the built artifact

live catalog 107; catalog_bytecompat.rs 107 (×3) + regenerated phase_catalog.json fixture (captured via decomp_dbg openfile write + phase catalog); kuna_phases/tests.rs 107 / tiers (23, 47, 37) / },\n 106 / live readers 33 (datasyms joins the PASS_GATES no-codegen-live-reader allowlist, read console-side via kuna_live_value); docs/options.md regenerated. tests/stages/kuna-catalog.xml needs no bump: #5/#9 are ranged (min=10 max=160) and datasyms joins neither the angr-provenance (#6) nor structure-recovery (#7) nor opt-in-tool (#8) exact buckets. No new scheduled Action ⇒ the action-tree oracle/leaf/adjacency tests are unmoved (confirmed by the suite).

Speed

Interleaved, minimum of 11 per side, kuna decompile-all tests/bug-repro/grep --json > /dev/null: base 15.797 s vs gated 15.669 s (-0.81% — the gated arm is faster, i.e. the one-bool-per-commit cost is below the noise floor).

Judgment calls

  • size==0 policy: skip (kept from DIV-26, now pinned by test): the linker's section-boundary markers (__bss_start, _edata, _end) are exactly the zero-size entries and would plant a name on the first byte of an unrelated object; there is also no extent to size the covering SymbolEntry against.
  • Dedupe policy: first-wins by address, .symtab walked before .dynsym (kept from DIV-26) — mirrors the funcsym stream's discipline; a WEAK alias sharing an address (e.g. program_invocation_short_name = __progname) keeps the first table entry.
  • No sanity cap added: neither the funcsym walks nor the sibling loader passes cap symbol-table cardinality; the data walk mirrors them (one HashSet<u64> + one Vec over defined OBJECT entries).
  • Relocatable objects excluded (kept from DIV-26): reloc_object rebases only the function half; a .o keeps its previous behavior.

🤖 Generated with Claude Code

https://claude.ai/code/session_01VBn8vgwoHqPFnnV4ZMApfq

…hat names libc globals (DIV-76)

[AUTOMATED] Completes GH-184. The mechanism -- reading the STT_OBJECT half of
the .symtab/.dynsym walks and installing each defined, named, non-zero-st_size
entry as a named undefined<size> global, so a copy-relocated libc extern
(stderr, stdout, stdin, optind, optarg, __progname) and a stripped/DWARF-less
binary's own statics render by name instead of dat_<addr> -- landed flagless in
7517e39 (DIV-26), against the standing anything-that-changes-emitted-C rule,
with no catalog row, no witness tests, and spec prose reading "carries no flag".

This PR adds the gate and the missing collateral:

- New settable option `datasyms` (P1/external-refinement, analysis tier,
  default-ON, DIV-76). Gate shape: the stream is collected at `load file` but
  committed at `read symbols` (commit_analysis_output arm 4a), AFTER the CLI's
  option lines on both paths, so the gate is the plain
  Architecture::analysis_datasyms flag -- no env bridge (unlike
  relocobjects/i386_pie_plt, which gate load-time layout). The stash drains
  either way so a second `read symbols` cannot re-commit; off restores the
  pre-DIV-26 rendering exactly.
- kuna-analysis unit test over a vendored copy of tests/bug-repro/faillog
  (datasyms_faillog_x86_64, md5-identical): pins the fact stream to exactly
  stdout@0x6160/8, stderr@0x61a0/8, optind@0x6168/4, optarg@0x6180/8 -- no
  zero-size linker markers, no UND placeholders, no @Version leakage.
- kuna-console e2e two-pass pair in verify_loader_data_symbols.rs: default
  asserts `stderr` (and no dat_61a0) at faillog 0x3320; `datasyms off` asserts
  dat_61a0 (and no stderr). No stage XML is possible -- the datatest path never
  constructs an ObjectLoadImage -- so the cargo suite hosts the pair.
- Docs: spec 01-program-prep re-worded for the gate; missing-ghidra-analyses §2
  records the data-symbol half; history.md DIV-76 row (+ DIV-26 row annotated);
  options.md regenerated.
- Counters re-derived from the built artifact: live catalog 107,
  catalog_bytecompat 107 + regenerated phase_catalog.json, kuna_phases tests
  107 / tiers (23,47,37) / "},\n" 106 / live readers 33 (datasyms joins the
  PASS_GATES kuna_live_value set); kuna-catalog.xml unmoved (ranged buckets).

Verified: default output byte-identical to base on decompile-all --json of
faillog/grep/sort/libselinux.so.1; on/off proven on BOTH the in-process
decompile-all path and the subprocess decompile path. Gates: make test 675/675
PARITY OK, make test-stages 460/460 PARITY OK, make rust-test green,
make check-spec OK, kuna catalog --check OK.

Fixes #184

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01VBn8vgwoHqPFnnV4ZMApfq
@mahaloz
mahaloz merged commit 6353796 into main Aug 16, 2026
9 checks passed
@mahaloz
mahaloz deleted the fix/i184-elf-data-symbols branch August 16, 2026 19:55
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.

Loader imports no ELF data (OBJECT) symbols: libc globals like stderr render dat_<addr>

1 participant