[llvm-dev] Passing global variable to external function

Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

[llvm-dev] Passing global variable to external function

Björn Pettersson A via llvm-dev

I need help in passing global string variable to runtime. This is how I have created a global variable and passed to the runtime -

Constant *fname = ConstantDataArray::getString(M->getContext(),"hi", true);
  Value *FBloc = new GlobalVariable(*M, fname->getType(), true, GlobalValue::InternalLinkage, fname, "fBloc");
 BitCastInst* BCToAddr = new BitCastInst(FBloc, PointerType::getUnqual(Type::getInt8Ty(M->getContext())),"", First);
  FuncInit = M->getOrInsertFunction("funcInit", VoidTy, PtrVoidTy);
  IRB.CreateCall(FuncInit, {BCToAddr});```

Unfortunately, runtime gets null pointer

extern "C" void funcInit(void *fName){
  std::cout<<"******funcInit*****"<<(char *)fName;   

Breakpoint 1, funcInit (fName=0x0) at handleReal.cpp:66
66    extern "C" void funcInit(void *fName){


LLVM Developers mailing list
[hidden email]