[compiler-rt] [compiler-rt] Add MinGW GCC support for Windows sanitizer runtimes (PR #209902)

Martin Storsjö via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 10 02:45:35 PDT 2026


================
@@ -332,15 +335,27 @@ ShadowExceptionHandler(PEXCEPTION_POINTERS exception_pointers) {
 #endif
 
 void InitializePlatformExceptionHandlers() {
-#if SANITIZER_WINDOWS64
+#  if SANITIZER_WINDOWS64
   // On Win64, we map memory on demand with access violation handler.
   // Install our exception handler.
   CHECK(AddVectoredExceptionHandler(TRUE, &ShadowExceptionHandler));
 #endif
 }
 
 bool IsSystemHeapAddress(uptr addr) {
-  return ::HeapValidate(GetProcessHeap(), 0, (void *)addr) != FALSE;
+  HANDLE process_heap = GetProcessHeap();
+  if (::HeapValidate(process_heap, 0, (void*)addr))
+    return true;
+
+#  if defined(__GNUC__) && !defined(__clang__)
+  HANDLE crt_heap = (HANDLE)_get_heap_handle();
+  if (crt_heap == process_heap)
----------------
mstorsjo wrote:

Yes, it's probably not worth trying to care about msvcrt here. (However if we did, the ifdefs don't seem right - if something is required for msvcrt, we'd want that if we target msvcrt with clang too.)

Earlier, asan with msvcrt used to work to some extent (perhaps it would have worked better with this change?), but it broke more in https://github.com/llvm/llvm-project/pull/120397#issuecomment-2635072339. Before that, there were also other known issues with it, see https://github.com/mstorsjo/llvm-mingw/issues/224 and https://github.com/mstorsjo/llvm-mingw/issues/552. I've later entirely stopped distributing asan in msvcrt targeting builds of llvm-mingw.

So just dropping any msvcrt specific concerns sounds good to me.

https://github.com/llvm/llvm-project/pull/209902


More information about the llvm-commits mailing list