Stream: git-wasmtime

Topic: wasmtime / issue #5260 Any examples to bind host function...


view this post on Zulip Wasmtime GitHub notifications bot (Nov 13 2022 at 10:59):

alexthomas1 opened issue #5260:

I have a WASM file that calls a function in the host, but the name of the label becomes env::_Z5hellov.

How do I register the binding in C++? Thank you!

view this post on Zulip Wasmtime GitHub notifications bot (Nov 13 2022 at 11:36):

bjorn3 commented on issue #5260:

You have to put the function prototype in a extern "C" { ... } block to disable name mangling.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 13 2022 at 17:48):

alexthomas1 commented on issue #5260:

Thank you, I did that and I get

(import "env" "_Z5hellov" (func $hello__ (type 2)))

and

unknown import: env::_Z5hellov has not been defined

when I put the function prototype in the extern block.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 13 2022 at 17:50):

bjorn3 commented on issue #5260:

What is the exact code you used?

view this post on Zulip Wasmtime GitHub notifications bot (Nov 13 2022 at 17:52):

alexthomas1 commented on issue #5260:

I have been trying to modify the example: third_party/wasmtime/examples/hello.c, to load the binary directly (instead of using the wat representation).

`#include <stdio.h>

extern "C" {
void hello();
}

int main(int argc, char **argv){
hello();
}`

This is what my hello.cc looks like.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 13 2022 at 18:03):

alexthomas1 edited a comment on issue #5260:

I have been trying to modify the example: third_party/wasmtime/examples/hello.c, to load the binary directly (instead of using the wat representation).

`#include <stdio.h>

extern "C" {
    void hello();
}

int main(int argc, char **argv){
    hello();
}`

This is what my hello.cc looks like.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 13 2022 at 18:15):

bjorn3 commented on issue #5260:

It works for me: https://godbolt.org/z/YGccKMhWY

__main_argc_argv:                       # @__main_argc_argv
        call    hello
        i32.const       0
        end_function

view this post on Zulip Wasmtime GitHub notifications bot (Nov 13 2022 at 19:10):

alexthomas1 commented on issue #5260:

On the host-side, in third_party/wasmtime/examples/hello.c, how does wasmtime know the correct symbol to use (i.e. hello)?

view this post on Zulip Wasmtime GitHub notifications bot (Nov 13 2022 at 19:13):

bjorn3 commented on issue #5260:

I think it sets hello_callback as the first import, not for the import named "hello".

view this post on Zulip Wasmtime GitHub notifications bot (Nov 13 2022 at 19:22):

alexthomas1 commented on issue #5260:

So when I have multiple imports, how does that work? Are there any examples of this?

I also still get:

unknown import: env::_Z5hellov has not been defined

view this post on Zulip Wasmtime GitHub notifications bot (Nov 13 2022 at 21:03):

alexthomas1 edited a comment on issue #5260:

So when I have multiple imports, how does that work? Are there any examples of this?

I also still get:

unknown import: env::hello has not been defined

view this post on Zulip Wasmtime GitHub notifications bot (Nov 14 2022 at 15:17):

alexcrichton closed issue #5260:

I have a WASM file that calls a function in the host, but the name of the label becomes env::_Z5hellov.

How do I register the binding in C++? Thank you!


Last updated: Nov 22 2024 at 16:03 UTC