fix(relinker): emit separate macOS run paths from ELF lists #5298

Merged
Ondra97 merged 1 commit from upstream-pr/5298 into main 2026-10-14 18:55:25 +00:00
Ondra97 commented 2026-10-13 16:42:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Ondra97 on 2026-10-13T16:42:59Z.


What

A --macos conversion with --rpath '$ORIGIN/first:$ORIGIN/second' wrote one LC_RPATH containing a literal colon and an untranslated second $ORIGIN. dyld therefore searched a different directory. Split the ELF list into separate load commands, translating each path for the executable or guest library and preserving order. Empty components fail explicitly before output. This follows Apple's run-path dependent library contract.

Tested

Windows, supported WinLibs GCC 15.2, Release relinker-only full build and 150/150 tests passed. The new actual Mach-O output regression failed on main with ['@executable_path/first:$ORIGIN/second']; after the fix, executable and guest module load commands contain separate correctly relocated paths. Absolute lists and empty-component rejection are covered. This is structural validation; no macOS title execution is claimed.

Local conventions and whitespace checks passed. Current open PRs were checked for overlapping files, lines and functions.

CI relinker builds and test suites passed on Linux, Windows and macOS for eb10acbfb (Build). Full runtime-library jobs were skipped by the automatic PR policy.

Combined local validation of #5283, #5286, #5298, #5302, #5305, #5308 and #5310 on main 61b8742b6: all seven patches merge without conflicts; the full relinker-only build and 150/150 CTest tests passed.

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

  • Unblocks: none

  • GPUs tested: n/a

  • AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4846465315 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5298). Originally posted by [Ondra97](https://github.com/Ondra97) on 2026-10-13T16:42:59Z. --- ### What A --macos conversion with --rpath '$ORIGIN/first:$ORIGIN/second' wrote one LC_RPATH containing a literal colon and an untranslated second $ORIGIN. dyld therefore searched a different directory. Split the ELF list into separate load commands, translating each path for the executable or guest library and preserving order. Empty components fail explicitly before output. This follows [Apple's run-path dependent library contract](https://developer.apple.com/library/archive/documentation/DeveloperTools/Conceptual/DynamicLibraries/100-Articles/RunpathDependentLibraries.html). ### Tested Windows, supported WinLibs GCC 15.2, Release relinker-only full build and 150/150 tests passed. The new actual Mach-O output regression failed on main with ['@executable_path/first:$ORIGIN/second']; after the fix, executable and guest module load commands contain separate correctly relocated paths. Absolute lists and empty-component rejection are covered. This is structural validation; no macOS title execution is claimed. Local conventions and whitespace checks passed. Current open PRs were checked for overlapping files, lines and functions. CI relinker builds and test suites passed on Linux, Windows and macOS for `eb10acbfb` ([Build](https://github.com/boykopovar/AnyPS5/actions/runs/38434790185)). Full runtime-library jobs were skipped by the automatic PR policy. Combined local validation of #5283, #5286, #5298, #5302, #5305, #5308 and #5310 on main `61b8742b6`: all seven patches merge without conflicts; the full relinker-only build and 150/150 CTest tests passed. ### 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) - [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 - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
simonbronk commented 2026-10-13 18:13:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by simonbronk on 2026-10-13T18:13:32Z.


Checked on a real Mac (macOS 27.0.1, Apple silicon, relinker-only Release), this PR (eb10acbfb) merged into main 18c438b10: 146/146 tests pass. I also converted a small executable plus one module with --macos --rpath '$ORIGIN/first:$ORIGIN/second' and read the output with Apple's otool -l:

  • main: one LC_RPATH each: @executable_path/first:$ORIGIN/second and @loader_path/../../first:$ORIGIN/../../second.
  • This PR: two each, @executable_path/first, @executable_path/second and @loader_path/../../first, @loader_path/../../second, in order.

AI-assisted: yes (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6152116705 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5298#issuecomment-6152116705). Originally posted by [simonbronk](https://github.com/simonbronk) on 2026-10-13T18:13:32Z. --- Checked on a real Mac (macOS 27.0.1, Apple silicon, relinker-only Release), this PR (`eb10acbfb`) merged into `main` `18c438b10`: 146/146 tests pass. I also converted a small executable plus one module with `--macos --rpath '$ORIGIN/first:$ORIGIN/second'` and read the output with Apple's `otool -l`: - `main`: one `LC_RPATH` each: `@executable_path/first:$ORIGIN/second` and `@loader_path/../../first:$ORIGIN/../../second`. - This PR: two each, `@executable_path/first`, `@executable_path/second` and `@loader_path/../../first`, `@loader_path/../../second`, in order. AI-assisted: yes (Claude Code).
thuanquang commented 2026-10-13 18:14:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by thuanquang on 2026-10-13T18:14:14Z.


Checked on macOS 27.0.1 (Apple silicon, Rosetta 2) with this PR merged into main 18c438b10; macos_output, guest_runpath and guest_module_args pass.

Runtime check with dyld, --macos --rpath '$ORIGIN/first:$ORIGIN/second' and an x86-64 libkernel.prx only in second/:

  • Executable: DYLD_PRINT_SEARCHING=1 shows first/libkernel.prx tried, then found: dylib-from-disk: ".../second/libkernel.prx". With main, dyld tries .../first:$ORIGIN/second/libkernel.prx and stops with Library not loaded: @rpath/libkernel.prx.
  • Converted module: LC_RPATH is @loader_path/../../first, @loader_path/../../second. Loading it from an x86-64 Python, as guest_module_args does, resolves libkernel.prx and libc.prx from second/, and its DT_INIT records the expected args/argp and result. With main the load fails on .../first:$ORIGIN/../../second/libc.prx. The module used a fixture with separate RX/RW segments, because dyld on macOS 27 refuses binds into the current RWX fixture (#5362).

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6152129374 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5298#issuecomment-6152129374). Originally posted by [thuanquang](https://github.com/thuanquang) on 2026-10-13T18:14:14Z. --- Checked on macOS 27.0.1 (Apple silicon, Rosetta 2) with this PR merged into `main` 18c438b10; `macos_output`, `guest_runpath` and `guest_module_args` pass. Runtime check with dyld, `--macos --rpath '$ORIGIN/first:$ORIGIN/second'` and an x86-64 `libkernel.prx` only in `second/`: - Executable: `DYLD_PRINT_SEARCHING=1` shows `first/libkernel.prx` tried, then `found: dylib-from-disk: ".../second/libkernel.prx"`. With `main`, dyld tries `.../first:$ORIGIN/second/libkernel.prx` and stops with `Library not loaded: @rpath/libkernel.prx`. - Converted module: `LC_RPATH` is `@loader_path/../../first`, `@loader_path/../../second`. Loading it from an x86-64 Python, as `guest_module_args` does, resolves `libkernel.prx` and `libc.prx` from `second/`, and its `DT_INIT` records the expected `args`/`argp` and result. With `main` the load fails on `.../first:$ORIGIN/../../second/libc.prx`. The module used a fixture with separate RX/RW segments, because dyld on macOS 27 refuses binds into the current RWX fixture (#5362). AI-assisted: yes (Claude Code)
adriadam10 commented 2026-10-14 18:33:01 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T18:33:01Z.


Checked that MachORunPaths splits the ELF list into one LC_RPATH per component for both the executable and guest modules, in order, with $ORIGIN translated per component and empty components rejected before any output is written. The new macos_output check fails without the change and passes with it; relinker build and ctest pass locally and on CI (linux, windows, macos), and the otool -l / dyld runs by @simonbronk and @thuanquang on macOS confirm the result. Merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6175510845 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5298#issuecomment-6175510845). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-14T18:33:01Z. --- Checked that `MachORunPaths` splits the ELF list into one `LC_RPATH` per component for both the executable and guest modules, in order, with `$ORIGIN` translated per component and empty components rejected before any output is written. The new `macos_output` check fails without the change and passes with it; relinker build and ctest pass locally and on CI (linux, windows, macos), and the `otool -l` / dyld runs by @simonbronk and @thuanquang on macOS confirm the result. 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!5298
No description provided.