Skip to content

[AUTOMATED] fix(entry): preserve loader selectors - #350

Merged
mahaloz merged 3 commits into
Noelo-Lab:mainfrom
phix33:fix/et-rel-entry-model
Sep 3, 2026
Merged

mahaloz merged 3 commits into
Noelo-Lab:mainfrom
phix33:fix/et-rel-entry-model

Conversation

@phix33

@phix33 phix33 commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

The problem

Relocatable objects can contain same-named local functions at the same section-relative offset. kuna decompile silently selects the first definition instead of reporting the ambiguity.

set -eu
make >/dev/null 2>&1
repro=$(mktemp -d decompiler/target/entry-selector.XXXXXX)
build_obj() {
  printf '%s\n' \
    ".section .text.selector_$1,\"ax\",@progbits" \
    '.local duplicate_local' \
    '.type duplicate_local,@function' \
    'duplicate_local:' \
    "mov \$$2, %eax" \
    'ret' \
    '.size duplicate_local, .-duplicate_local' |
    as --64 -o "$repro/$1.o"
}
build_obj a 1
build_obj b 2
ld -r -o "$repro/repro.o" "$repro/a.o" "$repro/b.o"
decompiler/target/release/kuna decompile "$repro/repro.o" duplicate_local
unsigned long duplicate_local(void)
{
  return 1;
}

The fix

  • Retain each relocatable function’s section coordinate, binding, and defined/undefined provenance alongside its synthetic VMA.
  • Accept .section+0xOFFSET and SECTION_INDEX:0xOFFSET; report candidates for ambiguous names or raw offsets and reject unmapped addresses.
  • Apply the same selection rules across the console, CLI, project export, and WASM, and expose object_location in JSON output.

The tests

Added console, CLI, and WASM cases for collisions, section-qualified selection, invalid coordinates, sectionless mappings, non-default address spaces, and Thumb symbols. The duplicate-name CLI case fails without the fix.

- Probe bytes when section metadata is absent.
- Keep address spaces and relocatable coordinates.
@phix33
phix33 force-pushed the fix/et-rel-entry-model branch from dbc9185 to 0058dea Compare September 2, 2026 21:33
@phix33

phix33 commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto current main. The selector and object-location changes now compose with the new function-size inventory, so native CLI and WASM JSON retain both object_location and size.

Conflict resolution
- `decompile.rs`: keep main's `decompile_all` import beside the branch's
  `EntrySelector` one.
- `decompile_all.rs (run_functions)`: keep main's `functions_json` +
  zero-discovery-error shape and add `object_location` to that renderer,
  rather than the branch's inlined JSON, which predated both.

Review fixes
- `kuna decompile <obj> <ambiguous-name>` printed a console transcript capped
  at its FIRST 2000 characters instead of the ambiguity report — in the default
  mode that cap lands inside the `option ...` preamble, so the PR's own repro
  command showed the user nothing. `check_errors` now recovers the selector
  diagnostic verbatim, candidate lines included, behind the unmapped-entry
  probe so an external stays an external.
- `resolve_entry(Name)` did not apply the `symbolnamebound` fold that
  `find_entry_by_name` documents as load-bearing, so `--functions <original
  name>` stopped resolving on a hostile deep-scope name. Bounded in the one
  shared place.
- `kuna xrefs --to <name>` fell through `find_entry_by_name`'s new
  None-on-ambiguity into `lookup_symbol`, which answers for the first match —
  the guess this branch exists to refuse. `xrefs` landed on main after the
  branch, so nothing had reconciled the two. Ambiguity is now reported.
- `entry_selectors.rs` hard-coded `target/debug/decomp_dbg`, failing the case
  outright under `cargo test --release`; it now takes the sibling of its own
  `kuna`.
- `find_entry_by_name`'s doc no longer claims first-match.

Tests: two new cases (default-mode ambiguity, `xrefs` ambiguity).
Gates: make test 675/675 PARITY OK; make test-stages 574/574 PARITY OK;
cargo test --workspace green; make check-spec OK; kuna catalog --check OK.

[AUTOMATED] Prepared by Claude Code and reviewed by the maintainer before
submission.
@mahaloz
mahaloz merged commit 211f54a into Noelo-Lab:main Sep 3, 2026
2 checks passed
mahaloz added a commit that referenced this pull request Sep 3, 2026
The PR was CONFLICTING against main, which is why no `pull_request` workflow run
ever appeared for it: GitHub does not run those when it cannot compute the merge
commit, so the PR presented as "CodeQL green" with not one gate executed -- the
exact failure mode the tests.yml header warns about. `open_pr.sh --merge` would
have refused it (a required suite that is `missing` is treated the same as one
that is `skipped`), which is that guard earning its place against a real case.

Both conflicts were additive-on-both-sides and are unioned, not picked:
- `decompile_all.rs` -- the import block; #350 added EntryLookupError /
  EntrySelector / ObjectLocation, this branch added the xrefs index, Address,
  BTreeSet/VecDeque and Rc for `--reachable-from`.
- `docs/cli.md` -- #350 documented `object_location`, this branch documented
  `--summary` and the `total` field.

#350 touches loader/entry selectors, which is where `unmappedentry` and
`entrymainproto` live, so a clean textual merge proves nothing here. Re-verified
on the merged build: the unmappedentry witness still drops 0x349688c1 by default
and restores it with `--option unmappedentry off`; entrymainproto still types
argc/argv/envp on the PE CRT fixture; and #350's own property -- a loader `main`
symbol surviving discovery -- holds.

Gates re-run after the merge: make test PARITY OK · make test-stages PARITY OK ·
make test-cli 10/10 · make check-spec OK · kuna catalog --check OK · counters no
drift.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@phix33
phix33 deleted the fix/et-rel-entry-model branch September 6, 2026 21: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.

2 participants