fix(build): keep libc.prx needed by every executable that links a prx #3684

Merged
zmeizy merged 1 commit from upstream-pr/3684 into main 2026-10-11 21:50:33 +00:00
zmeizy commented 2026-10-11 15:19:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by zmeizy on 2026-10-11T15:19:50Z.


What

guest_kernel_stack_protect aborts on Linux (Ubuntu 24.04, GCC 13.3, the CI configuration) at its last check: an mprotect that spans the page below a thread stack must return -1. The abort comes from _Unwind_Resume in libc.prx. Cause:

  1. Ubuntu's GCC links with --as-needed. GuestKernelStackProtect.cpp calls nothing in libc.prx directly, so the linker drops libc.prx from the test's DT_NEEDED. It then satisfies libkernel.prx's references to __cxa_allocate_exception, __cxa_begin_catch, __cxa_init_primary_exception and __gxx_personality_v0 from the static libstdc++ (-static-libstdc++). The link map shows eh_throw.o, eh_alloc.o, eh_catch.o and eh_personality.o included "to satisfy reference by libkernel.prx".
  2. The executable exports those copies, so they interpose libc.prx's for every library. throw inside libc.prx and libkernel.prx then uses libstdc++'s __cxa_throw and libgcc's search phase.
  3. The landing pads inside the prx libraries still call _Unwind_Resume, which is libc.prx's guest unwinder, because the executable's static libgcc keeps its own hidden. The guest unwinder continues an exception that libgcc searched. libgcc identifies the handler frame by its stack pointer (uw_identify_context), the guest unwinder by its CFA, and the guest personality cannot match the types of a libstdc++ exception, so the cleanup phase fails and _Unwind_Resume aborts.

On current main, 55 test executables that link a prx are missing libc.prx from DT_NEEDED. 38 of them carry their own copy of the C++ exception runtime, so they test the libraries with a different runtime than titles get. guest_kernel_stack_protect is the one whose test currently fails because of it.

The fix is two lines in core/libs/CMakeLists.txt:

  • libc adds --no-as-needed to its consumers' link options on Linux. guest_module_fixture already links with --no-as-needed.
  • Every prx links libc PUBLIC instead of PRIVATE, so a test that links only, say, libSceHttp also gets libc.prx on its link line.

Only targets in core/libs link prx libraries.

Tested

Ubuntu 24.04, GCC 13.3, lavapipe, on main a11c8f7f.

  • guest_kernel_stack_protect aborts on main and passes with the change. Relinking it by hand with -Wl,--no-as-needed on unchanged main also makes it pass.
  • After the change, all 618 test executables that link a prx have libc.prx in DT_NEEDED, and none defines __cxa_throw or __gxx_personality_v0 itself. Before: 55 without libc.prx, 38 with their own runtime.
  • Full ctest --timeout 120 --parallel 4: 832 tests. All pass except three that also fail on main here: guest_truncate (the container runs as root, which ignores the read-only bit) and two lavapipe image-sampling tests. No test over 30 s.
  • Not tested on Windows or macOS. The link option is Linux-only. PUBLIC linking only adds libc's import library to the link lines of prx consumers there.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt (n/a)
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source (n/a)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes

🤖 Generated with Claude Code

https://claude.ai/code/session_01Ha6Tsy62AFUyp9a5Mf7vjA

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4820102140 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3684). Originally posted by [zmeizy](https://github.com/zmeizy) on 2026-10-11T15:19:50Z. --- ### What `guest_kernel_stack_protect` aborts on Linux (Ubuntu 24.04, GCC 13.3, the CI configuration) at its last check: an `mprotect` that spans the page below a thread stack must return -1. The abort comes from `_Unwind_Resume` in libc.prx. Cause: 1. Ubuntu's GCC links with `--as-needed`. `GuestKernelStackProtect.cpp` calls nothing in libc.prx directly, so the linker drops libc.prx from the test's `DT_NEEDED`. It then satisfies libkernel.prx's references to `__cxa_allocate_exception`, `__cxa_begin_catch`, `__cxa_init_primary_exception` and `__gxx_personality_v0` from the static libstdc++ (`-static-libstdc++`). The link map shows `eh_throw.o`, `eh_alloc.o`, `eh_catch.o` and `eh_personality.o` included "to satisfy reference by libkernel.prx". 2. The executable exports those copies, so they interpose libc.prx's for every library. `throw` inside libc.prx and libkernel.prx then uses libstdc++'s `__cxa_throw` and libgcc's search phase. 3. The landing pads inside the prx libraries still call `_Unwind_Resume`, which is libc.prx's guest unwinder, because the executable's static libgcc keeps its own hidden. The guest unwinder continues an exception that libgcc searched. libgcc identifies the handler frame by its stack pointer (`uw_identify_context`), the guest unwinder by its CFA, and the guest personality cannot match the types of a libstdc++ exception, so the cleanup phase fails and `_Unwind_Resume` aborts. On current `main`, 55 test executables that link a prx are missing libc.prx from `DT_NEEDED`. 38 of them carry their own copy of the C++ exception runtime, so they test the libraries with a different runtime than titles get. `guest_kernel_stack_protect` is the one whose test currently fails because of it. The fix is two lines in `core/libs/CMakeLists.txt`: - `libc` adds `--no-as-needed` to its consumers' link options on Linux. `guest_module_fixture` already links with `--no-as-needed`. - Every prx links `libc` `PUBLIC` instead of `PRIVATE`, so a test that links only, say, libSceHttp also gets libc.prx on its link line. Only targets in `core/libs` link prx libraries. ### Tested Ubuntu 24.04, GCC 13.3, lavapipe, on `main` `a11c8f7f`. - `guest_kernel_stack_protect` aborts on `main` and passes with the change. Relinking it by hand with `-Wl,--no-as-needed` on unchanged `main` also makes it pass. - After the change, all 618 test executables that link a prx have libc.prx in `DT_NEEDED`, and none defines `__cxa_throw` or `__gxx_personality_v0` itself. Before: 55 without libc.prx, 38 with their own runtime. - Full `ctest --timeout 120 --parallel 4`: 832 tests. All pass except three that also fail on `main` here: `guest_truncate` (the container runs as root, which ignores the read-only bit) and two lavapipe image-sampling tests. No test over 30 s. - Not tested on Windows or macOS. The link option is Linux-only. `PUBLIC` linking only adds libc's import library to the link lines of prx consumers there. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) (n/a) - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source (n/a) - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01Ha6Tsy62AFUyp9a5Mf7vjA
adriadam10 commented 2026-10-11 21:50:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T21:50:29Z.


Checked core/libs build + ctest (19/19) on the PR merged onto main; every relinked test now lists libc.prx in DT_NEEDED, including guest_kernel_stack_protect_tests. The --as-needed failure itself is Ubuntu/GCC 13 specific and doesn't reproduce on our toolchain; relying on the described link-map evidence. Merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6114187705 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3684#issuecomment-6114187705). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T21:50:29Z. --- Checked `core/libs` build + ctest (19/19) on the PR merged onto main; every relinked test now lists libc.prx in `DT_NEEDED`, including `guest_kernel_stack_protect_tests`. The `--as-needed` failure itself is Ubuntu/GCC 13 specific and doesn't reproduce on our toolchain; relying on the described link-map evidence. Merging.
Sign in to join this conversation.
No reviewers
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!3684
No description provided.