Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support to bind wasm #2658

Open
HerrCai0907 opened this issue Feb 26, 2023 · 3 comments
Open

support to bind wasm #2658

HerrCai0907 opened this issue Feb 26, 2023 · 3 comments

Comments

@HerrCai0907
Copy link
Member

HerrCai0907 commented Feb 26, 2023

Feature suggestion

I think it will improve the software community ecology if we can support bind wasm which satisfies the requirement of linking. It means we can call c/c++(maybe other language based on LLVM like rust but I don't try it) function in assemblyscript.

How to implement in assemblyscript:

First step we can add a command line option to preload one wasm file and add it into Program instance and then compile wasm module.
Second step maybe statement like import * as xxx from "xxx.wasm" can be supported, but it needs more effort.

I wonder if this proposal meets the roadmap of the community and if this PR can be merged into main.

How to handle multiple memory manager:

Memory.grow in wasm should be checked and it will trigger a compile-time Error.
For c/cpp, most of code will alloc memory by malloc / free / realloc in libc, so it can be resolved by using custom libc. e.g. https://github.com/WebAssembly/wasi-sdk

@CountBleck
Copy link
Member

On a sidenote, specifying MALLOC_IMPL=none when compiling wasi-libc won't compile any malloc implementation, which lets us provide our own. Alternatively, we could fork wasi-libc and add our own implementation there.

@HerrCai0907
Copy link
Member Author

On a sidenote, specifying MALLOC_IMPL=none when compiling wasi-libc won't compile any malloc implementation, which lets us provide our own.

I think it is enough, we need to design some way to bind the import and export from wasm to as.

@dcodeIO
Copy link
Member

dcodeIO commented Mar 3, 2023

First step we can add a command line option to preload one wasm file and add it into Program instance and then compile wasm module.

There is more to this if we want to link properly. For instance, if the preloaded module has a static memory region and a heap region, besides reusing an existing / providing a shared malloc/free, AS would still need to add to the static memory region, which then conflicts with the preloaded module's heap region that typically starts right after. Can't get around relocatable modules, likely with some metadata, akin to what the dylink section does.

Forget about wasi-libc btw., that's overly specific and won't really help with linking anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants