<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=iso-8859-1">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:Consolas;
panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;
mso-fareast-language:EN-US;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:#0563C1;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:#954F72;
text-decoration:underline;}
span.EmailStyle17
{mso-style-type:personal-compose;
font-family:"Calibri",sans-serif;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri",sans-serif;
mso-fareast-language:EN-US;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:70.85pt 70.85pt 2.0cm 70.85pt;}
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="DE" link="#0563C1" vlink="#954F72">
<div class="WordSection1">
<p class="MsoNormal"><span lang="EN-GB">Heyho,<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">Recently I tried out the ORCv2 JIT, especially the LLJIT. I gotta say, that I really like the new interface and the way you use it! However there is one thing I’m missing. I wrote a small bit code file, which should force
having a global constructor.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:blue">int</span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black"> wuff();<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black"><o:p> </o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:blue">__declspec</span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black">(</span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:blue">noinline</span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black">)
</span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:blue">int</span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black"> miau()<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black">{<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black"> printf(</span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:#A31515">"Huhuhu"</span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black">);<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black">
</span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:blue">return</span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black"> wuff();<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black">}<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:blue">const</span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black">
</span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:blue">int</span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black"> x = miau();<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">When I parse this IR file in my JIT and go through the ‘globals()’ of the llvm::Module, then I will encounter a symbol with the following name:<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">“_GLOBAL__sub_I_VectorBIOS.cpp” where VectorBIOS.cpp was the name of the source file I compiled to the bit code.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">I then wanted to get the address of that symbol - from the MCJIT times I remember, that those functions are the global constructors, but when calling lookup on that name, I was not able to find the symbol.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">So I tried a different way:<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black">llvm::</span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:#2B91AF">GlobalVariable</span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black">
*var = </span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:gray">module</span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:teal">-></span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black">getNamedGlobal(</span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:#A31515">"llvm.global_ctors"</span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black">);<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:blue">if</span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black">(var)<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black">{<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black"> llvm::</span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:#2B91AF">ConstantArray</span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black">
*InitList = (llvm::</span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:#2B91AF">ConstantArray</span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black">*)var->getInitializer();<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black">
</span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:blue">for</span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black">(</span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:blue">unsigned</span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black">
</span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:blue">int</span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black"> n = 0; n < InitList->getNumOperands(); n++)<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black"> {<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black"> llvm::</span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:#2B91AF">ConstantStruct</span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black">
*CS = (llvm::</span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:#2B91AF">ConstantStruct</span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black">*)InitList->getOperand(n);<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black">
</span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:blue">if</span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black">(!CS)<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black"> {<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black">
</span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:blue">continue</span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black">;<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black"> }<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black"><o:p> </o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black"> llvm::</span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:#2B91AF">Constant</span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black">
*FP = CS->getOperand(1);<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black">
</span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:blue">if</span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black">(FP->isNullValue())<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black">
</span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:blue">continue</span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black">;<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black"><o:p> </o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black"> llvm::</span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:#2B91AF">ConstantExpr</span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black">
*CE = (llvm::</span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:#2B91AF">ConstantExpr</span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black">*)FP;<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black">
</span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:blue">if</span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black">(CE->isCast())<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black"> {<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black"> FP = CE->getOperand(0);<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black"> }<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black"><o:p> </o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black"> ((llvm::</span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:#2B91AF">Function</span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black">*)FP)->getName();<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black"> }<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black">}</span><span lang="EN-GB"><o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">I then printed the name of the llvm::Function but it was exactly the name I expected “_GLOBAL__sub_I_VectorBIOS.cpp”. This code was executed before I added module to the JIT.
<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">For various reasons I wanted to store the address to the constructor – so I don’t want to call the LLJIT runConstructor – simply because I want to execute those functions later, when the LLJIT does not exist anymore.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">I hope someone can help me with this…<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">Kind Greetings<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">Björn<o:p></o:p></span></p>
</div>
Als GmbH eingetragen im Handelsregister Bad Homburg v.d.H. HRB 9816, USt.ID-Nr. DE 114 165 789 Geschäftsführer: Dr. Hiroshi Nakamura, Dr. Robert Plank, Markus Bode, Heiko Lampert, Takashi Nagano, Takeshi Fukushima. Junichi Tajika
</body>
</html>