• Russ Cox's avatar
    time: avoid garbage collector aliasing bug · f21bc792
    Russ Cox authored
    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
    f21bc792
Name
Last commit
Last update
api Loading commit data...
doc Loading commit data...
include Loading commit data...
lib Loading commit data...
misc Loading commit data...
src Loading commit data...
test Loading commit data...
.hgignore Loading commit data...
.hgtags Loading commit data...
AUTHORS Loading commit data...
CONTRIBUTORS Loading commit data...
LICENSE Loading commit data...
PATENTS Loading commit data...
README Loading commit data...
favicon.ico Loading commit data...
robots.txt Loading commit data...