Skip to content

fix(build): spell the ASan opt-out so Clang honours it - #20050

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
uttam12331:fix/clang-no-sanitize-address
Nov 22, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
uttam12331:fix/clang-no-sanitize-address

Conversation

@uttam12331

Copy link
Copy Markdown
Contributor

What

Seven functions opt out of AddressSanitizer with [[gnu::no_sanitize("address")]]. GCC accepts that spelling, but Clang only knows no_sanitize as __attribute__((no_sanitize(...))) or [[clang::no_sanitize(...)]], so it drops the attribute and instruments the functions anyway:

core/libs/prx/libc/src/GuestAllocations.cpp:148:3: warning: unknown attribute 'no_sanitize' ignored [-Wunknown-attributes]

Each of these functions deliberately reads memory that ASan poisons (the main image's writable pages with their global redzones, 16-byte blocks that run past a string's end, a fiber's stack), so in a Clang ASan build they report false overflows. copyImagePages runs from a static initializer of libc, so every test that loads libc.prx stops there:

ERROR: AddressSanitizer: global-buffer-overflow
    #0 in copyImagePages core/libs/prx/libc/src/GuestAllocations.cpp:151:90
    #1 in backWritableImageAnonymously core/libs/prx/libc/src/GuestAllocations.cpp:161:9
    #2 in __cxx_global_var_init core/libs/prx/libc/src/GuestAllocations.cpp:170:54

This uses [[gnu::no_sanitize_address]], which GCC and Clang both accept with the same meaning, in all seven places:

  • core/libs/prx/libc/src/GuestAllocations.cpp: copyImagePages
  • core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp: CopyGuestBytes
  • core/libs/prx/libc/src/Strings.cpp: MismatchedUnits, MatchUnits, MatchUnitsOrZero, FindLastUnit
  • core/libs/tests/Fiber.cpp: CheckActiveContext

GCC builds the same code as before.

Tested

Ubuntu 24.04, Ninja, Release, -DANYPS5_ENABLE_ASAN=ON -fsanitize=undefined, ASAN_OPTIONS=detect_leaks=0, UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1, main 8d3ff887df and this change. The tests cover all seven functions:

Test Clang 18.1.3, main Clang 18.1.3, this PR GCC 13.3.0, this PR
guest_freetype_postscript_private global-buffer-overflow in copyImagePages passes passes
guest_dinkumware_fetch_add_8 global-buffer-overflow in copyImagePages passes passes
guest_wide_strings global-buffer-overflow in MatchUnitsOrZero passes passes
guest_wide_scan_blocks stack-buffer-overflow in MatchUnits passes passes
agc_driver_compute_user_data_calls global-buffer-overflow in CopyGuestBytes passes passes
agc_driver_draw_cache_relocation global-buffer-overflow in CopyGuestBytes passes passes
fiber stack-buffer-overflow in CheckActiveContext passes passes

With this PR the Clang build prints no unknown attribute 'no_sanitize' warning. In a full Clang ASan and UBSan run of main 2cebbe43ee, 158 of the 450 failing tests stop in one of these functions: 124 in copyImagePages, 31 in CopyGuestBytes, 2 in Strings.cpp and 1 in Fiber.cpp.

  • tools/check_conventions.py --base origin/main and git diff --check: clean.
  • tools/pr_overlap.py --branch fix/clang-no-sanitize-address, against 1,520 open pull requests: no overlap reported. 21 that share a file conflict with main and could not be compared; none of them changes a no_sanitize line.
  • Not run: Windows, macOS, a full rerun of every Clang test with this PR, any title.

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
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

@github-actions github-actions Bot added libc agc libSceAgc* labels Nov 14, 2026
@github-actions

github-actions Bot commented Nov 14, 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
PR 22156 core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp L3682-3684

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 1835 core/libs/prx/libc/src/GuestAllocations.cpp
PR 4448 core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
PR 6186 core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
PR 6188 core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
PR 6192 core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
PR 6209 core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
PR 7642 core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
PR 8965 core/libs/prx/libc/src/Strings.cpp
PR 9508 core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
PR 10193 core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
PR 12157 core/libs/prx/libc/src/GuestAllocations.cpp
PR 12840 core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
PR 13928 core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
PR 13929 core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
PR 15136 core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
PR 20084 core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
PR 20315 core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
PR 22062 core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
PR 22434 core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp
PR 22647 core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp

@JJenkx

JJenkx commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

Windows check of head 3521a9feb2, merged onto main c04f8bec02 (390894ae6e, clean merge).

Setup: Windows 11 Enterprise 22621, WinLibs GCC 15.2 UCRT, Release. The hosted Windows check does not run these tests on pull requests.

  • fiber, fiber_contextless pass in 3 of 3 runs, none skipped.

AI-assisted: yes.

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — looks good

Nothing in the reviewed changes blocks merging; the replacement attribute spelling is consistently applied at all seven reported sites.

What I ran

Reviewed head 3521a9feb2b541233d1a474017cac1aac9923c19. Read the prepared diff and all four changed files through repo_read.py; no build or tests were run.

Results

Check Result Note
Changed files reviewed passed All four files read
Build and tests not run Author reports compiler and test results

Findings

Blocking

None.

Non-blocking

None.

Not verified

Build and test claims in the description were not independently verified. No files were excluded from the changed-file review; files.json was unavailable, so the included-file list was confirmed with the review directory listing.

To get this to a good state

Nothing is required.

Continued review (pass 2)

The requested added lines are address-sanitizer function attributes on SIMD helpers; their implementations and callers show no defect in this continuation pass.

What I ran

  • Reviewed head 3521a9feb2b541233d1a474017cac1aac9923c19.
  • Read the prepared diff and core/libs/prx/libc/src/Strings.cpp lines 120–195, plus lines 1–68 for the relevant helper context. No tests were run.

Results

Check Result Note
Requested added lines passed All three requested lines and surrounding helper code read
Tests not run This continuation pass was limited to the requested lines

Findings

Blocking

None.

Non-blocking

None.

Not verified

This pass covers only the three requested added lines in Strings.cpp; other changes and tests from the full pull request review are outside its scope.

To get this to a good state

Nothing is required.

@kiwe147

kiwe147 commented Nov 21, 2026

Copy link
Copy Markdown

Tested head 3521a9feb2, applied with git apply on main fd4aeed483 together with the other 29 PRs of one batch (#24470, #24601, #17439, #17546, #21117, #21261, #21741, #21995, #22067, #22398, #23111, #23346, #23864, #24377, #24475, #24556, #14106, #14109, #19966, #20161, #20622, #21237, #22215, #22764, #22884, #22938, #23745, #24399, #24460). All applied without conflicts and the whole tree built.

Setup: Windows 11 Pro 10.0.26200, Ryzen 7 9800X3D, WinLibs GCC 15.2.0 r7, Release, BUILD_TESTING=ON. GPUs: NVIDIA GeForce RTX 3080 (driver 621.24) and the AMD Radeon iGPU of the CPU (gfx1036, driver 32.0.21036.18). No validation layer. iGPU run: ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 ANYPS5_GPU="AMD Radeon", agc_/video tests only.

tests RTX 3080 iGPU
fiber, fiber_contextless, guest_fiber_context_margin_bounds and 4 more (7 tests, matched by name to the test file this PR changes) all pass outside the iGPU subset

Whole batch: the full ctest -j 12 (6525 tests) on the RTX 3080 has 5 failing tests; the 4 that also fail on main fd4aeed483 are agc_driver_stencil_plane_memory, agc_driver_msaa_dcc_unwatch, agc_storage_write_back_host_retile, and pr_overlap_names, which needs a newer Python than my 3.10. Traced to other PRs of the batch, each by reverting it and testing again: #21117 (guest_pad); none is in this PR's area. The 2125 agc_/video tests on the iGPU have 1 failing: agc_driver_stencil_plane_memory (agc_driver_stencil_plane_memory also fails on main).

This is one combined tree, not a run of this PR alone.

AI-assisted: yes (Claude Code)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* libc

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants