Hello LLVM-World, currently I play around with a "llvm::Module" and an external function defined there "puts". Normally this function gets resolved in the JIT-Process but I wonder about two things: 1. Can I resolve the function already in this step? I used "replaceAllUsesWith" and passed a "llvm::ConstantInt" to the function. But this didn't worked. 2. What might happen if I have two modules and use "replaceAllUsesWith" on a function of Module A, passing a function of Module B. Thank you for the help in advance! Kind greetings Björn Als GmbH eingetragen im Handelsregister Bad Homburg v.d.H. HRB 9816, USt.ID-Nr. DE 114 165 789 Geschäftsführer: Dr. Hiroshi Nakamura, Dr. Robert Plank, Markus Bode, Heiko Lampert, Takashi Nagano, Takeshi Fukushima. Junichi Tajika -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190114/bcb3b1e2/attachment.html>
Hi Björn, On Mon, 14 Jan 2019 at 11:21, Gaier, Bjoern via llvm-dev <llvm-dev at lists.llvm.org> wrote:> Can I resolve the function already in this step? I used “replaceAllUsesWith” and passed a “llvm::ConstantInt” to the function. But this didn’t worked.In general it's good to tell us why something didn't work (error messages, assertions etc). In this case I'd guess it's because the types don't match up: you probably have to wrap your int in a ConstantExpr::getPointerCast to the same type you're replacing.> What might happen if I have two modules and use “replaceAllUsesWith” on a function of Module A, passing a function of Module B.Nothing good. You have to copy the function (and its dependencies) into the new module yourself. CloneFunction will probably be helpful there, or maybe just linking the modules together. Cheers. Tim.
On Mon, Jan 14, 2019 at 3:21 AM Gaier, Bjoern via llvm-dev < llvm-dev at lists.llvm.org> wrote:> Hello LLVM-World, > > > > currently I play around with a „llvm::Module” and an external function > defined there “puts”. Normally this function gets resolved in the > JIT-Process but I wonder about two things: > > > > 1. Can I resolve the function already in this step? I used > “replaceAllUsesWith” and passed a “llvm::ConstantInt” to the function. But > this didn’t worked. > >I'm not sure if I followed correctly, but you can't replace a function declaration with a constant int. The value for the function will be used (mostly) as an argument to the call instruction, which won't really be able to operate on an int. It isn't clear to me what you're trying to do exactly, replace the call to puts with an indirect call to the pointer value that correspond to puts in your current process? You would need to at least cast this pointer value to the right type, and use an indirect call. Best, -- Mehdi> > 1. > 2. What might happen if I have two modules and use > “replaceAllUsesWith” on a function of Module A, passing a function of > Module B. > > > > Thank you for the help in advance! > > > > Kind greetings > > Björn > Als GmbH eingetragen im Handelsregister Bad Homburg v.d.H. HRB 9816, > USt.ID-Nr. DE 114 165 789 Geschäftsführer: Dr. Hiroshi Nakamura, Dr. Robert > Plank, Markus Bode, Heiko Lampert, Takashi Nagano, Takeshi Fukushima. > Junichi Tajika > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://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/20190114/0be79af6/attachment.html>
On Mon, Jan 14, 2019 at 3:21 AM Gaier, Bjoern via llvm-dev <llvm-dev at lists.llvm.org<mailto:llvm-dev at lists.llvm.org>> wrote: Hello LLVM-World, currently I play around with a „llvm::Module” and an external function defined there “puts”. Normally this function gets resolved in the JIT-Process but I wonder about two things: 1. Can I resolve the function already in this step? I used “replaceAllUsesWith” and passed a “llvm::ConstantInt” to the function. But this didn’t worked. I'm not sure if I followed correctly, but you can't replace a function declaration with a constant int. The value for the function will be used (mostly) as an argument to the call instruction, which won't really be able to operate on an int. It isn't clear to me what you're trying to do exactly, replace the call to puts with an indirect call to the pointer value that correspond to puts in your current process? You would need to at least cast this pointer value to the right type, and use an indirect call. Hey Mehdi, I simply try overloading “puts” with a custom address before I start the JIT process. I want to replace the call to “puts” with my own address. For a test purpose I tried this now: mainModue->getFunction("puts")->replaceAllUsesWith( llvm::ConstantExpr::getPointerCast( llvm::ConstantInt::get(llvm::IntegerType::get(context, 64), 0xF), mainModue->getFunction("puts")->getType() ) ); This code will crash the application though. I know that 0xF is not a correct address and that there can be stuff optimized, but currently I just want to ‘see’ that “puts” was overloaded with 0xF. Kind greetings Björn Best, -- Mehdi 1. 2. What might happen if I have two modules and use “replaceAllUsesWith” on a function of Module A, passing a function of Module B. Thank you for the help in advance! Kind greetings Björn Als GmbH eingetragen im Handelsregister Bad Homburg v.d.H. HRB 9816, USt.ID-Nr. DE 114 165 789 Geschäftsführer: Dr. Hiroshi Nakamura, Dr. Robert Plank, Markus Bode, Heiko Lampert, Takashi Nagano, Takeshi Fukushima. Junichi Tajika _______________________________________________ LLVM Developers mailing list llvm-dev at lists.llvm.org<mailto:llvm-dev at lists.llvm.org> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev Als GmbH eingetragen im Handelsregister Bad Homburg v.d.H. HRB 9816, USt.ID-Nr. DE 114 165 789 Geschäftsführer: Dr. Hiroshi Nakamura, Dr. Robert Plank, Markus Bode, Heiko Lampert, Takashi Nagano, Takeshi Fukushima. Junichi Tajika -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190115/fbccbcab/attachment.html>