]> Cypherpunks repositories - gostls13.git/commit
cmd/ld: fix large stack split for preempt check
authorRuss Cox <rsc@golang.org>
Fri, 12 Jul 2013 16:12:56 +0000 (12:12 -0400)
committerRuss Cox <rsc@golang.org>
Fri, 12 Jul 2013 16:12:56 +0000 (12:12 -0400)
commit031c107cad93174a6e33d3af31c1e3613129ad08
treea2388a8082804254a26495e0a831a20344d03098
parent56cd47b295e033f39534d80effc45f4abe125bec
cmd/ld: fix large stack split for preempt check

If the stack frame size is larger than the known-unmapped region at the
bottom of the address space, then the stack split prologue cannot use the usual
condition:

        SP - size >= stackguard

because SP - size may wrap around to a very large number.
Instead, if the stack frame is large, the prologue tests:

        SP - stackguard >= size

(This ends up being a few instructions more expensive, so we don't do it always.)

Preemption requests register by setting stackguard to a very large value, so
that the first test (SP - size >= stackguard) cannot possibly succeed.
Unfortunately, that same very large value causes a wraparound in the
second test (SP - stackguard >= size), making it succeed incorrectly.

To avoid *that* wraparound, we have to amend the test:

        stackguard != StackPreempt && SP - stackguard >= size

This test is only used for functions with large frames, which essentially
always split the stack, so the cost of the few instructions is noise.

This CL and CL 11085043 together fix the known issues with preemption,
at the beginning of a function, so we will be able to try turning it on again.

R=ken2
CC=golang-dev
https://golang.org/cl/11205043
src/cmd/5l/noop.c
src/cmd/6l/pass.c
src/cmd/8l/pass.c
src/pkg/runtime/proc_test.go
src/pkg/runtime/stack.c
src/pkg/runtime/stack.h