Skip to content

wasm-smith does not support --available-imports with GC types #2110

Open
@mobsceneZ

Description

@mobsceneZ

Hi developers, I try to leverage wasm-smith to generate random Wasm modules with the specified imports and exports. However, when passing the following Wasm module to the --available-imports option, wasm-smith (commit 4355604) panicked:

thread 'main' panicked at crates/wasm-smith/src/core.rs:1309:37:
could not parse type section: BinaryReaderError { inner: BinaryReaderErrorInner { message: "gc proposal not supported", kind: Custom, offset: 11, needed_hint: None } }
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace

(module
  (rec
    (type (sub final (array (mut i32))))
    (type (sub final (func (param i32) (result i32))))
  )
  (import "a" "f1" (func (type 1)))
  (import "a" "m1" (memory (;0;) 43153 57698))
)

The provided module itself is valid, thus I manually checked out the panicked location. As it turns out, the into_iter_err_on_gc_types() public function of the wasmparser crate assumes each recursive group contains exactly one function type, which IMO makes no sense for wasm-smith since GC proposal is now standardized:

pub fn into_iter_err_on_gc_types(self) -> impl Iterator<Item = Result<FuncType>> + 'a {
self.into_iter_with_offsets().map(|item| {
let (offset, group) = item?;
let mut types = group.into_types();
let ty = match (types.next(), types.next()) {
(Some(ty), None) => ty,
_ => bail!(offset, "gc proposal not supported"),
};
if !ty.is_final || ty.supertype_idx.is_some() {
bail!(offset, "gc proposal not supported");
}
match ty.composite_type.inner {
CompositeInnerType::Func(f) => Ok(f),
CompositeInnerType::Array(_) | CompositeInnerType::Struct(_) => {
bail!(offset, "gc proposal not supported");
}
CompositeInnerType::Cont(_) => {
bail!(offset, "stack switching proposal not supported");
}
}
})
}

I think maybe we should update the related code logic for wasm-smith crate to better support the GC proposal? If you think this is appropriate but don't have time to implement these changes yet, I can submit a PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingwasm-smithRelated to the wasm-smith crate and creating wasm modules for fuzzing

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions