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: panic: runtime error: slice bounds out of range [::1751306] with length 1048576 #41621

Closed
w01fb0ss opened this issue Sep 25, 2020 · 15 comments

Comments

@w01fb0ss
Copy link

@w01fb0ss w01fb0ss commented Sep 25, 2020

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](https://user-images.githubusercontent.com/44709004/94216230-74f59580-ff11-11ea-8947-a36c8bfbf679.png)

What did you do?

$ go build -o xxx main.go

What did you expect to see?

build success

What did you see instead?

image

@w01fb0ss
Copy link
Author

@w01fb0ss w01fb0ss commented Sep 25, 2020

$ go env

image

@davecheney
Copy link
Contributor

@davecheney davecheney commented Sep 25, 2020

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

@ianlancetaylor ianlancetaylor changed the title panic: runtime error: slice bounds out of range [::1751306] with length 1048576 cmd/link: panic: runtime error: slice bounds out of range [::1751306] with length 1048576 Sep 25, 2020
@ianlancetaylor ianlancetaylor added this to the Go1.16 milestone Sep 25, 2020
@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Sep 25, 2020

@w01fb0ss
Copy link
Author

@w01fb0ss w01fb0ss commented Sep 25, 2020

$ 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

@randall77
Copy link
Contributor

@randall77 randall77 commented Sep 25, 2020

@thanm
Copy link
Member

@thanm thanm commented Sep 25, 2020

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).

@odeke-em
Copy link
Member

@odeke-em odeke-em commented Nov 29, 2020

@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!

@w01fb0ss w01fb0ss closed this Nov 30, 2020
@roger6106
Copy link

@roger6106 roger6106 commented Dec 15, 2020

@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"
@thanm
Copy link
Member

@thanm thanm commented Dec 15, 2020

Thanks @roger6106 . I will take a look.

@thanm
Copy link
Member

@thanm thanm commented Dec 15, 2020

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

@gopherbot
Copy link

@gopherbot gopherbot commented Dec 15, 2020

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

@gopherbot
Copy link

@gopherbot gopherbot commented Dec 15, 2020

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

@thanm
Copy link
Member

@thanm thanm commented Dec 16, 2020

@gopherbot please consider this for backport to 1.15

@gopherbot
Copy link

@gopherbot gopherbot commented Dec 16, 2020

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.

@gopherbot gopherbot closed this in f4e7a6b Dec 16, 2020
@gopherbot
Copy link

@gopherbot gopherbot commented Dec 16, 2020

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

gopherbot pushed a commit that referenced this issue Feb 2, 2021
…e reader

The code in the Go object file reader was casting a pointer to mmaped
memory into a large array prior to performing a read of the
relocations section:

	return (*[1<<20]Reloc)(unsafe.Pointer(&r.b[off]))[:n:n]

For very large object files, this artificial array isn't large enough
(that is, there are more than 1048576 relocs to read), so update the
code to use a larger artifical array size.

Fixes #43214.
Updates #41621.

Change-Id: Ic047c8aef4f8a3839f2e7e3594bce652ebd6bd5b
Reviewed-on: https://go-review.googlesource.com/c/go/+/278492
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Reviewed-by: Jeremy Faller <jeremy@golang.org>
Trust: Than McIntosh <thanm@google.com>
(cherry picked from commit f4e7a6b)
Reviewed-on: https://go-review.googlesource.com/c/go/+/278673
gopherbot pushed a commit that referenced this issue Feb 24, 2021
Add test in which a input Go object file contains a very large number
of relocations (more than 1<<20).

Updates #41621.

Change-Id: If1ebf3c4fefbf55ddec4e05c5299e7c48fc697d8
Reviewed-on: https://go-review.googlesource.com/c/go/+/278493
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Trust: Than McIntosh <thanm@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
10 participants