<html>
  <head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    For catching the exception you may use VEH as a fallback on Windows
    as discussed earlier this year:<br>
    <a class="moz-txt-link-freetext" href="http://lists.llvm.org/pipermail/llvm-dev/2016-June/100902.html">http://lists.llvm.org/pipermail/llvm-dev/2016-June/100902.html</a><br>
<a class="moz-txt-link-freetext" href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms681411(v=vs.85).aspx">https://msdn.microsoft.com/en-us/library/windows/desktop/ms681411(v=vs.85).aspx</a><br>
    <br>
    So far that worked for me. The problem was that I could not manage
    to escape from this handler and resume execution, because
    setjmp/longjmp didn't to work (fails with an exception and re-enters
    the VEH handler). However, there seems to be some magic behind, as
    it sometimes works with trivial examples.<br>
    <br>
    Thanks Reid for pointing to the bug. It explains most of it.<br>
    <br>
    <div class="moz-cite-prefix">Am 07.09.16 um 18:37 schrieb Reid
      Kleckner via llvm-dev:<br>
    </div>
    <blockquote
cite="mid:CACs=ty+s1+OfYJjw0XMdHjgcXzuLSoxChQy=Sp9ogujofgKicg@mail.gmail.com"
      type="cite">
      <div dir="ltr">Someone needs to implement <a
          moz-do-not-send="true"
          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
              moz-do-not-send="true"
              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 link="#0563C1" vlink="#954F72" lang="NL">
              <div class="m_-2792294432728419895WordSection1">
                <p class="MsoNormal"><span lang="EN-US">Hi,</span></p>
                <p class="MsoNormal"><span lang="EN-US"> </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.</span></p>
                <p class="MsoNormal"><span lang="EN-US"> </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.
                  </span></p>
                <p class="MsoNormal"><span lang="EN-US"> </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
                      moz-do-not-send="true"
                      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.</span></p>
                <p class="MsoNormal"><span lang="EN-US"> </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:</span></p>
                <p class="MsoNormal"><span lang="EN-US"> </span></p>
                <p class="MsoNormal"><span lang="EN-US">--</span></p>
                <p class="MsoNormal"><span lang="EN-US">extern "C++"
                    void Test2();</span></p>
                <p class="MsoNormal"><span lang="EN-US"> </span></p>
                <p class="MsoNormal"><span lang="EN-US">int Foo()</span></p>
                <p class="MsoNormal"><span lang="EN-US">{</span></p>
                <p class="MsoNormal"><span lang="EN-US">               
                    try</span></p>
                <p class="MsoNormal"><span lang="EN-US">               
                    {</span></p>
                <p class="MsoNormal"><span lang="EN-US">                              
                    Test2();</span></p>
                <p class="MsoNormal"><span lang="EN-US">                              
                    return 1;</span></p>
                <p class="MsoNormal"><span lang="EN-US">               
                    }</span></p>
                <p class="MsoNormal"><span lang="EN-US">               
                    catch (...)</span></p>
                <p class="MsoNormal"><span lang="EN-US">               
                    {</span></p>
                <p class="MsoNormal"><span lang="EN-US">                              
                    return 0;</span></p>
                <p class="MsoNormal"><span lang="EN-US">               
                    }</span></p>
                <p class="MsoNormal"><span lang="EN-US">}</span></p>
                <p class="MsoNormal"><span lang="EN-US">--</span></p>
                <p class="MsoNormal"><span lang="EN-US"> </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:</span></p>
                <p class="MsoNormal"><span lang="EN-US"> </span></p>
                <p class="MsoNormal"><span lang="EN-US">- clang
                    -std=c++14 -O3 -emit-llvm -S -fexceptions
                    -fms-compatibility -fcxx-exceptions test.cpp</span></p>
                <p class="MsoNormal"><span lang="EN-US">- llc -march=cpp
                    -o test_exceptions.cpp test.ll</span></p>
                <p class="MsoNormal"><span lang="EN-US"> </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'.</span></p>
                <p class="MsoNormal"><span lang="EN-US"> </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
                      moz-do-not-send="true"
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.".
                  </span></p>
                <p class="MsoNormal"><span lang="EN-US"> </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.</span></p>
                <p class="MsoNormal"><span lang="EN-US"> </span></p>
                <p class="MsoNormal">Kind regards,</p>
                <p class="MsoNormal">Stefan.</p>
              </div>
            </div>
            <br>
            ______________________________<wbr>_________________<br>
            LLVM Developers mailing list<br>
            <a moz-do-not-send="true"
              href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
            <a moz-do-not-send="true"
              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>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
LLVM Developers mailing list
<a class="moz-txt-link-abbreviated" href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>
<a class="moz-txt-link-freetext" href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a>
</pre>
    </blockquote>
    <br>
    <pre class="moz-signature" cols="72">-- 
<a class="moz-txt-link-freetext" href="https://about.me/stefan.graenitz">https://about.me/stefan.graenitz</a></pre>
  </body>
</html>