[llvm-dev] Inserting a function with arguments to appendToGlobalCtors

Mohannad Ismail via llvm-dev llvm-dev at lists.llvm.org
Mon Dec 21 17:28:02 PST 2020


I want to insert a function call that executes first. I figured the way to
do this is to insert to the global constructors with appendToGlobalCtors()
in this way:

LLVMContext &C = M.getContext();
Function* FInit =
Function::Create(FunctionType::get(Type::getVoidTy(C), false),
GlobalValue::ExternalLinkage, INITMEMORY, &M);
appendToGlobalCtors(M, FInit, 0);

This works well if the function has no arguments. But what if the function
I need to insert has arguments that I would like to specify? How do I
create the function to insert into the global constructors? The function I
have returns void. I already know how to use the IRBuilder to create a
function call. But the builder takes the arguments in the
builder.CreateCall(Func, FuncArgs). In general, I need to execute a bunch
of function calls first when I am able to obtain their parameters in the
program.

Hope I was clear enough. Let me know if this needs more clarification.
Thanks!


Best regards,

Mohannad Ismail
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20201221/326cd575/attachment.html>


More information about the llvm-dev mailing list