fix(relinker): resolve symbol-name imports through NIDs on Windows #6697

Merged
karimibrahim07 merged 1 commit from upstream-pr/6697 into main 2026-10-19 08:49:06 +00:00
karimibrahim07 commented 2026-10-16 05:08:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by karimibrahim07 on 2026-10-16T05:08:34Z.


What

Homebrew built with the ps5-payload-dev SDK for the websrv launcher imports functions by symbol name (strlen, pthread_create, scePadOpen), and names its system libraries libSceLibcInternal.sprx, libkernel_web.sprx and so on. On Windows nothing of that resolved:

  • The loader opened libs\libSceLibcInternal.sprx, while libs/ holds .prx files.
  • The libraries in libs/ export NIDs (strlen is j4ViWNHEgww), so GetProcAddress by name found nothing.
  • libc.prx, where AnyPS5 implements the C runtime, was not searched either. The rule that adds it only matched libSceLibcInternal.prx.

The Quake homebrew stopped before its entry point with 457 FAIL: unresolved ELF import lines (331 names). #6239 reports the same wall for Mari0 from the same launcher ("this fix enables diagnosis, not successful loading").

On Windows:

  • An import without a module that no searched library exports under its name is now looked up again under the NID of that name, as the console resolves these names. The stub only adds a second GetProcAddress loop for those imports, after the existing one. A name that a library exports as written still binds there first, so native libraries with plain exports (unscoped-native-import in windows_import_modules) behave as before. Qualified imports (name#L#M) and imports with a module are unchanged.
  • A dependency named with .sprx, .suprx or .debug_prx loads the .prx library of the same stem (Domain::NeededLibraryName). An import's module name is compared the same way.
  • libkernel_web also loads libkernel.prx, next to the existing libSceLibcInternal → libc.prx rule. AnyPS5's libkernel_web.prx exports two functions, and 121 of Quake's names (open, pthread_create, clock_gettime…) are in libkernel.prx.
  • The NIDs come from core/libs/nid's ComputeNid, which relinker_core now compiles. The relinker already compiles ParamJsonParser.cpp from ../libs.

Unresolved imports are still reported by name. Linux and macOS resolve these imports through the host loader and are unchanged. The new entry in docs/dev/debt/relinker.md records this.

Tested

Windows 11 Pro (26300), WinLibs GCC 15.2.0 r7, Ninja Release, BUILD_TESTING=ON, on main 5d9dcc42d:

  • New windows_named_imports test. A relinked provider exports the NID of shared and is installed as libs/available.prx. An executable that imports shared without a module:

    • exits with the provider's value through available.prx and through a DT_NEEDED of available.sprx
    • against a provider that exports shared as written, still takes that export
    • with shared#A#B (qualified), still fails as unresolved ELF import shared from available.prx
    • with an absent name, still fails as unresolved ELF import absent

    With the source changes reverted it fails at the first case with FAIL: unresolved ELF import shared.

  • The relinker tests pass, 131 of 131, and the full suite passes, 1301 tests (one conventions_function_bodies shard timed out while the machine was busy and passed alone). python tools/check_conventions.py --base origin/main passes.

Quake (homebrew q1 from gen04177/q1-ps5, q1.7z SHA-256 9692254071d5a90b5f4d7fb316960ae1f4e586f944eb1d4641a79a914fd834fb, with the shareware pak0.pak it ships). quake.elf (b2f667f8…8ca5c) and its libOSMesa.so.8 (255b57aa…08ba) are plain ELFs. They were relinked with --windows --to-intel --trap-sdk-syscall-stubs --registry, with libOSMesa.so.8 placed in sce_module/:

  • On main: 457 FAIL: unresolved ELF import lines, among them strlen, malloc, pthread_create and scePadOpen. Only OSMesa's own gl* exports resolve.

  • With this PR, 11 imports stay unresolved, all from libOSMesa.so.8:

    • 10 weak ones: ZSTD_trace_*, the SDK's __dlopen, __dlsym, __dladdr, __dlclose, __dlerror, and kernel_mprotect
    • qsort_s

    A weak import of a bundled module still stops a Windows title, because Domain::GuestImport has no weak flag. That's a separate change, and so is qsort_s.

Linux and macOS not tested; their code paths are unchanged.

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: Quake homebrew #6698 (to its next stops); Mari0 (#6239)
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4883783321 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6697). Originally posted by [karimibrahim07](https://github.com/karimibrahim07) on 2026-10-16T05:08:34Z. --- ### What Homebrew built with the [ps5-payload-dev SDK](https://github.com/ps5-payload-dev/sdk) for the websrv launcher imports functions by symbol name (`strlen`, `pthread_create`, `scePadOpen`), and names its system libraries `libSceLibcInternal.sprx`, `libkernel_web.sprx` and so on. On Windows nothing of that resolved: - The loader opened `libs\libSceLibcInternal.sprx`, while `libs/` holds `.prx` files. - The libraries in `libs/` export NIDs (`strlen` is `j4ViWNHEgww`), so `GetProcAddress` by name found nothing. - `libc.prx`, where AnyPS5 implements the C runtime, was not searched either. The rule that adds it only matched `libSceLibcInternal.prx`. The Quake homebrew stopped before its entry point with 457 `FAIL: unresolved ELF import` lines (331 names). #6239 reports the same wall for Mari0 from the same launcher ("this fix enables diagnosis, not successful loading"). On Windows: - An import without a module that no searched library exports under its name is now looked up again under the NID of that name, as the console resolves these names. The stub only adds a second `GetProcAddress` loop for those imports, after the existing one. A name that a library exports as written still binds there first, so native libraries with plain exports (`unscoped-native-import` in `windows_import_modules`) behave as before. Qualified imports (`name#L#M`) and imports with a module are unchanged. - A dependency named with `.sprx`, `.suprx` or `.debug_prx` loads the `.prx` library of the same stem (`Domain::NeededLibraryName`). An import's module name is compared the same way. - `libkernel_web` also loads `libkernel.prx`, next to the existing `libSceLibcInternal` → `libc.prx` rule. AnyPS5's `libkernel_web.prx` exports two functions, and 121 of Quake's names (`open`, `pthread_create`, `clock_gettime`…) are in `libkernel.prx`. - The NIDs come from `core/libs/nid`'s `ComputeNid`, which `relinker_core` now compiles. The relinker already compiles `ParamJsonParser.cpp` from `../libs`. Unresolved imports are still reported by name. Linux and macOS resolve these imports through the host loader and are unchanged. The new entry in `docs/dev/debt/relinker.md` records this. ### Tested Windows 11 Pro (26300), WinLibs GCC 15.2.0 r7, Ninja Release, `BUILD_TESTING=ON`, on `main` `5d9dcc42d`: - New `windows_named_imports` test. A relinked provider exports the NID of `shared` and is installed as `libs/available.prx`. An executable that imports `shared` without a module: - exits with the provider's value through `available.prx` and through a `DT_NEEDED` of `available.sprx` - against a provider that exports `shared` as written, still takes that export - with `shared#A#B` (qualified), still fails as `unresolved ELF import shared from available.prx` - with an absent name, still fails as `unresolved ELF import absent` With the source changes reverted it fails at the first case with `FAIL: unresolved ELF import shared`. - The relinker tests pass, 131 of 131, and the full suite passes, 1301 tests (one `conventions_function_bodies` shard timed out while the machine was busy and passed alone). `python tools/check_conventions.py --base origin/main` passes. Quake (homebrew `q1` from [gen04177/q1-ps5](https://github.com/gen04177/q1-ps5/releases/tag/q1), `q1.7z` SHA-256 `9692254071d5a90b5f4d7fb316960ae1f4e586f944eb1d4641a79a914fd834fb`, with the shareware `pak0.pak` it ships). `quake.elf` (`b2f667f8…8ca5c`) and its `libOSMesa.so.8` (`255b57aa…08ba`) are plain ELFs. They were relinked with `--windows --to-intel --trap-sdk-syscall-stubs --registry`, with `libOSMesa.so.8` placed in `sce_module/`: - On `main`: 457 `FAIL: unresolved ELF import` lines, among them `strlen`, `malloc`, `pthread_create` and `scePadOpen`. Only OSMesa's own `gl*` exports resolve. - With this PR, 11 imports stay unresolved, all from `libOSMesa.so.8`: - 10 weak ones: `ZSTD_trace_*`, the SDK's `__dlopen`, `__dlsym`, `__dladdr`, `__dlclose`, `__dlerror`, and `kernel_mprotect` - `qsort_s` A weak import of a bundled module still stops a Windows title, because `Domain::GuestImport` has no weak flag. That's a separate change, and so is `qsort_s`. Linux and macOS not tested; their code paths are unchanged. ### 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: Quake homebrew #6698 (to its next stops); Mari0 (#6239) - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-10-16 05:15:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-16T05:15:07Z.


The relinker CI has now completed successfully on Ubuntu (GCC), macOS (Clang) and Windows (GCC); conventions, eligibility and intake also pass. Platform build jobs were skipped for this PR.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6208622110 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6697#issuecomment-6208622110). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-16T05:15:07Z. --- The relinker CI has now completed successfully on Ubuntu (GCC), macOS (Clang) and Windows (GCC); conventions, eligibility and intake also pass. Platform build jobs were skipped for this PR.
github-actions[bot] commented 2026-10-16 05:32:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-16T05:32:30Z.


Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 2780 core/relinker/CMakeLists.txt
PR 5021 core/relinker/CMakeLists.txt
docs/dev/debt/relinker.md
PR 6044 core/relinker/CMakeLists.txt
PR 6618 core/relinker/CMakeLists.txt
PR 6879 core/relinker/CMakeLists.txt
PR 6977 core/relinker/CMakeLists.txt
docs/dev/debt/relinker.md
PR 7173 core/relinker/CMakeLists.txt
docs/dev/debt/relinker.md
PR 7332 core/relinker/CMakeLists.txt
docs/dev/debt/relinker.md
PR 7453 core/relinker/CMakeLists.txt
PR 7594 core/relinker/CMakeLists.txt
core/relinker/elfpatcher/src/windows/WindowsEntryStubBuilder.cpp
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6208827411 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6697#issuecomment-6208827411). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-16T05:32:30Z. --- <!-- pr-overlap --> Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap. | Pull request | Shared files not compared | |---|---| | [PR 2780](https://www.github.com/boykopovar/AnyPS5/pull/2780) | `core/relinker/CMakeLists.txt` | | [PR 5021](https://www.github.com/boykopovar/AnyPS5/pull/5021) | `core/relinker/CMakeLists.txt`<br>`docs/dev/debt/relinker.md` | | [PR 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `core/relinker/CMakeLists.txt` | | [PR 6618](https://www.github.com/boykopovar/AnyPS5/pull/6618) | `core/relinker/CMakeLists.txt` | | [PR 6879](https://www.github.com/boykopovar/AnyPS5/pull/6879) | `core/relinker/CMakeLists.txt` | | [PR 6977](https://www.github.com/boykopovar/AnyPS5/pull/6977) | `core/relinker/CMakeLists.txt`<br>`docs/dev/debt/relinker.md` | | [PR 7173](https://www.github.com/boykopovar/AnyPS5/pull/7173) | `core/relinker/CMakeLists.txt`<br>`docs/dev/debt/relinker.md` | | [PR 7332](https://www.github.com/boykopovar/AnyPS5/pull/7332) | `core/relinker/CMakeLists.txt`<br>`docs/dev/debt/relinker.md` | | [PR 7453](https://www.github.com/boykopovar/AnyPS5/pull/7453) | `core/relinker/CMakeLists.txt` | | [PR 7594](https://www.github.com/boykopovar/AnyPS5/pull/7594) | `core/relinker/CMakeLists.txt`<br>`core/relinker/elfpatcher/src/windows/WindowsEntryStubBuilder.cpp` |
screamm commented 2026-10-16 11:11:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by screamm on 2026-10-16T11:11:24Z.


Cross-validation on Windows 11 Pro 26220, WinLibs MinGW-w64 GCC 15.2, PR head 55408512c on main 5d9dcc42d (fast-forward, no conflicts). This is the Windows-only path, so the checks are on the relinker; I did not run Quake or Mari0 (not available here).

  • windows_named_imports, --repeat until-fail:3: 3 of 3.
  • Negative control: with ImportModule.hpp, WindowsEntryStubBuilder.cpp and WindowsImportBuilder.cpp from main (test and CMake kept) the test fails at the first case with FAIL: unresolved ELF import shared (exit 0xC0000139, GetLastError: 127). With the changes it passes. Same result as your description.
  • Relinker tests: 101 of 101 pass on a tree with #6697 and #6702 merged (windows_import_modules, guest_module_dir, windows_dependency_diagnostics included). Merging #6697 and #6702 has no conflict.
  • tools/check_conventions.py --base origin/main and git diff --check: pass.
  • Relink-only pass over the 51 local titles that have an eboot.elf, main's relinker against this PR's (same flags, no runs): the same outcome for every title (50 relink, PPSA99995 stops in both with FAIL: Unsupported Windows guest TLS instruction (bytes: 65 48 8b 0c 25 78 03 00 00)), no other FAIL, no WARN, the registries are byte-identical. app.exe changes in 3 titles (PPSA28319 +3 072 bytes, PPSA99109 +2 048, PPSA99110 +1 024); the other 48 are byte-identical.
  • Before and after on PPSA28319 and PPSA99109 (the two largest changes), main relinker against the PR relinker, same runtime, 130 s, 2 runs each: all 8 run to the limit with no stop line and no unresolved line; the logs differ only in addresses and paths.

No local title has an import by plain name without a module, so none of them exercises the new NID search; I cannot confirm the Quake result (457 down to 11 unresolved imports).

Not checked: Quake, Mari0, Linux, macOS, a full-tree build (relinker targets only).

Written with Claude Code assistance (validation by a subagent, reviewed in this session).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6214229882 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6697#issuecomment-6214229882). Originally posted by [screamm](https://github.com/screamm) on 2026-10-16T11:11:24Z. --- Cross-validation on Windows 11 Pro 26220, WinLibs MinGW-w64 GCC 15.2, PR head `55408512c` on main `5d9dcc42d` (fast-forward, no conflicts). This is the Windows-only path, so the checks are on the relinker; I did not run Quake or Mari0 (not available here). - `windows_named_imports`, `--repeat until-fail:3`: 3 of 3. - Negative control: with `ImportModule.hpp`, `WindowsEntryStubBuilder.cpp` and `WindowsImportBuilder.cpp` from main (test and CMake kept) the test fails at the first case with `FAIL: unresolved ELF import shared` (exit `0xC0000139`, `GetLastError: 127`). With the changes it passes. Same result as your description. - Relinker tests: 101 of 101 pass on a tree with #6697 and #6702 merged (`windows_import_modules`, `guest_module_dir`, `windows_dependency_diagnostics` included). Merging #6697 and #6702 has no conflict. - `tools/check_conventions.py --base origin/main` and `git diff --check`: pass. - Relink-only pass over the 51 local titles that have an `eboot.elf`, main's relinker against this PR's (same flags, no runs): the same outcome for every title (50 relink, PPSA99995 stops in both with `FAIL: Unsupported Windows guest TLS instruction (bytes: 65 48 8b 0c 25 78 03 00 00)`), no other `FAIL`, no `WARN`, the registries are byte-identical. `app.exe` changes in 3 titles (PPSA28319 +3 072 bytes, PPSA99109 +2 048, PPSA99110 +1 024); the other 48 are byte-identical. - Before and after on PPSA28319 and PPSA99109 (the two largest changes), main relinker against the PR relinker, same runtime, 130 s, 2 runs each: all 8 run to the limit with no stop line and no `unresolved` line; the logs differ only in addresses and paths. No local title has an import by plain name without a module, so none of them exercises the new NID search; I cannot confirm the Quake result (457 down to 11 unresolved imports). Not checked: Quake, Mari0, Linux, macOS, a full-tree build (relinker targets only). Written with Claude Code assistance (validation by a subagent, reviewed in this session).
adriadam10 commented 2026-10-19 08:50:51 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-19T08:50:51Z.


Checked the second GetProcAddress loop (NID fallback runs only after the by-name search, only for unqualified imports without a module; every resolved branch is patched), the .sprx/.suprx/.debug_prx → .prx mapping, the libkernel_web → libkernel.prx rule, the debt entry and windows_named_imports (covered by the relinker Windows job and screamm's negative control on main). Merged.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6263393802 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6697#issuecomment-6263393802). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-19T08:50:51Z. --- Checked the second `GetProcAddress` loop (NID fallback runs only after the by-name search, only for unqualified imports without a module; every `resolved` branch is patched), the `.sprx`/`.suprx`/`.debug_prx` → `.prx` mapping, the `libkernel_web` → `libkernel.prx` rule, the debt entry and `windows_named_imports` (covered by the relinker Windows job and screamm's negative control on `main`). Merged.
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!6697
No description provided.