Bad permissions for mapped region

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.



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);

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?


I managed to make it work by cloning code from lli and making my own cpp wrapper.

Hi Konstantin,

Which additional functions did you need to get this to work beyond the ones listed in your original message?