fix(relinker): name R_X86_64_PC32 in the import registry #10679

Merged
roboterspinne merged 1 commit from upstream-pr/10679 into main 2026-10-27 16:56:00 +00:00
roboterspinne commented 2026-10-24 17:11:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by roboterspinne on 2026-10-24T17:11:59Z.


What

relocationTypeName named R_X86_64_64, GLOB_DAT, JUMP_SLOT, R_X86_64_32 and the three TLS types, but not R_X86_64_PC32 (type 2), which ValidationPolicy accepts and extractRela adds to the imports like R_X86_64_64, so a PC32 import relinked for Linux with exit 0 and appeared in the registry as UNKNOWN(2). The name is used only for the relocationType field of the executable's --registry JSON (CallRegistryWriter); bundled-module registries leave it empty. R_X86_64_COPY (type 5) prints UNKNOWN(5) the same way on main; #10658 rejects it in validation, so it gets no name here.

  • Fix. case 2 returns R_X86_64_PC32, the psABI name of type 2 and of Elfpatcher::R_X86_64_PC32. Apart from COPY, every type that can reach a registry entry was named: NONE and RELATIVE are skipped in extractRela, TLS relocations against no symbol or a defined STT_TLS symbol are not imports, IRELATIVE fails validation, and Windows and macOS reject PC32, COPY, R_X86_64_32 and imported TLS in WindowsRelocationBuilder before the registry is written.
  • Tests. test_call_registry.py sets the info word of the fixture's only DT_RELA entry (0x708) to symbol 1 with types 1, 2, 6, 10 and the TLS types 16 to 18 (seven relinks) and asserts the single registry entry's relocationType. Linux output only: Windows and macOS stop at Unsupported Windows relocation type 2 and 10 before a registry exists. JUMP_SLOT (7) cannot be expressed in this DT_RELA entry (JUMP_SLOT relocation is not aligned to the original .rela.plt entry size; the fixture has no DT_JMPREL) and its name is already asserted by test_optional_rela.py.
  • Overlap. pr_overlap.py cannot compare this branch with #8076 and reports no other shared lines. Checked by hand: the RelinkerPipeline.cpp hunk of #8076 starts at line 374, this one at 42. No open PR touches test_call_registry.py; #10658 shares no file with this PR.

Tested

Windows 11, GCC 15.2.0 (WinLibs UCRT), relinker-only Release build (-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON); synthetic fixtures only, no title or homebrew, relinked outputs not run.

  • The new test against a main build (e4bb5fc125) passes type 1 and fails at type 2 with AssertionError: (2, 'R_X86_64_PC32', [{... 'relocationType': 'UNKNOWN(2)', ...}]).
  • call_registry, call_registry_writer, guest_registry and unused_filter_indirect pass with this change; call_registry takes about 3 s on main and with it.
  • ctest --test-dir build-relinker: 244 tests, 242 passed; the two failures are known on this machine and unrelated to this change: select_tests (Windows symlink fixture) and patch_advisor_unit (build path with spaces, fixed by #10667).
  • python tools/check_conventions.py --base upstream/main with this title and description passed.
  • Not tested on Linux or macOS; CI runs the test on all three hosts.

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 (Claude Code)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4997432318 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10679). Originally posted by [roboterspinne](https://github.com/roboterspinne) on 2026-10-24T17:11:59Z. --- ### What `relocationTypeName` named `R_X86_64_64`, `GLOB_DAT`, `JUMP_SLOT`, `R_X86_64_32` and the three TLS types, but not `R_X86_64_PC32` (type 2), which `ValidationPolicy` accepts and `extractRela` adds to the imports like `R_X86_64_64`, so a PC32 import relinked for Linux with exit 0 and appeared in the registry as `UNKNOWN(2)`. The name is used only for the `relocationType` field of the executable's `--registry` JSON (`CallRegistryWriter`); bundled-module registries leave it empty. `R_X86_64_COPY` (type 5) prints `UNKNOWN(5)` the same way on `main`; #10658 rejects it in validation, so it gets no name here. - **Fix.** `case 2` returns `R_X86_64_PC32`, the psABI name of type 2 and of `Elfpatcher::R_X86_64_PC32`. Apart from `COPY`, every type that can reach a registry entry was named: `NONE` and `RELATIVE` are skipped in `extractRela`, TLS relocations against no symbol or a defined `STT_TLS` symbol are not imports, `IRELATIVE` fails validation, and Windows and macOS reject `PC32`, `COPY`, `R_X86_64_32` and imported TLS in `WindowsRelocationBuilder` before the registry is written. - **Tests.** `test_call_registry.py` sets the info word of the fixture's only `DT_RELA` entry (0x708) to symbol 1 with types 1, 2, 6, 10 and the TLS types 16 to 18 (seven relinks) and asserts the single registry entry's `relocationType`. Linux output only: Windows and macOS stop at `Unsupported Windows relocation type 2` and `10` before a registry exists. `JUMP_SLOT` (7) cannot be expressed in this `DT_RELA` entry (`JUMP_SLOT relocation is not aligned to the original .rela.plt entry size`; the fixture has no `DT_JMPREL`) and its name is already asserted by `test_optional_rela.py`. - **Overlap.** `pr_overlap.py` cannot compare this branch with #8076 and reports no other shared lines. Checked by hand: the `RelinkerPipeline.cpp` hunk of #8076 starts at line 374, this one at 42. No open PR touches `test_call_registry.py`; #10658 shares no file with this PR. ### 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 11, GCC 15.2.0 (WinLibs UCRT), relinker-only Release build (`-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON`); synthetic fixtures only, no title or homebrew, relinked outputs not run. - The new test against a `main` build (e4bb5fc125) passes type 1 and fails at type 2 with `AssertionError: (2, 'R_X86_64_PC32', [{... 'relocationType': 'UNKNOWN(2)', ...}])`. - `call_registry`, `call_registry_writer`, `guest_registry` and `unused_filter_indirect` pass with this change; `call_registry` takes about 3 s on `main` and with it. - `ctest --test-dir build-relinker`: 244 tests, 242 passed; the two failures are known on this machine and unrelated to this change: `select_tests` (Windows symlink fixture) and `patch_advisor_unit` (build path with spaces, fixed by #10667). - `python tools/check_conventions.py --base upstream/main` with this title and description passed. - Not tested on Linux or macOS; CI runs the test on all three hosts. ### 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 (Claude Code)
MarcZX10 commented 2026-10-24 17:15:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T17:15:59Z.

Review: COMMENTED


I reviewed head d63c9533a7cc6370ad6c4d9c87688429a650676b. The new R_X86_64_PC32 label matches the accepted relocation type, and the test exercises the registry output for the supported imported relocation types. Independently, I configured a relinker-only Release build with GCC 12.2, built target relinker, and ran ctest -R '^call_registry$': 1/1 passed. git diff --check, conventions, and merge-tree with current main also pass. Ubuntu relinker and ASan checks are green; Windows and macOS relinker jobs are still pending, so this is a progress report rather than an approval. Product jobs are skipped by path policy.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5639109699 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10679#pullrequestreview-5639109699). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-24T17:15:59Z. **Review:** COMMENTED --- I reviewed head `d63c9533a7cc6370ad6c4d9c87688429a650676b`. The new `R_X86_64_PC32` label matches the accepted relocation type, and the test exercises the registry output for the supported imported relocation types. Independently, I configured a relinker-only Release build with GCC 12.2, built target `relinker`, and ran `ctest -R '^call_registry$'`: 1/1 passed. `git diff --check`, conventions, and merge-tree with current `main` also pass. Ubuntu relinker and ASan checks are green; Windows and macOS relinker jobs are still pending, so this is a progress report rather than an approval. Product jobs are skipped by path policy.
MarcZX10 commented 2026-10-24 17:21:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T17:21:14Z.

Review: APPROVED


Reviewed exact head d63c9533a7cc6370ad6c4d9c87688429a650676b. The new registry name is consistent with the accepted R_X86_64_PC32 import type; the test checks the JSON field for the supported relocation cases.

Independent validation: relinker-only Release build with GCC 12.2 and ctest -R '^call_registry$' pass on this head. I also ran the PR's updated test script against a relinker built from current main: it fails at type 2 with UNKNOWN(2) as expected; the same script passes against the PR build. Diff-check, conventions and merge-tree with current main pass. Hosted Ubuntu, Windows, macOS ARM64, macOS x86_64 and ASan relinker jobs are green; product jobs are skipped by path policy.

The overlap report could not compare #8076 because that head conflicts with current main; I manually confirmed its Relink() change around line 373 is separate from this relocationTypeName case near line 42. I found no remaining blocker.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5639124830 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10679#pullrequestreview-5639124830). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-24T17:21:14Z. **Review:** APPROVED --- Reviewed exact head `d63c9533a7cc6370ad6c4d9c87688429a650676b`. The new registry name is consistent with the accepted `R_X86_64_PC32` import type; the test checks the JSON field for the supported relocation cases. Independent validation: relinker-only Release build with GCC 12.2 and `ctest -R '^call_registry$'` pass on this head. I also ran the PR's updated test script against a relinker built from current `main`: it fails at type 2 with `UNKNOWN(2)` as expected; the same script passes against the PR build. Diff-check, conventions and merge-tree with current `main` pass. Hosted Ubuntu, Windows, macOS ARM64, macOS x86_64 and ASan relinker jobs are green; product jobs are skipped by path policy. The overlap report could not compare #8076 because that head conflicts with current `main`; I manually confirmed its `Relink()` change around line 373 is separate from this `relocationTypeName` case near line 42. I found no remaining blocker.
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!10679
No description provided.