Skip to content

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

Merged
adriadam10 merged 1 commit into
boykopovar:mainfrom
Zinebyte:fix/macos-guest-weak-imports
Oct 17, 2026
Merged

adriadam10 merged 1 commit into
boykopovar:mainfrom
Zinebyte:fix/macos-guest-weak-imports

Conversation

@Zinebyte

@Zinebyte Zinebyte commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

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

@Zinebyte
Zinebyte marked this pull request as ready for review October 14, 2026 22:26
This was referenced Oct 15, 2026
@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

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

@adriadam10 adriadam10 self-assigned this Oct 16, 2026
@adriadam10

Copy link
Copy Markdown
Collaborator

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.

@adriadam10
adriadam10 merged commit 864729d into boykopovar:main Oct 17, 2026
10 of 11 checks passed
ycarogabriel-lgtm added a commit to ycarogabriel-lgtm/AnyPS5 that referenced this pull request Oct 18, 2026
…rve weak imports in macOS guest modules (@Zinebyte)

Taken from the open upstream pull request so the macOS integration branch carries every piece of the port that is already under review, instead of re-implementing it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants