<div style="line-height:1.7;color:#000000;font-size:14px;font-family:arial">Thanks for your reply!  I send the message to the mail list this time~<img src="http://mimg.163.com/jy3style/lib/htmlEditor/portrait/face/preview/face0.gif"><br><br>Did you mean I need to initialize M and 
the Context? Is that really necessary? Does all the function need to be wrapped in the module? I remember you once said "you can
 just declare the function (i.e. no need to give it a body), and call 
it.You can then link with an object file that defines it.  This is 
simpler than injecting the function into each module."  <br>I DEFINITELY GO FOR 
THE SIMPLER ONE! That is to say, I simply give the declaration and then 
the body of the function in C language(not in LLVM API), then I just use
 the CallInst to call that "check function". Could you be kind and  show
 me how exactly to define that "int check()" function and then "link it 
with an object file"? I really need your help!!!<br><br>Thank you!<br><br><div>--<br><div>
<div>
<div><font color="#c0c0c0" size="2">
<div><font color="#c0c0c0"><font size="3">  <span style="COLOR: #000000">          ×£ºÃ£¡</span></font></font></div><span style="COLOR: #000000">
<div> </div>
<div><font size="3">  Õç¿­</font></div>
<div>
<div><font color="#c0c0c0"><font size="3">------------------------------------------------------------------------------------------------------</font></font></div></div>
<div><font color="#c0c0c0"><font size="3">2012-04-08</font></font></div></span></font></div>
<div><font color="#c0c0c0"><font size="3">------------------------------------------------------------------------------------------------------</font></font></div>
<div><font color="#c0c0c0"><font size="3">Name: Õç¿­(ZhenKai)<br>Homepage:http://www.renren.com/262729393</font></font></div>
<div><font color="#c0c0c0"><font size="3">Email: </font><a href="mailto:zhenkaixd@126.com" target="_blank" _listener="1901"><font color="#0066cc" size="3">zhenkaixd@126.com</font></a><font size="3"> or <a href="mailto:846227103@qq.com">846227103@qq.com</a></font></font></div>
<div><font color="#c0c0c0" size="3">TEL: 15810729006(Beijing)<br>Address: Room I-406, Central Building, Tsinghua University, Beijing, China. 100084.</font></div></div></div></div><div id="divNeteaseMailCard"></div><br>At 2012-04-07 10:43:06,15102925731 <zhenkaixd@126.com> wrote:<br> <blockquote id="isReplyContent" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid"><div style="line-height:1.7;color:#000000;font-size:14px;font-family:arial"> <br>Hi all,<br>         I wrote a function pass. In the pass, it ran through all the instruction that call to functions. When arriving at the exact function that I m interested in, it would insert a self-made function.<br><br>         Now I've finished the pass, the compilation is successful. The pass can find the function I like and can insert the CallInst to call my check function. BUT, when running the pass, it breaks down. The Diagnose is as follow,<br><br>************************************************************************************<br><b>Referencing function in another module!<br>  %CallCheck = call i32 @check()<br>Broken module found, compilation aborted!</b><br>0  opt       0x087aa95b<br>1  opt       0x087aa6e8<br>2            0x00d54400 __kernel_sigreturn + 0<br>3  libc.so.6 0x009c2a82 abort + 386<br>4  opt       0x08756f15<br>5  opt       0x08756c2d<br>6  opt       0x0873a18a llvm::FPPassManager::runOnFunction(llvm::Function&) + 306<br>7  opt       0x0873a34a llvm::FPPassManager::runOnModule(llvm::Module&) + 114<br>8  opt       0x0873a62a llvm::MPPassManager::runOnModule(llvm::Module&) + 400<br>9  opt       0x0873aae0 llvm::PassManagerImpl::run(llvm::Module&) + 122<br>10 opt       0x0873ada5 llvm::PassManager::run(llvm::Module&) + 39<br>11 opt       0x0827cec3 main + 4475<br>12 libc.so.6 0x009abbd6 __libc_start_main + 230<br>13 opt       0x0826e811<br>Stack dump:<br>0.    Program arguments: opt -load ../../../Debug+Asserts/lib/Hello.so -hello <br>1.    Running pass 'Function Pass Manager' on module '<stdin>'.<br>2.    Running pass 'Module Verifier' on function '@main'<br>*****************************************************************************************************************<br>*****************************************************************************************************************<br><span style="font-size: 24px;">The source code is like,</span><br><br><b>// my "check function"</b><br>int check()<br>{<br>    printf("Hello me!!\n");<br>    return 0;<br>}<br><br><br><b>//Create a function prototype exactly like "int check()", then create a call instruction to that function.</b><br>Module * M;<br>LLVMContext Context;<br>  FunctionType *STy=FunctionType::get(Type::getInt32Ty(Context), false);<br>  Function *check = Function::Create(STy, Function::InternalLinkage, "check" ,M);<br>  CallInst *callcheck = CallInst::Create(check,"CallCheck");<br><br>namespace {<br>struct Hello : public FunctionPass<br>    {<br>                     static char ID;<br>                      Hello() : FunctionPass(ID) {}<br>                      virtual bool runOnFunction(Function &F)<br>                      {<br><b>// run through all the instruction and find the one that call <br>"puts</b><br>                            for (Function::iterator BI = F.begin(), BE = F.end(); BI != BE; ++BI)<br>                             {<br>                                for(BasicBlock::iterator II = BI->begin(),IE = BI->end();II != IE; ++II)<br>                                 {<br>                                        if(CallInst * III = dyn_cast<CallInst>(II))<br>                                         {<br><br>                                             if(III->getCalledFunction()!=NULL&&III->getCalledFunction()->getName()=="puts")<br>                                             {<br>                                                     errs() <<III->getCalledFunction()->getName()<<" function found!\n";<br>                                                callcheck->insertBefore(II);<br>                                                      errs() <<"INSERT SUCCEEDED!!!!!!!!\n";<br>                                              }<br>                                              else<br>                                             {<br>                                                  errs() <<"it's not main function!\n"<<"it is:"<<III->getCalledFunction()->getName()<<'\n';<br>                                              }<br>                                        }/**/<br>                            <br>                            }<br>************************************************************************************************************************************************************************************************************************************************************************************************<br>QUESTION: IS IT BECAUSE THE PASS CAN'T RECOGNIZE MY CHECK FUNCTION OR WHAT?? HOW TO MAKE THE PASS WORK AS EXPECTED???<br>THANK YOU!!<br><br><div>--<br><div>
<div>
<div><font color="#c0c0c0" size="2">
<div><font color="#c0c0c0"><font size="3">  <span style="COLOR: #000000">          ×£ºÃ£¡</span></font></font></div><span style="COLOR: #000000">
<div> </div>
<div><font size="3">  Õç¿­</font></div>
<div>
<div><font color="#c0c0c0"><font size="3">------------------------------------------------------------------------------------------------------</font></font></div></div>
<div><font color="#c0c0c0"><font size="3">2012-04-07</font></font></div></span></font></div>
<div><font color="#c0c0c0"><font size="3">------------------------------------------------------------------------------------------------------</font></font></div>
<div><font color="#c0c0c0"><font size="3">Name: Õç¿­(ZhenKai)<br>Homepage:http://www.renren.com/262729393</font></font></div>
<div><font color="#c0c0c0"><font size="3">Email: </font><a href="mailto:zhenkaixd@126.com" target="_blank" _listener="1901"><font color="#0066cc" size="3">zhenkaixd@126.com</font></a><font size="3"> or <a href="mailto:846227103@qq.com">846227103@qq.com</a></font></font></div>
<div><font color="#c0c0c0" size="3">TEL: 15810729006(Beijing)<br>Address: Room I-406, Central Building, Tsinghua University, Beijing, China. 100084.</font></div></div></div></div></div><br><br><span title="neteasefooter"><span id="netease_mail_footer"></span></span></blockquote></div><br><br><span title="neteasefooter"><span id="netease_mail_footer"></span></span>