<div dir="ltr"><div dir="ltr">Hi Ladybug,<div><br></div><div>Is this on Linux? With LLVM top-of-tree, or a release branch? Are you able to get a backtrace of the crash?</div><div><br></div><div>There are a couple of issues that I can see by inspection:</div><div><br></div><div>(1) You will want to remove the call to LLVMOrcGetSymbolAddress from your sym_resolver function: In the ORC C API resolvers are only used to resolve external symbols (i.e. ones not defined in the JIT'd code). So in your case, given that you *only* searched the JIT, I think you can define this function to just return zero, meaning JIT'd code can't call external functions.</div><div><br></div><div>(2) You should remove the call to LLVMDisposeModule at the end of main. LLVMOrcAddLazilyCompiledIR takes ownership of the module (my bad: this should be documented in the comments.) and will manage its lifetime for you.</div><div><br></div><div>(3) You should not need to mangle the symbol you pass to LLVMOrcGetMangledSymbol. That function will mangle it for you.</div><div><br></div><div>None of these explain your crash in LLVMOrcAddLazilyCompiledIR though, so I will need enough information to reproduce the crash before I can explain that.<br></div><div><br></div><div>A heads up too: the current C API is not well maintained (as you've discovered). The reason is that the underlying C++ APIs have undergone a big redesign to support concurrent compilation, but the C API has not caught up yet. We definitely want to update the C API, but I don't have a timeline for it yet. Patches very welcome if you are interested in getting involved!</div><div><br></div><div>Cheers,</div><div>Lang.</div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Feb 26, 2019 at 11:42 AM Ladybug . via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">Hello, I've been trying to use LLVM's Orc JIT from C API for a few days and i can't get it to work, I'm kind of annoyed for the lack of documentation examples for the C API.<div><br></div><div>Here's my code: <a href="https://hasteb.in/ohexiweb.cpp" target="_blank">https://hasteb.in/ohexiweb.cpp</a></div><div><br></div><div>I compile it using</div><div><br></div><div>clang `llvm-config --cflags --ldflags --libs all` main.c -o main -g -rdynamic</div><div><br></div><div>And it ends up segfaulting at the line where it calls LLVMOrcAddLazilyCompiledIR</div><div><br></div><div>I can do a similar example with MCJIT just fine but i need to use lazy compiling here.</div><div><br></div><div>Could anyone point out the mistakes in my code or give me a full example of properly using Orc JIT from the C API, Thanks.</div>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div>