feat(libkernel): implement __tls_get_addr #9059
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9059"
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 mehmetbayoglu on 2026-10-21T11:10:09Z.
What
__tls_get_addr(NIDvNe1w4diLCs) was an unimplemented stub inlibkernel/Unimplemented.cpp. It now takes the FreeBSD/ELFtls_index{module, offset} and returns the calling thread's address of that offset in the module's TLS block. The module word is read the way the relinker writes it forR_X86_64_DTPMOD64:_tls_index, resolved through the thread'sThreadLocalStoragePointer, as in the resolver the relinker emits for guest modules (WindowsGuestStartup.cpp);__tls_get_addr.A null index, module 0 and a Windows thread without a block for the module throw. macOS throws, recorded in
docs/dev/debt/libkernel.md: the relinker binds guest modules there toAps5GuestTlsGetAddr_nid_no_patch, which no library defines yet.Tested
-DBUILD_TESTING=ON.guest_tls_get_addr: atls_indexfor the test executable's own TLS block (its PE_tls_indexon Windows) resolves to the calling thread's block, and on a second thread to that thread's own, freshly initialized block; writes on one thread do not show on the other; a null index throws.ctest -R "tls|thread_local|module").guest_tls_get_addron Arch Linux (GCC 16.2.1, glibc 2.44) at da9728f5ac, 3 of 3 runs pass, plus adlopenTLS module probe (comment on this PR).mainas well:agc_driver_image_array_window_past_layer_limit_tests(alignas(65536)exceeds the object file maximum of 8192).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 mehmetbayoglu on 2026-10-21T13:27:54Z.
no more line conflicts after new comitt
Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-22T05:47:42Z.
Review: APPROVED
Checked against main
4a17c7175and the relinker's TLS handling (WindowsGuestStartup.cppEmitTlsResolver,WindowsGuestModuleWriter.cpp:98,LinuxGuestModuleWriter.cpp:60-67):[[rdi]]as the slot, thegs:[0x58]array,+[rdi+8]). Guest DTPMOD64 is written asImageBase + _tls_indexRVA, and executable DTPMOD64 is rejected at relink time, so no other module-word encoding can reach it.vNe1w4diLCsimports are already renamed to glibc's__tls_get_addr, andsceKernelGetModuleInforeportsdlpi_tls_modid. Forwarding to glibc keeps the same id space.MacOsGuestModuleWriter.cpp:86, which binds toAps5GuestTlsGetAddr_nid_no_patch. The SDK'ssce_stubs/libkernel.cconfirms the libkernel export. I found nothing to change.Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.
Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-22T06:23:47Z.
Independent Windows run of this PR, as data only. The machine is a Ryzen 9 5950X on Windows 11 (10.0.22621), built with WinLibs GCC 15.2.0 UCRT r7, Release,
BUILD_TESTING=ON. I tested a local merge of your head da9728f5ac intomaind6eafa54d0(f37482568e). It merged cleanly; git auto-merged libkernel'sCMakeLists.txt,Unimplemented.cppanddebt/libkernel.md.ctest -R "tls|thread_local|module"passes 69/69 in each of 3 runs,guest_tls_get_addrincluded.guest_raise_in_host_code(30 s timeout), which also times out intermittently onmainon this machine.A note for
import_audit(you also have #9372): with this PR's source as--source,tools/import_audit.pystill classifiesvNe1w4diLCs(__tls_get_addr) as stub. I checked on the registries of Graven (PPSA09614), Goat Simulator 3 (PPSA04158) and Overcooked! All You Can Eat (PPSA01528), withmain's and this PR's trees.The cause is the non-Windows, non-Linux
#elsebranch, which callsNotImplemented_nid_no_patch("__tls_get_addr on this host"). The source scan inprogress.scan_librarydoesn't evaluate preprocessor branches, so any reachable-looking stub call marks the export as to-do. That's arguably right for macOS, but titles audited for Windows or Linux will keep listing__tls_get_addras throwing, even after this merges. I haven't checked how #9372's partial detection treats a#ifbranch.Imported from boykopovar/AnyPS5. Originally posted by mehmetbayoglu on 2026-10-22T06:45:17Z.
Thanks @harisibrar1 for the review and @JJenkx for the 5950X run. On the audit: right, the throw is only in the
#elsebranch for hosts other than Windows and Linux, but neitherprogress.pynor #9372's partial detection evaluates preprocessor branches, so it still reads as a stub. That belongs to the audit, not to this PR: I'll extend #9372 so aNotImplemented_nid_no_patchreached only under#if/#elif/#elsecounts as partial, with a test.