Execution Engine issue with composite module

Hi,

I'm having an issue with the below modules.

I build module X, then module Y (which has a dependency on X). I've
added an external declaration on module Y of the functions defined in
X.

i also link the except-handling module, but i think it is peripheral
to the issue

i like all the modules together in a single module called
executableModule. I link them with the method:

Linker::LinkModules(executableModule , moduleToLink,
llvm::Linker::PreserveSource, &errorMsg);

i call

llvm::verifyModule(* executableModule, llvm::AbortProcessAction, &err);

which doesn't seem to find anything wrong with the linked module.

then i proceed to create the executionEngine:

            llvm::EngineBuilder eB(executableModule);
            eB.setEngineKind(llvm::EngineKind::JIT);
            llvmEngine = eB.create();

which seems to go well, but as soon as i run:

           llvm::Function* foo2 = moduleX->getFunction("foo2");
           engine->getPointerToFunction(foo2);

i get the error:

LLVM ERROR: Program used external function 'foo' which could not be resolved!

Any idea what is wrong? i thought linking those modules together in a
single module would solve this problem.

I've attached all the .ll files for the modules involved

except-handling.ll (740 Bytes)

executableModule.ll (1.51 KB)

X.ll (355 Bytes)

Y.ll (512 Bytes)

Hi Charles,

then i proceed to create the executionEngine:

             llvm::EngineBuilder eB(executableModule);
             eB.setEngineKind(llvm::EngineKind::JIT);
             llvmEngine = eB.create();

which seems to go well, but as soon as i run:

            llvm::Function* foo2 = moduleX->getFunction("foo2");
            engine->getPointerToFunction(foo2);

i get the error:

LLVM ERROR: Program used external function 'foo' which could not be resolved!

Make sure that you get the Function* in the linked module, which is being executed by the ExecutionEngine (executableModule in your case).

Cheers,
Clemens