fix(relinker): skip the data of Mono AOT images in the syscall scan and code analysis #8198

Closed
ntamas94 wants to merge 1 commit from upstream-pr/8198 into main
ntamas94 commented 2026-10-20 02:17:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ntamas94 on 2026-10-20T02:17:56Z.


What

Unity's Mono AOT images keep their tables, the info word of each PLT entry and their strings in the executable segment. Only the module's own C functions have FDEs, so the relinker scanned the whole segment as code. Gang Beasts (CUSA04865) Media/Modules/MonoAssembliesPS4.prx (78 images, mono_aot_version 67) stopped three times on data:

  1. Forbidden syscall instruction at code offset 0x129f1c: inside class_name_table.
  2. A PLT info word (0f 07) decoded as sysret.
  3. Code analysis: overlapping instruction boundaries: in the string area of the last image.

MonoAotDataRanges reads each image's static globals table: name and address pairs held in RELATIVE relocations, ended by a NULL name. In each image, code is methods..methods_end, the 6-byte jmp *rel32(%rip) of each 10-byte PLT entry, X..X_p trampolines, and specific_trampolines/static_rgctx_trampolines/imt_thunks up to the next listed address. Everything else from methods to the end of the image's last string is data.

  • The syscall scans, for the executable and for guest modules, replace that data with 0x90 in their scan copy, as is already done for relative jump tables. The output bytes are unchanged.
  • The code analysis adds the ranges to its table set, so no roots or control-flow paths start in them.
  • A table that names mono_aot_file_info but lacks methods, methods_end, plt or plt_end, an unterminated table, a global without a relocated value, a PLT whose size is not a whole number of 10-byte entries or whose entry is not jmp *rel32(%rip), overlapping code ranges and overlapping images all throw.

The format details were read from the module itself (findings in discussion #7941). The 78 image blocks tile the segment from 0xf0 to 0x2ddf2f8 with no gap or overlap, and all 79,477 PLT entries have the 10-byte form. The debt entry records what is not covered: newer Mono AOT formats that bound code with jit_code_start/jit_code_end, and trampoline arrays bounded by the next listed address instead of their counts.

Tested

Windows 11 Pro (26200), WinLibs GCC 15.2.0 r7, on main at 6bd669e40: the new mono_aot_ranges test passes, and 118 of the 120 relinker tests pass. windows_trace_imports and windows_import_modules fail on this machine because Windows Defender quarantines a DLL they generate (WinError 225), with or without this change.

Gang Beasts (CUSA04865, 01.00, own dump): with this change on top of #6684, #7660 and the TLS relocation fix from #6977, the executable and all 18 modules convert, including MonoAssembliesPS4.prx. The executable segment of the converted MonoAssembliesPS4.prx is byte-identical to the input. Converted this way and run on #6977 with local changes, the title plays a full round (#7941).

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: CUSA04865 #7941 (conversion; running also needs #6977)
  • GPUs tested: n/a
  • AI-assisted: yes (Claude Code)

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4930053794 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8198). Originally posted by [ntamas94](https://github.com/ntamas94) on 2026-10-20T02:17:56Z. --- ### What Unity's Mono AOT images keep their tables, the info word of each PLT entry and their strings in the executable segment. Only the module's own C functions have FDEs, so the relinker scanned the whole segment as code. Gang Beasts (CUSA04865) `Media/Modules/MonoAssembliesPS4.prx` (78 images, `mono_aot_version` 67) stopped three times on data: 1. `Forbidden syscall instruction at code offset 0x129f1c`: inside `class_name_table`. 2. A PLT info word (`0f 07`) decoded as `sysret`. 3. `Code analysis: overlapping instruction boundaries`: in the string area of the last image. `MonoAotDataRanges` reads each image's static `globals` table: name and address pairs held in RELATIVE relocations, ended by a NULL name. In each image, code is `methods`..`methods_end`, the 6-byte `jmp *rel32(%rip)` of each 10-byte PLT entry, `X`..`X_p` trampolines, and `specific_trampolines`/`static_rgctx_trampolines`/`imt_thunks` up to the next listed address. Everything else from `methods` to the end of the image's last string is data. - The syscall scans, for the executable and for guest modules, replace that data with `0x90` in their scan copy, as is already done for relative jump tables. The output bytes are unchanged. - The code analysis adds the ranges to its table set, so no roots or control-flow paths start in them. - A table that names `mono_aot_file_info` but lacks `methods`, `methods_end`, `plt` or `plt_end`, an unterminated table, a global without a relocated value, a PLT whose size is not a whole number of 10-byte entries or whose entry is not `jmp *rel32(%rip)`, overlapping code ranges and overlapping images all throw. The format details were read from the module itself (findings in discussion #7941). The 78 image blocks tile the segment from 0xf0 to 0x2ddf2f8 with no gap or overlap, and all 79,477 PLT entries have the 10-byte form. The debt entry records what is not covered: newer Mono AOT formats that bound code with `jit_code_start`/`jit_code_end`, and trampoline arrays bounded by the next listed address instead of their counts. ### Tested Windows 11 Pro (26200), WinLibs GCC 15.2.0 r7, on `main` at 6bd669e40: the new `mono_aot_ranges` test passes, and 118 of the 120 relinker tests pass. `windows_trace_imports` and `windows_import_modules` fail on this machine because Windows Defender quarantines a DLL they generate (`WinError 225`), with or without this change. Gang Beasts (CUSA04865, 01.00, own dump): with this change on top of #6684, #7660 and the TLS relocation fix from #6977, the executable and all 18 modules convert, including `MonoAssembliesPS4.prx`. The executable segment of the converted `MonoAssembliesPS4.prx` is byte-identical to the input. Converted this way and run on #6977 with local changes, the title plays a full round (#7941). ### 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: CUSA04865 #7941 (conversion; running also needs #6977) - [x] GPUs tested: n/a - [x] AI-assisted: yes (Claude Code) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-actions[bot] commented 2026-10-20 02:23:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-20T02:23:07Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 6607 core/relinker/relinker/src/pipeline/RelinkerPipeline.cpp L328-329
PR 7660 core/relinker/relinker/src/guest/GuestModuleBuilder.cpp L351-352
PR 7837 docs/dev/debt/relinker.md L4
PR 8076 core/relinker/relinker/src/guest/GuestModuleBuilder.cpp L1-2, L346, L351-352
PR 8166 core/relinker/relinker/src/guest/GuestModuleBuilder.cpp L351-352

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
docs/dev/debt/relinker.md
PR 6044 core/relinker/CMakeLists.txt
PR 6618 core/relinker/CMakeLists.txt
core/relinker/relinker/src/analysis/CodeInstructionCollector.cpp
core/relinker/relinker/src/pipeline/RelinkerPipeline.cpp
PR 6879 core/relinker/CMakeLists.txt
PR 6977 core/relinker/CMakeLists.txt
core/relinker/relinker/src/analysis/CodeInstructionCollector.cpp
core/relinker/relinker/src/guest/GuestModuleBuilder.cpp
core/relinker/relinker/src/pipeline/RelinkerPipeline.cpp
docs/dev/debt/relinker.md
PR 7332 core/relinker/CMakeLists.txt
docs/dev/debt/relinker.md
PR 7822 docs/dev/debt/relinker.md
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6281854084 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8198#issuecomment-6281854084). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-20T02:23:07Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | [PR 6607](https://www.github.com/boykopovar/AnyPS5/pull/6607) | `core/relinker/relinker/src/pipeline/RelinkerPipeline.cpp` [L328-329](https://github.com/boykopovar/AnyPS5/blob/eca8d6cca48d4313a00aedc2bb949059619a0a54/core/relinker/relinker/src/pipeline/RelinkerPipeline.cpp#L328-L329) | | | | [PR 7660](https://www.github.com/boykopovar/AnyPS5/pull/7660) | `core/relinker/relinker/src/guest/GuestModuleBuilder.cpp` [L351-352](https://github.com/boykopovar/AnyPS5/blob/eca8d6cca48d4313a00aedc2bb949059619a0a54/core/relinker/relinker/src/guest/GuestModuleBuilder.cpp#L351-L352) | | | | [PR 7837](https://www.github.com/boykopovar/AnyPS5/pull/7837) | `docs/dev/debt/relinker.md` [L4](https://github.com/boykopovar/AnyPS5/blob/eca8d6cca48d4313a00aedc2bb949059619a0a54/docs/dev/debt/relinker.md#L4) | | | | [PR 8076](https://www.github.com/boykopovar/AnyPS5/pull/8076) | `core/relinker/relinker/src/guest/GuestModuleBuilder.cpp` [L1-2](https://github.com/boykopovar/AnyPS5/blob/eca8d6cca48d4313a00aedc2bb949059619a0a54/core/relinker/relinker/src/guest/GuestModuleBuilder.cpp#L1-L2), [L346](https://github.com/boykopovar/AnyPS5/blob/eca8d6cca48d4313a00aedc2bb949059619a0a54/core/relinker/relinker/src/guest/GuestModuleBuilder.cpp#L346), [L351-352](https://github.com/boykopovar/AnyPS5/blob/eca8d6cca48d4313a00aedc2bb949059619a0a54/core/relinker/relinker/src/guest/GuestModuleBuilder.cpp#L351-L352) | | | | [PR 8166](https://www.github.com/boykopovar/AnyPS5/pull/8166) | `core/relinker/relinker/src/guest/GuestModuleBuilder.cpp` [L351-352](https://github.com/boykopovar/AnyPS5/blob/eca8d6cca48d4313a00aedc2bb949059619a0a54/core/relinker/relinker/src/guest/GuestModuleBuilder.cpp#L351-L352) | | | 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`<br>`docs/dev/debt/relinker.md` | | [PR 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `core/relinker/CMakeLists.txt` | | [PR 6618](https://www.github.com/boykopovar/AnyPS5/pull/6618) | `core/relinker/CMakeLists.txt`<br>`core/relinker/relinker/src/analysis/CodeInstructionCollector.cpp`<br>`core/relinker/relinker/src/pipeline/RelinkerPipeline.cpp` | | [PR 6879](https://www.github.com/boykopovar/AnyPS5/pull/6879) | `core/relinker/CMakeLists.txt` | | [PR 6977](https://www.github.com/boykopovar/AnyPS5/pull/6977) | `core/relinker/CMakeLists.txt`<br>`core/relinker/relinker/src/analysis/CodeInstructionCollector.cpp`<br>`core/relinker/relinker/src/guest/GuestModuleBuilder.cpp`<br>`core/relinker/relinker/src/pipeline/RelinkerPipeline.cpp`<br>`docs/dev/debt/relinker.md` | | [PR 7332](https://www.github.com/boykopovar/AnyPS5/pull/7332) | `core/relinker/CMakeLists.txt`<br>`docs/dev/debt/relinker.md` | | [PR 7822](https://www.github.com/boykopovar/AnyPS5/pull/7822) | `docs/dev/debt/relinker.md` |
ntamas94 commented 2026-10-20 02:40:01 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ntamas94 on 2026-10-20T02:40:01Z.


Closing: #8166 converts the same module without a Mono-specific reader. Tested on Gang Beasts' MonoAssembliesPS4.prx; details in https://github.com/boykopovar/AnyPS5/pull/8166#issuecomment-6282062362

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6282063458 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8198#issuecomment-6282063458). Originally posted by [ntamas94](https://github.com/ntamas94) on 2026-10-20T02:40:01Z. --- Closing: #8166 converts the same module without a Mono-specific reader. Tested on Gang Beasts' `MonoAssembliesPS4.prx`; details in https://github.com/boykopovar/AnyPS5/pull/8166#issuecomment-6282062362

Pull request closed

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!8198
No description provided.