LLVM JIT 3.9 vs 6.0: How to emitAndFinalize multiple modules correctly?

Hi all,

I am having hard time figuring out how I should use the API for JIT in LLVM 6.

In LLVM 3.9 I am used to adding all objects at once and
emitAndFinalizing them all:

handle = objectLayer.addObjectSet(objectFiles, memoryManager, resolver);

In LLVM 6.0 the objects are added one by one:

auto handle = objectLayer.addObject(objectFile, resolver).get();

The problem is that emitAndFinalize in this case works for one module
and JIT exits on
"LLVM ERROR: Program used external function 'XXXX' which could not be resolved!"
errors because it seems to not see the other modules loaded with addObject.

What am I missing?



Hi Stan, the change happend with 5.0 [1]. There's a few options:
(1) Submit all modules and then explicitly finalize one after the other.
(2) Skip the explicit finalization, it should happen lazily for the
respective modules, when querying a function name.
(3) Last but not least, you could also merge all your modules into one
using Linker::link() [2] and submit this one. (This should be the
closest to pre-5.0)

You probably want to use a single resolver for all of them. Simply
forward symbol queries to your top ORC layer, and (again) it should
on-demand emit & finalize the respective module if it hasn't happened
already. E.g.:

Hope it helps!
Best, Stefan