Patch backported from:
https://go-review.googlesource.com/c/go/+/569475
https://go-review.googlesource.com/c/go/+/590695