fix(build): run the CPU-side tests in an ANYPS5_ENABLE_ASAN build #7147

Merged
milescoviello merged 1 commit from upstream-pr/7147 into main 2026-10-17 14:25:45 +00:00
milescoviello commented 2026-10-17 13:55:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-17T13:55:33Z.


What

-DANYPS5_ENABLE_ASAN=ON builds, but its tests don't pass. The set below is the 849 tests outside agc_driver_*, agc_vertex_barrier*, agc_shader* and the VideoOut tests, run with ASAN_OPTIONS=detect_leaks=0. On main 4827f36cb5 with #7115 applied, 14 of them fail. Each failure comes from the ASan build itself, not from the code under test. No CI job runs these tests under ASan, so nothing catches this. #7062, #7096 and #7097 add one for the relinker tests only. With this PR, all 849 pass and ASan reports nothing.

Tests Why they fail under ASan Change
patched_libraries, guest_memory_lifetime At load, libc copies the main executable's file-backed writable pages (GuestAllocations.cpp) before remapping them anonymously. In an instrumented test executable those pages hold ASan's redzones around globals: global-buffer-overflow ... READ of size 4096 ... in backWritableImageAnonymously. ASan builds copy the pages word by word in an uninstrumented function. Other builds keep memcpy.
guest_thread_self, guest_pthread_stack, guest_kernel_is_stack, guest_kernel_stack_protect, guest_raise_exception They check that the address of a local is on the thread's stack. With detect_stack_use_after_return, which is on by default on Linux, an instrumented local lives on ASan's fake stack instead. These five run with detect_stack_use_after_return=0.
guest_kernel_is_stack It also requires a worker's stack below 0xFC00000000, but the ASan build moves the guest arena up by 0x100000000000. The bound includes that offset, as guest_memory's arena check already does.
fiber LargeContextEntry and CheckActiveContext check a local's address against the fiber's context, which fake stacks break. CheckActiveContext also reads the fiber's stack word by word above that local, through the redzones of the frames on that stack: stack-buffer-overflow ... in CheckActiveContext. Runs with detect_stack_use_after_return=0, and CheckActiveContext is not instrumented.
guest_module_args, guest_deferred_dependencies, guest_module_fini, loadexec_arguments They load instrumented libraries into a Python process or a relinked guest: ASan runtime does not come first in initial library list. These four run with verify_asan_link_order=0. Preloading libasan instead makes loadexec_arguments abort. ASan's __cxa_throw interceptor then comes before libc.prx's, and the unwind of the exception that LoadExec throws for a missing target, and GuestLoadExecHost catches, aborts in _Unwind_Resume.
guest_allocator_failures It lowers RLIMIT_DATA to 128 MiB and then commits 300 GiB. ASan maps that commit's 37.5 GiB of shadow, which the limit refuses: AddressSanitizer failed to allocate 0x960002000 (40265326592) bytes ... (errno: 12). ASan builds skip that section and print why, as non-Linux hosts already do.
agc_multisample_guest_access (GPU) fmaskDecompressMsaaTests asks aligned_alloc for 0x71000 bytes at a 64 KiB alignment. C11 requires the size to be a multiple of the alignment, and ASan rejects it. The size is rounded up.

add_asan_test_options(test options) (top-level CMakeLists.txt) appends to ASAN_OPTIONS for one test in an ASan build and does nothing otherwise. Non-ASan builds run the same code as before, except for the rounded aligned_alloc size.

Leak detection is not covered. With ASan's default detect_leaks=1, 73 tests fail, mostly Vulkan-driver and process-lifetime allocations. That is separate work.

Tested

Ubuntu 24.04, GCC 13.3, RTX 4070 Ti (NVIDIA 595.99). ASan build: -DCMAKE_BUILD_TYPE=RelWithDebInfo -DANYPS5_ENABLE_ASAN=ON, ASAN_OPTIONS=detect_leaks=0, ctest -E '^agc_driver_|^agc_vertex_barrier|videoout|^agc_shader' -j6.

  • main 4827f36cb5 + #7115: 14 of 849 fail, the 14 tests in the table, with 4 ASan reports. agc_multisample_guest_access fails with invalid alignment requested in aligned_alloc.
  • This PR (f9cae48517) + #7115: 849 of 849 pass, with no ASan report. fiber, patched_libraries and guest_memory_lifetime pass 3 of 3. The head, 1c9d9d6bc5, only moves the three relinker add_asan_test_options lines below guest_module_fini, away from where #6112 adds guest_preinit. After reconfiguring, those four Python-hosted tests carry verify_asan_link_order=0 and pass.
  • Release build, on this PR before its fiber test option and its attribute spelling (861107b45a): the 14 changed tests pass 3 of 3, and the same 849-test set passes 849 of 849. On the final head, fiber builds without warnings and passes 3 of 3.
  • tools/check_conventions.py passes. tools/pr_overlap.py couldn't compare 16 open PRs that conflict with main. None of their diffs changes the lines this PR touches. #6044 moves Fiber.cpp, GuestAllocatorFailures.cpp and GuestKernelIsStack.cpp into subfolders and edits the same CMake files, so whichever of the two merges second needs a rebase. I'll do it if it's this one. #6112's new guest_preinit loads the same instrumented host into Python, so it will need add_asan_test_options(guest_preinit verify_asan_link_order=0) once both are in.

Without #7115, guest_once also aborts in the ASan build (guest address space arena exhausted). That fix is separate because it changes libkernel itself.

Not checked: Clang's ASan, Windows and macOS (ASan builds are Linux-only).

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 (#7115 for guest_once)
  • Unblocks: none
  • GPUs tested: NVIDIA GeForce RTX 4070 Ti, driver 595.99, Ubuntu 24.04 (agc_multisample_guest_access only)
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4900638352 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7147). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-17T13:55:33Z. --- ### What `-DANYPS5_ENABLE_ASAN=ON` builds, but its tests don't pass. The set below is the 849 tests outside `agc_driver_*`, `agc_vertex_barrier*`, `agc_shader*` and the VideoOut tests, run with `ASAN_OPTIONS=detect_leaks=0`. On `main` 4827f36cb5 with #7115 applied, 14 of them fail. Each failure comes from the ASan build itself, not from the code under test. No CI job runs these tests under ASan, so nothing catches this. #7062, #7096 and #7097 add one for the relinker tests only. With this PR, all 849 pass and ASan reports nothing. | Tests | Why they fail under ASan | Change | |---|---|---| | `patched_libraries`, `guest_memory_lifetime` | At load, libc copies the main executable's file-backed writable pages (`GuestAllocations.cpp`) before remapping them anonymously. In an instrumented test executable those pages hold ASan's redzones around globals: `global-buffer-overflow ... READ of size 4096 ... in backWritableImageAnonymously`. | ASan builds copy the pages word by word in an uninstrumented function. Other builds keep `memcpy`. | | `guest_thread_self`, `guest_pthread_stack`, `guest_kernel_is_stack`, `guest_kernel_stack_protect`, `guest_raise_exception` | They check that the address of a local is on the thread's stack. With `detect_stack_use_after_return`, which is on by default on Linux, an instrumented local lives on ASan's fake stack instead. | These five run with `detect_stack_use_after_return=0`. | | `guest_kernel_is_stack` | It also requires a worker's stack below `0xFC00000000`, but the ASan build moves the guest arena up by `0x100000000000`. | The bound includes that offset, as `guest_memory`'s arena check already does. | | `fiber` | `LargeContextEntry` and `CheckActiveContext` check a local's address against the fiber's context, which fake stacks break. `CheckActiveContext` also reads the fiber's stack word by word above that local, through the redzones of the frames on that stack: `stack-buffer-overflow ... in CheckActiveContext`. | Runs with `detect_stack_use_after_return=0`, and `CheckActiveContext` is not instrumented. | | `guest_module_args`, `guest_deferred_dependencies`, `guest_module_fini`, `loadexec_arguments` | They load instrumented libraries into a Python process or a relinked guest: `ASan runtime does not come first in initial library list`. | These four run with `verify_asan_link_order=0`. Preloading libasan instead makes `loadexec_arguments` abort. ASan's `__cxa_throw` interceptor then comes before libc.prx's, and the unwind of the exception that LoadExec throws for a missing target, and `GuestLoadExecHost` catches, aborts in `_Unwind_Resume`. | | `guest_allocator_failures` | It lowers `RLIMIT_DATA` to 128 MiB and then commits 300 GiB. ASan maps that commit's 37.5 GiB of shadow, which the limit refuses: `AddressSanitizer failed to allocate 0x960002000 (40265326592) bytes ... (errno: 12)`. | ASan builds skip that section and print why, as non-Linux hosts already do. | | `agc_multisample_guest_access` (GPU) | `fmaskDecompressMsaaTests` asks `aligned_alloc` for 0x71000 bytes at a 64 KiB alignment. C11 requires the size to be a multiple of the alignment, and ASan rejects it. | The size is rounded up. | `add_asan_test_options(test options)` (top-level `CMakeLists.txt`) appends to `ASAN_OPTIONS` for one test in an ASan build and does nothing otherwise. Non-ASan builds run the same code as before, except for the rounded `aligned_alloc` size. Leak detection is not covered. With ASan's default `detect_leaks=1`, 73 tests fail, mostly Vulkan-driver and process-lifetime allocations. That is separate work. ### Tested Ubuntu 24.04, GCC 13.3, RTX 4070 Ti (NVIDIA 595.99). ASan build: `-DCMAKE_BUILD_TYPE=RelWithDebInfo -DANYPS5_ENABLE_ASAN=ON`, `ASAN_OPTIONS=detect_leaks=0`, `ctest -E '^agc_driver_|^agc_vertex_barrier|videoout|^agc_shader' -j6`. - `main` 4827f36cb5 + #7115: 14 of 849 fail, the 14 tests in the table, with 4 ASan reports. `agc_multisample_guest_access` fails with `invalid alignment requested in aligned_alloc`. - This PR (f9cae48517) + #7115: 849 of 849 pass, with no ASan report. `fiber`, `patched_libraries` and `guest_memory_lifetime` pass 3 of 3. The head, 1c9d9d6bc5, only moves the three relinker `add_asan_test_options` lines below `guest_module_fini`, away from where #6112 adds `guest_preinit`. After reconfiguring, those four Python-hosted tests carry `verify_asan_link_order=0` and pass. - Release build, on this PR before its `fiber` test option and its attribute spelling (861107b45a): the 14 changed tests pass 3 of 3, and the same 849-test set passes 849 of 849. On the final head, `fiber` builds without warnings and passes 3 of 3. - `tools/check_conventions.py` passes. `tools/pr_overlap.py` couldn't compare 16 open PRs that conflict with `main`. None of their diffs changes the lines this PR touches. #6044 moves `Fiber.cpp`, `GuestAllocatorFailures.cpp` and `GuestKernelIsStack.cpp` into subfolders and edits the same CMake files, so whichever of the two merges second needs a rebase. I'll do it if it's this one. #6112's new `guest_preinit` loads the same instrumented host into Python, so it will need `add_asan_test_options(guest_preinit verify_asan_link_order=0)` once both are in. Without #7115, `guest_once` also aborts in the ASan build (`guest address space arena exhausted`). That fix is separate because it changes libkernel itself. Not checked: Clang's ASan, Windows and macOS (ASan builds are Linux-only). ### Checklist - [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 (#7115 for `guest_once`) - [x] Unblocks: none - [x] GPUs tested: NVIDIA GeForce RTX 4070 Ti, driver 595.99, Ubuntu 24.04 (`agc_multisample_guest_access` only) - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-actions[bot] commented 2026-10-17 14:35:00 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-17T14:35:00Z.


Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 674 CMakeLists.txt
PR 1324 core/libs/prx/libc/src/GuestAllocations.cpp
PR 1368 core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
PR 1395 core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
PR 1835 CMakeLists.txt
core/libs/prx/libc/src/GuestAllocations.cpp
PR 4972 core/libs/prx/libkernel/CMakeLists.txt
PR 5021 CMakeLists.txt
core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
core/libs/prx/libc/src/GuestAllocations.cpp
core/libs/prx/libkernel/CMakeLists.txt
core/relinker/CMakeLists.txt
PR 5925 core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
PR 6044 CMakeLists.txt
core/libs/prx/libSceFiber/CMakeLists.txt
core/libs/prx/libSceSystemService/CMakeLists.txt
core/libs/prx/libkernel/CMakeLists.txt
core/libs/tests/Fiber.cpp
core/libs/tests/GuestAllocatorFailures.cpp
core/libs/tests/GuestKernelIsStack.cpp
core/relinker/CMakeLists.txt
PR 6188 core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
PR 6222 core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
core/libs/prx/libc/src/GuestAllocations.cpp
core/libs/prx/libkernel/CMakeLists.txt
PR 6287 core/libs/prx/libkernel/CMakeLists.txt
PR 6314 core/relinker/CMakeLists.txt
PR 6373 core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
PR 6487 core/libs/prx/libkernel/CMakeLists.txt
PR 6565 core/libs/prx/libc/src/GuestAllocations.cpp
PR 6747 core/libs/prx/libSceAgcDriver/tests/Recorder.cpp
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6235150601 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7147#issuecomment-6235150601). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-17T14:35:00Z. --- <!-- pr-overlap --> Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap. | Pull request | Shared files not compared | |---|---| | [PR 674](https://www.github.com/boykopovar/AnyPS5/pull/674) | `CMakeLists.txt` | | [PR 1324](https://www.github.com/boykopovar/AnyPS5/pull/1324) | `core/libs/prx/libc/src/GuestAllocations.cpp` | | [PR 1368](https://www.github.com/boykopovar/AnyPS5/pull/1368) | `core/libs/prx/libSceAgcDriver/tests/Recorder.cpp` | | [PR 1395](https://www.github.com/boykopovar/AnyPS5/pull/1395) | `core/libs/prx/libSceAgcDriver/tests/Recorder.cpp` | | [PR 1835](https://www.github.com/boykopovar/AnyPS5/pull/1835) | `CMakeLists.txt`<br>`core/libs/prx/libc/src/GuestAllocations.cpp` | | [PR 4972](https://www.github.com/boykopovar/AnyPS5/pull/4972) | `core/libs/prx/libkernel/CMakeLists.txt` | | [PR 5021](https://www.github.com/boykopovar/AnyPS5/pull/5021) | `CMakeLists.txt`<br>`core/libs/prx/libSceAgcDriver/tests/Recorder.cpp`<br>`core/libs/prx/libc/src/GuestAllocations.cpp`<br>`core/libs/prx/libkernel/CMakeLists.txt`<br>`core/relinker/CMakeLists.txt` | | [PR 5925](https://www.github.com/boykopovar/AnyPS5/pull/5925) | `core/libs/prx/libSceAgcDriver/tests/Recorder.cpp` | | [PR 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `CMakeLists.txt`<br>`core/libs/prx/libSceFiber/CMakeLists.txt`<br>`core/libs/prx/libSceSystemService/CMakeLists.txt`<br>`core/libs/prx/libkernel/CMakeLists.txt`<br>`core/libs/tests/Fiber.cpp`<br>`core/libs/tests/GuestAllocatorFailures.cpp`<br>`core/libs/tests/GuestKernelIsStack.cpp`<br>`core/relinker/CMakeLists.txt` | | [PR 6188](https://www.github.com/boykopovar/AnyPS5/pull/6188) | `core/libs/prx/libSceAgcDriver/tests/Recorder.cpp` | | [PR 6222](https://www.github.com/boykopovar/AnyPS5/pull/6222) | `core/libs/prx/libSceAgcDriver/tests/Recorder.cpp`<br>`core/libs/prx/libc/src/GuestAllocations.cpp`<br>`core/libs/prx/libkernel/CMakeLists.txt` | | [PR 6287](https://www.github.com/boykopovar/AnyPS5/pull/6287) | `core/libs/prx/libkernel/CMakeLists.txt` | | [PR 6314](https://www.github.com/boykopovar/AnyPS5/pull/6314) | `core/relinker/CMakeLists.txt` | | [PR 6373](https://www.github.com/boykopovar/AnyPS5/pull/6373) | `core/libs/prx/libSceAgcDriver/tests/Recorder.cpp` | | [PR 6487](https://www.github.com/boykopovar/AnyPS5/pull/6487) | `core/libs/prx/libkernel/CMakeLists.txt` | | [PR 6565](https://www.github.com/boykopovar/AnyPS5/pull/6565) | `core/libs/prx/libc/src/GuestAllocations.cpp` | | [PR 6747](https://www.github.com/boykopovar/AnyPS5/pull/6747) | `core/libs/prx/libSceAgcDriver/tests/Recorder.cpp` |
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!7147
No description provided.