go: runtime: gopls -v crashes immediately when linked with Xcode 15 beta

gopls version

Tested both 0.11.0 and 0.12.4. Cannot capture version output, as it crashes immediately on launch. Output is:

fatal: morestack on g0

go env

GO111MODULE=“” GOARCH=“arm64” GOBIN=“” GOCACHE=“/Users/matt/Library/Caches/go-build” GOENV=“/Users/matt/Library/Application Support/go/env” GOEXE=“” GOEXPERIMENT=“” GOFLAGS=“” GOHOSTARCH=“arm64” GOHOSTOS=“darwin” GOINSECURE=“” GOMODCACHE=“/Users/matt/go/pkg/mod” GONOPROXY=“” GONOSUMDB=“” GOOS=“darwin” GOPATH=“/Users/matt/go” GOPRIVATE=“” GOPROXY=“https://proxy.golang.org,direct” GOROOT=“/opt/homebrew/Cellar/go/1.20.5/libexec” GOSUMDB=“sum.golang.org” GOTMPDIR=“” GOTOOLDIR=“/opt/homebrew/Cellar/go/1.20.5/libexec/pkg/tool/darwin_arm64” GOVCS=“” GOVERSION=“go1.20.5” GCCGO=“gccgo” AR=“ar” CC=“cc” CXX=“c++” CGO_ENABLED=“1” GOMOD=“/dev/null” GOWORK=“” CGO_CFLAGS=“-O2 -g” CGO_CPPFLAGS=“” CGO_CXXFLAGS=“-O2 -g” CGO_FFLAGS=“-O2 -g” CGO_LDFLAGS=“-O2 -g” PKG_CONFIG=“pkg-config” GOGCCFLAGS=“-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/9_/q1rgv_js2rb518ql_svng32c0000gn/T/go-build3080324972=/tmp/go-build -gno-record-gcc-switches -fno-common”

What did you do?

Built gopls 0.12.4 with 1.20.5. Ran “gopls -v”. Crashes immediately. Things were working fine on beta 2. Now, normally, I’d just wait because this is a beta. But, I always get worried when stuff like this happens, so I figured I’d at least make you aware.

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 7
  • Comments: 33 (16 by maintainers)

Most upvoted comments

The same problem happens with me when running gopls from VS Code. Here is what I have worked around while waiting for an official fix.

Delete the crashed version of gopls from GOPATH (the <GOPATH>/bin/gopls file), then install another gopls package using homebrew

brew install gopls

You can check whether it is installed successfully by using the command gopls version (restart your terminal if needed)

Finally, copy gopls executable file from your brew path (default is /opt/homebrew/bin/gopls, or you can run the command which gopls to check that info) to your GOPATH, which will be later read by VS Code.

cp <HOMEBREW_PATH>/bin/gopls <GOPATH>/bin/gopls

Restart VS Code and done.

I think the bug is fixed in Xcode 15 beta 6. With beta 6, gopls builds and runs fine with Go tip, 1.21.0, and 1.20.7, both on ARM64 and AMD64. So I think we are done with this. If one still sees a failure, feel free to comment. Thanks.

I submitted a few CLs to the master branch. Now it seems to work fine with Go tip on Intel Mac. Note that you’ll need to build PIE binary with go build -buildmode=pie, as non-PIE build is broken in the new Apple linker.

It still fails on ARM64 Mac. Some CLs linked at #61229 will work around it, but not yet submitted. One way to checkout the CLs are

% go install golang.org/dl/gotip@latest
% gotip download 511355

The run gotip as the go command, such as gotip build.

I also can’t downgrade the XCode tools version. The download page didn’t work, and wants me to pay $99 to be an Apple Developer???

@wtfiscrq issue #61229 linked a number of CLs. If you want to test you can checkout them and build a new Go toolchain. One way of doing it is git fetch https://go.googlesource.com/go refs/changes/55/511355/2 && git checkout FETCH_HEAD then run make.bash in GOROOT/src.

@bobdoah the CLs include workarounds in the Go toolchain. You need to checkout the CLs and build a new Go toolchain (as mentioned above). If you don’t want to build the Go toolchain yourself, here are some other workarounds: go build -ldflags="-extldflags=-Wl,-ld64" - force using the old Apple linker (update: in Xcode 15 beta 5 the flag is switched to -ld_classic, so the workaround is go build -ldflags="-extldflags=-Wl,-ld_classic") go build -ldflags=-linkmode=internal - force internal linking, don’t use Apple linker at all

@cherrymui I have two M1 MBP, both on most recent Sonoma Beta, with go version go1.21.0 darwin/arm64. I’m having trouble with one of the machine when running gopls version crashes showing fatal: morestack on g0. however on the other machine, everything seems fine.

I’m willing to check log/versions on my laptops if this would help on tracing the issue.

The morestack on g0 failure is from an infinite recursion

^C* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BREAKPOINT (code=EXC_I386_BPT, subcode=0x0)
  * frame #0: 0x0000000100075102 gopls`go:buildid + 457090
    frame #1: 0x0000000100073365 gopls`runtime.morestack.abi0 + 37
    frame #2: 0x000000010003cb69 gopls`runtime.panicCheck1 + 169
    frame #3: 0x000000010005d705 gopls`runtime.findfunc + 261
    frame #4: 0x000000010003cae5 gopls`runtime.panicCheck1 + 37
    frame #5: 0x000000010003cc0e gopls`runtime.goPanicIndex + 46
    frame #6: 0x000000010005d705 gopls`runtime.findfunc + 261
    frame #7: 0x000000010003cae5 gopls`runtime.panicCheck1 + 37
    frame #8: 0x000000010003cc0e gopls`runtime.goPanicIndex + 46
    frame #9: 0x000000010005d705 gopls`runtime.findfunc + 261

which looks like runtime func table is probably corrupted…

Just want to point out that this isn’t just an issue for macOS 14. 😞

I have macOS 13.4.1 but the latest beta version of Xcode CommandLineTools installed as it was suggested via the mac software update tool. Not sure why it’s installing beta versions of xcode tools (I didn’t realise until I hit this issue)

$ clang -v
Apple clang version 15.0.0 (clang-1500.0.34.3)
Target: arm64-apple-darwin22.5.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

Screenshot 2023-07-11 at 10 54 07 am

$ pkgutil --pkg-info=com.apple.pkg.CLTools_Executables
package-id: com.apple.pkg.CLTools_Executables
version: 15.0.0.0.1.1688827124
volume: /
location: /
install-time: 1689068473

If anyone else is in the same situation as me I was able to resolve it by downloading the old CommandLineTools from here: https://download.developer.apple.com/Developer_Tools/Command_Line_Tools_for_Xcode_14.3.1/Command_Line_Tools_for_Xcode_14.3.1.dmg

It crashes when built with 1.20.5, in the same way. I’ve rebuilt in numerous times, and it always crashes. I tracked down a previous copy I built (built on different OS, toolchain, and Go version) and it runs ok.

How exactly can I get the C toolchain version that you are looking for? I just use whatever comes packaged with Xcode. Currently using Xcode 15 beta 3.

Most of the errors in https://github.com/golang/go/issues/61190#issuecomment-1623929669 should be addressed with CL stack https://golang.org/cl/505415 . I think they are caused by the (buggy or intentional or a mixture of) behavior changes of Apple’s new linker. What version of the C toolchain and Xcode are you using? Could you share the output of ld -v? (I thought the new Apple linker has not been made default, maybe it does?)

fatal: morestack on g0

This is more concerning. Does this occur only with previously-built binaries, or it also occurs with new binaries?

I’ll update my macOS machine to the beta and see tonight…