fix(relinker): keep segment-relative transfers unresolved in CFG #13620

Merged
PolkadotDom merged 2 commits from upstream-pr/13620 into main 2026-10-31 09:28:55 +00:00
PolkadotDom commented 2026-10-30 19:49:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PolkadotDom on 2026-10-30T19:49:13Z.


What

An indirect call or jmp through FS/GS-relative RIP/EIP memory was resolved using the relocation at the unbased effective address. The segment base is unknown to this analysis, so that relocation can belong to unrelated data. Following its value could add unrelated code to the graph or fail decoding bytes that the transfer never targets.

Keep these transfers unresolved, as other indirect transfers are. Calls still fall through, jumps still end the block, and explicit roots remain reachable. Flat RIP/EIP transfers and ignored CS/DS/ES/SS overrides retain relocation resolution. FS/GS-prefixed LEA still discovers code addresses because LEA does not apply the segment base.

Addressing basis: Linux x86 architecture documentation, consistent with the existing call-site resolver's FS/GS exclusion. This does not infer an FS/GS base or implement runtime indirect-target discovery.

The overlap checker reports an uncomparable shared file with #10861 because that branch conflicts with current main. Manually compared its ControlFlowGraph.cpp diff: it adds followPadding handling and changes the graph API/fall-through policy; it does not change either relocation lookup guarded here. No shared changed lines or dependency was found. Both this branch and the annotation fix are independent.

Tested

Windows x64, Python 3.12.3, GCC 12.2.0, Ninja, Release relinker-only configuration with BUILD_TESTING=ON, based on main 3713032179.

  • New regression fails on the original production code with Segment-relative transfer followed a flat relocation slot; it passes with the fix. Final coverage is 28 transfer combinations (seven segment-prefix choices, RIP/EIP, call/jump), FS/GS unrelated undecodable targets and explicit-root controls, plus FS/GS-prefixed LEA controls.
  • Full relinker-only build succeeds. Six focused CTests pass: control_flow_graph, strict_nid_filter, relinker_conversion, call_site_index, call_registry, and guest_registry.
  • Full suite: 536/537 pass. select_tests_NonAsciiDirectoryTests fails when dumping a build graph under a Unicode directory on this Windows toolchain. Reproduced separately using unchanged select_tests.py and its test from main; neither is touched here. The same failure was present in the preceding contribution round.
  • Conventions and git diff --check pass. Merge preview onto the overlap checker's current-main snapshot is clean. Overlap warning manually reviewed as described above.

Synthetic analysis/conversion fixtures only; no console binary, title execution, GPU validation, or local Linux/macOS run. No title is claimed unblocked.

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:5090188752 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/13620). Originally posted by [PolkadotDom](https://github.com/PolkadotDom) on 2026-10-30T19:49:13Z. --- ### What An indirect `call` or `jmp` through FS/GS-relative RIP/EIP memory was resolved using the relocation at the unbased effective address. The segment base is unknown to this analysis, so that relocation can belong to unrelated data. Following its value could add unrelated code to the graph or fail decoding bytes that the transfer never targets. Keep these transfers unresolved, as other indirect transfers are. Calls still fall through, jumps still end the block, and explicit roots remain reachable. Flat RIP/EIP transfers and ignored CS/DS/ES/SS overrides retain relocation resolution. FS/GS-prefixed LEA still discovers code addresses because LEA does not apply the segment base. Addressing basis: [Linux x86 architecture documentation](https://kernel.org/doc/html/latest/arch/x86/x86_64/fsgs.html), consistent with the existing call-site resolver's FS/GS exclusion. This does not infer an FS/GS base or implement runtime indirect-target discovery. The overlap checker reports an uncomparable shared file with #10861 because that branch conflicts with current main. Manually compared its `ControlFlowGraph.cpp` diff: it adds `followPadding` handling and changes the graph API/fall-through policy; it does not change either relocation lookup guarded here. No shared changed lines or dependency was found. Both this branch and the annotation fix are independent. ### Tested Windows x64, Python 3.12.3, GCC 12.2.0, Ninja, Release relinker-only configuration with `BUILD_TESTING=ON`, based on main `3713032179`. - New regression fails on the original production code with `Segment-relative transfer followed a flat relocation slot`; it passes with the fix. Final coverage is 28 transfer combinations (seven segment-prefix choices, RIP/EIP, call/jump), FS/GS unrelated undecodable targets and explicit-root controls, plus FS/GS-prefixed LEA controls. - Full relinker-only build succeeds. Six focused CTests pass: `control_flow_graph`, `strict_nid_filter`, `relinker_conversion`, `call_site_index`, `call_registry`, and `guest_registry`. - Full suite: 536/537 pass. `select_tests_NonAsciiDirectoryTests` fails when dumping a build graph under a Unicode directory on this Windows toolchain. Reproduced separately using unchanged `select_tests.py` and its test from main; neither is touched here. The same failure was present in the preceding contribution round. - Conventions and `git diff --check` pass. Merge preview onto the overlap checker's current-main snapshot is clean. Overlap warning manually reviewed as described above. Synthetic analysis/conversion fixtures only; no console binary, title execution, GPU validation, or local Linux/macOS run. No title is claimed unblocked. <!-- 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. --> ### 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: none <!-- #PR, or none --> - [x] Fixes: none <!-- issue it closes as Fixes #N, or none --> - [x] Unblocks: none <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> - [x] GPUs tested: n/a <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> - [x] AI-assisted: yes <!-- yes / no -->
blawesom commented 2026-10-30 20:24:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-30T20:24:38Z.

Review: APPROVED


Verified 06340c048 on Linux x86-64 (Ryzen 7 9800X3D, CachyOS kernel 6.2.10, GCC 16.2.1, Release, BUILD_TESTING=ON, Ninja; shared build dir, focused targets only).

  • Built control_flow_graph_tests on the PR head; control_flow_graph passes 5/5 consecutive runs (no flakiness).
  • Broader relinker family on the PR head all pass: relinker_conversion, relinker_game_patch, call_site_index, call_site_resolver, relinker_executables, guest_registry, call_registry, strict_nid_filter (9/9 including control_flow_graph).
  • Regression confirmed: rebuilt the test against base 3713032179 with only the ControlFlowGraph.cpp fix reverted (new tests kept) in a scratch build dir — it fails with Segment-relative transfer followed a flat relocation slot, and passes with the fix.
  • Code read: the two-line change skips relativeRelocations.TargetOfSlot when info.SegmentPrefix != 0 for RIP/EIP-relative indirect jmp/call (both UnconditionalJump and Call arms). This matches x86-64 semantics — FS/GS bases are unknown to this analysis, and CS/DS/ES/SS prefixes are null in 64-bit mode — and is consistent with the existing FS/GS exclusion pattern in WindowsTlsBuilder.cpp (SegmentPrefix == 0x65 handling). No other call sites of TargetOfSlot are affected.
  • Tests read: 28 transfer combinations (7 segment prefixes × RIP/EIP × call/jump) verify flat/ignored-prefix cases keep relocation resolution while FS/GS stay unresolved; FS/GS-prefixed cases also verify undecodable unrelated targets are not followed and explicit roots survive. CheckCodeAddresses extends the FS/GS LEA address-discovery coverage. Segment-relative transfers staying unresolved (like other indirect transfers) matches the reported failure shape.

Scope: relinker-only change, no GPU validation applicable (AGC protocol N/A). Not run: full test suite, Windows/console. PR body checklist is complete and consistent with the diff; the #10861 overlap claim (no shared changed lines) matches what I see in the diff.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5718238843 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/13620#pullrequestreview-5718238843). Originally posted by [blawesom](https://github.com/blawesom) on 2026-10-30T20:24:38Z. **Review:** APPROVED --- Verified 06340c048 on Linux x86-64 (Ryzen 7 9800X3D, CachyOS kernel 6.2.10, GCC 16.2.1, Release, BUILD_TESTING=ON, Ninja; shared build dir, focused targets only). - Built `control_flow_graph_tests` on the PR head; `control_flow_graph` passes 5/5 consecutive runs (no flakiness). - Broader relinker family on the PR head all pass: `relinker_conversion`, `relinker_game_patch`, `call_site_index`, `call_site_resolver`, `relinker_executables`, `guest_registry`, `call_registry`, `strict_nid_filter` (9/9 including `control_flow_graph`). - Regression confirmed: rebuilt the test against base 3713032179 with only the `ControlFlowGraph.cpp` fix reverted (new tests kept) in a scratch build dir — it fails with `Segment-relative transfer followed a flat relocation slot`, and passes with the fix. - Code read: the two-line change skips `relativeRelocations.TargetOfSlot` when `info.SegmentPrefix != 0` for RIP/EIP-relative indirect `jmp`/`call` (both `UnconditionalJump` and `Call` arms). This matches x86-64 semantics — FS/GS bases are unknown to this analysis, and CS/DS/ES/SS prefixes are null in 64-bit mode — and is consistent with the existing FS/GS exclusion pattern in `WindowsTlsBuilder.cpp` (`SegmentPrefix == 0x65` handling). No other call sites of `TargetOfSlot` are affected. - Tests read: 28 transfer combinations (7 segment prefixes × RIP/EIP × call/jump) verify flat/ignored-prefix cases keep relocation resolution while FS/GS stay unresolved; FS/GS-prefixed cases also verify undecodable unrelated targets are not followed and explicit roots survive. `CheckCodeAddresses` extends the FS/GS LEA address-discovery coverage. Segment-relative transfers staying unresolved (like other indirect transfers) matches the reported failure shape. Scope: relinker-only change, no GPU validation applicable (AGC protocol N/A). Not run: full test suite, Windows/console. PR body checklist is complete and consistent with the diff; the #10861 overlap claim (no shared changed lines) matches what I see in the diff.
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!13620
No description provided.