[llvm-dev] Function - replaceAllUsesWith

Gaier, Bjoern via llvm-dev llvm-dev at lists.llvm.org
Mon Jan 14 23:02:33 PST 2019


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>


More information about the llvm-dev mailing list