David Blaikie via llvm-dev
2020-Dec-22 01:40 UTC
[llvm-dev] Inserting a function with arguments to appendToGlobalCtors
You probably need to create a function that takes no arguments - and have that function then create the arguments and call the functions-taking-arguments you want to run as global ctors. Add the outer no-argument-taking-function to the global ctors list. On Mon, Dec 21, 2020 at 5:28 PM Mohannad Ismail via llvm-dev < llvm-dev at lists.llvm.org> wrote:> 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 > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20201221/6dfe72a9/attachment.html>
Mohannad Ismail via llvm-dev
2020-Dec-22 02:16 UTC
[llvm-dev] Inserting a function with arguments to appendToGlobalCtors
Hi David, Thank you for your fast reply. That's a good idea. But the arguments I need are obtained from the IR, or in more accurately, from the static analysis I do on the IR. I can't get these arguments externally. Are you proposing I create the function within the pass? How do I do that? On Mon, Dec 21, 2020 at 8:40 PM David Blaikie <dblaikie at gmail.com> wrote:> You probably need to create a function that takes no arguments - and have > that function then create the arguments and call the > functions-taking-arguments you want to run as global ctors. Add the outer > no-argument-taking-function to the global ctors list. > > On Mon, Dec 21, 2020 at 5:28 PM Mohannad Ismail via llvm-dev < > llvm-dev at lists.llvm.org> wrote: > >> 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 >> _______________________________________________ >> LLVM Developers mailing list >> llvm-dev at lists.llvm.org >> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >> >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20201221/719c33f6/attachment.html>