• 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
..
Makefile Loading commit data...
example_test.go Loading commit data...
export_test.go Loading commit data...
export_windows_test.go Loading commit data...
format.go Loading commit data...
genzabbrs.go Loading commit data...
internal_test.go Loading commit data...
sleep.go Loading commit data...
sleep_test.go Loading commit data...
sys_plan9.go Loading commit data...
sys_unix.go Loading commit data...
sys_windows.go Loading commit data...
tick.go Loading commit data...
tick_test.go Loading commit data...
time.go Loading commit data...
time_test.go Loading commit data...
zoneinfo.go Loading commit data...
zoneinfo_abbrs_windows.go Loading commit data...
zoneinfo_plan9.go Loading commit data...
zoneinfo_read.go Loading commit data...
zoneinfo_unix.go Loading commit data...
zoneinfo_windows.go Loading commit data...
zoneinfo_windows_test.go Loading commit data...