[cfe-dev] LLVM - Dynamicly load Functions via IR?

via cfe-dev cfe-dev at lists.llvm.org
Tue Apr 18 02:40:00 PDT 2017


Hello LLVM-World,

I always thought, that clang is just a normal C/C++ Compiler, but after 
some research I'm getting a little confused. Do I'm right with the 
following?

I have a simple C/C++ program and I compile it with clang.

1.) Clang generates me a LLVM IR file
2.) LLVM uses the IR file to generate the.obj file
3.) My linker creates an executebale file from that.

Is this correct? On Stackoverflow (
http://stackoverflow.com/questions/3509215/llvm-jit-and-native) I read:

So how does one use LLVM as a JIT compiler? 
You build an application which generates some LLVM IR (in memory), then 
use the LLVM library to generate native code (still in memory). LLVM hands 
you back a pointer which you can call afterwards. No clang involved. 

So... Is it possible to grab the IR-File clang created and load them into 
a normal C/C++ written program? Could this program now use the 
LLVM-Library to create functions from it and let me call them? So this 
would be like a dll/so?  How could you perform this? What would happen if 
I'm using a function like printf? So the created code must have a 
"undefined reference".

Kind regards 
Björn
Als GmbH eingetragen im Handelsregister Bad Homburg v.d.H. HRB 9816, 
USt.ID-Nr. DE 114 165 789
Geschäftsführer: Hiroshi Kawamura, Dr Hiroshi Nakamura, Markus Bode, Heiko 
Lampert, Takashi Nagano, Takeshi Fukushima.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170418/79e0fcd0/attachment.html>


More information about the cfe-dev mailing list