Linux: since #1156, a bundled sce_module/libc.prx is never initialised, but titles still call its malloc, which returns NULL #1500

Closed
opened 2026-10-08 10:02:49 +00:00 by awake-devel · 0 comments
awake-devel commented 2026-10-08 10:02:49 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by awake-devel on 2026-10-08T10:02:49Z.


Symptom

Hollow Knight: Silksong (PPSA12544), Linux, main 296d68a3 + #846 (--module-dir Media/Plugins). The process dies with SIGSEGV while the dynamic loader runs module initialisers, before AnyPS5 prints anything:

Program received signal SIGSEGV, Segmentation fault.
rax 0x0   r14 0x300

The faulting code is in Media/Modules/Il2cppUserAssemblies.prx.guest.prx (file offset 0x292608):

call  0x2bc460          ; PLT slot 0x34
mov   %rax,0x68(%rbx)
...
movl  $0x1,(%rax)       ; rax = 0, crash

PLT slot 0x34 is a R_X86_64_JUMP_SLOT for gQX+4GDQjpM#guest (malloc). The only module that defines it is the title's bundled app0/sce_module/libc.prx.guest.prx (symbol 357, address 0x5eb0). That malloc calls through a function pointer whose default target allocates from a global mspace in the bundled libc's .bss. That mspace is only set up by the bundled libc's own initialiser.

Cause

#1156 (9517cc33) stops writing DT_INIT/DT_INIT_ARRAY/DT_FINI/DT_FINI_ARRAY for a guest module that has an AnyPS5 replacement (libc.prx). But the bundled module is still the export provider for the title's own imports: guest modules are listed ahead of host prx, and the imports are #guest symbols. So the title calls a libc whose initialiser never ran. readelf -d on the relinked bundled libc: no INIT entry with #1156, and INIT 0x210c90 / FINI 0x210c9b without it.

Evidence

  • With only the Linux part of 9517cc33 undone (two lines in LinuxGuestModuleWriter.cpp, relinker rebuilt, all else unchanged), the same build gets past module loading, opens /app0/Media/boot.config and stops later at an unrelated, known missing feature (sceKernelLoadStartModule with start arguments not implemented, handled by #1102). That is also where builds from before #1156 stopped.
  • #1156 was tested with synthetic fixtures on macOS only ("No proprietary title was tested"). The fixture checks that dependent modules can still call the bundled exports, but its exports do not rely on state set up by the initialiser, so the test cannot catch this.
  • Silksong reached gameplay on Windows (discussion #726, 2026-10-06), before #1156 was merged (2026-10-08). The Windows writer has the same suppression, so Windows is probably affected as well. Not tested: there is no Windows machine here.

Possible directions (for the maintainers to choose)

  1. Revert the lifecycle suppression. This brings back #693 (two heap handshakes for titles with a malloc replacement).
  2. Keep the bundled libc's lifecycle, because the title's code binds to it. When a bundled libc is present, skip the host libc's application-heap handshake instead, so the title's allocator is still initialised once.
  3. Suppress the lifecycle only for a bundled module that no other guest module imports from. In practice a title bundles libc precisely so that it can import from it, so this is close to option 1.

Our local workaround is option 1 (Linux only).

Related: #1497 is the other side of the same binding question on Linux. There, a bundled libc.prx shim captures a title's libc imports with placeholder exports, and the fix direction is to bind to AnyPS5's libc instead, as #684 did on Windows. Here the bundled module is Sony's real libc, which the title's code expects to be initialised. A fix for one should keep the other working.

This was investigated and written by Claude Code (AI), and posted by me after review.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5759776085 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/1500). Originally posted by [awake-devel](https://github.com/awake-devel) on 2026-10-08T10:02:49Z. --- ### Symptom Hollow Knight: Silksong (PPSA12544), Linux, `main` 296d68a3 + #846 (`--module-dir Media/Plugins`). The process dies with SIGSEGV while the dynamic loader runs module initialisers, before AnyPS5 prints anything: ``` Program received signal SIGSEGV, Segmentation fault. rax 0x0 r14 0x300 ``` The faulting code is in `Media/Modules/Il2cppUserAssemblies.prx.guest.prx` (file offset 0x292608): ``` call 0x2bc460 ; PLT slot 0x34 mov %rax,0x68(%rbx) ... movl $0x1,(%rax) ; rax = 0, crash ``` PLT slot 0x34 is a `R_X86_64_JUMP_SLOT` for `gQX+4GDQjpM#guest` (`malloc`). The only module that defines it is the title's bundled `app0/sce_module/libc.prx.guest.prx` (symbol 357, address 0x5eb0). That `malloc` calls through a function pointer whose default target allocates from a global mspace in the bundled libc's `.bss`. That mspace is only set up by the bundled libc's own initialiser. ### Cause #1156 (9517cc33) stops writing `DT_INIT`/`DT_INIT_ARRAY`/`DT_FINI`/`DT_FINI_ARRAY` for a guest module that has an AnyPS5 replacement (`libc.prx`). But the bundled module is still the export provider for the title's own imports: guest modules are listed ahead of host prx, and the imports are `#guest` symbols. So the title calls a libc whose initialiser never ran. `readelf -d` on the relinked bundled libc: no INIT entry with #1156, and `INIT 0x210c90` / `FINI 0x210c9b` without it. ### Evidence - With only the Linux part of 9517cc33 undone (two lines in `LinuxGuestModuleWriter.cpp`, relinker rebuilt, all else unchanged), the same build gets past module loading, opens `/app0/Media/boot.config` and stops later at an unrelated, known missing feature (`sceKernelLoadStartModule with start arguments not implemented`, handled by #1102). That is also where builds from before #1156 stopped. - #1156 was tested with synthetic fixtures on macOS only ("No proprietary title was tested"). The fixture checks that dependent modules can still *call* the bundled exports, but its exports do not rely on state set up by the initialiser, so the test cannot catch this. - Silksong reached gameplay on Windows (discussion #726, 2026-10-06), before #1156 was merged (2026-10-08). The Windows writer has the same suppression, so Windows is probably affected as well. Not tested: there is no Windows machine here. ### Possible directions (for the maintainers to choose) 1. Revert the lifecycle suppression. This brings back #693 (two heap handshakes for titles with a malloc replacement). 2. Keep the bundled libc's lifecycle, because the title's code binds to it. When a bundled libc is present, skip the *host* libc's application-heap handshake instead, so the title's allocator is still initialised once. 3. Suppress the lifecycle only for a bundled module that no other guest module imports from. In practice a title bundles libc precisely so that it can import from it, so this is close to option 1. Our local workaround is option 1 (Linux only). Related: #1497 is the other side of the same binding question on Linux. There, a bundled `libc.prx` *shim* captures a title's libc imports with placeholder exports, and the fix direction is to bind to AnyPS5's libc instead, as #684 did on Windows. Here the bundled module is Sony's real libc, which the title's code expects to be initialised. A fix for one should keep the other working. This was investigated and written by Claude Code (AI), and posted by me after review.
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#1500
No description provided.