gopherjs icon indicating copy to clipboard operation
gopherjs copied to clipboard

fmt.Println() panics

Open Michael-F-Ellis opened this issue 3 years ago • 4 comments

Just installed gopherjs and go1.17.2 on my mac. Calls to fmt.Println() are panicking in the browser. I've reduced it to the simplest possible test case:

package main

import "fmt"

func main() {
	fmt.Println("Hello, GopherJs")
}

No errors or warning when transpiling. The error reported in the browser (via devtools) is:

Uncaught Error: runtime error: native function not implemented: internal/abi.FuncPCABI0
    at $callDeferred (..js:1506)
    at $panic (..js:1549)
    at throw$1 (runtime.go:384)
    at Object.FuncPCABI0 (wrap.go:103)
    at write (zsyscall_darwin_amd64.go:1635)
    at Write (syscall_unix.go:214)
    at ignoringEINTRIO (fd_unix.go:582)
    at Object.$packages.internal/poll.FD.ptr.Write (fd_unix.go:275)
    at Object.$packages.os.File.ptr.write (file_posix.go:49)
    at Object.$packages.os.File.ptr.Write (file.go:176)
    at Fprintln (print.go:265)
    at Object.Println (..js:23892)
    at main (main.go:6)
    at $init (..js:25201)
    at $goroutine (..js:1569)
    at $runScheduled (..js:1609)
    at $schedule (..js:1625)
    at $go (..js:1601)
    at ..js:25213
    at ..js:25216

Paths and system info:

% uname -a
Darwin michaels-mbp.lan 19.6.0 Darwin Kernel Version 19.6.0: Thu Sep 16 20:58:47 PDT 2021; root:xnu-6153.141.40.1~1/RELEASE_X86_64 x86_64

% which go
/usr/local/go/bin/go

% go version
go version go1.17.2 darwin/amd64

% gopherjs version
GopherJS 1.17.0+go1.17.1

I'm new to gopherjs (but not to Go) so this is probably some silly configuration issue but darned if I can figure it out. Any help appreciated!

Michael-F-Ellis avatar Oct 11 '21 22:10 Michael-F-Ellis

FWIW, I found the following on FuncPCABI0 at https://cs.opensource.google/go/go/+/master:src/internal/abi/abi.go;l=99

// FuncPC* intrinsics.
//
// CAREFUL: In programs with plugins, FuncPC* can return different values
// for the same function (because there are actually multiple copies of
// the same function in the address space). To be safe, don't use the
// results of this function in any == expression. It is only safe to
// use the result as an address at which to start executing code.

// FuncPCABI0 returns the entry PC of the function f, which must be a
// direct reference of a function defined as ABI0. Otherwise it is a
// compile-time error.
//
// Implemented as a compile intrinsic.
func FuncPCABI0(f interface{}) uintptr

Michael-F-Ellis avatar Oct 11 '21 22:10 Michael-F-Ellis

Hi @Michael-F-Ellis, thanks for a well-written report! This is probably a regression that happened when we upgraded to Go 1.17... Neither of the current maintainers use Macs, so this happens with disappointing regularity 😟 Since you are targeting browser, you can avoid this problem by building with GOOS=linux, I think this should fix the problem in the short term.

In the longer term I started work on https://github.com/gopherjs/gopherjs/issues/693#issuecomment-932964199, so in some near future GopherJS will stop using darwin sources entirely.

@flimzy what are your thoughts on our GOOS=darwin support? This is probably fifth or so report within the last half a year. The only case where darwin support matters is when someone is using GopherJS with NodeJS on a mac. Anecdotally everyone who reported an issue of this type was targeting browser and was ok with GOOS=linux workaround. Until #693 is done, we could probably just default to GOOS=linux and print some kind of error if we detect that we are running on Node on MacOS.

nevkontakte avatar Oct 11 '21 22:10 nevkontakte

Thanks for the quick response! GOOS=linux works for both the simple case and the real app I'm converting from wasm.

Michael-F-Ellis avatar Oct 11 '21 23:10 Michael-F-Ellis

@nevkontakte I think defaulting to GOOS=linux makes sense, as it's a clear improvement over the current state.

If we determine that's not sufficient for some people, we can consider adding proper darwin support in the future?

flimzy avatar Jan 03 '22 16:01 flimzy