<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
Hi Björn<br>
<br>
What does the IR code look like when you dump your module?<br>
llvm::outs() << mainModule;<br>
<br>
I guess for the external function "puts" it will have a declaration
like this:<br>
declare i32 @puts(i8*)<br>
<br>
When loading your module in the JIT, RuntimeDyld will resolve it to
an actual address. This lookup is done by name and it happens in a
stage called external symbol resolution. You should be able to
inspect how this works by setting a breakpoint here:<br>
<a class="moz-txt-link-freetext" href="https://github.com/llvm/llvm-project/blob/cce1c2eb0e87e84be6345c870d3334f748bdc5bb/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp#L1084">https://github.com/llvm/llvm-project/blob/cce1c2eb0e87e84be6345c870d3334f748bdc5bb/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp#L1084</a><br>
<br>
Hope it helps.<br>
Stefan<br>
<br>
<div class="moz-cite-prefix">Am 15.01.19 um 08:02 schrieb Gaier,
Bjoern via llvm-dev:<br>
</div>
<blockquote type="cite"
cite="mid:OSAPR01MB3171BFC2D6214F5EF02F92EDE2810@OSAPR01MB3171.jpnprd01.prod.outlook.com">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<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;}
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;}
p.msonormal0, li.msonormal0, div.msonormal0
{mso-style-name:msonormal;
mso-margin-top-alt:auto;
margin-right:0cm;
mso-margin-bottom-alt:auto;
margin-left:0cm;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
p.gmail-m3997524881775611987msolistparagraph, li.gmail-m3997524881775611987msolistparagraph, div.gmail-m3997524881775611987msolistparagraph
{mso-style-name:gmail-m_3997524881775611987msolistparagraph;
mso-margin-top-alt:auto;
margin-right:0cm;
mso-margin-bottom-alt:auto;
margin-left:0cm;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
span.EmailStyle19
{mso-style-type:personal-reply;
font-family:"Calibri",sans-serif;}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri",sans-serif;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:70.85pt 70.85pt 2.0cm 70.85pt;}
div.WordSection1
{page:WordSection1;}
/* List Definitions */
@list l0
{mso-list-id:239095895;
mso-list-template-ids:-566081794;}
@list l1
{mso-list-id:564027733;
mso-list-template-ids:-1927775990;}
ol
{margin-bottom:0cm;}
ul
{margin-bottom:0cm;}
--></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]-->
<div class="WordSection1">
<div>
<div>
<div>
<p class="MsoNormal">On Mon, Jan 14, 2019 at 3:21 AM
Gaier, Bjoern via llvm-dev <<a
href="mailto:llvm-dev@lists.llvm.org"
moz-do-not-send="true">llvm-dev@lists.llvm.org</a>>
wrote:<o:p></o:p></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC
1.0pt;padding:0cm 0cm 0cm
6.0pt;margin-left:4.8pt;margin-right:0cm">
<div>
<div>
<p class="MsoNormal"
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span
lang="DE">Hello LLVM-World,</span><o:p></o:p></p>
<p class="MsoNormal"
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span
lang="DE"> </span><o:p></o:p></p>
<p class="MsoNormal"
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">currently
I play around with a „llvm::Module” and an external
function defined there “puts”. Normally this
function gets resolved in the JIT-Process but I
wonder about two things:<o:p></o:p></p>
<p class="MsoNormal"
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
<ol start="1" type="1">
<li
class="gmail-m3997524881775611987msolistparagraph"
style="mso-list:l0 level1 lfo1">
Can I resolve the function already in this step? I
used “replaceAllUsesWith” and passed a
“llvm::ConstantInt” to the function. But this
didn’t worked.<o:p></o:p></li>
</ol>
</div>
</div>
</blockquote>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">I'm not sure if I followed correctly,
but you can't replace a function declaration with a
constant int. The value for the function will be used
(mostly) as an argument to the call instruction, which
won't really be able to operate on an int. It isn't
clear to me what you're trying to do exactly, replace
the call to puts with an indirect call to the pointer
value that correspond to puts in your current process?
You would need to at least cast this pointer value to
the right type, and use an indirect call.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span style="color:#4472C4">Hey
Mehdi,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#4472C4"><o:p> </o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span
style="color:#4472C4">I simply try overloading “puts”
with a custom address before I start the JIT process.
I want to replace the call to “puts” with my own
address. For a test purpose I tried this now:<br>
</span><span
style="font-size:9.5pt;font-family:Consolas;color:black">
mainModue->getFunction(</span><span
style="font-size:9.5pt;font-family:Consolas;color:#A31515">"puts"</span><span
style="font-size:9.5pt;font-family:Consolas;color:black">)->replaceAllUsesWith(<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span
style="font-size:9.5pt;font-family:Consolas;color:black">
llvm::</span><span
style="font-size:9.5pt;font-family:Consolas;color:#2B91AF">ConstantExpr</span><span
style="font-size:9.5pt;font-family:Consolas;color:black">::getPointerCast(<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span
style="font-size:9.5pt;font-family:Consolas;color:black">
llvm::</span><span
style="font-size:9.5pt;font-family:Consolas;color:#2B91AF">ConstantInt</span><span
style="font-size:9.5pt;font-family:Consolas;color:black">::get(llvm::</span><span
style="font-size:9.5pt;font-family:Consolas;color:#2B91AF">IntegerType</span><span
style="font-size:9.5pt;font-family:Consolas;color:black">::get(context,
64), 0xF),<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span
style="font-size:9.5pt;font-family:Consolas;color:black">
mainModue->getFunction(</span><span
style="font-size:9.5pt;font-family:Consolas;color:#A31515">"puts"</span><span
style="font-size:9.5pt;font-family:Consolas;color:black">)->getType()<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span
style="font-size:9.5pt;font-family:Consolas;color:black">
)<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:9.5pt;font-family:Consolas;color:black">
);</span><o:p></o:p></p>
<p class="MsoNormal"><span style="color:#4472C4">This code
will crash the application though. I know that 0xF is
not a correct address and that there can be stuff
optimized, but currently I just want to ‘see’ that
“puts” was overloaded with 0xF.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#4472C4"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#4472C4">Kind
greetings<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#4472C4">Björn<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Best,<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">Mehdi<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"> <o:p></o:p></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC
1.0pt;padding:0cm 0cm 0cm
6.0pt;margin-left:4.8pt;margin-right:0cm">
<div>
<div>
<ol start="1" type="1">
<li
class="gmail-m3997524881775611987msolistparagraph"
style="mso-list:l1 level1 lfo2">
<o:p> </o:p></li>
<li
class="gmail-m3997524881775611987msolistparagraph"
style="mso-list:l1 level1 lfo2">
What might happen if I have two modules and use
“replaceAllUsesWith” on a function of Module A,
passing a function of Module B.<o:p></o:p></li>
</ol>
<p class="MsoNormal"
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
<p class="MsoNormal"
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">Thank
you for the help in advance!<o:p></o:p></p>
<p class="MsoNormal"
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
<p class="MsoNormal"
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">Kind
greetings<o:p></o:p></p>
<p class="MsoNormal"
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">Björn<o:p></o:p></p>
</div>
<p class="MsoNormal">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
<o:p></o:p></p>
</div>
<p class="MsoNormal">_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank"
moz-do-not-send="true">llvm-dev@lists.llvm.org</a><br>
<a
href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev"
target="_blank" moz-do-not-send="true">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><o:p></o:p></p>
</blockquote>
</div>
</div>
</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
<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="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev">http://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://weliveindetail.github.io/blog/">https://weliveindetail.github.io/blog/</a>
<a class="moz-txt-link-freetext" href="https://cryptup.org/pub/stefan.graenitz@gmail.com">https://cryptup.org/pub/stefan.graenitz@gmail.com</a></pre>
</body>
</html>