golang/go

cmd/link: panic: runtime error: makeslice: cap out of range

ray2011 opened this issue · 9 comments

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

$ go version
go version go1.16.6 linux/amd64

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=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/raynor/.cache/go-build"
GOENV="/home/raynor/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/raynor/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/raynor/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.16.6"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/raynor/git/go_shared_build/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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build1655817667=/tmp/go-build -gno-record-gcc-switches"

What did you do?

raynor@DESKTOP-7TTOU8H:~/git/go_shared_build$ go install -buildmode=shared -linkshared std
raynor@DESKTOP-7TTOU8H:~/git/go_shared_build$
raynor@DESKTOP-7TTOU8H:~/git/go_shared_build$ go install -buildmode=shared -linkshared shared/pkg0
# /tmp/go-build2695248807/b002/libshared-pkg0.so
panic: runtime error: makeslice: cap out of range

goroutine 1 [running]:
cmd/link/internal/loader.(*Loader).LoadSyms(0xc000700000, 0x87f340)
        /usr/local/go/src/cmd/link/internal/loader/loader.go:2188 +0x125
cmd/link/internal/ld.(*Link).loadlib(0xc00014e000)
        /usr/local/go/src/cmd/link/internal/ld/lib.go:558 +0x3de
cmd/link/internal/ld.Main(0x87f340, 0x20, 0x20, 0x1, 0x7, 0x10, 0x0, 0x0, 0x6e86a7, 0x1b, ...)
        /usr/local/go/src/cmd/link/internal/ld/main.go:244 +0xdbc
main.main()
        /usr/local/go/src/cmd/link/main.go:68 +0x258
raynor@DESKTOP-7TTOU8H:~/git/go_shared_build$ go list ./...
shared
shared/pkg0
shared/pkg1
raynor@DESKTOP-7TTOU8H:~/git/go_shared_build$ cat pkg0/pkg0.go
package pkg0

var (
  X int
  Y int
)

func Init() {
  X = 1
  Y = 2
}

What did you expect to see?

raynor@DESKTOP-7TTOU8H:~/git/go_shared_build$ go install -buildmode=shared -linkshared shared/pkg0
# /tmp/go-build2695248807/b002/libshared-pkg0.so
panic: runtime error: makeslice: cap out of range

goroutine 1 [running]:
cmd/link/internal/loader.(*Loader).LoadSyms(0xc000700000, 0x87f340)
        /usr/local/go/src/cmd/link/internal/loader/loader.go:2188 +0x125
cmd/link/internal/ld.(*Link).loadlib(0xc00014e000)
        /usr/local/go/src/cmd/link/internal/ld/lib.go:558 +0x3de
cmd/link/internal/ld.Main(0x87f340, 0x20, 0x20, 0x1, 0x7, 0x10, 0x0, 0x0, 0x6e86a7, 0x1b, ...)
        /usr/local/go/src/cmd/link/internal/ld/main.go:244 +0xdbc
main.main()
        /usr/local/go/src/cmd/link/main.go:68 +0x258

What did you see instead?

install success

Change https://golang.org/cl/338831 mentions this issue: cmd/link: do not load symbols if size is 0

Close to #47183 and #42189 or similar: receiving error "panic: runtime error: makeslice: cap out of range" when trying to install with buildmode=shared

I successfully reproduce error on go v1.16.0 (1,6,9), 1.17.2 in docker env golang:1.x.x-stretch. And it's correctly worked on 1.14.15, 1.15.15.
And it's correlated with that @mengzhuo said before - this changes has been made since 1.16.x tag.
5402d40

Kindly cc @cherrymui

Obsoleted by #47788

Same issue with 1.18.3 version

Seeing issues on go version go1.20 linux/amd64

Obsoleted by #47788

Isn't it declined #47788 (comment) ?

Per #47788 (comment)

We've decided to leave -buildmode=shared alone (not delete it) for Go 1.18,
but it's not going to work any better than it does today.
In particular, we're not fixing any bugs in it anymore, ...

So it still applies. Thanks.