]> Cypherpunks repositories - gostls13.git/commit
time: avoid garbage collector aliasing bug
authorRuss Cox <rsc@golang.org>
Mon, 24 Jun 2013 18:49:35 +0000 (14:49 -0400)
committerRuss Cox <rsc@golang.org>
Mon, 24 Jun 2013 18:49:35 +0000 (14:49 -0400)
commitf21bc7920decb5b6f94d49a9e8eefcdb74960c24
tree3b748bd5c28dc927554ef557b8f67814741a8cbe
parentce5d91baa5df81f88161f3eb42b5dab7d829461c
time: avoid garbage collector aliasing bug

Time is a tiny struct, so the compiler copies a Time by
copying each of the three fields.

The layout of a time on amd64 is [ptr int32 gap32 ptr].
Copying a Time onto a location that formerly held a pointer in the
second word changes only the low 32 bits, creating a different
but still plausible pointer. This confuses the garbage collector
when it appears in argument or result frames.

To avoid this problem, declare nsec as uintptr, so that there is
no gap on amd64 anymore, and therefore no partial pointers.

Note that rearranging the fields to put the int32 last still leaves
a gap - [ptr ptr int32 gap32] - because Time must have a total
size that is ptr-width aligned.

Update #5749

This CL is enough to fix the problem, but we should still do
the other actions listed in the initial report. We're not too far
from completely precise collection.

R=golang-dev, dvyukov, r
CC=golang-dev
https://golang.org/cl/10504043
src/pkg/time/time.go