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

x/tools/gopls: gopls instantly segfaults after installation #61676

Closed
matthewdavidrodgers opened this issue Jul 31, 2023 · 11 comments
Closed

x/tools/gopls: gopls instantly segfaults after installation #61676

matthewdavidrodgers opened this issue Jul 31, 2023 · 11 comments
Labels
gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@matthewdavidrodgers
Copy link

gopls version

Installed at latest (v0.13.0) - but unable to verify as the version command also segfaults

go env

> go env                                                                                                                                                                                                                                 
GO111MODULE=""
GOARCH="arm64"
GOBIN=""
GOCACHE="/Users/matthewrodgers/Library/Caches/go-build"
GOENV="/Users/matthewrodgers/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/matthewrodgers/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/matthewrodgers/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/opt/homebrew/Cellar/go/1.20.6/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/opt/homebrew/Cellar/go/1.20.6/libexec/pkg/tool/darwin_arm64"
GOVCS=""
GOVERSION="go1.20.6"
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/d9/b6xts_292jl1xm48py971tm40000gp/T/go-build2431123774=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

To begin my week I opened VS Code to a go project, which noted that the gopls server failed to initialize. I was not greeted with helpful logs:
Screenshot 2023-07-31 at 10 11 52 AM

I went to the terminal to see if I could initialize the server myself, but any commands to gopls instantly segfaulted with no other message.

From here, I wiped go (via homebrew), removed $HOME/go (and thus gopls), and applied a software update to Mac OSX 13.5

After reboot, I installed go (via homebrew) again. I then installed gopls via go install golang.org/x/tools/gopls@latest, which succeeded, albeit with a linker warning. Other issues in the project have indicated that the linker warning may be expected, or at least not an issue for usage.

After installation, any invocation of gopls continues to instantly fails with a segmentation fault.

Additionally, I will note that, following my go reinstallation, installing some packages fails with a linker assertion failure.

What did you expect to see?

A valid response from gopls

What did you see instead?

A segmentation fault

Editor and settings

N/A

Logs

> go install golang.org/x/tools/gopls@latest                                                                                                                                                                                               
go: downloading golang.org/x/tools/gopls v0.13.0
go: downloading golang.org/x/tools v0.11.1
go: downloading golang.org/x/tools v0.11.1-0.20230727183555-65b14ec44dc9
go: downloading github.com/sergi/go-diff v1.1.0
go: downloading honnef.co/go/tools v0.4.2
go: downloading mvdan.cc/gofumpt v0.4.0
go: downloading mvdan.cc/xurls/v2 v2.4.0
go: downloading golang.org/x/mod v0.12.0
go: downloading golang.org/x/sync v0.3.0
go: downloading golang.org/x/text v0.11.0
go: downloading github.com/google/go-cmp v0.5.9
go: downloading golang.org/x/sys v0.10.0
go: downloading golang.org/x/vuln v0.0.0-20230110180137-6ad3e3d07815
go: downloading golang.org/x/exp/typeparams v0.0.0-20221212164502-fae10dda9338
go: downloading github.com/BurntSushi/toml v1.2.1
go: downloading golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e
# golang.org/x/tools/gopls
ld: warning: '/private/var/folders/d9/b6xts_292jl1xm48py971tm40000gp/T/go-link-2922608012/go.o' has malformed LC_DYSYMTAB, expected 130 undefined symbols to start at index 25688, found 139 undefined symbols starting at index 77

> gopls
[1]    5513 segmentation fault  gopls

Possibly relevant go install linker errors

> go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.53.3
# github.com/golangci/golangci-lint/cmd/golangci-lint
/opt/homebrew/Cellar/go/1.20.6/libexec/pkg/tool/darwin_arm64/link: running cc failed: exit status 1
ld: warning: -bind_at_load is deprecated on macOS
ld: warning: '/private/var/folders/d9/b6xts_292jl1xm48py971tm40000gp/T/go-link-1908992931/go.o' has malformed LC_DYSYMTAB, expected 138 undefined symbols to start at index 81717, found 150 undefined symbols starting at index 112
0  0x10016c380  __assert_rtn + 72
1  0x1001259bc  ___ZN2ld16LayoutExecutable27writeContentWithoutLinkEditENSt3__14spanIhLm18446744073709551615EEEy_block_invoke + 9620
2  0x180990440  _dispatch_client_callout2 + 20
3  0x1809a3f1c  _dispatch_apply_invoke + 224
4  0x180990400  _dispatch_client_callout + 20
5  0x1809a1fb8  _dispatch_root_queue_drain + 684
6  0x1809a26c0  _dispatch_worker_thread2 + 164
7  0x180b3c038  _pthread_wqthread + 228
ld: Assertion failed: (addr + content.size() <= sectionEndAddr), function writeContentWithoutLinkEdit_block_invoke, file Layout.cpp, line 5689.
clang: error: linker command failed with exit code 1 (use -v to see invocation)
@matthewdavidrodgers matthewdavidrodgers added gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository. labels Jul 31, 2023
@gopherbot gopherbot added this to the Unreleased milestone Jul 31, 2023
@findleyr
Copy link
Contributor

CC @golang/compiler

Possibly related: #61229

Are you able to install gopls@v0.12.4, or does that also segfault after rebuilding with your current toolchain?

@matthewdavidrodgers
Copy link
Author

Same results when installing v0.12.4 - install "succeeds" with linker warning, and then segfaults on any invocation

@findleyr
Copy link
Contributor

@matthewdavidrodgers can you confirm if you are using Xcode 15?

@matthewdavidrodgers
Copy link
Author

yes, i can confirm:

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

@cherrymui
Copy link
Member

cherrymui commented Jul 31, 2023

Thanks. I think this is #61190. Closing as a dup. See also #61229.

@cherrymui cherrymui closed this as not planned Won't fix, can't repro, duplicate, stale Jul 31, 2023
@findleyr
Copy link
Contributor

@matthewdavidrodgers there are some workarounds described here to help get you moving again:
#61190 (comment)

@matthewdavidrodgers
Copy link
Author

perfect - using -ldflags="-extldflags=-Wl,-ld64" does indeed resolve this for me. thanks for pointing me along

@Chinocy
Copy link

Chinocy commented Aug 1, 2023

@matthewdavidrodgers Hey how did you fix it? i have the same problem, thanks

@Kavinjsir
Copy link

@Chinocy

Here is what I did locally to build gopls with classical linkers:

  1. Clone the go tools repository: https://github.com/golang/tools
  2. Go to the ./gopls folder in the repo
  3. Build the executable: go build -ldflags="-extldflags=-Wl,-ld_classic" -o gopls .
  4. Check if the output file is good, for instance: ./gopls -V
  5. If cool, move it to your go bin path, mine looks like: cp gopls ~/go/bin/gopls

@ctxkenb
Copy link

ctxkenb commented Aug 2, 2023

For a one-line work-around this is what I'm using: go install -ldflags="-extldflags=-Wl,-ld_classic" golang.org/x/tools/gopls@latest

@htiennv
Copy link

htiennv commented Aug 3, 2023

For a one-line work-around this is what I'm using: go install -ldflags="-extldflags=-Wl,-ld_classic" golang.org/x/tools/gopls@latest

Oh nice solution! It works for me. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

8 participants