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)
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 homebrewYou 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 commandwhich gopls
to check that info) to your GOPATH, which will be later read by VS Code.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
The run
gotip
as the go command, such asgotip 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 runmake.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 isgo 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 showingfatal: 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 recursionwhich 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)
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?)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…