feat(libc): export the CRT data markers #17062
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/17062"
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 Opensource55 on 2026-11-08T08:52:45Z.
What
libc.prxexports data as well as functions: for a data slot the export is the object's address, and the NID comes from its name.__isthreaded(q1OvUam0BJU) has been exported that way inStandardStreams.cppfor a while; three more slots the console exports were missing here:P330P3dFF68Need_sceLibckQelMBYgkK0_thread_autoinit_dummy_decldmUgzUX3nXU_thread_autoinit_dummy_decl_stubNeed_sceLibcalready existed inExport.cppas a plainuint32_tthat nothing exported, so it needed only the suffix; the two_thread_autoinit_dummy_declobjects did not exist at all.The
libc.prxof PPSA01341 v01.007.000 exports them at0x15d780and0x1a60a8. The two dummy declarations share one address in that module, so here the stub is an assembler alias of the declaration — the same.setthatAPS5_EXPORTuses for function NIDs — and a caller comparing their addresses sees one address too. Emscripten and MSVC keep a second object, which the debt entry records.The same entry records the twelve data slots this change deliberately does not export, and why:
_Fileshas no measured length, and a table shorter than the console's would let a guest that indexes it read past the end, which is worse than an import that fails to resolve;fcloseallcloses that table's streams and needs the registryfopen/fdopendo not keep;_Ctype,_Locale,_Tolotaband_Touptabare console-private TLS tables; the four_Tls_setup__*flags record setup internal to that module; the two_PJP_*_Copyrighttexts have unknown bytes; and__cleanupshares its eight-byte slot with__isthreadedthere, so the console holds one slot that is both a thread flag and a cleanup pointer.Tested
Windows 10 19045.6456, MinGW GCC 15.2.0, Ninja, Release.
ctest -R standard_stream: 6/6 pass, including the three new assertions (Need_sceLibc_nid_postfix == 1, both dummies== 0).objdump -p libc.prxlistsNeed_sceLibc_nid_postfix,_thread_autoinit_dummy_decl_nid_postfixand_thread_autoinit_dummy_decl_stub_nid_postfix, and recomputing their NIDs gives the three console values above.ctest -j6: 4638 tests, 25 failures; rerunning them serially leaves 10, all of kinds this machine produces with or without this change: creating symbolic links withoutSeCreateSymbolicLinkPrivilegefails withWinError 1314, andguest_directory,guest_filesystem,guest_kernel_sysandguest_kqueueabort with0xc0000409on stacks that carrytsbx.dll, the hook the agent sandbox uses to redirect deletions — the tests that abort are exactly the filesystem ones.agc_shader_cache_housekeeping_plainfails under parallel load and passes when run alone.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by gabichuuuuu on 2026-11-08T16:03:14Z.
Review: COMMENTED
Windows run of head
b58f62ed1e, merged ontomain828e44310e(clean merge). Setup: Windows 11, WinLibs GCC 15.2 (x86_64-ucrt-posix-seh), Release,BUILD_TESTING=ON.guest_standard_streams*with--repeat until-fail:20: 100 / 100 pass (5 tests).objdump -pon the patchedbuild/core/libs/libs/libc.prxlists each ofP330P3dFF68(Need_sceLibc),kQelMBYgkK0anddmUgzUX3nXUonce, next to the existingq1OvUam0BJU(__isthreaded). So the_nid_postfixdata objects become NID data exports on Windows too, not only in-process symbols the test links against.The aliasing the debt entry records, two separate objects where the console has one address, could be matched in-tree. You could define one object and give the second NID an
APS5_EXPORTalias to it, as other modules alias function NIDs. Then a caller comparing the two addresses would see what it sees on the console. I haven't checked whetherAPS5_EXPORTaccepts data symbols.