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

Merged
fdfawef324 merged 1 commit from upstream-pr/4960 into main 2026-10-13 08:34:05 +00:00
fdfawef324 commented 2026-10-13 06:37:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by fdfawef324 on 2026-10-13T06:37:40Z.


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

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4839388438 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4960). Originally posted by [fdfawef324](https://github.com/fdfawef324) on 2026-10-13T06:37:40Z. --- ### 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](core/relinker/relinker/src/guest/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](core/relinker/elfpatcher/src/windows/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](https://github.com/llvm/llvm-project/blob/87f0227cb60147a26a1eeb4fb06e3b505e9c7261/compiler-rt/include/sanitizer/tsan_interface.h#L24-L25). 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](core/libs/prx/libkernel/System/src/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 <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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 under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [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 - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Unblocks: PPSA23226, its start-up stop on the missing libSceDbgThreadSanitizer.prx (title not rerun with this change; no Game bring-up discussion found) - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-actions[bot] commented 2026-10-13 06:38:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T06:38:03Z.


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
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6139831658 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4960#issuecomment-6139831658). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-13T06:38:03Z. --- <!-- progress-report --> ### Progress report (ea2bbef → 0f77f3e) 📉 **System libraries**: 87.93% (-0.05%, +1 implemented, +2 declared functions) <details> <summary>✅ 1 implemented</summary> | Library | Name | | - | - | | libkernel | `sceKernelIsThreadSanitizerEnabled` | </details> <details> <summary>⚪ 1 behaviourally empty (constant return or throw)</summary> | Library | Name | | - | - | | libkernel | `sceKernelIsThreadSanitizerEnabled` | </details> <details> <summary>🆕 2 declared as stubs</summary> | Library | Name | | - | - | | libSceDbgThreadSanitizer | `__tsan_acquire` | | libSceDbgThreadSanitizer | `__tsan_release` | </details>
github-actions[bot] commented 2026-10-13 06:50:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T06:50:46Z.


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
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6140005868 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4960#issuecomment-6140005868). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-13T06:50:46Z. --- <!-- pr-overlap --> 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](https://github.com/boykopovar/AnyPS5/blob/5f426f9478074fda565969c786041e2c2c329703/docs/dev/debt/libkernel.md#L89) | | |
adriadam10 commented 2026-10-13 08:34:01 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-13T08:34:01Z.


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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6141602040 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4960#issuecomment-6141602040). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-13T08:34:01Z. --- 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.
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!4960
No description provided.