Builder = std::make_unique<IRBuilder<>>(*TheContext); } GlobalVariable *createGlob(Type *type, std::string name) { TheModule->getOrInsertGlobal(name, type); GlobalVariable *gVar = TheModule->getNamedGlobal(name); return gVar; } int main(int argc, char *argv[]) { InitializeModule()...
globalVariable->setAlignment(MaybeAlign(4)); // Add a function Type* voidType = Type::getVoidTy(context); FunctionType* functionType = FunctionType::get(voidType, false); Function* function = Function::Create(functionType, GlobalValue::ExternalLinkage, "HelloFunction", module); // Create a...
// llvm-6.0/include/llvm/IR/GlobalObject.h:64函数 void setAlignment(unsigned Align),参数是unsigned int即可 gv->setAlignment(4); Type *voidTy = Type::getVoidTy(c); /*函数在 include/llvm/IR/DerivedTypes.h:102:class FunctionType : public Type { /// Create a FunctionType taking no parame...
#include"llvm/IR/BasicBlock.h"#include"llvm/IR/Function.h"#include"llvm/IR/GlobalVariable.h"#include"llvm/IR/IRBuilder.h"#include"llvm/IR/LLVMContext.h"#include"llvm/IR/Module.h"#include"llvm/IR/Verifier.h"#include<llvm/IR/Type.h>usingnamespacellvm;staticstd::unique_ptr<LLVMContext>my_...
// Create switch variable and set as it 创建switchVar变量并设置一个随机生成的值 switchVar = new AllocaInst(Type::getInt32Ty(f->getContext()), 0, "switchVar", insert); new StoreInst( ConstantInt::get(Type::getInt32Ty(f->getContext...
return GlobalStrings; } 将每个全局常量字符串加密之后,我们就要进行解密,首先我们要创建一个解密函数。 Function* createDecodeFunc(Module& M) { auto& Ctx = M.getContext(); // 创建函数声明,参数是int8指针类型,也就是char*,和int32类型,字符串的长度, 返回...
llvm::BasicBlock *entry = llvm::BasicBlock::Create(context,"entrypoint", mainFunc); builder.SetInsertPoint(entry); llvm::Value *helloWorld = builder.CreateGlobalStringPtr("hello world!\n"); std::vector<llvm::Type *> putsArgs; putsArgs.push_back(builder.getInt8Ty()->getPointerTo()); ...
LLVM是一套提供编译器基础设施的开源项目,是用 C++ 编写,包含一系列模块化的编译器组件和工具链,用来...
ScalarType())->getElementType(),EncGVAddr,X);GVAddr=IRB.CreateBitCast(GVAddr,GV->getType());GVAddr->setName("IndGV");Inst->replaceUsesOfWith(GV,GVAddr);}}}else{for(User::op_iteratorop=Inst->op_begin();op!=Inst->op_end();++op){if(GlobalVariable*GV=dyn_cast<GlobalVariable>(*...
// Create a new LLVM IR module. m := ir.NewModule() // Create an external function declaration and append it to the module. // // int abs(int x); abs := m.NewFunc("abs", i32, ir.NewParam("x", i32)) // Create a global variable definition and append it to the module. ...