fix(relinker): report PLT stubs replaced after linking #18085

Merged
eliasbruno124-dev merged 3 commits from upstream-pr/18085 into main 2026-11-16 02:18:24 +00:00
eliasbruno124-dev commented 2026-11-10 11:06:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by eliasbruno124-dev on 2026-11-10T11:06:58Z.


What

Some dumps carry PLT stubs that were overwritten after linking: the stub's jmp through its GOT entry is replaced by inline code or by a jump to code placed in the segment's padding, so the import of that entry is no longer called. #12123 describes two titles whose bundled libc.prx has such a stub jumping to an inline _umtx_op syscall; the relinker then reports only Forbidden syscall instruction at code offset 0x116c84, which does not say where the instruction comes from. A stub replaced by mov eax, 0; ret converts without any message at all.

Report every replaced stub of the executable and of each bundled module during the conversion, with the bytes that restore it through the existing --patches mechanism:

Replaced PLT stub: sce_module/libc.prx va=0x116bb0 ff254aba0700 -> e99b00000090 (jump to 0x116c50); import Hc4CaR6JBL0 is not called through it; a --patches entry with expected = "e99b00000090" and value = "ff254aba0700" restores the linked stub

When the syscall scan refuses an instruction in the code such a stub jumps to, before that code's first return or jump, the error names the stub:

FAIL: Forbidden syscall instruction at code offset 0x116c84; it is in the code at 0x116c50 that the replaced PLT stub at 0x116bb0 jumps to (offset 0x116c84)

This is the general diagnostic offered as option 2 in #12123; the relinker does not learn the inline helper and converts replacements exactly as before. The PLT header is located by its push/jmp through GOT+8 and GOT+16; stub i is expected at header + 16 * (i + 1) with a jmp through GOT + 24 + 8 * i. A stub that differs is reported with its 6-byte jump, or with all 16 bytes when its push index; jmp header tail differs too. A table in which no stub has the linked form is not reported, so an unknown PLT layout stays silent. No output byte changes: only messages and the text of that one error. docs/user/USAGE.md describes the line beside the patch file format.

No maintainer has chosen between the two options in #12123 yet, so this does not close it. @B-Howell offered to write option 2 there; no branch or PR for it exists, and this one can be dropped if theirs is preferred.

Tested

Windows 11 Pro 10.0.26300, MSYS2 MinGW-w64 GCC 16.2.0, CMake 4.4.5, Ninja, CPython 3.12.14, Release, ANYPS5_RELINKER_ONLY=ON, BUILD_TESTING=ON.

  • Base 70aab1bf93, whole relinker-only suite with ctest -j 5: main passes 859 of 860 tests, this change 861 of 862 (the two new tests). The one failure is the same in both runs: vulkan_validation_gate_commands, whose symlink-loop case cannot create a symbolic link without the Windows privilege (WinError 1314); #16558 addresses it.
  • Rebased onto 39bac5d055 as 25f32d517d; nothing under core/relinker or in docs/user/USAGE.md changed in between. Full rebuild and suite again: 861 of 862, the same single failure.
  • replaced_plt_stubs checks the finder directly: a linked table, no relocations, no PLT header, a table longer than its segment and a table without one linked stub report nothing; a 6-byte replacement, a 16-byte replacement and a jump are reported with their addresses, GOT entries and both byte strings; the cause is given for an instruction reached from the jump target and withheld after a return, inside an instruction, before the target and past the segment.
  • replaced_plt_stubs_conversion runs the relinker for Linux and Windows output: a linked executable prints nothing; replaced stubs in an executable are reported and it converts; a module whose stub jumps to a syscall is refused with the stub named in the error and no output written; the same module converts without a report once a patch file restores the stub and overwrites the helper; a syscall behind a return is refused without the cause. Run against the relinker built from main, the test fails at its first report check.
  • python tools/check_conventions.py --base origin/main and git diff --check pass.

Title files, conversion only (--windows --to-intel, SELF containers unwrapped with tools/unwrap_self.py), 22 PS5 titles with 142 ELF files in total:

  • Every title ends with the same exit code as with the relinker of main 70aab1bf93: 20 convert, 2 are refused at the same instruction. 5 titles get reports, 17 stubs in all; the other 17 titles print none. A separate script that parses the same files independently (36,665 linked stubs, 17 replaced) lists the same 17 addresses.
  • Assassin's Creed Shadows PPSA20397 01.019.076: sce_module/libc.prx (SHA-256 b3e1a95e…1d0bef) prints the line quoted above and the conversion stops with the extended error; eboot.bin reports two more stubs (TViD1EZXkNI, a jump to 0x4370eb7, and VANhIWcqYak, 16 bytes of inline code). A patch file holding the three reported expected/value pairs plus one entry that overwrites the now unreferenced helper at 0x116c50 passes --verify-patches (4 applicable) and converts the title with the syscall scan on (5 modules). main refuses the same input.
  • Assassin's Creed Mirage PPSA07230 01.012.000: the same libc.prx stub and refusal. Its unwrapped libc.prx has SHA-256 e0143155…85234f, the hash reported for Minecraft in #12123.
  • The Last of Us Part I PPSA03396 02.000.000 and Part II Remastered PPSA15508 01.002.000: 6 stubs each in eboot.bin (mov eax, 0; ret, mov byte [rdi], 1; xor eax, eax; ret and two 16-byte replacements). Both convert, as on main, now with the reports.
  • God of War Ragnarök PPSA08330 05.005.000: one 16-byte replacement in eboot.bin; its libc.prx has no replaced stub and converts, unlike the PPSA08329 copy of #12123.

Not tested: Linux and macOS hosts, the web converter, and launching any title. Whether the runtime implements the imports a restored stub calls again was not checked. The provenance of these dumps is not established here.

Overlap: tools/pr_overlap.py --branch fix/relinker-replaced-plt-stubs did not finish on this machine (its diffs fetch blobs on demand in a partial clone, and the connection was dropped in two runs), so the comparison was made directly against the 1,986 open pull request heads it had fetched on 2026-11-10. 76 of them change a file this branch changes; a trial merge (git merge-tree) of this branch with each adds conflicts for four. #14107 registers a test on the line next to the one added here in core/relinker/CMakeLists.txt; both lines stay. #10792, #10861 and #11525, which already conflict with main, change lines this branch changes around the syscall scan: #10792 and #10861 in GuestModuleBuilder.cpp, RelinkerPipeline.cpp and the same CMake list, #11525 in GuestModuleBuilder.cpp. None of the four reports replaced PLT stubs; whichever lands later resolves the conflict. The branch merges cleanly into main 2c41a032c6, which was not built here.

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 (relates to #12123, which awaits a maintainer decision)
  • Unblocks: none
  • GPUs tested: n/a (relinker change)
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5240226143 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18085). Originally posted by [eliasbruno124-dev](https://github.com/eliasbruno124-dev) on 2026-11-10T11:06:58Z. --- ### What Some dumps carry PLT stubs that were overwritten after linking: the stub's `jmp` through its GOT entry is replaced by inline code or by a jump to code placed in the segment's padding, so the import of that entry is no longer called. #12123 describes two titles whose bundled `libc.prx` has such a stub jumping to an inline `_umtx_op` syscall; the relinker then reports only `Forbidden syscall instruction at code offset 0x116c84`, which does not say where the instruction comes from. A stub replaced by `mov eax, 0; ret` converts without any message at all. Report every replaced stub of the executable and of each bundled module during the conversion, with the bytes that restore it through the existing `--patches` mechanism: ``` Replaced PLT stub: sce_module/libc.prx va=0x116bb0 ff254aba0700 -> e99b00000090 (jump to 0x116c50); import Hc4CaR6JBL0 is not called through it; a --patches entry with expected = "e99b00000090" and value = "ff254aba0700" restores the linked stub ``` When the syscall scan refuses an instruction in the code such a stub jumps to, before that code's first return or jump, the error names the stub: ``` FAIL: Forbidden syscall instruction at code offset 0x116c84; it is in the code at 0x116c50 that the replaced PLT stub at 0x116bb0 jumps to (offset 0x116c84) ``` This is the general diagnostic offered as option 2 in #12123; the relinker does not learn the inline helper and converts replacements exactly as before. The PLT header is located by its `push`/`jmp` through `GOT+8` and `GOT+16`; stub `i` is expected at header + 16 * (i + 1) with a `jmp` through `GOT + 24 + 8 * i`. A stub that differs is reported with its 6-byte jump, or with all 16 bytes when its `push index; jmp header` tail differs too. A table in which no stub has the linked form is not reported, so an unknown PLT layout stays silent. No output byte changes: only messages and the text of that one error. `docs/user/USAGE.md` describes the line beside the patch file format. No maintainer has chosen between the two options in #12123 yet, so this does not close it. @B-Howell offered to write option 2 there; no branch or PR for it exists, and this one can be dropped if theirs is preferred. ### 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 Pro 10.0.26300, MSYS2 MinGW-w64 GCC 16.2.0, CMake 4.4.5, Ninja, CPython 3.12.14, Release, `ANYPS5_RELINKER_ONLY=ON`, `BUILD_TESTING=ON`. - Base `70aab1bf93`, whole relinker-only suite with `ctest -j 5`: `main` passes 859 of 860 tests, this change 861 of 862 (the two new tests). The one failure is the same in both runs: `vulkan_validation_gate_commands`, whose symlink-loop case cannot create a symbolic link without the Windows privilege (`WinError 1314`); #16558 addresses it. - Rebased onto `39bac5d055` as `25f32d517d`; nothing under `core/relinker` or in `docs/user/USAGE.md` changed in between. Full rebuild and suite again: 861 of 862, the same single failure. - `replaced_plt_stubs` checks the finder directly: a linked table, no relocations, no PLT header, a table longer than its segment and a table without one linked stub report nothing; a 6-byte replacement, a 16-byte replacement and a jump are reported with their addresses, GOT entries and both byte strings; the cause is given for an instruction reached from the jump target and withheld after a return, inside an instruction, before the target and past the segment. - `replaced_plt_stubs_conversion` runs the relinker for Linux and Windows output: a linked executable prints nothing; replaced stubs in an executable are reported and it converts; a module whose stub jumps to a syscall is refused with the stub named in the error and no output written; the same module converts without a report once a patch file restores the stub and overwrites the helper; a syscall behind a return is refused without the cause. Run against the relinker built from `main`, the test fails at its first report check. - `python tools/check_conventions.py --base origin/main` and `git diff --check` pass. Title files, conversion only (`--windows --to-intel`, SELF containers unwrapped with `tools/unwrap_self.py`), 22 PS5 titles with 142 ELF files in total: - Every title ends with the same exit code as with the relinker of `main` `70aab1bf93`: 20 convert, 2 are refused at the same instruction. 5 titles get reports, 17 stubs in all; the other 17 titles print none. A separate script that parses the same files independently (36,665 linked stubs, 17 replaced) lists the same 17 addresses. - Assassin's Creed Shadows PPSA20397 01.019.076: `sce_module/libc.prx` (SHA-256 `b3e1a95e…1d0bef`) prints the line quoted above and the conversion stops with the extended error; `eboot.bin` reports two more stubs (`TViD1EZXkNI`, a jump to `0x4370eb7`, and `VANhIWcqYak`, 16 bytes of inline code). A patch file holding the three reported `expected`/`value` pairs plus one entry that overwrites the now unreferenced helper at `0x116c50` passes `--verify-patches` (4 applicable) and converts the title with the syscall scan on (5 modules). `main` refuses the same input. - Assassin's Creed Mirage PPSA07230 01.012.000: the same `libc.prx` stub and refusal. Its unwrapped `libc.prx` has SHA-256 `e0143155…85234f`, the hash reported for Minecraft in #12123. - The Last of Us Part I PPSA03396 02.000.000 and Part II Remastered PPSA15508 01.002.000: 6 stubs each in `eboot.bin` (`mov eax, 0; ret`, `mov byte [rdi], 1; xor eax, eax; ret` and two 16-byte replacements). Both convert, as on `main`, now with the reports. - God of War Ragnarök PPSA08330 05.005.000: one 16-byte replacement in `eboot.bin`; its `libc.prx` has no replaced stub and converts, unlike the PPSA08329 copy of #12123. Not tested: Linux and macOS hosts, the web converter, and launching any title. Whether the runtime implements the imports a restored stub calls again was not checked. The provenance of these dumps is not established here. Overlap: `tools/pr_overlap.py --branch fix/relinker-replaced-plt-stubs` did not finish on this machine (its diffs fetch blobs on demand in a partial clone, and the connection was dropped in two runs), so the comparison was made directly against the 1,986 open pull request heads it had fetched on 2026-11-10. 76 of them change a file this branch changes; a trial merge (`git merge-tree`) of this branch with each adds conflicts for four. #14107 registers a test on the line next to the one added here in `core/relinker/CMakeLists.txt`; both lines stay. #10792, #10861 and #11525, which already conflict with `main`, change lines this branch changes around the syscall scan: #10792 and #10861 in `GuestModuleBuilder.cpp`, `RelinkerPipeline.cpp` and the same CMake list, #11525 in `GuestModuleBuilder.cpp`. None of the four reports replaced PLT stubs; whichever lands later resolves the conflict. The branch merges cleanly into `main` `2c41a032c6`, which was not built here. ### 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: none <!-- #PR, or none --> - [x] Fixes: none (relates to #12123, which awaits a maintainer decision) <!-- issue it closes as Fixes #N, or none --> - [x] Unblocks: none <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> - [x] GPUs tested: n/a (relinker change) <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> - [x] AI-assisted: yes <!-- yes / no -->
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!18085
No description provided.