Hi List, I'm trying to upgrade our llvm-c based compiler from JIT to MCJIT. While trying to do so I encountered several problems. Looks like C API does not have proper functions to intialize LLVM with MCJIT. I ended up wrapping the following functions in my own init routine. LLVMInitializeX86TargetInfo(); LLVMInitializeX86Target(); LLVMInitializeX86TargetMC(); LLVMInitializeX86AsmPrinter(); LLVMInitializeX86AsmParser(); With this set of functions it attempts to JIT something at least. I run into a segfault, valgrind reports the following: ==27130== Process terminating with default action of signal 11 (SIGSEGV) ==27130== Bad permissions for mapped region at address 0xEAF02F7 ==27130== at 0xEAF031F: llvm::RuntimeDyldELF::resolveX86_64Relocation(llvm::SectionEntry const&, unsigned long, unsigned long, unsigned int, long, unsigned long) (RuntimeDyldELF.cpp:213) ==27130== by 0xEAF260F: llvm::RuntimeDyldELF::resolveRelocation(llvm::SectionEntry const&, unsigned long, unsigned long, unsigned int, long, unsigned long) (RuntimeDyldELF.cpp:798) ==27130== by 0xEAF258F: llvm::RuntimeDyldELF::resolveRelocation(llvm::RelocationEntry const&, unsigned long) (RuntimeDyldELF.cpp:787) ==27130== by 0xEAE7C67: llvm::RuntimeDyldImpl::resolveRelocationList(llvm::SmallVector<llvm::RelocationEntry, 64u> const&, unsigned long) (RuntimeDyld.cpp:462) ==27130== by 0xEAE543C: llvm::RuntimeDyldImpl::resolveRelocations() (RuntimeDyld.cpp:51) ==27130== by 0xEAE8236: llvm::RuntimeDyld::resolveRelocations() (RuntimeDyld.cpp:561) ==27130== by 0xA25EA99: llvm::MCJIT::finalizeObject() (MCJIT.cpp:173) ==27130== by 0xAB57918: LLVMGetPointerToGlobal (ExecutionEngineBindings.cpp:332) ==27130== by 0x4E4813D: compile_query (ql.c:2286) ==27130== by 0x4E4836A: tusto_ql_compile (ql.c:2322) ==27130== by 0x402D19: process_query (ts_util.c:167) ==27130== by 0x403205: run_shell (ts_util.c:296) I have source tree checked out at f46e5eadc307beaef6e8dd0602bb4c63ca41fd50. To create MCJIT i use provided llvm-c apis: LLVMInitializeMCJITCompilerOptions(&options, sizeof(options)); options.OptLevel = MODULE_OPT_LEVEL; /* 3 of 0 */ options.CodeModel = LLVMCodeModelJITDefault; if (LLVMCreateMCJITCompilerForModule(&qry->llvm.engine, qry->llvm.mod, &options, sizeof(options), &error) != 0) { fprintf(stderr, "%s\n", error); LLVMDisposeMessage(error); abort(); } LLVMRunStaticConstructors(qry->llvm.engine); Then I do the IR building and get the function pointer i need: iter->run = LLVMGetPointerToGlobal(qry->llvm.engine, func_ref); Am i doing something wrong? Thanks -- Regards, Konstantin -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130922/ac4fa650/attachment.html>
I managed to make it work by cloning code from lli and making my own cpp wrapper. 2013/9/22 Konstantin Olkhovskiy <lupus at oxnull.net>> Hi List, > > I'm trying to upgrade our llvm-c based compiler from JIT to MCJIT. > While trying to do so I encountered several problems. Looks like C > API does not have proper functions to intialize LLVM with MCJIT. > I ended up wrapping the following functions in my own init routine. > > LLVMInitializeX86TargetInfo(); > LLVMInitializeX86Target(); > LLVMInitializeX86TargetMC(); > LLVMInitializeX86AsmPrinter(); > LLVMInitializeX86AsmParser(); > > With this set of functions it attempts to JIT something at least. > I run into a segfault, valgrind reports the following: > > ==27130== Process terminating with default action of signal 11 (SIGSEGV) > ==27130== Bad permissions for mapped region at address 0xEAF02F7 > ==27130== at 0xEAF031F: > llvm::RuntimeDyldELF::resolveX86_64Relocation(llvm::SectionEntry const&, > unsigned long, unsigned long, unsigned int, long, unsigned long) > (RuntimeDyldELF.cpp:213) > ==27130== by 0xEAF260F: > llvm::RuntimeDyldELF::resolveRelocation(llvm::SectionEntry const&, unsigned > long, unsigned long, unsigned int, long, unsigned long) > (RuntimeDyldELF.cpp:798) > ==27130== by 0xEAF258F: > llvm::RuntimeDyldELF::resolveRelocation(llvm::RelocationEntry const&, > unsigned long) (RuntimeDyldELF.cpp:787) > ==27130== by 0xEAE7C67: > llvm::RuntimeDyldImpl::resolveRelocationList(llvm::SmallVector<llvm::RelocationEntry, > 64u> const&, unsigned long) (RuntimeDyld.cpp:462) > ==27130== by 0xEAE543C: llvm::RuntimeDyldImpl::resolveRelocations() > (RuntimeDyld.cpp:51) > ==27130== by 0xEAE8236: llvm::RuntimeDyld::resolveRelocations() > (RuntimeDyld.cpp:561) > ==27130== by 0xA25EA99: llvm::MCJIT::finalizeObject() (MCJIT.cpp:173) > ==27130== by 0xAB57918: LLVMGetPointerToGlobal > (ExecutionEngineBindings.cpp:332) > ==27130== by 0x4E4813D: compile_query (ql.c:2286) > ==27130== by 0x4E4836A: tusto_ql_compile (ql.c:2322) > ==27130== by 0x402D19: process_query (ts_util.c:167) > ==27130== by 0x403205: run_shell (ts_util.c:296) > > I have source tree checked out at f46e5eadc307beaef6e8dd0602bb4c63ca41fd50. > To create MCJIT i use provided llvm-c apis: > > LLVMInitializeMCJITCompilerOptions(&options, sizeof(options)); > options.OptLevel = MODULE_OPT_LEVEL; /* 3 of 0 */ > options.CodeModel = LLVMCodeModelJITDefault; > > if (LLVMCreateMCJITCompilerForModule(&qry->llvm.engine, qry->llvm.mod, > &options, sizeof(options), &error) != 0) { > fprintf(stderr, "%s\n", error); > LLVMDisposeMessage(error); > abort(); > } > LLVMRunStaticConstructors(qry->llvm.engine); > > Then I do the IR building and get the function pointer i need: > > iter->run = LLVMGetPointerToGlobal(qry->llvm.engine, func_ref); > > > Am i doing something wrong? > > Thanks > -- > Regards, > Konstantin >-- Regards, Konstantin -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130922/1840234d/attachment.html>
Hi Konstantin, Which additional functions did you need to get this to work beyond the ones listed in your original message? Thanks, Andy From: llvmdev-bounces at cs.uiuc.edu [mailto:llvmdev-bounces at cs.uiuc.edu] On Behalf Of Konstantin Olkhovskiy Sent: Sunday, September 22, 2013 2:47 AM To: llvmdev at cs.uiuc.edu Subject: Re: [LLVMdev] Bad permissions for mapped region I managed to make it work by cloning code from lli and making my own cpp wrapper. 2013/9/22 Konstantin Olkhovskiy <lupus at oxnull.net<mailto:lupus at oxnull.net>> Hi List, I'm trying to upgrade our llvm-c based compiler from JIT to MCJIT. While trying to do so I encountered several problems. Looks like C API does not have proper functions to intialize LLVM with MCJIT. I ended up wrapping the following functions in my own init routine. LLVMInitializeX86TargetInfo(); LLVMInitializeX86Target(); LLVMInitializeX86TargetMC(); LLVMInitializeX86AsmPrinter(); LLVMInitializeX86AsmParser(); With this set of functions it attempts to JIT something at least. I run into a segfault, valgrind reports the following: ==27130== Process terminating with default action of signal 11 (SIGSEGV) ==27130== Bad permissions for mapped region at address 0xEAF02F7 ==27130== at 0xEAF031F: llvm::RuntimeDyldELF::resolveX86_64Relocation(llvm::SectionEntry const&, unsigned long, unsigned long, unsigned int, long, unsigned long) (RuntimeDyldELF.cpp:213) ==27130== by 0xEAF260F: llvm::RuntimeDyldELF::resolveRelocation(llvm::SectionEntry const&, unsigned long, unsigned long, unsigned int, long, unsigned long) (RuntimeDyldELF.cpp:798) ==27130== by 0xEAF258F: llvm::RuntimeDyldELF::resolveRelocation(llvm::RelocationEntry const&, unsigned long) (RuntimeDyldELF.cpp:787) ==27130== by 0xEAE7C67: llvm::RuntimeDyldImpl::resolveRelocationList(llvm::SmallVector<llvm::RelocationEntry, 64u> const&, unsigned long) (RuntimeDyld.cpp:462) ==27130== by 0xEAE543C: llvm::RuntimeDyldImpl::resolveRelocations() (RuntimeDyld.cpp:51) ==27130== by 0xEAE8236: llvm::RuntimeDyld::resolveRelocations() (RuntimeDyld.cpp:561) ==27130== by 0xA25EA99: llvm::MCJIT::finalizeObject() (MCJIT.cpp:173) ==27130== by 0xAB57918: LLVMGetPointerToGlobal (ExecutionEngineBindings.cpp:332) ==27130== by 0x4E4813D: compile_query (ql.c:2286) ==27130== by 0x4E4836A: tusto_ql_compile (ql.c:2322) ==27130== by 0x402D19: process_query (ts_util.c:167) ==27130== by 0x403205: run_shell (ts_util.c:296) I have source tree checked out at f46e5eadc307beaef6e8dd0602bb4c63ca41fd50. To create MCJIT i use provided llvm-c apis: LLVMInitializeMCJITCompilerOptions(&options, sizeof(options)); options.OptLevel = MODULE_OPT_LEVEL; /* 3 of 0 */ options.CodeModel = LLVMCodeModelJITDefault; if (LLVMCreateMCJITCompilerForModule(&qry->llvm.engine, qry->llvm.mod, &options, sizeof(options), &error) != 0) { fprintf(stderr, "%s\n", error); LLVMDisposeMessage(error); abort(); } LLVMRunStaticConstructors(qry->llvm.engine); Then I do the IR building and get the function pointer i need: iter->run = LLVMGetPointerToGlobal(qry->llvm.engine, func_ref); Am i doing something wrong? Thanks -- Regards, Konstantin -- Regards, Konstantin -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130924/8d997e67/attachment.html>