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

cmd/link: ld: B/BL out of range -134840372 (max +/-128MB) from 0x10809F954 #67854

Open
d-bytebase opened this issue Jun 6, 2024 · 13 comments
Open
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Darwin

Comments

@d-bytebase
Copy link

d-bytebase commented Jun 6, 2024

Go version

1.22.4

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/danny/Library/Caches/go-build'
GOENV='/Users/danny/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/danny/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/danny/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/opt/homebrew/Cellar/go/1.22.4/libexec'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/opt/homebrew/Cellar/go/1.22.4/libexec/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.22.4'
GCCGO='gccgo'
AR='ar'
CC='cc'
CXX='c++'
CGO_ENABLED='1'
GOMOD='/Users/danny/src/bytebase/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/2m/s9rrpxps5rl00_wnvy3b2jd40000gn/T/go-build3442076162=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

https://github.com/bytebase/bytebase

build command: CGO_ENABLED=1 go build -o ./.air/bytebase ./backend/bin/server/main.go

What did you see happen?

/opt/homebrew/Cellar/go/1.22.4/libexec/pkg/tool/darwin_arm64/link: running cc failed: exit status 1
ld: warning: -bind_at_load is deprecated on macOS
ld: B/BL out of range -134840372 (max +/-128MB) from 0x10809F954 ('_runtime.cmpstring.island' from 'branch-islands-file') to 0x100007920 ('_runtime.cmpstring' from '/private/var/folders/2m/s9rrpxps5rl00_wnvy3b2jd40000gn/T/go-link-1336181017/go.o')
final section layout:
__PAGEZERO addr=0x00000000, size=0x100000000, fileOffset=0x00000000
__TEXT addr=0x100000000, size=0x11640000, fileOffset=0x00000000
__text addr=0x100002ff0, size=0x082b982c, fileOffset=0x00002ff0
__stubs addr=0x1082bc81c, size=0x00000810, fileOffset=0x082bc81c
__rodata addr=0x1082bd040, size=0x0929ddf0, fileOffset=0x082bd040
__cstring addr=0x11155ae30, size=0x000363a7, fileOffset=0x1155ae30
__const addr=0x111591200, size=0x000a71b8, fileOffset=0x11591200
__unwind_info addr=0x1116383b8, size=0x00003d40, fileOffset=0x116383b8
__eh_frame addr=0x11163c0f8, size=0x000000b8, fileOffset=0x1163c0f8
__DATA_CONST addr=0x111640000, size=0x0f640000, fileOffset=0x11640000
__got addr=0x111640000, size=0x00000948, fileOffset=0x11640000
__const addr=0x111640948, size=0x00039678, fileOffset=0x11640948
__cfstring addr=0x111679fc0, size=0x000000e0, fileOffset=0x11679fc0
__rodata addr=0x11167a0a0, size=0x027eb4d0, fileOffset=0x1167a0a0
__typelink addr=0x113e65580, size=0x00050d44, fileOffset=0x13e65580
__itablink addr=0x113eb62e0, size=0x0003a7c8, fileOffset=0x13eb62e0
__gopclntab addr=0x113ef0ac0, size=0x0cd8c250, fileOffset=0x13ef0ac0
__DATA addr=0x120c80000, size=0x011f8000, fileOffset=0x20c80000
__data addr=0x120c80000, size=0x006ad908, fileOffset=0x20c80000
__go_buildinfo addr=0x12132d910, size=0x000069c0, fileOffset=0x2132d910
__noptrdata addr=0x1213342e0, size=0x009145c0, fileOffset=0x213342e0
__thread_vars addr=0x121c488a0, size=0x00000630, fileOffset=0x21c488a0
__thread_ptrs addr=0x121c48ed0, size=0x00000138, fileOffset=0x21c48ed0
__thread_data addr=0x121c49008, size=0x00000108, fileOffset=0x21c49008
__thread_bss addr=0x121c49110, size=0x00000618, fileOffset=0x21c49110
__bss addr=0x121c49740, size=0x0020c74c, fileOffset=0x00000000
__noptrbss addr=0x121e55ea0, size=0x000201b0, fileOffset=0x00000000
__common addr=0x121e76050, size=0x00000070, fileOffset=0x00000000
__LINKEDIT addr=0x121e78000, size=0x0db24000, fileOffset=0x21c4c000
clang: error: linker command failed with exit code 1 (use -v to see invocation)

What did you expect to see?

build success. I think this is MacOS only issue related to linker and starting since 1.22.

related issue: #66993

@d-bytebase
Copy link
Author

d-bytebase commented Jun 6, 2024

Hi @cherrymui @randall77 would you help take a look? Thanks!

I feel like it's a bug in MacOS linker. We can workaround the issue with -ldflags="-extldflags='-ld64'", however, not sure what the long-term solution is.

@seankhliao seankhliao changed the title build/link: ld: B/BL out of range -134840372 (max +/-128MB) from 0x10809F954 cmd/link: ld: B/BL out of range -134840372 (max +/-128MB) from 0x10809F954 Jun 6, 2024
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Jun 6, 2024
@seankhliao seankhliao added OS-Darwin NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Jun 6, 2024
@randall77
Copy link
Contributor

It does not fail for me.

What does /usr/bin/xcodebuild -version print? For me it is

Xcode 15.2
Build version 15C500b

The error printed is strange. arm64 has a branch limit of +/- 32MB, not +/- 128MB. Also, the branch is between two locations in the text section, which has presumably already been resolved by the Go linker. The external linker shouldn't have to process any relocations for such a branch.

@d-bytebase
Copy link
Author

Thanks. The link failures were not consistent with low chance to succeed. We could run 'go clean -cache' and reboot the laptop to get a more consistent failure.

% /usr/bin/xcodebuild -version
Xcode 15.4
Build version 15F31d

% clang --version
Apple clang version 15.0.0 (clang-1500.3.9.4)
Target: arm64-apple-darwin23.5.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

@randall77
Copy link
Contributor

So the failure doesn't happen consistently? That is even more strange.
The Go tools are carefully designed to generate the exact same artifacts each time.

@d-bytebase
Copy link
Author

Yup, +1 for Go tool consistency. We have different Xcode version though. I wonder if it's using some cached objects or it's a bug in Xcode toolkit instead of Go, but Go triggers it somehow. The behavior is quite consistent if we clean all the cache and reboot the laptop.

@cherrymui
Copy link
Member

I cannot reproduce this with

Xcode 15.4
Build version 15F31d

It builds successfully for me.

We can workaround the issue with -ldflags="-extldflags='-ld64'"

As it works with the old Apple linker, it might be a bug in the new Apple linker. The .island symbol looks like a trampoline generated by the Apple linker. It is unclear to me why it wants to generate such a symbol at that address.

(ARM64 B/BL instruction branch limit is actually +/- 128MB. It takes 26 bits off offset, adding two 0s at the end, as the an instruction address is always 4-byte aligned.)

@cherrymui cherrymui added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Jun 7, 2024
@gabyhelp
Copy link

gabyhelp commented Jun 8, 2024

Similar Issues

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

@gopherbot
Copy link
Contributor

Timed out in state WaitingForInfo. Closing.

(I am just a bot, though. Please speak up if this is a mistake or you have the requested information.)

@gopherbot gopherbot closed this as not planned Won't fix, can't repro, duplicate, stale Jul 7, 2024
@vektah
Copy link

vektah commented Jul 8, 2024

I'm also seeing this issue with go 1.22.4 and 1.22.5, xcode 15.3.0.0.1.1708646388, M2

ld: B/BL out of range -154140372 (max +/-128MB) from 0x1093089D4 ('_runtime.memequal.island' from 'branch-islands-file') to 0x100008B00 ('_runtime.memequal' from '/private/var/folders/bx/qq1wvp2n1ms609wzzgg0rm5m0000gn/T/go-link-274490021/go.o')

@cherrymui
Copy link
Member

@vektah could you share what program you are building? Thanks.

@cherrymui cherrymui reopened this Jul 8, 2024
@github-project-automation github-project-automation bot moved this from Done to In Progress in Go Compiler / Runtime Jul 8, 2024
@alexBoldt95
Copy link

@d-bytebase Does the issue clear if you rebase your working branch or check out another branch?

@vektah
Copy link

vektah commented Jul 8, 2024

@vektah could you share what program you are building? Thanks.

Its when running the test case for an internal service, sorry.

@strideynet
Copy link

I encounter this when compiling https://github.com/gravitational/teleport . The behaviour seems a little odd, it'll be fine sometimes but once I've hit the failure, it'll repeat until I reboot. At least a few members of the team here are encountering this.

@seankhliao seankhliao removed the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Dec 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Darwin
Projects
Status: In Progress
Development

No branches or pull requests

9 participants