[llvm-dev] Passing global variable to external function

sangeeta chowdhary via llvm-dev llvm-dev at lists.llvm.org
Tue Dec 4 05:20:25 PST 2018


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){

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20181204/baea763b/attachment.html>

More information about the llvm-dev mailing list