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: inline of f(m T) from package containing type m causes stack overflow #25984

Closed
dr2chase opened this issue Jun 20, 2018 · 5 comments

Comments

Projects
None yet
3 participants
@dr2chase
Copy link
Contributor

commented Jun 20, 2018

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

Development tip as of bug report (2018-06-20)

Does this issue reproduce with the latest release?

Yes

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

GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/drchase/Library/Caches/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/drchase/GoogleDrive/work/gocode"
GOPROXY=""
GORACE=""
GOROOT="/Users/drchase/GoogleDrive/work/go"
GOTMPDIR=""
GOTOOLDIR="/Users/drchase/GoogleDrive/work/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
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/gr/vvb66dqx6jl6lh8wckfd5p9w0095tn/T/go-build491052553=/tmp/go-build -gno-record-gcc-switches -fno-common"
VGOMODROOT=""

What did you do?

mkdir -p testfoo/src/pkg
cd testfoo
cat > main.go <<"EOF"
package main

import (
"pkg"
"runtime"
)

//go:noinline
func countThreadCreate() int {
n := pkg.ThreadCreateProfile(nil)
return n
}

//go:noinline
func main() {
println("ctc=", countThreadCreate())
n,_ := runtime.ThreadCreateProfile(nil)
println("tcp=", n)
}
EOF
cat > src/pkg/pkg.go <<- "EOF"
package pkg

type m struct {
alllink     *m // Comment out this line for a different error.
}

var allm *m

type StackRecord struct {
Stack0 [32]uintptr
}

func ThreadCreateProfile(m []StackRecord) (n int) {
if mp := allm; mp != nil {
n++
}
return
}
EOF
GOPATH=`pwd` go build main.go

What did you expect to see?

Successful compilation.

What did you see instead?

# command-line-arguments
runtime: goroutine stack exceeds 1000000000-byte limit
fatal error: stack overflow
(etc)

1.10 seems to be okay. This is not caused by the recent CL for importing FOR loops, unless I am utterly failing at "git checkout". I'm still looking for the commit where it goes wrong.

Bad commit is between these two:

Previous HEAD position was 58c231f244 runtime: FreeBSD fast clock_gettime HPET timecounter support
HEAD is now at d2c7dec183 net: implement (*syscall.RawConn).Read/Write on Windows

The good commit is dated "Sat Apr 14 05:36:36 2018 +0000"

@dr2chase

This comment has been minimized.

Copy link
Contributor Author

commented Jun 21, 2018

I'm bisecting, back from evening events.

@dr2chase

This comment has been minimized.

Copy link
Contributor Author

commented Jun 21, 2018

@mdempsky, @gri, one of you might want to take a look at this, I will also check on it in the morning.

a3c75d9b313cc9f06969125ff28501c081dac3b8 is the first bad commit
commit a3c75d9b313cc9f06969125ff28501c081dac3b8
    cmd/compile: enable indexed export format by default

@dr2chase dr2chase changed the title cmd/compile: inline of f(x m) from package containing type m causes stack overflow cmd/compile: inline of f(m T) from package containing type m causes stack overflow Jun 21, 2018

@dr2chase

This comment has been minimized.

Copy link
Contributor Author

commented Jun 21, 2018

I pruned some unnecessary code from the test case, and managed to replicate a different error that is the one I was originally looking for. If you remove

	alllink     *m // Comment out this line for a different error.

the error is instead (at least at tip)

# command-line-arguments
./main.go:10:30: pkg.m redeclared during import "pkg"
	previous declaration at ./main.go:10:30

@dr2chase dr2chase added this to the Go1.11 milestone Jun 21, 2018

@mdempsky mdempsky self-assigned this Jun 21, 2018

@mdempsky

This comment has been minimized.

Copy link
Member

commented Jun 21, 2018

Ugh, this is yet another scoping issue due to resolving symbols within import bodies.

The problem is export.go:importsym uses s.Def. But when called to import a package-scoped symbol that's shadowed within an inline body (e.g., the recursive m type declaration shadowed by the m parameter to ThreadCreateProfile), s.Def will point to the local parameter instead of the package-scoped definition.

It needs to use s.PkgDef() instead, and maybe a corresponding s.SetPkgDef method.

@gopherbot

This comment has been minimized.

Copy link

commented Jun 21, 2018

Change https://golang.org/cl/120456 mentions this issue: cmd/compile: fix compile failure for lazily resolved shadowed types

@gopherbot gopherbot closed this in f422bea Jun 22, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.