Trouble using the MCJIT: "Target does not support MC emission" error

I'm trying to wire up some code to use the MC-based JIT; my understanding is that it should be able to JIT AVX code (and that the regular JIT cannot). However, I'm getting the error "Target does not support MC emission!" when I call EngineBuilder::create(). I assume that I'm just not doing something necessary for initialization, but I'm not sure what it would be--I am calling all of:

    llvm::InitializeNativeTarget();
    llvm::InitializeAllTargetMCs();
    LLVMLinkInMCJIT();
    LLVMLinkInJIT();

and the module I'm trying to load does have a reasonable target:

target triple = "x86_64-apple-darwin11.0.0"

I've attached a short test case that has the sequence of calls that I'm making and one of the bitcode files I'm trying to use. I'd be happy for any guidance or suggestions.

Thanks,
-matt

a.bc (4.97 KB)

bug.cpp (1.79 KB)

Hi Matt,

You may want to have a look at lli in the llvm codebase. It can use the MCJIT for x86_64, so will have examples of all the setup required.

Do note, however, that the MCJIT is relatively feature limited at this point. It's not (yet) a drop-in replacement for the old JIT.

-Jim

Hi Matt,

I am unsure about MCJIT, but I guess the problem is the same.
Just like when invoking llc, you need to pass the information to use AVX (llc -mattr=+avx).
I guess the corresponding code should look like this:

     llvm::EngineBuilder engineBuilder(module);
     engineBuilder.setErrorStr(&eeError);
     engineBuilder.setEngineKind(llvm::EngineKind::JIT);
     engineBuilder.setUseMCJIT(true);
     engineBuilder.setMCPU("corei7-avx");
     std::vector<std::string> attrs;
     attrs.push_back("avx");
     engineBuilder.setMAttrs(attrs);
     llvm::ExecutionEngine *ee = engineBuilder.create();

Note that I have just today filed a bug report also related to jitted AVX: http://llvm.org/bugs/show_bug.cgi?id=10742
Thus, it might very well be the case that I am also mistaken and need to do something different.

Best,
Ralf

Hi Ralf,

FYI, old JIT doesn't support AVX at all, no encoding info, etc... The
only way to use AVX+JIT is using MCJIT, which contains the correct
encoding, but unfortunately the framework isn't good yet as the old
one is.

Ah, now that makes sense. Guess I was a little over-eager with my
bugreport. Thanks! :slight_smile:

However, I am now running into the same Problem as Matt ("Target does
not support MC emission!").

Best,
Ralf

Following along from lli code, if you add a call to InitializeNativeTargetAsmPrinter() during setup, it gets a bit farther and crashes rather than issuing that error. (Rebuilding with debugging symbols now to dig into it further…)

-matt

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0x0000000000000000
0x000000010000349e in llvm::MCJITMemoryManager::startFunctionBody ()
(gdb) where
#0 0x000000010000349e in llvm::MCJITMemoryManager::startFunctionBody ()
#1 0x0000000100003ea0 in llvm::RuntimeDyldImpl::extractFunction ()
#2 0x00000001000059a5 in llvm::RuntimeDyldMachO::loadSegment64 ()
#3 0x000000010000493d in llvm::RuntimeDyldMachO::loadObject ()
#4 0x0000000100003cf9 in llvm::RuntimeDyld::loadObject ()
#5 0x00000001000032e5 in llvm::MCJIT::MCJIT ()
#6 0x00000001000021c2 in llvm::MCJIT::createJIT ()
#7 0x0000000100023274 in llvm::EngineBuilder::create ()
#8 0x0000000100001417 in lRunTest (fn=0x7fff5fbffb3a "a.bc") at bug.cpp:44
#9 0x000000010000175a in main (argc=2, argv=0x7fff5fbff9c8) at bug.cpp:61
(gdb) quit

Hi Matt, hi Bruno,

I am still struggling to use AVX via MCJIT on TOT... did you succeed yet?

I seem to be unable to even get lli to run some code with the
"use-mcjit" flag.
I attached a test case that works fine for "lli y.bc" but exits with an
error for "lli -use-mcjit y.bc":
"LLVM ERROR: Unknown object format"

If I call InitializeAllTargetMCs() before creating the execution engine,
I end up with linker errors for PPC, MIPS, and MSP430 like this one:

llvm-svn-install/lib/libLLVMPowerPCDesc.a(PPCMCTargetDesc.o): In
function `PPCInstPrinter':
llvm-svn/lib/Target/PowerPC/MCTargetDesc/../InstPrinter/PPCInstPrinter.h:28:
undefined reference to `vtable for llvm::PPCInstPrinter'

However, I noticed that lli does neither call InitializeAllTargetMCs(),
nor does it call LLVMLinkInMCJIT() and LLVMLinkInJIT(). Adapting my code
to lli yields the same problem as for lli (unknown object format).

Any more ideas?

Best,
Ralf

Matt Pharr wrote:

y.ll (800 Bytes)

y.bc (776 Bytes)

ons 2011-08-31 klockan 10:51 +0200 skrev Ralf Karrenberg:

Hi Matt, hi Bruno,

I am still struggling to use AVX via MCJIT on TOT... did you succeed yet?

I seem to be unable to even get lli to run some code with the
"use-mcjit" flag.
I attached a test case that works fine for "lli y.bc" but exits with an
error for "lli -use-mcjit y.bc":
"LLVM ERROR: Unknown object format"

When I test the MCJIT under Linux I notice that lli are indeed trying to
load a buffer that contains an ELF object but fails to verify the format
using RuntimeDyldMachO::isKnownFormat this of course fails since Linux
uses ELF instead of Mach-o and this are causing lli to report (unknown
object format).

We need to implement
llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp
for the MCJIT to work on ELF systems.

Testcase:
./llvm-as < llvm/test/ExecutionEngine/hello.ll | ./lli -use-mcjit

Any more ideas?

Best,
Ralf

Cheers
Xerxes

Hi Xerxes, Hi everybody,

can anybody comment on the status of the MC JIT on Linux?
Is there somebody working on this already or does any schedule (e.g. for LLVM 3.0) exist?
I guess filing a bug report is not appropriate here since there is no implementation...

Best,
Ralf