fix(relinker): read guest TLS relocations against the module's own section symbol #9429

Merged
Get-fix merged 1 commit from upstream-pr/9429 into main 2026-10-22 04:32:05 +00:00
Get-fix commented 2026-10-21 21:50:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Get-fix on 2026-10-21T21:50:59Z.


What

Split out of #6977 as asked there; part of the PS4 Limbo work tracked in #6978.

The bundled libSceFios2.prx of Limbo (CUSA01664) and of Bloodborne (CUSA00900) has DTPMOD64 relocations against a local section symbol with section index 0 and value 0, and the modules carry no section headers (e_shnum 0). As for a TLS relocation without a symbol, the module and offset are the module's own TLS block, so GuestImageReader passes a DTPMOD64 or DTPOFF64 against such a symbol on without the symbol.

The accepted form is narrow: a local STT_SECTION symbol with section index 0 and value 0, in a module with PT_TLS. A section symbol that names a section (there is no section table in these modules to show that section is TLS) or has a value, a TPOFF64, a module without PT_TLS and a DTPMOD64 with an addend still fail with Invalid guest TLS relocation.

Tested

Windows 11, WinLibs GCC 15.2, relinker on main cecb540a6:

  • New test guest_own_tls_relocations: DTPMOD64 and DTPOFF64 against the own section symbol convert for Linux, Windows and macOS output (the Linux output keeps the relocation without the symbol), for plain and SCE modules; the refused forms above fail. With main's GuestImageReader.cpp the test fails with Invalid guest TLS relocation.
  • All 163 relinker tests pass.
  • Limbo converts with both bundled modules and Bloodborne with all 7, for Linux and --windows; on main alone both stop in libSceFios2.prx with Invalid guest TLS relocation.

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: Limbo (CUSA01664) #6978, Bloodborne (CUSA00900)
  • GPUs tested: n/a
  • AI-assisted: yes (Claude Code)

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4958851441 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9429). Originally posted by [Get-fix](https://github.com/Get-fix) on 2026-10-21T21:50:59Z. --- ### What Split out of #6977 as asked there; part of the PS4 Limbo work tracked in #6978. The bundled `libSceFios2.prx` of Limbo (CUSA01664) and of Bloodborne (CUSA00900) has DTPMOD64 relocations against a local section symbol with section index 0 and value 0, and the modules carry no section headers (`e_shnum` 0). As for a TLS relocation without a symbol, the module and offset are the module's own TLS block, so `GuestImageReader` passes a DTPMOD64 or DTPOFF64 against such a symbol on without the symbol. The accepted form is narrow: a local `STT_SECTION` symbol with section index 0 and value 0, in a module with `PT_TLS`. A section symbol that names a section (there is no section table in these modules to show that section is TLS) or has a value, a TPOFF64, a module without `PT_TLS` and a DTPMOD64 with an addend still fail with `Invalid guest TLS relocation`. ### Tested Windows 11, WinLibs GCC 15.2, relinker on `main` cecb540a6: - New test `guest_own_tls_relocations`: DTPMOD64 and DTPOFF64 against the own section symbol convert for Linux, Windows and macOS output (the Linux output keeps the relocation without the symbol), for plain and SCE modules; the refused forms above fail. With `main`'s `GuestImageReader.cpp` the test fails with `Invalid guest TLS relocation`. - All 163 relinker tests pass. - Limbo converts with both bundled modules and Bloodborne with all 7, for Linux and `--windows`; on `main` alone both stop in `libSceFios2.prx` with `Invalid guest TLS relocation`. ### Checklist - [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 - [x] Fixes: none - [x] Unblocks: Limbo (CUSA01664) #6978, Bloodborne (CUSA00900) - [x] GPUs tested: n/a - [x] AI-assisted: yes (Claude Code) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
jotitadev commented 2026-10-21 22:29:04 +00:00 (Migrated from github.com)

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

Review: COMMENTED


Validated on Apple Silicon, both native arm64 and x86_64 under Rosetta 2.

  • Machine: Apple M2 Max, macOS 27.2.
  • Head: 6f3e4a147, on top of main a6dcea9279.
  • Build: relinker-only (-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON). x86_64 build with -DCMAKE_OSX_ARCHITECTURES=x86_64 -DPython3_EXECUTABLE=/usr/bin/python3 (Python 3.9.6), so the Python harness and the relinker run under Rosetta.

Results:

  • arm64: 230/230.
  • x86_64 under Rosetta 2 (Python 3.9.6): 230/230.

guest_own_tls_relocations passes on both arches; it exercises the --macos output path alongside Linux and --windows, so the new DTPMOD64/DTPOFF64 own-TLS-block handling is covered for the Mach-O guest layout too.

Red/green on arm64: reverting only GuestImageReader.cpp to main while keeping the new test makes it fail at the first case with FAIL: ... Invalid guest TLS relocation; the full merge turns it green. So the test guards the regression.

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

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5607012103 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9429#pullrequestreview-5607012103). Originally posted by [jotitadev](https://github.com/jotitadev) on 2026-10-21T22:29:04Z. **Review:** COMMENTED --- Validated on Apple Silicon, both native arm64 and x86_64 under Rosetta 2. - Machine: Apple M2 Max, macOS 27.2. - Head: 6f3e4a147, on top of main a6dcea9279. - Build: relinker-only (`-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON`). x86_64 build with `-DCMAKE_OSX_ARCHITECTURES=x86_64 -DPython3_EXECUTABLE=/usr/bin/python3` (Python 3.9.6), so the Python harness and the relinker run under Rosetta. Results: - arm64: 230/230. - x86_64 under Rosetta 2 (Python 3.9.6): 230/230. `guest_own_tls_relocations` passes on both arches; it exercises the `--macos` output path alongside Linux and `--windows`, so the new DTPMOD64/DTPOFF64 own-TLS-block handling is covered for the Mach-O guest layout too. Red/green on arm64: reverting only `GuestImageReader.cpp` to main while keeping the new test makes it fail at the first case with `FAIL: ... Invalid guest TLS relocation`; the full merge turns it green. So the test guards the regression. Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
github-actions[bot] commented 2026-10-21 22:39:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-21T22:39:13Z.


Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 5021 core/relinker/CMakeLists.txt
PR 6044 core/relinker/CMakeLists.txt
PR 6879 core/relinker/CMakeLists.txt
PR 9408 core/relinker/CMakeLists.txt
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6328125525 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9429#issuecomment-6328125525). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-21T22:39:13Z. --- <!-- pr-overlap --> Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap. | Pull request | Shared files not compared | |---|---| | [PR 5021](https://www.github.com/boykopovar/AnyPS5/pull/5021) | `core/relinker/CMakeLists.txt` | | [PR 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `core/relinker/CMakeLists.txt` | | [PR 6879](https://www.github.com/boykopovar/AnyPS5/pull/6879) | `core/relinker/CMakeLists.txt` | | [PR 9408](https://www.github.com/boykopovar/AnyPS5/pull/9408) | `core/relinker/CMakeLists.txt` |
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!9429
No description provided.