R=gri CC=golang-dev https://golang.org/cl/1326042
Depends on CL 957045, 980043, 1004043. Fixes #715. R=agl1, agl CC=golang-dev https://golang.org/cl/943043