<div dir="ltr">In r<span style="font-size:13px">234975 I</span> fixed an issue where we were failing to emit the eh_frame for JIT'd code on MacOS. It may have fixed this problem.<div><br></div><div>- Lang.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Mar 24, 2015 at 10:16 AM, Jonathan Roelofs <span dir="ltr"><<a href="mailto:jonathan@codesourcery.com" target="_blank">jonathan@codesourcery.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><br>
<br>
On 3/24/15 10:32 AM, Reid Kleckner wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I haven't dug into your example, but I would say exceptions don't work<br>
on Windows yet.<br>
<br>
I don't know why it doesn't work on Mac.<br>
</blockquote>
<br></span>
The symptoms look like what happens when you have two copies of the rtti each in different SOs. If that's the problem, then throwing from one SO and trying to catch in the other will terminate this way when the first's typeinfos don't match against any in the second.<br>
<br>
I don't know the JIT well at all, but I'd suggest printing out the address of the type info for int, _ZTIi, and check that they're the same in both the JIT-ee and the JIT-er.<br>
<br>
<br>
Jon<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">
<br>
On Fri, Mar 20, 2015 at 9:33 AM, Anil Can Akay <<a href="mailto:anilck@gmail.com" target="_blank">anilck@gmail.com</a><br></span><div><div class="h5">
<mailto:<a href="mailto:anilck@gmail.com" target="_blank">anilck@gmail.com</a>>> wrote:<br>
<br>
    Hi,<br>
<br>
    I am trying to implement a scenario similar to running<br>
    ExceptionDemo.cpp with parameter -1 (where the JITed code calls the<br>
    C++ function which throws an exception)<br>
<br>
    Different from the given example I am using IRParser instead of<br>
    IRBuilder. I can successfully catch the exception in Linux but the<br>
    program crashes in Mac and Windows.<br>
<br>
    The code is similar to as follows:<br>
<br>
    ### The test.cpp : (clang++ -O0 -S -emit-llvm test.cpp –c)<br>
<br>
    extern void test() ;<br>
<br>
    extern "C" void exec(void*) {<br>
<br>
    test();<br>
<br>
    }<br>
<br>
    ### main.cpp<br>
<br>
    // necessary includes here....<br>
<br>
    static void test() {<br>
<br>
    throw 1;<br>
<br>
    }<br>
<br>
    int main(int, const char **) {<br>
<br>
    llvm::InitializeNativeTarget();<br>
<br>
    llvm::InitializeNativeTargetAsmPrinter();<br>
<br>
    llvm::InitializeNativeTargetAsmParser();<br>
<br>
    llvm::LLVMContext &Context = llvm::getGlobalContext();<br>
<br>
    llvm::SMDiagnostic Err;<br>
<br>
    std::unique_ptr<llvm::Module> Mod = llvm::parseIRFile("test.ll",<br>
    Err, Context);<br>
<br>
         std::string triple = llvm::sys::getProcessTriple();<br>
<br>
         Mod->setTargetTriple(triple);<br>
<br>
    llvm::Function* f = Mod->getFunction("exec");<br>
<br>
    llvm::TargetOptions Opts;<br>
<br>
         Opts.NoFramePointerElim = true;<br>
<br>
    // Build engine with JIT<br>
<br>
    std::unique_ptr<llvm::RTDyldMemoryManager> MemMgr(new<br>
    llvm::SectionMemoryManager());<br>
<br>
    std::string err;<br>
<br>
    llvm::EngineBuilder factory(std::move(Mod));<br>
<br>
    factory.setErrorStr(&err);<br>
<br>
    factory.setEngineKind(llvm::EngineKind::JIT);<br>
<br>
    factory.setTargetOptions(Opts);<br>
<br>
    factory.setMCJITMemoryManager(std::move(MemMgr));<br>
<br>
    llvm::ExecutionEngine* EE = factory.create();<br>
<br>
    llvm::sys::DynamicLibrary::AddSymbol("_Z4testv",<br>
    reinterpret_cast<void*>(test));<br>
<br>
    EE->finalizeObject();<br>
<br>
    void* poi = EE->getPointerToFunction(f);<br>
<br>
    void (*exec)(void*) = reinterpret_cast<void (*)(void*)>(poi);<br>
<br>
    try {<br>
<br>
    exec(NULL);<br>
<br>
    } catch (int e) {<br>
<br>
    std::cout << "catched " << e << std::endl;<br>
<br>
    }<br>
<br>
    return 0;<br>
<br>
    }<br>
<br>
    ###<br>
<br>
    Crash like below:<br>
<br>
    libc++abi.dylib: terminating with uncaught exception of type int<br>
<br>
    [1] 15639 abort (core dumped)  ./main<br>
<br>
    What can be the reason for the different behaviour in different<br>
    platforms? In order to make it work, do I need to wrap the<br>
    llvm::Function* f with the unwindResume and externalException blocks<br>
    ? Any other suggestions ? By the way I use LLVM 3.6.0 compiled with<br>
    LLVM_ENABLE_EH and RTTI enabled.<br>
<br>
    Thanks in advance for your help.<br>
<br>
<br>
    _______________________________________________<br>
    LLVM Developers mailing list<br></div></div>
    <a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a> <mailto:<a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a>> <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><span class=""><br>
    <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
<br>
<br>
<br>
<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
<br>
</span></blockquote><span class="HOEnZb"><font color="#888888">
<br>
-- <br>
Jon Roelofs<br>
<a href="mailto:jonathan@codesourcery.com" target="_blank">jonathan@codesourcery.com</a><br>
CodeSourcery / Mentor Embedded</font></span><div class="HOEnZb"><div class="h5"><br>
<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
</div></div></blockquote></div><br></div>