<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<p>Hi Yafei<br>
<br>
What JIT backend do you use in lli? The default is still MCJIT!<br>
<a class="moz-txt-link-freetext" href="https://github.com/llvm/llvm-project/blob/13bdae8541c3/llvm/tools/lli/lli.cpp#L88">https://github.com/llvm/llvm-project/blob/13bdae8541c3/llvm/tools/lli/lli.cpp#L88</a><br>
<br>
I think -jit-kind=orc-lazy gives ORCv2 behavior.<br>
<br>
Cheers<br>
<br>
On 19/09/2019 14:02, Yafei Liu via llvm-dev wrote:<br>
</p>
<blockquote type="cite"
cite="mid:CAMUQRet=0GGVcgJy0QANYLLNyvM35=n18JK9V_TnvH7bO9+42w@mail.gmail.com">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<div dir="ltr">
<div>Hi, I wrote a compiler that generate IR code and run it on
the JIT, and there randomly crashed due to "corrupted size vs.
prev_size" depends on the IR code generated from the source
code.
<div><br>
</div>
<div>Here's how I created the JIT:</div>
<div><br>
</div>
<div><br>
</div>
</div>
<blockquote style="margin:0 0 0 40px;border:none;padding:0px">
<div>
<div>llvm::InitializeNativeTarget();</div>
</div>
<div>
<div> llvm::InitializeNativeTargetAsmPrinter();</div>
</div>
<div>
<div> llvm::InitializeNativeTargetAsmParser();</div>
</div>
<div>
<div> // create jit</div>
</div>
<div>
<div> llvm::orc::ExecutionSession ES;</div>
</div>
<div>
<div> llvm::orc::RTDyldObjectLinkingLayer ObjectLayer(ES,</div>
</div>
<div>
<div> []()
{ return
std::make_unique<llvm::SectionMemoryManager>(); });</div>
</div>
<div>
<div> auto JTMB =
llvm::orc::JITTargetMachineBuilder::detectHost();</div>
</div>
<div>
<div> auto DL = JTMB->getDefaultDataLayoutForTarget();</div>
</div>
<div>
<div> llvm::orc::IRCompileLayer CompileLayer(ES,
ObjectLayer,
llvm::orc::ConcurrentIRCompiler(std::move(*JTMB)));</div>
</div>
<div>
<div> llvm::orc::MangleAndInterner Mangle(ES, *DL);</div>
</div>
<div>
<div> ES.getMainJITDylib().setGenerator(</div>
</div>
<div>
<div>
llvm::cantFail(llvm::orc::DynamicLibrarySearchGenerator::GetForCurrentProcess(*DL)));</div>
</div>
<div>
<div><br>
</div>
</div>
<div>
<div>// ... large part to generate IR code</div>
</div>
<div>
<div>.</div>
</div>
<div>
<div><br>
</div>
</div>
<div>
<div> if (llvm::verifyModule(*AST::getModule(),
&llvm::errs())) {</div>
</div>
<div>
<div> return 0;</div>
</div>
<div>
<div> } else {</div>
</div>
<div>
<div> std::cout << "Verified success\n";</div>
</div>
<div>
<div> }</div>
</div>
<div>
<div><br>
</div>
</div>
<div>
<div> // run the generated IR code</div>
</div>
<div>
<div> llvm::cantFail(CompileLayer.add(ES.getMainJITDylib(),</div>
</div>
<div>
<div>
llvm::orc::ThreadSafeModule(std::move(AST::takeModule()),</div>
</div>
<div>
<div>
AST::takeContext())));</div>
</div>
<div>
<div><br>
</div>
</div>
<div>
<div> auto symbol =
llvm::cantFail(ES.lookup({&ES.getMainJITDylib()},
Mangle("main")));</div>
</div>
<div>
<div><br>
</div>
</div>
<div>
<div> int (*entry)() = (decltype(entry))
symbol.getAddress();</div>
</div>
<div>
<div> std::cout << entry() << std::endl;</div>
</div>
</blockquote>
<div><br>
</div>
<div>and the "corrupted size vs. prev_size" will happen if the
IR code is this:<br>
<br>
</div>
<blockquote style="margin:0 0 0 40px;border:none;padding:0px">
<div>; ModuleID = 'top'</div>
<div>source_filename = "top"</div>
<div><br>
</div>
<div>@0 = global [3 x i32] [i32 1, i32 2, i32 3]</div>
<div><br>
</div>
<div>define i32 @main() {</div>
<div> %1 = alloca i32</div>
<div> store i32 0, i32* %1</div>
<div> br label %2</div>
<div><br>
</div>
<div>; <label>:2: ;
preds = %0</div>
<div> %3 = load i32, i32* %1</div>
<div> ret i32 %3</div>
<div>}</div>
</blockquote>
I put this IR code to lli, and it works fine.
<div><br>
</div>
<div>So any idea why I get "corrupted size vs. prev_size" when
calling calling ExecutionSession::lookup()?</div>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<pre class="moz-quote-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="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a>
</pre>
</blockquote>
<pre class="moz-signature" cols="72">--
<a class="moz-txt-link-freetext" href="https://flowcrypt.com/pub/stefan.graenitz@gmail.com">https://flowcrypt.com/pub/stefan.graenitz@gmail.com</a></pre>
</body>
</html>