<div dir="ltr"><a class="gmail_plusreply" id="plusReplyChip-2" href="mailto:lhames@gmail.com" tabindex="-1">+Lang Hames</a> owner/author of the ORC JIT (though I think he's out of office at the moment, so replies from him might be delayed).<br><br>I believe there's a way to wire up the global ctors, but I don't know the details unfortunately - perhaps someone else will chime in if/before Lang gets a chance.</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Dec 19, 2019 at 5:53 AM Gaier, Bjoern via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div lang="DE">
<div class="gmail-m_-3650128240603158513WordSection1">
<p class="MsoNormal"><span lang="EN-GB">Heyho,<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-GB"><u></u> <u></u></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.<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-GB"><u></u> <u></u></span></p>
<p class="MsoNormal"><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();<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black"><u></u> <u></u></span></p>
<p class="MsoNormal"><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()<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black">{<u></u><u></u></span></p>
<p class="MsoNormal"><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:rgb(163,21,21)">"Huhuhu"</span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black">);<u></u><u></u></span></p>
<p class="MsoNormal"><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();<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black">}<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black"><u></u> <u></u></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();<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-GB"><u></u> <u></u></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:<u></u><u></u></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.<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-GB"><u></u> <u></u></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.<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-GB">So I tried a different way:<u></u><u></u></span></p>
<p class="MsoNormal"><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:rgb(43,145,175)">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:rgb(163,21,21)">"llvm.global_ctors"</span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black">);<u></u><u></u></span></p>
<p class="MsoNormal"><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)<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black">{<u></u><u></u></span></p>
<p class="MsoNormal"><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:rgb(43,145,175)">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:rgb(43,145,175)">ConstantArray</span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black">*)var->getInitializer();<u></u><u></u></span></p>
<p class="MsoNormal"><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++)<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black"> {<u></u><u></u></span></p>
<p class="MsoNormal"><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:rgb(43,145,175)">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:rgb(43,145,175)">ConstantStruct</span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black">*)InitList->getOperand(n);<u></u><u></u></span></p>
<p class="MsoNormal"><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)<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black"> {<u></u><u></u></span></p>
<p class="MsoNormal"><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">;<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black"> }<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black"><u></u> <u></u></span></p>
<p class="MsoNormal"><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:rgb(43,145,175)">Constant</span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black">
*FP = CS->getOperand(1);<u></u><u></u></span></p>
<p class="MsoNormal"><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())<u></u><u></u></span></p>
<p class="MsoNormal"><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">;<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black"><u></u> <u></u></span></p>
<p class="MsoNormal"><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:rgb(43,145,175)">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:rgb(43,145,175)">ConstantExpr</span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black">*)FP;<u></u><u></u></span></p>
<p class="MsoNormal"><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())<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black"> {<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black"> FP = CE->getOperand(0);<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black"> }<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black"><u></u> <u></u></span></p>
<p class="MsoNormal"><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:rgb(43,145,175)">Function</span><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black">*)FP)->getName();<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black"> }<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:9.5pt;font-family:Consolas;color:black">}</span><span lang="EN-GB"><u></u><u></u></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.
<u></u><u></u></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.<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-GB"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-GB">I hope someone can help me with this…<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-GB"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-GB">Kind Greetings<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-GB">Björn<u></u><u></u></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
</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>