<div dir="ltr"><div>Hi all,</div><div>I have been working on an llvm plugin which should create a .dot file containing the execute IR code by a specific program. My idea is to inject calls to external functions which would take care of the .dot file creation. I would like to give you an idea on the structure of my project so far:<br></div><div><br></div><div>libGraph: This is small part of the project which is in charge of creating the .dot file</div><div><br></div><div>libMiddle: This is a sort wrapper which is able to use the libGraph project</div><div><br></div><div>plugin: This is the real .so which is passed to clang with -fpass-plugin which is in charge of injecting the function calls to the functions exposed by libMiddle.</div><div><br></div><div><br></div><div>libMiddle has a simple function called addNode with the following code:</div><div><br></div><div>```</div><div>extern "C" void addNodeMiddle(std::string name) {<br>    std::cout << name << "\n";<br>}</div><div>```</div><div><br></div><div>This function should take the LLVM IR code of a specific basic block and print it on the screen. <br></div><div><br></div><div>The call to this function is injected by the plugin in this way:</div><div><br></div><div>```</div><div>//heavily based on the libInjectPrint from the llvm-tutor project<br></div><div>PointerType *GraphArgTy = PointerType::getUnqual(Type::getInt8Ty(CTX));</div><div><br></div><div>FunctionType *GraphTy = FunctionType::get(<br>            IntegerType::getVoidTy(CTX),<br>            GraphArgTy,<br>            false);</div><div><br></div><div>....</div><div><br></div><div>auto code = Builder.CreateGlobalStringPtr(OS.str());<br><br>Builder.CreateCall(<br>       GraphFunction, {code}<br>);</div><div>```</div><div><br></div><div>I can successfully run the plugin but unfortunately the output elf file crashes. In my opinion the problem is related to how I pass the parameter but I cannot fix it.</div><div><br></div><div>Can you suggest to me how to pass the content of code to an external function? Do you think my way to call external functions is too complicated and maybe I could simplify it?<br></div><div><br></div><div>Thanks</div><div>Alberto<br></div><div><br></div><div><br></div><div><br></div><div><br></div></div>