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/compile: Internal compiler error: InitLSym called twice #49029

Closed
joeycumines opened this issue Oct 18, 2021 · 4 comments
Closed

cmd/compile: Internal compiler error: InitLSym called twice #49029

joeycumines opened this issue Oct 18, 2021 · 4 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@joeycumines
Copy link

joeycumines commented Oct 18, 2021

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

$ go version
go version go1.17.2 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="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/joey/.cache/go-build"
GOENV="/home/joey/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/joey/under/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/joey/under/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.17.2"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
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-build2466057989=/tmp/go-build -gno-record-gcc-switches"

What did you do?

I tried to compile/run an existing test case, that was last working using go version go1.16.2 linux/amd64.

Stripped down example that reproduces my issue: https://play.golang.org/p/iLs_hTb2DIo

What did you expect to see?

It successfully compile

What did you see instead?

./prog.go:29:15: internal compiler error: InitLSym called twice on main.func1

Please file a bug report including a short program that triggers the error.
https://golang.org/issue/new

It compiles if you remove the select statement, or any one of the struct literals.

@ALTree ALTree changed the title Internal compiler error: InitLSym called twice cmd/compile: Internal compiler error: InitLSym called twice Oct 18, 2021
@ALTree ALTree added this to the Go1.18 milestone Oct 18, 2021
@ALTree ALTree added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Oct 18, 2021
@ALTree
Copy link
Member

ALTree commented Oct 18, 2021

cc @cuonglm @mdempsky

@cuonglm
Copy link
Member

cuonglm commented Oct 18, 2021

Git bisects point to https://go-review.googlesource.com/c/go/+/282892

Somehow, we walked main.func1 twice.

@cuonglm
Copy link
Member

cuonglm commented Oct 18, 2021

Simpler reproducer:

package main

type Step struct {
	Handler func()
}

func main() {
	notify := make(chan struct{}, 1)
	_ = [...]struct{ Steps []Step }{
		{}, {}, {}, {},
		{
			Steps: []Step{
				{
					Handler: func() {
						notify <- struct{}{}
					},
				},
			},
		},
	}
}

So when initializing arrays literal have more than 4 elements, the compiler performs both static and dynamic initialization, which will use the same func literal func() { notify <- struct{}{} } for both of them, causing the closure walked twice.

Maybe we can mark the closure as walked at the first time we visit it, then re-walking will check that flag to prevent appending the closure to Func.Closures twice. How do you think @mdempsky?

@gopherbot
Copy link

Change https://golang.org/cl/357960 mentions this issue: cmd/compile: prevent compiling closures more than once

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants