fix(relinker): reject guest TLS symbols in special sections #10731

Merged
roboterspinne merged 1 commit from upstream-pr/10731 into main 2026-10-25 16:57:35 +00:00
roboterspinne commented 2026-10-24 19:56:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by roboterspinne on 2026-10-24T19:56:50Z.


What

GuestImageReader rejects a defined symbol whose st_shndx is SHN_LORESERVE (0xff00) or higher, SHN_ABS excepted, but the check sat inside the (info & 15) != 6 branch, so STT_TLS symbols skipped it. On main a guest module with a PT_TLS and an STT_TLS symbol in SHN_ABS, SHN_COMMON, 0xff00 or SHN_XINDEX (0xffff) relinks with exit 0 on Linux, whose output keeps the symbol in .dynsym with that section index. Windows and macOS exit 2 with Unsupported guest export section: <name> only for an exported symbol outside SHN_ABS; they drop an SHN_ABS export (WindowsGuestModuleWriter.cpp:134, MacOsGuestModuleWriter.cpp:97) and, for a local symbol, write st_value plus addend for an R_X86_64_DTPOFF64 against it and exit 0.

  • Rule. Before the TLS bounds check, every defined symbol with section >= 0xff00 && (section != AbsoluteSection || (info & 15) == 6) now fails with the existing Unsupported special symbol section: <name>, so SHN_ABS stays accepted for non-TLS symbols only and the non-TLS behaviour is unchanged. The gABI says a defined STT_TLS symbol "gives the assigned offset for the symbol, not the actual address", an offset in the module's TLS block; SHN_ABS means a value that relocation does not change, SHN_COMMON an unallocated common block that a shared object must allocate, and the other reserved indexes are processor-specific, OS-specific, unassigned or the SHN_XINDEX escape. The gABI gives an STT_TLS symbol no meaning in any of them; FreeBSD rtld uses st_value of a defined TLS symbol whatever its st_shndx, but the PS5 loader's handling is not measured, so the reader fails instead of picking a meaning. The macOS executable patcher already rejects TLS exports at or above SHN_LORESERVE (MacOsMachOPatcher.cpp:89), and open #10646 does the same for executable exports in RelinkerPipeline.cpp. The export-section checks at WindowsGuestModuleWriter.cpp:135 and MacOsGuestModuleWriter.cpp:98 can no longer be reached and stay for a follow-up. No issue and no test fixture has an STT_TLS symbol in a reserved section; the only SHN_ABS guest symbols reported (PPSA12544, #698) are STT_NOTYPE and stay accepted.
  • Tests. test_guest_absolute_symbols.py gains tls_module, built on module_with_symbol(True) with a PT_TLS (vaddr 0x2380, filesz 8, memsz 0x40) and symbol 1 as a LOCAL or GLOBAL STT_TLS symbol (value 0, size 8) with an R_X86_64_DTPOFF64 against it. On Linux, --windows and --macos, section 1 relinks with exit 0 in both bindings, and SHN_ABS, SHN_COMMON, 0xff00 and 0xffff exit 2 with Unsupported special symbol section and write no module.prx.guest.prx. convert now takes the module bytes; the existing absolute and common cases are unchanged.
  • Overlap. pr_overlap.py reports no overlap with open pull requests.

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.

  • Counter-check on untouched main (2fade7ef4e): the extended test fails at its first special-section case with AssertionError: ('linux', '0xfff1', 0, ''), a LOCAL SHN_ABS symbol relinked with exit 0. Per target on main: LOCAL in all four special sections and GLOBAL in SHN_ABS exit 0 on all three targets; GLOBAL in 0xfff2, 0xff00 and 0xffff exit 0 on Linux and 2 on Windows and macOS with Unsupported guest export section: shared.
  • With this change guest_absolute_symbols passes in 2.5 s: the 24 special-section runs exit 2 with Unsupported special symbol section: shared and write no artifact, the 6 section-1 runs exit 0. The 71 tests matching guest|tls|absolute|symbol pass (33 s).
  • ctest --test-dir build-relinker -j 4: 244 tests, 240 passed, long_paths skipped; select_tests (Windows symlink fixture) and patch_advisor_unit (build path with spaces, fix open in #10667) are known local failures on main; shader_cache_runtime_sources timed out at 180 s under parallel load and passed when rerun alone (119 s).
  • python tools/check_conventions.py --base upstream/main with this title and description passed.
  • Not tested on Linux or macOS; CI runs the tests 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:4998643357 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10731). Originally posted by [roboterspinne](https://github.com/roboterspinne) on 2026-10-24T19:56:50Z. --- ### What `GuestImageReader` rejects a defined symbol whose `st_shndx` is `SHN_LORESERVE` (0xff00) or higher, `SHN_ABS` excepted, but the check sat inside the `(info & 15) != 6` branch, so `STT_TLS` symbols skipped it. On `main` a guest module with a `PT_TLS` and an `STT_TLS` symbol in `SHN_ABS`, `SHN_COMMON`, 0xff00 or `SHN_XINDEX` (0xffff) relinks with exit 0 on Linux, whose output keeps the symbol in `.dynsym` with that section index. Windows and macOS exit 2 with `Unsupported guest export section: <name>` only for an exported symbol outside `SHN_ABS`; they drop an `SHN_ABS` export (`WindowsGuestModuleWriter.cpp:134`, `MacOsGuestModuleWriter.cpp:97`) and, for a local symbol, write `st_value` plus addend for an `R_X86_64_DTPOFF64` against it and exit 0. - **Rule.** Before the TLS bounds check, every defined symbol with `section >= 0xff00 && (section != AbsoluteSection || (info & 15) == 6)` now fails with the existing `Unsupported special symbol section: <name>`, so `SHN_ABS` stays accepted for non-TLS symbols only and the non-TLS behaviour is unchanged. The gABI says a defined `STT_TLS` symbol "gives the assigned offset for the symbol, not the actual address", an offset in the module's TLS block; `SHN_ABS` means a value that relocation does not change, `SHN_COMMON` an unallocated common block that a shared object must allocate, and the other reserved indexes are processor-specific, OS-specific, unassigned or the `SHN_XINDEX` escape. The gABI gives an `STT_TLS` symbol no meaning in any of them; FreeBSD rtld uses `st_value` of a defined TLS symbol whatever its `st_shndx`, but the PS5 loader's handling is not measured, so the reader fails instead of picking a meaning. The macOS executable patcher already rejects TLS exports at or above `SHN_LORESERVE` (`MacOsMachOPatcher.cpp:89`), and open #10646 does the same for executable exports in `RelinkerPipeline.cpp`. The export-section checks at `WindowsGuestModuleWriter.cpp:135` and `MacOsGuestModuleWriter.cpp:98` can no longer be reached and stay for a follow-up. No issue and no test fixture has an `STT_TLS` symbol in a reserved section; the only `SHN_ABS` guest symbols reported (PPSA12544, #698) are `STT_NOTYPE` and stay accepted. - **Tests.** `test_guest_absolute_symbols.py` gains `tls_module`, built on `module_with_symbol(True)` with a `PT_TLS` (vaddr 0x2380, filesz 8, memsz 0x40) and symbol 1 as a LOCAL or GLOBAL `STT_TLS` symbol (value 0, size 8) with an `R_X86_64_DTPOFF64` against it. On Linux, `--windows` and `--macos`, section 1 relinks with exit 0 in both bindings, and `SHN_ABS`, `SHN_COMMON`, 0xff00 and 0xffff exit 2 with `Unsupported special symbol section` and write no `module.prx.guest.prx`. `convert` now takes the module bytes; the existing absolute and common cases are unchanged. - **Overlap.** `pr_overlap.py` reports no overlap with open pull requests. ### 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. - Counter-check on untouched `main` (2fade7ef4e): the extended test fails at its first special-section case with `AssertionError: ('linux', '0xfff1', 0, '')`, a LOCAL `SHN_ABS` symbol relinked with exit 0. Per target on `main`: LOCAL in all four special sections and GLOBAL in `SHN_ABS` exit 0 on all three targets; GLOBAL in 0xfff2, 0xff00 and 0xffff exit 0 on Linux and 2 on Windows and macOS with `Unsupported guest export section: shared`. - With this change `guest_absolute_symbols` passes in 2.5 s: the 24 special-section runs exit 2 with `Unsupported special symbol section: shared` and write no artifact, the 6 section-1 runs exit 0. The 71 tests matching `guest|tls|absolute|symbol` pass (33 s). - `ctest --test-dir build-relinker -j 4`: 244 tests, 240 passed, `long_paths` skipped; `select_tests` (Windows symlink fixture) and `patch_advisor_unit` (build path with spaces, fix open in #10667) are known local failures on `main`; `shader_cache_runtime_sources` timed out at 180 s under parallel load and passed when rerun alone (119 s). - `python tools/check_conventions.py --base upstream/main` with this title and description passed. - Not tested on Linux or macOS; CI runs the tests 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 20:05:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T20:05:08Z.

Review: APPROVED


Reviewed the symbol-section validation and its regression coverage. TLS symbols are now rejected for SHN_ABS, SHN_COMMON, SHN_XINDEX and the other reserved indices, while ordinary SHN_ABS symbols and normal TLS sections retain their existing handling. The tests cover local/global bindings on Linux, Windows and macOS fixtures. The hosted relinker matrix, ASan and conventions checks all pass on this head. I found no blocking issue.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5639757571 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10731#pullrequestreview-5639757571). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-24T20:05:08Z. **Review:** APPROVED --- Reviewed the symbol-section validation and its regression coverage. TLS symbols are now rejected for SHN_ABS, SHN_COMMON, SHN_XINDEX and the other reserved indices, while ordinary SHN_ABS symbols and normal TLS sections retain their existing handling. The tests cover local/global bindings on Linux, Windows and macOS fixtures. The hosted relinker matrix, ASan and conventions checks all pass on this head. I found no blocking issue.
MarcZX10 commented 2026-10-24 20:19:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T20:19:56Z.

Review: APPROVED


Reviewed the complete diff at 21127fe316. The special-section guard now applies before TLS bounds validation and still permits SHN_ABS for non-TLS symbols; the new fixture exercises local/global TLS symbols across Linux, Windows and macOS output modes, including SHN_ABS, SHN_COMMON, SHN_LORESERVE and SHN_XINDEX. The reported main counter-check reproduces the prior acceptance, and the focused fixture plus 71 related tests passed locally on Windows; hosted Ubuntu, Windows, macOS arm64/x86_64 and ASAN relinker checks all passed. Product Linux/Windows jobs were skipped by repository workflow policy.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5639801843 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10731#pullrequestreview-5639801843). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-24T20:19:56Z. **Review:** APPROVED --- Reviewed the complete diff at 21127fe316db580492921055ed3ae18e42876b7c. The special-section guard now applies before TLS bounds validation and still permits SHN_ABS for non-TLS symbols; the new fixture exercises local/global TLS symbols across Linux, Windows and macOS output modes, including SHN_ABS, SHN_COMMON, SHN_LORESERVE and SHN_XINDEX. The reported main counter-check reproduces the prior acceptance, and the focused fixture plus 71 related tests passed locally on Windows; hosted Ubuntu, Windows, macOS arm64/x86_64 and ASAN relinker checks all passed. Product Linux/Windows jobs were skipped by repository workflow policy.
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!10731
No description provided.