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

Merged
RockENZO merged 1 commit from upstream-pr/7361 into main 2026-10-19 18:41:17 +00:00
RockENZO commented 2026-10-18 02:05:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by RockENZO on 2026-10-18T02:05:43Z.


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 195d0d08a. 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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4905643688 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7361). Originally posted by [RockENZO](https://github.com/RockENZO) on 2026-10-18T02:05:43Z. --- ### 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](https://github.com/apple-oss-distributions/xnu/blob/main/EXTERNAL_HEADERS/mach-o/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` 195d0d08a. 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. <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> ### 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 <!-- #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 -->
github-actions[bot] commented 2026-10-18 02:16:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-18T02:16:26Z.


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
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6244633412 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7361#issuecomment-6244633412). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-18T02:16:26Z. --- <!-- 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 2780](https://www.github.com/boykopovar/AnyPS5/pull/2780) | `core/relinker/CMakeLists.txt` | | [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 6618](https://www.github.com/boykopovar/AnyPS5/pull/6618) | `core/relinker/CMakeLists.txt` | | [PR 6879](https://www.github.com/boykopovar/AnyPS5/pull/6879) | `core/relinker/CMakeLists.txt` | | [PR 6977](https://www.github.com/boykopovar/AnyPS5/pull/6977) | `core/relinker/CMakeLists.txt` | | [PR 7417](https://www.github.com/boykopovar/AnyPS5/pull/7417) | `core/relinker/CMakeLists.txt` |
adriadam10 commented 2026-10-19 18:44:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-19T18:44:09Z.


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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6274630065 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7361#issuecomment-6274630065). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-19T18:44:09Z. --- 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.
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!7361
No description provided.