Comments (13)
you are not using Linker::func_new
I have no idea if one way to do things is better than the other 🤷
or even better Linker::func_wrap?
I need to be able to accept unresolved imports. If a function name is not recognized by smoldot, the VM should still be able run, and errors should happen only if the function is actually called. To achieve that, I can't know the function signature at compilation time.
And I use the same code for both recognized and unrecognized functions by convenience.
Does using Linker::func_new or Linker::func_wrap solve your issues?
func_new
doesn't solve it, no.
from wasmi.
does enabling the new no-hash-maps crate feature of Wasmi solve your issues?
It doesn't compile:
error[E0432]: unresolved imports `std::cmp`, `std::mem`, `std::ops`
--> /Users/tomaka/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wasmi_collections-0.1.0/src/string_interner/detail.rs:4:5
|
4 | cmp::Ordering,
| ^^^ could not find `cmp` in `std`
5 | collections::{btree_map::Entry, BTreeMap},
6 | mem,
| ^^^ no `mem` in the root
7 | ops::Deref,
| ^^^ could not find `ops` in `std`
|
= help: consider importing one of these items instead:
core::mem
std::mem
For more information about this error, try `rustc --explain E0432`.
error: could not compile `wasmi_collections` (lib) due to 1 previous error
from wasmi.
If I activate both std
and no-hash-maps
, the issue is fixed.
from wasmi.
smoldot does not propagate its std feature
Smoldot is entirely no-std
. Smoldot's std
feature is completely disconnected from the VM.
enabling either wasmi/std, wasmi/no-hash-maps
I'm happy to enable no-hash-maps
if it compiles.
from wasmi.
@tomaka I opened this PR to fix no_std
+no-hash-maps
builds which should help you until the underlying issue is properly fixed.
If you can confirm me that the PR fixes your issue for now I will create another beta release today and work on the proper fix in the meantime.
from wasmi.
@tomaka I released Wasmi version 0.32.0-beta.14
with the proper fix included.
from wasmi.
@tomaka thanks for reporting the bug, I am going to investigate it with high priority.
My random guess as what might be causing trouble is the fact that I'm using the generic function constructor:
Is there a specific reason as to why you are not using Linker::func_new
or even better Linker::func_wrap
?
Does using Linker::func_new
or Linker::func_wrap
solve your issues?
from wasmi.
Okay, very weird question but does enabling the new no-hash-maps
crate feature of Wasmi solve your issues?
from wasmi.
smol-dot/smoldot#1817 udpates from beta.10
directly to beta.13
. Can you tell me which was the last working beta.N
?
I built smoldot
locally and can confirm that Wasmi v0.32.0-beta.12
still worked and the problems started with Wasmi v0.32.0-beta.13
.
from wasmi.
I took one of the failing smoldot tests and re-created a regression test in the Wasmi repository, however, I somehow cannot reproduce it there. Can you please take a look and maybe tell me what smoldot is doing differently?
#[test]
fn smoldot_regression() {
use crate::{Engine, Func, Linker, Memory, Module, Store};
let wasm = wat::parse_str(
r#"
(module
(import "host" "hello" (func $host_hello (param i32) (result i32)))
(import "env" "memory" (memory $mem 0 4096))
(func (export "hello") (result i32)
(call $host_hello (i32.const 3))
(i32.const 2)
i32.add
)
)"#,
)
.unwrap();
let engine = Engine::default();
let mut store = Store::new(&engine, ());
let module = Module::new(&engine, &wasm[..]).unwrap();
let mut linker = <Linker<()>>::new(&engine);
for import_type in module.imports() {
let name = import_type.import_name();
match import_type.ty() {
ExternType::Memory(memory_type) => {
let memory = Memory::new(&mut store, memory_type.clone()).unwrap();
linker.define(name.module(), name.name(), memory).unwrap();
}
ExternType::Func(func_type) => {
let func = Func::new(
&mut store,
func_type.clone(),
|_caller, _params, _results| unimplemented!(),
);
linker.define(name.module(), name.name(), func).unwrap();
}
ExternType::Global(_) => unimplemented!(),
ExternType::Table(_) => unimplemented!(),
}
}
// In smoldot this call fails ...
linker.instantiate(&mut store, &module).unwrap();
}
from wasmi.
I debugged it some more in smoldot
:
This call fails:
https://github.com/smol-dot/smoldot/blob/61cf6a956907f384e8ed3225a4145ff47b8bb26b/lib/src/executor/vm/interpreter.rs#L178
Because wasmi::Linker::get("host", "hello")
at this point returns None
when not enabling wasmi/no-hash-maps
crate feature. I have not yet figured out why. My base assumption is that this is connected to the wasmi_collections::StringInterner
which returns consecutive indices for Symbol
in no-hash-maps
mode and non-consecutive Symbol
indices otherwise. Unfortunately I am unable to reproduce this at Wasmi locally ...
from wasmi.
I figured out that I cannot reproduce this directly inside the Wasmi crate test suite since the Wasmi test suite does not compile under no_std
but the error in smoldot
only happens in Wasmi's no_std
mode without the no-hash-maps
feature enable. Thus enabling either wasmi/std
, wasmi/no-hash-maps
or both will fix the issue on the smoldot
side.
@tomaka smoldot
does not propagate its std
feature for its wasmi
dependency. Is this an oversight or wanted behavior?
from wasmi.
This minimized Wasmi test case fails only if both std
and no-hash-maps
crate features are disabled:
#[test]
fn min_smoldot_regression() {
let mut interner = crate::collections::StringInterner::new();
let sym = interner.get_or_intern("hello");
assert_eq!(interner.get("hello"), Some(sym));
}
Reason being that in the aforementioned mode make_hash
calls in StringInterner::{get, get_or_intern}
return different hashes for the same string which is obviously incorrect. As of now I have no clue why. On std
mode everything seems to work. So my best guess is that it has something to do with how wasmi_collections
use ahash
in no_std
mode.
from wasmi.
Related Issues (20)
- Add customizable `wasmi::Engine` limits
- Reconsider proper fuel charging for lazily compiled functions
- Reduce `wasmi::Engine` memory consumption for storing function artifacts HOT 3
- Try to put the Wasmi engine internals into its own crate
- Wasmi v0.32 stable release preparations
- CLI: cannot find definition for imported function HOT 4
- Performance regression since `v0.32-beta.16` for `debug` builds with profile overwrites HOT 7
- Optimize `Instance` handling in the `CallStack` HOT 1
- Thoughts on js-promise-integration HOT 4
- Redundant `local.tee` instruction with overwriting semantics causes miscompilation HOT 13
- Add `Store::call_hook` API HOT 4
- Add way to access unknown custom sections in `Module`
- Implement stable fuel metering HOT 6
- Implement support for `wasi-nn` HOT 1
- Failed to install `wasmi_cli`: `raw mutable pointers are not allowed in statics` (Rust 1.77.1) HOT 4
- How does the executor calculate i32 binary opcodes? HOT 2
- Prepare Wasmi bytecode, translator and executor for tail-call based instruction dispatch
- CI: fuzzing CI seems to not cache the corpus
- Make `CodeMap` lock-free
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wasmi.