I do appreciate your patience. I will try out that idea to see what may bring about~ Thank you!<br><br>ÔÚ 2012-04-09 17:56:05£¬"Joey Gouly" <joel.gouly@gmail.com> Ð´µÀ£º<br> <blockquote id="isReplyContent" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">That sounds like a good general plan, yes!<div><br></div><div>Joey<br><br><div class="gmail_quote">2012/4/9 15102925731 <span dir="ltr"><<a href="mailto:zhenkaixd@126.com">zhenkaixd@126.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="line-height:1.7;font-size:14px;font-family:arial">Thank you very much!<br><br>To make it simpler, I may as well just implement the self-written "check function" in C language instead of wrapping it in LLVM module. <b>According to the hint you give me, all I need to do is as follow(?)</b><br>
<br>1. Implement the "Check function" in the check.c file;<br>2. Add the check function into the module(the Hello1.bc file which I will run the functionPass on) in the functionPass file.<br>3. Determine the exact position and insert the CallInst instruction to call that check function. (already done as is shown in the source code).<br>
4. gmake and use the opt tool to generate the instrumented module(Hello2.bc).<br>5. Link the check.c file and Hello2.bc file together to generate ELF file.<br><br><b>does that make sense?</b><div class="im"><br><br><br><br>
<div>--<br><div>
<div>
<div><font color="#c0c0c0">
<div><font color="#c0c0c0"><font size="3">  <span style="">          ×£ºÃ£¡</span></font></font></div><span style="">
<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-09</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:<a href="http://www.renren.com/262729393" target="_blank">http://www.renren.com/262729393</a></font></font></div>
<div><font color="#c0c0c0"><font size="3">Email: </font><a href="mailto:zhenkaixd@126.com" target="_blank"><font color="#0066cc" size="3">zhenkaixd@126.com</font></a><font size="3"> or <a href="mailto:846227103@qq.com" target="_blank">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></div><br></div><div><div class="h5">
At 2012-04-09 17:16:52,"Joey Gouly" <<a href="mailto:joel.gouly@gmail.com" target="_blank">joel.gouly@gmail.com</a>> wrote:<br> <blockquote style="PADDING-LEFT:1ex;MARGIN:0px 0px 0px 0.8ex;BORDER-LEFT:#ccc 1px solid">
Hi,<div><br></div><div>I don't think the code you pasted can be the correct code, where does FibF come from?</div><div><br></div><div>Anyway, the problem is that you're calling the FibF from Module A, however you defined it for Module B.</div>

<div><br></div><div>You need to insert the FibF function into the Module that you're running. To do this override "virtual bool doInitialization(Module &M);" and insert FibF into M.</div><div><br></div>
<div>
Joey</div><div><br><div class="gmail_quote">2012/4/9 <a href="tel:15102925731" value="+15102925731" target="_blank">15102925731</a> <span dir="ltr"><<a href="mailto:zhenkaixd@126.com" target="_blank">zhenkaixd@126.com</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="line-height:1.7;font-size:14px;font-family:arial">Hi,<br>I got upset.. What does ¡°Broken module found, compilation aborted!¡± mean really?? what¡®s ¡°broken module¡°??<div><br><br><br><div>--<br><div>
<div>
<div><font color="#c0c0c0">
<div><font color="#c0c0c0"><font size="3">  <span>          ×£ºÃ£¡</span></font></font></div><span>
<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-09</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:<a href="http://www.renren.com/262729393" target="_blank">http://www.renren.com/262729393</a></font></font></div>
<div><font color="#c0c0c0"><font size="3">Email: </font><a href="mailto:zhenkaixd@126.com" target="_blank"><font color="#0066cc" size="3">zhenkaixd@126.com</font></a><font size="3"> or <a href="mailto:846227103@qq.com" target="_blank">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></div><br></div>ÔÚ 2012-04-09 15:50:00£¬<a href="tel:15102925731" value="+15102925731" target="_blank">15102925731</a> <<a href="mailto:zhenkaixd@126.com" target="_blank">zhenkaixd@126.com</a>> Ð´µÀ£º<div>

<div><br> <blockquote style="PADDING-LEFT:1ex;MARGIN:0px 0px 0px 0.8ex;BORDER-LEFT:#ccc 1px solid"><div style="line-height:1.7;font-size:14px;font-family:arial">Hi all£¬<br>Im trying to instrument this hello function right before the instruction that call the "puts" function(the source code is as follow).<br>

<br>Now I can compile the pass without errors, but when run the pass with opt tool, it broke down. The diagnose is something like<br> <br>Referencing function in another module!<br>  %CallCheck = call i32 @fib()<br>Broken module found, compilation aborted!<br>

<br>Does it mean I fail to wrap the function into a module?? How to actually insert the the "hello function" before the calling instruction ?? Im waiting for your help.<br>Thank you!!<br><br>//******=========================================================================================================================================******//<br>

//******=========================================================================================================================================******////                                     FPSFI: a Function Pass Based Idea for Software Fault Isolation<br>

//<br>//<br>//This file involves the main work of SFI. It will source the certain point in any programme(mainly modules in our context)and insert our manully made//<br>//check function to provide API integrity. Thanks to the pass mechanism that LLVM provide, we can wrap our fix and optimization idea into a function pass<br>

// and  act it on every function the clang has analysed.<br>//<br>//******=========================================================================================================================================******//<br>

//******=========================================================================================================================================******//<br>#include "llvm/Pass.h"<br>#include "llvm/Function.h"<br>

#include "llvm/Support/raw_ostream.h"<br>#include "llvm/Instruction.h"<br>#include "llvm/Transforms/Utils/UnrollLoop.h"<br>#include "llvm/BasicBlock.h"<br>#include "llvm/ADT/Statistic.h"<br>

#include "llvm/Analysis/LoopIterator.h"<br>#include "llvm/Analysis/LoopPass.h"<br>#include "llvm/Analysis/ScalarEvolution.h"<br>#include "llvm/Analysis/ScalarEvolutionExpander.h"<br>

#include "llvm/Support/Debug.h"<br>#include "llvm/Transforms/Utils/BasicBlockUtils.h"<br>#include "llvm/Transforms/Utils/Cloning.h"<br>#include "llvm/Type.h"<br>#include "llvm/LLVMContext.h"<br>

#include "llvm/Support/Casting.h"<br>#include "stdio.h"<br><br>#include "llvm/Module.h"<br>using namespace llvm;<br><br><br>int check()<br>{<br>    printf("Hello me!!\n");<br>    return 0;<br>

}<br><br> <br><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>

<br>  CallInst *callcheck = CallInst::Create(FibF,"CallCheck");<br><br>namespace {<br><br>struct Hello : public FunctionPass<br>    {<br><br>                      static char ID;<br>                      Hello() : FunctionPass(ID) {}<br>

                      virtual bool runOnFunction(Function &F)<br>                      {<br>                              errs() << "Hello: ";<br>                                  errs().write_escaped(F.getName()) <<'\n';                                 <br>

// run through all the instruction and convert all the callinst to ...<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>//                                     errs() <<"between instructions! \n";<br>//                                     CallInst * III = CallInst::Create(&F,"InsttoCallInst",II);<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>         <br>                                }  <br>                              return true;<br>

                        }<br>       };<br> }<br><br>char Hello::ID = 0;<br>static RegisterPass<Hello> X("hello", "ZHello Korld Pass", false, false);<br><br><div>--<br><div>
<div>
<div><font color="#c0c0c0">
<div><font color="#c0c0c0"><font size="3">  <span>          ×£ºÃ£¡</span></font></font></div><span>
<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-09</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:<a href="http://www.renren.com/262729393" target="_blank">http://www.renren.com/262729393</a></font></font></div>
<div><font color="#c0c0c0"><font size="3">Email: </font><a href="mailto:zhenkaixd@126.com" target="_blank"><font color="#0066cc" size="3">zhenkaixd@126.com</font></a><font size="3"> or <a href="mailto:846227103@qq.com" target="_blank">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></span></span></blockquote>

</div></div></div><br><br><span title="neteasefooter"><span></span></span><br>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
<br></blockquote></div><br></div>
</blockquote></div></div></div><br><br><span title="neteasefooter"><span></span></span></blockquote></div><br></div>
</blockquote><br><br><span title="neteasefooter"><span id="netease_mail_footer"></span></span>