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: g0 stack.lo is sometimes too low #26061

aclements opened this Issue Jun 26, 2018 · 2 comments


None yet
3 participants
Copy link

aclements commented Jun 26, 2018

In cgo mode for UNIX platforms, we compute the g0 stack bounds by querying the stack size from pthread_get_stacksize, subtracting that from the current SP in mstart, and adding a 1k buffer. However, on my Linux laptop, over 4k of the stack has already been consumed by the time we reach mstart, so the runtime sets the bottom of the g0 stack to be below the mapped memory. As a result, if we actually overflow the g0 stack, we get a segfault instead of a useful message with a traceback.

We should use pthread_get_stack instead to get both stack bounds.

Discovered when writing a test of overflowing the g0 stack for #21382, which I had assumed would pass on linux/amd64 but didn't.

@aclements aclements added this to the Go1.11 milestone Jun 26, 2018


This comment has been minimized.

Copy link

gopherbot commented Jun 26, 2018

Change mentions this issue: runtime/cgo: use get pthread stack bounds instead of size


This comment has been minimized.

Copy link

gopherbot commented Jul 7, 2018

Change mentions this issue: runtime: test g0 stack overflow handling on all OSes

@aclements aclements modified the milestones: Go1.11, Go1.12 Jul 24, 2018

@aclements aclements modified the milestones: Go1.12, Go1.13 Jan 8, 2019

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.