[compiler-rt] 814a75d - [compiler-rt][asan][win] Intercept exceptions for i686 MinGW

Alvin Wong via llvm-commits llvm-commits at lists.llvm.org
Thu May 4 07:41:42 PDT 2023


Author: Alvin Wong
Date: 2023-05-04T22:41:26+08:00
New Revision: 814a75dca75406dd06dfdf72bed078394f239728

URL: https://github.com/llvm/llvm-project/commit/814a75dca75406dd06dfdf72bed078394f239728
DIFF: https://github.com/llvm/llvm-project/commit/814a75dca75406dd06dfdf72bed078394f239728.diff

LOG: [compiler-rt][asan][win] Intercept exceptions for i686 MinGW

The i686-w64-windows-gnu target does not use SEH (which MSVC uses),
but DWARF-2 exception handling or possibly sjlj depending on the
toolchain build options. On this target we have to actually intercept
functions in libc++ and libunwind which handles throwing exceptions.
This fixes the `TestCases/intercept-rethrow-exception.cpp` test.

The x86_64-w64-windows-gnu target already works because it uses SEH
which is handled by intercepting RaiseException, so this change does not
affect x86_64.

Depends on https://reviews.llvm.org/D148990

Differential Revision: https://reviews.llvm.org/D148991

Added: 
    

Modified: 
    compiler-rt/lib/asan/asan_interceptors.h
    compiler-rt/lib/interception/interception_win.cpp

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/asan/asan_interceptors.h b/compiler-rt/lib/asan/asan_interceptors.h
index c4bf087ea17f0..e7bec02f048d9 100644
--- a/compiler-rt/lib/asan/asan_interceptors.h
+++ b/compiler-rt/lib/asan/asan_interceptors.h
@@ -78,8 +78,8 @@ void InitializePlatformInterceptors();
 # define ASAN_INTERCEPT___LONGJMP_CHK 0
 #endif
 
-#if ASAN_HAS_EXCEPTIONS && !SANITIZER_WINDOWS && !SANITIZER_SOLARIS && \
-    !SANITIZER_NETBSD
+#if ASAN_HAS_EXCEPTIONS && !SANITIZER_SOLARIS && !SANITIZER_NETBSD && \
+    (!SANITIZER_WINDOWS || (defined(__MINGW32__) && defined(__i386__)))
 # define ASAN_INTERCEPT___CXA_THROW 1
 # define ASAN_INTERCEPT___CXA_RETHROW_PRIMARY_EXCEPTION 1
 # if defined(_GLIBCXX_SJLJ_EXCEPTIONS) || (SANITIZER_IOS && defined(__arm__))

diff  --git a/compiler-rt/lib/interception/interception_win.cpp b/compiler-rt/lib/interception/interception_win.cpp
index 7e8a78bae89ab..ed840d90e6fea 100644
--- a/compiler-rt/lib/interception/interception_win.cpp
+++ b/compiler-rt/lib/interception/interception_win.cpp
@@ -898,6 +898,10 @@ static void **InterestingDLLsAvailable() {
       "msvcr120.dll",      // VS2013
       "vcruntime140.dll",  // VS2015
       "ucrtbase.dll",      // Universal CRT
+#if (defined(__MINGW32__) && defined(__i386__))
+      "libc++.dll",        // libc++
+      "libunwind.dll",     // libunwind
+#endif
       // NTDLL should go last as it exports some functions that we should
       // override in the CRT [presumably only used internally].
       "ntdll.dll", NULL};


        


More information about the llvm-commits mailing list