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

Loading wasm built with C++ fails: missing fd_close and fd_seek #145

Closed
ivannp opened this issue Jun 14, 2020 · 6 comments
Closed

Loading wasm built with C++ fails: missing fd_close and fd_seek #145

ivannp opened this issue Jun 14, 2020 · 6 comments

Comments

@ivannp
Copy link

ivannp commented Jun 14, 2020

A simple wasm module loads when build with C, malloc and free, but fails to load when build with C++, new and delete. The runtime error from wasmer is:

Error: 3 link errors: (1 of 3) Import not found, namespace: wasi_snapshot_preview1, name: fd_close (2 of 3) Import not found, namespace: wasi_snapshot_preview1, name: fd_seek (3 of 3) Import not found, namespace: wasi_snapshot_preview1, name: fd_write

@sbc100
Copy link
Member

sbc100 commented Jun 15, 2020

What wasi runtime are you trying to run the binary under?

It looks like the runtime is missing fd_seek and fd_write syscalls.

@ivannp
Copy link
Author

ivannp commented Jun 15, 2020

wasmer. Opened an issue there, although I see these functions in their repo. Thanks!

@ivannp
Copy link
Author

ivannp commented Jul 2, 2020

After the above advise, I opened an issues against wasmer. The solution proposed there worked for me.

The following changes made my code work on wasmer:

// Compile the module
wasmer_module_t *module = nullptr;
wasmer_result_t res = wasmer_compile(&module, bytes, len);

// Get the WASI version
Version version = wasmer_wasi_get_version(module);

wasmer_import_object_t *importObj = wasmer_wasi_generate_import_object_for_version(
    static_cast<unsigned char>(version),
    nullptr,
    0,
    nullptr,
    0,
    nullptr,
    0,
    nullptr,
    0);

wasmer_instance_t *instance = NULL;
res = wasmer_module_import_instantiate(&instance, module, importObj);

@sbc100
Copy link
Member

sbc100 commented Jul 3, 2020

I don't think this is an issue with the wasi-sdk is it? can we close this issue?

@sunfishcode
Copy link
Member

This appears to be resolved; feel free to re-open if there's any followup!

kildom pushed a commit to kildom/clang-wasi-port that referenced this issue Jul 14, 2021
master now contains a new v2 beta version of this action that no longer
supports "submodules".   We can update to v2 later once it stabilizes.
alexcrichton pushed a commit to alexcrichton/wasi-sdk that referenced this issue Apr 5, 2023
This brings in the following changes:

f645f49 Update signal macros after upgrade to snapshot1 (WebAssembly#144)
8b3266d github actions: pin checkout action to v1 (WebAssembly#145)
410c660 Use constructor functions for optional init routines. (WebAssembly#142)
fe13053 c header generation updated for reorganized witx ast (WebAssembly#139)
cd74e1d Correct the version of WebAssembly#136 on master (WebAssembly#141)
446cb3f Wasi snapshot preview1 (WebAssembly#140)
54102f0 Ignore rights in libpreopen. (WebAssembly#129)
8c9e1c6 Make the `__original_main` definition weak, fixing -flto. (WebAssembly#138)
cf81683 Optimize `fmin`, `fmax`, etc. (WebAssembly#120)
deb8eae Don't pre-check capabilities in `openat`. (WebAssembly#130)
ca9046d Use consistent style for wasi-libc C source files. (WebAssembly#131)
951cc3e Fix unintended recursion in __wasilibc_register_preopened_fd. (WebAssembly#133)
5216983 Avoid a `strdup` call in `__wasilibc_populate_libpreopen`. (WebAssembly#128)
70099d4 Don't link in libpreopen initialization code when it isn't needed. (WebAssembly#127)
ec4549d Temporarily disable the use of `__heap_base`. (WebAssembly#132)
a214f1c Use __heap_base by dlmalloc (WebAssembly#114)
a94d2d0 Avoid varargs conventions when calling open (WebAssembly#126)
7fcc4f2 Revamp and simplify the libpreopen code. (WebAssembly#110)
eb7230c Remove more unsupported headers. (WebAssembly#123)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants