fix(relinker): accept section-relative guest module relocations #5138
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5138"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by veosett on 2026-10-13T12:37:59Z.
What
The OpenOrbis using_library sample (homebrew ID
BREW00089) stops atUnsupported symbol attributeswhen converting itssce_module/libExample.prx: the module dynamic table contains a localSTT_SECTIONmarker. The concrete reproduction is recorded below. The executable path already accepts this layout after #4203; the guest-module reader still rejects it. This is a follow-up to the format support discussed in #3093, not a claim that PS4 titles run.Accept local section symbols and allow
R_X86_64_RELATIVEto name one only when its value is zero. Normalize that relocation to symbol index zero before the ELF, PE and Mach-O writers consume it. Preserve main's support for defined function and object symbols whose value matches the addend. Invalid symbol indices, undefined or mismatching ordinary symbols and nonzero section-marker values still fail.OpenOrbis create-fself inserts a zero-valued local section marker and increments every copied relocation's symbol index. FreeBSD rtld computes RELATIVE as the relocation base plus addend.
Tested
Refreshed onto upstream
mainfd423f9b2; both hosts built and tested the exact updated PR head269a59e23withANYPS5_RELINKER_ONLY=ON, Release,BUILD_TESTING=ONand two parallel jobs:guest_relative_section_symbolspasses in 2.55 seconds.guest_relative_section_symbolspasses in 0.50 seconds.guest_none_relocations,guest_tlsandguest_absolute_symbolsalongside the new regression.tools/check_test_registration.py,tools/check_conventions.py --base origin/main, andgit diff --checkpass on both hosts. No full system-library build or title-startup claim is made.Historical negative controls, before the earlier main refresh: the new regression fails against unmodified upstream
d1fd9372bon both hosts withUnsupported symbol attributes; six existing-format controls (SysV/SCE, ELF/PE/Mach-O) produce byte-identical executable and module output versus that upstream revision. These controls were not rerun for this merge.Real homebrew reproduction
Get-fix reported this Windows reproduction. The official sample README identifies
BREW00089; its main.cpp loads/app0/sce_module/libExample.prx.On Windows 11 / WinLibs GCC 15.2, converting the sample with
relinker --windows --windows-guireaches the module and fails on main84b01f9cdande442f4c2e:With this PR at
5f5641732, the module passes symbol validation and reaches a separate syscall-scan failure at offset0xd016e. #5994 addresses that scan reaching module data. With this PR, #5994, and #5990, #5991, #5992 and #5993 for executable startup, the reporter converted and started the sample and called the library export:This combined startup run is attributed to Get-fix; no additional homebrew execution was performed for this description update. The relocation change itself builds independently of those other startup fixes.
Independent retail-module conversion
savvaniss reports a leave-one-out conversion check for Hasbro Family Fun Pack (
CUSA03312), using a cumulative relinker stack on Windows 11 / WinLibs GCC 15.2.0 r7. Both Linux and Windows output conversions complete with the stack. Without this PR (and with its dependent TLS follow-up omitted), conversion first stops inlibSceFace.prxwithUnsupported symbol attributes.This is independent conversion evidence, not a local run, a standalone test of this PR or a claim that the title starts. The complete stack and the separate stops caused by its other members are documented in the linked comment.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-13T15:35:35Z.
Windows test: head
5f5641732merged onto currentmain60fb61870, together with 9 other open pull requests in one build (the merges were conflict-free); a failure would have been bisected per PR. Windows 10, MinGW GCC (WinLibs), Ninja Release,-j2: full build 0 errors; ctest for the tests this change adds or touches: guest_relative_section_symbols passed;python tools/check_conventions.py --base upstream/mainpassed for the combined tree. I did not run the new tests againstmainwithout the change.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T03:05:29Z.
Which homebrew or sample ships an OpenOrbis module that stops at
Unsupported symbol attributeson main? With its name and the log line this can go in, as #4203 did for the executable side; the synthetic test alone doesn't show a need.Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-14T15:46:22Z.
macOS data point, since the description inspects the Mach-O output only.
Apple M2 Max, macOS 27.2 (26B5091g), AppleClang, Ninja Release, relinker-only. Head
5f5641732merged without conflicts intomain84b01f9cd.ctest --parallel 8 --timeout 30157/157 pass, includingguest_relative_section_symbols.-DCMAKE_OSX_ARCHITECTURES=x86_64, x86_64 Python):guest_relative_section_symbolspasses. 6 tests fail (pr_overlap_encoding,progress_history,stubgen_stdout_newlines,release_package,linux_fixed_base,guest_module_args), the same 6 that fail on unmodifiedmainon this machine (five are Python 3.9 incompatibilities of the only x86_64 Python here;guest_module_argsis the fixture #5362 fixes).conventions_function_bodiesandcheck_skipstimed out once under parallel load and passed when rerun alone.mainrelinker fails at the first conversion, as described.Native Mach-O load under Rosetta 2: I ran a copy of
test_guest_relative_section_symbols.pywhose--loadbranch also coverssystem == "macos"on Darwin, with an x86_64/usr/bin/python3. I put empty stand-in x86_64libs/libc.prxandlibs/libkernel.prxnext to the output so dyld resolves the module's load commands. For SysV and SCE tables and section markers at index 1 and 3 (the four non-lifecycle cases), dyld loadsmodule.prx.guest.prx,shared#guestreturns 42, the relocated slot holds the function's own address, and a call through it returns 42. The lifecycle cases were not loaded, as on Linux and Windows.Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T17:44:42Z.
Review: CHANGES_REQUESTED
The change itself checks out: the local
STT_SECTION/ zero-value RELATIVE handling matches FreeBSD rtld (relocbase + r_addend), build and the relinker ctest scope pass here, and the new test fails without theGuestImageReader.cppchange.One thing is still open, the question @oneandonlydean asked above: please name the OpenOrbis module (sample or homebrew
.prx) that stops atUnsupported symbol attributeson main, with the log line, as #4203 did for the executable side. The synthetic test alone doesn't show the need. Once that is in the PR body this is ready to merge.Imported from boykopovar/AnyPS5. Originally posted by Get-fix on 2026-10-14T18:38:40Z.
@oneandonlydean The OpenOrbis PS4 toolchain sample
using_librarydoes. Its modulesce_module/libExample.prxis linked by the toolchain'screate-fself, which adds the section symbol 1 that the module'sR_X86_64_RELATIVErelocations name. Onmain(84b01f9cd, and again one442f4c2e) the conversion stops at:This was on Windows 11 with WinLibs GCC 15.2, running
relinker --windows --windows-gui using_library-eboot.elf …. The executable itself converts; the module does not.With this PR (head
5f5641732) merged, the module passes that check and the conversion stops one step later, in the module's syscall scan:That second stop is a separate relinker issue: module syscall scans run past the end of the module's code into its data. #5994 fixes it. With both, the program converts, starts on Windows and calls into the module:
That run also uses #5990 to #5993, which the executable needs to start (overview in #3093).
AI-assisted: yes (Claude Code). I ran the conversions and the program myself on Windows 11.
🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-15T11:56:39Z.
I found a separate PS4 relocation case in #3093: libc.prx has defined FUNC/OBJECT symbols on R_X86_64_RELATIVE entries where st_value equals the nonnegative addend. #5138 handles the zero-valued STT_SECTION marker case; it does not cover these entries. I have an independent local patch and SysV/SCE Linux/Windows/macOS regression coverage for the equality case. It touches the same RELATIVE validation block, so it would need integration with this PR. Would you prefer to extend #5138 with this follow-up, or should I open a dependent PR after yours? I have not copied or used this PR’s branch.
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T12:07: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.
main)core/relinker/CMakeLists.txtL432Some 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.
core/relinker/CMakeLists.txtcore/relinker/CMakeLists.txtcore/relinker/CMakeLists.txtcore/relinker/CMakeLists.txtcore/relinker/CMakeLists.txtcore/relinker/CMakeLists.txtcore/relinker/CMakeLists.txtcore/relinker/CMakeLists.txtImported from boykopovar/AnyPS5. Originally posted by SandstromPL on 2026-10-16T04:49:15Z.
@veosett Here is a retail-module data point for this PR, and a follow-up it exposes.
PS4 Until Dawn (CUSA02636) bundles Sony's
libSceFios2.prxandlibc.prx. Both have the same unnamedSTT_SECTIONat symbol index 1 (st_info0x03,st_shndx0,st_value0). Ond92a8da, with scratch fixes for the eboot's earlier stops, the conversion stops at:SuperCatElvis ran these files on #3093 (stop 4 in https://github.com/boykopovar/AnyPS5/issues/3093#issuecomment-6190626823).
In these modules no RELATIVE relocation uses the index-1 marker. Only
R_X86_64_DTPMOD64with addend 0 does: 13 times inlibc.prxand 3 times inlibSceFios2.prx. With this PR applied, the next stop is:That is because the TLS branch (
GuestImageReader.cpp:317at5f5641732) requires anSTT_TLSsymbol whenever the index is nonzero. A DTPMOD64 against the module's own local marker refers to the module's own TLS block, just as symbol 0 does. Rewriting those entries to symbol 0, as this PR does for RELATIVE, gets past this stop (stop 5 in the same comment).@adriadam10's remaining request was a named module with its log line in the body, which it now has (
using_library, BREW00089), so I'd keep this PR as it is rather than widen it. Unless you'd rather fold the DTPMOD64 case in, I'll open it as a follow-up that depends on #5138, the way #6357 does for the RELATIVE case. Does that work for you?AI Assisted
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-16T04:51:03Z.
From my side, keeping the
DTPMOD64marker case in a separate follow-up that depends on #5138 is the clearest split. #6357 already tracks the distinct defined-symbolR_X86_64_RELATIVEcase as a dependent PR; the TLS relocation has its own semantics and evidence in the Until Dawn modules. That keeps this PR focused on the section-symbol RELATIVE case while the follow-up can carry its own regression coverage. Maintainers can decide the final sequencing.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-16T04:51:29Z.
For the review thread: the PR description now includes the requested real OpenOrbis
using_library/ BREW00089 module reproduction, the exactUnsupported symbol attributeslog on main, and the follow-on stop after this fix. This appears to address the evidence request; the PR remains marked changes requested pending review.Imported from boykopovar/AnyPS5. Originally posted by savvaniss on 2026-10-18T20:59:44Z.
Second-title data point: Hasbro Family Fun Pack (CUSA03312, my own dump) needs this PR, on Linux and Windows.
Relinker-only Release build, Windows 11 Pro 26300, WinLibs GCC 15.2.0 r7. Starting from
mainf3059421f, I merged, in this order: #7660, #6619 (a9fa0e8b0), #5138 (5f5641732), #6381 (6f8d9a09d),3b158c1e4from #6977, #6354 (81561867f), #6357 (32fe3aa8b), #6684 (ab9d21afc) and #6618 (bf06a8e5c). With that stack, the Linux and--windowsconversions of the eboot and its 9 bundled modules complete. I then rebuilt the relinker once per member with only that member left out. Without this PR, both targets stop inlibSceFace.prx:3b158c1e4from #6977 was left out of this build too, because it applies only on top of this PR;libSceFace.prxconverts beforelibSceFios2.prx, so this is the first stop either way.The other members each stop at their own step, so every one of them is needed for this title; the whole table is on #6977.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T21:22:49Z.
Thanks for the detailed leave-one-out run. It isolates this PR as necessary for Hasbro Family Fun Pack (CUSA03312) in the cumulative Linux/Windows conversion stack. Without #5138, the leave-one-out run stops in libSceFace.prx with “Unsupported symbol attributes.” I tried to add the setup and result to the PR's Tested section, but GitHub denied the body edit with an admin-rights error; the full evidence remains here in your comment.
Imported from boykopovar/AnyPS5. Originally posted by SandstromPL on 2026-10-19T04:11:50Z.
@veosett the
mainmerge (269a59e23) looks right to me: a section marker still takes the RELATIVE path with symbol 0, and a defined symbol takes #6357's path. Two things that follow from it:The 04:00 body edit sets
Unblocks: none, so the bot dropped theunblocks titlelabel. savvaniss's Hasbro Family Fun Pack bring-up (#7198) lists this PR in its stack, and the leave-one-out run now in the body shows the title needs it, soUnblocks: CUSA03312 #7198would fit the template's title-plus-discussion form if you want the label back. Limbo's bring-up (#6978) lists it too, through #6977.@Get-fix the merge conflicts with
3b158c1e4from #6977 (DTPMOD64 against the module's own section symbol). It removedconst auto position = output.size();and theif (relocation == 8) Io::WriteU64(...)line, because a RELATIVE entry with a symbol is now appended and skipped earlier. Keeping only this side compiles, but it leaves the symbol index in the TLS entry, andguest_own_tls_relocationsfails (AssertionError: (False, 16)). With this resolution, all 211 relinker tests pass here, includingguest_own_tls_relocationsandguest_relative_section_symbols(relinker-only Release, Ubuntu 24.04, GCC 13.3; Linux only):AI-assisted: yes (Claude Code)