Skip to content

fix(relinker): convert guest modules with GNU hash tables - #4340

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
ArjenS-LA:fix/guest-gnu-hash
Oct 13, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
ArjenS-LA:fix/guest-gnu-hash

Conversation

@ArjenS-LA

@ArjenS-LA ArjenS-LA commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

What

A guest ELF module that supplies DT_GNU_HASH but neither DT_HASH nor DT_SCE_SYMTABSZ fails conversion with Missing dynamic symbol count. Retain DT_GNU_HASH and derive the symbol count from the last bucket's terminating chain, using the same bounded walk already used by CodeInstructionCollector after #3273. Existing SCE and SysV symbol-count precedence is preserved.

The regression converts synthetic guest providers containing multiple buckets, one chain, one symbol, and no hashed symbols. On Windows it executes a converted executable that imports the last hashed guest function and checks its return value; Linux output inspection checks the complete resulting symbol count. Invalid headers and a chain that exceeds its mapped segment still fail.

Overlap review: inspected merged #3273 and issue #3224 (main-image code analysis), plus open #4091 (guest no-op relocation copying). #4091 edits a different block in GuestImageReader::Read and does not implement GNU hash symbol counting. No existing open PR in the complete changed-file inventory implements this behavior. Refreshed all 451 open PR file lists and relevant issues, reviews and discussions against current main; none addresses this regression.

Branch: fix/guest-gnu-hash.
Base: d06c06565717961104edecdab46ce61c8cc72a70.
Fixed commit: 100896c1dc00d337bdba4aa0be3f9511610db6ab.

Tested

Shipped-homebrew conversion evidence is recorded in the Mari0 1.6.2 report: websrv v0.34 bundles GNU-hash-only libOSMesa.so.8. Main c13dc7e6b440725babd25ccec4262ccc4c78dfc3 exits 2 with Missing dynamic symbol count; the same main plus this PR at 100896c1dc00d337bdba4aa0be3f9511610db6ab (uncommitted fixed tree 73eb5135fb14ec71e97ace360010b4e021d0ffd2) converts successfully. Both runs use --trap-sdk-syscall-stubs, --module-dir ., and a separate package copy with an added empty sce_module directory; all original file paths and hashes are preserved. The report includes commands, hashes and Windows/WinLibs toolchain details. This is conversion evidence only: neither the game nor the generated executable was run, and maintainer assessment remains pending. The automated regression below uses generated fixtures; the standalone Lua binary in #3224 does not exercise this guest-module path.

Windows x86-64, Windows build 10.0.26200; supported WinLibs MinGW-w64 GCC 15.2.0 (x86_64-ucrt-posix-seh, r7). No title dump, GPU, or hardware measurements were used.

  • Before: python core/relinker/relinker/tests/test_guest_gnu_hash.py <baseline-relinker.exe> exits 1 because conversion reports Missing dynamic symbol count.
  • After: the identical regression exits 0. Windows converted guest execution returns 43 for the three-symbol cases and 41 for the one-symbol case; the empty-table fixture returns 42. Linux artifacts have the expected dynamic symbol counts.
  • The baseline executable was built from b42ef24e07725ba1166420073817d80a60ec9149; git diff b42ef24e07725ba1166420073817d80a60ec9149 2ccbd376f86a0ab2dafca98749585e281f37d599 -- core/relinker is empty.
  • cmake -S . -B build-relinker -G Ninja -DCMAKE_BUILD_TYPE=Release -DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON -DCMAKE_CXX_COMPILER=g++ -DPython3_EXECUTABLE=C:/Users/arjen/AppData/Local/Temp/anyps5-toolchain/python/python.exe
  • cmake --build build-relinker --parallel 4 succeeds.
  • ctest --test-dir build-relinker -N registers 123 tests, including input_magic and guest_gnu_hash.
  • ctest --test-dir build-relinker --output-on-failure -j 4 -E '^(pr_overlap_encoding|import_audit|conventions_function_bodies|conventions_wrapped_declarations)$': 119/119 pass in 17.52 seconds; guest_gnu_hash takes 0.74 seconds. Four unrelated tooling groups were excluded because local commit-creation limits prohibit their temporary Git commits. Some existing platform-specific test scripts return early on Windows; their CTest pass status is not Linux/macOS execution evidence.
  • git diff --check passes. python tools/check_conventions.py --base origin/main passes on the submitted commit.

Linux guest execution, macOS guest execution, full library builds, and CI were not run for this relinker-only change.

After fast-forwarding to current main, the targeted regression passed again. Relinker builds reported no work because their sources and build configuration were unchanged. No upstream CI result is claimed.

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 (none added)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: none
  • AI-assisted: yes

@MarcZX10

Copy link
Copy Markdown
Contributor

I built the relinker from this PR on Linux (GCC 12.2, Release, Ninja) and ran the GNU-hash regression against it. test_guest_gnu_hash.py passed, and the registered guest_gnu_hash CTest passed (1/1). The conventions check and git diff --check also passed. This validates the Linux conversion and malformed-header fixture paths; it does not exercise Windows guest execution.

@oneandonlydean

Copy link
Copy Markdown
Collaborator

Which title or homebrew ships a bundled module with DT_GNU_HASH and neither DT_HASH nor DT_SCE_SYMTABSZ? The Lua binary from #3224 is a standalone executable, so it doesn't reach GuestImageReader. With the name and the Missing dynamic symbol count line on main this can go in; otherwise I'll close it until one does.

RINNECODER added a commit to RINNECODER/AnyPS5 that referenced this pull request Oct 13, 2026
…oykopovar#4501) (#439)

* Port upstream boykopovar#4340 (GNU hash tables) by @ArjenS-LA

Ported from boykopovar/AnyPS5 PR boykopovar#4340 (author @ArjenS-LA), applied as a patch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Port upstream boykopovar#4802 (output collisions) by @ArjenS-LA

Ported from boykopovar/AnyPS5 PR boykopovar#4802 (author @ArjenS-LA), applied as a patch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Port upstream boykopovar#4501 (SELF skip warning) by @devavijitsingh

Ported from boykopovar/AnyPS5 PR boykopovar#4501 (author @devavijitsingh), applied as a patch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Adapt boykopovar#4802 port: hoist registry paths so the collision check runs before registries are written

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
@ArjenS-LA

Copy link
Copy Markdown
Contributor Author

Update with shipped-bundle evidence for @oneandonlydean: Mari0 1.6.2 from ps5-payload-dev/websrv v0.34 reaches this path through its bundled libOSMesa.so.8. This addresses the evidence gap noted in my preceding comment.

  • Original release archive: Mari0.zip.
  • The packaging script includes both love.elf and libOSMesa.so.8. The launcher launches love.elf with mari0.love and sets LD_LIBRARY_PATH to the package directory. This is a PS5 payload homebrew distribution.
  • The shipped libOSMesa.so.8 is ELF64 ET_DYN, has DT_GNU_HASH at 0x1d61410, and has neither DT_HASH nor DT_SCE_SYMTABSZ.

On main c13dc7e6b440725babd25ccec4262ccc4c78dfc3, conversion exits 2 with this line (local package prefix abbreviated):

FAIL: <package>\libOSMesa.so.8: Missing dynamic symbol count

With this PR's patch from 100896c1dc00d337bdba4aa0be3f9511610db6ab applied to that same main, the same conversion exits 0 and produces output.exe and app0/libOSMesa.so.8.guest.prx. The tested fixed source was an uncommitted isolated worktree, tree 73eb5135fb14ec71e97ace360010b4e021d0ffd2.

There are two earlier checks to account for when reproducing this. The untouched archive fails the syscall check first. --trap-sdk-syscall-stubs passes that check, after which the relinker requires a standard module directory. I used a separate copy of the extracted bundle, added an empty sce_module directory, and passed --module-dir . to discover the library at its original package-root location. Every original file retained its path and SHA-256 before and after both runs; no module was substituted or moved.

Reproducer in PowerShell, with $package pointing to the extracted Mari0 directory containing love.elf, and $baseline / $fixed pointing to the two relinker executables:

New-Item -ItemType Directory -Force -Path "$package/sce_module" | Out-Null
New-Item -ItemType Directory -Force -Path "$PWD/baseline-out", "$PWD/fixed-out" | Out-Null
& $baseline --trap-sdk-syscall-stubs --windows --sce-module-path $package --module-dir . "$package/love.elf" "$PWD/baseline-out/output.exe"
& $fixed --trap-sdk-syscall-stubs --windows --sce-module-path $package --module-dir . "$package/love.elf" "$PWD/fixed-out/output.exe"

SHA-256:

Mari0.zip       e0331ed5a22e7fe72843d268cd2c8b297d761a75b7c83d828f5cc58a82a72ce3
libOSMesa.so.8  128d2ab20b980b96decb1f20a9ed57d10cc922605259666b63efa52963920f0a
love.elf        54bcc91670fd759bbd3488284dce351b6421cb83016e9ad8da6b5186da067a39

Test platform: Windows 11 Pro x64 (build 26200), WinLibs MinGW-w64 GCC 15.2.0, Release relinker-only builds, CMake 4.3.1 and Ninja 1.13.2. This establishes the shipped module reaching GuestImageReader and before/after conversion behavior with the disclosed options/layout accommodation. I did not execute the game on a physical PS5 or run the generated executable in AnyPS5; this is not a gameplay or runtime compatibility claim. Investigation and this report were AI-assisted.

@oneandonlydean
oneandonlydean merged commit ebf417a into boykopovar:main Oct 13, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants