<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:Tahoma;
panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
span.hoenzb
{mso-style-name:hoenzb;}
span.EmailStyle18
{mso-style-type:personal-reply;
font-family:"Calibri","sans-serif";
color:#1F497D;}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri","sans-serif";}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Hi Konstantin,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Which additional functions did you need to get this to work beyond the ones listed in your original message?<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Thanks,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Andy<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> llvmdev-bounces@cs.uiuc.edu [mailto:llvmdev-bounces@cs.uiuc.edu]
<b>On Behalf Of </b>Konstantin Olkhovskiy<br>
<b>Sent:</b> Sunday, September 22, 2013 2:47 AM<br>
<b>To:</b> llvmdev@cs.uiuc.edu<br>
<b>Subject:</b> Re: [LLVMdev] Bad permissions for mapped region<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">I managed to make it work by cloning code from lli and making my own cpp wrapper.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><o:p> </o:p></p>
<div>
<p class="MsoNormal">2013/9/22 Konstantin Olkhovskiy <<a href="mailto:lupus@oxnull.net" target="_blank">lupus@oxnull.net</a>><o:p></o:p></p>
<div>
<p class="MsoNormal">Hi List,<o:p></o:p></p>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">I'm trying to upgrade our llvm-c based compiler from JIT to MCJIT.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">While trying to do so I encountered several problems. Looks like C<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">API does not have proper functions to intialize LLVM with MCJIT.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">I ended up wrapping the following functions in my own init routine.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<div>
<p class="MsoNormal">LLVMInitializeX86TargetInfo();<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">LLVMInitializeX86Target();<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">LLVMInitializeX86TargetMC();<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">LLVMInitializeX86AsmPrinter();<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">LLVMInitializeX86AsmParser();<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">With this set of functions it attempts to JIT something at least.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">I run into a segfault, valgrind reports the following:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<div>
<p class="MsoNormal">==27130== Process terminating with default action of signal 11 (SIGSEGV)<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">==27130== Bad permissions for mapped region at address 0xEAF02F7<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">==27130== at 0xEAF031F: llvm::RuntimeDyldELF::resolveX86_64Relocation(llvm::SectionEntry const&, unsigned long, unsigned long, unsigned int, long, unsigned long) (RuntimeDyldELF.cpp:213)<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">==27130== by 0xEAF260F: llvm::RuntimeDyldELF::resolveRelocation(llvm::SectionEntry const&, unsigned long, unsigned long, unsigned int, long, unsigned long) (RuntimeDyldELF.cpp:798)<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">==27130== by 0xEAF258F: llvm::RuntimeDyldELF::resolveRelocation(llvm::RelocationEntry const&, unsigned long) (RuntimeDyldELF.cpp:787)<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">==27130== by 0xEAE7C67: llvm::RuntimeDyldImpl::resolveRelocationList(llvm::SmallVector<llvm::RelocationEntry, 64u> const&, unsigned long) (RuntimeDyld.cpp:462)<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">==27130== by 0xEAE543C: llvm::RuntimeDyldImpl::resolveRelocations() (RuntimeDyld.cpp:51)<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">==27130== by 0xEAE8236: llvm::RuntimeDyld::resolveRelocations() (RuntimeDyld.cpp:561)<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">==27130== by 0xA25EA99: llvm::MCJIT::finalizeObject() (MCJIT.cpp:173)<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">==27130== by 0xAB57918: LLVMGetPointerToGlobal (ExecutionEngineBindings.cpp:332)<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">==27130== by 0x4E4813D: compile_query (ql.c:2286)<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">==27130== by 0x4E4836A: tusto_ql_compile (ql.c:2322)<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">==27130== by 0x402D19: process_query (ts_util.c:167)<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">==27130== by 0x403205: run_shell (ts_util.c:296)<o:p></o:p></p>
</div>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">I have source tree checked out at f46e5eadc307beaef6e8dd0602bb4c63ca41fd50.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">To create MCJIT i use provided llvm-c apis:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<div>
<p class="MsoNormal">LLVMInitializeMCJITCompilerOptions(&options, sizeof(options));<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">options.OptLevel = MODULE_OPT_LEVEL; /* 3 of 0 */<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">options.CodeModel = LLVMCodeModelJITDefault;<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">if (LLVMCreateMCJITCompilerForModule(&qry->llvm.engine, qry->llvm.mod,<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">&options, sizeof(options), &error) != 0) {<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">fprintf(stderr, "%s\n", error);<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">LLVMDisposeMessage(error);<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">abort();<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">}<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">LLVMRunStaticConstructors(qry->llvm.engine);<o:p></o:p></p>
</div>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Then I do the IR building and get the function pointer i need:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">iter->run = LLVMGetPointerToGlobal(qry->llvm.engine, func_ref);<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Am i doing something wrong?<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Thanks<o:p></o:p></p>
</div>
<p class="MsoNormal"><span class="hoenzb"><span style="color:#888888">-- <o:p></o:p></span></span></p>
<div>
<p class="MsoNormal"><span style="color:#888888">Regards,</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="color:#888888">Konstantin<o:p></o:p></span></p>
</div>
</div>
</div>
</div>
<p class="MsoNormal"><br>
<br clear="all">
<o:p></o:p></p>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<p class="MsoNormal">-- <o:p></o:p></p>
<div>
<p class="MsoNormal">Regards,<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">Konstantin<o:p></o:p></p>
</div>
</div>
</div>
</body>
</html>