Since #6112, every title aborts at start-up on Linux: "Thread destructor callback is already registered" #7636

Closed
opened 2026-10-18 18:46:36 +00:00 by babyhuey · 20 comments
babyhuey commented 2026-10-18 18:46:36 +00:00 (Migrated from github.com)
Contributor

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 as 376c04029), every catalog title I run on Linux aborts right after start-up:

[libc] unhandled exception 'St13runtime_error' thrown from 0x7f...bba
terminate called after throwing an instance of 'std::runtime_error'
  what():  Thread destructor callback is already registered

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:

Build Wind Waker (PPSA99309) XashPS5 (PPSA19111)
d7a455a90 (first parent of the #6112 merge) exit 0, its own "Copy your own disc image ..." message exit 0, its own "Copy the whole "valve" folder ..." message
376c04029 (the #6112 merge) abort, Thread destructor callback is already registered the same abort

Where. The throw is ThreadLifecycle::SetThreadDtors in core/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.cpp and WindowsGuestModuleWriter.cpp, so it may well hit there too.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5912889012 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/7636). Originally posted by [babyhuey](https://github.com/babyhuey) on 2026-10-18T18:46:36Z. --- Since #6112 (`fix(relinker): run guest preinit arrays before the module initializer`, merged as `376c04029`), every catalog title I run on Linux aborts right after start-up: ``` [libc] unhandled exception 'St13runtime_error' thrown from 0x7f...bba terminate called after throwing an instance of 'std::runtime_error' what(): Thread destructor callback is already registered ``` **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`: | Build | Wind Waker (PPSA99309) | XashPS5 (PPSA19111) | |---|---|---| | `d7a455a90` (first parent of the #6112 merge) | exit 0, its own "Copy your own disc image ..." message | exit 0, its own "Copy the whole \"valve\" folder ..." message | | `376c04029` (the #6112 merge) | abort, `Thread destructor callback is already registered` | the same abort | **Where.** The throw is `ThreadLifecycle::SetThreadDtors` in `core/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.cpp` and `WindowsGuestModuleWriter.cpp`, so it may well hit there too. AI-assisted: yes
MarcZX10 commented 2026-10-18 18:59:22 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T18:59:22Z.


I traced the in-tree setter call: RegisterThreadExitHook in libSceLibcInternal/Export.cpp is the only source call site, and it always passes RunThreadDestructors_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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6253848244 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/7636#issuecomment-6253848244). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-18T18:59:22Z. --- I traced the in-tree setter call: `RegisterThreadExitHook` in `libSceLibcInternal/Export.cpp` is the only source call site, and it always passes `RunThreadDestructors_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.
ayam04 commented 2026-10-18 19:04:22 +00:00 (Migrated from github.com)
Author
Contributor

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 sceKernelSetThreadDtors calls 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:

  • If the same start-up also registers the atexit count/report callbacks (all three setters are exported from libkernel/System/src/Rtld.cpp), the same double-run would next abort in SetThreadAtexitCount, so the idempotence may need to cover those setters as well.
  • The Windows output runs preinit entries through the same kind of sequence, so it has the same exposure even though it has not been tested there; the fix is host-side, so it covers all three platforms.
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6253899460 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/7636#issuecomment-6253899460). Originally posted by [ayam04](https://github.com/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 `sceKernelSetThreadDtors` calls 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: - If the same start-up also registers the atexit count/report callbacks (all three setters are exported from `libkernel/System/src/Rtld.cpp`), the same double-run would next abort in `SetThreadAtexitCount`, so the idempotence may need to cover those setters as well. - The Windows output runs preinit entries through the same kind of sequence, so it has the same exposure even though it has not been tested there; the fix is host-side, so it covers all three platforms.
MarcZX10 commented 2026-10-18 19:10:43 +00:00 (Migrated from github.com)
Author
Contributor

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 sceKernelSetThreadDtors is inside RegisterThreadExitHook, whose function-local static suppresses a second registration through that same loaded libSceLibcInternal image. 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 _sceLibcInternalThreadAtexit through 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 sceKernelSetThreadDtors directly or reaches another copy of libSceLibcInternal? That will distinguish this hypothesis from a same-callback repeat the current source already guards against.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6253967177 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/7636#issuecomment-6253967177). Originally posted by [MarcZX10](https://github.com/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 `sceKernelSetThreadDtors` is inside `RegisterThreadExitHook`, whose function-local static suppresses a second registration through that same loaded `libSceLibcInternal` image. 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 `_sceLibcInternalThreadAtexit` through 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 `sceKernelSetThreadDtors` directly or reaches another copy of `libSceLibcInternal`? That will distinguish this hypothesis from a same-callback repeat the current source already guards against.
milescoviello commented 2026-10-18 19:11:24 +00:00 (Migrated from github.com)
Author
Contributor

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 main 400baa252b, 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 own libc.prx in sce_module (next to libSceFontGsm, libSceJobManager, libSceNpCppWebApi and libScePfs). 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 the SetThreadDtors call stacks on a homebrew title here if that would help.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6253974332 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/7636#issuecomment-6253974332). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-18T19:11:24Z. --- A data point on scope: not every title stops. MXGP 26 (PPSA30839, retail) on `main` 400baa252b, 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 own `libc.prx` in `sce_module` (next to `libSceFontGsm`, `libSceJobManager`, `libSceNpCppWebApi` and `libScePfs`). 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 the `SetThreadDtors` call stacks on a homebrew title here if that would help. AI-assisted: yes (Claude Code)
MarcZX10 commented 2026-10-18 19:16:21 +00:00 (Migrated from github.com)
Author
Contributor

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 sceKernelSetThreadDtors call 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 same libSceLibcInternal image 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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6254038385 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/7636#issuecomment-6254038385). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-18T19:16:21Z. --- Yes, a call-stack capture would help. If convenient, could you record each `sceKernelSetThreadDtors` call 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 same `libSceLibcInternal` image 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.
milescoviello commented 2026-10-18 19:19:03 +00:00 (Migrated from github.com)
Author
Contributor

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 main 400baa252b, with every library built at that commit, so it includes #6112 and not #7639. It runs under gdb with a breakpoint on ThreadLifecycle::SetThreadDtors. For each call I'll record the callback address and what it resolves to, the stack with each frame's module, and the libSceLibcInternal images loaded at that point. Results here shortly.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6254066165 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/7636#issuecomment-6254066165). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-18T19:19:03Z. --- @MarcZX10 on it. The run is Wind Waker Recompiled (PPSA99309, @babyhuey's bisect title) on `main` 400baa252b, with every library built at that commit, so it includes #6112 and not #7639. It runs under gdb with a breakpoint on `ThreadLifecycle::SetThreadDtors`. For each call I'll record the callback address and what it resolves to, the stack with each frame's module, and the `libSceLibcInternal` images loaded at that point. Results here shortly. AI-assisted: yes (Claude Code)
babyhuey commented 2026-10-18 19:42:03 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-18T19:42:03Z.


@MarcZX10 on whether #7639 covers it: on its own, no. main 376c04029 plus #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:

[libc] unhandled exception 'St13runtime_error' thrown from 0x7f...c6c
terminate called after throwing an instance of 'std::runtime_error'
  what():  Thread atexit count callback is already registered

That's ThreadLifecycle::SetThreadAtexitCount, right after SetThreadDtors in Thread.cpp. So the second registration repeats the whole hook set, not just the destructor callback.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6254296672 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/7636#issuecomment-6254296672). Originally posted by [babyhuey](https://github.com/babyhuey) on 2026-10-18T19:42:03Z. --- @MarcZX10 on whether #7639 covers it: on its own, no. `main` `376c04029` plus #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: ``` [libc] unhandled exception 'St13runtime_error' thrown from 0x7f...c6c terminate called after throwing an instance of 'std::runtime_error' what(): Thread atexit count callback is already registered ``` That's `ThreadLifecycle::SetThreadAtexitCount`, right after `SetThreadDtors` in `Thread.cpp`. So the second registration repeats the whole hook set, not just the destructor callback. AI-assisted: yes
milescoviello commented 2026-10-18 19:42:19 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-18T19:42:19Z.


@MarcZX10 first results: Wind Waker Recompiled (PPSA99309) on main 400baa252b, with every library built there (includes #6112, not #7639). It aborts at 0 s with Thread destructor callback is already registered. Under gdb with a breakpoint on ThreadLifecycle::SetThreadDtors:

  • Two calls, identical. Both pass callback 0x7ffff7e44200 from the same return address, 0x7ffff7e44111. The second throws.
  • One libSceLibcInternal image. libSceLibcInternal.prx is loaded once, at 0x7ffff7dffb40–0x7ffff7e09b7f. The caller at 0x7ffff7e44111 and the callback are outside it, so the setter isn't reached through RegisterThreadExitHook. The caller is in another module, one that registers its own routine.
  • Both calls come from the same module's initialization. Both are under glibc's _dl_init → call_init for the same link map (l=0x7ffff7fbd290). The first goes through 0x7ffff7fbb27c. The second goes through 0x7ffff7fbb25d and then 0x7ffff7e44022, 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 /proc mappings at each hit. It will name the caller's module, give offsets inside it, and show what 0x7ffff7fbb25d/27c are, probably #6112's combined init stub. I'll post it here.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6254299274 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/7636#issuecomment-6254299274). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-18T19:42:19Z. --- @MarcZX10 first results: Wind Waker Recompiled (PPSA99309) on `main` 400baa252b, with every library built there (includes #6112, not #7639). It aborts at 0 s with `Thread destructor callback is already registered`. Under gdb with a breakpoint on `ThreadLifecycle::SetThreadDtors`: - **Two calls, identical.** Both pass callback `0x7ffff7e44200` from the same return address, `0x7ffff7e44111`. The second throws. - **One `libSceLibcInternal` image.** `libSceLibcInternal.prx` is loaded once, at `0x7ffff7dffb40`–`0x7ffff7e09b7f`. The caller at `0x7ffff7e44111` and the callback are outside it, so the setter isn't reached through `RegisterThreadExitHook`. The caller is in another module, one that registers its own routine. - **Both calls come from the same module's initialization.** Both are under glibc's `_dl_init` → `call_init` for the same link map (`l=0x7ffff7fbd290`). The first goes through `0x7ffff7fbb27c`. The second goes through `0x7ffff7fbb25d` and then `0x7ffff7e44022`, 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 `/proc` mappings at each hit. It will name the caller's module, give offsets inside it, and show what `0x7ffff7fbb25d`/`27c` are, probably #6112's combined init stub. I'll post it here. AI-assisted: yes (Claude Code)
milescoviello commented 2026-10-18 19:45:39 +00:00 (Migrated from github.com)
Author
Contributor

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. Its DT_INIT is now #6112's combined stub at 0x177267. Offsets below are virtual addresses in that module.

  • Both calls: callback +0x200, set from +0x111, inside the routine at +0x100:
    0x100: sub  $0x8,%rsp
    0x104: lea  0x200,%rdi
    0x10b: call *0x113908        ; sceKernelSetThreadDtors
    
  • The stub (DT_INIT): it calls the pointer at 0x113ce0, which is call 1 (returns to 0x17727c, frame #3 of the first stack). Then it jumps to 0x177248, which calls the module's original initializer at +0x10 (returns to 0x17725d, frame #5 of the second stack):
    0x177267: push %rax
    0x177268: mov  0x113ce0,%rax
    0x17726f: test %rax,%rax
    0x177272: je   0x17727c
    0x177274: xor  %edi,%edi ; xor %esi,%esi ; xor %edx,%edx
    0x17727a: call *%rax                 ; call 1
    0x17727c: pop  %rax
    0x17727d: jmp  0x177248
    ...
    0x177258: call 0x10                  ; the module's original init
    
  • The original initializer already calls the same pointer, which is call 2 (returns to +0x22):
    0x10: sub  $0x8,%rsp
    0x14: mov  0x113ce0,%rax
    0x1b: test %rax,%rax
    0x1e: je   0x22
    0x20: call *%rax                     ; call 2
    0x22: add  $0x8,%rsp
    

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 what main did before #6112: it didn't run module preinit arrays, and this title worked. The gABI also processes DT_PREINIT_ARRAY only for the executable, not for shared objects, as @SandstromPL noted for fpPS4's digest_dynamic. Only one libSceLibcInternal.prx image is loaded, and it isn't on these stacks.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6254331604 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/7636#issuecomment-6254331604). Originally posted by [milescoviello](https://github.com/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`. Its `DT_INIT` is now #6112's combined stub at `0x177267`. Offsets below are virtual addresses in that module. - **Both calls:** callback `+0x200`, set from `+0x111`, inside the routine at `+0x100`: ``` 0x100: sub $0x8,%rsp 0x104: lea 0x200,%rdi 0x10b: call *0x113908 ; sceKernelSetThreadDtors ``` - **The stub (`DT_INIT`):** it calls the pointer at `0x113ce0`, which is call 1 (returns to `0x17727c`, frame #3 of the first stack). Then it jumps to `0x177248`, which calls the module's original initializer at `+0x10` (returns to `0x17725d`, frame #5 of the second stack): ``` 0x177267: push %rax 0x177268: mov 0x113ce0,%rax 0x17726f: test %rax,%rax 0x177272: je 0x17727c 0x177274: xor %edi,%edi ; xor %esi,%esi ; xor %edx,%edx 0x17727a: call *%rax ; call 1 0x17727c: pop %rax 0x17727d: jmp 0x177248 ... 0x177258: call 0x10 ; the module's original init ``` - **The original initializer** already calls the same pointer, which is call 2 (returns to `+0x22`): ``` 0x10: sub $0x8,%rsp 0x14: mov 0x113ce0,%rax 0x1b: test %rax,%rax 0x1e: je 0x22 0x20: call *%rax ; call 2 0x22: add $0x8,%rsp ``` 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 what `main` did before #6112: it didn't run module preinit arrays, and this title worked. The gABI also processes `DT_PREINIT_ARRAY` only for the executable, not for shared objects, as @SandstromPL noted for fpPS4's `digest_dynamic`. Only one `libSceLibcInternal.prx` image is loaded, and it isn't on these stacks. AI-assisted: yes (Claude Code)
MarcZX10 commented 2026-10-18 19:48:27 +00:00 (Migrated from github.com)
Author
Contributor

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_INIT calls the same startup pointer that the wrapper has already invoked from its DT_PREINIT_ARRAY entry. The subsequent repeated SetThreadAtexitCount also shows why making only SetThreadDtors idempotent 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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6254359577 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/7636#issuecomment-6254359577). Originally posted by [MarcZX10](https://github.com/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_INIT` calls the same startup pointer that the wrapper has already invoked from its `DT_PREINIT_ARRAY` entry. The subsequent repeated `SetThreadAtexitCount` also shows why making only `SetThreadDtors` idempotent 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.
oneandonlydean commented 2026-10-18 19:52:04 +00:00 (Migrated from github.com)
Author
Contributor

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.prx already runs it from DT_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?

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6254395146 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/7636#issuecomment-6254395146). Originally posted by [oneandonlydean](https://github.com/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.prx` already runs it from `DT_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?
ps54all commented 2026-10-18 20:01:05 +00:00 (Migrated from github.com)
Author
Contributor

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 main 376c04029 plus open PRs. It also comes from the title's sce_module/libc.prx.guest.prx: Thread destructor callback is already registered, thrown from libkernel.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 in SetThreadAtexitCount and SetThreadAtexitReport too, 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

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6254483567 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/7636#issuecomment-6254483567). Originally posted by [ps54all](https://github.com/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 `main` 376c04029 plus open PRs. It also comes from the title's `sce_module/libc.prx.guest.prx`: `Thread destructor callback is already registered`, thrown from `libkernel.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 in `SetThreadAtexitCount` and `SetThreadAtexitReport` too, 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
milescoviello commented 2026-10-18 20:05:08 +00:00 (Migrated from github.com)
Author
Contributor

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. The SetThreadAtexitCount abort after #7639 fits the reading above. The whole routine at 0x113ce0 runs 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_INIT runs its own startup table.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6254525201 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/7636#issuecomment-6254525201). Originally posted by [milescoviello](https://github.com/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. The `SetThreadAtexitCount` abort after #7639 fits the reading above. The whole routine at `0x113ce0` runs 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_INIT` runs its own startup table. AI-assisted: yes (Claude Code)
m335671 commented 2026-10-18 20:32:06 +00:00 (Migrated from github.com)
Author
Contributor

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 main 400baa252, with every library built at that commit (WinLibs GCC 15.2.0, Windows 11, Ryzen 9 7900, RTX 4070). It stops right after FBootAllocator, before any title thread starts:

[libc] unhandled exception 'St13runtime_error' thrown from 00007ffd12cbebcc
  what():  Thread destructor callback is already registered
FATAL: abort() (SIGABRT)

The title ships its own libc.prx in sce_module/, alongside libSceFontGsm, libSceJobManager, libSceNpCppWebApi and libScePfs, the same set as the MXGP 26 control above. Its prx/ 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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6254802225 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/7636#issuecomment-6254802225). Originally posted by [m335671](https://github.com/m335671) on 2026-10-18T20:32:06Z. --- The same abort happens on **Windows**: Sword of the Sea (PPSA25344, retail 01.510.000) on `main` `400baa252`, with every library built at that commit (WinLibs GCC 15.2.0, Windows 11, Ryzen 9 7900, RTX 4070). It stops right after `FBootAllocator`, before any title thread starts: ``` [libc] unhandled exception 'St13runtime_error' thrown from 00007ffd12cbebcc what(): Thread destructor callback is already registered FATAL: abort() (SIGABRT) ``` The title ships its own `libc.prx` in `sce_module/`, alongside `libSceFontGsm`, `libSceJobManager`, `libSceNpCppWebApi` and `libScePfs`, the same set as the MXGP 26 control above. Its `prx/` 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.
MarcZX10 commented 2026-10-18 20:32:53 +00:00 (Migrated from github.com)
Author
Contributor

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 a DT_INIT that 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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6254810075 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/7636#issuecomment-6254810075). Originally posted by [MarcZX10](https://github.com/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 a `DT_INIT` that 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.
babyhuey commented 2026-10-18 20:42:00 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-18T20:42:00Z.


@oneandonlydean start-up works again with the revert. main 6e27fc8f0 plus #7646 at c3b900159 (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:

  • Wind Waker (PPSA99309): exit 0, its own "Copy your own disc image ..." message.
  • XashPS5 (PPSA19111): exit 0, "Copy the whole "valve" folder ...".
  • vkQuake (PPSA99010): exit 0 at its getpwuid check.
  • PICO-8 for PS5 (PPSA99808): exit 1, "Make sure elfldr is running (port 9021)".
  • Ruffle (PPSA68091), VLC (PPSA85300), XPSemu (PPSA97358): the same early stops as before #6112, after ruffle.log, after the /dev/urandom open, and in its first RunThread (the fixed-base GOT read of #4013).
  • PS5CEMU-HAR (PPSA99360, --trap-sdk-syscall-stubs): exit 1, its own forwarder.json notice.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6254903889 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/7636#issuecomment-6254903889). Originally posted by [babyhuey](https://github.com/babyhuey) on 2026-10-18T20:42:00Z. --- @oneandonlydean start-up works again with the revert. `main` `6e27fc8f0` plus #7646 at `c3b900159` (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: - Wind Waker (PPSA99309): exit 0, its own "Copy your own disc image ..." message. - XashPS5 (PPSA19111): exit 0, "Copy the whole \"valve\" folder ...". - vkQuake (PPSA99010): exit 0 at its `getpwuid` check. - PICO-8 for PS5 (PPSA99808): exit 1, "Make sure elfldr is running (port 9021)". - Ruffle (PPSA68091), VLC (PPSA85300), XPSemu (PPSA97358): the same early stops as before #6112, after `ruffle.log`, after the `/dev/urandom` open, and in its first `RunThread` (the fixed-base GOT read of #4013). - PS5CEMU-HAR (PPSA99360, `--trap-sdk-syscall-stubs`): exit 1, its own `forwarder.json` notice. AI-assisted: yes
m335671 commented 2026-10-18 20:44:15 +00:00 (Migrated from github.com)
Author
Contributor

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 failing 400baa252 run above.

It starts without the abort: there's no already registered throw 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 bundled sce_module/libc.prx, the same module that aborts on 400baa252. One run.

AI-assisted: yes (Claude Code). The build, the run and this comment were done and written by Claude Code on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6254926532 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/7636#issuecomment-6254926532). Originally posted by [m335671](https://github.com/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 failing `400baa252` run above. It starts without the abort: there's no `already registered` throw 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 bundled `sce_module/libc.prx`, the same module that aborts on `400baa252`. One run. AI-assisted: yes (Claude Code). The build, the run and this comment were done and written by Claude Code on my machine.
MarcZX10 commented 2026-10-18 20:45:47 +00:00 (Migrated from github.com)
Author
Contributor

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

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6254941623 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/7636#issuecomment-6254941623). Originally posted by [MarcZX10](https://github.com/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
ps54all commented 2026-10-22 08:48:27 +00:00 (Migrated from github.com)
Author
Contributor

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)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6336682456 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/7636#issuecomment-6336682456). Originally posted by [ps54all](https://github.com/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)
milescoviello commented 2026-10-22 09:14:26 +00:00 (Migrated from github.com)
Author
Contributor

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)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6337164493 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/7636#issuecomment-6337164493). Originally posted by [milescoviello](https://github.com/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)
Sign in to join this conversation.
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#7636
No description provided.