fix(relinker): reserve space after the Mach-O load commands for the code signature #11284

Merged
iamthehimansh merged 9 commits from upstream-pr/11284 into main 2026-10-27 18:43:39 +00:00
iamthehimansh commented 2026-10-25 23:50:10 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by iamthehimansh on 2026-10-25T23:50:10Z.


What

A relinked macOS executable reserves no space after its Mach-O load commands: the entry stub starts right after them. codesign adds an LC_CODE_SIGNATURE command to the end of that list, so signing the relinked game overwrites the first bytes of the entry stub, and the game exits with SIGILL (exit 132) before any guest code runs.

elfpatcher/src/macos/MacOsImage.cpp now leaves 0x400 bytes after the load commands before placing the entry stub, like ld's -headerpad. The existing "load commands do not fit" check still applies, now with the reserve included. This file builds on every host, because the relinker can produce Mac executables anywhere, but the change only affects Mach-O output.

This PR first also carried the guest entry, guest TLS and main-thread SDL code. @imellag's earlier #11047 and #11048 carry the same imports, and @krishalivaibhav's #10876 has the same ApplicationProcessParameters.cpp change, so those parts were dropped here. Of the four other open PRs that change MacOsImage.cpp (#11045, #10946, #10861, #10249), none touches the stub offset.

Tested

relinker/tests/test_macos_output.py (the macos_output CTest) now checks the reserve. On every host, each relinked output must keep its entry stub at least 0x400 bytes past the load commands. On macOS it also signs the import output with codesign -s - -f and checks that the entry stub bytes are unchanged. Relinker-only Release build with BUILD_TESTING=ON, Apple M2 Pro:

MacOsImage.cpp macos_output
this PR pass
main fail: import: entry stub at 0x3e0 leaves under 0x400 bytes after the load commands for codesign

Earlier runs on the same Apple M2 Pro, macOS 26.6.2, x86_64 Release under Rosetta 2, on main at 4b1a9a3b2: relinker_conversion, relinker_game_patch, macos_tls_alu and relinker_executables pass. A relinked game still can't start on main alone: it needs #11047 for the guest TLS imports, and libkernel to build on macOS. #11048 and #10876 are now on main. With the same reserve on #8658's branch, ccleste got past that exit on this machine, opened its window and created a MoltenVK device and swapchain. python3 tools/check_conventions.py --base origin/main passes.

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 to build; running a relinked game needs #11047
  • Fixes: none
  • Unblocks: starting relinked games on macOS once #11047 lands
  • GPUs tested: n/a
  • AI-assisted: yes (Cana)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5009914527 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11284). Originally posted by [iamthehimansh](https://github.com/iamthehimansh) on 2026-10-25T23:50:10Z. --- ### What A relinked macOS executable reserves no space after its Mach-O load commands: the entry stub starts right after them. `codesign` adds an `LC_CODE_SIGNATURE` command to the end of that list, so signing the relinked game overwrites the first bytes of the entry stub, and the game exits with `SIGILL` (exit 132) before any guest code runs. `elfpatcher/src/macos/MacOsImage.cpp` now leaves `0x400` bytes after the load commands before placing the entry stub, like ld's `-headerpad`. The existing "load commands do not fit" check still applies, now with the reserve included. This file builds on every host, because the relinker can produce Mac executables anywhere, but the change only affects Mach-O output. This PR first also carried the guest entry, guest TLS and main-thread SDL code. @imellag's earlier #11047 and #11048 carry the same imports, and @krishalivaibhav's #10876 has the same `ApplicationProcessParameters.cpp` change, so those parts were dropped here. Of the four other open PRs that change `MacOsImage.cpp` (#11045, #10946, #10861, #10249), none touches the stub offset. ### Tested `relinker/tests/test_macos_output.py` (the `macos_output` CTest) now checks the reserve. On every host, each relinked output must keep its entry stub at least `0x400` bytes past the load commands. On macOS it also signs the import output with `codesign -s - -f` and checks that the entry stub bytes are unchanged. Relinker-only Release build with `BUILD_TESTING=ON`, Apple M2 Pro: | `MacOsImage.cpp` | `macos_output` | |---|---| | this PR | pass | | `main` | fail: `import: entry stub at 0x3e0 leaves under 0x400 bytes after the load commands for codesign` | Earlier runs on the same Apple M2 Pro, macOS 26.6.2, x86_64 Release under Rosetta 2, on `main` at `4b1a9a3b2`: `relinker_conversion`, `relinker_game_patch`, `macos_tls_alu` and `relinker_executables` pass. A relinked game still can't start on `main` alone: it needs #11047 for the guest TLS imports, and libkernel to build on macOS. #11048 and #10876 are now on `main`. With the same reserve on #8658's branch, ccleste got past that exit on this machine, opened its window and created a MoltenVK device and swapchain. `python3 tools/check_conventions.py --base origin/main` passes. ### 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 to build; running a relinked game needs #11047 - [x] Fixes: none - [x] Unblocks: starting relinked games on macOS once #11047 lands - [x] GPUs tested: n/a - [x] AI-assisted: yes ([Cana](https://cana.build))
MarcZX10 commented 2026-10-25 23:56:00 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T23:56:00Z.

Review: CHANGES_REQUESTED


I found a race in the new macOS guest TLS registration path (GuestTls.cpp, especially the descriptor->Key reads in Aps5GuestTlsAllocateBlock_nid_no_patch and Aps5GuestTlsGetAddr_nid_no_patch). Multiple guest threads can make their first TLS access at the same time. The mutex serializes pthread_key_create inside Aps5GuestTlsRegister_nid_no_patch, but the callers read and write the shared non-atomic Key outside that mutex, which is a C++ data race and can also expose a stale/partially published key. Please make every access to Key use one synchronization scheme (for example, route initialization and reads through a locked helper or an atomic representation that preserves the descriptor ABI), and add a test that races first access from multiple threads and verifies a single registered key and distinct per-thread blocks.

Local python3 tools/check_conventions.py --base upstream/main --head upstream/pr/11284 and git diff --check upstream/main...upstream/pr/11284 pass. Hosted Linux relinker/ASan and policy checks pass; macOS relinker, macOS register-context, and other listed macOS jobs are still pending. I have not run macOS product tests locally.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5646046480 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11284#pullrequestreview-5646046480). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-25T23:56:00Z. **Review:** CHANGES_REQUESTED --- I found a race in the new macOS guest TLS registration path (`GuestTls.cpp`, especially the `descriptor->Key` reads in `Aps5GuestTlsAllocateBlock_nid_no_patch` and `Aps5GuestTlsGetAddr_nid_no_patch`). Multiple guest threads can make their first TLS access at the same time. The mutex serializes `pthread_key_create` inside `Aps5GuestTlsRegister_nid_no_patch`, but the callers read and write the shared non-atomic `Key` outside that mutex, which is a C++ data race and can also expose a stale/partially published key. Please make every access to `Key` use one synchronization scheme (for example, route initialization and reads through a locked helper or an atomic representation that preserves the descriptor ABI), and add a test that races first access from multiple threads and verifies a single registered key and distinct per-thread blocks. Local `python3 tools/check_conventions.py --base upstream/main --head upstream/pr/11284` and `git diff --check upstream/main...upstream/pr/11284` pass. Hosted Linux relinker/ASan and policy checks pass; macOS relinker, macOS register-context, and other listed macOS jobs are still pending. I have not run macOS product tests locally.
MarcZX10 commented 2026-10-26 00:21:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-26T00:21:24Z.

Review: CHANGES_REQUESTED


Re-reviewed exact head 988eabf3dc3448b9cc1d51c267ec72f1ebe8d0d5. The new RegisteredKey helper uses an acquire/release atomic_ref for each access to GuestTlsDescriptor::Key, and the added concurrent first-access test exercises registration through both TLS entry paths. That addresses my earlier data-race finding; the author reports the focused test and ThreadSanitizer pass, which I have not independently reproduced.

There is still a macOS main-thread gap in the video path. presentLoop runs on presentThread and calls windowExtensions(window.Handle()) both at startup and in processFlip; windowExtensions invokes SDL_Vulkan_GetInstanceExtensions without RunOnMainThread. It also passes windowDrawableSize to the presentation driver; that callback calls SDL_GetWindowFlags and SDL_Vulkan_GetDrawableSize directly, and presentLoop calls SDL_GetWindowSize directly after a flip. These are SDL video/window operations on worker or renderer threads. SDL2's own FAQ says SDL video functions should be called from the application's main thread: https://wiki.libsdl.org/SDL2/FAQDevelopment#can-i-call-sdl-video-functions-from-multiple-threads. Please marshal these paths through the main-thread helper (including the actual thread that invokes the drawable-size callback), or provide an exact-head macOS test demonstrating that these specific calls are safe on the supported SDL/Cocoa backend. The current PR says the full libc and libSceVideoOut product cannot link on macOS, so the older ccleste smoke run on #8658 does not verify these new call paths.

Current hosted conventions, eligibility, labels and report checks pass; cross-platform relinker and macOS register-context/write-watch checks are still pending. Product builds are path-skipped.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5646143254 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11284#pullrequestreview-5646143254). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-26T00:21:24Z. **Review:** CHANGES_REQUESTED --- Re-reviewed exact head `988eabf3dc3448b9cc1d51c267ec72f1ebe8d0d5`. The new `RegisteredKey` helper uses an acquire/release `atomic_ref` for each access to `GuestTlsDescriptor::Key`, and the added concurrent first-access test exercises registration through both TLS entry paths. That addresses my earlier data-race finding; the author reports the focused test and ThreadSanitizer pass, which I have not independently reproduced. There is still a macOS main-thread gap in the video path. `presentLoop` runs on `presentThread` and calls `windowExtensions(window.Handle())` both at startup and in `processFlip`; `windowExtensions` invokes `SDL_Vulkan_GetInstanceExtensions` without `RunOnMainThread`. It also passes `windowDrawableSize` to the presentation driver; that callback calls `SDL_GetWindowFlags` and `SDL_Vulkan_GetDrawableSize` directly, and `presentLoop` calls `SDL_GetWindowSize` directly after a flip. These are SDL video/window operations on worker or renderer threads. SDL2's own FAQ says SDL video functions should be called from the application's main thread: https://wiki.libsdl.org/SDL2/FAQDevelopment#can-i-call-sdl-video-functions-from-multiple-threads. Please marshal these paths through the main-thread helper (including the actual thread that invokes the drawable-size callback), or provide an exact-head macOS test demonstrating that these specific calls are safe on the supported SDL/Cocoa backend. The current PR says the full libc and libSceVideoOut product cannot link on macOS, so the older ccleste smoke run on #8658 does not verify these new call paths. Current hosted conventions, eligibility, labels and report checks pass; cross-platform relinker and macOS register-context/write-watch checks are still pending. Product builds are path-skipped.
MarcZX10 commented 2026-10-26 00:35:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-26T00:35:31Z.

Review: CHANGES_REQUESTED


Follow-up on exact head ee2bfe5dbb9a1053d096f334e9b04381f8e75fba: the new wrappers now marshal windowExtensions, windowDrawableSize, and the post-flip size query, which addresses those paths from my previous review. One main-thread violation remains in the event path:

  • VideoOutDriver::presentLoop runs on presentThread and calls padInput.HandleEvent. That can call DisplayWindow::ToggleFullscreen (PadInput.cpp), where SDL_GetWindowFlags(window) is still evaluated before the RunOnMainThread wrapper around SDL_SetWindowFullscreen. Please move both the flags read and fullscreen update into the main-thread closure.
  • The same presentLoop calls SDL_GetWindowID for mouse, keyboard, and IME event routing. SDL_GetWindowID is part of SDL's video API; SDL's FAQ says video functions should only be called on the application main thread (https://wiki.libsdl.org/SDL2/FAQDevelopment). Please marshal these queries or capture the window ID while on the main thread and use the captured value in the event loop.

There is also a diagnostic issue in the new initialization wrapper: SDL_InitSubSystem runs inside RunOnMainThread, but on failure the subsequent SDL_GetError() runs on the calling thread. SDL documents error strings as per-thread (https://wiki.libsdl.org/SDL2/SDL_GetError), so that message can lose the actual initialization error. Capture/copy the error inside the dispatched closure.

The current head's macOS compile/test checks are still pending, and this environment has no macOS or Vulkan device to reproduce them. Please address the remaining video calls, retain the exact-head macOS compile/focused test evidence, and rerun the relevant checks before requesting another review.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5646193049 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11284#pullrequestreview-5646193049). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-26T00:35:31Z. **Review:** CHANGES_REQUESTED --- Follow-up on exact head `ee2bfe5dbb9a1053d096f334e9b04381f8e75fba`: the new wrappers now marshal `windowExtensions`, `windowDrawableSize`, and the post-flip size query, which addresses those paths from my previous review. One main-thread violation remains in the event path: - `VideoOutDriver::presentLoop` runs on `presentThread` and calls `padInput.HandleEvent`. That can call `DisplayWindow::ToggleFullscreen` (`PadInput.cpp`), where `SDL_GetWindowFlags(window)` is still evaluated before the `RunOnMainThread` wrapper around `SDL_SetWindowFullscreen`. Please move both the flags read and fullscreen update into the main-thread closure. - The same `presentLoop` calls `SDL_GetWindowID` for mouse, keyboard, and IME event routing. `SDL_GetWindowID` is part of SDL's video API; SDL's FAQ says video functions should only be called on the application main thread (https://wiki.libsdl.org/SDL2/FAQDevelopment). Please marshal these queries or capture the window ID while on the main thread and use the captured value in the event loop. There is also a diagnostic issue in the new initialization wrapper: `SDL_InitSubSystem` runs inside `RunOnMainThread`, but on failure the subsequent `SDL_GetError()` runs on the calling thread. SDL documents error strings as per-thread (https://wiki.libsdl.org/SDL2/SDL_GetError), so that message can lose the actual initialization error. Capture/copy the error inside the dispatched closure. The current head's macOS compile/test checks are still pending, and this environment has no macOS or Vulkan device to reproduce them. Please address the remaining video calls, retain the exact-head macOS compile/focused test evidence, and rerun the relevant checks before requesting another review.
MarcZX10 commented 2026-10-26 00:37:01 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-26T00:37:01Z.

Review: CHANGES_REQUESTED


Reviewed exact head d67dc5ba43d616b34a4929df230adbc732b9fdbb. The new mouse-mode operations now marshal to main, but the remaining SDL video calls and thread-local error handling still need attention:

  • VideoOutDriver::presentLoop calls padInput.HandleEvent on presentThread. That path reaches DisplayWindow::ToggleFullscreen, whose SDL_GetWindowFlags(window) remains outside RunOnMainThread; only SDL_SetWindowFullscreen is marshaled. The event handlers also call SDL_GetWindowID directly for mouse, keyboard and IME routing. These are SDL video API calls from the presentation thread. SDL's SDL2 FAQ says video functions should only be called from the application main thread: https://wiki.libsdl.org/SDL2/FAQDevelopment. Please marshal those queries or capture the needed values on the main thread.
  • The latest PadInput::setMouseMode and MouseInput::UpdateCapture changes call SDL_SetRelativeMouseMode on main but call SDL_GetError on the caller thread when it fails. The earlier SDL_InitSubSystem wrapper has the same problem. SDL2 error strings are per-thread (https://wiki.libsdl.org/SDL2/SDL_GetError), so copy the error inside the RunOnMainThread closure and report that copy outside it.

The newest head's conventions/report checks are still running, and there is no macOS device in this environment for an independent compile or runtime check. Please address these paths and provide exact-head macOS compile/focused-test results before requesting another review.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5646198198 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11284#pullrequestreview-5646198198). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-26T00:37:01Z. **Review:** CHANGES_REQUESTED --- Reviewed exact head `d67dc5ba43d616b34a4929df230adbc732b9fdbb`. The new mouse-mode operations now marshal to main, but the remaining SDL video calls and thread-local error handling still need attention: - `VideoOutDriver::presentLoop` calls `padInput.HandleEvent` on `presentThread`. That path reaches `DisplayWindow::ToggleFullscreen`, whose `SDL_GetWindowFlags(window)` remains outside `RunOnMainThread`; only `SDL_SetWindowFullscreen` is marshaled. The event handlers also call `SDL_GetWindowID` directly for mouse, keyboard and IME routing. These are SDL video API calls from the presentation thread. SDL's SDL2 FAQ says video functions should only be called from the application main thread: https://wiki.libsdl.org/SDL2/FAQDevelopment. Please marshal those queries or capture the needed values on the main thread. - The latest `PadInput::setMouseMode` and `MouseInput::UpdateCapture` changes call `SDL_SetRelativeMouseMode` on main but call `SDL_GetError` on the caller thread when it fails. The earlier `SDL_InitSubSystem` wrapper has the same problem. SDL2 error strings are per-thread (https://wiki.libsdl.org/SDL2/SDL_GetError), so copy the error inside the `RunOnMainThread` closure and report that copy outside it. The newest head's conventions/report checks are still running, and there is no macOS device in this environment for an independent compile or runtime check. Please address these paths and provide exact-head macOS compile/focused-test results before requesting another review.
MarcZX10 commented 2026-10-26 05:47:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-26T05:47:29Z.

Review: DISMISSED


I rechecked the latest head 38a945da2b1c6a576a0399c482d732de318ebde3. The added cached window ID removes the remaining SDL_GetWindowID calls from presentation-thread routing, and ToggleFullscreen now reads flags inside the main-thread closure; SDL error text is copied while still in that closure. Those changes address the main-thread issues from my prior reviews. I cannot approve this revision yet because tools/check_main_sync.py --base upstream/main --head refs/review/pr11284-current reports 5 commits ahead and 196 behind current main (14c99b52ac), and the reported macOS compile/TSan/test results are from the older acb900c19 base. Please rebase/refresh and rerun the focused macOS TLS/video tests on the resulting exact head. Hosted policy checks pass; product and relinker jobs are path-skipped.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5647879366 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11284#pullrequestreview-5647879366). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-26T05:47:29Z. **Review:** DISMISSED --- I rechecked the latest head `38a945da2b1c6a576a0399c482d732de318ebde3`. The added cached window ID removes the remaining `SDL_GetWindowID` calls from presentation-thread routing, and `ToggleFullscreen` now reads flags inside the main-thread closure; SDL error text is copied while still in that closure. Those changes address the main-thread issues from my prior reviews. I cannot approve this revision yet because `tools/check_main_sync.py --base upstream/main --head refs/review/pr11284-current` reports 5 commits ahead and 196 behind current `main` (`14c99b52ac`), and the reported macOS compile/TSan/test results are from the older `acb900c19` base. Please rebase/refresh and rerun the focused macOS TLS/video tests on the resulting exact head. Hosted policy checks pass; product and relinker jobs are path-skipped.
jotitadev commented 2026-10-27 01:48:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-27T01:48:05Z.

Review: COMMENTED


Red to green on a Mac with real codesign, at head 27147acbb applied onto main 27ad7244d2.

Machine: Apple M2 Max, macOS 27.2, Xcode 27 clang, relinker-only Release, built both arm64-native and x86_64 (run under Rosetta 2, /usr/bin/python3 3.9.6).

Input: macos/import_fixture.py with the entry code replaced by mov eax, 42; ret, relinked with --macos --skip-sce-module. To run the output without the real runtime I put two x86_64 stub dylibs in libs/ (@rpath/libc.prx exporting the two NID symbols, @rpath/libkernel.prx with an Aps5StartGuest_nid_no_patch that calls the entry and exits with its return value). Then codesign -s - -f on a copy and ran both under Rosetta:

relinker header + load commands entryoff unsigned after codesign -s -
main 32 + 952 = 0x3d8 0x3e0 exit 42 exit 132 (SIGILL)
this PR 32 + 952 = 0x3d8 0x7e0 exit 42 exit 42

On main, codesign appends its 16-byte LC_CODE_SIGNATURE at 0x3d8 (1d000000 10000000 60300100 90030000), so the first 8 bytes of the entry stub at 0x3e0 become dataoff/datasize. Worth noting: codesign --verify -v on that broken binary still reports satisfies its Designated Requirement, so the corruption is silent until the first instruction runs. With the PR the same signing leaves the stub untouched and the signed output runs. The arm64-built and Rosetta-built relinkers write byte-identical output.

Full relinker-only suite with the PR: arm64 309/309, x86_64 under Rosetta 307/307 (same counts as main).

One gap: the PR adds no test, so nothing stops the reserve from regressing. A host-independent check in test_macos_output.py (entryoff >= 32 + sizeofcmds + 16, or >= ... + 0x400 to pin the reserve) would fail on main and pass here; on macOS hosts it could also codesign -s - the output and check that the bytes at entryoff are unchanged.

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

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5661321915 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11284#pullrequestreview-5661321915). Originally posted by [jotitadev](https://github.com/jotitadev) on 2026-10-27T01:48:05Z. **Review:** COMMENTED --- Red to green on a Mac with real `codesign`, at head `27147acbb` applied onto `main` `27ad7244d2`. Machine: Apple M2 Max, macOS 27.2, Xcode 27 clang, relinker-only Release, built both arm64-native and x86_64 (run under Rosetta 2, `/usr/bin/python3` 3.9.6). Input: `macos/import_fixture.py` with the entry code replaced by `mov eax, 42; ret`, relinked with `--macos --skip-sce-module`. To run the output without the real runtime I put two x86_64 stub dylibs in `libs/` (`@rpath/libc.prx` exporting the two NID symbols, `@rpath/libkernel.prx` with an `Aps5StartGuest_nid_no_patch` that calls the entry and exits with its return value). Then `codesign -s - -f` on a copy and ran both under Rosetta: | relinker | header + load commands | `entryoff` | unsigned | after `codesign -s -` | |---|---|---|---|---| | `main` | 32 + 952 = 0x3d8 | 0x3e0 | exit 42 | **exit 132 (SIGILL)** | | this PR | 32 + 952 = 0x3d8 | 0x7e0 | exit 42 | exit 42 | On `main`, `codesign` appends its 16-byte `LC_CODE_SIGNATURE` at 0x3d8 (`1d000000 10000000 60300100 90030000`), so the first 8 bytes of the entry stub at 0x3e0 become `dataoff`/`datasize`. Worth noting: `codesign --verify -v` on that broken binary still reports `satisfies its Designated Requirement`, so the corruption is silent until the first instruction runs. With the PR the same signing leaves the stub untouched and the signed output runs. The arm64-built and Rosetta-built relinkers write byte-identical output. Full relinker-only suite with the PR: arm64 309/309, x86_64 under Rosetta 307/307 (same counts as `main`). One gap: the PR adds no test, so nothing stops the reserve from regressing. A host-independent check in `test_macos_output.py` (`entryoff >= 32 + sizeofcmds + 16`, or `>= ... + 0x400` to pin the reserve) would fail on `main` and pass here; on macOS hosts it could also `codesign -s -` the output and check that the bytes at `entryoff` are unchanged. Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
jotitadev commented 2026-10-27 03:07:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-27T03:07:57Z.

Review: COMMENTED


Re-ran at head 1220ef855 merged onto main abed035468. Apple M2 Max, macOS 27.2, Xcode 27 clang, relinker-only Release, BUILD_TESTING=ON, built arm64-native and x86_64 (tests run under Rosetta 2 with /usr/bin/python3 3.9.6).

arm64 x86_64 / Rosetta 2
full suite, this PR 310/310 308/308
macos_output, main's MacOsImage.cpp fail: entry stub at 0x3e0 leaves under 0x400 bytes ... same
same, with the structural check line removed fail: codesign overwrote the entry stub same

The structural check fails first, so on main the codesign half never gets to run in your table. With that line removed, the codesign -s - -f comparison catches the overwritten entry stub on its own, on both architectures. Both halves of the test work independently.

guest_module_args and guest_zero_initializer pass here in the relinker-only builds: arm64 with and without the PR, and x86_64 under Rosetta 2 with it. The failures in your build look local to that build.

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

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5661773921 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11284#pullrequestreview-5661773921). Originally posted by [jotitadev](https://github.com/jotitadev) on 2026-10-27T03:07:57Z. **Review:** COMMENTED --- Re-ran at head `1220ef855` merged onto `main` `abed035468`. Apple M2 Max, macOS 27.2, Xcode 27 clang, relinker-only Release, `BUILD_TESTING=ON`, built arm64-native and x86_64 (tests run under Rosetta 2 with `/usr/bin/python3` 3.9.6). | | arm64 | x86_64 / Rosetta 2 | |---|---|---| | full suite, this PR | 310/310 | 308/308 | | `macos_output`, `main`'s `MacOsImage.cpp` | fail: `entry stub at 0x3e0 leaves under 0x400 bytes ...` | same | | same, with the structural check line removed | fail: `codesign overwrote the entry stub` | same | The structural check fails first, so on `main` the `codesign` half never gets to run in your table. With that line removed, the `codesign -s - -f` comparison catches the overwritten entry stub on its own, on both architectures. Both halves of the test work independently. `guest_module_args` and `guest_zero_initializer` pass here in the relinker-only builds: arm64 with and without the PR, and x86_64 under Rosetta 2 with it. The failures in your build look local to that build. 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!11284
No description provided.