-
Notifications
You must be signed in to change notification settings - Fork 112
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
Add some option to disable the wasm-shim #250
Comments
Hi, and thanks for the report! I can look into adding a |
Added a
|
Thank you for investigating as well! If you look at your wasm32 output module with wasm2wat, do you still see the imports? I also agree solving that problem would be preferable, but I greatly appreciate the new feature as a fix! |
(Disclaimer: I have zero experience building stuff for wasm.) There is a I then see 3
Using |
This issue is getting weirder. I have two different WASM modules that both depend on zstd-sys:
Both set |
Perhaps this discrepancy could be since I use the stream API from zstd but perhaps sz3 uses some code path that does need to allocate? |
Looking at both output modules again, I can see that the first does export all symbols from the wasm-shim, while they are missing from the second. I might have an idea, but will see if it's the right one. |
Ok, this seems to be an issue in Rust itself (rust-lang/rust#50007 is the closest I could find, even though that one says it is fixed). The issue can be fixed by re-exporting the wasm-shim symbols into the top-level shared library. Thank you so much for your help investigating this issue! For now, I would recommend to change the following: zstd-rs/zstd-safe/zstd-sys/src/lib.rs Lines 12 to 13 in 92f87dc
to: #[cfg(all(not(feature = "no_wasm_shim"), target_arch = "wasm32"))]
#[doc(hidden)]
// If you come across an error similar to
// "cannot find definition for import env::rust_zstd_wasm_shim_malloc"
// when loading a wasm module with zstd-sys, try re-exporting all symbols
// in this module in your top-level WASM shared library module.
pub mod wasm_shim; |
I've been thinking about it some more and here is my best understanding. From my understanding of As I am currently using my own for of |
I stumbled across rust-lang/rust#94348 (comment), which seems to work for me - just add With this, my new suggestion would be to change my above suggestion to #[cfg(all(not(feature = "no_wasm_shim"), target_arch = "wasm32"))]
// If you come across an error similar to
// "cannot find definition for import env::rust_zstd_wasm_shim_malloc"
// when loading a wasm module with zstd-sys, try adding an
// `extern crate zstd_sys` to your crate.
mod wasm_shim; |
As discussed in gyscos#250, in some cases the definitions of `malloc`, `free`, and `calloc` are used but don't get linked in, leading to undefined symbols (i.e. reference to the symbol in "env"). I was not able to determine exactly why this is happening, but it seems to be related to `malloc`, `calloc`, and `free` being defined as inline functions. When building in debug mode there are undefined symbols; when building in release mode there are not, presumably because the functions are inlined. Switching to macros avoids issues of inlining and fixes this issue for me.
As discussed in #250, in some cases the definitions of `malloc`, `free`, and `calloc` are used but don't get linked in, leading to undefined symbols (i.e. reference to the symbol in "env"). I was not able to determine exactly why this is happening, but it seems to be related to `malloc`, `calloc`, and `free` being defined as inline functions. When building in debug mode there are undefined symbols; when building in release mode there are not, presumably because the functions are inlined. Switching to macros avoids issues of inlining and fixes this issue for me.
…cos#275) As discussed in gyscos#250, in some cases the definitions of `malloc`, `free`, and `calloc` are used but don't get linked in, leading to undefined symbols (i.e. reference to the symbol in "env"). I was not able to determine exactly why this is happening, but it seems to be related to `malloc`, `calloc`, and `free` being defined as inline functions. When building in debug mode there are undefined symbols; when building in release mode there are not, presumably because the functions are inlined. Switching to macros avoids issues of inlining and fixes this issue for me.
Thank you for your great library! I am compiling
zstd-sys
forwasm32-wasi
in an environment with wasi-sdk, which exposes the WASI stdlib to C and C++. I am also trying to not have any additional WASM imports in the resulting module. Unfortunately, building with the current wasm-shim results in several symbols needing to be imported, e.g.env::rust_zstd_wasm_shim_malloc
. If I instead remove both the C and Rust sides of the wasm-shim, everything compiles (withwasi-sdk
) and runs without issues. Could there perhaps be some way to disable the wasm-shim / to fix the underlying issue thatzstd-sys
ends up with several symbols needing to be imported? Thanks for your help!The text was updated successfully, but these errors were encountered: