Skip to content

fix(relinker): preserve executable exports in macOS output - #7361

Merged
adriadam10 merged 1 commit into
boykopovar:mainfrom
RockENZO:codex/macos-executable-exports
Oct 19, 2026
Merged

adriadam10 merged 1 commit into
boykopovar:mainfrom
RockENZO:codex/macos-executable-exports

Conversation

@RockENZO

@RockENZO RockENZO commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

What

macOS executables currently drop the defined dynamic symbols that the pipeline already preserves. A dependent library that imports a function or global from the main executable therefore fails to load, and dlsym cannot find those exports. The regression fixture converts successfully on current main, but running it under Rosetta aborts with symbol not found in flat namespace '_FixtureData'.

Populate the Mach-O executable export trie from the rebuilt dynamic symbol table. Preserve function/data addresses, 64-bit absolute values, weak-definition flags and protected visibility; omit hidden/local symbols. TLS exports use the existing descriptor representation and validate their range. Unsupported attributes/sections, duplicate stripped names and unmapped addresses fail explicitly.

The new test checks the trie on every host and, on macOS, runs the converted x86-64 executable with a small native dependency that imports and calls its function, reads its global and queries weak/absolute/protected exports through dlsym. This uses no game files or full runtime libraries. It is a loader prerequisite, not a claim that a particular game now runs.

Mach-O flag semantics follow Apple's loader.h: EXPORT_SYMBOL_FLAGS_KIND_ABSOLUTE, EXPORT_SYMBOL_FLAGS_WEAK_DEFINITION and MH_WEAK_DEFINES.

Overlap: tools/pr_overlap.py --branch codex/macos-executable-exports --repo boykopovar/AnyPS5 completed with no confirmed duplicate implementation or conflict. It could not compare shared files in already-conflicting PRs #2780, #5021, #6044, #6697, #6879, #6977 and #7332. Manual inspection found CMake registration changes in the first six; #7332 also changes macOS TLS/fixed-base code and does not implement executable exports. #6802 changes the patcher's load-image construction, not this export population. There is no functional dependency on those PRs; whichever lands later may need to rebase.

Tested

2026-10-19 revalidation: rebased onto upstream c820102bd03cc5ec4f3ebd35ccc20570e5d50f5d; head ec5c0dcd0cfcdd51cfe4056cfedb50b01ed998e5. git range-diff confirms the patch is unchanged. Fresh Release relinker-only builds on macOS 27.2 pass all 193 registered tests for arm64 and all 193 for x86-64 under Rosetta. Both runs execute the converted x86-64 export/import and dlsym probe successfully. input_magic and both macOS loader tests are registered. Conventions and whitespace checks pass. The original baseline evidence below remains historical; no game or full-runtime compatibility is claimed.

macOS 27.2, Apple Silicon, AppleClang 21.0.0.21000334, Release, based on main 195d0d0. CMake 4.4.4, Ninja 1.13.2, Python 3.9.6.

  • Before the change: the new test fails with an empty export trie; independently running the fixture aborts in dyld on the missing _FixtureData symbol.
  • After the change: the converted executable runs as x86-64 under Rosetta, binds the imported global, calls the exported function and passes its dlsym checks.
  • Relinker-only arm64 build: all 186 ctest tests pass.
  • Relinker-only x86-64 build under Rosetta: all 186 ctest tests pass, including the architecture-specific instruction execution checks.
  • Coverage includes ordinary/weak TLS descriptors and range failures; no native guest TLS-runtime execution is claimed by this new test.
  • The fixture's Linux and Windows outputs are byte-identical to the baseline (33,670 and 243,712 bytes). Linux and Windows host builds were not run locally.
  • python3 tools/check_conventions.py --base origin/main and git diff --check pass.

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

@github-actions

github-actions Bot commented Oct 18, 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 2780 core/relinker/CMakeLists.txt
PR 5021 core/relinker/CMakeLists.txt
PR 6044 core/relinker/CMakeLists.txt
PR 6618 core/relinker/CMakeLists.txt
PR 6879 core/relinker/CMakeLists.txt
PR 6977 core/relinker/CMakeLists.txt
PR 7417 core/relinker/CMakeLists.txt

ycarogabriel-lgtm added a commit to ycarogabriel-lgtm/AnyPS5 that referenced this pull request Oct 18, 2026
…in macOS output (@RockENZO)

Brings the macOS fix from the open upstream pull request into the fork's main ahead of its review, so the port runs with it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ycarogabriel-lgtm added a commit to ycarogabriel-lgtm/AnyPS5 that referenced this pull request Oct 18, 2026
…in macOS output (@RockENZO)

Includes the open upstream macOS pull request, as the fork's main does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@RockENZO
RockENZO force-pushed the codex/macos-executable-exports branch from 02c13a6 to ec5c0dc Compare October 18, 2026 22:31
ycarogabriel-lgtm added a commit to ycarogabriel-lgtm/AnyPS5 that referenced this pull request Oct 19, 2026
…in macOS output (@RockENZO)

This branch already carried an earlier head of this PR; the author has pushed newer commits since, and this merge brings the branch up to them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@adriadam10 adriadam10 self-assigned this Oct 19, 2026
@adriadam10
adriadam10 merged commit ae7ad5f into boykopovar:main Oct 19, 2026
10 of 11 checks passed
@adriadam10

Copy link
Copy Markdown
Collaborator

Checked the export population against the dynsym (function/data, absolute, weak, protected, hidden/local skipped), the TLS range validation, the MacOsExport field change (the other user in MacOsGuestModuleWriter.cpp still compiles with the positional initializer), and the new test (trie contents and flags, plus the failure cases); merged.

ycarogabriel-lgtm added a commit to ycarogabriel-lgtm/AnyPS5 that referenced this pull request Oct 25, 2026
…in macOS output (@RockENZO)

Brings the macOS fix from the open upstream pull request into the fork's main ahead of its review, so the port runs with 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