fix(relinker): accept the input's directory as a module directory #3850

Merged
SandstromPL merged 2 commits from upstream-pr/3850 into main 2026-10-12 03:07:28 +00:00
SandstromPL commented 2026-10-11 17:58:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by SandstromPL on 2026-10-11T17:58:18Z.


What

--module-dir . did not work for modules kept next to the executable, the layout Hades (PPSA03355) uses for libfmod.prx and libfmodstudio.prx, which it loads with dlopen("/app0/libfmod.prx") (#2724). Three problems:

  • The scan of a module directory read the input executable as a guest module and failed (ELF is not a shared module, reported in #2724). The input executable is now skipped when scanning module directories.
  • Modules in the module parent directory got app0/./<name>.guest.prx as output, runtime and Linux DT_NEEDED path. They now get app0/<name>.guest.prx, which is where dlopen looks (<requested path>.guest.prx, DynamicLoader.cpp:131). One helper builds the path for both uses.
  • (root / ".").lexically_normal() keeps a trailing separator, so the directory did not match the module's parent and the module was not treated as runtime-loaded (it went into Linux DT_NEEDED and was started without start arguments). #3509 fixes that normalization; this branch carries its commit unchanged.

Non-ELF files are still skipped, and the scan stays non-recursive, so sce_sys/ and dump folders are not walked (#2708). USAGE.md documents ..

Tested

Ubuntu 24.04, GCC 13.3.0, relinker-only build (-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON, Release): 114/114 tests pass.

  • guest_module_dir gains two cases, run for both Linux and Windows output:
    • a root-level runtime module with --module-dir .: it is written to app0/root.prx.guest.prx, stays out of DT_NEEDED on Linux, and exports __aps5_guest_initialize on Windows;
    • a root-level module the executable needs: Linux DT_NEEDED is $ORIGIN/app0/needed.prx.guest.prx.
  • Both new cases fail on #3509 alone, without this commit. The scan stops on the input (input.elf: Invalid string or symbol table), and with only the scan fix the path is $ORIGIN/app0/./root.prx.guest.prx.
  • Ran the reporter's command shape by hand with the test fixtures, relinker --windows --module-dir . game/eboot.elf app.exe with libfmod.prx next to eboot.elf: it writes game/app0/libfmod.prx.guest.prx. A second Linux run with the output .elf inside the module directory stops with the existing "Executable output would overwrite an input module" error. The output is deliberately not skipped by the scan, since skipping it would bypass that guard when the output path names a real module. An earlier relinked output left in a module directory is scanned like any other ELF there (true of every --module-dir), so the output belongs outside the game directory.
  • tools/check_conventions.py from main passes on this branch with this title and body.

Not tested: Windows host (the .exe run in the test only runs on Windows) or the title itself. I don't have a Hades dump. The reporter's workaround in #2724 (copying the .guest.prx files to app0/) is the layout this change produces.

Checklist

What

--module-dir . did not work for modules kept next to the executable, the layout Hades (PPSA03355) uses for libfmod.prx and libfmodstudio.prx, which it loads with dlopen("/app0/libfmod.prx") (#2724). Three problems:

  • The scan of a module directory read the input executable as a guest module and failed (ELF is not a shared module, reported in #2724). The input executable is now skipped when scanning module directories.
  • Modules in the module parent directory got app0/./<name>.guest.prx as output, runtime and Linux DT_NEEDED path. They now get app0/<name>.guest.prx, which is where dlopen looks (<requested path>.guest.prx, DynamicLoader.cpp:131). One helper builds the path for both uses.
  • (root / ".").lexically_normal() keeps a trailing separator, so the directory did not match the module's parent and the module was not treated as runtime-loaded (it went into Linux DT_NEEDED and was started without start arguments). #3509 fixes that normalization; this branch carries its commit unchanged.

Non-ELF files are still skipped, and the scan stays non-recursive, so sce_sys/ and dump folders are not walked (#2708). USAGE.md documents ..

Tested

Ubuntu 24.04, GCC 13.3.0, relinker-only build (-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON, Release): 114/114 tests pass.

  • guest_module_dir gains two cases, run for both Linux and Windows output:
    • a root-level runtime module with --module-dir .: it is written to app0/root.prx.guest.prx, stays out of DT_NEEDED on Linux, and exports __aps5_guest_initialize on Windows;
    • a root-level module the executable needs: Linux DT_NEEDED is $ORIGIN/app0/needed.prx.guest.prx.
  • Both new cases fail on #3509 alone, without this commit. The scan stops on the input (input.elf: Invalid string or symbol table), and with only the scan fix the path is $ORIGIN/app0/./root.prx.guest.prx.
  • Ran the reporter's command shape by hand with the test fixtures, relinker --windows --module-dir . game/eboot.elf app.exe with libfmod.prx next to eboot.elf: it writes game/app0/libfmod.prx.guest.prx. A second Linux run with the output .elf inside the module directory stops with the existing "Executable output would overwrite an input module" error. The output is deliberately not skipped by the scan, since skipping it would bypass that guard when the output path names a real module. An earlier relinked output left in a module directory is scanned like any other ELF there (true of every --module-dir), so the output belongs outside the game directory.
  • tools/check_conventions.py from main passes on this branch with this title and body.

Not tested: Windows host (the .exe run in the test only runs on Windows) or the title itself. I don't have a Hades dump. The reporter's workaround in #2724 (copying the .guest.prx files to app0/) is the layout this change produces.

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: #3509 (its commit is the first one on this branch; review only the second)
  • AI-assisted: yes (Claude Code); I reviewed and tested every line

Fixes #2724

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4821128385 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3850). Originally posted by [SandstromPL](https://github.com/SandstromPL) on 2026-10-11T17:58:18Z. --- ### What `--module-dir .` did not work for modules kept next to the executable, the layout Hades (PPSA03355) uses for `libfmod.prx` and `libfmodstudio.prx`, which it loads with `dlopen("/app0/libfmod.prx")` (#2724). Three problems: - The scan of a module directory read the input executable as a guest module and failed (`ELF is not a shared module`, reported in #2724). The input executable is now skipped when scanning module directories. - Modules in the module parent directory got `app0/./<name>.guest.prx` as output, runtime and Linux `DT_NEEDED` path. They now get `app0/<name>.guest.prx`, which is where `dlopen` looks (`<requested path>.guest.prx`, `DynamicLoader.cpp:131`). One helper builds the path for both uses. - `(root / ".").lexically_normal()` keeps a trailing separator, so the directory did not match the module's parent and the module was not treated as runtime-loaded (it went into Linux `DT_NEEDED` and was started without start arguments). #3509 fixes that normalization; this branch carries its commit unchanged. Non-ELF files are still skipped, and the scan stays non-recursive, so `sce_sys/` and dump folders are not walked (#2708). `USAGE.md` documents `.`. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. --> Ubuntu 24.04, GCC 13.3.0, relinker-only build (`-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON`, Release): 114/114 tests pass. - `guest_module_dir` gains two cases, run for both Linux and Windows output: - a root-level runtime module with `--module-dir .`: it is written to `app0/root.prx.guest.prx`, stays out of `DT_NEEDED` on Linux, and exports `__aps5_guest_initialize` on Windows; - a root-level module the executable needs: Linux `DT_NEEDED` is `$ORIGIN/app0/needed.prx.guest.prx`. - Both new cases fail on #3509 alone, without this commit. The scan stops on the input (`input.elf: Invalid string or symbol table`), and with only the scan fix the path is `$ORIGIN/app0/./root.prx.guest.prx`. - Ran the reporter's command shape by hand with the test fixtures, `relinker --windows --module-dir . game/eboot.elf app.exe` with `libfmod.prx` next to `eboot.elf`: it writes `game/app0/libfmod.prx.guest.prx`. A second Linux run with the output `.elf` inside the module directory stops with the existing "Executable output would overwrite an input module" error. The output is deliberately not skipped by the scan, since skipping it would bypass that guard when the output path names a real module. An earlier relinked output left in a module directory is scanned like any other ELF there (true of every `--module-dir`), so the output belongs outside the game directory. - `tools/check_conventions.py` from `main` passes on this branch with this title and body. Not tested: Windows host (the `.exe` run in the test only runs on Windows) or the title itself. I don't have a Hades dump. The reporter's workaround in #2724 (copying the `.guest.prx` files to `app0/`) is the layout this change produces. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> ### What `--module-dir .` did not work for modules kept next to the executable, the layout Hades (PPSA03355) uses for `libfmod.prx` and `libfmodstudio.prx`, which it loads with `dlopen("/app0/libfmod.prx")` (#2724). Three problems: - The scan of a module directory read the input executable as a guest module and failed (`ELF is not a shared module`, reported in #2724). The input executable is now skipped when scanning module directories. - Modules in the module parent directory got `app0/./<name>.guest.prx` as output, runtime and Linux `DT_NEEDED` path. They now get `app0/<name>.guest.prx`, which is where `dlopen` looks (`<requested path>.guest.prx`, `DynamicLoader.cpp:131`). One helper builds the path for both uses. - `(root / ".").lexically_normal()` keeps a trailing separator, so the directory did not match the module's parent and the module was not treated as runtime-loaded (it went into Linux `DT_NEEDED` and was started without start arguments). #3509 fixes that normalization; this branch carries its commit unchanged. Non-ELF files are still skipped, and the scan stays non-recursive, so `sce_sys/` and dump folders are not walked (#2708). `USAGE.md` documents `.`. ### Tested Ubuntu 24.04, GCC 13.3.0, relinker-only build (`-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON`, Release): 114/114 tests pass. - `guest_module_dir` gains two cases, run for both Linux and Windows output: - a root-level runtime module with `--module-dir .`: it is written to `app0/root.prx.guest.prx`, stays out of `DT_NEEDED` on Linux, and exports `__aps5_guest_initialize` on Windows; - a root-level module the executable needs: Linux `DT_NEEDED` is `$ORIGIN/app0/needed.prx.guest.prx`. - Both new cases fail on #3509 alone, without this commit. The scan stops on the input (`input.elf: Invalid string or symbol table`), and with only the scan fix the path is `$ORIGIN/app0/./root.prx.guest.prx`. - Ran the reporter's command shape by hand with the test fixtures, `relinker --windows --module-dir . game/eboot.elf app.exe` with `libfmod.prx` next to `eboot.elf`: it writes `game/app0/libfmod.prx.guest.prx`. A second Linux run with the output `.elf` inside the module directory stops with the existing "Executable output would overwrite an input module" error. The output is deliberately not skipped by the scan, since skipping it would bypass that guard when the output path names a real module. An earlier relinked output left in a module directory is scanned like any other ELF there (true of every `--module-dir`), so the output belongs outside the game directory. - `tools/check_conventions.py` from `main` passes on this branch with this title and body. Not tested: Windows host (the `.exe` run in the test only runs on Windows) or the title itself. I don't have a Hades dump. The reporter's workaround in #2724 (copying the `.guest.prx` files to `app0/`) is the layout this change produces. ### 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: #3509 (its commit is the first one on this branch; review only the second) - [x] AI-assisted: yes (Claude Code); I reviewed and tested every line Fixes #2724
xXPBSXx commented 2026-10-11 21:33:51 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-11T21:33:51Z.


Windows test of this PR with Hades (PPSA03355), as asked in #2724: Windows 10, MinGW/Ninja Release build of main c5da8233a with this PR merged in (merge was clean), relinked from the reconstructed ELF with --windows --registry --module-dir . (the input directory holds eboot.elf, sce_module/ and the two root-level modules).

  • The relinker no longer stops on "ELF is not a shared module": 8 modules convert, the import audit has no absent imports, and app0/libfmod.prx.guest.prx and app0/libfmodstudio.prx.guest.prx are written at the app0 root, where the title's dlopen("/app0/libfmod.prx") looks. I did not copy anything by hand.
  • Two 90 s runs: the start-up fault in the title's libc (the dlopen failure from #2724) is gone. The title opens about 1200 files, mounts its save data and compiles shaders (223 shaders in the first 10 s).
  • It then faults on the RenderThread (unhandled exception 0xc0000005, libc.prx.guest.prx+0x13a15, write of 0x0): a title loop at app.exe+0x318059 calls a memcpy-like routine for 0x1830 bytes with a null destination (rdi = 0, base pointer read from the loop's stack frame). That is a separate stop that I have not explained; I will put it on #2724.

Not tested: Linux, and a run without . (the old workaround layout) for comparison.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6114020988 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3850#issuecomment-6114020988). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-11T21:33:51Z. --- Windows test of this PR with Hades (PPSA03355), as asked in #2724: Windows 10, MinGW/Ninja Release build of `main` c5da8233a with this PR merged in (merge was clean), relinked from the reconstructed ELF with `--windows --registry --module-dir .` (the input directory holds `eboot.elf`, `sce_module/` and the two root-level modules). - The relinker no longer stops on "ELF is not a shared module": 8 modules convert, the import audit has no absent imports, and `app0/libfmod.prx.guest.prx` and `app0/libfmodstudio.prx.guest.prx` are written at the `app0` root, where the title's `dlopen("/app0/libfmod.prx")` looks. I did not copy anything by hand. - Two 90 s runs: the start-up fault in the title's libc (the `dlopen` failure from #2724) is gone. The title opens about 1200 files, mounts its save data and compiles shaders (223 shaders in the first 10 s). - It then faults on the `RenderThread` (`unhandled exception 0xc0000005`, `libc.prx.guest.prx+0x13a15`, write of `0x0`): a title loop at `app.exe+0x318059` calls a `memcpy`-like routine for 0x1830 bytes with a null destination (`rdi = 0`, base pointer read from the loop's stack frame). That is a separate stop that I have not explained; I will put it on #2724. Not tested: Linux, and a run without `.` (the old workaround layout) for comparison. AI-assisted (Claude Code).
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!3850
No description provided.