fix(relinker): validate Linux guest runpaths with target syntax #4801

Merged
ArjenS-LA merged 1 commit from upstream-pr/4801 into main 2026-10-14 01:45:58 +00:00
ArjenS-LA commented 2026-10-12 22:21:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ArjenS-LA on 2026-10-12T22:21:31Z.


What

Converting bundled guest modules to Linux output on Windows rejects --rpath /opt/libs, while accepting Windows drive paths as Linux search paths. Validate the target's leading / root independently of the host filesystem. Existing $ORIGIN behavior remains covered.

Tested

Windows x64 build 26200, supported WinLibs MinGW-w64 GCC 15.2.0 r7, Python 3.13.7, CMake 4.3.1, Ninja 1.13.2. The same final test_guest_runpath.py fails against a separately preserved main binary at /opt/absolute libs; the fix passes 32 module/path combinations and rejects four invalid paths before output creation. Tests inspect emitted ELF DT_RUNPATH.

Release relinker-only build with ANYPS5_RELINKER_ONLY=ON, BUILD_TESTING=ON, and an explicit working Python3_EXECUTABLE; ctest -N confirms input_magic is registered. Full ctest --test-dir build-relinker --output-on-failure -j 4: 138/138 passed, 34.78 seconds, with no groups excluded. Individual suites retain host-specific and Windows symlink-privilege skips. git diff --check and committed-object conventions checks pass.

Original regression baseline: ee496219007b05e054a469fe12330f7e38e5451a. Rebased onto current main 43e3a70f8143f014f621c48abbdb137fffd7346e and reran fixed validation. Fixed: e148cc6f9bb42c9d7ed83f7817f31879aeade835 on fix/guest-posix-runpath. No title, GPU, native Linux/macOS runtime, full library build, or upstream CI result is claimed.

Refreshed 472 open PRs across 5 pages, including full changed-file lists, against main 43e3a70f8143f014f621c48abbdb137fffd7346e. Shared-file implementations are unrelated SELF diagnostics: #4501 at 429c9421be7f85a22d6f4b14fe5f5fa3ac93120b, #4623 at 8fb0c165981020479fd458057ed095bed787b6b5. Tree-only merge previews on the explicit current-main base are clean. The three proposed changes also merge cleanly with one another. Related issue searches were reviewed; no issue matched this regression.

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
  • AI-assisted: yes, OpenAI Codex
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4835664368 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4801). Originally posted by [ArjenS-LA](https://github.com/ArjenS-LA) on 2026-10-12T22:21:31Z. --- ### What Converting bundled guest modules to Linux output on Windows rejects `--rpath /opt/libs`, while accepting Windows drive paths as Linux search paths. Validate the target's leading `/` root independently of the host filesystem. Existing `$ORIGIN` behavior remains covered. ### Tested Windows x64 build 26200, supported WinLibs MinGW-w64 GCC 15.2.0 r7, Python 3.13.7, CMake 4.3.1, Ninja 1.13.2. The same final `test_guest_runpath.py` fails against a separately preserved main binary at `/opt/absolute libs`; the fix passes 32 module/path combinations and rejects four invalid paths before output creation. Tests inspect emitted ELF `DT_RUNPATH`. Release relinker-only build with `ANYPS5_RELINKER_ONLY=ON`, `BUILD_TESTING=ON`, and an explicit working `Python3_EXECUTABLE`; `ctest -N` confirms `input_magic` is registered. Full `ctest --test-dir build-relinker --output-on-failure -j 4`: **138/138 passed**, 34.78 seconds, with no groups excluded. Individual suites retain host-specific and Windows symlink-privilege skips. `git diff --check` and committed-object conventions checks pass. Original regression baseline: `ee496219007b05e054a469fe12330f7e38e5451a`. Rebased onto current main `43e3a70f8143f014f621c48abbdb137fffd7346e` and reran fixed validation. Fixed: `e148cc6f9bb42c9d7ed83f7817f31879aeade835` on `fix/guest-posix-runpath`. No title, GPU, native Linux/macOS runtime, full library build, or upstream CI result is claimed. Refreshed 472 open PRs across 5 pages, including full changed-file lists, against main `43e3a70f8143f014f621c48abbdb137fffd7346e`. Shared-file implementations are unrelated SELF diagnostics: #4501 at `429c9421be7f85a22d6f4b14fe5f5fa3ac93120b`, #4623 at `8fb0c165981020479fd458057ed095bed787b6b5`. Tree-only merge previews on the explicit current-main base are clean. The three proposed changes also merge cleanly with one another. Related issue searches were reviewed; no issue matched this regression. ### Checklist - [ ] 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] AI-assisted: yes, OpenAI Codex
xXPBSXx commented 2026-10-13 04:52:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-13T04:52:37Z.


Windows test: head e148cc6f9 merged onto current main e51428bf2 (clean merge, no conflicts). Windows 10, MinGW GCC (WinLibs), Ninja Release, -j2: full build 0 errors; ctest with the filter ^guest_runpath$: guest_runpath passed (1 test(s), 0 failed); python tools/check_conventions.py --base upstream/main passed. I did not run the new tests against main without the change. The title names Linux, so this Windows run only shows that the change builds and the tests still pass on Windows.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6138507173 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4801#issuecomment-6138507173). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-13T04:52:37Z. --- Windows test: head `e148cc6f9` merged onto current `main` `e51428bf2` (clean merge, no conflicts). Windows 10, MinGW GCC (WinLibs), Ninja Release, `-j2`: full build 0 errors; ctest with the filter `^guest_runpath$`: guest_runpath passed (1 test(s), 0 failed); `python tools/check_conventions.py --base upstream/main` passed. I did not run the new tests against `main` without the change. The title names Linux, so this Windows run only shows that the change builds and the tests still pass on Windows. AI-assisted (Claude Code).
ArjenS-LA commented 2026-10-13 17:42:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ArjenS-LA on 2026-10-13T17:42:42Z.


@Ondra97: #5302 and this PR apply the same change in GuestModuleBuilder::Build: replace the host-dependent std::filesystem::path(runPath).is_absolute() check with runPath.starts_with('/') for non-Windows output. Could we agree which PR should carry the shared fix and combine the regression coverage?

I compared #4801 at e148cc6f9bb42c9d7ed83f7817f31879aeade835 with #5302 at 446a5893b73e1bcad0e7b60bd28f512cd55bc571, against main 8cf6a0bc3a17782e8f1063d1127f72419260230b. This PR additionally tests /, a colon-separated absolute path list, a relative path, and a backslash drive path; #5302 additionally inspects Mach-O executable and guest-module runpaths. Both touch core/relinker/relinker/src/guest/GuestModuleBuilder.cpp and core/relinker/relinker/tests/test_guest_runpath.py.

This PR already conflicts with main in GuestModuleBuilder.cpp; #5302's main preview is clean. The normalized pair preview reports both files, but this PR's pre-existing main conflict makes that pair result inconclusive. The duplicate predicate is established by source inspection. No dependency order is agreed, and I have not built or run a combined tree. AI-assisted: OpenAI Codex.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6151566752 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4801#issuecomment-6151566752). Originally posted by [ArjenS-LA](https://github.com/ArjenS-LA) on 2026-10-13T17:42:42Z. --- @Ondra97: #5302 and this PR apply the same change in `GuestModuleBuilder::Build`: replace the host-dependent `std::filesystem::path(runPath).is_absolute()` check with `runPath.starts_with('/')` for non-Windows output. Could we agree which PR should carry the shared fix and combine the regression coverage? I compared #4801 at `e148cc6f9bb42c9d7ed83f7817f31879aeade835` with #5302 at `446a5893b73e1bcad0e7b60bd28f512cd55bc571`, against main `8cf6a0bc3a17782e8f1063d1127f72419260230b`. This PR additionally tests `/`, a colon-separated absolute path list, a relative path, and a backslash drive path; #5302 additionally inspects Mach-O executable and guest-module runpaths. Both touch `core/relinker/relinker/src/guest/GuestModuleBuilder.cpp` and `core/relinker/relinker/tests/test_guest_runpath.py`. This PR already conflicts with main in `GuestModuleBuilder.cpp`; #5302's main preview is clean. The normalized pair preview reports both files, but this PR's pre-existing main conflict makes that pair result inconclusive. The duplicate predicate is established by source inspection. No dependency order is agreed, and I have not built or run a combined tree. AI-assisted: OpenAI Codex.
Ondra97 commented 2026-10-13 18:30:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Ondra97 on 2026-10-13T18:30:47Z.


@ArjenS-LA You are right: #5302 duplicates the predicate change already in #4801. I overlooked your PR during source review. I have closed #5302 so your older PR carries the shared fix.

Here is a test-only supplement against your unchanged head e148cc6f9bb42c9d7ed83f7817f31879aeade835. It preserves your 32 ELF module/path combinations and four invalid-path cases, and adds 12 Mach-O executable/guest-module checks for Unix absolute paths and /.

Validation: Windows, supported WinLibs GCC 15.2. The combined test passed all 32 ELF combinations, 12 Mach-O checks and four rejection cases. The validation binary was the previously built seven-fix combined checkout on main 61b8742b6, containing the identical target-path predicate; its full relinker-only suite passed 150/150. Please rerun this supplement against your rebased PR before merging. The Mach-O checks inspect output structure on Windows.

I also verified that the patch applies to your exact head. The shared production change remains in #4801.

--- a/core/relinker/relinker/tests/test_guest_runpath.py
+++ b/core/relinker/relinker/tests/test_guest_runpath.py
@@ -7,6 +7,7 @@
 from test_guest_module_directories import module_with_symbol
 from test_guest_intel_trampolines import PLAIN_SITE, guest_fixture
 from test_linux_dynamic_strings import DT_RUNPATH, dynamic_strings
+from test_macos_output import MachO
 
 
 def main():
@@ -15,6 +16,7 @@
         work = Path(directory)
         failures = []
         checked = 0
+        mac_checked = 0
         for index, module_directory in enumerate(("sce_module", "prx")):
             for label, run_path in (("default", None), ("origin", "$ORIGIN"),
                                     ("custom", "$ORIGIN/host libs"), ("absolute", "/opt/absolute libs"),
@@ -52,6 +54,16 @@
                     if resolved != expected or (label.startswith("absolute") and actual != run_path):
                         failures.append((str(relative), label, actual, str(resolved), str(expected)))
                     checked += 1
+                if label in ("absolute", "absolute-root"):
+                    mac_output = output.with_suffix(".macho")
+                    result = subprocess.run([str(relinker), "--macos", *options, str(source), str(mac_output)],
+                                            capture_output=True, text=True, timeout=20)
+                    assert result.returncode == 0, (result.stdout, result.stderr)
+                    assert MachO(mac_output.read_bytes()).rpaths == [run_path]
+                    mac_checked += 1
+                    for relative in (Path(module_directory) / "needed.prx.guest.prx", Path("sce_module/standard.prx.guest.prx")):
+                        assert MachO((output.parent / "app0" / relative).read_bytes()).rpaths == [run_path]
+                        mac_checked += 1
         for index, run_path in enumerate(("relative/libs", "C:/host/libs", "C:\\host\\libs", "\\\\server\\share")):
             output = work / f"invalid-{index}.elf"
             result = subprocess.run([str(relinker), "--rpath", run_path, str(source), str(output)],
@@ -60,7 +72,7 @@
                 run_path, result.returncode, result.stdout, result.stderr)
             assert not output.exists()
         assert not failures, failures
-        print(f"Guest run path tests passed: {checked} module/path combinations")
+        print(f"Guest run path tests passed: {checked} Linux module/path combinations, {mac_checked} Mach-O checks, 4 rejected invalid paths")
 
 
 if __name__ == "__main__":

AI-assisted: yes, OpenAI Codex.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6152428159 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4801#issuecomment-6152428159). Originally posted by [Ondra97](https://github.com/Ondra97) on 2026-10-13T18:30:47Z. --- @ArjenS-LA You are right: #5302 duplicates the predicate change already in #4801. I overlooked your PR during source review. I have closed #5302 so your older PR carries the shared fix. Here is a test-only supplement against your unchanged head `e148cc6f9bb42c9d7ed83f7817f31879aeade835`. It preserves your 32 ELF module/path combinations and four invalid-path cases, and adds 12 Mach-O executable/guest-module checks for Unix absolute paths and `/`. Validation: Windows, supported WinLibs GCC 15.2. The combined test passed all 32 ELF combinations, 12 Mach-O checks and four rejection cases. The validation binary was the previously built seven-fix combined checkout on main `61b8742b6`, containing the identical target-path predicate; its full relinker-only suite passed 150/150. Please rerun this supplement against your rebased PR before merging. The Mach-O checks inspect output structure on Windows. I also verified that the patch applies to your exact head. The shared production change remains in #4801. ```diff --- a/core/relinker/relinker/tests/test_guest_runpath.py +++ b/core/relinker/relinker/tests/test_guest_runpath.py @@ -7,6 +7,7 @@ from test_guest_module_directories import module_with_symbol from test_guest_intel_trampolines import PLAIN_SITE, guest_fixture from test_linux_dynamic_strings import DT_RUNPATH, dynamic_strings +from test_macos_output import MachO def main(): @@ -15,6 +16,7 @@ work = Path(directory) failures = [] checked = 0 + mac_checked = 0 for index, module_directory in enumerate(("sce_module", "prx")): for label, run_path in (("default", None), ("origin", "$ORIGIN"), ("custom", "$ORIGIN/host libs"), ("absolute", "/opt/absolute libs"), @@ -52,6 +54,16 @@ if resolved != expected or (label.startswith("absolute") and actual != run_path): failures.append((str(relative), label, actual, str(resolved), str(expected))) checked += 1 + if label in ("absolute", "absolute-root"): + mac_output = output.with_suffix(".macho") + result = subprocess.run([str(relinker), "--macos", *options, str(source), str(mac_output)], + capture_output=True, text=True, timeout=20) + assert result.returncode == 0, (result.stdout, result.stderr) + assert MachO(mac_output.read_bytes()).rpaths == [run_path] + mac_checked += 1 + for relative in (Path(module_directory) / "needed.prx.guest.prx", Path("sce_module/standard.prx.guest.prx")): + assert MachO((output.parent / "app0" / relative).read_bytes()).rpaths == [run_path] + mac_checked += 1 for index, run_path in enumerate(("relative/libs", "C:/host/libs", "C:\\host\\libs", "\\\\server\\share")): output = work / f"invalid-{index}.elf" result = subprocess.run([str(relinker), "--rpath", run_path, str(source), str(output)], @@ -60,7 +72,7 @@ run_path, result.returncode, result.stdout, result.stderr) assert not output.exists() assert not failures, failures - print(f"Guest run path tests passed: {checked} module/path combinations") + print(f"Guest run path tests passed: {checked} Linux module/path combinations, {mac_checked} Mach-O checks, 4 rejected invalid paths") if __name__ == "__main__": ``` AI-assisted: yes, OpenAI Codex.
oneandonlydean commented 2026-10-14 01:20:16 +00:00 (Migrated from github.com)

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


Rebased onto main to resolve the conflict in core/relinker/relinker/src/guest/GuestModuleBuilder.cpp after #5044; no other change.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6158736468 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4801#issuecomment-6158736468). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-14T01:20:16Z. --- Rebased onto main to resolve the conflict in `core/relinker/relinker/src/guest/GuestModuleBuilder.cpp` after #5044; no other change.
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!4801
No description provided.