Since #6112, every title aborts at start-up on Linux: "Thread destructor callback is already registered" #7636
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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 babyhuey on 2026-10-18T18:46:36Z.
Since #6112 (
fix(relinker): run guest preinit arrays before the module initializer, merged as376c04029), every catalog title I run on Linux aborts right after start-up:Scope. In a full Linux catalog run on
376c04029, all 97 titles except the ones skipped or stopped at load end with that line. That includes titles that ran much further on the previous run (218aa8f00): XashPS5, Wind Waker, Ruffle, VLC, XPSemu, vkQuake and PICO-8, plus the 8 trap-flag titles.Bisect. Ubuntu 24.04 container, GCC 13, Release, relinker and every library rebuilt at each commit, run with
.github/title-audit/run.py --linux:d7a455a90(first parent of the #6112 merge)376c04029(the #6112 merge)Thread destructor callback is already registeredWhere. The throw is
ThreadLifecycle::SetThreadDtorsincore/libs/prx/libkernel/Pthread/src/Thread.cpp, which refuses a second registration. So the guest libc's start-up that registers the thread destructor callback now runs twice: once through the preinit array that #6112 now runs, and again through the module initializer. That's my reading of the symptom; I haven't traced which entry it is.Not checked on Windows yet. #6112 also changes
WindowsGuestStartup.cppandWindowsGuestModuleWriter.cpp, so it may well hit there too.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T18:59:22Z.
I traced the in-tree setter call:
RegisterThreadExitHookinlibSceLibcInternal/Export.cppis the only source call site, and it always passesRunThreadDestructors_nid_no_patch; its function-local static is intended to register once per loaded module. Could you capture the setter call count and callback address (or a stack trace) on the failing Linux startup? That would confirm whether this is a repeated identical registration from the same module or a second guest callback, which determines whether the narrow idempotence fix in #7639 resolves the catalog failure.Imported from boykopovar/AnyPS5. Originally posted by ayam04 on 2026-10-18T19:04:22Z.
An angle from the #6112 side that may pin the duplicate down.
After #6112, a converted module's initialization is "run the preinit entries, then the module initializer" as a single load sequence (on Linux the module's DT_INIT is the combined stub, on Windows the startup runs the preinit slots before the initializer, on macOS the generated init does the same). So if a start-up routine is both a preinit entry and the module initializer, or the initializer calls into that same start-up, it now runs twice in one load. Both runs go through the same code with the same argument, so both
sceKernelSetThreadDtorscalls would carry the same callback, which is the case #7639's idempotence covers.A static check that settles it without a debugger: dump the bundled libc.prx dynamic tags and compare DT_INIT with the DT_PREINIT_ARRAY entries. If the initializer address is one of the preinit entries (or the initializer calls the entry), the duplicate is same-callback by construction and the narrow fix is enough. If the trace instead shows two different callback addresses, this is a different collision and the narrow fix will not resolve it.
Two adjacent notes:
libkernel/System/src/Rtld.cpp), the same double-run would next abort inSetThreadAtexitCount, so the idempotence may need to cover those setters as well.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T19:10:43Z.
Thanks, the preinit/DT_INIT check is a useful discriminator. One source detail to account for: the only in-tree caller of
sceKernelSetThreadDtorsis insideRegisterThreadExitHook, whose function-local static suppresses a second registration through that same loadedlibSceLibcInternalimage. So a repeated initializer alone would only explain the setter error if that initializer directly calls the kernel export, or if it causes registration through a second independently loaded copy; repeated calls to_sceLibcInternalThreadAtexitthrough the same image should hit the static guard.Could you run the dynamic-tag comparison on the exact module from the failing catalog startup and identify whether its initializer calls
sceKernelSetThreadDtorsdirectly or reaches another copy oflibSceLibcInternal? That will distinguish this hypothesis from a same-callback repeat the current source already guards against.Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-18T19:11:24Z.
A data point on scope: not every title stops. MXGP 26 (PPSA30839, retail) on
main400baa252b, which includes #6112, ran 2 of 2 times to the 140 s limit with pad input from start-up. That was Linux, RTX 4070 Ti, with every library built at that commit. It ships its ownlibc.prxinsce_module(next tolibSceFontGsm,libSceJobManager,libSceNpCppWebApiandlibScePfs). So a bundled libc alone doesn't trigger the second registration. Comparing which of these modules have a preinit array and a DT_INIT, against the homebrew titles @babyhuey lists, may separate the cases. I can capture theSetThreadDtorscall stacks on a homebrew title here if that would help.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T19:16:21Z.
Yes, a call-stack capture would help. If convenient, could you record each
sceKernelSetThreadDtorscall during the failing homebrew title startup, including the callback address and caller module/offset? If the failing title or a representative reproducer is available, the exact title/build plus whether the samelibSceLibcInternalimage is loaded twice would tell us whether #7639 covers this startup failure. The MXGP pass is a useful control, but does not identify the failing call path.Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-18T19:19:03Z.
@MarcZX10 on it. The run is Wind Waker Recompiled (PPSA99309, @babyhuey's bisect title) on
main400baa252b, with every library built at that commit, so it includes #6112 and not #7639. It runs under gdb with a breakpoint onThreadLifecycle::SetThreadDtors. For each call I'll record the callback address and what it resolves to, the stack with each frame's module, and thelibSceLibcInternalimages loaded at that point. Results here shortly.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-18T19:42:03Z.
@MarcZX10 on whether #7639 covers it: on its own, no.
main376c04029plus #7639 (d10b11432, clean merge), relinker and every library rebuilt, Linux, the same setup as above. Wind Waker (PPSA99309), XashPS5 (PPSA19111) and Ruffle (PPSA68091) all still abort at start-up, now on the next setter:That's
ThreadLifecycle::SetThreadAtexitCount, right afterSetThreadDtorsinThread.cpp. So the second registration repeats the whole hook set, not just the destructor callback.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-18T19:42:19Z.
@MarcZX10 first results: Wind Waker Recompiled (PPSA99309) on
main400baa252b, with every library built there (includes #6112, not #7639). It aborts at 0 s withThread destructor callback is already registered. Under gdb with a breakpoint onThreadLifecycle::SetThreadDtors:0x7ffff7e44200from the same return address,0x7ffff7e44111. The second throws.libSceLibcInternalimage.libSceLibcInternal.prxis loaded once, at0x7ffff7dffb40–0x7ffff7e09b7f. The caller at0x7ffff7e44111and the callback are outside it, so the setter isn't reached throughRegisterThreadExitHook. The caller is in another module, one that registers its own routine._dl_init→call_initfor the same link map (l=0x7ffff7fbd290). The first goes through0x7ffff7fbb27c. The second goes through0x7ffff7fbb25dand then0x7ffff7e44022, so that module's start-up runs once per path. That fits @ayam04's reading: one start-up routine reached both as a preinit entry and from the module initializer.Since the two registrations are the same callback from the same module, #7639's "allow repeated registration" should cover this start-up, if it accepts an identical repeat. A second, different callback would still be refused. The second capture is already running with the full library map and
/procmappings at each hit. It will name the caller's module, give offsets inside it, and show what0x7ffff7fbb25d/27care, probably #6112's combined init stub. I'll post it here.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-18T19:45:39Z.
@MarcZX10 @ayam04 the second capture names the module and shows why the routine runs twice. The caller is the title's own libc, converted as
sce_module/libc.prx.guest.prx. ItsDT_INITis now #6112's combined stub at0x177267. Offsets below are virtual addresses in that module.+0x200, set from+0x111, inside the routine at+0x100:DT_INIT): it calls the pointer at0x113ce0, which is call 1 (returns to0x17727c, frame #3 of the first stack). Then it jumps to0x177248, which calls the module's original initializer at+0x10(returns to0x17725d, frame #5 of the second stack):+0x22):So this libc's own initializer runs the routine stored at
0x113ce0, the entry #6112 runs as its preinit array. Running the preinit array before it makes the routine run twice. That matches whatmaindid before #6112: it didn't run module preinit arrays, and this title worked. The gABI also processesDT_PREINIT_ARRAYonly for the executable, not for shared objects, as @SandstromPL noted for fpPS4'sdigest_dynamic. Only onelibSceLibcInternal.prximage is loaded, and it isn't on these stacks.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T19:48:27Z.
Thanks for the full module trace. It confirms the duplicate is caused by #6112’s wrapper: the module’s own
DT_INITcalls the same startup pointer that the wrapper has already invoked from itsDT_PREINIT_ARRAYentry. The subsequent repeatedSetThreadAtexitCountalso shows why making onlySetThreadDtorsidempotent in #7639 would address a symptom rather than the startup sequence. This supports #7646’s revert as the root-level correction; any future preinit handling should distinguish the main executable from shared modules and have a regression for a module whose initializer runs its own startup table.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-18T19:52:04Z.
@babyhuey thanks for the clean bisect. We traced it to #6112 running libc's preinit array a second time (a recent
libc.prxalready runs it fromDT_INIT). The revert is in #7646. If you have time, could you rerun a few titles on that branch to confirm start-up works again?Imported from boykopovar/AnyPS5. Originally posted by ps54all on 2026-10-18T20:01:05Z.
Windows data point, since the report was Linux-only: the same abort hits on Windows 11 (MinGW-w64 GCC 15.2, RTX 3080, NVIDIA 610.74) with Metal Gear Solid Master Collection Vol. 1 / MGS4 (PPSA18194), relinked on
main376c04029plus open PRs. It also comes from the title'ssce_module/libc.prx.guest.prx:Thread destructor callback is already registered, thrown fromlibkernel.prx, about 3 s after start.With #7639 applied, the next registration in the same start-up throws
Thread atexit count callback is already registered. With a local change that accepts a repeated identical callback inSetThreadAtexitCountandSetThreadAtexitReporttoo, the title boots and reaches gameplay (one 600 s run, no further aborts). This matches the duplicated start-up reading above. I have not run #7646 yet.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-18T20:05:08Z.
@ps54all thanks, that's useful: it's the same module,
sce_module/libc.prx.guest.prx, on Windows. TheSetThreadAtexitCountabort after #7639 fits the reading above. The whole routine at0x113ce0runs twice, so each registration in it hits a duplicate in turn. Making each setter idempotent gets past that, but the routine still runs twice. #7646 makes it run once, so if you can run MGS4 on #7646 without your local change, that would confirm the revert on Windows too.@MarcZX10 agreed. A future preinit change should limit it to the executable and add a regression test for a module whose
DT_INITruns its own startup table.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by m335671 on 2026-10-18T20:32:06Z.
The same abort happens on Windows: Sword of the Sea (PPSA25344, retail 01.510.000) on
main400baa252, with every library built at that commit (WinLibs GCC 15.2.0, Windows 11, Ryzen 9 7900, RTX 4070). It stops right afterFBootAllocator, before any title thread starts:The title ships its own
libc.prxinsce_module/, alongsidelibSceFontGsm,libSceJobManager,libSceNpCppWebApiandlibScePfs, the same set as the MXGP 26 control above. Itsprx/also holds 32 Wwise and EOS modules. The parent of the #6112 merge (d7a455a90) starts and reaches gameplay with the same conversion steps, so on this title the regression comes from #6112.AI-assisted: yes (Claude Code). The builds, the runs and this comment were done and written by Claude Code on my machine.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T20:32:53Z.
The Sword of the Sea report adds an independent Windows reproduction on a title with its own
sce_module/libc.prx, with the pre-#6112 parent reaching gameplay. Together with the Wind Waker/XashPS5 Linux bisect and the MGS4 Windows trace, this confirms the regression is not Linux-only or limited to one title layout. It is consistent with #6112 invoking the shared-object preinit path before aDT_INITthat already runs the startup table. The remaining validation for #7646 is a title startup run on the reverted head, especially Windows; the generated-module tests establish the mechanism but not title startup.Imported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-18T20:42:00Z.
@oneandonlydean start-up works again with the revert.
main6e27fc8f0plus #7646 atc3b900159(clean merge), relinker and every library rebuilt, Linux (Ubuntu 24.04 container, GCC 13, Release), 30 s per title. None of these throw the duplicate registration; each is back to its pre-#6112 stop:getpwuidcheck.ruffle.log, after the/dev/urandomopen, and in its firstRunThread(the fixed-base GOT read of #4013).--trap-sdk-syscall-stubs): exit 1, its ownforwarder.jsonnotice.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by m335671 on 2026-10-18T20:44:15Z.
The Windows title run for #7646: Sword of the Sea (PPSA25344, retail 01.510.000) on #7646's head
441190cf6, with the relinker and every library built at that commit and no local changes (WinLibs GCC 15.2.0, Windows 11, Ryzen 9 7900, RTX 4070, NVIDIA 616.92). I reconverted the title from scratch with the same steps as the failing400baa252run above.It starts without the abort: there's no
already registeredthrow in any of the three setters, and nothing else stops it. It reaches the title screen, and New Game loads into the opening cutscene, where the run stopped at the 240 s limit I set. The title uses the bundledsce_module/libc.prx, the same module that aborts on400baa252. One run.AI-assisted: yes (Claude Code). The build, the run and this comment were done and written by Claude Code on my machine.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T20:45:47Z.
PR #7646 now has direct title-startup evidence for both host paths: the Linux eight-title matrix and the Windows Sword of the Sea run (fresh conversion, no duplicate-registration abort, reached the opening cutscene). Its Linux/Windows/macOS relinker matrix, ASan, conventions, eligibility and labels checks have all completed successfully; path-scoped full Linux/Windows suites were skipped. The Windows title run is one run and stopped at a 240 s limit, so it confirms startup recovery for that case rather than sustained gameplay.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by ps54all on 2026-10-22T08:48:27Z.
@milescoviello confirmed on Windows: MGS4 (PPSA18194) boots and reaches gameplay with #7646. Build: our test branch at main
1d4164552(includes #7646) plus unrelated open AGC picks, with #7639 and our local atexit workaround removed. No duplicate-registration abort. RTX 3080, NVIDIA 610.74, WinLibs GCC 15.2, Release.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-22T09:14:26Z.
@ps54all thanks for confirming MGS4 (PPSA18194) on Windows with #7646, without the atexit workaround.
AI-assisted: yes (Claude Code)