fix(relinker): preserve weak imports in macOS guest modules #6105

Merged
Zinebyte merged 1 commit from upstream-pr/6105 into main 2026-10-17 10:44:42 +00:00
Zinebyte commented 2026-10-14 22:19:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Zinebyte on 2026-10-14T22:19:29Z.


What

A converted macOS guest module currently emits strong Mach-O binds for both weak and global undefined ELF symbols. An optional symbol therefore becomes a mandatory import, even though the macOS executable writer already preserves weak binding.

Pass the guest symbol's STB_WEAK binding to the existing Mach-O bind writer. Add a focused guest-module regression that checks the weak/strong opcodes and declared library dependency on all hosts. On macOS it also compiles a small x86-64 loader and providers with the system Clang, then checks missing/present weak imports, missing strong imports, and missing declared libraries in fresh processes.

The native probe uses RTLD_NOW | RTLD_LOCAL, matching the guest dynamic-loader API. It runs directly on Intel or through already-installed Rosetta on Apple Silicon. Local machines without x86-64 execution can skip native controls; hosted Darwin CI fails rather than skipping them. No Rosetta installation or workflow changes are added.

Tested

Linux x86-64, Release relinker-only build at upstream fa9365ca74: all 182 CTests pass (12.89 s). The new regression is also selected by ctest -L '^relinker$' -R '^macos_guest_weak_imports$' and passes. The standalone metadata regression fails against unchanged production on the optional import's strong bind opcode (0x40 instead of 0x41). The required import remains strong and the declared host library remains required. Independent adversarial review checked the fixture, branch displacements, runpaths, missing-import controls and hosted native-execution guard.

Hosted Build 38778017732 passed for PR head 5c378ece, merged into current main: Linux 183/183 tests, Windows 178/178 and macOS 174/174. The focused regression took 0.05 s, 0.25 s and 2.83 s respectively. The macOS probe passed all five native loader controls: 42 with the weak import absent, 77 with its provider present, and failure for missing required/global imports or a declared library. Hosted Darwin cannot skip these controls. Production and regression code are unchanged from the previously green revision; this update adds the component test label and rebases onto current main. Conventions passed. No retail-title result is claimed.

Manual review of all 21 peers named in the partial-comparison notice against main fa9365ca74 found no new conflict blocks from this PR. The macOS preinit metadata in #6112 composes with the weak bind flag; the other shared changes register unrelated tests or organize components. Their existing conflicts with main remain unchanged. The test now carries the relinker label so it also remains included in component-filtered runs if #6044 lands; this uses existing CMake functionality and does not depend on that PR.

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; no silent stubs added
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source (none added)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4865349898 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6105). Originally posted by [Zinebyte](https://github.com/Zinebyte) on 2026-10-14T22:19:29Z. --- ### What A converted macOS guest module currently emits strong Mach-O binds for both weak and global undefined ELF symbols. An optional symbol therefore becomes a mandatory import, even though the macOS executable writer already preserves weak binding. Pass the guest symbol's `STB_WEAK` binding to the existing Mach-O bind writer. Add a focused guest-module regression that checks the weak/strong opcodes and declared library dependency on all hosts. On macOS it also compiles a small x86-64 loader and providers with the system Clang, then checks missing/present weak imports, missing strong imports, and missing declared libraries in fresh processes. The native probe uses `RTLD_NOW | RTLD_LOCAL`, matching the guest dynamic-loader API. It runs directly on Intel or through already-installed Rosetta on Apple Silicon. Local machines without x86-64 execution can skip native controls; hosted Darwin CI fails rather than skipping them. No Rosetta installation or workflow changes are added. ### Tested Linux x86-64, Release relinker-only build at upstream `fa9365ca74`: all 182 CTests pass (12.89 s). The new regression is also selected by `ctest -L '^relinker$' -R '^macos_guest_weak_imports$'` and passes. The standalone metadata regression fails against unchanged production on the optional import's strong bind opcode (`0x40` instead of `0x41`). The required import remains strong and the declared host library remains required. Independent adversarial review checked the fixture, branch displacements, runpaths, missing-import controls and hosted native-execution guard. Hosted [Build 38778017732](https://github.com/boykopovar/AnyPS5/actions/runs/38778017732) passed for PR head `5c378ece`, merged into current main: Linux 183/183 tests, Windows 178/178 and macOS 174/174. The focused regression took 0.05 s, 0.25 s and 2.83 s respectively. The macOS probe passed all five native loader controls: 42 with the weak import absent, 77 with its provider present, and failure for missing required/global imports or a declared library. Hosted Darwin cannot skip these controls. Production and regression code are unchanged from the previously green revision; this update adds the component test label and rebases onto current main. Conventions passed. No retail-title result is claimed. Manual review of all 21 peers named in the partial-comparison notice against main `fa9365ca74` found no new conflict blocks from this PR. The macOS preinit metadata in #6112 composes with the weak bind flag; the other shared changes register unrelated tests or organize components. Their existing conflicts with main remain unchanged. The test now carries the `relinker` label so it also remains included in component-filtered runs if #6044 lands; this uses existing CMake functionality and does not depend on that PR. ### 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 - [x] Unimplemented paths throw; no silent stubs added - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source (none added) - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-15 12:14:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T12:14:48Z.


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
PR 6044 core/relinker/CMakeLists.txt
PR 6314 core/relinker/CMakeLists.txt
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6191797970 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6105#issuecomment-6191797970). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-15T12:14:48Z. --- <!-- 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 5021](https://www.github.com/boykopovar/AnyPS5/pull/5021) | `core/relinker/CMakeLists.txt` | | [PR 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `core/relinker/CMakeLists.txt` | | [PR 6314](https://www.github.com/boykopovar/AnyPS5/pull/6314) | `core/relinker/CMakeLists.txt` |
adriadam10 commented 2026-10-16 23:14:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-16T23:14:20Z.


Checked: STB_WEAK now reaches the existing Mach-O weak bind flag (MacOsGuestModuleWriter.cpp:86 → MacOsImage.cpp:613); required imports stay strong. The new macos_guest_weak_imports test fails without the change (verified by reverting the writer line) and passes with it; relinker jobs are green on Linux, Windows and macOS. Merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6226445334 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6105#issuecomment-6226445334). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-16T23:14:20Z. --- Checked: `STB_WEAK` now reaches the existing Mach-O weak bind flag (`MacOsGuestModuleWriter.cpp:86` → `MacOsImage.cpp:613`); required imports stay strong. The new `macos_guest_weak_imports` test fails without the change (verified by reverting the writer line) and passes with it; relinker jobs are green on Linux, Windows and macOS. Merging.
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!6105
No description provided.