fix(relinker): reject R_X86_64_COPY relocations #10658

Merged
roboterspinne merged 1 commit from upstream-pr/10658 into main 2026-10-25 08:50:13 +00:00
roboterspinne commented 2026-10-24 15:31:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by roboterspinne on 2026-10-24T15:31:07Z.


What

ValidationPolicy accepted R_X86_64_COPY (type 5) and the Linux outputs kept it: SysVDynamicSectionBuilder writes every import symbol with st_size 0 and copies the relocation type into the output RELA, so glibc's elf_machine_rela runs memcpy(reloc_addr, value, MIN(sym->st_size, refsym->st_size)) with a reference size of 0 (sysdeps/x86_64/dl-machine.h, case R_X86_64_COPY), copies nothing and at most warns about the size difference; the variable stays zero. Windows and macOS already rejected the type in the relocation builder (Unsupported Windows relocation type 5, WindowsRelocationBuilder.cpp), the default and --lazy-binding Linux outputs relinked with exit 0.

  • Rule. Type 5 is no longer in the supported set, so extractRela throws Unsupported relocation type 0x5 for every output before any target code runs, and the case R_X86_64_COPY in the fixed-base rebasing of LinuxElfPatcher.cpp, which validation makes unreachable, is gone. The relinker cannot emit the definition's size, which only the library knows, so rejecting is the fail-fast answer. No title is known to use COPY: PS5 executables are position independent and reach shared data through the GOT, while COPY relocations arise in non-PIC executables that reference a shared library's data directly.
  • Tests. New test_copy_relocations.py on the fixture of test_jmprel_table_bounds.py: a COPY in DT_RELA and one in the PLT table are rejected on the default and --lazy-binding Linux, Windows and macOS outputs with the identical FAIL line, and the GLOB_DAT and JUMP_SLOT controls stay accepted. The test asserts the type part of the message only, so it holds with #10390, which drops the offset the CLI already prints.
  • Relation to #10402. Both PRs are mine. #10402 derived a width for COPY relocations from the symbol size and had three copy-* cases; its commit 9bf8860f87 drops that width and those cases, so COPY takes the 8-byte default there until this PR rejects it in validation. The merged state rejects COPY consistently in either merge order, the two branches share no lines, and neither depends on the other.
  • Overlap. pr_overlap.py cannot compare this branch with #5021 and #7173 (core/relinker/CMakeLists.txt), because those do not merge with main, and reports no other shared lines. Checked by hand: their CMakeLists.txt hunks start at lines 52 to 390 and 505, this PR adds two lines after 766. The test is registered after jmprel_table_bounds, whose fixture it uses, rather than after linux_fixed_base, where #7532 inserts its own test.

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.

  • ctest --test-dir build-relinker -j 6: 242 tests, 240 passed, long_paths skipped; select_tests fails on this machine on main as well (FileExistsError in tools/tests/test_select_tests.py, a Windows symlink problem unrelated to this change).
  • copy_relocations against a main build (d098eca3d6): the COPY in DT_RELA relinks with exit 0 and an output file on the default and --lazy-binding Linux outputs and fails on Windows and macOS with Unsupported Windows relocation type 5; the COPY in the PLT table already failed on every output with Unsupported PLT relocation type; both controls pass. With this change all 16 runs behave as asserted, in 0.8 s.
  • The Linux behaviour behind the check comes from an earlier run of the assistant on a Linux host, not reproduced here: against a library defining the variable as 42, a relinked fixture with a COPY relocation read 0; with st_size 8 on the import symbol the value was copied.
  • python tools/check_conventions.py --base upstream/main with this title and description passed.
  • Not tested on Linux or macOS; the changed code is host-independent and 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:4996696430 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10658). Originally posted by [roboterspinne](https://github.com/roboterspinne) on 2026-10-24T15:31:07Z. --- ### What `ValidationPolicy` accepted `R_X86_64_COPY` (type 5) and the Linux outputs kept it: `SysVDynamicSectionBuilder` writes every import symbol with `st_size` 0 and copies the relocation type into the output `RELA`, so glibc's `elf_machine_rela` runs `memcpy(reloc_addr, value, MIN(sym->st_size, refsym->st_size))` with a reference size of 0 (`sysdeps/x86_64/dl-machine.h`, case `R_X86_64_COPY`), copies nothing and at most warns about the size difference; the variable stays zero. Windows and macOS already rejected the type in the relocation builder (`Unsupported Windows relocation type 5`, `WindowsRelocationBuilder.cpp`), the default and `--lazy-binding` Linux outputs relinked with exit 0. - **Rule.** Type 5 is no longer in the supported set, so `extractRela` throws `Unsupported relocation type 0x5` for every output before any target code runs, and the `case R_X86_64_COPY` in the fixed-base rebasing of `LinuxElfPatcher.cpp`, which validation makes unreachable, is gone. The relinker cannot emit the definition's size, which only the library knows, so rejecting is the fail-fast answer. No title is known to use `COPY`: PS5 executables are position independent and reach shared data through the GOT, while `COPY` relocations arise in non-PIC executables that reference a shared library's data directly. - **Tests.** New `test_copy_relocations.py` on the fixture of `test_jmprel_table_bounds.py`: a `COPY` in `DT_RELA` and one in the PLT table are rejected on the default and `--lazy-binding` Linux, Windows and macOS outputs with the identical `FAIL` line, and the `GLOB_DAT` and `JUMP_SLOT` controls stay accepted. The test asserts the type part of the message only, so it holds with #10390, which drops the offset the CLI already prints. - **Relation to #10402.** Both PRs are mine. #10402 derived a width for `COPY` relocations from the symbol size and had three `copy-*` cases; its commit 9bf8860f87 drops that width and those cases, so `COPY` takes the 8-byte default there until this PR rejects it in validation. The merged state rejects `COPY` consistently in either merge order, the two branches share no lines, and neither depends on the other. - **Overlap.** `pr_overlap.py` cannot compare this branch with #5021 and #7173 (`core/relinker/CMakeLists.txt`), because those do not merge with `main`, and reports no other shared lines. Checked by hand: their `CMakeLists.txt` hunks start at lines 52 to 390 and 505, this PR adds two lines after 766. The test is registered after `jmprel_table_bounds`, whose fixture it uses, rather than after `linux_fixed_base`, where #7532 inserts its own test. ### 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. - `ctest --test-dir build-relinker -j 6`: 242 tests, 240 passed, `long_paths` skipped; `select_tests` fails on this machine on `main` as well (`FileExistsError` in `tools/tests/test_select_tests.py`, a Windows symlink problem unrelated to this change). - `copy_relocations` against a `main` build (d098eca3d6): the `COPY` in `DT_RELA` relinks with exit 0 and an output file on the default and `--lazy-binding` Linux outputs and fails on Windows and macOS with `Unsupported Windows relocation type 5`; the `COPY` in the PLT table already failed on every output with `Unsupported PLT relocation type`; both controls pass. With this change all 16 runs behave as asserted, in 0.8 s. - The Linux behaviour behind the check comes from an earlier run of the assistant on a Linux host, not reproduced here: against a library defining the variable as 42, a relinked fixture with a `COPY` relocation read 0; with `st_size` 8 on the import symbol the value was copied. - `python tools/check_conventions.py --base upstream/main` with this title and description passed. - Not tested on Linux or macOS; the changed code is host-independent and 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 15:39:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T15:39:24Z.

Review: CHANGES_REQUESTED


The implementation and regression coverage look sound: removing R_X86_64_COPY from ValidationPolicy makes validation fail before either output is emitted, and removing the now-unreachable Linux fixed-base case keeps behavior consistent. The test exercises COPY in both DT_RELA and JMPREL across all output targets, with GLOB_DAT/JUMP_SLOT controls. git diff --check and the merge-tree check pass. Hosted conventions, eligibility, intake, labels, all four relinker platform jobs, and ASan pass; product jobs are skipped by policy. I did not independently run the tests locally.

Please coordinate the behavior with open #10402 before merging. That PR explicitly derives a width for and accepts COPY relocations; this PR rejects them because emitted import symbols have size zero and the dynamic loader would copy no data. The body recognizes that one branch must adapt, but the checklist still says Depends on: none and does not record an agreed order or which branch will be changed. Please agree on the integration order with #10402’s author and record the dependency/plan so the final merged state rejects or correctly supports COPY consistently, including updating #10402’s acceptance tests if rejection is the chosen behavior.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5638815301 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10658#pullrequestreview-5638815301). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-24T15:39:24Z. **Review:** CHANGES_REQUESTED --- The implementation and regression coverage look sound: removing `R_X86_64_COPY` from `ValidationPolicy` makes validation fail before either output is emitted, and removing the now-unreachable Linux fixed-base case keeps behavior consistent. The test exercises COPY in both DT_RELA and JMPREL across all output targets, with GLOB_DAT/JUMP_SLOT controls. `git diff --check` and the merge-tree check pass. Hosted conventions, eligibility, intake, labels, all four relinker platform jobs, and ASan pass; product jobs are skipped by policy. I did not independently run the tests locally. Please coordinate the behavior with open #10402 before merging. That PR explicitly derives a width for and accepts COPY relocations; this PR rejects them because emitted import symbols have size zero and the dynamic loader would copy no data. The body recognizes that one branch must adapt, but the checklist still says `Depends on: none` and does not record an agreed order or which branch will be changed. Please agree on the integration order with #10402’s author and record the dependency/plan so the final merged state rejects or correctly supports COPY consistently, including updating #10402’s acceptance tests if rejection is the chosen behavior.
harisibrar1 commented 2026-10-24 15:43:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-24T15:43:22Z.

Review: APPROVED


Checked against main c9b75825f3 and the relinker sources (RelinkerPipeline.cpp, ValidationPolicy.cpp, LinuxElfPatcher.cpp, WindowsRelocationBuilder.cpp, MacOsMachOPatcher.cpp, GuestImageReader.cpp):

  • extractRela validates the type (RelinkerPipeline.cpp:349) for both DT_RELA and DT_JMPREL before the PLT check and before any target writer. With type 5 gone from the set, every output, including --lazy-binding, stops with the same Unsupported relocation type 0x5, which is what the new test asserts.
  • Removing case R_X86_64_COPY from RebasedRelocations looks safe: those tables only carry validated types, and the default branch would still throw.
  • Guest modules already reject type 5 (GuestImageReader.cpp:243), so the executable and the modules now agree.
  • No existing test depends on COPY being accepted, and the branch still merges cleanly with current main after da511cb29c landed next to the LinuxElfPatcher hunk. Looks good to me.

Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5638826630 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10658#pullrequestreview-5638826630). Originally posted by [harisibrar1](https://github.com/harisibrar1) on 2026-10-24T15:43:22Z. **Review:** APPROVED --- Checked against main c9b75825f3 and the relinker sources (RelinkerPipeline.cpp, ValidationPolicy.cpp, LinuxElfPatcher.cpp, WindowsRelocationBuilder.cpp, MacOsMachOPatcher.cpp, GuestImageReader.cpp): - `extractRela` validates the type (RelinkerPipeline.cpp:349) for both DT_RELA and DT_JMPREL before the PLT check and before any target writer. With type 5 gone from the set, every output, including `--lazy-binding`, stops with the same `Unsupported relocation type 0x5`, which is what the new test asserts. - Removing `case R_X86_64_COPY` from `RebasedRelocations` looks safe: those tables only carry validated types, and the default branch would still throw. - Guest modules already reject type 5 (GuestImageReader.cpp:243), so the executable and the modules now agree. - No existing test depends on COPY being accepted, and the branch still merges cleanly with current main after da511cb29c landed next to the LinuxElfPatcher hunk. Looks good to me. Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.
MarcZX10 commented 2026-10-24 16:06:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T16:06:32Z.

Review: APPROVED


Re-reviewed exact head 7f58c7a407aed7cb626f90f3212bc392f141f7d7. The earlier integration concern with #10402 is addressed: that PR now removes its COPY support cases, and its current body records that #10658 rejects COPY after validation; the other reviewer also verified the behavior/order. I built the relinker-only Release target with GCC 12.2.0 and ran ctest -R copy_relocations (1/1 passed), ran tools/check_conventions.py --base upstream/main (pass), and confirmed git diff --check plus a clean merge tree with current upstream/main. Hosted Linux/Windows/macOS relinker matrices and ASan are green; product jobs were skipped by policy. I did not run the full relinker suite.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5638892697 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10658#pullrequestreview-5638892697). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-24T16:06:32Z. **Review:** APPROVED --- Re-reviewed exact head `7f58c7a407aed7cb626f90f3212bc392f141f7d7`. The earlier integration concern with #10402 is addressed: that PR now removes its COPY support cases, and its current body records that #10658 rejects COPY after validation; the other reviewer also verified the behavior/order. I built the relinker-only Release target with GCC 12.2.0 and ran `ctest -R copy_relocations` (1/1 passed), ran `tools/check_conventions.py --base upstream/main` (pass), and confirmed `git diff --check` plus a clean merge tree with current `upstream/main`. Hosted Linux/Windows/macOS relinker matrices and ASan are green; product jobs were skipped by policy. I did not run the full relinker suite.
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!10658
No description provided.