fix(libs): keep a $ORIGIN runpath in the patched prx libraries #732

Merged
alfalfa-star merged 2 commits from upstream-pr/732 into main 2026-10-07 03:45:29 +00:00
alfalfa-star commented 2026-10-05 18:20:36 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by alfalfa-star on 2026-10-05T18:20:36Z.


What

Since #225, libSceVideoOut.prx has DT_NEEDED libSceKeyboard.prx. A title that does not import libSceKeyboard itself fails at startup on Linux:

./app.elf: error while loading shared libraries: libSceKeyboard.prx: cannot open shared object file: No such file or directory

The executable's DT_RUNPATH ($ORIGIN/libs) does not apply to the dependencies of a library, and the patched prx libraries ship with an empty runpath. The NID patcher rebuilds .dynstr keeping only the DT_NEEDED and DT_SONAME strings, so DT_RUNPATH kept a stale offset; the absolute build directory in it became "", or could have become a fragment of another name. A prx could load only the sibling prx that the executable already loads. libSceVideoOut's other dependencies (AgcDriver, Pad, Mouse) only work for the same reason.

  • The patcher keeps the DT_RPATH and DT_RUNPATH strings like DT_NEEDED and DT_SONAME.
  • The prx libraries are linked with a $ORIGIN runpath (BUILD_WITH_INSTALL_RPATH, INSTALL_RPATH "$ORIGIN") instead of the build directory, so they find each other in any directory they are copied to, and no build path is shipped. Windows ignores these properties.

Tested

  • Arch Linux, GCC 16.2, Release, based on 33e9a121. New nid_patcher_dynamic_strings test (Linux, Python): the patched guest_module_fixture keeps RUNPATH $ORIGIN and valid NEEDED names. With the patcher change reverted it fails with (29, ''). Full ctest: 293/293 apart from the three wave64 pixel tests that fail on main on this GPU (RX 9070 XT, RADV).
  • build/core/libs/libs/*.prx now all have RUNPATH [$ORIGIN]. dlopen of the patched libSceVideoOut.prx from another directory without LD_LIBRARY_PATH succeeds; the previous build fails on its first sibling dependency.
  • LEGO Horizon Adventures (PPSA14632), which does not import libSceKeyboard, needed LD_LIBRARY_PATH=libs to start before this change.
  • Windows not built or tested.

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 in TechnicalDebt
  • 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
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4749143842 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/732). Originally posted by [alfalfa-star](https://github.com/alfalfa-star) on 2026-10-05T18:20:36Z. --- ### What Since #225, `libSceVideoOut.prx` has `DT_NEEDED libSceKeyboard.prx`. A title that does not import libSceKeyboard itself fails at startup on Linux: ``` ./app.elf: error while loading shared libraries: libSceKeyboard.prx: cannot open shared object file: No such file or directory ``` The executable's `DT_RUNPATH` (`$ORIGIN/libs`) does not apply to the dependencies of a library, and the patched prx libraries ship with an empty runpath. The NID patcher rebuilds `.dynstr` keeping only the `DT_NEEDED` and `DT_SONAME` strings, so `DT_RUNPATH` kept a stale offset; the absolute build directory in it became `""`, or could have become a fragment of another name. A prx could load only the sibling prx that the executable already loads. libSceVideoOut's other dependencies (AgcDriver, Pad, Mouse) only work for the same reason. - The patcher keeps the `DT_RPATH` and `DT_RUNPATH` strings like `DT_NEEDED` and `DT_SONAME`. - The prx libraries are linked with a `$ORIGIN` runpath (`BUILD_WITH_INSTALL_RPATH`, `INSTALL_RPATH "$ORIGIN"`) instead of the build directory, so they find each other in any directory they are copied to, and no build path is shipped. Windows ignores these properties. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. --> - Arch Linux, GCC 16.2, Release, based on `33e9a121`. New `nid_patcher_dynamic_strings` test (Linux, Python): the patched `guest_module_fixture` keeps `RUNPATH $ORIGIN` and valid `NEEDED` names. With the patcher change reverted it fails with `(29, '')`. Full ctest: 293/293 apart from the three wave64 pixel tests that fail on `main` on this GPU (RX 9070 XT, RADV). - `build/core/libs/libs/*.prx` now all have `RUNPATH [$ORIGIN]`. `dlopen` of the patched `libSceVideoOut.prx` from another directory without `LD_LIBRARY_PATH` succeeds; the previous build fails on its first sibling dependency. - LEGO Horizon Adventures (PPSA14632), which does not import libSceKeyboard, needed `LD_LIBRARY_PATH=libs` to start before this change. - Windows not built or tested. ### 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 in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [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] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
oneandonlydean commented 2026-10-05 22:56:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-05T22:56:47Z.


The Linux re-run fails in the new test (run 37355223174):

AssertionError: [(14, 'libguest_module_fixture.so'), (29, '$ORIGIN')]

The runpath check passes; it's the needed assertion that fails, because the fixture has no DT_NEEDED entry at all on the runner. GuestModuleFixture.cpp uses nothing from libstdc++ or libc, and Ubuntu's GCC links with --as-needed by default, so every library gets dropped. Without --as-needed (my Linux setup, where the test passed) the same fixture needs libstdc++, libm, libgcc_s and libc. I checked that with a one-function shared library built both ways.

Either of these should fix it: link the fixture with -Wl,--no-as-needed so it keeps its DT_NEEDED entries, or point the test at one of the patched host prx that has a real DT_NEEDED on another prx. Dropping the non-empty check would also pass, but then the test no longer covers the needed names on CI.

The rest still looks good to me, and Windows is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6004892682 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/732#issuecomment-6004892682). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-05T22:56:47Z. --- The Linux re-run fails in the new test ([run 37355223174](https://github.com/boykopovar/AnyPS5/actions/runs/37355223174/job/112000758715)): ``` AssertionError: [(14, 'libguest_module_fixture.so'), (29, '$ORIGIN')] ``` The runpath check passes; it's the `needed` assertion that fails, because the fixture has no `DT_NEEDED` entry at all on the runner. `GuestModuleFixture.cpp` uses nothing from libstdc++ or libc, and Ubuntu's GCC links with `--as-needed` by default, so every library gets dropped. Without `--as-needed` (my Linux setup, where the test passed) the same fixture needs libstdc++, libm, libgcc_s and libc. I checked that with a one-function shared library built both ways. Either of these should fix it: link the fixture with `-Wl,--no-as-needed` so it keeps its `DT_NEEDED` entries, or point the test at one of the patched host prx that has a real `DT_NEEDED` on another prx. Dropping the non-empty check would also pass, but then the test no longer covers the needed names on CI. The rest still looks good to me, and Windows is green.
fisherjoey commented 2026-10-06 23:34:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by fisherjoey on 2026-10-06T23:34:06Z.


Tested with a real title on Linux: Demon's Souls (PPSA01341, v1.07), RTX 5070 Ti, Fedora 44. On main (c1241ad0) the relinked executable fails to start with libSceMouse.prx: cannot open shared object file. LD_DEBUG shows it is needed by libs/libSceVideoOut.prx, which has an empty RUNPATH. With this PR merged, the executable loads its libraries without LD_LIBRARY_PATH and reaches the title's main loop.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6027398881 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/732#issuecomment-6027398881). Originally posted by [fisherjoey](https://github.com/fisherjoey) on 2026-10-06T23:34:06Z. --- Tested with a real title on Linux: Demon's Souls (PPSA01341, v1.07), RTX 5070 Ti, Fedora 44. On `main` (c1241ad0) the relinked executable fails to start with `libSceMouse.prx: cannot open shared object file`. `LD_DEBUG` shows it is needed by `libs/libSceVideoOut.prx`, which has an empty RUNPATH. With this PR merged, the executable loads its libraries without `LD_LIBRARY_PATH` and reaches the title's main loop.
ThisIsAkill commented 2026-10-06 23:40:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ThisIsAkill on 2026-10-06T23:40:50Z.


Tested on PPSA21567 (Linux, RTX 3070, default build, PPSA21567 relinked with main's relinker, no LD_LIBRARY_PATH).

  • main 5895ea72 alone: the executable stops at load with libSceKeyboard.prx: cannot open shared object file. libSceVideoOut.prx needs it, and readelf -d shows Library runpath: [] on libSceVideoOut.prx, libSceKeyboard.prx and libkernel.prx.
  • With this PR merged locally on top (1d52422d): the patched prx report RUNPATH [$ORIGIN], and the loader finishes in 3 of 3 launches. Two of those were on main + this PR, the third with #285 added. Each later stopped at an unrelated GPU error.

Details on #476.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6027496101 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/732#issuecomment-6027496101). Originally posted by [ThisIsAkill](https://github.com/ThisIsAkill) on 2026-10-06T23:40:50Z. --- Tested on PPSA21567 (Linux, RTX 3070, default build, PPSA21567 relinked with `main`'s relinker, no `LD_LIBRARY_PATH`). - **`main` `5895ea72` alone:** the executable stops at load with `libSceKeyboard.prx: cannot open shared object file`. `libSceVideoOut.prx` needs it, and `readelf -d` shows `Library runpath: []` on `libSceVideoOut.prx`, `libSceKeyboard.prx` and `libkernel.prx`. - **With this PR merged locally on top (`1d52422d`):** the patched prx report `RUNPATH [$ORIGIN]`, and the loader finishes in 3 of 3 launches. Two of those were on `main` + this PR, the third with #285 added. Each later stopped at an unrelated GPU error. Details on #476.
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!732
No description provided.