[LLVMdev] Understanding resolving external/built-in function references

Bill Kelly billk at cts.com
Mon Jun 6 05:36:17 PDT 2011


Hi James,

> It depends on how your bitcode is loaded. It can be loaded either by llc,
> which outputs pure ELF/Mach-O, in which case those function references get
> turned into relocations that the linker (ld, Gold) applies.
> 
> If you're loading bitcode via the JIT, it uses dlsym() to try and introspect
> your runtime environment to find the symbol.

Ah, that makes sense - thanks.


> The simple answer is that LLVM bitcode cannot be "loaded and run" as-is - it
> needs to be converted to machine code and relocations are processed at this
> time.

I suspect the way I'm hoping to use LLVM may be slightly
uncommon:

I'd like to use the LLVM C++ API to generate modules and
functions on-the-fly and JIT-execute them, and then I'd
like to add additional functions and modules in a piecemeal
fashion, to the growing system.  Similar in this way to a
Forth or Smalltalk image-based system where one can add,
remove, or recompile function definitions on the fly, in
the context of the whole image in memory.

My impression so far from the LLVM C++ API is that this
would appear to be possible - at least up to a point.

One thing I'm unclear on is whether it's possible to add
a new function and/or module to the system, which can
reference functions in previously defined modules, without
needing to re-generate the bitcode for the whole system.

Is it possible to keep adding bitcode incrementally to the
system, and JIT'ing it, and have the set of functions
defined in the system keep growing, so that the next hunk
of bitcode added can have access to all the functions
defined so far?


Thanks,

Bill




More information about the llvm-dev mailing list