revert(relinker): run guest preinit arrays before the module initializer (#6112) #7646
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7646"
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 oneandonlydean on 2026-10-18T19:25:17Z.
What
Reverts #6112 (merge
376c04029), which makes every title abort at start-up on Linux withThread destructor callback is already registered(#7636).SCE-built modules run their own preinit array from their initializer. In a recent
libc.prxtheDT_INITfunction loads the start ofDT_PREINIT_ARRAYand calls each non-null entry before going on. #6112 calls those entries again from the stub it places in front ofDT_INITon Linux and macOS, and beforeInitRvaon Windows. So libc's early start-up runs twice, and the second thread destructor registration is refused byThreadLifecycle::SetThreadDtors.Running a module's preinit array outside its initializer would need a module that doesn't run its own, and none has been seen yet. That can come back as a new pull request with such a module as its test case.
Tested
441190cf6onmain8a7f434f1: the full build succeeds, and the relinker tests plus everyguest_test (518 in all) give 512 passed, 6 skipped (theguest_video_out_*display tests, which need a display) and 0 failed.guest_preinitis removed with the change.libc.prx:DT_PREINIT_ARRAYholds one entry, and theDT_INITfunction loads that array and calls each non-null entry before going on. With #6112 the same entries also run from the stub in front ofDT_INIT(and beforeInitRvaon Windows).libc.prx, and the ctests don't load one, so the ctests above show the revert breaks nothing but not that it fixes the start-up. The first parent of the #6112 merge,d7a455a90, is the bisected good build in #7636, and this revert restores its relinker sources byte for byte.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 MarcZX10 on 2026-10-18T19:26:10Z.
CI note: the conventions check currently fails on this head for both commit
441190cf6(the generatedRevert "Merge pull request ..."subject) and the PR title (Revert "fix(relinker): ..." (#6112)). Please retitle/reword the commit and PR to the repository’s Conventional Commits format (for example,fix(relinker): revert duplicate guest preinit execution). The relinker jobs are still pending; the failing conventions output is available in run 39158694737.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T19:26:21Z.
Scope correction for the PR description: #7636’s initial “every title” report has a counterexample now. MXGP 26 PPSA30839 reached the 140-second limit twice on Linux with #6112 and its own
libc.prx, so the description should say the regression affects at least the reported titles/startup paths, not every title or every bundled libc. The exact Wind Waker call trace is still being collected in #7636; it should help decide whether reverting all preinit handling is necessary or whether the callback-registration collision is narrower.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-18T19:43:55Z.
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.
core/relinker/CMakeLists.txtcore/relinker/CMakeLists.txtdocs/dev/debt/relinker.mddocs/dev/ARCHITECTURE.mdcore/relinker/CMakeLists.txtdocs/dev/ARCHITECTURE.mddocs/dev/debt/relinker.mddocs/dev/ARCHITECTURE.mddocs/dev/ARCHITECTURE.mdcore/relinker/CMakeLists.txtcore/relinker/elfpatcher/src/linux/LinuxGuestModuleWriter.cppcore/relinker/elfpatcher/src/macos/MacOsGuestModuleWriter.cppcore/relinker/elfpatcher/src/windows/WindowsGuestModuleWriter.cppcore/relinker/relinker/include/relinker/guest/GuestImage.hppcore/relinker/relinker/src/guest/GuestImageReader.cppdocs/dev/ARCHITECTURE.mddocs/dev/ARCHITECTURE.mdcore/relinker/CMakeLists.txtdocs/dev/ARCHITECTURE.mddocs/dev/ARCHITECTURE.mddocs/dev/ARCHITECTURE.mdcore/relinker/CMakeLists.txtcore/relinker/domain/include/domain/GuestRuntime.hppcore/relinker/elfpatcher/src/linux/LinuxGuestModuleWriter.cppcore/relinker/elfpatcher/src/macos/MacOsGuestModuleWriter.cppcore/relinker/elfpatcher/src/windows/WindowsGuestModuleWriter.cppcore/relinker/relinker/include/relinker/guest/GuestImage.hppcore/relinker/relinker/src/guest/GuestImageReader.cppdocs/dev/debt/relinker.mdcore/relinker/CMakeLists.txtdocs/dev/debt/relinker.mdcore/relinker/CMakeLists.txtcore/relinker/elfpatcher/include/elfpatcher/macos/MacOsImage.hppcore/relinker/elfpatcher/src/macos/MacOsImage.cppdocs/dev/debt/relinker.mdcore/relinker/CMakeLists.txtcore/relinker/domain/include/domain/GuestRuntime.hppcore/relinker/elfpatcher/include/elfpatcher/macos/MacOsImage.hppcore/relinker/elfpatcher/src/linux/LinuxGuestModuleWriter.cppcore/relinker/elfpatcher/src/macos/MacOsGuestModuleWriter.cppcore/relinker/elfpatcher/src/macos/MacOsImage.cppcore/relinker/elfpatcher/src/windows/WindowsGuestModuleWriter.cppcore/relinker/elfpatcher/src/windows/WindowsGuestStartup.cppcore/relinker/relinker/include/relinker/guest/GuestImage.hppcore/relinker/relinker/src/guest/GuestImageReader.cppcore/relinker/relinker/tests/test_guest_preinit.pydocs/dev/ARCHITECTURE.mddocs/dev/debt/relinker.mdcore/relinker/CMakeLists.txtdocs/dev/debt/relinker.mddocs/dev/ARCHITECTURE.mdImported from boykopovar/AnyPS5. Originally posted by DProkos on 2026-10-18T19:51:02Z.
Windows check of 441190cf6 merged onto current
main(48d61f53b, clean merge).Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7 UCRT, Ninja, Release,
ANYPS5_RELINKER_ONLY=ON,BUILD_TESTING=ON, Python 3.11.0.main;guest_preinitis removed with the change).Like the Linux run, this shows the revert breaks nothing in the Windows output's ctests. It does not show that it fixes start-up: no title and no SDK
libc.prxwas run.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T20:05:45Z.
Review: COMMENTED
The implementation diff has passing relinker builds/tests across Linux, Windows, macOS, and ASan, but the required
conventionscheck currently fails because the revert commit subject isRevert "Merge pull request #6112 ...", which is not Conventional Commits. Could you amend the commit subject to something likerevert(relinker): run guest preinit arrays before the module initializerand rerun CI? The check annotation points to this exact commit subject.Imported from boykopovar/AnyPS5. Originally posted by simonbbby on 2026-10-18T20:25:07Z.
Native Linux generated-module check of exact head
441190cf6955dc7a1822e4f4fd09be9efa525910against its parent8a7f434f19052c75d6cb54ba2342905e5f0b238e(Ubuntu 24.04, kernel 7.0.0-38, GCC 13.3, Release).This adds an execution control for the double-preinit mechanism, without loading an SDK libc. I extended the removed
test_guest_preinit.py'srecording_module()fixture so itsDT_INITcalls each non-null pointer in its own preinit array, then records its original initializer arguments and returns0x5a17. Every converted module is loaded throughctypes.CDLLin a fresh subprocess with the existingguest_module_args_hostprovider.DT_INITruns its two preinit callbacksDT_INITruns one callback; the other slot is nullDT_INITsees two null slotsDT_INITdoes not run its two callbacksAll eight conversions and native loads complete. The body of
DT_INITrecords its nonzero argument pair exactly once, and the result is0x5a17exactly once in every case; each input hash stays unchanged. Thus the duplicated events in the first two rows are the preinit callbacks, not two loader executions of the whole initializer or a damaged argument/result bridge. The non-self-initializing row also explicitly confirms the revert's tradeoff rather than hiding it.On the restored, clean PR worktree,
guest_module_args,guest_deferred_dependencies,guest_module_finiandinit_array_rootspass (4/4).This demonstrates the reported mechanism for a self-initializing module and the changed behavior for a module that leaves its preinit array to the converter. It does not reproduce
ThreadLifecycle's registration abort, establish which real modules self-initialize, or prove that every title is affected/fixed. No title, SDK module, Windows/macOS execution or full-suite result is claimed.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T20:28:12Z.
Thanks for updating the PR title and adding the generated-module execution control. The new check is useful for the self-initializing-module mechanism, and the description correctly states that it does not reproduce title startup.
The latest conventions run (39160782891) now reports only the commit subject as failing:
Revert "Merge pull request #6112 ...". Could you reword that commit to a Conventional Commit subject such asfix(relinker): revert duplicate guest preinit executionand rerun conventions? The PR title itself now passes.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T20:39:11Z.
Thanks for rewording the commit. The latest conventions check now passes on
c3b900159; the relinker platform matrix and ASan jobs are running on this head. I will treat the title-startup result separately from the generated-module control already reported.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T20:43:57Z.
The issue reporter has now run the reverted head (
main6e27fc8f0+ this PRc3b900159) on Linux with rebuilt libraries across eight titles. None hit the duplicate-registration abort; each returned to its previously observed stop point (including Wind Waker, XashPS5, vkQuake, PICO-8, Ruffle, VLC, XPSemu and PS5CEMU-HAR). This is title-startup validation for those cases, distinct from the generated-module control. CI currently passes Linux, macOS arm64/x86_64, ASan and conventions; the Windows relinker job is still pending in run 39164239098.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T20:44:30Z.
Additional title validation is now reported on #7636: Sword of the Sea (PPSA25344, retail 01.510.000) was freshly converted and run on Windows 11 with the relinker and libraries built at this PR's head
441190cf6. It produced no duplicate-registration throw, reached the title screen, and loaded New Game into the opening cutscene before the reporter's 240-second limit. This is one Windows run; it validates startup for this title, not sustained gameplay. Combined with the eight Linux title runs, the original startup regression has direct reverted-head evidence on both host OSes.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T20:44:54Z.
The GitHub run has now completed successfully: Linux and Windows relinker builds, macOS arm64/x86_64, ASan, eligibility, conventions and labels passed; the path-scoped full Linux/Windows suites were skipped. Together with the reported Linux title matrix and the single Windows Sword of the Sea run, both startup validation and the generated-module control are now documented. The Windows title reached its opening cutscene, not a sustained gameplay result.
AI-assisted: yes