Skip to content

feat(libSceDbgThreadSanitizer): declare the TSan annotation calls and report the sanitizer disabled - #4960

Merged
adriadam10 merged 1 commit into
boykopovar:mainfrom
fdfawef324:feat/libSceDbgThreadSanitizer
Oct 13, 2026
Merged

adriadam10 merged 1 commit into
boykopovar:mainfrom
fdfawef324:feat/libSceDbgThreadSanitizer

Conversation

@fdfawef324

Copy link
Copy Markdown
Contributor

What

Black Myth: Wukong (PPSA23226) exits at start-up with 0xC0000135 (STATUS_DLL_NOT_FOUND):

Failed to load module: ...\run-integ\libs\libSceDbgThreadSanitizer.prx
GetLastError: 126 - The specified module could not be found.

Why the library is loaded at start-up. The executable does not reference it: eboot.bin's DT_NEEDED has no libSceDbgThreadSanitizer and no libSceJobManager, and app.registry.json has no import from either. The title's own sce_module/libSceJobManager_nosubmission.prx lists libSceDbgThreadSanitizer.prx in its DT_NEEDED (the plain libSceJobManager.prx does not), and its registry imports __tsan_acquire (XyX1104ACcU), __tsan_release (IkoI44e0OXc) and sceKernelIsThreadSanitizerEnabled (LzoM-wVLJDE, libkernel). In GuestModuleBuilder.cpp every ELF in sce_module is converted and loaded at start-up (deferred applies only to --module-dir directories), and each module's own DT_NEEDED (image.Dependencies) goes into hostLibraries, which becomes the executable's DT_NEEDED. The Windows start-up stub (WindowsEntryStubBuilder.cpp) then loads it. A missing library is skipped only when nothing imports from it (#3129), and this one has imports, so the load fails.

Change.

  • New system library core/libs/prx/libSceDbgThreadSanitizer. It is an Export.cpp-only directory, which the prx/* glob in core/libs/CMakeLists.txt registers and nid_patcher patches, as for libSceXml. It declares __tsan_acquire and __tsan_release with the void(void* addr) signatures from LLVM compiler-rt tsan_interface.h at llvm-project 87f0227 (LLVM 20.1.8), lines 24-25. The names hash to the imported NIDs. Both throw through NotImplemented_nid_no_patch, because AnyPS5 runs no race detector.
  • sceKernelIsThreadSanitizerEnabled in libkernel (Sanitizer.cpp) returns 0. A converted title never runs under the sanitizer. It sits next to sceKernelIsAddressSanitizerEnabled, which also returns 0.
  • No public source gives the signature of sceKernelIsThreadSanitizerEnabled. int(void) is assumed from the address-sanitizer counterpart and from how the module uses it, and is recorded under Unknown function info in docs/dev/debt/libkernel.md. The constant result is also listed there under Silent stubs, because the conventions check requires that for an sce* export whose body only returns a constant (as for sceKernelGetMainSocId). The TSan signature assumption is in the new docs/dev/debt/libSceDbgThreadSanitizer.md.

Behaviour of the module (from reading it locally; no code is reproduced here). One initialisation routine calls sceKernelIsThreadSanitizerEnabled without setting up arguments. If the 32-bit result is nonzero, it sets a module-wide flag. That routine is the only writer of the flag. All 60 call sites of __tsan_acquire/__tsan_release check the flag first and skip the call when it is clear. With the kernel reporting 0, the throwing stubs are never reached.

Tested

Windows Server 2025, MinGW-w64 GCC 15.2.0, build-dev (Release).

  • New guest_thread_sanitizer test: the guest calls sceKernelIsThreadSanitizerEnabled and requires 0. It passes with the change. With Sanitizer.cpp reverted and libkernel rebuilt, it fails with 0xC0000139 (entry point not found); a clean build fails to link. No export-only test was added for libSceDbgThreadSanitizer (CONTRIBUTING).
  • patched_libraries and guest_software_version pass. Exports were checked on the patched libSceDbgThreadSanitizer.prx (IkoI44e0OXc, XyX1104ACcU) and on libkernel.prx (LzoM-wVLJDE).
  • tools/import_audit.py on the 41 PPSA23226 registries, with the title's sce_module and prx as modules:
    • against the libraries of the failing run: absent 3 imports (the two TSan NIDs and LzoM-wVLJDE)
    • against this branch's libs: absent 0 imports, implemented 1088, stub 49 (the two new throwing stubs count as stubs)
  • The title was not run.

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 under Silent stubs in their library's technical debt file
  • 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
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: PPSA23226, its start-up stop on the missing libSceDbgThreadSanitizer.prx (title not rerun with this change; no Game bring-up discussion found)
  • AI-assisted: yes

🤖 Generated with Claude Code

… report the sanitizer disabled

Black Myth: Wukong (PPSA23226) exits at start-up with
STATUS_DLL_NOT_FOUND after "Failed to load module:
libs\libSceDbgThreadSanitizer.prx". The executable does not need the
library: its bundled sce_module/libSceJobManager_nosubmission.prx lists
it in DT_NEEDED and imports __tsan_acquire and __tsan_release from it,
plus sceKernelIsThreadSanitizerEnabled from libkernel. The relinker
converts every module in sce_module and loads it at start-up (only
--module-dir directories are deferred), and GuestModuleBuilder adds each
module's host dependencies to the executable's DT_NEEDED, which the
Windows start-up stub loads.

libSceDbgThreadSanitizer now exports __tsan_acquire and __tsan_release
with the void(void* addr) signatures of LLVM compiler-rt's
tsan_interface.h (llvm-project 87f0227cb601, LLVM 20.1.8). Both throw:
AnyPS5 runs no race detector, and the module calls them only after
sceKernelIsThreadSanitizerEnabled reports the sanitizer enabled.
libkernel's sceKernelIsThreadSanitizerEnabled returns 0, as
sceKernelIsAddressSanitizerEnabled does; its int(void) signature is
assumed and recorded in the libkernel debt file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

Progress report (ea2bbef → 0f77f3e)

📉 System libraries: 87.93% (-0.05%, +1 implemented, +2 declared functions)

✅ 1 implemented
Library Name
libkernel sceKernelIsThreadSanitizerEnabled
⚪ 1 behaviourally empty (constant return or throw)
Library Name
libkernel sceKernelIsThreadSanitizerEnabled
🆕 2 declared as stubs
Library Name
libSceDbgThreadSanitizer __tsan_acquire
libSceDbgThreadSanitizer __tsan_release

@github-actions

github-actions Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#3870 docs/dev/debt/libkernel.md L89

@adriadam10

Copy link
Copy Markdown
Collaborator

Checked build and ctest (145 tests, guest_thread_sanitizer included) on Linux; the new test fails to build without the change; the technical debt entries sit under the right sections and the branch merges cleanly with main. Merging.

@adriadam10
adriadam10 merged commit cac4e96 into boykopovar:main Oct 13, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants