我正在尝试这样做:
1-插入变量t1。
2-插入对chrono函数的调用(获取时间)。
3-将Chrono的返回值存储在t1中
4-插入对“function”(我写的一个函数)的调用,传递t1作为它的参数。函数对t1进行一些计算。
在代码中它是:
float t1 = std::chrono::duration_cast<chrono::nanoseconds(chrono_steady_clock::now().time_since_epoch().count());
function(t1);
然而,我想在一个我试图修改的程序中用LLVM pass插入上面的内容。我不确定该怎么做,但我的想法是:
Constant *TFunc = M.getOrInsertFunction("std::chrono::duration_cast<chrono::nanoseconds(chrono_steady_clock::now().time_since_epoch().count())", Type::getFloatTy(M.getContext()),NULL);
tfunc = cast<Function>(TFunc);
for (*certain type of instructions Inst*){
CallInst *CurrInst = dyn_cast<CallInst>(Inst);
AllocaInst *Talloc = new AllocaInst(Type::getFloatTy((*Inst).getContext()),"t1");
Instruction *Tcall = CallInst::Create(tfunc,"");
StoreInst* store_t = new StoreInst(Tcall,Talloc,(Instruction*)CurrInst);
if(storeT != NULL) {
LoadInst* loadT = new LoadInst(storeT,"",false);
Value* t1 = loadT;
Instruction *newInst = CallInst::Create(hook,loadT, "");
Inst->getInstList().insert((Instruction*)CurrInst, newInst);
}
}
我得到的错误是:
0 libllvm-3.4.so.1 0x40f8150f llvm::sys::printStackTrace(_IO_File*)+47 1 libllvm-3.4.so.1 0x40f8177f 2 libllvm-3.4.so.1 0x40f812ec 3
0x40022400__kernel_sigreturn+0 4 libllvm-3.4.so.1 0x40864ee7 llvm::loadinst::loadinst(Llvm::value*,char const*,bool,llvm::instruction*)+71 5 pass.so 0x400265b2程序参数:/usr/bin/clang-cc1-triple i386-pc-linux-gnu-emit-obj-disable-free-disable-llvm-verifier-main-file-name mtd.cc-mrelocation-model pic-pic-level 2-fmath-errno-masm-verbose-mconstructor-aliases-fuse-init-array-target-cpu pentium4-target-linker-version 2.24-momit-leaf-frame-pointer-g-coverage-file/。。/mtd.o-resource--内部-ISystem/usr/include//C++/4.8-内部-ISystem/usr/include//C++/4.8/i386-Linux/i386-Linux-GNU/C++/4.8-内部-ISystem/usr/include//C++/4.8-内部-ISystem/usr/include//C++/4.8-内部-ISystem/usr/include//C++/4.8-内部-ISystem/usr/include//C++/4.8-内部-ISystem/usr/include//i386-Linux-GNU/C++/4.8-内部rror-limit 19-fmessage-length 80-fvisibility-inlines-hidding-MstackRealign-fobjc-runtime=gcc-fdiagnostics-show-option-fcolor-diagnostics-vectorize-loops-vectorize-slp-load/。。/pass.so-o mtd.o-x C++mtd.cc 1。解析器位于文件%2的末尾。每模块优化通过%3。正在模块“mtd.cc”上运行传递“同步探查器”。clang:ERROR:无法执行命令:分段错误(核心转储)clang:ERROR:clang前端命令由于信号(使用-V查看调用)Ubuntu clang版本3.4-1Ubuntu3(Tags/RELEASE_34/FINAL)(基于LLVM 3.4)目标:i386-pc-linux-gnu线程模型:posix clang:注意:诊断消息:请向http://bugs.debian.org/提交错误报告,并包括崩溃回溯,预处理源和相关的运行脚本。CLANG:注意:诊断消息:
请将以下文件附加到错误报告:预处理的源和关联的运行脚本位于:clang:注意:diagnostic Msg:/tmp/mtd-7d9a20.cpp clang:注意:diagnostic Msg:/tmp/mtd-7d9a20.sh clang:注意:diagnostic Msg:/tmp/mtd-7d9a20.sh
************************制造:***[MTD.O]错误254
除了生成上面的代码之外,阅读文档对我没有太大的帮助。我有以下问题:
1-我的通行证密码有什么问题?换句话说,如何添加我想要的代码?
2-这个错误是什么意思?除了分段错误和命令无法执行(可能是因为我是新手?)之外,我在其中看不到任何有意义的消息。
3-我知道如何插入对我在另一个C++文件中编写的函数的调用(比如“function”),而不是对函数的调用,也不是对C++库中定义的函数的调用,比如这个chrono函数,这就是为什么我写了“std::chrono::duration_cast
抱歉,如果我的问题太基本了。我们将感谢您的帮助和指导!
由于指令继承自LLVM中值,所以在将函数作为调用指令插入之后,您可以将该指令传递给下一个函数。不需要您尝试执行的加载存储操作。所以调用你的时间函数,把你用来调用它的指令对象传递给“function”。