fix(relinker): emit module-qualified guest imports in macOS output #21728

Merged
AasishDairelSahayaGrinspan merged 1 commit from upstream-pr/21728 into main 2026-11-26 01:38:44 +00:00
AasishDairelSahayaGrinspan commented 2026-11-16 17:18:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by AasishDairelSahayaGrinspan on 2026-11-16T17:18:26Z.


What

macOS output dropped module-qualified guest imports. When two bundled modules export the same NID, Linux rewrites the executable's imports to name#moduleN and binds them in the declared provider; on macOS every one of those steps was gated off (bindingName, the declared-provider rename/type check, executableProviders, guest-module importBindings, and BindingAliases), so an import needed from two providers failed conversion outright.

macOS now uses the same mechanism: the guest-module writer emits each BindingAliases entry as an extra Mach-O export (ordinary into Exports, TLS into TlsExports, weak flag copied), and dyld flat-namespace binds resolve the aliased name in the declared provider. The multi-provider rejection remains only when no provider is declared, matching Linux. BindNamedImportsByNid stays macOS-gated.

Evidence: technical debt entry 92 — "still use flat symbol lookup on macOS; the requested provider is not retained" — and the tested Linux provider-qualified path (test_linux_guest_qualified_imports.py).

Tested

Linux (Omarchy 4.0.2), relinker-only build (-DANYPS5_RELINKER_ONLY=ON, Release, BUILD_TESTING=ON):

  • Build: 376/376 targets, success.
  • Focused: macos_guest_qualified_imports|linux_guest_qualified_imports|macos_guest_weak_imports|macos_guest_weak_exports|guest_symbol_names|macos_output — 6/6 passed (new test 0.05 s).
  • Full relinker-only suite: 948/948 passed in 64 s.

The new fixture mirrors the macOS weak-import test and asserts the export trie and bind opcodes structurally; there is no Mach-O runtime on this machine, so runtime execution on macOS/Rosetta remains unmeasured and stays recorded in the debt entry.

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 and the licence notice of code adapted from upstream (see AGENTS.md)
  • 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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5341619092 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/21728). Originally posted by [AasishDairelSahayaGrinspan](https://github.com/AasishDairelSahayaGrinspan) on 2026-11-16T17:18:26Z. --- ### What macOS output dropped module-qualified guest imports. When two bundled modules export the same NID, Linux rewrites the executable's imports to `name#moduleN` and binds them in the declared provider; on macOS every one of those steps was gated off (`bindingName`, the declared-provider rename/type check, `executableProviders`, guest-module `importBindings`, and `BindingAliases`), so an import needed from two providers failed conversion outright. macOS now uses the same mechanism: the guest-module writer emits each `BindingAliases` entry as an extra Mach-O export (ordinary into `Exports`, TLS into `TlsExports`, weak flag copied), and dyld flat-namespace binds resolve the aliased name in the declared provider. The multi-provider rejection remains only when no provider is declared, matching Linux. `BindNamedImportsByNid` stays macOS-gated. Evidence: technical debt entry 92 — "still use flat symbol lookup on macOS; the requested provider is not retained" — and the tested Linux provider-qualified path (`test_linux_guest_qualified_imports.py`). ### Tested Linux (Omarchy 4.0.2), relinker-only build (`-DANYPS5_RELINKER_ONLY=ON`, Release, `BUILD_TESTING=ON`): - Build: 376/376 targets, success. - Focused: `macos_guest_qualified_imports|linux_guest_qualified_imports|macos_guest_weak_imports|macos_guest_weak_exports|guest_symbol_names|macos_output` — 6/6 passed (new test 0.05 s). - Full relinker-only suite: 948/948 passed in 64 s. The new fixture mirrors the macOS weak-import test and asserts the export trie and bind opcodes structurally; there is no Mach-O runtime on this machine, so runtime execution on macOS/Rosetta remains unmeasured and stays recorded in the debt entry. ### 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) and the licence notice of code adapted from upstream (see AGENTS.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 <!-- 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 <!-- 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 -->
kurexw commented 2026-11-17 06:14:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by kurexw on 2026-11-17T06:14:32Z.

Review: COMMENTED


Tested on macOS 27.2 on an Apple M4. This is an x86-64 build under Rosetta with Apple clang 21.0.0. As far as I can tell, this is the first macOS run of this PR; the description lists Linux only.

Method. I compared main at a72186d3cf with this PR merged onto it. The merge was clean. I ran the full relinker suite three times on each:

ctest --test-dir build/core/relinker
main (3 runs) This PR (3 runs)
Relinker suite 254/254 pass 255/255 pass
macos_guest_qualified_imports (absent) Passes
linux_guest_qualified_imports Passes Passes

The new test catches the bug. I kept this PR's tests and restored main's MacOsGuestModuleWriter.cpp and GuestModuleBuilder.cpp. Then macos_guest_qualified_imports fails at test_macos_guest_qualified_imports.py:65 with Ambiguous guest import shared ... exported by .../a.prx .../b.prx. That is the old gate refusing the input. With the PR's sources back in place, it passes.

Limitation. The new test checks the structure of the output: the export trie and the bind opcodes. It doesn't load the converted program with dyld or run it. So even on macOS, nothing here confirms that a module-qualified import actually binds to the right PRX at run time. A test that runs the converted fixture and checks which module's export it reached would cover that. I didn't run any title with this change.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5933865628 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/21728#pullrequestreview-5933865628). Originally posted by [kurexw](https://github.com/kurexw) on 2026-11-17T06:14:32Z. **Review:** COMMENTED --- Tested on macOS 27.2 on an Apple M4. This is an x86-64 build under Rosetta with Apple clang 21.0.0. As far as I can tell, this is the first macOS run of this PR; the description lists Linux only. **Method.** I compared `main` at a72186d3cf with this PR merged onto it. The merge was clean. I ran the full relinker suite three times on each: ``` ctest --test-dir build/core/relinker ``` | | main (3 runs) | This PR (3 runs) | | --- | --- | --- | | Relinker suite | 254/254 pass | 255/255 pass | | `macos_guest_qualified_imports` | (absent) | Passes | | `linux_guest_qualified_imports` | Passes | Passes | **The new test catches the bug.** I kept this PR's tests and restored `main`'s `MacOsGuestModuleWriter.cpp` and `GuestModuleBuilder.cpp`. Then `macos_guest_qualified_imports` fails at `test_macos_guest_qualified_imports.py:65` with `Ambiguous guest import shared ... exported by .../a.prx .../b.prx`. That is the old gate refusing the input. With the PR's sources back in place, it passes. **Limitation.** The new test checks the structure of the output: the export trie and the bind opcodes. It doesn't load the converted program with `dyld` or run it. So even on macOS, nothing here confirms that a module-qualified import actually binds to the right PRX at run time. A test that runs the converted fixture and checks which module's export it reached would cover that. I didn't run any title with this change.
MarcZX10 commented 2026-11-23 02:12:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-23T02:12:33Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this change; the synthetic fixtures cover declared-provider selection, ambiguous imports, aliases, and type mismatch handling.

What I ran

Reviewed head ab2b4bf377034922fab374e7deb64afa01b0bad2 against main using the prepared diff and repo_read.py at the pinned head. I did not run commands or tests; author-reported test results are not independently verified.

Results

Check Result Note
Diff and changed source passed All six changed files read
Automated tests not run Only author-reported results available
macOS runtime behavior not run No runtime execution verified

Findings

Blocking

None.

Non-blocking

None.

Not verified

Build and test results reported in the PR description; macOS or Rosetta runtime behavior. Read all changed files listed in the review manifest; no changed files were excluded.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6015841983 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/21728#pullrequestreview-6015841983). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-23T02:12:33Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this change; the synthetic fixtures cover declared-provider selection, ambiguous imports, aliases, and type mismatch handling. ## What I ran Reviewed head `ab2b4bf377034922fab374e7deb64afa01b0bad2` against `main` using the prepared diff and `repo_read.py` at the pinned head. I did not run commands or tests; author-reported test results are not independently verified. ## Results | Check | Result | Note | |---|---|---| | Diff and changed source | passed | All six changed files read | | Automated tests | not run | Only author-reported results available | | macOS runtime behavior | not run | No runtime execution verified | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified Build and test results reported in the PR description; macOS or Rosetta runtime behavior. Read all changed files listed in the review manifest; no changed files were excluded. ## To get this to a good state Nothing is required.
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!21728
No description provided.