fix(relinker): write a bucketed hash table for Linux guest modules #1249

Merged
Raghav314 merged 1 commit from upstream-pr/1249 into main 2026-10-09 22:37:48 +00:00
Raghav314 commented 2026-10-07 19:45:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Raghav314 on 2026-10-07T19:45:24Z.


What

On Linux the relinker wrote each guest module's DT_HASH with one bucket, so every symbol sat in a single chain. Guest modules come first in the global lookup scope, so every symbol lookup from a host prx walked every symbol of every guest module before reaching the host definition. The relinker now writes a standard SysV hash table (gABI ELF hash) with one bucket per symbol, which is how the console's own modules ship it (nbucket == nchain in all seven of Hades II's sce_module prx). The table is built from the final string and symbol tables, after the #guest and __tls_get_addr renames.

Hades II (PPSA36082) bundles libSceNpCppWebApi.prx with 44906 symbols, and a lookup walked all of them. Its 512 MiB upload pool is freed only after a GPU fence, and the slow lookups were one of the delays in front of that fence: with this change and some local changes it gets past loading (3/3 runs); without it the pool overflows (2/2).

Tested

Linux (CachyOS), x86-64, GCC, 7800X3D / RTX 4090.

  • guest_symbol_names: checks the bucket count and that every symbol is reached through its bucket chain. Fails on main (one bucket); one-bucket, no-fold, unlinked-chain and skipped-symbol mutations all fail it.
  • Relinker tests pass on current main.
  • Hades II, launch to first file open: 1.88 s with one-bucket modules, 0.51 s with this change (host prx bound lazily in both).

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:4777629069 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1249). Originally posted by [Raghav314](https://github.com/Raghav314) on 2026-10-07T19:45:24Z. --- ### What On Linux the relinker wrote each guest module's DT_HASH with one bucket, so every symbol sat in a single chain. Guest modules come first in the global lookup scope, so every symbol lookup from a host prx walked every symbol of every guest module before reaching the host definition. The relinker now writes a standard SysV hash table (gABI ELF hash) with one bucket per symbol, which is how the console's own modules ship it (nbucket == nchain in all seven of Hades II's sce_module prx). The table is built from the final string and symbol tables, after the `#guest` and `__tls_get_addr` renames. Hades II (PPSA36082) bundles libSceNpCppWebApi.prx with 44906 symbols, and a lookup walked all of them. Its 512 MiB upload pool is freed only after a GPU fence, and the slow lookups were one of the delays in front of that fence: with this change and some local changes it gets past loading (3/3 runs); without it the pool overflows (2/2). ### Tested Linux (CachyOS), x86-64, GCC, 7800X3D / RTX 4090. - guest_symbol_names: checks the bucket count and that every symbol is reached through its bucket chain. Fails on main (one bucket); one-bucket, no-fold, unlinked-chain and skipped-symbol mutations all fail it. - Relinker tests pass on current `main`. - Hades II, launch to first file open: 1.88 s with one-bucket modules, 0.51 s with this change (host prx bound lazily in both). ### 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 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
oneandonlydean commented 2026-10-08 03:26:00 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-08T03:26:00Z.


Please move the -z now link change (core/libs/CMakeLists.txt, HostLibraryBinding.cpp) into its own PR: it changes when a missing import fails for every host prx, and it's a second topic. The hash table fix can go in on its own; a launch-to-first-open number for it alone would help, since the description has -z now alone (2.73 s) and both (0.38 s) but not the hash fix alone.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6051542096 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1249#issuecomment-6051542096). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-08T03:26:00Z. --- Please move the `-z now` link change (`core/libs/CMakeLists.txt`, `HostLibraryBinding.cpp`) into its own PR: it changes when a missing import fails for every host prx, and it's a second topic. The hash table fix can go in on its own; a launch-to-first-open number for it alone would help, since the description has `-z now` alone (2.73 s) and both (0.38 s) but not the hash fix alone.
Raghav314 commented 2026-10-08 05:03:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Raghav314 on 2026-10-08T05:03:56Z.


Thanks for the review,Done, #1249 is now only the hash table fix, rebased on current main. Launch to first file open in Hades II with the hash fix alone is 0.51 s (1.88 s on main; 0.38 s with both changes, 2.73 s with -z now alone).

Before I open a separate PR for -z now, do you think its worth having on its own? with this hash fix, hades 2 still loads on my separate local branch, although the load margins are a small amount tighter.

-z does also make linux match the behaviour thats there on windows by default, so its ur call.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6052689180 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1249#issuecomment-6052689180). Originally posted by [Raghav314](https://github.com/Raghav314) on 2026-10-08T05:03:56Z. --- Thanks for the review,Done, #1249 is now only the hash table fix, rebased on current main. Launch to first file open in Hades II with the hash fix alone is 0.51 s (1.88 s on main; 0.38 s with both changes, 2.73 s with -z now alone). Before I open a separate PR for -z now, do you think its worth having on its own? with this hash fix, hades 2 still loads on my separate local branch, although the load margins are a small amount tighter. -z does also make linux match the behaviour thats there on windows by default, so its ur call.
oneandonlydean commented 2026-10-08 06:37:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-08T06:37:16Z.


Only if a title needs it. With the hash fix Hades II gets past loading, so I'd leave -z now out until one does.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6054010827 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1249#issuecomment-6054010827). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-08T06:37:16Z. --- Only if a title needs it. With the hash fix Hades II gets past loading, so I'd leave `-z now` out until one does.
Raghav314 commented 2026-10-08 06:53:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Raghav314 on 2026-10-08T06:53:53Z.


Alright sounds good

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6054277347 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1249#issuecomment-6054277347). Originally posted by [Raghav314](https://github.com/Raghav314) on 2026-10-08T06:53:53Z. --- Alright sounds good
github-actions[bot] commented 2026-10-09 22:03:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-09T22:03:26Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#1102 core/relinker/elfpatcher/src/linux/LinuxGuestModuleWriter.cpp L57-58
#2323 core/relinker/elfpatcher/src/linux/LinuxGuestModuleWriter.cpp L57-58
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6090007104 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1249#issuecomment-6090007104). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-09T22:03:26Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #1102 | `core/relinker/elfpatcher/src/linux/LinuxGuestModuleWriter.cpp` [L57-58](https://github.com/boykopovar/AnyPS5/blob/64fe74399528c84fd74c3f736e632f89f4a7f211/core/relinker/elfpatcher/src/linux/LinuxGuestModuleWriter.cpp#L57-L58) | | | | #2323 | `core/relinker/elfpatcher/src/linux/LinuxGuestModuleWriter.cpp` [L57-58](https://github.com/boykopovar/AnyPS5/blob/64fe74399528c84fd74c3f736e632f89f4a7f211/core/relinker/elfpatcher/src/linux/LinuxGuestModuleWriter.cpp#L57-L58) | | |
adriadam10 commented 2026-10-09 22:37:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-09T22:37:45Z.


Checked the new DT_HASH layout (gABI ELF hash, nbucket == nchain == symbol count, null symbol skipped) and the test: guest_symbol_names fails without the change and passes with it, full ctest passes (549/549) on Linux, CI is green. Merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6090430938 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1249#issuecomment-6090430938). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-09T22:37:45Z. --- Checked the new DT_HASH layout (gABI ELF hash, nbucket == nchain == symbol count, null symbol skipped) and the test: `guest_symbol_names` fails without the change and passes with it, full ctest passes (549/549) on Linux, CI is green. Merging.
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!1249
No description provided.