fix(relinker): recognize ignored segment prefixes in import sites #11626

Merged
Mherberts merged 1 commit from upstream-pr/11626 into main 2026-11-02 12:26:05 +00:00
Mherberts commented 2026-10-26 23:31:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Mherberts on 2026-10-26T23:31:15Z.


What

--registry misses RIP-relative import accesses when their instructions carry the ignored 64-bit CS (2E), ES (26) or SS (36) prefix. For example, 2e ff 15 f9 00 00 00 at 0x200 references the import slot at 0x300, but currently produces an empty callSites list with callSitesResolved: false.

Recognize those prefixes alongside the existing DS/F2 handling. A legacy prefix still clears a preceding REX.W, so narrow loads remain excluded unless a later REX.W restores pointer width. FS/GS, address/operand-size overrides and unsupported prefixes retain their conservative handling. Update the existing debt entry to remove only the three newly handled prefixes.

AMD64 APM Volume 3, section 1.2.4, describes CS/DS/ES/SS as null prefixes in 64-bit mode. REX placement follows Intel SDM Volume 2A, section 2.2.1.

Tested

Windows x64, GCC 15.2.0 / MinGW-w64, C++20 Release, Ninja, Python 3.13; ANYPS5_RELINKER_ONLY=ON, BUILD_TESTING=ON. Base: 74acfad65b3f0fd4eab653f3a3989d298fba1157; tested head: 21211527670dcdcd85918a96a49edcfa0bace0d2.

  • Negative control: built the new tests against the unchanged base implementation. Both call_site_resolver and call_registry fail on the first CS-prefixed call; the conversion succeeds but its registry omits 0x200.
  • Complete relinker-only build passed. All 17 focused CTest tests passed (27.68 s): call_registry_writer, call_site_index, call_site_resolver, decoder_length, call_zero_padding, windows_trace_imports, linux_trace_imports, macos_trace_imports, import_symbol_types, guest_registry, guest_unused_import_dependencies, weak_imports, call_registry, unused_filter_indirect, unused_filter_fallthrough_padding, control_flow_graph, strict_nid_filter.
  • Native regression adds a CS/ES/SS/DS matrix covering indirect call/jump/push forms, pointer loads, F2 order, REX precedence and negative prefix/width/operation controls. The existing JSON integration test adds 64 Linux/Windows conversions, checking the complete registry entry, instruction-start address and narrow-load exclusions.
  • Test registration audit: 39 native test executables registered; all 196 Python test scripts have a CTest/workflow entry. git diff --check passed.
  • Required conventions check against origin/main: 0 errors, 34 warnings in upstream debt files because this fork's main is older. Check against the actual upstream/main base passed without findings.
  • Ran the repository's tools/pr_overlap.py --branch codex/fix-segment-prefixed-import-sites through a local public-API adapter (GitHub CLI is unavailable), comparing changed paths across 1,282 open PRs. Seven conflicting PRs required manual comparison of docs/dev/debt/relinker.md: #5021, #10479, #10861, #10970, #10983, #11061 and #11107. Their debt changes concern TLS, syscall/code extent, red-zone framing or Rosetta lowering; none changes this registry-prefix entry or implements this fix.

This is focused native/synthetic-fixture validation, not the full product test suite. No commercial title or native Linux/macOS runtime was run; Linux and Windows output generation was checked on Windows. No performance claim.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5026218599 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11626). Originally posted by [Mherberts](https://github.com/Mherberts) on 2026-10-26T23:31:15Z. --- ### What `--registry` misses RIP-relative import accesses when their instructions carry the ignored 64-bit CS (`2E`), ES (`26`) or SS (`36`) prefix. For example, `2e ff 15 f9 00 00 00` at `0x200` references the import slot at `0x300`, but currently produces an empty `callSites` list with `callSitesResolved: false`. Recognize those prefixes alongside the existing DS/F2 handling. A legacy prefix still clears a preceding REX.W, so narrow loads remain excluded unless a later REX.W restores pointer width. FS/GS, address/operand-size overrides and unsupported prefixes retain their conservative handling. Update the existing debt entry to remove only the three newly handled prefixes. AMD64 APM Volume 3, section 1.2.4, describes CS/DS/ES/SS as null prefixes in 64-bit mode. REX placement follows [Intel SDM Volume 2A, section 2.2.1](https://cdrdv2-public.intel.com/812383/253666-sdm-vol-2a.pdf#page=46). ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Windows x64, GCC 15.2.0 / MinGW-w64, C++20 Release, Ninja, Python 3.13; `ANYPS5_RELINKER_ONLY=ON`, `BUILD_TESTING=ON`. Base: `74acfad65b3f0fd4eab653f3a3989d298fba1157`; tested head: `21211527670dcdcd85918a96a49edcfa0bace0d2`. - Negative control: built the new tests against the unchanged base implementation. Both `call_site_resolver` and `call_registry` fail on the first CS-prefixed call; the conversion succeeds but its registry omits `0x200`. - Complete relinker-only build passed. All **17 focused CTest tests passed** (27.68 s): `call_registry_writer`, `call_site_index`, `call_site_resolver`, `decoder_length`, `call_zero_padding`, `windows_trace_imports`, `linux_trace_imports`, `macos_trace_imports`, `import_symbol_types`, `guest_registry`, `guest_unused_import_dependencies`, `weak_imports`, `call_registry`, `unused_filter_indirect`, `unused_filter_fallthrough_padding`, `control_flow_graph`, `strict_nid_filter`. - Native regression adds a CS/ES/SS/DS matrix covering indirect call/jump/push forms, pointer loads, F2 order, REX precedence and negative prefix/width/operation controls. The existing JSON integration test adds **64 Linux/Windows conversions**, checking the complete registry entry, instruction-start address and narrow-load exclusions. - Test registration audit: 39 native test executables registered; all 196 Python test scripts have a CTest/workflow entry. `git diff --check` passed. - Required conventions check against `origin/main`: 0 errors, 34 warnings in upstream debt files because this fork's `main` is older. Check against the actual `upstream/main` base passed without findings. - Ran the repository's `tools/pr_overlap.py --branch codex/fix-segment-prefixed-import-sites` through a local public-API adapter (GitHub CLI is unavailable), comparing changed paths across 1,282 open PRs. Seven conflicting PRs required manual comparison of `docs/dev/debt/relinker.md`: #5021, #10479, #10861, #10970, #10983, #11061 and #11107. Their debt changes concern TLS, syscall/code extent, red-zone framing or Rosetta lowering; none changes this registry-prefix entry or implements this fix. This is focused native/synthetic-fixture validation, not the full product test suite. No commercial title or native Linux/macOS runtime was run; Linux and Windows output generation was checked on Windows. No performance claim. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: <!-- #PR, or none --> none - [x] Fixes: <!-- issue it closes as Fixes #N, or none --> none - [x] Unblocks: <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> none - [x] GPUs tested: <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> n/a - [x] AI-assisted: <!-- yes / no --> yes
MarcZX10 commented 2026-10-26 23:43:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-26T23:43:09Z.

Review: APPROVED


Reviewed exact head 21211527670dcdcd85918a96a49edcfa0bace0d2. The decoder recognizes only the additional ignored CS/ES/SS prefixes alongside existing DS/F2 handling, resets a preceding REX.W on legacy prefixes, and preserves the conservative treatment of FS/GS and unsupported prefixes. The new matrix covers indirect call/jump/push, pointer loads, prefix order, REX precedence, and negative controls. I independently built and ran call_site_resolver and call_registry from this head on Linux (2/2 passed), and git diff --check passed. Hosted conventions/eligibility/intake/labels plus Linux, Windows, macOS (both configurations) relinker and ASan jobs all pass; product checks are skipped by path policy. I found no blocking issue.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5660568773 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11626#pullrequestreview-5660568773). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-26T23:43:09Z. **Review:** APPROVED --- Reviewed exact head `21211527670dcdcd85918a96a49edcfa0bace0d2`. The decoder recognizes only the additional ignored CS/ES/SS prefixes alongside existing DS/F2 handling, resets a preceding REX.W on legacy prefixes, and preserves the conservative treatment of FS/GS and unsupported prefixes. The new matrix covers indirect call/jump/push, pointer loads, prefix order, REX precedence, and negative controls. I independently built and ran `call_site_resolver` and `call_registry` from this head on Linux (2/2 passed), and `git diff --check` passed. Hosted conventions/eligibility/intake/labels plus Linux, Windows, macOS (both configurations) relinker and ASan jobs all pass; product checks are skipped by path policy. I found no blocking issue.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!11626
No description provided.