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 linkage. 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? ============================================================================michaelMuller = mmuller at enduden.com | http://www.mindhog.net/~mmuller ----------------------------------------------------------------------------- We are the music-makers, and we are the dreamers of dreams - Arthur O'Shaughnessy =============================================================================
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 > linkage. > 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?> > ============================================================================> michaelMuller = mmuller at enduden.com | http://www.mindhog.net/~mmuller > ----------------------------------------------------------------------------- > We are the music-makers, and we are the dreamers of dreams > - Arthur O'Shaughnessy > ============================================================================> _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >============================================================================michaelMuller = mmuller at enduden.com | http://www.mindhog.net/~mmuller ----------------------------------------------------------------------------- you and I are only different in our minds, the universe makes no such distinction =============================================================================
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 >> linkage. >> 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.
The JIT tries to handle this in some cases (http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/ExecutionEngine.cpp?annotate=92771#l942), but doesn't handle it for functions. There aren't any tests, so I'm not surprised it's broken. The JIT would be simpler if we just dropped multiple-module support and asked people to link their modules together before trying to JIT them. Is there a reason you can't do that? If there is, could you write a test for http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ExecutionEngine/JIT/ that exercises the behavior you want, and file a bug with it attached? I'm not likely to actually implement that any time soon, but having a bug with a test will make it easier for someone else to pick it up. Thanks, Jeffrey On Fri, Jan 8, 2010 at 4:49 PM, Michael Muller <mmuller at enduden.com> 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 > linkage. > 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? > > ============================================================================> michaelMuller = mmuller at enduden.com | http://www.mindhog.net/~mmuller > ----------------------------------------------------------------------------- > We are the music-makers, and we are the dreamers of dreams > - Arthur O'Shaughnessy > ============================================================================> _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >
On Mon, Jan 11, 2010 at 1:39 PM, Jeffrey Yasskin <jyasskin at google.com> wrote:> The JIT tries to handle this in some cases > (http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/ExecutionEngine.cpp?annotate=92771#l942), > but doesn't handle it for functions. There aren't any tests, so I'm > not surprised it's broken. > > The JIT would be simpler if we just dropped multiple-module support > and asked people to link their modules together before trying to JIT > them. Is there a reason you can't do that?I'd like to be able to JIT a module, call imported functions from it, and then write out that module without including the bodies of the imported functions in the output .bc file.