Skip to content

Duplicate imports #27

Closed
Closed

Description

@maximebedard

Hi! I have a setup where I'm embedding quickjs (with wasi support) and pre-initializing as such:

#[export_name = "wizer.initialize"]
pub extern "C" fn init() {
    let bytes = std::fs::read("./foo.js");
    unsafe {
        Ctx::new().compile(&bytes, "foo.js");
        // ...
    }
}

Turns out I'm having duplicate imports when introspecting the WASM module:

$ wasm2wat out.wasm | grep 'fd_write' | head -n 2
  (import "wasi_snapshot_preview1" "fd_write" (func $_ZN4wasi13lib_generated22wasi_snapshot_preview18fd_write17h33e34a8685c72169E (type 30)))
  (import "wasi_snapshot_preview1" "fd_write" (func $__wasi_fd_write (type 30)))

This seems to be tripping the following assertion https://github.com/bytecodealliance/wizer/blob/main/src/parse.rs#L268.

I'd be happy to open a PR, I'm just unsure what the expectation is in such case. Any idea?

Activity

  1. fitzgen commented on Jul 21, 2021

    @fitzgen
    Member

    Duplicate imports are disallowed by module linking. I'd expect that the module would be rejected before making it that far. So that's a little funny. The root issue here is that your module has duplicate imports, though. That will eventually be fixed in https://bugs.llvm.org/show_bug.cgi?id=50938. In the meantime, you can run wasm-opt -O to deduplicate the imports.

  2. maximebedard commented on Jul 22, 2021

    @maximebedard
    ContributorAuthor

    Amazing, thanks for the link and the tip, I'll try it out with wasm-opt -0. I seemed to have had success when compiling in release mode (which effectively skips this assertion).

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions