[LLVMdev] Dynamically loading native code generated from LLVM IR
baris.aktemur at ozyegin.edu.tr
Thu Oct 11 23:57:30 PDT 2012
I'm building LLVM IR. I'd like to compile this IR to native code (I don't want JIT) and immediately load it to execute. So far, I've the following:
1) I can emit the IR to native assembly/object file doing the same thing llc does (using TargetMachine::addPassesToEmitFile).
2) I can dynamically load a precompiled .so file (using llvm::sys::DynamicLibrary::getPermanentLibrary), get a function pointer from that file, and execute.
I can't dynamically load the .o file I produce in step 1 because it's a static library. If I could produce a .so file in step 1, my problem would be solved. llc has a "-relocation-model=pic" option, but the file produced with that did not dynamically load. I got lost in clang's options when trying to find where the "-shared" and "-fPIC" options are used.
So, my question is: Which API should I look at to emit dynamically loadable native code from LLVM IR?
I would also like to emit code to an in-memory stream instead of a file because everything happens at runtime, but that's a secondary concern.
Thanks in advance.
More information about the llvm-dev