[LLVMdev] Using a function from another module
kennethuil at gmail.com
Sun Jan 10 07:31:56 PST 2010
On Sun, Jan 10, 2010 at 8:58 AM, Michael Muller <mmuller at enduden.com> wrote:
> Michael Muller wrote:
>> Hi all,
>> I'm trying to use a function defined in one LLVM module from another module
>> (in the JIT) but for some reason it's not working out. My sequence of
>> activity is roughly like this:
>> 1) Create moduleA
>> 2) Create moduleB with "func()"
>> 3) execEng = ExecutionEngine::create(
>> new ExistingModuleProvider(moduleB));
>> 4) execute "func()" (this works fine)
>> 4) add "func()" to moduleA as a declaration (no code blocks) with External
>> 5) execEng->addModuleProvider(new ExistingModuleProvider(moduleA));
>> 6) run a function in moduleA that calls "func()"
>> I get:
>> LLVM ERROR: Program used external function 'func' which could not be resolved!
>> I'm guessing I'm either going about this wrong or missing something. Can
>> anyone offer me some insight?
> I've played around with this some more.
> It looks like the only way that I can get this to work is to do an
> ExecutionEngine::addGlobalMapping() on the function declaration in moduleA to
> map it to the function pointer in moduleB.
> This seems awkward, is there a better way to do this?
I'm doing the same thing, and had to do it in the same way.
Just because the JIT loads two modules doesn't mean that they're
automatically linked together within the JIT... one module cannot call
functions in the other unless the external functions are declared and
explicitly mapped using addGlobalMapping. I'm guessing it's meant to
be that way.
More information about the llvm-dev