libSceLibcInternal: inventory stub oly3wSwEJ2A is std::system_error(error_code, const char*), and the NID patch step fails whenever libc stops exporting libstdc++'s copy of it #15955

Closed
opened 2026-11-05 02:46:42 +00:00 by StepFPV · 0 comments
StepFPV commented 2026-11-05 02:46:42 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by StepFPV on 2026-11-05T02:46:42Z.


What happens

An ASan+UBSan build of main b611e634f7 with GCC 16.1.1 (-DANYPS5_ENABLE_ASAN=ON, -fsanitize=undefined -fno-sanitize=vptr, -march=x86-64-v3, the Sanitizers workflow's flags) stops in the NID patch step:

[2830/7346] Patching NIDs for libSceLibcInternal
FAIL: .../build/core/libs/libs/libSceLibcInternal.prx: duplicate patched export name: oly3wSwEJ2A

avplayer_http_patched_modules, guest_sigvec_modules and the ten tests that stage libSceLibcInternal.prx are not run. The same tree builds with GCC 16 in Release, and the nightly Sanitizers run (GCC 15) builds it too.

Why

InventoryExports.cpp:100 exports a NotImplemented stub under the NID oly3wSwEJ2A:

APS5_EXPORT("oly3wSwEJ2A", libSceLibcInternalInventory_019_nid_no_patch);

That NID is the hash of the mangled name _ZNSt12system_errorC2ESt10error_codePKc, i.e. std::system_error::system_error(std::error_code, const char*) (base-object constructor); the console's libSceLibcInternal exports the C++ runtime under mangled-name NIDs, and this one is simply not implemented yet.

libstdc++ defines that constructor inline, so every module that throws std::system_error(ec, "text") carries a weak copy of it. libSceLibcInternal does (Spawn.cpp:135), and so does libc. libSceLibcInternal is patched with --preserve-export-list libc.exports, so as long as libc's own export list contains _ZNSt12system_errorC2ESt10error_codePKc, the copy in libSceLibcInternal keeps its name and only the stub provides oly3wSwEJ2A. When libc's build does not export that copy, the patcher hashes libSceLibcInternal's copy to oly3wSwEJ2A, finds the stub's alias at another address and stops (ElfNidPatcher.cpp:518).

Swapping the inputs confirms it: the sanitizer module patched with the Release libc.exports succeeds; the Release module patched with the sanitizer libc.exports fails. Whether libc exports the weak symbol depends on the compiler and flags (GCC 16 Release: yes; GCC 16 ASan+UBSan: no; GCC 15 ASan+UBSan on ubuntu-latest: yes; MinGW: the C1 variant), so any libc change that stops instantiating std::system_error(error_code, const char*) out of line breaks the Release build on every host.

A scan of all 830 APS5_EXPORT inventory NIDs across 15 libraries against the dynamic symbols of every module finds no other collision; libSceLibcInternal exports 2062 symbols, 2039 of them NID-suffixed, 12 intended plain names (sceLibcHeap*, sceLibcPafMspace*, sceLibcInternalSetMallocCallback, sceLibcMspaceSetMallocCallback, SpawnProgram) and 11 leaked libstdc++ instantiations.

Options

  1. Export only the intended symbols from libSceLibcInternal (a generated version script / .def / -exported_symbols_list, as libSceJson2 does), so libstdc++ instantiations never reach the patcher. The 12 plain-name exports have to stay on the list.
  2. Implement std::system_error(std::error_code, const char*) in libc next to the other std::system_error members (libc/src/exception/StandardExceptions.cpp:502-518) and drop the stub; the message needs the guest error_category::message call.
  3. Keep the stub and make the patcher prefer an explicit _nid_no_patch_cut alias over a weak symbol that hashes to the same NID, or skip weak (STB_WEAK) symbols when hashing.

Removing the stub alone (the #2462/#2473 pattern) is not enough here: in Release the leaked copy is preserved under its plain name, so libSceLibcInternal would stop exporting oly3wSwEJ2A at all.

Environment

Arch Linux in WSL2, GCC 16.1.1, Ninja; also checked the Release x86-64-v3 build (passes) and the Windows 11 WinLibs GCC 15.2.0 build (passes, libc.exports lists the C1 variant).

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:6215709618 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/15955). Originally posted by [StepFPV](https://github.com/StepFPV) on 2026-11-05T02:46:42Z. --- ### What happens An ASan+UBSan build of `main` `b611e634f7` with GCC 16.1.1 (`-DANYPS5_ENABLE_ASAN=ON`, `-fsanitize=undefined -fno-sanitize=vptr`, `-march=x86-64-v3`, the Sanitizers workflow's flags) stops in the NID patch step: ``` [2830/7346] Patching NIDs for libSceLibcInternal FAIL: .../build/core/libs/libs/libSceLibcInternal.prx: duplicate patched export name: oly3wSwEJ2A ``` `avplayer_http_patched_modules`, `guest_sigvec_modules` and the ten tests that stage `libSceLibcInternal.prx` are not run. The same tree builds with GCC 16 in Release, and the nightly Sanitizers run (GCC 15) builds it too. ### Why `InventoryExports.cpp:100` exports a `NotImplemented` stub under the NID `oly3wSwEJ2A`: ```cpp APS5_EXPORT("oly3wSwEJ2A", libSceLibcInternalInventory_019_nid_no_patch); ``` That NID is the hash of the mangled name `_ZNSt12system_errorC2ESt10error_codePKc`, i.e. `std::system_error::system_error(std::error_code, const char*)` (base-object constructor); the console's `libSceLibcInternal` exports the C++ runtime under mangled-name NIDs, and this one is simply not implemented yet. libstdc++ defines that constructor inline, so every module that throws `std::system_error(ec, "text")` carries a weak copy of it. `libSceLibcInternal` does (`Spawn.cpp:135`), and so does `libc`. `libSceLibcInternal` is patched with `--preserve-export-list libc.exports`, so as long as libc's own export list contains `_ZNSt12system_errorC2ESt10error_codePKc`, the copy in `libSceLibcInternal` keeps its name and only the stub provides `oly3wSwEJ2A`. When libc's build does not export that copy, the patcher hashes `libSceLibcInternal`'s copy to `oly3wSwEJ2A`, finds the stub's alias at another address and stops (`ElfNidPatcher.cpp:518`). Swapping the inputs confirms it: the sanitizer module patched with the Release `libc.exports` succeeds; the Release module patched with the sanitizer `libc.exports` fails. Whether libc exports the weak symbol depends on the compiler and flags (GCC 16 Release: yes; GCC 16 ASan+UBSan: no; GCC 15 ASan+UBSan on ubuntu-latest: yes; MinGW: the `C1` variant), so any libc change that stops instantiating `std::system_error(error_code, const char*)` out of line breaks the Release build on every host. A scan of all 830 `APS5_EXPORT` inventory NIDs across 15 libraries against the dynamic symbols of every module finds no other collision; `libSceLibcInternal` exports 2062 symbols, 2039 of them NID-suffixed, 12 intended plain names (`sceLibcHeap*`, `sceLibcPafMspace*`, `sceLibcInternalSetMallocCallback`, `sceLibcMspaceSetMallocCallback`, `SpawnProgram`) and 11 leaked libstdc++ instantiations. ### Options 1. Export only the intended symbols from `libSceLibcInternal` (a generated version script / `.def` / `-exported_symbols_list`, as `libSceJson2` does), so libstdc++ instantiations never reach the patcher. The 12 plain-name exports have to stay on the list. 2. Implement `std::system_error(std::error_code, const char*)` in libc next to the other `std::system_error` members (`libc/src/exception/StandardExceptions.cpp:502-518`) and drop the stub; the message needs the guest `error_category::message` call. 3. Keep the stub and make the patcher prefer an explicit `_nid_no_patch_cut` alias over a weak symbol that hashes to the same NID, or skip weak (`STB_WEAK`) symbols when hashing. Removing the stub alone (the #2462/#2473 pattern) is not enough here: in Release the leaked copy is preserved under its plain name, so `libSceLibcInternal` would stop exporting `oly3wSwEJ2A` at all. ### Environment Arch Linux in WSL2, GCC 16.1.1, Ninja; also checked the Release x86-64-v3 build (passes) and the Windows 11 WinLibs GCC 15.2.0 build (passes, `libc.exports` lists the `C1` variant). AI-assisted: yes
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#15955
No description provided.