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: "pc-relative relocation address too big" for program with huge static data #63202

Closed
peter-xiao opened this issue Sep 25, 2023 · 2 comments

Comments

@peter-xiao
Copy link

What version of Go are you using (go version)?

$ go version
go1.21

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE='on'
GOARCH='amd64'
GOBIN=''
GOCACHE='/Users/xxx/Library/Caches/go-build'
GOENV='/Users/xxx/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/xxx/gopackage/pkg/mod'
GONOPROXY='*.byted.org,*.everphoto.cn,git.smartisan.com'
GONOSUMDB='*.byted.org,*.everphoto.cn,git.smartisan.com'
GOOS='darwin'
GOPATH='/Users/xxx/gopackage'
GOPRIVATE='*.byted.org,*.everphoto.cn,git.smartisan.com'
GOPROXY='https://goproxy.byted.org|https://goproxy.cn|direct'
GOROOT='/Users/xxx/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/Users/xxx/go/pkg/tool/darwin_amd64'
GOVCS=''
GOVERSION='go1.21.1'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='clang'
CXX='clang++'
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 x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/b1/0fd1b6hs7lz0fm_mh346lybm0000gn/T/go-build3937965288=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

package main

var x1 = [2000000000 - 10000000]byte{0: 1}

func main() {
	println(x1[0])
	x2 := [100000000]int{1}
	_ = x2
}
go build

What did you expect to see?

Compile successfully && console prints 0

What did you see instead?

Compile failed && console prints

internal/cpu.processOptions: pc-relative relocation address for internal/cpu.options is too big: 0xa6598603
internal/cpu.processOptions: pc-relative relocation address for internal/cpu.options is too big: 0xa65985f0
internal/cpu.processOptions: pc-relative relocation address for internal/cpu.options is too big: 0xa659850f
internal/cpu.processOptions: pc-relative relocation address for internal/cpu.options is too big: 0xa6598510
internal/cpu.processOptions: pc-relative relocation address for internal/cpu.options is too big: 0xa6598418
internal/cpu.processOptions: pc-relative relocation address for internal/cpu.options is too big: 0xa65983f9
internal/cpu.processOptions: pc-relative relocation address for internal/cpu.options is too big: 0xa65983b0
internal/cpu.processOptions: pc-relative relocation address for internal/cpu.options is too big: 0xa6598390
internal/cpu.processOptions: pc-relative relocation address for internal/cpu.options is too big: 0xa6598387
internal/cpu.processOptions: pc-relative relocation address for internal/cpu.options is too big: 0xa6598373
internal/cpu.processOptions: pc-relative relocation address for internal/cpu.options is too big: 0xa65982f4
internal/cpu.processOptions: pc-relative relocation address for internal/cpu.options is too big: 0xa65982e4
internal/cpu.processOptions: pc-relative relocation address for internal/cpu.options is too big: 0xa65982c9
internal/cpu.processOptions: pc-relative relocation address for internal/cpu.options is too big: 0xa65982c4
internal/cpu.doinit: pc-relative relocation address for internal/cpu.X86 is too big: 0xa67c986a
internal/cpu.doinit: pc-relative relocation address for internal/cpu.X86 is too big: 0xa67c984b
internal/cpu.doinit: pc-relative relocation address for internal/cpu.X86 is too big: 0xa67c9833
internal/cpu.doinit: pc-relative relocation address for internal/cpu.X86 is too big: 0xa67c9818
internal/cpu.doinit: pc-relative relocation address for internal/cpu.X86 is too big: 0xa67c97f6
internal/cpu.doinit: pc-relative relocation address for internal/cpu.X86 is too big: 0xa67c97d0
internal/cpu.doinit: pc-relative relocation address for internal/cpu.options is too big: 0xa659815a
/Users/xxx/go/pkg/tool/darwin_amd64/link: too many errors
@thanm thanm changed the title affected/package: cmd/link cmd/link: "pc-relative relocation address too big" for program with huge static data Sep 25, 2023
@thanm
Copy link
Contributor

thanm commented Sep 25, 2023

Thanks for the report.

Please see these related issues:

#7980
#9862

The crux of the matter here is that the Go toolchain is not set up to support programs that use more than 2GB of static data.

I am going to close this as a duplicate of 7980 for now.

It is possible to imagine adding support for programs that use huge amounts of data (perhaps via something like -mcmodel=medium as describe here), however this work hasn't been done yet, and it would have to be very carefully designed in order to avoid performance problems.

@thanm
Copy link
Contributor

thanm commented Sep 25, 2023

Duplicate of #7980

@thanm thanm marked this as a duplicate of #7980 Sep 25, 2023
@thanm thanm closed this as completed Sep 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants