[LLVMdev] How to instrument a this function using insertBefore instruction???
15102925731
zhenkaixd at 126.com
Mon Apr 9 01:53:21 PDT 2012
Hi,
I got upset.. What does “Broken module found, compilation aborted!” mean really?? what‘s “broken module“??
--
祝好!
甄凯
------------------------------------------------------------------------------------------------------
2012-04-09
------------------------------------------------------------------------------------------------------
Name: 甄凯(ZhenKai)
Homepage:http://www.renren.com/262729393
Email: zhenkaixd at 126.com or 846227103 at qq.com
TEL: 15810729006(Beijing)
Address: Room I-406, Central Building, Tsinghua University, Beijing, China. 100084.
在 2012-04-09 15:50:00,15102925731 <zhenkaixd at 126.com> 写道:
Hi all,
Im trying to instrument this hello function right before the instruction that call the "puts" function(the source code is as follow).
Now I can compile the pass without errors, but when run the pass with opt tool, it broke down. The diagnose is something like
Referencing function in another module!
%CallCheck = call i32 @fib()
Broken module found, compilation aborted!
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.
Thank you!!
//******=========================================================================================================================================******//
//******=========================================================================================================================================******//// FPSFI: a Function Pass Based Idea for Software Fault Isolation
//
//
//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//
//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
// and act it on every function the clang has analysed.
//
//******=========================================================================================================================================******//
//******=========================================================================================================================================******//
#include "llvm/Pass.h"
#include "llvm/Function.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Instruction.h"
#include "llvm/Transforms/Utils/UnrollLoop.h"
#include "llvm/BasicBlock.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Analysis/LoopIterator.h"
#include "llvm/Analysis/LoopPass.h"
#include "llvm/Analysis/ScalarEvolution.h"
#include "llvm/Analysis/ScalarEvolutionExpander.h"
#include "llvm/Support/Debug.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
#include "llvm/Transforms/Utils/Cloning.h"
#include "llvm/Type.h"
#include "llvm/LLVMContext.h"
#include "llvm/Support/Casting.h"
#include "stdio.h"
#include "llvm/Module.h"
using namespace llvm;
int check()
{
printf("Hello me!!\n");
return 0;
}
Module * M;
LLVMContext Context;
FunctionType *STy=FunctionType::get(Type::getInt32Ty(Context), false);
Function *check = Function::Create(STy, Function::InternalLinkage, "check" ,&M);
CallInst *callcheck = CallInst::Create(FibF,"CallCheck");
namespace {
struct Hello : public FunctionPass
{
static char ID;
Hello() : FunctionPass(ID) {}
virtual bool runOnFunction(Function &F)
{
errs() << "Hello: ";
errs().write_escaped(F.getName()) <<'\n';
// run through all the instruction and convert all the callinst to ...
for (Function::iterator BI = F.begin(), BE = F.end(); BI != BE; ++BI)
{
for(BasicBlock::iterator II = BI->begin(),IE = BI->end();II != IE; ++II)
{
// errs() <<"between instructions! \n";
// CallInst * III = CallInst::Create(&F,"InsttoCallInst",II);
if(CallInst * III = dyn_cast<CallInst>(II))
{
if(III->getCalledFunction()!=NULL&&III->getCalledFunction()->getName()=="puts")
{
errs() <<III->getCalledFunction()->getName()<<" function found!\n";
callcheck->insertBefore(II);
errs() <<"INSERT SUCCEEDED!!!!!!!!\n";
}
else
{
errs() <<"it's not main function!\n"<<"it is:"<<III->getCalledFunction()->getName()<<'\n';
}
}/**/
}
}
}
return true;
}
};
}
char Hello::ID = 0;
static RegisterPass<Hello> X("hello", "ZHello Korld Pass", false, false);
--
祝好!
甄凯
------------------------------------------------------------------------------------------------------
2012-04-09
------------------------------------------------------------------------------------------------------
Name: 甄凯(ZhenKai)
Homepage:http://www.renren.com/262729393
Email: zhenkaixd at 126.com or 846227103 at qq.com
TEL: 15810729006(Beijing)
Address: Room I-406, Central Building, Tsinghua University, Beijing, China. 100084.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20120409/fcddc5a8/attachment.html>
More information about the llvm-dev
mailing list