Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin is not compiling with tinygo v0.29.0 #57

Open
inliquid opened this issue Aug 29, 2023 · 2 comments
Open

Plugin is not compiling with tinygo v0.29.0 #57

inliquid opened this issue Aug 29, 2023 · 2 comments

Comments

@inliquid
Copy link
Contributor

inliquid commented Aug 29, 2023

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.

@inliquid
Copy link
Contributor Author

inliquid commented Sep 2, 2023

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 log in libc which can't be used as method names?

@inliquid
Copy link
Contributor Author

inliquid commented Sep 3, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant