Go: cmd/link: panic: runtime error: slice bounds out of range [::1751306] with length 1048576

Created on 25 Sep 2020  路  15Comments  路  Source: golang/go

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

$ go version
$ go version go1.15.2 darwin/amd64

Does this issue reproduce with the latest release?

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

go env Output

$ go env
image

What did you do?


$ go build -o xxx main.go

What did you expect to see?

build success

What did you see instead?

image

NeedsFix okay-after-beta1 release-blocker

Most helpful comment

Would you be able to post instructions and/or source code so that we can reproduce this?

The panic is happening while the linker is reading relocations out of an object file -- the offset it reads from the file is insane, which triggers the bounds range error. It would probably be a good idea to try to rule out the possibility of a corrupted object file (e.g. go clean -cache and rebuild).

All 15 comments

$ go env

image

@w01fb0ss please do not post screenshots of text, please just copy and paste the text. Thank you

CC @thanm @cherrymui @jeremyfaller

$ go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/xxx/Library/Caches/go-build"
GOENV="/Users/xxx/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/xxx/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/xxx/go"
GOPRIVATE=""
GOPROXY="https://goproxy.cn"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/xxx/go/src/aiotools/server/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/13/jzs_fl_10zqbptmd_9flzr040000gn/T/go-build766193444=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you see instead?

command-line-arguments

panic: runtime error: slice bounds out of range [::1751306] with length 1048576

goroutine 1 [running]:
cmd/internal/goobj2.(Reader).Relocs(0xc00094f710, 0x6, 0xc0000680b0, 0x2d7b, 0xc00010ec80)
/usr/local/go/src/cmd/internal/goobj2/objfile.go:655 +0xb4
cmd/link/internal/loader.(
Loader).relocs(0xc000614000, 0xc000619f80, 0x6, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
/usr/local/go/src/cmd/link/internal/loader/loader.go:1712 +0xf0
cmd/link/internal/loader.(Loader).Relocs(0xc000614000, 0x116e7, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
/usr/local/go/src/cmd/link/internal/loader/loader.go:1702 +0x7d
cmd/link/internal/ld.(
deadcodePass).flood(0xc0000680a0)
/usr/local/go/src/cmd/link/internal/ld/deadcode.go:119 +0x425
cmd/link/internal/ld.deadcode(0xc00007b880)
/usr/local/go/src/cmd/link/internal/ld/deadcode.go:264 +0xcc
cmd/link/internal/ld.Main(0x14709e0, 0x20, 0x20, 0x1, 0x7, 0x10, 0x0, 0x0, 0x12d81c2, 0x1b, ...)
/usr/local/go/src/cmd/link/internal/ld/main.go:235 +0xd3c
main.main()
/usr/local/go/src/cmd/link/main.go:68 +0x1dc

@thanm @jeremyfaller @cherrymui

Would you be able to post instructions and/or source code so that we can reproduce this?

The panic is happening while the linker is reading relocations out of an object file -- the offset it reads from the file is insane, which triggers the bounds range error. It would probably be a good idea to try to rule out the possibility of a corrupted object file (e.g. go clean -cache and rebuild).

@w01fb0ss, kindly pinging you to take a look. Go1.16 will be released in the next 2.5 months and this issue is stalling completion of the milestone. @thanm asked some questions, @w01fb0ss please take a look.Thank you!

@thanm: I just ran into this same issue. I have included reproducible code. Run go generate and then go build.

golang-41621.zip

$ go version
go version go1.15.6 darwin/amd64

go env Output

$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/roger/Library/Caches/go-build"
GOENV="/Users/roger/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/roger/go/pkg/mod"
GONOPROXY="[removed]"
GONOSUMDB="[removed]"
GOOS="darwin"
GOPATH="/Users/roger/go"
GOPRIVATE="[removed]"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/_c/lb59l5wn1yv2sj3g83s0hqbm0000gn/T/go-build160846022=/tmp/go-build -gno-record-gcc-switches -fno-common"

Thanks @roger6106 . I will take a look.

I can reproduce this on tip; working on a fix.

Change https://golang.org/cl/278492 mentions this issue: cmd/internal/goobj: fix buglet in object file reader

Change https://golang.org/cl/278493 mentions this issue: test: add test case for object file reader

@gopherbot please consider this for backport to 1.15

Backport issue(s) opened: #43214 (for 1.15).

Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://golang.org/wiki/MinorReleases.

Change https://golang.org/cl/278673 mentions this issue: cmd/internal/goobj: fix buglet in object file reader

Was this page helpful?
0 / 5 - 0 ratings