<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Aug 5, 2016 at 2:47 PM, Reid Kleckner via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: rnk<br>
Date: Fri Aug  5 16:47:46 2016<br>
New Revision: 277874<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=277874&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project?rev=277874&view=rev</a><br>
Log:<br>
Fix two tests in Win64 ASan<br>
<br>
Go back to intercepting kernel32!RaiseException, and only go for<br>
ntdll!RtlRaiseException if that fails. Fixes throw_and_catch.cc test.<br>
<br>
Work around an issue in LLVM's win64 epilogues. We end up with an<br>
epilogue that looks like this, and it drives the Win64 unwinder crazy<br>
until stack overflow:<br>
        call    ill_cc!__asan_handle_no_return<br>
        xor     eax,eax<br>
        add     rsp,40h // epilogue starts </blockquote><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
        pop     rbp     // CSR<br>
        ud2             // Trap here<br>
        ret             // Ret?<br>
        nop     word ptr [rax+rax]<br>
        sub     rsp,28h // Next function<br></blockquote><div><br></div><div><br></div><div>Interesting.  So we started the epilogue but didn't finish it.  Happen to have some IR or C lying around?  I'm curious exactly when we decided that a ud2 between the pop and the ret was a smart move...</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Will file a PR soon.<br>
<br>
Modified:<br>
    compiler-rt/trunk/lib/asan/<wbr>asan_win.cc<br>
    compiler-rt/trunk/test/asan/<wbr>TestCases/Windows/dll_host.cc<br>
    compiler-rt/trunk/test/asan/<wbr>TestCases/ill.cc<br>
<br>
Modified: compiler-rt/trunk/lib/asan/<wbr>asan_win.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_win.cc?rev=277874&r1=277873&r2=277874&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/compiler-rt/trunk/lib/<wbr>asan/asan_win.cc?rev=277874&<wbr>r1=277873&r2=277874&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- compiler-rt/trunk/lib/asan/<wbr>asan_win.cc (original)<br>
+++ compiler-rt/trunk/lib/asan/<wbr>asan_win.cc Fri Aug  5 16:47:46 2016<br>
@@ -80,6 +80,11 @@ INTERCEPTOR_WINAPI(void, RtlRaiseExcepti<br>
   REAL(RtlRaiseException)(<wbr>ExceptionRecord);<br>
 }<br>
<br>
+INTERCEPTOR_WINAPI(void, RaiseException, void *a, void *b, void *c, void *d) {<br>
+  CHECK(REAL(RaiseException));<br>
+  __asan_handle_no_return();<br>
+  REAL(RaiseException)(a, b, c, d);<br>
+}<br>
<br>
 #ifdef _WIN64<br>
<br>
@@ -138,10 +143,6 @@ namespace __asan {<br>
<br>
 void InitializePlatformInterceptors<wbr>() {<br>
   ASAN_INTERCEPT_FUNC(<wbr>CreateThread);<br>
-  // RtlRaiseException is always linked dynamically.<br>
-  CHECK(::__interception::<wbr>OverrideFunction("<wbr>RtlRaiseException",<br>
-                                           (uptr)WRAP(RtlRaiseException),<br>
-                                           (uptr *)&REAL(RtlRaiseException)));<br>
<br>
 #ifdef _WIN64<br>
   ASAN_INTERCEPT_FUNC(__C_<wbr>specific_handler);<br>
@@ -149,6 +150,16 @@ void InitializePlatformInterceptors<wbr>() {<br>
   ASAN_INTERCEPT_FUNC(_except_<wbr>handler3);<br>
   ASAN_INTERCEPT_FUNC(_except_<wbr>handler4);<br>
 #endif<br>
+<br>
+  // Try to intercept kernel32!RaiseException, and if that fails, intercept<br>
+  // ntdll!RtlRaiseException instead.<br>
+  if (!::__interception::<wbr>OverrideFunction("<wbr>RaiseException",<br>
+                                          (uptr)WRAP(RaiseException),<br>
+                                          (uptr *)&REAL(RaiseException))) {<br>
+    CHECK(::__interception::<wbr>OverrideFunction("<wbr>RtlRaiseException",<br>
+                                             (uptr)WRAP(RtlRaiseException),<br>
+                                             (uptr *)&REAL(RtlRaiseException)));<br>
+  }<br>
 }<br>
<br>
 void AsanApplyToGlobals(globals_op_<wbr>fptr op, const void *needle) {<br>
<br>
Modified: compiler-rt/trunk/test/asan/<wbr>TestCases/Windows/dll_host.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Windows/dll_host.cc?rev=277874&r1=277873&r2=277874&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/compiler-rt/trunk/<wbr>test/asan/TestCases/Windows/<wbr>dll_host.cc?rev=277874&r1=<wbr>277873&r2=277874&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- compiler-rt/trunk/test/asan/<wbr>TestCases/Windows/dll_host.cc (original)<br>
+++ compiler-rt/trunk/test/asan/<wbr>TestCases/Windows/dll_host.cc Fri Aug  5 16:47:46 2016<br>
@@ -24,6 +24,7 @@<br>
 // IMPORT: __asan_wrap_HeapReAlloc<br>
 // IMPORT: __asan_wrap_HeapSize<br>
 // IMPORT: __asan_wrap_CreateThread<br>
+// IMPORT: __asan_wrap_RaiseException<br>
 // IMPORT: __asan_wrap_RtlRaiseException<br>
 //<br>
 // The exception handlers differ in 32-bit and 64-bit, so we ignore them:<br>
<br>
Modified: compiler-rt/trunk/test/asan/<wbr>TestCases/ill.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/ill.cc?rev=277874&r1=277873&r2=277874&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/compiler-rt/trunk/<wbr>test/asan/TestCases/ill.cc?<wbr>rev=277874&r1=277873&r2=<wbr>277874&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- compiler-rt/trunk/test/asan/<wbr>TestCases/ill.cc (original)<br>
+++ compiler-rt/trunk/test/asan/<wbr>TestCases/ill.cc Fri Aug  5 16:47:46 2016<br>
@@ -9,7 +9,7 @@<br>
 #include <windows.h><br>
 #endif<br>
<br>
-int main() {<br>
+int main(int argc, char **argv) {<br>
 #ifdef _WIN32<br>
   // Sometimes on Windows this test generates a WER fault dialog. Suppress that.<br>
   UINT new_flags = SEM_FAILCRITICALERRORS |<br>
@@ -21,7 +21,10 @@ int main() {<br>
   SetErrorMode(existing_flags | new_flags);<br>
 #endif<br>
<br>
-  __builtin_trap();<br>
+  if (argc)<br>
+    __builtin_trap();<br>
+  // Unreachable code to avoid confusing the Windows unwinder.<br>
+  SetErrorMode(0);<br>
 }<br>
 // CHECK0-NOT: ERROR: AddressSanitizer<br>
 // CHECK1: ERROR: AddressSanitizer: {{ILL|illegal-instruction}} on unknown address {{0x0*}}<br>
<br>
<br>
______________________________<wbr>_________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div></div>