[LLVMdev] Dynamically loading native code generated from LLVM IR
as at steinhoff-automation.com
Fri Oct 12 05:35:56 PDT 2012
Tim Northover wrote:
> Hi Baris,
>> 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.
> That relocation-model=pic option usually necessary for a linker to be
> able to produce a .so file (it changes how variables are addressed so
> that more things can be decided when the .so is loaded), but it won't
> produce a .so itself.
>> So, my question is: Which API should I look at to emit dynamically loadable native code from LLVM IR?
> The JIT sounds like it does almost exactly what you want. LLVM's JIT
> isn't a classical lightweight, dynamic one like you'd see for
> memory, take care of the relocations for you and then jump into it (or
> provide you with a function-pointer).
OK ... I have a similar issue. What happens if the code located in the
.o file has references to external libs ?
How can I link the inmemory .o file against the external libs ... just
to get a fully executable code segment in memory.
> Is there any other reason you
> want to avoid it?
> Otherwise, only a full linker is capable of turning a .o into
> something loadable with "dlopen" or its equivalents. That's a lot of
> work, though I suppose you could fork a process to the system's linker
> if there is one.
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu
More information about the llvm-dev