fix(relinker): keep the host libc.prx needed on Linux when a title bundles its own #618

Merged
oneandonlydean merged 1 commit from upstream-pr/618 into main 2026-10-05 08:26:08 +00:00
oneandonlydean commented 2026-10-05 07:41:01 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-05T07:41:01Z.


What

On Linux, when a title ships its own sce_module/libc.prx, GuestModuleBuilder drops the host dependency whose name matches a guest module (addHost), so the executable no longer lists the host libc.prx. This PR applies the Windows rule from WindowsImportBuilder::ReadLibraries (f146a3d0) to the guest module builder: when libSceLibcInternal.prx is a host dependency and no host libc.prx remains, libc.prx is appended as the last host dependency.

  • It goes last, so the guest modules still come first in DT_NEEDED and the title's own imports keep binding to its own libc first (9cfdbff1).
  • Nothing changes when the title doesn't bundle libc.prx, or when it is left out with --exclude-sce-module libc.prx: the host libc.prx is still in the list there.
  • Windows output is unchanged: ReadLibraries already appends libc.prx in this case, and now finds it present.

Why

Part 1 of #476. Every host prx needs libc.prx, but their DT_RUNPATH is empty, so without the executable listing it the loader fails with libc.prx: cannot open shared object file.

This only fixes the load failure. It does not fix part 2 of #476: with both libcs loaded, the host libc's references to its own exports still bind to the title's libc through the global scope (_Stdout and friends). Titles such as PPSA21567 and PPSA02929 will get past the loader with this and then crash as described in #476, until that part has its own fix. -Bsymbolic is left out on purpose, since it breaks guest_standard_streams, guest_memory and guest_system_font (see the comments on #476).

Tested

  • Linux (CachyOS, x86-64, GCC): full build with BUILD_TESTING=ON; ctest passes (269/269).
  • New guest_host_libc relinks a fake executable that imports libkernel.prx, libc.prx and libSceLibcInternal.prx, and reads the output's DT_NEEDED:
    • with a bundled libc.prx: the list ends with the host libc.prx, after the guest modules and the other host libraries;
    • without libSceLibcInternal.prx: unchanged;
    • with no bundled libc.prx: unchanged;
    • with the bundled libc.prx left out by --exclude-sce-module libc.prx: unchanged.
  • The bundled case fails without the change and passes with it.
  • Not tested with a title that bundles libc.prx.

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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4741716037 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/618). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-05T07:41:01Z. --- ### What On Linux, when a title ships its own `sce_module/libc.prx`, `GuestModuleBuilder` drops the host dependency whose name matches a guest module (`addHost`), so the executable no longer lists the host `libc.prx`. This PR applies the Windows rule from `WindowsImportBuilder::ReadLibraries` (f146a3d0) to the guest module builder: when `libSceLibcInternal.prx` is a host dependency and no host `libc.prx` remains, `libc.prx` is appended as the last host dependency. - It goes last, so the guest modules still come first in `DT_NEEDED` and the title's own imports keep binding to its own libc first (9cfdbff1). - Nothing changes when the title doesn't bundle `libc.prx`, or when it is left out with `--exclude-sce-module libc.prx`: the host `libc.prx` is still in the list there. - Windows output is unchanged: `ReadLibraries` already appends `libc.prx` in this case, and now finds it present. ### Why Part 1 of #476. Every host prx needs `libc.prx`, but their `DT_RUNPATH` is empty, so without the executable listing it the loader fails with `libc.prx: cannot open shared object file`. This only fixes the load failure. It does **not** fix part 2 of #476: with both libcs loaded, the host libc's references to its own exports still bind to the title's libc through the global scope (`_Stdout` and friends). Titles such as PPSA21567 and PPSA02929 will get past the loader with this and then crash as described in #476, until that part has its own fix. `-Bsymbolic` is left out on purpose, since it breaks `guest_standard_streams`, `guest_memory` and `guest_system_font` (see the comments on #476). ### Tested - Linux (CachyOS, x86-64, GCC): full build with `BUILD_TESTING=ON`; `ctest` passes (269/269). - New `guest_host_libc` relinks a fake executable that imports `libkernel.prx`, `libc.prx` and `libSceLibcInternal.prx`, and reads the output's `DT_NEEDED`: - with a bundled `libc.prx`: the list ends with the host `libc.prx`, after the guest modules and the other host libraries; - without `libSceLibcInternal.prx`: unchanged; - with no bundled `libc.prx`: unchanged; - with the bundled `libc.prx` left out by `--exclude-sce-module libc.prx`: unchanged. - The bundled case fails without the change and passes with it. - Not tested with a title that bundles `libc.prx`. ### 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
ThisIsAkill commented 2026-10-05 12:34:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ThisIsAkill on 2026-10-05T12:34:14Z.


Tested on PPSA21567 (Astro Bot v01.018, which bundles sce_module/libc.prx), Linux, oneandonlydean's astrobot at 4be8b3e7 with #602 and this PR on top (this PR's guest_host_libc test imports a helper from #602's test, so it needs #602 underneath). guest_host_libc passes.

Part 1: fixed for libc, but this title still doesn't load without LD_LIBRARY_PATH.

  • The relinked executable now ends its DT_NEEDED list with the host libc.prx (62 entries, 61 before).
  • Without LD_LIBRARY_PATH, the libc.prx: cannot open shared object file failure is gone. All 4 launches now stop at the next missing library: libSceKeyboard.prx: cannot open shared object file (2 with the -Bsymbolic libc, 2 with the default libc).

The cause is the general one from #476, not libc-specific. The host prx carry an empty DT_RUNPATH, and the executable's own $ORIGIN/libs covers only its own DT_NEEDED. So any host-to-host dependency that the title doesn't import itself is never found. On this title that's exactly one: libSceVideoOut.prx needs libSceKeyboard.prx (linked the same way on main), and PPSA21567's executable doesn't import libSceKeyboard. I checked the rest of the dependency graph: no other host prx is reachable only through another host prx here. Other titles will differ.

Part 2: unchanged, as the PR says. With LD_LIBRARY_PATH set so that it loads:

  • default libc: 2 of 2 launches segfault at once, exit 139, libc.prx.guest.prx+0x7d35, the same crash as before;
  • -Bsymbolic libc: 2 of 2 run to the end of the 120 s window and render the Crash Site.

So -Bsymbolic (or a real part 2 fix) is still needed for this title.

A question for the load half: should the relinker add every transitive host dependency to the executable's DT_NEEDED, rather than only libc.prx? Or should the host prx get DT_RUNPATH=$ORIGIN, so they find each other in libs/? Either would cover libSceKeyboard and libc together.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5994537988 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/618#issuecomment-5994537988). Originally posted by [ThisIsAkill](https://github.com/ThisIsAkill) on 2026-10-05T12:34:14Z. --- Tested on PPSA21567 (Astro Bot v01.018, which bundles `sce_module/libc.prx`), Linux, oneandonlydean's `astrobot` at `4be8b3e7` with #602 and this PR on top (this PR's `guest_host_libc` test imports a helper from #602's test, so it needs #602 underneath). `guest_host_libc` passes. **Part 1: fixed for libc, but this title still doesn't load without `LD_LIBRARY_PATH`.** - The relinked executable now ends its `DT_NEEDED` list with the host `libc.prx` (62 entries, 61 before). - Without `LD_LIBRARY_PATH`, the `libc.prx: cannot open shared object file` failure is gone. All 4 launches now stop at the next missing library: `libSceKeyboard.prx: cannot open shared object file` (2 with the `-Bsymbolic` libc, 2 with the default libc). The cause is the general one from #476, not libc-specific. The host prx carry an empty `DT_RUNPATH`, and the executable's own `$ORIGIN/libs` covers only its own `DT_NEEDED`. So any host-to-host dependency that the title doesn't import itself is never found. On this title that's exactly one: `libSceVideoOut.prx` needs `libSceKeyboard.prx` (linked the same way on `main`), and PPSA21567's executable doesn't import `libSceKeyboard`. I checked the rest of the dependency graph: no other host prx is reachable only through another host prx here. Other titles will differ. **Part 2: unchanged, as the PR says.** With `LD_LIBRARY_PATH` set so that it loads: - default libc: 2 of 2 launches segfault at once, exit 139, `libc.prx.guest.prx+0x7d35`, the same crash as before; - `-Bsymbolic` libc: 2 of 2 run to the end of the 120 s window and render the Crash Site. So `-Bsymbolic` (or a real part 2 fix) is still needed for this title. A question for the load half: should the relinker add every transitive host dependency to the executable's `DT_NEEDED`, rather than only `libc.prx`? Or should the host prx get `DT_RUNPATH=$ORIGIN`, so they find each other in `libs/`? Either would cover `libSceKeyboard` and libc together.
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!618
No description provided.