Skip to content

Add AddressSanitizer support for clang-cl builds - #692

Merged
majcosta merged 1 commit into
1dot13:masterfrom
majcosta:asan_instrumentation
Aug 21, 2026
Merged

Add AddressSanitizer support for clang-cl builds#692
majcosta merged 1 commit into
1dot13:masterfrom
majcosta:asan_instrumentation

Conversation

@majcosta

Copy link
Copy Markdown
Collaborator

Select the clang-cl-asan CMake preset (RelWithDebInfo, clang-cl, ADDRESS_SANITIZER=ON) to instrument first-party code with AddressSanitizer. The wiring lives in cmake/AddressSanitizer.cmake; SANITIZERS.md tells how to add the clang-cl tools, build, and read the report.

Details:

  • Add the clang-cl-asan preset so the asan build is one selection in Visual Studio, and a base for a CMakeUserPresets.json to inherit.
  • Instrument first-party code only; the vendored libraries keep default flags.
  • Use the release CRT and disable MSVC-STL container annotations, so instrumented and un-instrumented TUs stay compatible.
  • Pass /bigobj to the TUs asan inflates past the COFF section cap.
  • Link the asan runtime for clang-cl (lld-link does not infer it).
  • Stub Bink into the exe: retail binkw32.dll cannot load in an asan process (its image base is the 32-bit shadow), so compile no-op exports instead.
  • Route the asan report to gamedir/asan.report., since every app is a WIN32 GUI app with no console to receive the default stderr report.
  • Opt functions with 32-bit inline __asm out of instrumentation with cmake/asan-ignorelist.txt, one function at a time (asan reserves a register the asm needs). The rest of each translation unit stays instrumented.

Select the clang-cl-asan CMake preset (RelWithDebInfo, clang-cl,
ADDRESS_SANITIZER=ON) to instrument first-party code with AddressSanitizer.
The wiring lives in cmake/AddressSanitizer.cmake; SANITIZERS.md tells how to
add the clang-cl tools, build, and read the report.

Details:
- Add the clang-cl-asan preset so the asan build is one selection in Visual
  Studio, and a base for a CMakeUserPresets.json to inherit.
- Instrument first-party code only; the vendored libraries keep default flags.
- Use the release CRT and disable MSVC-STL container annotations, so
  instrumented and un-instrumented TUs stay compatible.
- Pass /bigobj to the TUs asan inflates past the COFF section cap.
- Link the asan runtime for clang-cl (lld-link does not infer it).
- Stub Bink into the exe: retail binkw32.dll cannot load in an asan process
  (its image base is the 32-bit shadow), so compile no-op exports instead.
- Route the asan report to gamedir/asan.report.<pid>, since every app is a
  WIN32 GUI app with no console to receive the default stderr report.
- Opt functions with 32-bit inline __asm out of instrumentation with
  cmake/asan-ignorelist.txt, one function at a time (asan reserves a register
  the asm needs). The rest of each translation unit stays instrumented.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@majcosta
majcosta merged commit 1bed004 into 1dot13:master Aug 21, 2026
6 checks passed
@majcosta
majcosta deleted the asan_instrumentation branch August 21, 2026 02:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant