Skip to content

Bad runtime.Stack() content in defer on Linux amd64 #47053

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

Closed
maxatome opened this issue Jul 4, 2021 · 3 comments
Closed

Bad runtime.Stack() content in defer on Linux amd64 #47053

maxatome opened this issue Jul 4, 2021 · 3 comments

Comments

@maxatome
Copy link

maxatome commented Jul 4, 2021

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

$ go version
go version devel go1.17-912f075 Fri Jul 2 21:06:08 2021 +0000 linux/amd64

Does this issue reproduce with the latest release?

No, only with tip on Linux amd64 (Debian 10.9).

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

Linux x86_64 (Debian 10.9)

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/root/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/root/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/root/sdk/gotip"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/root/sdk/gotip/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="devel go1.17-912f075 Fri Jul 2 21:06:08 2021 +0000"
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-build680001886=/tmp/go-build -gno-record-gcc-switches"

What did you do?

x.go file:

package main

import (
	"fmt"
	"runtime"
)

func dumpStack() {
	var buf [8192]byte
	n := runtime.Stack(buf[:], false)
	fmt.Print(string(buf[:n]))
}

func setVal(i int64) {
	defer dumpStack()
}

func main() {
	setVal(1)
}

then go run x.go

What did you expect to see?

go 1.16.5 prints:

goroutine 1 [running]:
main.dumpStack()
	/home/foo/gotest/x.go:10 +0x5b
main.setVal(0x1)
	/home/foo/gotest/x.go:16 +0x45
main.main()
	/home/foo/gotest/x.go:19 +0x2a

What did you see instead?

go1.17-912f075047 prints:

goroutine 1 [running]:
main.dumpStack()
	/home/foo/gotest/x.go:10 +0x39
main.setVal(0xc0000001a0)
	/home/foo/gotest/x.go:16 +0x3b
main.main()
	/home/foo/gotest/x.go:19 +0x1e

so main.setVal(0xc0000001a0) instead of main.setVal(0x1).

The same go1.17-912f075047 on FreeBSD 13.0 amd64 works correctly, so this bug seems to be related to Linux, at least on amd64.

@randall77
Copy link
Contributor

This is probably a duplicate of #45728 .
TL;DR the arguments printed in tracebacks are best-effort and are worse in 1.17 because of the new register-based calling convention.
Not sure why it would be different for freebsd, though.

@cherrymui @dr2chase

@randall77
Copy link
Contributor

Ah, because https://tip.golang.org/doc/go1.17#compiler indicates the regabi is only enabled for Windows, Mac, and Linux.

@maxatome
Copy link
Author

maxatome commented Jul 5, 2021

@randall77 you are right, thanks. No need to keep this one open.

@maxatome maxatome closed this as completed Jul 5, 2021
@golang golang locked and limited conversation to collaborators Jul 5, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants