What could be the reason "LLVM ERROR: Target does not support MC surge!"?

I am currently working on a LLVM tutorial in Rust. I have already implemented some parts of the Kaleidoscope REPL. It worked fine for me, but suddenly it stopped working, and every attempt to calculate the value ends in LLVM ERROR: Target does not support MC emission! . This seems to have happened after updating the Rust compiler until the last night (but I'm not sure here).

Relevant code snippets follow.

Initialization Function:

 #[allow(non_snake_case)] pub unsafe fn LLVMInitializeNativeTarget() { llvm::LLVMInitializeX86TargetInfo(); llvm::LLVMInitializeX86Target(); llvm::LLVMInitializeX86TargetMC(); } 

Creating a module:

  let module = llvm::LLVMModuleCreateWithNameInContext(module_name.to_c_str().as_ptr(), context); 

Creation of the execution mechanism:

  let mut exec_engine = 0 as llvm::ExecutionEngineRef; let mut error = 0 as *const c_char; LLVMCreateExecutionEngineForModule(&mut exec_engine, module, &mut error); assert!(exec_engine != 0 as llvm::ExecutionEngineRef); 

Compiling and running the function:

 pub fn run(value: llvm::ValueRef, context: &Context) -> f64 { unsafe { let result = LLVMRunFunction(context.exec_engine, value, 0, 0 as *const GenericValueRef); let ty = llvm::LLVMDoubleTypeInContext(context.context); LLVMGenericValueToFloat(ty, result) } } 

LLVM functions pre-processed by llvm :: are imported by rustc, those which are not predicated by llvm :: are imported by my code, see https://github.com/jauhien/iron-kaleidoscope/blob/master/src/missing_llvm_bindings/mod.rs .

For a complete list of codes, see https://github.com/jauhien/iron-kaleidoscope/blob/master/src/builder.rs

I use the latest nightly Rust and LLVM 3.5.0.

UPD: after commenting out the LLVMInitializeNativeTarget call, the JIT started working again. But I'm still wondering what the cause of the problem is and how JIT should be used correctly.

UPD2: after commenting out the line with initialization, not everything worked again: function calls defined in Rust code fail with LLVM ERROR: Tried to execute an unknown external function now.

The function I'm trying to call (this worked before):

 #[no_mangle] pub extern fn print(x: f64) -> f64 { println!("> {} <", x); x } 

Session Example:

 jauhien@zcj iron-repl % ./target/iron_kaleidoscope >extern print(x) declare double @print(double) >print(1) LLVM ERROR: Tried to execute an unknown external function: print 
+6
source share
1 answer

I had the same problem and I could solve it by also doing

 LLVMInitializeNativeAsmPrinter(); LLVMInitializeNativeAsmParser(); 

after initializing the X86Target. I found this in lli source code.

+4
source

Source: https://habr.com/ru/post/976455/


All Articles