On 3 February 2010 14:13, Garrison Venn <gvenn.cfe.dev at gmail.com> wrote:> I have not used the C api or the interpreter, but via JIT one can use > ExecutionEngine::addGlobalMapping(...) after the function decl in the > foreign module. See if there is an equivalent in the C API, which will > probably work for the interpreter given that this method is declared in > ExecutionEngine. Also search for a previous email thread in this list. > This discussion was fairly recent, and I believe I responded to it. >This is interesting. I've just implemented dynamic loading of bitcode modules into lli for my project. I did this by hacking lli using the Linker class. Is ExecutionEngine::addGlobalMapping() preferred for this purpose? -- James> > Hope this helps > > Garrison > > On Feb 3, 2010, at 8:53, Thomas W. wrote: > > > > > Hi everybody, > > > > I'm currently working with LLVM (v 2.6) and I try to interpret LLVM > bitcode > > using the c API. Here is my problem : I have two LLVMModuleRef, M1 and > M2, > > M1 contains the function "funct()" and M2 contains a main function which > > call "funct()" (M2 declares "funct()" too but it doesn't define it). If I > > try to run the main function, I got the error "LLVM ERROR: Tried to > execute > > unknown external function: ...". > > > > I build the interpreter giving it M1 and then I add M2. I can use the > > LLVMFindFunction(...) to get the functions "funct()" and "main()" and if > I > > apply LLVMIsDeclaration(...) to these LLVMValueRef, I got false (so the > > interpreter should know the two functions are defined and it should be > able > > to find their code). > > > > Is there something to do to enable the interpreter to find a function in > > another module ? I saw there is something like > LLVMLinker::LinkModules(...) > > in c++ but I didn't find the c version of this function. > > > > Thanks in advance for your help, > > > > Thomas. > > -- > > View this message in context: > http://old.nabble.com/Interpreter-with-multiple-modules.-tp27433312p27433312.html > > Sent from the LLVM - Dev mailing list archive at Nabble.com. > > > > _______________________________________________ > > LLVM Developers mailing list > > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20100203/302f0d85/attachment.html>
Hi James,> This is interesting. I've just implemented dynamic loading of bitcode modules into lli for my project. I did this by hacking lli using the Linker class. Is ExecutionEngine::addGlobalMapping() preferred for this purpose?I'm not sure about the preferred way, but at least for the JIT, here is an email from Jeffrey concerning a previous thread. The issue in that thread was solved via use of ExecutionEngine::addGlobalMapping(...). I don't know if the inability of the JIT or interpreter systems to automatically search in other modules is by design or not. Garrison On Jan 11, 2010, at 14:39, Jeffrey Yasskin 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? > > 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 >> > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
On 3 February 2010 15:29, Garrison Venn <gvenn.cfe.dev at gmail.com> wrote:> Hi James, > > > This is interesting. I've just implemented dynamic loading of bitcode > modules into lli for my project. I did this by hacking lli using the Linker > class. Is ExecutionEngine::addGlobalMapping() preferred for this purpose? > > I'm not sure about the preferred way, but at least for the JIT, here is an > email from Jeffrey > concerning a previous thread. The issue in that thread was solved via use > of > ExecutionEngine::addGlobalMapping(...). I don't know if the inability of > the JIT or > interpreter systems to automatically search in other modules is by design > or not. >Hi Garrison, Thanks for that. I got the same error that Michael Muller posted below and just assumed I'd need to use the linker to resolve it. I'm linking dynamically loaded modules on demand into the existing main module for the running program created by lli on startup. This seems to work on small test cases but I've no idea if this is the right thing to do (I doubt it's thread safe for example given the naive way I'm doing it). I think I need to go read the source and documentation! -- James> > Garrison > > On Jan 11, 2010, at 14:39, Jeffrey Yasskin 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? > > > > 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<http://www.mindhog.net/%7Emmuller> > >> > ----------------------------------------------------------------------------- > >> 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 > >> > > > > _______________________________________________ > > LLVM Developers mailing list > > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20100203/3f321e28/attachment.html>