Git Product home page Git Product logo

llvm-rs's Introduction

LLVM-rs

Crate Version Crate Downloads Crate License Build Status Dependency Status

This is a library that wraps LLVM using Rust idioms and the cbox library. There is good quality documentation available if you want to check out the API. It's basically a simplified version of the C++ API which has documentation.

Using in your projects

To use this in your project, add the following to your Cargo.toml

[dependencies]
...
llvm-alt = "*"

Bugs

While using this library, if you ever encounter a segmentation fault or similar unverbose error messages, please file an issue with what code caused the problem. Thanks!

llvm-rs's People

Contributors

bdash avatar dpzmick avatar heroesgrave avatar hywan avatar justinas avatar tombebbington avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

llvm-rs's Issues

codegen for f64 return type seems broken

I have been working on an experiment of trying to adapt the Kaleidoscope tutorial from the LLVM website to use this llvm-rs crate (with minimal changes to this crate, solely via extension traits if possible).

However, it appears that something goes wrong when I try to JIT compile a function that returns an f64. (Due to #5, its actually a function that consumes and returns an f64, since I was not able to reduce it further to a function that solely returns an f64 -- but it is ignoring its input, so I do not think this is relevant to the problem.)

In an attempt to illustrate the issue, I have made two test cases; they each are functions that return the value 3 as N, where in the first case N is u64, while in the second case N is f64.

I dumped the generated LLVM bytecode in both cases, and the LLVM code looks like it is handling the correct types. (The inputs also pass calls to "LLVM verify.")

Here is the case that is failing to run in the way I expect (I test it by throwing it into examples/demo_3f.rs):

demo_3f.rs:

extern crate llvm_sys;
extern crate llvm;
use llvm::*;
use llvm::Attribute::*;
fn main() {
    let ctx = llvm::Context::new();
    let module = llvm::Module::new("simple", &ctx);
    type N = f64;
    type T = extern "C" fn(N) -> N;
    let func = module.add_function(
        "thr", llvm::Type::get::<T>(&ctx));
    func.add_attributes(&[NoUnwind, ReadNone]);
    let entry = func.append("entry");
    let builder = llvm::Builder::new(&ctx);
    fn n(x: N) -> N { x }
    let three_r = n(3 as N).compile(&ctx);
    builder.position_at_end(entry);
    builder.build_ret(three_r);
    module.verify().unwrap();

    let ee = llvm::JitEngine::new(
        &module, llvm::JitOptions {opt_level: 0}).unwrap();

    unsafe {
        let mref: llvm_sys::prelude::LLVMModuleRef = module.as_ptr();
        llvm_sys::core::LLVMDumpModule(mref);
    }

    ee.with_function(func, |thr: T| {
        for i in 0..3 {
            println!("thr {} = {}", i, thr(0 as N))
        }
    });
}

Here is the result of attempting to run the example: https://gist.github.com/pnkfelix/772b08ccc6915a626366 along with disassembly of the generated machine code that is segfaulting.

Note that if you apply the following one line change, the example will compile and run fine:

% diff -u examples/demo_3f.rs examples/demo_3u.rs
--- examples/demo_3f.rs 2015-09-09 16:06:57.578737220 +0200
+++ examples/demo_3u.rs 2015-09-09 16:07:04.345277699 +0200
@@ -5,7 +5,7 @@
 fn main() {
     let ctx = llvm::Context::new();
     let module = llvm::Module::new("simple", &ctx);
-    type N = f64;
+    type N = u64;
     type T = extern "C" fn(N) -> N;
     let func = module.add_function(
         "thr", llvm::Type::get::<T>(&ctx));

(I'm not actually sure that this is really an llvm-rs bug. At this point I am probably going to switch to trying to use the underlying llvm-sys crate directly to determine whether I can properly generate the f64 code I expect -- if I can do that, then I should be better equipped to hunt down what is going wrong here.)

builder::build_neg only works for integer inputs

Just a heads up: The API of builder.rs might lead one to think that all the build methods for arithmetic will automatically dispatch to floating point or integer versions of the requested operations based on the input Value types

But the build_neg method does not dispatch to LLVMBuildFNeg when given a floating point value.

(This is easy for client to work around, e.g. by using builder.build_sub(0.0, arg); but it left me scratching my head for quite a while when my code was not passing the LLVM function validator.)

doesn't handle memory correctly

When an execution engine is created, it should take ownership of the module it wraps. In llvm, this is the case.

This package doesn't seem to do that, this results in lots of valgrind errors while rust cleans everything up

Examples Segfault on OS X (LLVM 3.8.1)

I'm compiling on OS X with rustc 1.13.0-nightly (f883b0bba 2016-08-19) and LLVM 3.8.1 from Homebrew.

When running any of the examples I receive a segfault:

$ PATH=$PATH:/usr/local/opt/llvm/bin cargo run --example add 
    Finished debug [unoptimized + debuginfo] target(s) in 0.0 secs
     Running `target/debug/examples/add`
1 + 2 = 3
error: Process didn't exit successfully: `target/debug/examples/add` (signal: 11, SIGSEGV: invalid memory reference)

This seems to be from the drop implementation for Module

(lldb) run
Process 61966 launched: '/Users/will/Repositories/llvm-rs/target/debug/examples/add' (x86_64)
1 + 2 = 3
Process 61966 stopped
* thread #1: tid = 0x640f90, 0x000000010063d8b2 add`llvm::LLVMContext::removeModule(llvm::Module*) + 4, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
    frame #0: 0x000000010063d8b2 add`llvm::LLVMContext::removeModule(llvm::Module*) + 4
add`llvm::LLVMContext::removeModule:
->  0x10063d8b2 <+4>:  movq   (%rdi), %rdi
    0x10063d8b5 <+7>:  popq   %rbp
    0x10063d8b6 <+8>:  jmp    0x10069b226               ; llvm::SmallPtrSetImplBase::erase_imp(void const*)
    0x10063d8bb <+13>: nop    
(lldb) bt
* thread #1: tid = 0x640f90, 0x000000010063d8b2 add`llvm::LLVMContext::removeModule(llvm::Module*) + 4, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
  * frame #0: 0x000000010063d8b2 add`llvm::LLVMContext::removeModule(llvm::Module*) + 4
    frame #1: 0x0000000100661901 add`llvm::Module::~Module() + 31
    frame #2: 0x00000001005d7f7d add`LLVMDisposeModule + 22
    frame #3: 0x0000000100002951 add`drop::h3fd646682453ffaf + 97
    frame #4: 0x0000000100004553 add`add::main::h8b97c6143f430fbb + 851 at add.rs:6
    frame #5: 0x000000010001417b add`__rust_maybe_catch_panic + 27
    frame #6: 0x0000000100012aff add`std::rt::lang_start::h352a66f5026f54bd + 399
    frame #7: 0x000000010000482a add`main + 42
    frame #8: 0x00007fff88ba65ad libdyld.dylib`start + 1
    frame #9: 0x00007fff88ba65ad libdyld.dylib`start + 1
(lldb)

I think this is because the JitEngine has taken ownership of the module and dropped it already.

can not link in win/msvc.

  = note: "C:\\Program Files (x86)\\Microsoft Visual Studio 12.0\\VC\\bin\\amd64\\link.exe" "/LIBPATH:C:\\Program Files (x86)\\Microsoft Visual
Studio 12.0\\VC\\lib\\amd64" "/LIBPATH:C:\\Program Files (x86)\\Windows Kits\\8.1\\lib\\winv6.3\\um\\x64" "/NOLOGO" "/NXCOMPAT" "/LIBPATH:C:\\Pr
ogram Files\\Rust nightly MSVC 1.14\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "d:\\dws\\r\\rinja\\target\\debug\\rinja.0.o" "/OUT:d:\\dws\\r\\
rinja\\target\\debug\\rinja.exe" "/OPT:REF,ICF" "/DEBUG" "/LIBPATH:d:\\dws\\r\\rinja\\target\\debug\\deps" "/LIBPATH:IBPATH:D:\\dws\\llvm-3.9.0\
\lib" "/LIBPATH:d:\\dws\\r\\rinja\\target\\debug\\build\\llvm-sys-7bf0294e050743f6\\out" "/LIBPATH:C:\\Program Files\\Rust nightly MSVC 1.14\\li
b\\rustlib\\x86_64-pc-windows-msvc\\lib" "D:\\dws\\r\\rinja\\target\\debug\\deps\\libllvm-2aaae2d25be31fa6.rlib" "D:\\dws\\r\\rinja\\target\\deb
ug\\deps\\libllvm_sys-054f6efd9344d651.rlib" "D:\\dws\\r\\rinja\\target\\debug\\deps\\libbitflags-808c1d1403868150.rlib" "D:\\dws\\r\\rinja\\tar
get\\debug\\deps\\libcbox-48fdc34ca924689d.rlib" "D:\\dws\\r\\rinja\\target\\debug\\deps\\liblibc-6e378f22710f2c4e.rlib" "C:\\Program Files\\Rus
t nightly MSVC 1.14\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libstd-6eb85298.rlib" "C:\\Program Files\\Rust nightly MSVC 1.14\\lib\\rustlib\\
x86_64-pc-windows-msvc\\lib\\libpanic_unwind-6eb85298.rlib" "C:\\Program Files\\Rust nightly MSVC 1.14\\lib\\rustlib\\x86_64-pc-windows-msvc\\li
b\\libunwind-6eb85298.rlib" "C:\\Program Files\\Rust nightly MSVC 1.14\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librand-6eb85298.rlib" "C:\\P
rogram Files\\Rust nightly MSVC 1.14\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcollections-6eb85298.rlib" "C:\\Program Files\\Rust nightly
MSVC 1.14\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_unicode-6eb85298.rlib" "C:\\Program Files\\Rust nightly MSVC 1.14\\lib\\rustlib\\
x86_64-pc-windows-msvc\\lib\\liblibc-6eb85298.rlib" "C:\\Program Files\\Rust nightly MSVC 1.14\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libal
loc-6eb85298.rlib" "C:\\Program Files\\Rust nightly MSVC 1.14\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liballoc_system-6eb85298.rlib" "C:\\Pr
ogram Files\\Rust nightly MSVC 1.14\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcore-6eb85298.rlib" "C:\\Program Files\\Rust nightly MSVC 1.1
4\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcompiler_builtins-6eb85298.rlib" "ffi.lib" "msvcrt.lib" "ws2_32.lib" "userenv.lib" "shell32.lib
" "advapi32.lib" "msvcrt.lib"

note: LINK : fatal error LNK1181: cannot open input file 'ffi.lib'

crash when calling build_gep with a compiled 0usize

crashing code:

extern crate llvm;
use llvm::*;

fn main() {
    let context = Context::new();
    let module = Module::new("test", &context);

    let u8_type = Type::get::<u8>(&context);
    let array_type = ArrayType::new(u8_type, 32);
    let struct_type = StructType::new(
        &context,
        &[
            array_type,
        ],
        false);
    let struct_ptr_type = PointerType::new(struct_type);

    let void_type = Type::get::<()>(&context);
    let fn_type = FunctionType::new(
        void_type,
        &[struct_ptr_type]);

    let func = module.add_function("test_func", fn_type);
    let first_block = func.append("a_block");
    let builder = Builder::new(&context);
    builder.position_at_end(first_block);

    let arg_ptr = &func[0];
    let zero = 0usize.compile(&context);
    builder.build_gep(arg_ptr, &[zero, zero]);
}

if I change 0usize to 0u32 then it doesn't crash.

Type checking code in `JitEngine::with_function` tends to fail with segfault.

#0  0x0000555555e963c0 in LLVMGetParamTypes ()
#1  0x00005555556901b2 in llvm::types::{{impl}}::get_params (
    self=0x7ffff60ba000) at /code/llvm-rs/src/types.rs:149
#2  0x000055555568a471 in llvm::engine::{{impl}}::with_function<closure,u64,u64> (self=0x7ffff609e400, function=0x7ffff60c6008, cb=...) at <std macros>:110
#3  0x0000555555689a89 in fib::main () at /code/llvm-rs/examples/fib.rs:36
#4  0x0000555555699f79 in std::panicking::try::call::h852b0d5f2eec25e4 ()
#5  0x00005555556a3b4c in __rust_try ()
#6  0x00005555556a3aef in __rust_maybe_catch_panic ()
#7  0x0000555555699a1f in std::rt::lang_start::hfe4efe1fc39e4a30 ()
#8  0x000055555568c26a in main ()

This can be worked around by adding the debug_assertions flag to rustc, or by adding --release to the cargo build flags. Also, modifying the library so it interacts with the function type in any way before calling get_params seems to fix this, so it could be some kind of null error that's slipped through.

libffi not linked in?

With a very simple program, building fails. It looks like it's from libffi not being linked?

$ cargo build   
   Compiling plb v0.1.0 (file:///home/nathan/Desktop/plbc)
error: linking with `cc` failed: exit code: 1
note: "cc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-m64" "-L" "/home/nathan/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "/home/nathan/Desktop/plbc/target/debug/plbc.0.o" "-o" "/home/nathan/Desktop/plbc/target/debug/plbc" "-Wl,--gc-sections" "-pie" "-nodefaultlibs" "-L" "/home/nathan/Desktop/plbc/target/debug" "-L" "/home/nathan/Desktop/plbc/target/debug/deps" "-L" "/usr/lib" "-L" "/home/nathan/Desktop/plbc/target/debug/build/llvm-sys-76a5d702ae8c46e3/out" "-L" "/home/nathan/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bstatic" "-Wl,-Bdynamic" "/home/nathan/Desktop/plbc/target/debug/deps/libgetopts-33691dbdf8852281.rlib" "/home/nathan/Desktop/plbc/target/debug/libplb.rlib" "/home/nathan/Desktop/plbc/target/debug/deps/libuuid-41f66b8ddc6c6059.rlib" "/home/nathan/Desktop/plbc/target/debug/deps/libllvm-6c21f2bf7fd206b5.rlib" "/home/nathan/Desktop/plbc/target/debug/deps/libllvm_sys-3628cf0853e8edea.rlib" "/home/nathan/Desktop/plbc/target/debug/deps/libnom-24d7a34b1cbfee73.rlib" "/home/nathan/Desktop/plbc/target/debug/deps/libcbox-75ae8b50200a40f5.rlib" "/home/nathan/Desktop/plbc/target/debug/deps/libbitflags-1efefdc447eb53f2.rlib" "/home/nathan/Desktop/plbc/target/debug/deps/librand-49a08859d086fffe.rlib" "/home/nathan/Desktop/plbc/target/debug/deps/liblibc-1bd8847afb79f283.rlib" "/home/nathan/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-39b92f95.rlib" "/home/nathan/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-39b92f95.rlib" "/home/nathan/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-39b92f95.rlib" "/home/nathan/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librand-39b92f95.rlib" "/home/nathan/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcollections-39b92f95.rlib" "/home/nathan/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_unicode-39b92f95.rlib" "/home/nathan/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-39b92f95.rlib" "/home/nathan/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc_jemalloc-39b92f95.rlib" "/home/nathan/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-39b92f95.rlib" "/home/nathan/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-39b92f95.rlib" "-l" "ffi" "-l" "LLVMLTO" "-l" "LLVMObjCARCOpts" "-l" "LLVMSymbolize" "-l" "LLVMDebugInfoPDB" "-l" "LLVMDebugInfoDWARF" "-l" "LLVMXCoreDisassembler" "-l" "LLVMXCoreCodeGen" "-l" "LLVMXCoreDesc" "-l" "LLVMXCoreInfo" "-l" "LLVMXCoreAsmPrinter" "-l" "LLVMSystemZDisassembler" "-l" "LLVMSystemZCodeGen" "-l" "LLVMSystemZAsmParser" "-l" "LLVMSystemZDesc" "-l" "LLVMSystemZInfo" "-l" "LLVMSystemZAsmPrinter" "-l" "LLVMSparcDisassembler" "-l" "LLVMSparcCodeGen" "-l" "LLVMSparcAsmParser" "-l" "LLVMSparcDesc" "-l" "LLVMSparcInfo" "-l" "LLVMSparcAsmPrinter" "-l" "LLVMPowerPCDisassembler" "-l" "LLVMPowerPCCodeGen" "-l" "LLVMPowerPCAsmParser" "-l" "LLVMPowerPCDesc" "-l" "LLVMPowerPCInfo" "-l" "LLVMPowerPCAsmPrinter" "-l" "LLVMNVPTXCodeGen" "-l" "LLVMNVPTXDesc" "-l" "LLVMNVPTXInfo" "-l" "LLVMNVPTXAsmPrinter" "-l" "LLVMMSP430CodeGen" "-l" "LLVMMSP430Desc" "-l" "LLVMMSP430Info" "-l" "LLVMMSP430AsmPrinter" "-l" "LLVMMipsDisassembler" "-l" "LLVMMipsCodeGen" "-l" "LLVMMipsAsmParser" "-l" "LLVMMipsDesc" "-l" "LLVMMipsInfo" "-l" "LLVMMipsAsmPrinter" "-l" "LLVMHexagonDisassembler" "-l" "LLVMHexagonCodeGen" "-l" "LLVMHexagonAsmParser" "-l" "LLVMHexagonDesc" "-l" "LLVMHexagonInfo" "-l" "LLVMCppBackendCodeGen" "-l" "LLVMCppBackendInfo" "-l" "LLVMBPFCodeGen" "-l" "LLVMBPFDesc" "-l" "LLVMBPFInfo" "-l" "LLVMBPFAsmPrinter" "-l" "LLVMARMDisassembler" "-l" "LLVMARMCodeGen" "-l" "LLVMARMAsmParser" "-l" "LLVMARMDesc" "-l" "LLVMARMInfo" "-l" "LLVMARMAsmPrinter" "-l" "LLVMAMDGPUCodeGen" "-l" "LLVMAMDGPUAsmParser" "-l" "LLVMAMDGPUDesc" "-l" "LLVMAMDGPUUtils" "-l" "LLVMAMDGPUInfo" "-l" "LLVMAMDGPUAsmPrinter" "-l" "LLVMAArch64Disassembler" "-l" "LLVMAArch64CodeGen" "-l" "LLVMAArch64AsmParser" "-l" "LLVMAArch64Desc" "-l" "LLVMAArch64Info" "-l" "LLVMAArch64AsmPrinter" "-l" "LLVMAArch64Utils" "-l" "LLVMMIRParser" "-l" "LLVMLibDriver" "-l" "LLVMOption" "-l" "LLVMTableGen" "-l" "LLVMLineEditor" "-l" "LLVMX86Disassembler" "-l" "LLVMX86AsmParser" "-l" "LLVMX86CodeGen" "-l" "LLVMSelectionDAG" "-l" "LLVMAsmPrinter" "-l" "LLVMX86Desc" "-l" "LLVMMCDisassembler" "-l" "LLVMX86Info" "-l" "LLVMX86AsmPrinter" "-l" "LLVMX86Utils" "-l" "LLVMMCJIT" "-l" "LLVMPasses" "-l" "LLVMipo" "-l" "LLVMVectorize" "-l" "LLVMLinker" "-l" "LLVMIRReader" "-l" "LLVMAsmParser" "-l" "LLVMDebugInfoCodeView" "-l" "LLVMInterpreter" "-l" "LLVMCodeGen" "-l" "LLVMScalarOpts" "-l" "LLVMInstCombine" "-l" "LLVMInstrumentation" "-l" "LLVMProfileData" "-l" "LLVMBitWriter" "-l" "LLVMOrcJIT" "-l" "LLVMTransformUtils" "-l" "LLVMExecutionEngine" "-l" "LLVMTarget" "-l" "LLVMAnalysis" "-l" "LLVMRuntimeDyld" "-l" "LLVMObject" "-l" "LLVMMCParser" "-l" "LLVMBitReader" "-l" "LLVMMC" "-l" "LLVMCore" "-l" "LLVMSupport" "-l" "rt" "-l" "dl" "-l" "curses" "-l" "pthread" "-l" "z" "-l" "m" "-l" "stdc++" "-l" "util" "-l" "dl" "-l" "pthread" "-l" "gcc_s" "-l" "pthread" "-l" "c" "-l" "m" "-l" "rt" "-l" "util" "-l" "compiler-rt"
note: /usr/lib/libLLVMInterpreter.a(ExternalFunctions.cpp.o): In function `llvm::Interpreter::callExternalFunction(llvm::Function*, llvm::ArrayRef<llvm::GenericValue>)':
(.text._ZN4llvm11Interpreter20callExternalFunctionEPNS_8FunctionENS_8ArrayRefINS_12GenericValueEEE+0x333): undefined reference to `ffi_type_pointer'
/usr/lib/libLLVMInterpreter.a(ExternalFunctions.cpp.o): In function `llvm::Interpreter::callExternalFunction(llvm::Function*, llvm::ArrayRef<llvm::GenericValue>)':
(.text._ZN4llvm11Interpreter20callExternalFunctionEPNS_8FunctionENS_8ArrayRefINS_12GenericValueEEE+0x386): undefined reference to `ffi_type_sint64'
/usr/lib/libLLVMInterpreter.a(ExternalFunctions.cpp.o): In function `llvm::Interpreter::callExternalFunction(llvm::Function*, llvm::ArrayRef<llvm::GenericValue>)':
(.text._ZN4llvm11Interpreter20callExternalFunctionEPNS_8FunctionENS_8ArrayRefINS_12GenericValueEEE+0x397): undefined reference to `ffi_type_sint32'
/usr/lib/libLLVMInterpreter.a(ExternalFunctions.cpp.o): In function `llvm::Interpreter::callExternalFunction(llvm::Function*, llvm::ArrayRef<llvm::GenericValue>)':
(.text._ZN4llvm11Interpreter20callExternalFunctionEPNS_8FunctionENS_8ArrayRefINS_12GenericValueEEE+0x3a9): undefined reference to `ffi_type_sint8'
/usr/lib/libLLVMInterpreter.a(ExternalFunctions.cpp.o): In function `llvm::Interpreter::callExternalFunction(llvm::Function*, llvm::ArrayRef<llvm::GenericValue>)':
(.text._ZN4llvm11Interpreter20callExternalFunctionEPNS_8FunctionENS_8ArrayRefINS_12GenericValueEEE+0x3b2): undefined reference to `ffi_type_sint16'
/usr/lib/libLLVMInterpreter.a(ExternalFunctions.cpp.o): In function `llvm::Interpreter::callExternalFunction(llvm::Function*, llvm::ArrayRef<llvm::GenericValue>)':
(.text._ZN4llvm11Interpreter20callExternalFunctionEPNS_8FunctionENS_8ArrayRefINS_12GenericValueEEE+0x746): undefined reference to `ffi_type_pointer'
/usr/lib/libLLVMInterpreter.a(ExternalFunctions.cpp.o): In function `llvm::Interpreter::callExternalFunction(llvm::Function*, llvm::ArrayRef<llvm::GenericValue>)':
(.text._ZN4llvm11Interpreter20callExternalFunctionEPNS_8FunctionENS_8ArrayRefINS_12GenericValueEEE+0x769): undefined reference to `ffi_prep_cif'
/usr/lib/libLLVMInterpreter.a(ExternalFunctions.cpp.o): In function `llvm::Interpreter::callExternalFunction(llvm::Function*, llvm::ArrayRef<llvm::GenericValue>)':
(.text._ZN4llvm11Interpreter20callExternalFunctionEPNS_8FunctionENS_8ArrayRefINS_12GenericValueEEE+0x7bf): undefined reference to `ffi_call'
/usr/lib/libLLVMInterpreter.a(ExternalFunctions.cpp.o): In function `llvm::Interpreter::callExternalFunction(llvm::Function*, llvm::ArrayRef<llvm::GenericValue>)':
(.text._ZN4llvm11Interpreter20callExternalFunctionEPNS_8FunctionENS_8ArrayRefINS_12GenericValueEEE+0xd52): undefined reference to `ffi_type_sint64'
/usr/lib/libLLVMInterpreter.a(ExternalFunctions.cpp.o): In function `llvm::Interpreter::callExternalFunction(llvm::Function*, llvm::ArrayRef<llvm::GenericValue>)':
(.text._ZN4llvm11Interpreter20callExternalFunctionEPNS_8FunctionENS_8ArrayRefINS_12GenericValueEEE+0xd5e): undefined reference to `ffi_type_double'
/usr/lib/libLLVMInterpreter.a(ExternalFunctions.cpp.o): In function `llvm::Interpreter::callExternalFunction(llvm::Function*, llvm::ArrayRef<llvm::GenericValue>)':
(.text._ZN4llvm11Interpreter20callExternalFunctionEPNS_8FunctionENS_8ArrayRefINS_12GenericValueEEE+0xd6a): undefined reference to `ffi_type_sint32'
/usr/lib/libLLVMInterpreter.a(ExternalFunctions.cpp.o): In function `llvm::Interpreter::callExternalFunction(llvm::Function*, llvm::ArrayRef<llvm::GenericValue>)':
(.text._ZN4llvm11Interpreter20callExternalFunctionEPNS_8FunctionENS_8ArrayRefINS_12GenericValueEEE+0xd7b): undefined reference to `ffi_type_sint8'
/usr/lib/libLLVMInterpreter.a(ExternalFunctions.cpp.o): In function `llvm::Interpreter::callExternalFunction(llvm::Function*, llvm::ArrayRef<llvm::GenericValue>)':
(.text._ZN4llvm11Interpreter20callExternalFunctionEPNS_8FunctionENS_8ArrayRefINS_12GenericValueEEE+0xd87): undefined reference to `ffi_type_sint16'
/usr/lib/libLLVMInterpreter.a(ExternalFunctions.cpp.o): In function `llvm::Interpreter::callExternalFunction(llvm::Function*, llvm::ArrayRef<llvm::GenericValue>)':
(.text._ZN4llvm11Interpreter20callExternalFunctionEPNS_8FunctionENS_8ArrayRefINS_12GenericValueEEE+0xd93): undefined reference to `ffi_type_float'
/usr/lib/libLLVMInterpreter.a(ExternalFunctions.cpp.o): In function `llvm::Interpreter::callExternalFunction(llvm::Function*, llvm::ArrayRef<llvm::GenericValue>)':
(.text._ZN4llvm11Interpreter20callExternalFunctionEPNS_8FunctionENS_8ArrayRefINS_12GenericValueEEE+0xd9f): undefined reference to `ffi_type_void'
/usr/lib/libLLVMInterpreter.a(ExternalFunctions.cpp.o): In function `llvm::Interpreter::callExternalFunction(llvm::Function*, llvm::ArrayRef<llvm::GenericValue>)':
(.text._ZN4llvm11Interpreter20callExternalFunctionEPNS_8FunctionENS_8ArrayRefINS_12GenericValueEEE+0x135c): undefined reference to `ffi_type_double'
/usr/lib/libLLVMInterpreter.a(ExternalFunctions.cpp.o): In function `llvm::Interpreter::callExternalFunction(llvm::Function*, llvm::ArrayRef<llvm::GenericValue>)':
(.text._ZN4llvm11Interpreter20callExternalFunctionEPNS_8FunctionENS_8ArrayRefINS_12GenericValueEEE+0x1368): undefined reference to `ffi_type_float'
/usr/lib/libLLVMInterpreter.a(ExternalFunctions.cpp.o): In function `llvm::Interpreter::callExternalFunction(llvm::Function*, llvm::ArrayRef<llvm::GenericValue>)':
(.text._ZN4llvm11Interpreter20callExternalFunctionEPNS_8FunctionENS_8ArrayRefINS_12GenericValueEEE+0x1374): undefined reference to `ffi_type_void'
collect2: error: ld returned 1 exit status

error: aborting due to previous error
Build failed, waiting for other jobs to finish...
error: linking with `cc` failed: exit code: 1
note: "cc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-m64" "-L" "/home/nathan/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "/home/nathan/Desktop/plbc/target/debug/plbi.0.o" "-o" "/home/nathan/Desktop/plbc/target/debug/plbi" "-Wl,--gc-sections" "-pie" "-nodefaultlibs" "-L" "/home/nathan/Desktop/plbc/target/debug" "-L" "/home/nathan/Desktop/plbc/target/debug/deps" "-L" "/usr/lib" "-L" "/home/nathan/Desktop/plbc/target/debug/build/llvm-sys-76a5d702ae8c46e3/out" "-L" "/home/nathan/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bstatic" "-Wl,-Bdynamic" "/home/nathan/Desktop/plbc/target/debug/deps/libgetopts-33691dbdf8852281.rlib" "/home/nathan/Desktop/plbc/target/debug/libplb.rlib" "/home/nathan/Desktop/plbc/target/debug/deps/libuuid-41f66b8ddc6c6059.rlib" "/home/nathan/Desktop/plbc/target/debug/deps/libllvm-6c21f2bf7fd206b5.rlib" "/home/nathan/Desktop/plbc/target/debug/deps/libllvm_sys-3628cf0853e8edea.rlib" "/home/nathan/Desktop/plbc/target/debug/deps/libnom-24d7a34b1cbfee73.rlib" "/home/nathan/Desktop/plbc/target/debug/deps/libcbox-75ae8b50200a40f5.rlib" "/home/nathan/Desktop/plbc/target/debug/deps/libbitflags-1efefdc447eb53f2.rlib" "/home/nathan/Desktop/plbc/target/debug/deps/librand-49a08859d086fffe.rlib" "/home/nathan/Desktop/plbc/target/debug/deps/liblibc-1bd8847afb79f283.rlib" "/home/nathan/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-39b92f95.rlib" "/home/nathan/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-39b92f95.rlib" "/home/nathan/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-39b92f95.rlib" "/home/nathan/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librand-39b92f95.rlib" "/home/nathan/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcollections-39b92f95.rlib" "/home/nathan/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_unicode-39b92f95.rlib" "/home/nathan/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-39b92f95.rlib" "/home/nathan/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc_jemalloc-39b92f95.rlib" "/home/nathan/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-39b92f95.rlib" "/home/nathan/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-39b92f95.rlib" "-l" "ffi" "-l" "LLVMLTO" "-l" "LLVMObjCARCOpts" "-l" "LLVMSymbolize" "-l" "LLVMDebugInfoPDB" "-l" "LLVMDebugInfoDWARF" "-l" "LLVMXCoreDisassembler" "-l" "LLVMXCoreCodeGen" "-l" "LLVMXCoreDesc" "-l" "LLVMXCoreInfo" "-l" "LLVMXCoreAsmPrinter" "-l" "LLVMSystemZDisassembler" "-l" "LLVMSystemZCodeGen" "-l" "LLVMSystemZAsmParser" "-l" "LLVMSystemZDesc" "-l" "LLVMSystemZInfo" "-l" "LLVMSystemZAsmPrinter" "-l" "LLVMSparcDisassembler" "-l" "LLVMSparcCodeGen" "-l" "LLVMSparcAsmParser" "-l" "LLVMSparcDesc" "-l" "LLVMSparcInfo" "-l" "LLVMSparcAsmPrinter" "-l" "LLVMPowerPCDisassembler" "-l" "LLVMPowerPCCodeGen" "-l" "LLVMPowerPCAsmParser" "-l" "LLVMPowerPCDesc" "-l" "LLVMPowerPCInfo" "-l" "LLVMPowerPCAsmPrinter" "-l" "LLVMNVPTXCodeGen" "-l" "LLVMNVPTXDesc" "-l" "LLVMNVPTXInfo" "-l" "LLVMNVPTXAsmPrinter" "-l" "LLVMMSP430CodeGen" "-l" "LLVMMSP430Desc" "-l" "LLVMMSP430Info" "-l" "LLVMMSP430AsmPrinter" "-l" "LLVMMipsDisassembler" "-l" "LLVMMipsCodeGen" "-l" "LLVMMipsAsmParser" "-l" "LLVMMipsDesc" "-l" "LLVMMipsInfo" "-l" "LLVMMipsAsmPrinter" "-l" "LLVMHexagonDisassembler" "-l" "LLVMHexagonCodeGen" "-l" "LLVMHexagonAsmParser" "-l" "LLVMHexagonDesc" "-l" "LLVMHexagonInfo" "-l" "LLVMCppBackendCodeGen" "-l" "LLVMCppBackendInfo" "-l" "LLVMBPFCodeGen" "-l" "LLVMBPFDesc" "-l" "LLVMBPFInfo" "-l" "LLVMBPFAsmPrinter" "-l" "LLVMARMDisassembler" "-l" "LLVMARMCodeGen" "-l" "LLVMARMAsmParser" "-l" "LLVMARMDesc" "-l" "LLVMARMInfo" "-l" "LLVMARMAsmPrinter" "-l" "LLVMAMDGPUCodeGen" "-l" "LLVMAMDGPUAsmParser" "-l" "LLVMAMDGPUDesc" "-l" "LLVMAMDGPUUtils" "-l" "LLVMAMDGPUInfo" "-l" "LLVMAMDGPUAsmPrinter" "-l" "LLVMAArch64Disassembler" "-l" "LLVMAArch64CodeGen" "-l" "LLVMAArch64AsmParser" "-l" "LLVMAArch64Desc" "-l" "LLVMAArch64Info" "-l" "LLVMAArch64AsmPrinter" "-l" "LLVMAArch64Utils" "-l" "LLVMMIRParser" "-l" "LLVMLibDriver" "-l" "LLVMOption" "-l" "LLVMTableGen" "-l" "LLVMLineEditor" "-l" "LLVMX86Disassembler" "-l" "LLVMX86AsmParser" "-l" "LLVMX86CodeGen" "-l" "LLVMSelectionDAG" "-l" "LLVMAsmPrinter" "-l" "LLVMX86Desc" "-l" "LLVMMCDisassembler" "-l" "LLVMX86Info" "-l" "LLVMX86AsmPrinter" "-l" "LLVMX86Utils" "-l" "LLVMMCJIT" "-l" "LLVMPasses" "-l" "LLVMipo" "-l" "LLVMVectorize" "-l" "LLVMLinker" "-l" "LLVMIRReader" "-l" "LLVMAsmParser" "-l" "LLVMDebugInfoCodeView" "-l" "LLVMInterpreter" "-l" "LLVMCodeGen" "-l" "LLVMScalarOpts" "-l" "LLVMInstCombine" "-l" "LLVMInstrumentation" "-l" "LLVMProfileData" "-l" "LLVMBitWriter" "-l" "LLVMOrcJIT" "-l" "LLVMTransformUtils" "-l" "LLVMExecutionEngine" "-l" "LLVMTarget" "-l" "LLVMAnalysis" "-l" "LLVMRuntimeDyld" "-l" "LLVMObject" "-l" "LLVMMCParser" "-l" "LLVMBitReader" "-l" "LLVMMC" "-l" "LLVMCore" "-l" "LLVMSupport" "-l" "rt" "-l" "dl" "-l" "curses" "-l" "pthread" "-l" "z" "-l" "m" "-l" "stdc++" "-l" "util" "-l" "dl" "-l" "pthread" "-l" "gcc_s" "-l" "pthread" "-l" "c" "-l" "m" "-l" "rt" "-l" "util" "-l" "compiler-rt"
note: /usr/lib/libLLVMInterpreter.a(ExternalFunctions.cpp.o): In function `llvm::Interpreter::callExternalFunction(llvm::Function*, llvm::ArrayRef<llvm::GenericValue>)':
(.text._ZN4llvm11Interpreter20callExternalFunctionEPNS_8FunctionENS_8ArrayRefINS_12GenericValueEEE+0x333): undefined reference to `ffi_type_pointer'
/usr/lib/libLLVMInterpreter.a(ExternalFunctions.cpp.o): In function `llvm::Interpreter::callExternalFunction(llvm::Function*, llvm::ArrayRef<llvm::GenericValue>)':
(.text._ZN4llvm11Interpreter20callExternalFunctionEPNS_8FunctionENS_8ArrayRefINS_12GenericValueEEE+0x386): undefined reference to `ffi_type_sint64'
/usr/lib/libLLVMInterpreter.a(ExternalFunctions.cpp.o): In function `llvm::Interpreter::callExternalFunction(llvm::Function*, llvm::ArrayRef<llvm::GenericValue>)':
(.text._ZN4llvm11Interpreter20callExternalFunctionEPNS_8FunctionENS_8ArrayRefINS_12GenericValueEEE+0x397): undefined reference to `ffi_type_sint32'
/usr/lib/libLLVMInterpreter.a(ExternalFunctions.cpp.o): In function `llvm::Interpreter::callExternalFunction(llvm::Function*, llvm::ArrayRef<llvm::GenericValue>)':
(.text._ZN4llvm11Interpreter20callExternalFunctionEPNS_8FunctionENS_8ArrayRefINS_12GenericValueEEE+0x3a9): undefined reference to `ffi_type_sint8'
/usr/lib/libLLVMInterpreter.a(ExternalFunctions.cpp.o): In function `llvm::Interpreter::callExternalFunction(llvm::Function*, llvm::ArrayRef<llvm::GenericValue>)':
(.text._ZN4llvm11Interpreter20callExternalFunctionEPNS_8FunctionENS_8ArrayRefINS_12GenericValueEEE+0x3b2): undefined reference to `ffi_type_sint16'
/usr/lib/libLLVMInterpreter.a(ExternalFunctions.cpp.o): In function `llvm::Interpreter::callExternalFunction(llvm::Function*, llvm::ArrayRef<llvm::GenericValue>)':
(.text._ZN4llvm11Interpreter20callExternalFunctionEPNS_8FunctionENS_8ArrayRefINS_12GenericValueEEE+0x746): undefined reference to `ffi_type_pointer'
/usr/lib/libLLVMInterpreter.a(ExternalFunctions.cpp.o): In function `llvm::Interpreter::callExternalFunction(llvm::Function*, llvm::ArrayRef<llvm::GenericValue>)':
(.text._ZN4llvm11Interpreter20callExternalFunctionEPNS_8FunctionENS_8ArrayRefINS_12GenericValueEEE+0x769): undefined reference to `ffi_prep_cif'
/usr/lib/libLLVMInterpreter.a(ExternalFunctions.cpp.o): In function `llvm::Interpreter::callExternalFunction(llvm::Function*, llvm::ArrayRef<llvm::GenericValue>)':
(.text._ZN4llvm11Interpreter20callExternalFunctionEPNS_8FunctionENS_8ArrayRefINS_12GenericValueEEE+0x7bf): undefined reference to `ffi_call'
/usr/lib/libLLVMInterpreter.a(ExternalFunctions.cpp.o): In function `llvm::Interpreter::callExternalFunction(llvm::Function*, llvm::ArrayRef<llvm::GenericValue>)':
(.text._ZN4llvm11Interpreter20callExternalFunctionEPNS_8FunctionENS_8ArrayRefINS_12GenericValueEEE+0xd52): undefined reference to `ffi_type_sint64'
/usr/lib/libLLVMInterpreter.a(ExternalFunctions.cpp.o): In function `llvm::Interpreter::callExternalFunction(llvm::Function*, llvm::ArrayRef<llvm::GenericValue>)':
(.text._ZN4llvm11Interpreter20callExternalFunctionEPNS_8FunctionENS_8ArrayRefINS_12GenericValueEEE+0xd5e): undefined reference to `ffi_type_double'
/usr/lib/libLLVMInterpreter.a(ExternalFunctions.cpp.o): In function `llvm::Interpreter::callExternalFunction(llvm::Function*, llvm::ArrayRef<llvm::GenericValue>)':
(.text._ZN4llvm11Interpreter20callExternalFunctionEPNS_8FunctionENS_8ArrayRefINS_12GenericValueEEE+0xd6a): undefined reference to `ffi_type_sint32'
/usr/lib/libLLVMInterpreter.a(ExternalFunctions.cpp.o): In function `llvm::Interpreter::callExternalFunction(llvm::Function*, llvm::ArrayRef<llvm::GenericValue>)':
(.text._ZN4llvm11Interpreter20callExternalFunctionEPNS_8FunctionENS_8ArrayRefINS_12GenericValueEEE+0xd7b): undefined reference to `ffi_type_sint8'
/usr/lib/libLLVMInterpreter.a(ExternalFunctions.cpp.o): In function `llvm::Interpreter::callExternalFunction(llvm::Function*, llvm::ArrayRef<llvm::GenericValue>)':
(.text._ZN4llvm11Interpreter20callExternalFunctionEPNS_8FunctionENS_8ArrayRefINS_12GenericValueEEE+0xd87): undefined reference to `ffi_type_sint16'
/usr/lib/libLLVMInterpreter.a(ExternalFunctions.cpp.o): In function `llvm::Interpreter::callExternalFunction(llvm::Function*, llvm::ArrayRef<llvm::GenericValue>)':
(.text._ZN4llvm11Interpreter20callExternalFunctionEPNS_8FunctionENS_8ArrayRefINS_12GenericValueEEE+0xd93): undefined reference to `ffi_type_float'
/usr/lib/libLLVMInterpreter.a(ExternalFunctions.cpp.o): In function `llvm::Interpreter::callExternalFunction(llvm::Function*, llvm::ArrayRef<llvm::GenericValue>)':
(.text._ZN4llvm11Interpreter20callExternalFunctionEPNS_8FunctionENS_8ArrayRefINS_12GenericValueEEE+0xd9f): undefined reference to `ffi_type_void'
/usr/lib/libLLVMInterpreter.a(ExternalFunctions.cpp.o): In function `llvm::Interpreter::callExternalFunction(llvm::Function*, llvm::ArrayRef<llvm::GenericValue>)':
(.text._ZN4llvm11Interpreter20callExternalFunctionEPNS_8FunctionENS_8ArrayRefINS_12GenericValueEEE+0x135c): undefined reference to `ffi_type_double'
/usr/lib/libLLVMInterpreter.a(ExternalFunctions.cpp.o): In function `llvm::Interpreter::callExternalFunction(llvm::Function*, llvm::ArrayRef<llvm::GenericValue>)':
(.text._ZN4llvm11Interpreter20callExternalFunctionEPNS_8FunctionENS_8ArrayRefINS_12GenericValueEEE+0x1368): undefined reference to `ffi_type_float'
/usr/lib/libLLVMInterpreter.a(ExternalFunctions.cpp.o): In function `llvm::Interpreter::callExternalFunction(llvm::Function*, llvm::ArrayRef<llvm::GenericValue>)':
(.text._ZN4llvm11Interpreter20callExternalFunctionEPNS_8FunctionENS_8ArrayRefINS_12GenericValueEEE+0x1374): undefined reference to `ffi_type_void'
collect2: error: ld returned 1 exit status

error: aborting due to previous error
error: Could not compile `plb`.

To learn more, run the command again with --verbose.

What is the status/roadmap of this crate

Hello :-),

I am very interesting by the approach of this crate and I would like to use it. However, I wonder what is the status or the roadmap of this crate? Is it still maintained? Still active?

Thanks!

Won't build

   Compiling llvm-alt v0.5.0
error[E0308]: mismatched types
   --> /home/alex/.cargo/registry/src/github.com-1ecc6299db9ec823/llvm-alt-0.5.0/src/engine.rs:154:109
    |
154 |             let result = engine::LLVMCreateMCJITCompilerForModule(&mut ee, (&*module).into(), &mut options, size, &mut out);
    |                                                                                                             ^^^^ expected `u64`, found `usize`
    |
help: you can convert an `usize` to `u64` and panic if the converted value wouldn't fit
    |
154 |             let result = engine::LLVMCreateMCJITCompilerForModule(&mut ee, (&*module).into(), &mut options, size.try_into().unwrap(), &mut out);
    |                                                                                                             ^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0308`.
error: could not compile `llvm-alt`.

JitEngine::with_function has strange precondition when StructType::cast fails

The logic in fn with_function here seems weird:

            let sig = function.get_signature();
            assert_eq!(Type::get::<R>(ctx), sig.get_return());
            let arg = Type::get::<A>(ctx);
            if let Some(args) = StructType::cast(arg) {
                assert_eq!(sig.get_params(), args.get_elements());
            } else {
                assert_eq!(arg, sig.get_return());
            }

In particular, when the StructType::cast(arg) returns None, it is checking that the return type of the signature matches ... the argument type to the callback (and this is after we have already confirmed that the return type of the signature matches the return type of the callback).

Was this a mistake -- i.e. was your intention to instead assert in the else branch that [arg] == sig.get_params(), (in other words, implicitly promoting a non-struct argument for the callback to a singleton list) ?

Or is there some hidden reasoning behind this that I am missing?

Build script behaves incorrectly on Windows

On Windows, LLVM is installed to C:\Program Files (x86)\LLVM by default.

So when build script calls, for example, llvm-config --ldflags, it returns -LIBPATH:C:\Program Files (x86)\LLVM\lib, and then build script performs .split_whitespace() which breaks those paths and compilation fails (UPD: apparently those are just paths for debug output, but gcc fails as well for the same reasons).

Of course, I can workaround this by temporarily pointing PATH to a separate folder with those binaries, but thought it's worth reporting so that this could be fixed for other users as well.

How to call `JitEngine.with_function` with more than 1 argument

Hello :-),

In your example, you have things like this:

let func = module.add_function("fib", Type::get::<fn(u64) -> u64>(&ctx));let ee = JitEngine::new(&module, JitOptions {opt_level: 0}).unwrap();
ee.with_function(func, |fib: extern fn(u64) -> u64| {
    for i in 0..10 {
        println!("fib {} = {}", i, fib(i))
    }
});

This is fine. func has only one argument. But how to declare 2 arguments?
If I do:

let func = module.add_function("fib", Type::get::<fn(u64, u64) -> u64>(&ctx));

it compiles and the produced IR is correct if I do not do ee.with_function. If I “uncomment” it:

ee.with_function(func, |fib: extern fn(u64, u64) -> u64| {})

does not compile. We have the following error:

error: type mismatch: the type `[closure@source/bin/tvm.rs:200:28: 201:6]` implements the trait `core::ops::FnOnce<(extern "C" fn(u64, u64) -> u64,)>`, but the trait `core::ops::FnOnce<(extern "C" fn(_) -> _,)>` is required (incorrect number of function parameters) [E0281]

I really don't know how to fix this.

cc @pnkfelix, @HeroesGrave, @bryal.

How do I insert intrinsics with this library?

Should those be inserted with special API which is not exposed (and thus require insertion with unsafe { ... } & llvm-sys) or is there a way to insert them using existing Builder APIs?

Trouble building

I built LLVM from source today, so llvm-config --version is 3.9.0svn.
(I also installed Rust today, so cargo --version is cargo 0.7.0-nightly (1af03be 2015-12-08) and rustc --version is rustc 1.6.0 (c30b771ad 2016-01-19).)
I can use LLVM in c++ projects, but I can't use llvm-rs.
I cloned it and ran cargo test, resulting in:

Compiling llvm-alt v0.3.2 (file:///home/koro/llvm-rs)
error: linking with `cc` failed: exit code: 1
note: "cc" "-Wl,--as-needed" "-m64" "-L" "/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib" "/home/koro/llvm-rs/target/debug/examples/tan.0.o" "-o" "/home/koro/llvm-rs/target/debug/examples/tan" "-Wl,--gc-sections" "-pie" "-nodefaultlibs" "-L" "/home/koro/llvm-rs/target/debug" "-L" "/home/koro/llvm-rs/target/debug/deps" "-L" "/usr/local/lib" "-L" "/home/koro/llvm-rs/target/debug/build/llvm-sys-911ba2de1be78b49/out" "-L" "/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bstatic" "-Wl,-Bdynamic" "/home/koro/llvm-rs/target/debug/libllvm.rlib" "/home/koro/llvm-rs/target/debug/deps/libllvm_sys-911ba2de1be78b49.rlib" "/home/koro/llvm-rs/target/debug/deps/libbitflags-7fb3e7f9e3d1842c.rlib" "/home/koro/llvm-rs/target/debug/deps/libcbox-e0efb99b7f89721a.rlib" "/home/koro/llvm-rs/target/debug/deps/liblibc-58e0bfb9440c5f8f.rlib" "/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-ca9f0d77.rlib" "/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcollections-ca9f0d77.rlib" "/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_unicode-ca9f0d77.rlib" "/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/librand-ca9f0d77.rlib" "/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-ca9f0d77.rlib" "/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc_jemalloc-ca9f0d77.rlib" "/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-ca9f0d77.rlib" "/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-ca9f0d77.rlib" "-l" "rt" "-l" "dl" "-l" "pthread" "-l" "z" "-l" "m" "-l" "stdc++" "-l" "c" "-l" "m" "-l" "dl" "-l" "pthread" "-l" "gcc_s" "-l" "pthread" "-l" "c" "-l" "m" "-l" "rt" "-l" "compiler-rt"
note: /home/koro/llvm-rs/target/debug/examples/tan.0.o: In function `cbox..CSemiBox$LT$llvm..module..Module$GT$::drop.4317::h57368b7cc4129623':
tan.0.rs:(.text._ZN42cbox..CSemiBox$LT$llvm..module..Module$GT$9drop.431717h57368b7cc4129623E+0x5a): undefined reference to `LLVMDisposeModule'
/home/koro/llvm-rs/target/debug/examples/tan.0.o: In function `cbox..CSemiBox$LT$llvm..builder..Builder$GT$::drop.4348::hd45b97f5c93d02d9':
tan.0.rs:(.text._ZN44cbox..CSemiBox$LT$llvm..builder..Builder$GT$9drop.434817hd45b97f5c93d02d9E+0x5a): undefined reference to `LLVMDisposeBuilder'
/home/koro/llvm-rs/target/debug/examples/tan.0.o: In function `tan::engine::ExecutionEngine::get_global<llvm::engine::JitEngine,u8>':
/home/koro/llvm-rs/src/engine.rs:72: undefined reference to `LLVMGetPointerToGlobal'
/home/koro/llvm-rs/target/debug/libllvm.rlib(llvm.0.o): In function `llvm::builder::Builder::new':
/home/koro/llvm-rs/src/builder.rs:45: undefined reference to `LLVMCreateBuilderInContext'
... skip a few ...
collect2: error: ld returned 1 exit status

(I get similar "undefined reference" errors when trying to compile examples/fib.rs in a project with llvm-alt as a dependency.)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.