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

runtime: Stack behaves differently between go1.8 and go1.9 #22916

Closed
2yz opened this issue Nov 29, 2017 · 6 comments

Comments

Projects
None yet
5 participants
@2yz
Copy link

commented Nov 29, 2017

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

go version go1.9.2 darwin/amd64

Does this issue reproduce with the latest release?

Yes

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

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/2yz/go"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.9.2/libexec"
GOTOOLDIR="/usr/local/Cellar/go/1.9.2/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/22/0c8jxg0j0j54f7xcw9zd0m8m0000gn/T/go-build362850491=/tmp/go-build -gno-record-gcc-switches -fno-common"
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"

What did you do?

package main

import (
	"runtime/debug"
)

func main() {
	PrintStack().nothing()
}

func PrintStack() Nothing {
	debug.PrintStack()
	return Nothing{}
}

type Nothing struct{}

func (Nothing) nothing() {}

https://play.golang.org/p/0DaVrfpCST

What did you expect to see?

go1.8.3 result

goroutine 1 [running]:
runtime/debug.Stack(0x0, 0x0, 0x109c981)
	/usr/local/Cellar/go/1.8.3/libexec/src/runtime/debug/stack.go:24 +0x79
runtime/debug.PrintStack()
	/usr/local/Cellar/go/1.8.3/libexec/src/runtime/debug/stack.go:16 +0x22
main.PrintStack()
	/Users/2yz/go/src/github.com/2yz/stack/main.go:12 +0x20
main.main()
	/Users/2yz/go/src/github.com/2yz/stack/main.go:8 +0x20

What did you see instead?

go1.9.2 result

goroutine 1 [running]:
runtime/debug.Stack(0x1004034, 0xc42001e0b8, 0x0)
	/usr/local/Cellar/go/1.9.2/libexec/src/runtime/debug/stack.go:24 +0xa7
runtime/debug.PrintStack()
	/usr/local/Cellar/go/1.9.2/libexec/src/runtime/debug/stack.go:16 +0x22
main.PrintStack()
	/Users/2yz/go/src/github.com/2yz/stack/main.go:12 +0x20
main.Nothing.nothing(...)
	/Users/2yz/go/src/github.com/2yz/stack/main.go:8
main.main()
	/Users/2yz/go/src/github.com/2yz/stack/main.go:8 +0x20

main.Nothing.nothing() is included in the call stack in go1.9.2

main.Nothing.nothing(...)
	/Users/2yz/go/src/github.com/2yz/stack/main.go:8
@davecheney

This comment has been minimized.

Copy link
Contributor

commented Nov 29, 2017

@bradfitz

This comment has been minimized.

Copy link
Member

commented Nov 29, 2017

Thanks, @davecheney

@bradfitz bradfitz closed this Nov 29, 2017

@2yz

This comment has been minimized.

Copy link
Author

commented Nov 29, 2017

Thanks

@magical

This comment has been minimized.

Copy link
Contributor

commented Nov 29, 2017

@davecheney That doesn't make sense. nothing makes no function calls, so it shouldn't wind up in the middle of a stack trace.

Changing this line

PrintStack().nothing()

to the equivalent

n := PrintStack()
n.nothing()

yields the expected result.

goroutine 1 [running]:
runtime/debug.Stack(0x10436070, 0xdce7a, 0x0, 0x1040c0f0)
	/usr/local/go/src/runtime/debug/stack.go:24 +0xc0
runtime/debug.PrintStack()
	/usr/local/go/src/runtime/debug/stack.go:16 +0x20
main.PrintStack()
	/tmp/sandbox852160124/main.go:13 +0x20
main.main()
	/tmp/sandbox852160124/main.go:8 +0x20

https://play.golang.org/p/Vb9vsdB5g0

@bradfitz bradfitz reopened this Nov 29, 2017

@bradfitz

This comment has been minimized.

Copy link
Member

commented Nov 29, 2017

Can you try Go master (what will become Go 1.10) ?

@bradfitz

This comment has been minimized.

Copy link
Member

commented Nov 29, 2017

Actually, I just did. And it's fixed with Go 1.10:

bradfitz@gdev:~$ GOROOT=$HOME/go1.8 go run x.go
goroutine 1 [running]:
runtime/debug.Stack(0x0, 0x0, 0x48fd53)
        /home/bradfitz/go1.8/src/runtime/debug/stack.go:24 +0x79
runtime/debug.PrintStack()
        /home/bradfitz/go1.8/src/runtime/debug/stack.go:16 +0x22
main.PrintStack()
        /home/bradfitz/x.go:12 +0x20
main.main()
        /home/bradfitz/x.go:8 +0x20
bradfitz@gdev:~$ GOROOT=$HOME/go1.9 go run x.go
goroutine 1 [running]:
runtime/debug.Stack(0x404384, 0xc420074058, 0x0)
        /home/bradfitz/go1.9/src/runtime/debug/stack.go:24 +0xa7
runtime/debug.PrintStack()
        /home/bradfitz/go1.9/src/runtime/debug/stack.go:16 +0x22
main.PrintStack()
        /home/bradfitz/x.go:12 +0x20
main.Nothing.nothing(...)
        /home/bradfitz/x.go:8
main.main()
        /home/bradfitz/x.go:8 +0x20
bradfitz@gdev:~$ go run x.go
goroutine 1 [running]:
runtime/debug.Stack(0xc420049f78, 0x40405c, 0xc42007c058)
        /home/bradfitz/go/src/runtime/debug/stack.go:24 +0xa7
runtime/debug.PrintStack()
        /home/bradfitz/go/src/runtime/debug/stack.go:16 +0x22
main.PrintStack()
        /home/bradfitz/x.go:12 +0x20
main.main()
        /home/bradfitz/x.go:8 +0x20

This isn't critical enough to warrant a backport to Go 1.9, though. (I assume.)

@bradfitz bradfitz closed this Nov 29, 2017

@golang golang locked and limited conversation to collaborators Nov 29, 2018

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