test(relinker): run the macOS guest module argument check under Rosetta #7519

Merged
Destroyers212x merged 1 commit from upstream-pr/7519 into main 2026-10-19 22:35:23 +00:00
Destroyers212x commented 2026-10-18 11:14:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Destroyers212x on 2026-10-18T11:14:22Z.


What

test_guest_module_args.py loads the converted Mach-O module to check the arguments its initializer receives. It ran that check only when Python itself reports x86_64. On Apple silicon, Python is arm64, including in the relinker (macos-latest, clang++, x86_64) job from #7322, so the check was skipped there ("native execution skipped") even though the host library and module are x86-64.

The macOS branch now keys on the host library's architecture: an x86-64 Mach-O, read from its header. It loads through a small x86-64 C loader built with xcrun clang -arch x86_64 and started with /usr/bin/arch -x86_64 on arm64, the same pattern test_macos_guest_weak_imports.py uses. The loader does what the Python --load path does: it dlopens the host with RTLD_GLOBAL, calls SetPendingArgs(ARGS, ARGP), then dlopens the module. A native arm64 build still skips the check, because its host library is arm64 and cannot load the x86-64 module. Linux is unchanged.

#6149 adds a Linux-only case to the same file in a different block; whichever merges second needs a small rebase.

Tested

Apple M1, macOS 26.6.2, AppleClang, arm64 Python 3.11, relinker-only Release builds with the CI configure line:

  • -DCMAKE_OSX_ARCHITECTURES=x86_64: guest_module_args prints "Guest module argument tests passed" (previously "...: native execution skipped"). guest_deferred_dependencies and macos_guest_weak_imports pass.
  • Native arm64: "Guest module argument tests passed: native execution skipped", as before.
  • With the loader given ARGS + 1, the test fails with AssertionError: args=1122334455667789 ..., so the check does reach the module's initializer.
  • 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
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes (Claude Code)

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4908596396 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7519). Originally posted by [Destroyers212x](https://github.com/Destroyers212x) on 2026-10-18T11:14:22Z. --- ### What `test_guest_module_args.py` loads the converted Mach-O module to check the arguments its initializer receives. It ran that check only when Python itself reports `x86_64`. On Apple silicon, Python is arm64, including in the `relinker (macos-latest, clang++, x86_64)` job from #7322, so the check was skipped there ("native execution skipped") even though the host library and module are x86-64. The macOS branch now keys on the host library's architecture: an x86-64 Mach-O, read from its header. It loads through a small x86-64 C loader built with `xcrun clang -arch x86_64` and started with `/usr/bin/arch -x86_64` on arm64, the same pattern `test_macos_guest_weak_imports.py` uses. The loader does what the Python `--load` path does: it `dlopen`s the host with `RTLD_GLOBAL`, calls `SetPendingArgs(ARGS, ARGP)`, then `dlopen`s the module. A native arm64 build still skips the check, because its host library is arm64 and cannot load the x86-64 module. Linux is unchanged. #6149 adds a Linux-only case to the same file in a different block; whichever merges second needs a small rebase. ### Tested Apple M1, macOS 26.6.2, AppleClang, arm64 Python 3.11, relinker-only Release builds with the CI configure line: - `-DCMAKE_OSX_ARCHITECTURES=x86_64`: `guest_module_args` prints "Guest module argument tests passed" (previously "...: native execution skipped"). `guest_deferred_dependencies` and `macos_guest_weak_imports` pass. - Native arm64: "Guest module argument tests passed: native execution skipped", as before. - With the loader given `ARGS + 1`, the test fails with `AssertionError: args=1122334455667789 ...`, so the check does reach the module's initializer. - `python3 tools/check_conventions.py --base origin/main` passes. ### 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 - [x] Fixes: none - [x] Unblocks: none - [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-18 11:35:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-18T11:35:04Z.


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 6149 core/relinker/relinker/tests/test_guest_module_args.py
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6249430381 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7519#issuecomment-6249430381). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-18T11:35:04Z. --- <!-- 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 6149](https://www.github.com/boykopovar/AnyPS5/pull/6149) | `core/relinker/relinker/tests/test_guest_module_args.py` |
imellag commented 2026-10-18 13:53:36 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by imellag on 2026-10-18T13:53:36Z.


Tested on an Apple M4 Pro (MacBook Pro, 24 GB), macOS 27.0.1 (26A434), Rosetta 2, Apple clang 21.0.0, CMake 4.4.4, Ninja 1.13.2, Xcode's Python 3.9.6 (runs as arm64).

PR head f08068ff5 merged into current main (385ed71f2), relinker-only Release builds with the CI configure line:

Build guest_module_args Full ctest
-DCMAKE_OSX_ARCHITECTURES=x86_64 "Guest module argument tests passed" (on main: "native execution skipped") 188/188
native arm64 "native execution skipped", as before 188/188

guest_module_args_host.prx is x86_64 in the first build and arm64 in the second, so macho_x86_64 picks the expected branch in both.

Negative controls on the x86_64 build, editing only the loader source in the test and restoring it afterwards:

  • loader passes ARGS + 1: fails with AssertionError: args=1122334455667789 argp=99aabbccddeeff00 (your control, reproduced here);
  • loader never calls SetPendingArgs: fails with AssertionError: args=0000000000000000 argp=0000000000000000, so the recorded values reach the module initializer through the host library and are not a default.

--repeat until-fail:20 on the x86_64 build: 20/20, about 0.5 s per run including the loader compile. guest_deferred_dependencies and macos_guest_weak_imports pass in the same build.

Not checked: Linux and Windows (their branches are unchanged), and guest_module_fini, which still skips on macOS because it converts to Linux ELF only.

AI-assisted: yes (Claude Code). I ran all of the above on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6250729758 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7519#issuecomment-6250729758). Originally posted by [imellag](https://github.com/imellag) on 2026-10-18T13:53:36Z. --- Tested on an Apple M4 Pro (MacBook Pro, 24 GB), macOS 27.0.1 (26A434), Rosetta 2, Apple clang 21.0.0, CMake 4.4.4, Ninja 1.13.2, Xcode's Python 3.9.6 (runs as arm64). PR head `f08068ff5` merged into current `main` (`385ed71f2`), relinker-only Release builds with the CI configure line: | Build | `guest_module_args` | Full ctest | |---|---|---| | `-DCMAKE_OSX_ARCHITECTURES=x86_64` | "Guest module argument tests passed" (on `main`: "native execution skipped") | 188/188 | | native arm64 | "native execution skipped", as before | 188/188 | `guest_module_args_host.prx` is x86_64 in the first build and arm64 in the second, so `macho_x86_64` picks the expected branch in both. Negative controls on the x86_64 build, editing only the loader source in the test and restoring it afterwards: - loader passes `ARGS + 1`: fails with `AssertionError: args=1122334455667789 argp=99aabbccddeeff00` (your control, reproduced here); - loader never calls `SetPendingArgs`: fails with `AssertionError: args=0000000000000000 argp=0000000000000000`, so the recorded values reach the module initializer through the host library and are not a default. `--repeat until-fail:20` on the x86_64 build: 20/20, about 0.5 s per run including the loader compile. `guest_deferred_dependencies` and `macos_guest_weak_imports` pass in the same build. Not checked: Linux and Windows (their branches are unchanged), and `guest_module_fini`, which still skips on macOS because it converts to Linux ELF only. AI-assisted: yes (Claude Code). I ran all of the above on my machine.
adriadam10 commented 2026-10-19 22:36:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-19T22:36:19Z.


Read the diff and checked CI on the current head, including the new relinker (macos-latest, clang++, x86_64) job; the x86-64 loader mirrors the Python --load path, native arm64 still skips, Linux is unchanged. Also confirmed on an M4 Pro by @imellag; merged.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6278883049 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7519#issuecomment-6278883049). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-19T22:36:19Z. --- Read the diff and checked CI on the current head, including the new `relinker (macos-latest, clang++, x86_64)` job; the x86-64 loader mirrors the Python `--load` path, native arm64 still skips, Linux is unchanged. Also confirmed on an M4 Pro by @imellag; merged.
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!7519
No description provided.