linker out of memory on compile?

Completed

I'm not a GO programmer, so please forgive me. I am however trying to contribute a fix for an issue in Hashicorp vault. Goland compiles and runs the project without errors, but when I try to execute the project in debug mode, the compilation throws an error that I don't entirely understand:

GOROOT=/opt/homebrew/opt/go/libexec #gosetup
GOPATH=/Users/rhornsby/go #gosetup
/opt/homebrew/opt/go/libexec/bin/go build -o /Users/rhornsby/Library/Caches/JetBrains/GoLand2023.2/tmp/GoLand/___1go_build_github_com_hashicorp_vault -gcflags all=-N -l github.com/hashicorp/vault #gosetup
# github.com/hashicorp/vault
/opt/homebrew/opt/go/libexec/pkg/tool/darwin_arm64/link: running cc failed: exit status 1
ld: B/BL out of range -149822468 (max +/-128MB) to '_runtime.memequal'
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I can read the words, and can guess that there's a memory constraint somehow related to compiling with symbols and/or linking debug-related libraries? - but I'm not entirely sure what the bigger picture is or what I can do about it. My Google-foo is failing, I can't figure out for example if runtime.memequal is settable and set too low, and if so how I could change it.

It might matter, so to be clear I'm trying to compile/run this on an ARM mac (Sonoma 14.1.1) just because that's the desktop I happen to run things on.

0
11 comments

After more digging, this does seem to be a platform or architecture specific issue, though I'm still not sure how/why. The debug behaves exactly as expected on x64 linux. I don't think the problem was ever with GoLand specifically, but rather something with the compiler/toolchain/linker. Was hoping someone here might have an idea.

0

Could you please provide the output of go version and go env in the terminal?

0

Sorry, should have included that. 

go version go1.21.5 darwin/arm64

goenv:

GO111MODULE=''
GOARCH='arm64'
GOBIN='/Users/rhornsby/go/bin'
GOCACHE='/Users/rhornsby/Library/Caches/go-build'
GOENV='/Users/rhornsby/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/rhornsby/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/rhornsby/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/opt/homebrew/Cellar/go/1.21.5/libexec'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/opt/homebrew/Cellar/go/1.21.5/libexec/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.21.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'
0

Thanks for sharing.

It's indeed a strange error. Have you tried to re-install XCode CLI Tools (https://apple.stackexchange.com/q/93573) or install Go using an official installation (https://go.dev/doc/install) instead of Homebrew?

1

I think since the original post, xcode has been updated and at your suggestion, I re-installed golang ("Go") from the go.dev package rather than from homebrew. Something seems to have fixed it, so maybe a weird thing with xcode or a weird incompatibility in the go compiler.

Weird. I dunno. Seems to be solved either way. Thanks for the suggestions.

0

I`ve met the same problem. I exactly installed GO  exactly using the official installation, and I even don`t have a xcode . what can I do to solve the problem ?

0

Hello 920866163,

Could you share the output of go env and go build in your environment?

0

 This is my  go env.

GO111MODULE='on'
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/bytedance/Library/Caches/go-build'
GOENV='/Users/bytedance/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/bytedance/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/bytedance/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='off'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.21.7'
GCCGO='gccgo'
AR='ar'
CC='clang'
CXX='clang++'
CGO_ENABLED='1'
GOMOD='/Users/bytedance/Documents/Workspace/mill/go.mod'
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 -ffile-prefix-map=/var/folders/2q/z5wp_7n56gv42fvn2s7167s00000gn/T/go-build1670768637=/tmp/go-build -gno-record-gcc-switches -fno-common'

But what does `go build` mean ? 

0

Could you share the output of clang --version, try to build your project and share the console output? If you are not comfortable sharing the build output, please let us know the build flags you are using (if any).

 

 

 

 

0

This is my clang version 

Apple clang version 15.0.0 (clang-1500.0.40.1)
Target: arm64-apple-darwin23.2.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

In fact I was trying to run a unit test ,so i didn`t have a build output.

This was my command.

/usr/local/go/bin/go test -json ./... -covermode=atomic -coverprofile /Users/bytedance/Library/Caches/JetBrains/GoLand2023.3/coverage/bentham_account$go_test_service.out

Thanks .

0

I found it`s not a problem of JetBrains , it is a problem of cgo . Just set CGO_ENABLED=0 , the problem could be solved .

0

Please sign in to leave a comment.