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

Stefano Cherubin via cfe-dev cfe-dev at lists.llvm.org
Tue Apr 18 03:02:07 PDT 2017


Hello Björn,



clang is a C/C++ compiler which uses the LLVM backend to generate object code. This means you can use clang to create directly the object code or simply emit the LLVM-IR and JIT it.
If you are looking for JIT support using LLVM, please take a look at compiler-RT [1].You can find a section of the LLVM tutorial [2] dedicated to JIT implementation.
I would also ask you if a JIT is actually what you need for your use-case.I did something similar to what you want to do (if I understood correctly)wrapping calls to the compiler/using libclang without using the JIT.I published my code as a LGPL library on github [3]. Feel free to check it out / contribute.
Cheers,
Stefano Cherubin
[1] https://compiler-rt.llvm.org/ [2http://llvm.org/docs/tutorial/[3https://github.com/skeru/libVersioningCompiler
      From: via cfe-dev <cfe-dev at lists.llvm.org>
 To: cfe-dev at lists.llvm.org 
 Sent: Tuesday, 18 April 2017, 11:40
 Subject: [cfe-dev] LLVM - Dynamicly load Functions via IR?
  
Hello LLVM-World,

I always thought, that clang is justa 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:

| Sohow 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 inmemory). LLVM hands you back a pointer which you can call afterwards. Noclang involved.  |



So... Is it possible to grab the IR-Fileclang created and load them into a normal C/C++ written program? Couldthis program now use the LLVM-Library to create functions from it and letme call them? So this would be like a dll/so?  How could you performthis? What would happen if I'm using a function like printf? So the createdcode 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, HeikoLampert, Takashi Nagano, Takeshi Fukushima._______________________________________________
cfe-dev mailing list
cfe-dev at lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev


   

   
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170418/b342c8cf/attachment.html>


More information about the cfe-dev mailing list