Skip to content

runtime: gentraceback on own stack confused by stack growth during gentraceback #9044

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
rsc opened this issue Nov 2, 2014 · 1 comment
Closed
Milestone

Comments

@rsc
Copy link
Contributor

rsc commented Nov 2, 2014

set StackFromSystem=1 and StackFaultOnFree=1 and go test -a -short strings.
It faults during gentraceback.

fatal error: unexpected signal during runtime execution
[signal 0xa code=0x2 addr=0x22084914b8 pc=0x1c290]

goroutine 1 [running, locked to thread]:
runtime.gothrow(0x1c0810, 0x2a)
    /Users/rsc/g/go/src/runtime/panic.go:503 +0x8e fp=0x22084939a8 sp=0x2208493990
runtime.sigpanic()
    /Users/rsc/g/go/src/runtime/sigpanic_unix.go:14 +0x5e fp=0x22084939f8 sp=0x22084939a8
runtime.gentraceback(0x10fe1, 0x2208491358, 0x0, 0x2082b2120, 0x4, 0x2208493b98, 0x20,
0x0, 0x0, 0x0, ...)
    /Users/rsc/g/go/src/runtime/traceback.go:200 +0xbc0 fp=0x2208493ae8 sp=0x22084939f8
runtime.callers(0x4, 0x2208493b98, 0x20, 0x0)
    /Users/rsc/g/go/src/runtime/traceback.go:514 +0xb5 fp=0x2208493b58 sp=0x2208493ae8
runtime.mProf_Malloc(0x2082f8000, 0x100000)
    /Users/rsc/g/go/src/runtime/mprof.go:237 +0x51 fp=0x2208493cc0 sp=0x2208493b58
runtime.profilealloc(0x265880, 0x2082f8000, 0x100000)
    /Users/rsc/g/go/src/runtime/malloc.go:408 +0x9b fp=0x2208493ce8 sp=0x2208493cc0
runtime.mallocgc(0x100000, 0x0, 0x3, 0x5c7d23d3aa6c13a4)
    /Users/rsc/g/go/src/runtime/malloc.go:335 +0x3e0 fp=0x2208493d98 sp=0x2208493ce8
runtime.rawstring(0x100000, 0x0, 0x0, 0x0, 0x0, 0x0)
    /Users/rsc/g/go/src/runtime/string.go:195 +0x94 fp=0x2208493dc8 sp=0x2208493d98
runtime.slicebytetostring(0x208500000, 0x100000, 0x100000, 0x0, 0x0)
    /Users/rsc/g/go/src/runtime/string.go:69 +0x4b fp=0x2208493e58 sp=0x2208493dc8
strings_test.func·007(0x0, 0x0)
    /Users/rsc/g/go/src/strings/strings_test.go:1163 +0xf2 fp=0x2208493ee8 sp=0x2208493e58
strings_test.init()
    /Users/rsc/g/go/src/strings/strings_test.go:1166 +0xd6a fp=0x2208493f80 sp=0x2208493ee8
main.init()
    strings/_test/_testmain.go:274 +0x4a fp=0x2208493f98 sp=0x2208493f80
runtime.main()
    /Users/rsc/g/go/src/runtime/proc.go:58 +0xe4 fp=0x2208493fe0 sp=0x2208493f98
runtime.goexit()
    /Users/rsc/g/go/src/runtime/asm_amd64.s:2232 +0x1 fp=0x2208493fe8 sp=0x2208493fe0

This was running on a 2k stack. It crossed the 2k boundary into a 4k stack in a call
made out of gentraceback with sp=...9f0. On return gentraceback was still using an
un-updated local SP variable.

We might be able to make gentraceback cope with this by giving the SP variables the
right types, but the result will still describe half one stack and half another. It
seems much safer to require that gentraceback of the current goroutine run on the g0
stack instead.

More generally, the result of getcallersp is invalidated by making a call to a function
that might grow the stack or pause the goroutine (because the stack can shrink during GC
pauses). It must be used basically immediately, and must only be passed to nosplit
functions that do not block.

This affects runtime.Callers, runtime.Stack, and nearly all the runtime profiling
routines. It does not directly impact garbage collection or stack copying; their uses of
gentraceback were already running on a g0 stack.

CL 167060043 should fix this.
@rsc
Copy link
Contributor Author

rsc commented Nov 6, 2014

Comment 1:

It did.

Status changed to Fixed.

@rsc rsc added fixed labels Nov 6, 2014
@rsc rsc self-assigned this Nov 6, 2014
@rsc rsc added this to the Go1.4 milestone Apr 14, 2015
@rsc rsc removed the release-go1.4 label Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 25, 2016
@rsc rsc removed their assignment Jun 23, 2022
This issue was closed.
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

2 participants