<div dir="ltr">Someone needs to implement <a href="https://llvm.org/bugs/show_bug.cgi?id=24233">https://llvm.org/bugs/show_bug.cgi?id=24233</a> before MCJIT can support EH on Win64.<div><br></div><div>The llc command probably failed because the Cpp backend was unmaintained. It was removed from the last release.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Sep 6, 2016 at 1:44 AM, Stefan de Bruijn via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@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">





<div lang="NL" link="#0563C1" vlink="#954F72">
<div class="m_-2792294432728419895WordSection1">
<p class="MsoNormal"><span lang="EN-US">Hi,<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">I apologize if I'm posting this to the wrong list; if this is the case, please let me know.<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">For some time now, I've been trying to get SEH exception handling to work in LLVM MCJIT (x64). While reading up on LLVM 3.8, I decided to pick it up again, because a lot has changed which simplifies things greatly.
<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">As a toy project, I'm attempting to catch an exception that's thrown in a Windows x64 C++ library call from within an LLVM x64 MCJIT instance. The version I'm working with is LLVM 3.8.1, and the code I've created is based
 on the documentation <a href="http://llvm.org/docs/ExceptionHandling.html" target="_blank">http://llvm.org/docs/<wbr>ExceptionHandling.html</a> . I've also been reading up on the Exception toy/example code that's shipped with LLVM, as well as several mail discussions, the CGException class from clang and of course the ever useful 'clang
 --emit-llvm'. My aim here is to create a minimum working test case.<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">My first attempt was to simply compile a piece of C++ code with an external function call and run that through LLC. The code is pretty straight-forward:<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">--<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">extern "C++" void Test2();<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">int Foo()<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">{<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">                try<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">                {<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">                               Test2();<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">                               return 1;<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">                }<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">                catch (...)<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">                {<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">                               return 0;<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">                }<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">}<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">--<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">My first attempt was to run LLC to simply create the code for me. Basically the steps I took were:<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">- clang -std=c++14 -O3 -emit-llvm -S -fexceptions -fms-compatibility -fcxx-exceptions test.cpp<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">- llc -march=cpp -o test_exceptions.cpp test.ll<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">Unfortunately this won't work; LLC doesn't seem to support this and will exit with an error: 'LLVM ERROR: Bad constant'.<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">My second attempt was to simply create the CPP code myself and emit the same IR code that clang has so gracefully provided me. The complete code of a self-contained minimum test case can be found at <a href="http://stackoverflow.com/questions/39224636/llvm-mcjit-seh-exception-handling" target="_blank">http://stackoverflow.com/<wbr>questions/39224636/llvm-mcjit-<wbr>seh-exception-handling</a>
 . However, when I try to run that code, the exception seems to corrupt the stack and the Visual Studio debugger will abort the execution with "Stack cookie instrumentation code detected a stack-based buffer overrun.".
<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">Currently I'm a bit lost what to try next. At this point I’m not even sure if this behavior is to be expected or not. I’m by no means an expert on SEH exception handling, so any help or advice would be very much appreciated.<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal">Kind regards,<u></u><u></u></p>
<p class="MsoNormal">Stefan.<u></u><u></u></p>
</div>
</div>

<br>______________________________<wbr>_________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br>
<br></blockquote></div><br></div>