build: add an ANYPS5_ENABLE_TSAN option for ThreadSanitizer builds #11179

Merged
MarcZX10 merged 10 commits from upstream-pr/11179 into main 2026-10-26 21:39:04 +00:00
MarcZX10 commented 2026-10-25 20:41:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T20:41:47Z.


What

The tree can be built with AddressSanitizer (-DANYPS5_ENABLE_ASAN=ON), but not with ThreadSanitizer, although the runtime is heavily threaded: guest pthreads, AGC queue workers, audio and equeue waiters. This adds -DANYPS5_ENABLE_TSAN=ON for Linux GCC and Clang builds.

  • Option: ANYPS5_ENABLE_TSAN compiles and links with -fsanitize=thread -fno-omit-frame-pointer and defines ANYPS5_ENABLE_TSAN=1. It is rejected with a configure error on other systems or compilers, and when combined with ANYPS5_ENABLE_ASAN. Like the ASan build, it keeps executables dynamically linked, because the sanitizer runtime cannot be linked statically.
  • Tests: guest_mlock and guest_memory skip their host mlock result checks under ThreadSanitizer, as they already do under ASan. The sanitizer's own mappings change what /proc/self/status reports and what a locked range can hold.
  • Suppressions: tools/tsan-suppressions.txt silences reports from Mesa's lavapipe, the LLVM it compiles shaders with, and PulseAudio. Those system libraries are not instrumented, so ThreadSanitizer cannot see their locking. Without the file, 94 AGC tests fail inside libvulkan_lvp.so. With lavapipe alone suppressed, 705 fail on lock-order reports inside libLLVM.
  • Docs: BUILD.md lists the flag and gets a short ThreadSanitizer section. It explains the suppressions, and that guest memory written by the emulated GPU while a guest thread polls it (labels, fences) is shared without C++ atomics on purpose, so those accesses are reported too.

Results. A full RelWithDebInfo build of this branch on an ubuntu-latest fork runner (GCC 15.2), with TSAN_OPTIONS=halt_on_error=1:second_deadlock_stack=1:suppressions=tools/tsan-suppressions.txt and ctest --timeout 600 --parallel 4: 2,274 tests, 2,112 passed, 88 skipped and 74 failed. The failures, by cause:

Cause Tests Status
Lock-order inversion between the app0.zar mutex and the directory mutex in libc 17 #10100 removes it (checked with this option: 3 affected tests fail before and pass after)
close racing an equeue file measurement 1 (guest_socket_events) #11125
scePthreadAttrGet reading _detached 1 (guest_pthread_stack) #10810 makes it atomic
Guest-memory polling by the emulated GPU (Pm4.cpp:581, GuestMemory.cpp label writes, and the tests that drive them) about 20 by design
Synchronization ThreadSanitizer cannot see: concurrent syscalls on one socket (recv), glibc flockfile around putc_unlocked, FFmpeg frame threading 5 false positives
No ThreadSanitizer report: call-trace abort tests timing out at 20 s, fibers and setcontext, RLIMIT_DATA, SEGVs in agc_driver_graphics* about 25 not threading
Others (Dispatch.cpp static profiling counters, libSceJobManager WorkerEntry, a few test-side plain flags) about 5 not triaged in this pull request

The option builds nothing differently unless it is turned on, and no workflow runs it yet.

Tested

  • The fork run above, plus two earlier runs that produced the suppression list (first without suppressions: 164 failures, 94 of them in lavapipe; then without the LLVM entries: 785 failures, 705 in libLLVM).
  • Configure-time checks: -DANYPS5_ENABLE_TSAN=ON -DANYPS5_ENABLE_ASAN=ON stops with ANYPS5_ENABLE_ASAN and ANYPS5_ENABLE_TSAN cannot be combined, and -DANYPS5_RELINKER_ONLY=ON -DANYPS5_ENABLE_TSAN=ON configures.
  • python3 tools/check_conventions.py --base upstream/main and git diff --check upstream/main pass. tools/pr_overlap.py --branch lists only pull requests that share CMakeLists.txt, docs/dev/BUILD.md or core/libs/tests/GuestMemory.cpp, with no conflicting lines. Windows and macOS are rejected by design and were 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 (not applicable; no third-party code added)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5008505998 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11179). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-25T20:41:47Z. --- ### What The tree can be built with AddressSanitizer (`-DANYPS5_ENABLE_ASAN=ON`), but not with ThreadSanitizer, although the runtime is heavily threaded: guest pthreads, AGC queue workers, audio and equeue waiters. This adds `-DANYPS5_ENABLE_TSAN=ON` for Linux GCC and Clang builds. - **Option:** `ANYPS5_ENABLE_TSAN` compiles and links with `-fsanitize=thread -fno-omit-frame-pointer` and defines `ANYPS5_ENABLE_TSAN=1`. It is rejected with a configure error on other systems or compilers, and when combined with `ANYPS5_ENABLE_ASAN`. Like the ASan build, it keeps executables dynamically linked, because the sanitizer runtime cannot be linked statically. - **Tests:** `guest_mlock` and `guest_memory` skip their host `mlock` result checks under ThreadSanitizer, as they already do under ASan. The sanitizer's own mappings change what `/proc/self/status` reports and what a locked range can hold. - **Suppressions:** `tools/tsan-suppressions.txt` silences reports from Mesa's lavapipe, the LLVM it compiles shaders with, and PulseAudio. Those system libraries are not instrumented, so ThreadSanitizer cannot see their locking. Without the file, 94 AGC tests fail inside `libvulkan_lvp.so`. With lavapipe alone suppressed, 705 fail on lock-order reports inside `libLLVM`. - **Docs:** BUILD.md lists the flag and gets a short ThreadSanitizer section. It explains the suppressions, and that guest memory written by the emulated GPU while a guest thread polls it (labels, fences) is shared without C++ atomics on purpose, so those accesses are reported too. **Results.** A full RelWithDebInfo build of this branch on an `ubuntu-latest` fork runner (GCC 15.2), with `TSAN_OPTIONS=halt_on_error=1:second_deadlock_stack=1:suppressions=tools/tsan-suppressions.txt` and `ctest --timeout 600 --parallel 4`: 2,274 tests, 2,112 passed, 88 skipped and 74 failed. The failures, by cause: | Cause | Tests | Status | |---|---|---| | Lock-order inversion between the `app0.zar` mutex and the directory mutex in libc | 17 | #10100 removes it (checked with this option: 3 affected tests fail before and pass after) | | `close` racing an equeue file measurement | 1 (`guest_socket_events`) | #11125 | | `scePthreadAttrGet` reading `_detached` | 1 (`guest_pthread_stack`) | #10810 makes it atomic | | Guest-memory polling by the emulated GPU (`Pm4.cpp:581`, `GuestMemory.cpp` label writes, and the tests that drive them) | about 20 | by design | | Synchronization ThreadSanitizer cannot see: concurrent syscalls on one socket (`recv`), glibc `flockfile` around `putc_unlocked`, FFmpeg frame threading | 5 | false positives | | No ThreadSanitizer report: call-trace abort tests timing out at 20 s, fibers and `setcontext`, `RLIMIT_DATA`, SEGVs in `agc_driver_graphics*` | about 25 | not threading | | Others (`Dispatch.cpp` static profiling counters, `libSceJobManager` `WorkerEntry`, a few test-side plain flags) | about 5 | not triaged in this pull request | The option builds nothing differently unless it is turned on, and no workflow runs it yet. ### Tested - The fork run above, plus two earlier runs that produced the suppression list (first without suppressions: 164 failures, 94 of them in lavapipe; then without the LLVM entries: 785 failures, 705 in `libLLVM`). - Configure-time checks: `-DANYPS5_ENABLE_TSAN=ON -DANYPS5_ENABLE_ASAN=ON` stops with `ANYPS5_ENABLE_ASAN and ANYPS5_ENABLE_TSAN cannot be combined`, and `-DANYPS5_RELINKER_ONLY=ON -DANYPS5_ENABLE_TSAN=ON` configures. - `python3 tools/check_conventions.py --base upstream/main` and `git diff --check upstream/main` pass. `tools/pr_overlap.py --branch` lists only pull requests that share `CMakeLists.txt`, `docs/dev/BUILD.md` or `core/libs/tests/GuestMemory.cpp`, with no conflicting lines. Windows and macOS are rejected by design and were 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 (not applicable; no third-party code added) - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
THEMANnt commented 2026-10-26 19:16:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by THEMANnt on 2026-10-26T19:16:54Z.

Review: COMMENTED


Reviewed 52e0132a34e117a197331c66a38a1382b5d3568a. Pending review.

Configuration branches are checked; Linux ThreadSanitizer runtime validation remains pending.

Validation: Executed the submitted CMake guards and flag branches: Linux GNU/Clang select thread sanitizer and dynamic linking; Windows, Darwin, unsupported compiler and ASan+TSan combinations refuse as intended. Source review also covers the sanitizer-specific mlock exclusions and suppressions.

Scope / next step: These are actual CMake branch checks with recorded commands, not native Linux TSan compilation or execution. Please retain that distinction until a supported Linux runtime run is available.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5657683770 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11179#pullrequestreview-5657683770). Originally posted by [THEMANnt](https://github.com/THEMANnt) on 2026-10-26T19:16:54Z. **Review:** COMMENTED --- Reviewed `52e0132a34e117a197331c66a38a1382b5d3568a`. Pending review. Configuration branches are checked; Linux ThreadSanitizer runtime validation remains pending. **Validation:** Executed the submitted CMake guards and flag branches: Linux GNU/Clang select thread sanitizer and dynamic linking; Windows, Darwin, unsupported compiler and ASan+TSan combinations refuse as intended. Source review also covers the sanitizer-specific mlock exclusions and suppressions. **Scope / next step:** These are actual CMake branch checks with recorded commands, not native Linux TSan compilation or execution. Please retain that distinction until a supported Linux runtime run is available.
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!11179
No description provided.