go-plugin
go-plugin copied to clipboard
Plugin is not compiling with tinygo v0.29.0
I posted an issue in tinygo repo, as I believe it's related to compiler, at least when it comes to Windows. However I'm not sure about Linux.
So I just cross-post original issue here as you guys may know better the reason which causing it:
I have some code using knqyf263/go-plugin which compiles with no problem ~~on both Windows and Linux platforms~~ using tinygo v0.28.1. However it stopped working after upgrade to v0.29.0:
~~On Windows:~~
task: [plugin] tinygo build -o wasm/plugin.wasm -scheduler=none -target=wasi --no-debug ./wasm
# os
c:\tinygo\src\os\stat_linuxlike.go:18:6: fillFileStatFromSys redeclared in this block
c:\tinygo\src\os\stat_linux.go:14:6: other declaration of fillFileStatFromSys
c:\tinygo\src\os\stat_linuxlike.go:50:6: timespecToTime redeclared in this block
c:\tinygo\src\os\stat_linux.go:46:6: other declaration of timespecToTime
c:\tinygo\src\os\stat_linuxlike.go:55:6: atime redeclared in this block
c:\tinygo\src\os\stat_linux.go:51:6: other declaration of atime
exit status 1~~
On Linux:
task: [plugin] tinygo build -o wasm/plugin.wasm -scheduler=none -target=wasi --no-debug ./wasm
tinygo:wasm-ld: warning: function signature mismatch: log
>>> defined as (i32, i32) -> i64 in lto.tmp
>>> defined as (f64) -> f64 in /usr/local/lib/tinygo/lib/wasi-libc/sysroot/lib/wasm32-wasi/libc.a(log.o)
task: [run] go build && ./test-wasm-plugin
Caught panic as *fmt.wrapError: wasm error: unreachable
wasm stack trace:
.interface:{HttpGet:func:{named:context.Context,pointer:named:gitlab.com/***/test-wasm-plugin/api.HttpGetReq}{pointer:named:gitlab.com/***/test-wasm-plugin/api.HttpGetResp,named:error},Log:func:{named:context.Context,pointer:named:gitlab.com/***/test-wasm-plugin/api.LogReq}{pointer:named:github.com/knqyf263/go-plugin/types/known/emptypb.Empty,named:error}}.Log$invoke(i32,i32)
.(main.MyPlugin).SendRequest(i32,i32)
.greeter_send_request(i32,i32) i64
Upd.: problem on Windows was due to broken installation please disregard this part.
It appears that for some reason Log method is conflicting with some log function in libc. This little change solves the issues above:
So the open questions are:
- Why this worked with no problems on tinygo v0.28.1?
- Are there any other reserved (?) function names such as
login libc which can't be used as method names?
Why this worked with no problems on tinygo v0.28.1
After some researching, I think the reason is basically this generated code when we use Log method name to become a host function:
//go:wasm-module env
//export log
//go:linkname _log
func _log(ptr uint32, size uint32) uint64