Git Product home page Git Product logo

cranelift-jit-demo's Issues

Readme is slightly out of date

Taken from #37:

  • there are a few links to an old version of the cranelift-module crate, for Module and Backend for instance.
  • ditto for cranelift-frontend
  • integer constants is linking to the readthedocs documentation, which is out of date. We should instead link to the IR descriptions (that live here).
  • the links to line numbers of the example programs foo and iterative_fib are off by one.
  • the link to github issues at the bottom is broken and should link to the bytecodealliance/cranelift repository instead.

Change default branch name

As a policy, the Bytecode Alliance is changing the default branch names in all repositories. We would like for all projects to change the default to main by June 26. (We mention June 26th because there is some suggestion that GitHub may be adding the ability to make this process more seamless. Feel free to wait for that, but only up to June 26. We'll provide further support and documentation before that date.)

Please consider this a tracking issue. It is not intended for public debate.

  • Change branch name
  • Update CI
  • Update build scripts
  • Update documentation

How do I call a function with arbitrary arguments?

At first, I appreciate your great effort, thank you for this nice demo of cranelift-jit.
I love this demo a lot.

My question is, it seems that functions are called with input of tuple. For example, (1, 0) is passed as arguments in the call below.

unsafe { run_code(jit, FOO_CODE, (1, 0)) }

But tuple's number of elements cannot be defined dynamically. Let's say, a user defines a function with 5 arguments, then Rust program must supply a tuple of 5 elements as an input (arguments) to run the function.

But Rust program cannot know how many arguments a user defines for a function before compilation, so I think it is impossible to define them as tuple. So how can I pass such arguments to a function?

How can I get type of Value?

This demo is great, so I'm enjoying creating some software with this, but currently I'm struggling to get type of "Value" of cranelift. How can I check if string is inside or if number is inside Value? Or can we use this immediate instead of Value?

Ability to call JIT-compiled function without hard-coding function signature with mem::transmute

In the example provided, the function signature for the to-be compiled code-string must be known in advance in order to be able to call into the function properly.

https://github.com/CraneStation/simplejit-demo/blob/4b7b8099346d877fe559dd5b593b18344d62e30d/src/toy.rs#L47

Is it possible to make a call dynamically using an array of parameters instead of being required to mem::transmute to the correct function signature?

Jit demo does "PermissionDenied"

my OS: Fedora 33,
Rust: 1.49.0

so when I do cargo run in "cranelift-jit-demo-main" it compiles but then:

thread 'main' panicked at 'unable to make memory readable+executable: SystemCall(Os { code: 13, kind: PermissionDenied, message: "Permission denied" })', /home/adsick/.cargo/registry/src/github.com-1ecc6299db9ec823/cranelift-simplejit-0.68.0/src/memory.rs:197:30
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

why is it so and how do I fix it (or rather it should be fixed somewhere in the actual project, I dunno)

Add example that uses `load` and `store`

I've been trying to create a fixed length of memory and load from it. I keep getting

terminated by signal SIGSEGV (Address boundary error)

If you could add an example showing such a usecase it would be very helpful.

using cranelift-simplejit inside a "rust compiled to wasm" application

Hi,

I am writing an in browser application via Rust compiled to wasm. In this in-browser application, I would like to be able to dynamically generate code and call it. Is it possible to do this via cranelift-simplejit ? [I am having problem building it for the wasm32-unknown-unknown target.]

Thanks!

Demo also runs in Windows

I removed the assert to see that the demo does work in Windows. I haven't dug in further to see why it works, but figured I'd share.

Not compiled on fedora with 'selinux-fix' feature

Error when compile on linux with
cranelift-jit = { version = "0.79", features = ['selinux-fix'] }
With versions 0.77, 0.78 also not compiled.

error[E0308]: mismatched types
--> /home/ali/.cargo/registry/src/github.com-1ecc6299db9ec823/cranelift-jit-0.79.0/src/memory.rs:37:9
|
35 | fn with_size(size: usize) -> io::Result {
| ---------------- expected std::result::Result<PtrLen, std::io::Error> because of return type
36 | let alloc_size = region::page::ceil(size);
37 | / MmapMut::map_anon(alloc_size).map(|mut mmap| {
38 | | // The order here is important; we assign the pointer first to get
39 | | // around compile time borrow errors.
40 | | Ok(Self {
... |
44 | | })
45 | | })
| |__________^ expected struct PtrLen, found enum std::result::Result
|
= note: expected enum std::result::Result<PtrLen, _>
found enum std::result::Result<std::result::Result<PtrLen, _>, _>

EXC_BAD_ACCESS on OSX

Tys-MacBook-Pro-2:simplejit-demo tyoverby$ lldb target/debug/toy
(lldb) target create "target/debug/toy"
Current executable set to 'target/debug/toy' (x86_64).
(lldb) run
Process 82396 launched: '/Users/tyoverby/clean/simplejit-demo/target/debug/toy' (x86_64)
the answer is: 42
recursive_fib(10) = 55
iterative_fib(10) = 55
Process 82396 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=2, address=0x102800408)
    frame #0: 0x00007fff684413b8 libsystem_malloc.dylib`small_free_list_add_ptr + 314
libsystem_malloc.dylib`small_free_list_add_ptr:
->  0x7fff684413b8 <+314>: movb   %r10b, 0x8(%rdx)
    0x7fff684413bc <+318>: movq   $0x0, (%rdx)
    0x7fff684413c3 <+325>: movq   %rax, %r10
    0x7fff684413c6 <+328>: shrq   $0x8, %r10
Target 0: (toy) stopped.
(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=2, address=0x102800408)
  * frame #0: 0x00007fff684413b8 libsystem_malloc.dylib`small_free_list_add_ptr + 314
    frame #1: 0x00007fff6844d4f3 libsystem_malloc.dylib`free_small + 921
    frame #2: 0x00007fff68442d87 libsystem_malloc.dylib`szone_memalign + 1126
    frame #3: 0x00007fff684428d9 libsystem_malloc.dylib`malloc_zone_memalign + 154
    frame #4: 0x00007fff68444386 libsystem_malloc.dylib`posix_memalign + 25
    frame #5: 0x000000010005dae5 toy`cretonne_simplejit::memory::PtrLen::with_size::hfa3dd636d07d161e(size=12) at memory.rs:25
    frame #6: 0x000000010005ddbb toy`cretonne_simplejit::memory::Memory::allocate::h918029ba354eb4c1(self=0x00007ffeefbff3f8, size=12) at memory.rs:75
    frame #7: 0x0000000100059f3e toy`_$LT$cretonne_simplejit..backend..SimpleJITBackend$u20$as$u20$cretonne_module..backend..Backend$GT$::define_data::h573815a0e058ec5a(self=0x00007ffeefbff378, _name=(data_ptr = "hello_string\x04", length = 12), data=0x00007ffeefbff2a0, _namespace=0x00007ffeefbfe5b0) at backend.rs:159
    frame #8: 0x000000010003f81c toy`_$LT$cretonne_module..module..Module$LT$B$GT$$GT$::define_data::h2a9842b185d866dd(self=0x00007ffeefbff320, data=(__0= 0), data_ctx=0x00007ffeefbff2a0) at module.rs:517
    frame #9: 0x000000010004679a toy`toy::jit::JIT::create_data::h8851a848fef777bc(self=0x00007ffeefbfe9a8, name=(data_ptr = "hello_stringhello world", length = 12), contents=<unavailable>) at jit.rs:125
    frame #10: 0x00000001000422d8 toy`toy::main::hd9bd26c7b8da2354 at toy.rs:122
    frame #11: 0x000000010003a8c2 toy`std::rt::lang_start::_$u7b$$u7b$closure$u7d$$u7d$::hfac8eb5e2ec564ba at rt.rs:74
    frame #12: 0x00000001002a9db8 toy`std::panicking::try::do_call::h6688c75b958424d8 [inlined] std::rt::lang_start_internal::_$u7b$$u7b$closure$u7d$$u7d$::h577272da3909533e at rt.rs:59 [opt]
    frame #13: 0x00000001002a9dac toy`std::panicking::try::do_call::h6688c75b958424d8 at panicking.rs:305 [opt]
    frame #14: 0x00000001002bd0bf toy`__rust_maybe_catch_panic at lib.rs:101 [opt]
    frame #15: 0x00000001002a6878 toy`std::rt::lang_start_internal::h1d7922f9dfd201cc [inlined] std::panicking::try::h6dbcd1a44c5bb721 at panicking.rs:284 [opt]
    frame #16: 0x00000001002a6845 toy`std::rt::lang_start_internal::h1d7922f9dfd201cc [inlined] std::panic::catch_unwind::hdd63a658020b6001 at panic.rs:361 [opt]
    frame #17: 0x00000001002a6845 toy`std::rt::lang_start_internal::h1d7922f9dfd201cc at rt.rs:58 [opt]
    frame #18: 0x000000010003a8a2 toy`std::rt::lang_start::heba532bdd26b7181(main=(toy`toy::main::hd9bd26c7b8da2354 at toy.rs:10), argc=1, argv=0x00007ffeefbff818) at rt.rs:74
    frame #19: 0x0000000100042395 toy`main + 37
    frame #20: 0x00007fff68297115 libdyld.dylib`start + 1
    frame #21: 0x00007fff68297115 libdyld.dylib`start + 1
(lldb)

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.