Skip to content

Cannot define fd_write in an imported package #1648

@fgsch

Description

@fgsch

Due to constraints in my environment, fd_write needs to be imported from wasi_snapshot_preview1.
This is possible if it is defined in the main package, for example using the following:

//go:wasm-module wasi_snapshot_preview1
//export fd_write
func placeholder() int32

or, using a similar signature:

//go:wasm-module wasi_snapshot_preview1
//export fd_write
func fd_write(int32, *int32, int32, *int32) int32

But using either of these approaches in an imported package fails with:

Attribute after last parameter!
i32 ()* @fd_write
Incorrect number of arguments passed to called function!
  %3 = call i32 @fd_write(i32 1, %runtime.__wasi_iovec_t* @runtime.putcharIOVec, i32 1, i32* @runtime.putcharNWritten)
error: verification error after IR construction

or:

Call parameter type does not match function signature!
%runtime.__wasi_iovec_t* @runtime.putcharIOVec
 i32*  %3 = call i32 @fd_write(i32 1, %runtime.__wasi_iovec_t* @runtime.putcharIOVec, i32 1, i32* @runtime.putcharNWritten)
error: verification error after IR construction

respectively.
I'm not sure if there is a way to match the signature as runtime.__wasi_iovec_t is not exported.

Tinygo version:

tinygo version 0.16.0 darwin/amd64 (using go version go1.15.8 and LLVM version 10.0.1)

Metadata

Metadata

Assignees

No one assigned

    Labels

    wasmWebAssembly

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions