Inter-module calls

Is there a preferred approach for an LLVM-based JIT-compiler to make calls from run-time generated functions in module A to bitcode-loaded functions in module B?

A naive CallInst across the boundary fails verification. Calling it as an external function fails to resolve, even if both ModuleA and ModuleB are in the same ExecutionEngine. I can think of two ways around this:

1. Create a constant function pointer in ModuleA using the value from EE.getPointerToFunction(FunctionB). This seems trivial, but I am concerned it will prevent many optimizations.

2. Copy functions from ModuleB into ModuleA. This appears to be a non-trivial operation. I could use Linker::LinkModules(ModuleA, ModuleB), but it seems rather inefficient to clone an entire module just to get at one function. Furthermore, since we maintain many separate run-time-generated modules, it would be especially wasteful to clone many copies of ModuleB into each of them.

Any suggestions?

-Sean