fix(relinker): reject link-time relocation types in executables #9220

Merged
roboterspinne merged 2 commits from upstream-pr/9220 into main 2026-10-23 18:27:45 +00:00
roboterspinne commented 2026-10-21 15:29:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by roboterspinne on 2026-10-21T15:29:54Z.


What

ValidationPolicy accepted the link-time relocation types R_X86_64_GOT32 (3), PLT32 (4), GOTPCREL (9), 32S (11), GOTPCRELX (41) and REX_GOTPCRELX (42) in an executable's DT_RELA. The linker resolves these types, and glibc's ld.so does not apply them: elf_machine_rela in sysdeps/x86_64/dl-machine.h has no case for them and its default branch fails with unexpected reloc type. FreeBSD's rtld-elf/amd64/reloc.c and musl's ldso/dynlink.c reject them as well. The --lazy-binding Linux output copied them into its dynamic relocation table, so the relink succeeded and ld.so refused the program at load; the fixed-base output, the default since #8973, did the same for 32S. They are now rejected when the executable is validated, for every target, with Unsupported relocation type 0x.., as TPOFF32 already is.

  • No input that works today is affected: Windows, macOS and guest modules already rejected all six, --linux-fixed-base all but 32S, and in DT_JMPREL they already fail the PLT slot check. Windows and macOS now report the shared message instead of Unsupported Windows relocation type.
  • The allowlist dates from the initial commit (657ada06b); no commit, test or debt entry relies on these entries. PC32 and 32 stay: glibc applies them and the fixed-base whitelist accepts them.
  • Since #8973 the default Linux output goes through the fixed-base whitelist, which already rejects five of these types; this change covers --lazy-binding and 32S.
  • The unsupported-type case of test_linux_fixed_base.py now uses 32S, the one type --linux-fixed-base accepted, and expects the validation error. No relocation type reaches the fixed-base rejection from the command line any more; that rejection, its R_X86_64_32S case and the now unused constants stay, to keep this pull request to one topic.

Tested

Ubuntu 24.04 x86_64, glibc 2.39, relinker-only Release build (-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON); synthetic fixtures only, no title or homebrew.

  • ctest --test-dir build-relinker -j4: 238/238 passed.
  • Without the ValidationPolicy.cpp change, the new executable_tls_relocations cases fail (Linux and --lazy-binding relink with exit 0, Windows and macOS exit 2 with the old Unsupported Windows relocation type message), and linux_fixed_base fails because the 32S fixture relinks.
  • On main before #8973 (cecb540a63), the default Linux output of the test fixture with one of these types against the null symbol relinks and then fails in ld.so with error while loading shared libraries: unexpected reloc type 0x03 (0x04, 0x09, 0x0b, 0x29, 0x2a), exit 127; type 11 does the same with --linux-fixed-base 0x400000. With this change each of them exits 2 at relink with Unsupported relocation type 0x.. and leaves no output.
  • Merged with current main (4777caca3, includes #8973): no conflicts, ctest 239/239 passed.
  • python3 tools/check_conventions.py --base upstream/main with this title and description passed.

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:4954110471 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9220). Originally posted by [roboterspinne](https://github.com/roboterspinne) on 2026-10-21T15:29:54Z. --- ### What `ValidationPolicy` accepted the link-time relocation types `R_X86_64_GOT32` (3), `PLT32` (4), `GOTPCREL` (9), `32S` (11), `GOTPCRELX` (41) and `REX_GOTPCRELX` (42) in an executable's `DT_RELA`. The linker resolves these types, and glibc's ld.so does not apply them: `elf_machine_rela` in `sysdeps/x86_64/dl-machine.h` has no case for them and its default branch fails with `unexpected reloc type`. FreeBSD's `rtld-elf/amd64/reloc.c` and musl's `ldso/dynlink.c` reject them as well. The `--lazy-binding` Linux output copied them into its dynamic relocation table, so the relink succeeded and ld.so refused the program at load; the fixed-base output, the default since #8973, did the same for 32S. They are now rejected when the executable is validated, for every target, with `Unsupported relocation type 0x..`, as `TPOFF32` already is. - No input that works today is affected: Windows, macOS and guest modules already rejected all six, `--linux-fixed-base` all but 32S, and in `DT_JMPREL` they already fail the PLT slot check. Windows and macOS now report the shared message instead of `Unsupported Windows relocation type`. - The allowlist dates from the initial commit (657ada06b); no commit, test or debt entry relies on these entries. `PC32` and `32` stay: glibc applies them and the fixed-base whitelist accepts them. - Since #8973 the default Linux output goes through the fixed-base whitelist, which already rejects five of these types; this change covers `--lazy-binding` and 32S. - The `unsupported-type` case of `test_linux_fixed_base.py` now uses 32S, the one type `--linux-fixed-base` accepted, and expects the validation error. No relocation type reaches the fixed-base rejection from the command line any more; that rejection, its `R_X86_64_32S` case and the now unused constants stay, to keep this pull request to one topic. ### 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. --> Ubuntu 24.04 x86_64, glibc 2.39, relinker-only Release build (`-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON`); synthetic fixtures only, no title or homebrew. - `ctest --test-dir build-relinker -j4`: 238/238 passed. - Without the `ValidationPolicy.cpp` change, the new `executable_tls_relocations` cases fail (Linux and `--lazy-binding` relink with exit 0, Windows and macOS exit 2 with the old `Unsupported Windows relocation type` message), and `linux_fixed_base` fails because the 32S fixture relinks. - On `main` before #8973 (cecb540a63), the default Linux output of the test fixture with one of these types against the null symbol relinks and then fails in ld.so with `error while loading shared libraries: unexpected reloc type 0x03` (`0x04`, `0x09`, `0x0b`, `0x29`, `0x2a`), exit 127; type 11 does the same with `--linux-fixed-base 0x400000`. With this change each of them exits 2 at relink with `Unsupported relocation type 0x..` and leaves no output. - Merged with current `main` (4777caca3, includes #8973): no conflicts, `ctest` 239/239 passed. - `python3 tools/check_conventions.py --base upstream/main` with this title and description passed. ### 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)
jotitadev commented 2026-10-21 22:07:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-21T22:07:32Z.

Review: COMMENTED


Confirmed on macOS Apple Silicon, arm64 and x86-64 under Rosetta (your PR lists no run).

  • Machine: Apple M2 Max, macOS 27.2, AppleClang, relinker-only Release. Head e839b2479 on current main a6dcea9279 (merged clean).
  • Full relinker-only CTest: arm64 229/229; x86-64 under Rosetta (-DCMAKE_OSX_ARCHITECTURES=x86_64 -DPython3_EXECUTABLE=/usr/bin/python3, Python 3.9.6) 229/229.

Red/green on the new coverage: with _initializeSupportedRelocationTypes reverted to main so the link-time types stay accepted (tests kept), executable_tls_relocations and linux_fixed_base fail — the relink accepts e.g. R_X86_64_32S (0xb) into the dynamic relocation table instead of rejecting it. With the fix, GOT32/PLT32/GOTPCREL/32S/GOTPCRELX/REX_GOTPCRELX are rejected for every target with Unsupported relocation type 0x.., matching glibc/FreeBSD/musl ld.so, which never apply them.

Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5606834524 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9220#pullrequestreview-5606834524). Originally posted by [jotitadev](https://github.com/jotitadev) on 2026-10-21T22:07:32Z. **Review:** COMMENTED --- Confirmed on macOS Apple Silicon, arm64 and x86-64 under Rosetta (your PR lists no run). - Machine: Apple M2 Max, macOS 27.2, AppleClang, relinker-only Release. Head e839b2479 on current `main` a6dcea9279 (merged clean). - Full relinker-only CTest: arm64 **229/229**; x86-64 under Rosetta (`-DCMAKE_OSX_ARCHITECTURES=x86_64 -DPython3_EXECUTABLE=/usr/bin/python3`, Python 3.9.6) **229/229**. Red/green on the new coverage: with `_initializeSupportedRelocationTypes` reverted to `main` so the link-time types stay accepted (tests kept), `executable_tls_relocations` and `linux_fixed_base` fail — the relink accepts e.g. `R_X86_64_32S` (0xb) into the dynamic relocation table instead of rejecting it. With the fix, GOT32/PLT32/GOTPCREL/32S/GOTPCRELX/REX_GOTPCRELX are rejected for every target with `Unsupported relocation type 0x..`, matching glibc/FreeBSD/musl ld.so, which never apply them. Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
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!9220
No description provided.