<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;background-color:#FFFFFF;font-family:Calibri,Arial,Helvetica,sans-serif;">
<p>Thanks a million!</p>
<p>I've finally went to the object file containing foo function and using objdump tool I found the exact used name in its symbol table. Using this mangled name in my pass, solved the resolve issue and my foo function is finally called correctly.</p>
<p><br>
</p>
<div id="Signature">
<div id="divtagdefaultwrapper" style="font-size:12pt; color:#000000; background-color:#FFFFFF; font-family:Calibri,Arial,Helvetica,sans-serif">
<div class="BodyFragment"><font size="2"><span style="font-size:10pt">
<div class="PlainText">Regards,<br>
Marwa Yusuf<br>
Teaching Assistant - Computer Engineering Department<br>
Faculty of Engineering - Benha University<br>
E-JUST PhD Student<br>
Computer Science & Engineering Dept.</div>
</span></font></div>
</div>
</div>
<br>
<br>
<div style="color: rgb(0, 0, 0);">
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>From:</b> mats.o.petersson@googlemail.com <mats.o.petersson@googlemail.com> on behalf of mats petersson <mats@planetcatfish.com><br>
<b>Sent:</b> Wednesday, September 2, 2015 4:36 PM<br>
<b>To:</b> marwayusuf@feng.bu.edu.eg<br>
<b>Cc:</b> llvm-dev<br>
<b>Subject:</b> Re: [llvm-dev] creating a callinst to an external function</font>
<div> </div>
</div>
<div>
<div dir="ltr">
<div>If you look at the computer output of the file that provides the function `myclass::foo` (-S -emit-llvm if you use clang), you should see that the name of the function (probably) isn't `foo`. You need to precisely match the name between the caller and
 the actual function. <br>
<br>
--<br>
</div>
Mats<br>
<div><br>
<br>
</div>
</div>
<div class="gmail_extra"><br>
<div class="gmail_quote">On 2 September 2015 at 15:17, <a href="mailto:marwayusuf@feng.bu.edu.eg">
marwayusuf@feng.bu.edu.eg</a> via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex; border-left:1px #ccc solid; padding-left:1ex">
<div dir="ltr">
<div style="font-size:12pt; color:#000000; background-color:#ffffff; font-family:Calibri,Arial,Helvetica,sans-serif">
<p>I tried to remove parameters from the called function "foo". So I got a different error.</p>
<p>LLVM ERROR: Program used external function 'foo' which could not be resolved!<br>
</p>
<p>Any help?</p>
<span class="">
<p><br>
</p>
<div>
<div style="font-size:12pt; color:#000000; background-color:#ffffff; font-family:Calibri,Arial,Helvetica,sans-serif">
<div><font size="2"><span style="font-size:10pt">
<div>Regards,<br>
Marwa Yusuf<br>
Teaching Assistant - Computer Engineering Department<br>
Faculty of Engineering - Benha University<br>
E-JUST PhD Student<br>
Computer Science & Engineering Dept.</div>
</span></font></div>
</div>
</div>
<br>
<br>
</span>
<div style="color:rgb(0,0,0)">
<hr style="display:inline-block; width:98%">
<div dir="ltr"><font color="#000000" face="Calibri, sans-serif" style="font-size:11pt"><b>From:</b> llvm-dev <<a href="mailto:llvm-dev-bounces@lists.llvm.org" target="_blank">llvm-dev-bounces@lists.llvm.org</a>> on behalf of
<a href="mailto:marwayusuf@feng.bu.edu.eg" target="_blank">marwayusuf@feng.bu.edu.eg</a> via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>><br>
<b>Sent:</b> Thursday, August 20, 2015 12:42 AM<br>
<b>To:</b> <a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<b>Subject:</b> [llvm-dev] creating a callinst to an external function</font>
<div> </div>
</div>
<div>
<div class="h5">
<div>
<div style="font-size:12pt; color:#000000; background-color:#ffffff; font-family:Calibri,Arial,Helvetica,sans-serif">
<p>Dear All</p>
<p>I'm making an instrumentation pass. The pass is supposed to modify the given IR in a specefic way. One of the required modifications is to insert a call to a function at a specific location. </p>
<p>This is the signature of the called function:</p>
<p>      void myclass::foo(Function *f, BasicBlock* b)</p>
<p>This function's prototype is in an foofile.h file in include/llvm</p>
<p>And the function definition is in foofile.cpp file in the MCJIT folder.</p>
<p>and running "make" at this folder works fine and the foofile.cpp is compiled with MCJIT.cpp and another function in the same file works just fine as expected.</p>
<p>Not back to the instrumentation pass. How can I insert a callinst to the foo function in the given IR?</p>
<p>Here is the snippet that inserts the call:</p>
<p>           Type* retTy = Type::getInt32Ty(C);</p>
<p>            FunctionType* FuncTy = FunctionType::get(retTy, false);</p>
<p>            PointerType* PtrToFuncTy = PointerType::get(FuncTy, 0);</p>
<p></p>
<p>            Constant *fun = M->getOrInsertFunction("foo", Type::getVoidTy(C), PtrToFuncTy, Type::getLabelTy(C), nullptr);</p>
<p></p>
<p>            Function *dofoo = cast<Function>(fun);</p>
<p>            Instruction* dofooCall = CallInst::Create(fun, Args2, "", bb);</p>
<p><br>
</p>
<p>Note: Args2 is an arraylist containing 2 value pointers to a function and a basicblock, bb is the basicblock to insert the call in.</p>
<p><br>
</p>
<p>When I run the pass using op on a given IR, it produces a declaration and a call correctly like this:</p>
<p> declaration:       declare void @foo(i32 ()*, label)</p>
<p> call:                   call void @foo(i32 ()* @main, label %for.cond)</p>
<p>But when I try to run the resulting .ll file using lli, everything explodes! This the first 2 lines before the stacktrace:</p>
<p>    Can't get register for value!</p>
<p>    UNREACHABLE executed at /home/marwayusuf/llvm-env/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp:1158!</p>
<p> </p>
<p>I concluded that the problem is it can't find the foo function. If this is the problem, how can I create the callinst correctly?</p>
<p>     </p>
<p><br>
</p>
<div>
<div style="font-size:12pt; color:#000000; background-color:#ffffff; font-family:Calibri,Arial,Helvetica,sans-serif">
<div><font size="2"><span style="font-size:10pt">
<div>Regards,<br>
Marwa Yusuf<br>
Teaching Assistant - Computer Engineering Department<br>
Faculty of Engineering - Benha University<br>
E-JUST PhD Student<br>
Computer Science & Engineering Dept.</div>
</span></font></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
<br>
</blockquote>
</div>
<br>
</div>
</div>
</div>
</div>
</body>
</html>