[Pkg-golang-commits] [golang] 01/04: Imported Upstream version 1.8~rc1

Michael Hudson-Doyle mwhudson-guest at moszumanska.debian.org
Thu Jan 19 19:28:20 UTC 2017


This is an automated email from the git hooks/post-receive script.

mwhudson-guest pushed a commit to branch golang-1.8
in repository golang.

commit e61bee665711de18cfe5a910d8d2ee74d85b67c8
Author: Michael Hudson-Doyle <michael.hudson at canonical.com>
Date:   Mon Jan 16 15:08:19 2017 +1300

    Imported Upstream version 1.8~rc1
---
 AUTHORS                                            |  21 +
 CONTRIBUTING.md                                    |   9 +-
 CONTRIBUTORS                                       |  23 +
 VERSION                                            |   2 +-
 api/go1.8.txt                                      |   1 -
 doc/asm.html                                       |  38 ++
 doc/code.html                                      |  10 +-
 doc/go1.8.html                                     |  59 ++-
 doc/install.html                                   |  16 +-
 lib/time/update.bash                               |   4 +-
 lib/time/zoneinfo.zip                              | Bin 364943 -> 366113 bytes
 misc/cgo/test/issue18146.go                        |  25 +
 misc/cgo/testcshared/main2.c                       |   2 +-
 misc/cgo/testsanitizers/test.bash                  |  10 +-
 misc/cgo/testsanitizers/tsan9.go                   |  11 +-
 misc/cgo/testshared/src/exe/exe.go                 |  12 +
 misc/ios/clangwrap.sh                              |   2 +-
 src/archive/zip/reader.go                          |  49 +-
 src/archive/zip/reader_test.go                     |  31 +-
 src/archive/zip/struct.go                          |   3 -
 src/archive/zip/testdata/extra-timestamp.zip       | Bin 152 -> 0 bytes
 src/archive/zip/writer.go                          |  17 -
 src/archive/zip/writer_test.go                     |  27 --
 src/archive/zip/zip_test.go                        |  39 --
 src/bytes/buffer.go                                |   2 +-
 src/cmd/compile/internal/gc/asm_test.go            |  29 ++
 src/cmd/compile/internal/gc/bexport.go             |   2 +-
 src/cmd/compile/internal/gc/builtin.go             |   1 +
 src/cmd/compile/internal/gc/builtin/runtime.go     |   1 +
 src/cmd/compile/internal/gc/noder.go               |   2 +
 src/cmd/compile/internal/gc/reflect.go             |   7 +-
 src/cmd/compile/internal/gc/sinit.go               |   4 +-
 src/cmd/compile/internal/gc/ssa.go                 |   3 +
 src/cmd/compile/internal/gc/type.go                |   2 +-
 src/cmd/compile/internal/gc/typecheck.go           |   2 +-
 src/cmd/compile/internal/gc/walk.go                |   4 +
 src/cmd/compile/internal/ssa/checkbce.go           |   2 +-
 src/cmd/compile/internal/ssa/compile.go            |  11 +-
 src/cmd/compile/internal/ssa/config.go             |   2 +-
 src/cmd/compile/internal/ssa/func.go               |   1 +
 src/cmd/compile/internal/ssa/gen/ARM64Ops.go       |   2 +-
 src/cmd/compile/internal/ssa/gen/ARMOps.go         |   2 +-
 src/cmd/compile/internal/ssa/gen/MIPS64Ops.go      |   2 +-
 src/cmd/compile/internal/ssa/gen/MIPSOps.go        |   2 +-
 src/cmd/compile/internal/ssa/gen/PPC64Ops.go       |   2 +-
 src/cmd/compile/internal/ssa/loopreschedchecks.go  | 517 +++++++++++++++++++++
 src/cmd/compile/internal/ssa/nilcheck.go           |   2 +
 src/cmd/compile/internal/ssa/op.go                 |   2 +-
 src/cmd/compile/internal/ssa/regalloc.go           |   2 +-
 src/cmd/compile/internal/ssa/sparsetree.go         |  33 +-
 src/cmd/cover/cover.go                             |  52 ++-
 src/cmd/cover/cover_test.go                        |   5 +
 src/cmd/cover/testdata/test.go                     |   4 +
 src/cmd/dist/test.go                               |   2 +-
 src/cmd/go/alldocs.go                              |   9 +-
 src/cmd/go/go_test.go                              |  50 +-
 src/cmd/go/help.go                                 |   2 +
 src/cmd/go/http.go                                 |   1 +
 src/cmd/go/pkg.go                                  |   4 +
 src/cmd/go/test.go                                 |   7 +-
 src/cmd/go/testdata/src/empty/pkg/pkg.go           |   1 +
 src/cmd/go/testdata/src/empty/pkgtest/pkg.go       |   1 +
 src/cmd/go/testdata/src/empty/pkgtest/test_test.go |   1 +
 src/cmd/go/testdata/src/empty/pkgtestxtest/pkg.go  |   1 +
 .../testdata/src/empty/pkgtestxtest/test_test.go   |   1 +
 .../testdata/src/empty/pkgtestxtest/xtest_test.go  |   1 +
 src/cmd/go/testdata/src/empty/pkgxtest/pkg.go      |   1 +
 .../go/testdata/src/empty/pkgxtest/xtest_test.go   |   1 +
 src/cmd/go/testdata/src/empty/test/test_test.go    |   1 +
 .../go/testdata/src/empty/testxtest/test_test.go   |   1 +
 .../go/testdata/src/empty/testxtest/xtest_test.go  |   1 +
 src/cmd/go/testdata/src/empty/xtest/xtest_test.go  |   1 +
 src/cmd/go/testflag.go                             |   4 +-
 src/cmd/internal/obj/go.go                         |   6 +-
 src/cmd/link/doc.go                                |   2 -
 src/cmd/link/internal/arm/obj.go                   |   2 +-
 src/cmd/link/internal/ld/pcln.go                   |   3 +
 src/cmd/pprof/internal/report/report.go            |   2 +-
 src/cmd/pprof/internal/report/source.go            |   2 +-
 src/cmd/vet/cgo.go                                 |  19 +-
 src/cmd/vet/copylock.go                            |  10 +-
 src/cmd/vet/testdata/cgo/cgo.go                    |   3 +
 src/cmd/vet/testdata/copylock.go                   |  16 +-
 src/cmd/vet/testdata/copylock_func.go              |   6 +-
 src/cmd/vet/vet_test.go                            |   1 +
 src/crypto/sha1/sha1block_amd64.s                  |  18 +-
 src/crypto/sha256/sha256block_amd64.s              |   5 +-
 src/crypto/tls/conn.go                             |   2 +-
 src/crypto/x509/root_darwin.go                     | 229 ++++++---
 src/crypto/x509/root_darwin_test.go                |  11 +-
 src/database/sql/sql.go                            |  11 +-
 src/database/sql/sql_test.go                       |  48 ++
 src/go/build/build.go                              |  11 +-
 src/go/build/build_test.go                         |  11 -
 src/go/build/testdata/ignored/ignored.go           |   3 -
 src/go/parser/interface.go                         |   2 +-
 src/go/types/api.go                                |   2 +-
 src/go/types/stdlib_test.go                        |   1 +
 src/io/pipe.go                                     |   1 +
 src/io/pipe_test.go                                |  12 +
 src/net/addrselect.go                              |  51 +-
 src/net/addrselect_test.go                         |  85 ----
 src/net/dial.go                                    |   2 +-
 src/net/dial_test.go                               |   2 +
 src/net/dnsclient_unix.go                          |  44 +-
 src/net/dnsclient_unix_test.go                     |  81 ++--
 src/net/http/client.go                             |  41 +-
 src/net/http/client_test.go                        |   6 +-
 src/net/http/h2_bundle.go                          |   4 +
 src/net/http/httputil/dump.go                      |  13 +-
 src/net/http/httputil/dump_test.go                 |  12 +
 src/net/http/httputil/reverseproxy.go              |   2 +
 src/net/http/request.go                            |  39 ++
 src/net/http/requestwrite_test.go                  | 208 +++++++++
 src/net/http/serve_test.go                         | 151 +++++-
 src/net/http/server.go                             |   4 +
 src/net/http/transfer.go                           | 153 +++++-
 src/net/http/transport_test.go                     |  19 +-
 src/net/interface.go                               |   7 +-
 src/net/ip.go                                      |   6 +
 src/net/iprawsock.go                               |  12 +
 src/net/iprawsock_posix.go                         |  12 -
 src/net/iprawsock_test.go                          |  27 +-
 src/net/ipsock.go                                  |   7 +
 src/net/ipsock_posix.go                            |   7 -
 src/net/lookup.go                                  |  24 +-
 src/net/lookup_plan9.go                            |   4 +
 src/net/lookup_test.go                             |   7 +-
 src/net/lookup_unix.go                             |   3 +-
 src/net/lookup_windows_test.go                     |   8 +-
 src/net/tcpsock_test.go                            |   7 +-
 src/net/udpsock_test.go                            |  31 +-
 src/os/user/user.go                                |  36 +-
 src/path/filepath/path_plan9.go                    |   3 +
 src/path/filepath/path_unix.go                     |   3 +-
 src/path/filepath/path_windows.go                  |   3 +
 src/path/filepath/symlink_windows.go               |   2 +-
 src/reflect/makefunc.go                            |  12 +-
 src/runtime/HACKING.md                             | 139 +++++-
 src/runtime/asm_amd64.s                            |  15 +-
 src/runtime/fastlog2.go                            |   4 +-
 src/runtime/iface.go                               |  14 +-
 src/runtime/malloc.go                              |   7 +
 src/runtime/mgc.go                                 | 129 ++---
 src/runtime/mgcsweep.go                            |   5 +-
 src/runtime/mksizeclasses.go                       |  16 +
 src/runtime/mstats.go                              |  15 +-
 src/runtime/os_linux.go                            |  23 +
 src/runtime/os_linux_arm.go                        |   6 +
 src/runtime/os_windows.go                          |  12 +
 src/runtime/pprof/pprof_test.go                    |   6 +-
 src/runtime/proc.go                                |  42 +-
 src/runtime/runtime2.go                            |   6 +-
 src/runtime/select.go                              |  69 ++-
 src/runtime/sizeclasses.go                         |  68 +++
 src/runtime/stack.go                               |   2 +-
 src/runtime/sys_dragonfly_amd64.s                  |  25 +-
 src/runtime/sys_freebsd_amd64.s                    |  25 +-
 src/runtime/sys_linux_386.s                        |  15 +-
 src/runtime/sys_linux_amd64.s                      |  25 +-
 src/runtime/sys_linux_mipsx.s                      |   2 +-
 src/runtime/sys_netbsd_386.s                       |  15 +-
 src/runtime/sys_netbsd_amd64.s                     |  27 +-
 src/runtime/sys_openbsd_386.s                      |  15 +-
 src/runtime/sys_openbsd_amd64.s                    |  25 +-
 src/runtime/traceback.go                           |   3 +-
 src/testing/sub_test.go                            |   4 +-
 src/testing/testing.go                             |   8 +-
 .../chacha20poly1305/chacha20poly1305_amd64.go     |   2 +-
 .../chacha20poly1305/chacha20poly1305_amd64.s      |  30 +-
 .../chacha20poly1305/chacha20poly1305_noasm.go     |   2 +-
 test/fixedbugs/gcc78763.go                         |  19 +
 test/fixedbugs/issue10958.go                       |  95 ++++
 test/fixedbugs/issue18392.go                       |  11 +
 test/fixedbugs/issue18410.go                       |  40 ++
 test/fixedbugs/issue18459.go                       |  13 +
 test/fixedbugs/issue6772.go                        |  21 +
 test/live.go                                       |   3 +-
 test/nosplit.go                                    |   2 +
 test/opt_branchlikely.go                           |   3 +-
 test/run.go                                        |  63 ++-
 test/zerodivide.go                                 |   9 +-
 182 files changed, 3034 insertions(+), 827 deletions(-)

diff --git a/AUTHORS b/AUTHORS
index 6e61db2..555ce0a 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -29,11 +29,13 @@ Akshat Kumar <seed at mail.nanosouffle.net>
 Alan Shreve <alan at inconshreveable.com>
 Albert Nigmatzianov <albertnigma at gmail.com>
 Albert Strasheim <fullung at gmail.com>
+Albert Yu <yukinying at gmail.com>
 Alberto Bertogli <albertito at blitiri.com.ar>
 Alberto Donizetti <alb.donizetti at gmail.com>
 Alberto García Hierro <alberto at garciahierro.com> <alberto.garcia.hierro at gmail.com>
 Aleksandar Dezelin <dezelin at gmail.com>
 Alessandro Arzilli <alessandro.arzilli at gmail.com>
+Alessandro Baffa <alessandro.baffa at gmail.com>
 Alex A Skinner <alex at lx.lc>
 Alex Brainman <alex.brainman at gmail.com>
 Alex Browne <stephenalexbrowne at gmail.com>
@@ -54,6 +56,7 @@ Alexander Surma <surma at surmair.de>
 Alexander Zhavnerchik <alex.vizor at gmail.com>
 Alexander Zolotov <goldifit at gmail.com>
 Alexandre Cesaro <alexandre.cesaro at gmail.com>
+Alexandre Fiori <fiorix at gmail.com>
 Alexandre Normand <alexandre.normand at gmail.com>
 Alexei Sholik <alcosholik at gmail.com>
 Alexey Borzenkov <snaury at gmail.com>
@@ -70,6 +73,7 @@ Andreas Auernhammer <aead at mail.de>
 Andreas Litt <andreas.litt at gmail.com>
 Andrei Korzhevskii <a.korzhevskiy at gmail.com>
 Andrei Vieru <euvieru at gmail.com>
+Andrew Austin <andrewaclt at gmail.com>
 Andrew Balholm <andybalholm at gmail.com>
 Andrew Bonventre <andybons at chromium.org>
 Andrew Bursavich <abursavich at gmail.com>
@@ -89,6 +93,7 @@ Andrey Petrov <andrey.petrov at shazow.net>
 Andriy Lytvynov <lytvynov.a.v at gmail.com>
 Andy Balholm <andy at balholm.com>
 Andy Davis <andy at bigandian.com>
+Andy Finkenstadt <afinkenstadt at zynga.com>
 Andy Maloney <asmaloney at gmail.com>
 Anfernee Yongkun Gui <anfernee.gui at gmail.com>
 Angelo Bulfone <mbulfone at gmail.com>
@@ -100,6 +105,7 @@ Anthony Eufemio <anthony.eufemio at gmail.com>
 Anthony Martin <ality at pbrane.org>
 Anthony Starks <ajstarks at gmail.com>
 Anthony Woods <awoods at raintank.io>
+Antonio Bibiano <antbbn at gmail.com>
 Apisak Darakananda <pongad at gmail.com>
 Aram Hăvărneanu <aram at mgk.ro>
 Areski Belaid <areski at gmail.com>
@@ -119,7 +125,9 @@ Aulus Egnatius Varialus <varialus at gmail.com>
 awaw fumin <awawfumin at gmail.com>
 Ayanamist Yang <ayanamist at gmail.com>
 Aymerick Jéhanne <aymerick at jehanne.org>
+Baiju Muthukadan <baiju.m.mail at gmail.com>
 Ben Burkert <ben at benburkert.com>
+Ben Lubar <ben.lubar at gmail.com>
 Ben Olive <sionide21 at gmail.com>
 Benjamin Black <b at b3k.us>
 Benny Siegert <bsiegert at gmail.com>
@@ -277,6 +285,7 @@ Erik St. Martin <alakriti at gmail.com>
 Erik Westrup <erik.westrup at gmail.com>
 Ernest Chiang <ernest_chiang at htc.com>
 Esko Luontola <esko.luontola at gmail.com>
+Euan Kemp <euank at euank.com>
 Evan Phoenix <evan at phx.io>
 Evan Shaw <chickencha at gmail.com>
 Ewan Chou <coocood at gmail.com>
@@ -332,6 +341,7 @@ Hajime Hoshi <hajimehoshi at gmail.com>
 Hari haran <hariharan.uno at gmail.com>
 Hariharan Srinath <srinathh at gmail.com>
 Harley Laue <losinggeneration at gmail.com>
+Harry Moreno <morenoh149 at gmail.com>
 Harshavardhana <hrshvardhana at gmail.com>
 Håvard Haugen <havard.haugen at gmail.com>
 Hector Chu <hectorchu at gmail.com>
@@ -434,6 +444,7 @@ Jonathan Rudenberg <jonathan at titanous.com>
 Jonathan Wills <runningwild at gmail.com>
 Jongmin Kim <atomaths at gmail.com>
 Joonas Kuorilehto <joneskoo at derbian.fi>
+Joop Kiefte <ikojba at gmail.com> <joop at kiefte.net>
 Jordan Lewis <jordanthelewis at gmail.com>
 Jose Luis Vázquez González <josvazg at gmail.com>
 Joseph Holsten <joseph at josephholsten.com>
@@ -500,6 +511,7 @@ Luigi Riefolo <luigi.riefolo at gmail.com>
 Luit van Drongelen <luitvd at gmail.com>
 Luka Zakrajšek <tr00.g33k at gmail.com>
 Luke Curley <qpingu at gmail.com>
+Maksym Trykur <maksym.trykur at gmail.com>
 Mal Curtis <mal at mal.co.nz>
 Manfred Touron <m at 42.am>
 Manu S Ajith <neo at codingarena.in>
@@ -545,6 +557,7 @@ Matthew Denton <mdenton at skyportsystems.com>
 Matthew Holt <Matthew.Holt+git at gmail.com>
 Matthew Horsnell <matthew.horsnell at gmail.com>
 Matthieu Hauglustaine <matt.hauglustaine at gmail.com>
+Matthieu Olivier <olivier.matthieu at gmail.com>
 Max Riveiro <kavu13 at gmail.com>
 Maxim Khitrov <max at mxcrypt.com>
 Maxwell Krohn <themax at gmail.com>
@@ -610,6 +623,7 @@ Nicholas Presta <nick at nickpresta.ca> <nick1presta at gmail.com>
 Nicholas Sullivan <nicholas.sullivan at gmail.com>
 Nicholas Waples <nwaples at gmail.com>
 Nick Craig-Wood <nick at craig-wood.com> <nickcw at gmail.com>
+Nick Leli <nicholasleli at gmail.com>
 Nick Patavalis <nick.patavalis at gmail.com>
 Nick Petroni <npetroni at cs.umd.edu>
 Nicolas Kaiser <nikai at nikai.net>
@@ -617,6 +631,7 @@ Nicolas Owens <mischief at offblast.org>
 Nicolas S. Dade <nic.dade at gmail.com>
 Niels Widger <niels.widger at gmail.com>
 Nigel Kerr <nigel.kerr at gmail.com>
+Nik Nyby <nnyby at columbia.edu>
 Niko Dziemba <niko at dziemba.com>
 Nikolay Turpitko <nikolay at turpitko.com>
 Noah Campbell <noahcampbell at gmail.com>
@@ -686,9 +701,11 @@ Quentin Perez <qperez at ocs.online.net>
 Quoc-Viet Nguyen <afelion at gmail.com>
 RackTop Systems Inc.
 Radu Berinde <radu at cockroachlabs.com>
+Rafal Jeczalik <rjeczalik at gmail.com>
 Raif S. Naffah <go at naffah-raif.name>
 Rajat Goel <rajat.goel2010 at gmail.com>
 Ralph Corderoy <ralph at inputplus.co.uk>
+Raphael Geronimi <raphael.geronimi at gmail.com>
 Red Hat, Inc.
 Reinaldo de Souza Jr <juniorz at gmail.com>
 Rémy Oudompheng <oudomphe at phare.normalesup.org>
@@ -719,6 +736,7 @@ Ron Minnich <rminnich at gmail.com>
 Ross Light <rlight2 at gmail.com>
 Rowan Worth <sqweek at gmail.com>
 Russell Haering <russellhaering at gmail.com>
+Ryan Bagwell <ryanbagwell at outlook.com>
 Ryan Hitchman <hitchmanr at gmail.com>
 Ryan Lower <rpjlower at gmail.com>
 Ryan Seys <ryan at ryanseys.com>
@@ -758,6 +776,7 @@ Simon Whitehead <chemnova at gmail.com>
 Sina Siadat <siadat at gmail.com>
 Sokolov Yura <funny.falcon at gmail.com>
 Song Gao <song at gao.io>
+Sourcegraph Inc
 Spencer Nelson <s at spenczar.com>
 Spring Mc <heresy.mc at gmail.com>
 Square, Inc.
@@ -814,6 +833,7 @@ Totoro W <tw19881113 at gmail.com>
 Travis Cline <travis.cline at gmail.com>
 Trey Lawrence <lawrence.trey at gmail.com>
 Trey Tacon <ttacon at gmail.com>
+Tristan Colgate <tcolgate at gmail.com>
 Tristan Ooohry <ooohry at gmail.com>
 Tudor Golubenco <tudor.g at gmail.com>
 Tuo Shan <sturbo89 at gmail.com>
@@ -866,4 +886,5 @@ Zemanta d.o.o.
 Zev Goldstein <zev.goldstein at gmail.com>
 Ziad Hatahet <hatahet at gmail.com>
 Zorion Arrizabalaga <zorionk at gmail.com>
+Фахриддин Балтаев <faxriddinjon at gmail.com>
 申习之 <bronze1man at gmail.com>
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 4120daf..9620d81 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -7,6 +7,11 @@ It is the work of hundreds of contributors. We appreciate your help!
 
 ## Filing issues
 
+General questions should go to the
+[golang-nuts mailing list](https://groups.google.com/group/golang-nuts) or
+[other forum](https://golang.org/wiki/Questions) instead of the issue tracker.
+The gophers there will answer or ask you to file an issue if you've tripped over a bug.
+
 When filing an issue, make sure to answer these five questions:
 
 1. What version of Go are you using (`go version`)?
@@ -15,8 +20,7 @@ When filing an issue, make sure to answer these five questions:
 4. What did you expect to see?
 5. What did you see instead?
 
-General questions should go to the [golang-nuts mailing list](https://groups.google.com/group/golang-nuts) instead of the issue tracker.
-The gophers there will answer or ask you to file an issue if you've tripped over a bug.
+For change proposals, see [Proposing Changes To Go](https://github.com/golang/proposal/).
 
 Sensitive security-related issues should be reported to [security at golang.org](mailto:security at golang.org).
 
@@ -28,6 +32,7 @@ before sending patches.
 **We do not accept GitHub pull requests**
 (we use [an instance](https://go-review.googlesource.com/) of the
 [Gerrit](https://www.gerritcodereview.com/) code review system instead).
+Also, please do not post patches on the issue tracker.
 
 Unless otherwise noted, the Go source files are distributed under
 the BSD-style license found in the LICENSE file.
diff --git a/CONTRIBUTORS b/CONTRIBUTORS
index 64cc592..d410b36 100644
--- a/CONTRIBUTORS
+++ b/CONTRIBUTORS
@@ -55,11 +55,13 @@ Alan Donovan <adonovan at google.com>
 Alan Shreve <alan at inconshreveable.com>
 Albert Nigmatzianov <albertnigma at gmail.com>
 Albert Strasheim <fullung at gmail.com>
+Albert Yu <yukinying at gmail.com>
 Alberto Bertogli <albertito at blitiri.com.ar>
 Alberto Donizetti <alb.donizetti at gmail.com>
 Alberto García Hierro <alberto at garciahierro.com> <alberto.garcia.hierro at gmail.com>
 Aleksandar Dezelin <dezelin at gmail.com>
 Alessandro Arzilli <alessandro.arzilli at gmail.com>
+Alessandro Baffa <alessandro.baffa at gmail.com>
 Alex A Skinner <alex at lx.lc>
 Alex Brainman <alex.brainman at gmail.com>
 Alex Bramley <abramley at google.com>
@@ -82,6 +84,7 @@ Alexander Surma <surma at surmair.de>
 Alexander Zhavnerchik <alex.vizor at gmail.com>
 Alexander Zolotov <goldifit at gmail.com>
 Alexandre Cesaro <alexandre.cesaro at gmail.com>
+Alexandre Fiori <fiorix at gmail.com>
 Alexandre Normand <alexandre.normand at gmail.com>
 Alexandru Moșoi <brtzsnr at gmail.com>
 Alexei Sholik <alcosholik at gmail.com>
@@ -102,6 +105,7 @@ Andreas Litt <andreas.litt at gmail.com>
 Andrei Korzhevskii <a.korzhevskiy at gmail.com>
 Andrei Vieru <euvieru at gmail.com>
 Andres Erbsen <andreser at google.com>
+Andrew Austin <andrewaclt at gmail.com>
 Andrew Balholm <andybalholm at gmail.com>
 Andrew Bonventre <andybons at chromium.org>
 Andrew Bursavich <abursavich at gmail.com>
@@ -124,6 +128,7 @@ Andrey Petrov <andrey.petrov at shazow.net>
 Andriy Lytvynov <lytvynov.a.v at gmail.com>
 Andy Balholm <andy at balholm.com>
 Andy Davis <andy at bigandian.com>
+Andy Finkenstadt <afinkenstadt at zynga.com>
 Andy Maloney <asmaloney at gmail.com>
 Anfernee Yongkun Gui <anfernee.gui at gmail.com>
 Angelo Bulfone <mbulfone at gmail.com>
@@ -135,6 +140,7 @@ Anthony Eufemio <anthony.eufemio at gmail.com>
 Anthony Martin <ality at pbrane.org>
 Anthony Starks <ajstarks at gmail.com>
 Anthony Woods <awoods at raintank.io>
+Antonio Bibiano <antbbn at gmail.com>
 Antonio Murdaca <runcom at redhat.com>
 Apisak Darakananda <pongad at gmail.com>
 Aram Hăvărneanu <aram at mgk.ro>
@@ -157,10 +163,12 @@ Austin Clements <austin at google.com> <aclements at csail.mit.edu>
 awaw fumin <awawfumin at gmail.com>
 Ayanamist Yang <ayanamist at gmail.com>
 Aymerick Jéhanne <aymerick at jehanne.org>
+Baiju Muthukadan <baiju.m.mail at gmail.com>
 Balazs Lecz <leczb at google.com>
 Ben Burkert <ben at benburkert.com>
 Ben Eitzen <eitzenb at golang.org>
 Ben Fried <ben.fried at gmail.com>
+Ben Lubar <ben.lubar at gmail.com>
 Ben Lynn <benlynn at gmail.com>
 Ben Olive <sionide21 at gmail.com>
 Benjamin Black <b at b3k.us>
@@ -384,6 +392,7 @@ Ernest Chiang <ernest_chiang at htc.com>
 Esko Luontola <esko.luontola at gmail.com>
 Ethan Burns <eaburns at google.com>
 Ethan Miller <eamiller at us.ibm.com>
+Euan Kemp <euank at euank.com>
 Evan Broder <evan at stripe.com>
 Evan Brown <evanbrown at google.com>
 Evan Kroske <evankroske at google.com>
@@ -454,6 +463,7 @@ Han-Wen Nienhuys <hanwen at google.com>
 Hari haran <hariharan.uno at gmail.com>
 Hariharan Srinath <srinathh at gmail.com>
 Harley Laue <losinggeneration at gmail.com>
+Harry Moreno <morenoh149 at gmail.com>
 Harshavardhana <hrshvardhana at gmail.com>
 Håvard Haugen <havard.haugen at gmail.com>
 Hector Chu <hectorchu at gmail.com>
@@ -524,6 +534,7 @@ Jan Ziak <0xe2.0x9a.0x9b at gmail.com>
 Jani Monoses <jani.monoses at ubuntu.com> <jani.monoses at gmail.com>
 Jaroslavas Počepko <jp at webmaster.ms>
 Jason Barnett <jason.w.barnett at gmail.com>
+Jason Buberel <jbuberel at google.com>
 Jason Del Ponte <delpontej at gmail.com>
 Jason Hall <jasonhall at google.com>
 Jason Smale <jsmale at zendesk.com>
@@ -593,6 +604,7 @@ Jonathan Rudenberg <jonathan at titanous.com>
 Jonathan Wills <runningwild at gmail.com>
 Jongmin Kim <atomaths at gmail.com>
 Joonas Kuorilehto <joneskoo at derbian.fi>
+Joop Kiefte <ikojba at gmail.com> <joop at kiefte.net>
 Jordan Lewis <jordanthelewis at gmail.com>
 Jos Visser <josv at google.com>
 Jose Luis Vázquez González <josvazg at gmail.com>
@@ -680,6 +692,7 @@ Luke Curley <qpingu at gmail.com>
 Luna Duclos <luna.duclos at palmstonegames.com>
 Luuk van Dijk <lvd at golang.org> <lvd at google.com>
 Lynn Boger <laboger at linux.vnet.ibm.com>
+Maksym Trykur <maksym.trykur at gmail.com>
 Mal Curtis <mal at mal.co.nz>
 Manfred Touron <m at 42.am>
 Manoj Dayaram <platform-dev at moovweb.com> <manoj.dayaram at moovweb.com>
@@ -736,6 +749,7 @@ Matthew Denton <mdenton at skyportsystems.com>
 Matthew Holt <Matthew.Holt+git at gmail.com>
 Matthew Horsnell <matthew.horsnell at gmail.com>
 Matthieu Hauglustaine <matt.hauglustaine at gmail.com>
+Matthieu Olivier <olivier.matthieu at gmail.com>
 Max Riveiro <kavu13 at gmail.com>
 Maxim Khitrov <max at mxcrypt.com>
 Maxim Pimenov <mpimenov at google.com>
@@ -820,6 +834,7 @@ Nicholas Waples <nwaples at gmail.com>
 Nick Cooper <nmvc at google.com>
 Nick Craig-Wood <nick at craig-wood.com> <nickcw at gmail.com>
 Nick Harper <nharper at google.com>
+Nick Leli <nicholasleli at gmail.com>
 Nick Patavalis <nick.patavalis at gmail.com>
 Nick Petroni <npetroni at cs.umd.edu>
 Nicolas Kaiser <nikai at nikai.net>
@@ -828,6 +843,7 @@ Nicolas S. Dade <nic.dade at gmail.com>
 Niels Widger <niels.widger at gmail.com>
 Nigel Kerr <nigel.kerr at gmail.com>
 Nigel Tao <nigeltao at golang.org>
+Nik Nyby <nnyby at columbia.edu>
 Niko Dziemba <niko at dziemba.com>
 Nikolay Turpitko <nikolay at turpitko.com>
 Noah Campbell <noahcampbell at gmail.com>
@@ -910,14 +926,17 @@ Quan Tran <qeed.quan at gmail.com>
 Quan Yong Zhai <qyzhai at gmail.com>
 Quentin Perez <qperez at ocs.online.net>
 Quentin Smith <quentin at golang.org>
+Quinn Slack <sqs at sourcegraph.com>
 Quoc-Viet Nguyen <afelion at gmail.com>
 Radu Berinde <radu at cockroachlabs.com>
+Rafal Jeczalik <rjeczalik at gmail.com>
 Rahul Chaudhry <rahulchaudhry at chromium.org>
 Raif S. Naffah <go at naffah-raif.name>
 Rajat Goel <rajat.goel2010 at gmail.com>
 Ralph Corderoy <ralph at inputplus.co.uk>
 Ramesh Dharan <dharan at google.com>
 Raph Levien <raph at google.com>
+Raphael Geronimi <raphael.geronimi at gmail.com>
 Raul Silvera <rsilvera at google.com>
 Rebecca Stambler <rstambler at golang.org>
 Reinaldo de Souza Jr <juniorz at gmail.com>
@@ -960,6 +979,7 @@ Rowan Worth <sqweek at gmail.com>
 Rui Ueyama <ruiu at google.com>
 Russ Cox <rsc at golang.org>
 Russell Haering <russellhaering at gmail.com>
+Ryan Bagwell <ryanbagwell at outlook.com>
 Ryan Barrett <ryanb at google.com>
 Ryan Brown <ribrdb at google.com>
 Ryan Hitchman <hitchmanr at gmail.com>
@@ -1030,6 +1050,7 @@ Stéphane Travostino <stephane.travostino at gmail.com>
 Stephen Ma <stephenm at golang.org>
 Stephen McQuay <stephen at mcquay.me>
 Stephen Weinberg <stephen at q5comm.com>
+Steve Francia <spf at golang.org>
 Steve McCoy <mccoyst at gmail.com>
 Steve Newman <snewman at google.com>
 Steve Phillips <elimisteve at gmail.com>
@@ -1092,6 +1113,7 @@ Trevor Strohman <trevor.strohman at gmail.com>
 Trey Lawrence <lawrence.trey at gmail.com>
 Trey Tacon <ttacon at gmail.com>
 Tristan Amini <tamini01 at ca.ibm.com>
+Tristan Colgate <tcolgate at gmail.com>
 Tristan Ooohry <ooohry at gmail.com>
 Tudor Golubenco <tudor.g at gmail.com>
 Tuo Shan <sturbo89 at gmail.com> <shantuo at google.com>
@@ -1157,4 +1179,5 @@ Zev Goldstein <zev.goldstein at gmail.com>
 Zhongwei Yao <zhongwei.yao at arm.com>
 Ziad Hatahet <hatahet at gmail.com>
 Zorion Arrizabalaga <zorionk at gmail.com>
+Фахриддин Балтаев <faxriddinjon at gmail.com>
 申习之 <bronze1man at gmail.com>
diff --git a/VERSION b/VERSION
index de57d7f..674242a 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-go1.8beta2
\ No newline at end of file
+go1.8rc1
\ No newline at end of file
diff --git a/api/go1.8.txt b/api/go1.8.txt
index 5e21b07..fca7e03 100644
--- a/api/go1.8.txt
+++ b/api/go1.8.txt
@@ -176,7 +176,6 @@ pkg expvar, method (*Float) Value() float64
 pkg expvar, method (Func) Value() interface{}
 pkg expvar, method (*Int) Value() int64
 pkg expvar, method (*String) Value() string
-pkg go/build, type NoGoError struct, Ignored bool
 pkg go/doc, func IsPredeclared(string) bool
 pkg go/types, func Default(Type) Type
 pkg go/types, func IdenticalIgnoreTags(Type, Type) bool
diff --git a/doc/asm.html b/doc/asm.html
index 3e03c54..79dc7df 100644
--- a/doc/asm.html
+++ b/doc/asm.html
@@ -838,6 +838,44 @@ It is a scaled mode as on the x86, but the only scale allowed is <code>1</code>.
 
 </ul>
 
+<h3 id="mips">MIPS, MIPS64</h3>
+
+<p>
+General purpose registers are named <code>R0</code> through <code>R31</code>,
+floating point registers are <code>F0</code> through <code>F31</code>.
+</p>
+
+<p>
+<code>R30</code> is reserved to point to <code>g</code>.
+<code>R23</code> is used as a temporary register.
+</p>
+
+<p>
+In a <code>TEXT</code> directive, the frame size <code>$-4</code> for MIPS or
+<code>$-8</code> for MIPS64 instructs the linker not to save <code>LR</code>.
+</p>
+
+<p>
+<code>SP</code> refers to the virtual stack pointer.
+For the hardware register, use <code>R29</code>.
+</p>
+
+<p>
+Addressing modes:
+</p>
+
+<ul>
+
+<li>
+<code>16(R1)</code>: The location at <code>R1</code> plus 16.
+</li>
+
+<li>
+<code>(R1)</code>: Alias for <code>0(R1)</code>.
+</li>
+
+</ul>
+
 <h3 id="unsupported_opcodes">Unsupported opcodes</h3>
 
 <p>
diff --git a/doc/code.html b/doc/code.html
index 9978b52..796431a 100644
--- a/doc/code.html
+++ b/doc/code.html
@@ -160,9 +160,13 @@ $ <b>export GOPATH=$(go env GOPATH)</b>
 </pre>
 
 <p>
-To learn more about setting up the <code>GOPATH</code> environment variable,
-please see
-<a href="/cmd/go/#hdr-GOPATH_environment_variable"><code>'go help gopath'</code></a>
+To learn more about the <code>GOPATH</code> environment variable, see
+<a href="/cmd/go/#hdr-GOPATH_environment_variable"><code>'go help gopath'</code></a>.
+</p>
+
+<p>
+To use a custom workspace location,
+<a href="https://golang.org/wiki/SettingGOPATH">set the <code>GOPATH</code> environment variable</a>.
 </p>
 
 <h3 id="ImportPaths">Import paths</h3>
diff --git a/doc/go1.8.html b/doc/go1.8.html
index 1ea0188..2ac4786 100644
--- a/doc/go1.8.html
+++ b/doc/go1.8.html
@@ -327,6 +327,18 @@ see improvements closer to the 32-bit ARM numbers.
 
 <h3 id="cmd_cgo">Cgo</h3>
 
+<p> <!-- CL 31141 -->
+The Go tool now remembers the value of the <code>CGO_ENABLED</code> environment
+variable set during <code>make.bash</code> and applies it to all future compilations
+by default to fix issue <a href="https://golang.org/issue/12808">#12808</a>.
+When doing native compilation, it is rarely necessary to explicitly set
+the <code>CGO_ENABLED</code> environment variable as <code>make.bash</code>
+will detect the correct setting automatically. The main reason to explicitly
+set the <code>CGO_ENABLED</code> environment variable is when your environment
+supports cgo, but you explicitly do not want cgo support, in which case, set
+<code>CGO_ENABLED=0</code> during <code>make.bash</code> or <code>all.bash</code>.
+</p>
+
 <p> <!-- CL 29991 -->
 The environment variable <code>PKG_CONFIG</code> may now be used to
 set the program to run to handle <code>#cgo</code> <code>pkg-config</code>
@@ -379,6 +391,15 @@ version of gccgo.
   <code>%USERPROFILE%/go</code> on Windows.
 </p>
 
+<h3 id="go_get">Go get</h3>
+
+<p> <!-- CL 34818 -->
+  The “<code>go</code> <code>get</code>” command now always respects
+  HTTP proxy environment variables, regardless of whether
+  the <code style='white-space:nowrap'>-insecure</code> flag is used. In previous releases, the
+  <code style='white-space:nowrap'>-insecure</code> flag had the side effect of not using proxies.
+</p>
+
 <h3 id="go_bug">Go bug</h3>
 
 <p>
@@ -619,6 +640,13 @@ now implements the new
   <a href="/pkg/runtime/#SetMutexProfileFraction"><code>SetMutexProfileFraction</code></a>.
 </p>
 
+<p>
+  A known limitation for Go 1.8 is that the profile only reports contention for
+  <a href="/pkg/sync/#Mutex"><code>sync.Mutex</code></a>,
+  not 
+  <a href="/pkg/sync/#RWMutex"><code>sync.RWMutex</code></a>.
+</p>
+
 <h3 id="minor_library_changes">Minor changes to the library</h3>
 
 <p>
@@ -642,23 +670,6 @@ Optimizations and minor bug fixes are not listed.
   </dd>
 </dl>
 
-<dl id="archive_zip"><dt><a href="/pkg/archive/zip/">archive/zip</a></dt>
-  <dd>
-
-    <p> <!-- CL 18274 -->
-      The
-      <a href="/pkg/archive/zip/#Reader"><code>Reader</code></a>
-      now supports modification times in
-      the NTFS, UNIX, and Extended Time Stamp metadata fields.
-      <!-- CL 30811 -->
-      The
-      <a href="/pkg/archive/zip/#Writer"><code>Writer</code></a>
-      now writes Extended Time Stamp fields.
-    </p>
-
-  </dd>
-</dl>
-
 <dl id="compress_flate"><dt><a href="/pkg/compress/flate/">compress/flate</a></dt>
   <dd>
 
@@ -1288,9 +1299,17 @@ crypto/x509: return error for missing SerialNumber (CL 27238)
       </li>
 
       <li><!-- CL 31733, CL 29852 -->
-        The <code>Client</code> now supports 307 and 308 redirects.
-        If the redirect requires resending the request body,
-        the request must have the new
+        The <code>Client</code> now supports 301, 307, and 308 redirects.
+
+        For example, <code>Client.Post</code> now follows 301
+        redirects, converting them to <code>GET</code> requests
+        without bodies, like it did for 302 and 303 redirect responses
+        previously.
+
+        The <code>Client</code> now also follows 307 and 308
+        redirects, preserving the original request method and body, if
+        any. If the redirect requires resending the request body, the
+        request must have the new
         <a href="/pkg/net/http/#Request"><code>Request.GetBody</code></a>
         field defined.
         <a href="pkg/net/http/#NewRequest"><code>NewRequest</code></a>
diff --git a/doc/install.html b/doc/install.html
index d8e04b7..2143d59 100644
--- a/doc/install.html
+++ b/doc/install.html
@@ -246,12 +246,12 @@ Then build it with the <code>go</code> tool:
 </p>
 
 <pre class="testUnix">
-$ <b>cd $HOME/go/src/hello
+$ <b>cd $HOME/go/src/hello</b>
 $ <b>go build</b>
 </pre>
 
 <pre class="testWindows" style="display: none">
-C:\> <b>cd %USERPROFILE%\go\src\hello<b>
+C:\> <b>cd %USERPROFILE%\go\src\hello</b>
 C:\Users\Gopher\go\src\hello> <b>go build</b>
 </pre>
 
@@ -313,16 +313,10 @@ environment variables under Windows</a>.
 <h2 id="help">Getting help</h2>
 
 <p>
-For real-time help, ask the helpful gophers in <code>#go-nuts</code> on the
-<a href="http://freenode.net/">Freenode</a> IRC server.
+  For help, see the <a href="/help/">list of Go mailing lists, forums, and places to chat</a>.
 </p>
 
 <p>
-The official mailing list for discussion of the Go language is
-<a href="//groups.google.com/group/golang-nuts">Go Nuts</a>.
-</p>
-
-<p>
-Report bugs using the
-<a href="//golang.org/issue">Go issue tracker</a>.
+  Report bugs either by running “<b><code>go</code> <code>bug</code></b>”, or
+  manually at the <a href="https://golang.org/issue">Go issue tracker</a>.
 </p>
diff --git a/lib/time/update.bash b/lib/time/update.bash
index b70788e..4297c5f 100755
--- a/lib/time/update.bash
+++ b/lib/time/update.bash
@@ -8,8 +8,8 @@
 # Consult http://www.iana.org/time-zones for the latest versions.
 
 # Versions to use.
-CODE=2016i
-DATA=2016i
+CODE=2016j
+DATA=2016j
 
 set -e
 rm -rf work
diff --git a/lib/time/zoneinfo.zip b/lib/time/zoneinfo.zip
index e12d6dc..d33dc1d 100644
Binary files a/lib/time/zoneinfo.zip and b/lib/time/zoneinfo.zip differ
diff --git a/misc/cgo/test/issue18146.go b/misc/cgo/test/issue18146.go
index 19c52b6..ffb04e9 100644
--- a/misc/cgo/test/issue18146.go
+++ b/misc/cgo/test/issue18146.go
@@ -37,6 +37,31 @@ func test18146(t *testing.T) {
 		attempts = 100
 	}
 
+	// Restrict the number of attempts based on RLIMIT_NPROC.
+	// Tediously, RLIMIT_NPROC was left out of the syscall package,
+	// probably because it is not in POSIX.1, so we define it here.
+	// It is not defined on Solaris.
+	var nproc int
+	setNproc := true
+	switch runtime.GOOS {
+	default:
+		setNproc = false
+	case "linux":
+		nproc = 6
+	case "darwin", "dragonfly", "freebsd", "netbsd", "openbsd":
+		nproc = 7
+	}
+	if setNproc {
+		var rlim syscall.Rlimit
+		if syscall.Getrlimit(nproc, &rlim) == nil {
+			max := int(rlim.Cur) / (threads + 5)
+			if attempts > max {
+				t.Logf("lowering attempts from %d to %d for RLIMIT_NPROC", attempts, max)
+				attempts = max
+			}
+		}
+	}
+
 	if os.Getenv("test18146") == "exec" {
 		runtime.GOMAXPROCS(1)
 		for n := threads; n > 0; n-- {
diff --git a/misc/cgo/testcshared/main2.c b/misc/cgo/testcshared/main2.c
index 9752006..6e8bf14 100644
--- a/misc/cgo/testcshared/main2.c
+++ b/misc/cgo/testcshared/main2.c
@@ -21,7 +21,7 @@ int main(void) {
 
   // The descriptor will be initialized in a thread, so we have to
   // give a chance to get opened.
-  for (i = 0; i < 100; i++) {
+  for (i = 0; i < 1000; i++) {
     n = read(fd, buf, sizeof buf);
     if (n >= 0)
       break;
diff --git a/misc/cgo/testsanitizers/test.bash b/misc/cgo/testsanitizers/test.bash
index 9853875..dfc6d38 100755
--- a/misc/cgo/testsanitizers/test.bash
+++ b/misc/cgo/testsanitizers/test.bash
@@ -24,8 +24,14 @@ msan=yes
 
 TMPDIR=${TMPDIR:-/tmp}
 echo 'int main() { return 0; }' > ${TMPDIR}/testsanitizers$$.c
-if $CC -fsanitize=memory -c ${TMPDIR}/testsanitizers$$.c -o ${TMPDIR}/testsanitizers$$.o 2>&1 | grep "unrecognized" >& /dev/null; then
-  echo "skipping msan tests: -fsanitize=memory not supported"
+if $CC -fsanitize=memory -o ${TMPDIR}/testsanitizers$$ ${TMPDIR}/testsanitizers$$.c 2>&1 | grep "unrecognized" >& /dev/null; then
+  echo "skipping msan tests: $CC -fsanitize=memory not supported"
+  msan=no
+elif ! test -x ${TMPDIR}/testsanitizers$$; then
+  echo "skipping msan tests: $CC -fsanitize-memory did not generate an executable"
+  msan=no
+elif ! ${TMPDIR}/testsanitizers$$ >/dev/null 2>&1; then
+  echo "skipping msan tests: $CC -fsanitize-memory generates broken executable"
   msan=no
 fi
 rm -f ${TMPDIR}/testsanitizers$$.*
diff --git a/misc/cgo/testsanitizers/tsan9.go b/misc/cgo/testsanitizers/tsan9.go
index 7cd0ac7..f166d8b 100644
--- a/misc/cgo/testsanitizers/tsan9.go
+++ b/misc/cgo/testsanitizers/tsan9.go
@@ -6,7 +6,8 @@ package main
 
 // This program failed when run under the C/C++ ThreadSanitizer. The
 // TSAN library was not keeping track of whether signals should be
-// delivered on the alternate signal stack.
+// delivered on the alternate signal stack, and the Go signal handler
+// was not preserving callee-saved registers from C callers.
 
 /*
 #cgo CFLAGS: -g -fsanitize=thread
@@ -19,10 +20,14 @@ void spin() {
 	size_t n;
 	struct timeval tvstart, tvnow;
 	int diff;
+	void *prev = NULL, *cur;
 
 	gettimeofday(&tvstart, NULL);
 	for (n = 0; n < 1<<20; n++) {
-		free(malloc(n));
+		cur = malloc(n);
+		free(prev);
+		prev = cur;
+
 		gettimeofday(&tvnow, NULL);
 		diff = (tvnow.tv_sec - tvstart.tv_sec) * 1000 * 1000 + (tvnow.tv_usec - tvstart.tv_usec);
 
@@ -32,6 +37,8 @@ void spin() {
 			break;
 		}
 	}
+
+	free(prev);
 }
 */
 import "C"
diff --git a/misc/cgo/testshared/src/exe/exe.go b/misc/cgo/testshared/src/exe/exe.go
index f01ad8a..4337271 100644
--- a/misc/cgo/testshared/src/exe/exe.go
+++ b/misc/cgo/testshared/src/exe/exe.go
@@ -12,6 +12,13 @@ import (
 func DeclaredInMain() {
 }
 
+type C struct {
+}
+
+func F() *C {
+	return nil
+}
+
 func main() {
 	defer depBase.ImplementedInAsm()
 	// This code below causes various go.itab.* symbols to be generated in
@@ -20,4 +27,9 @@ func main() {
 	reflect.TypeOf(os.Stdout).Elem()
 	runtime.GC()
 	depBase.V = depBase.F() + 1
+
+	var c *C
+	if reflect.TypeOf(F).Out(0) != reflect.TypeOf(c) {
+		panic("bad reflection results, see golang.org/issue/18252")
+	}
 }
diff --git a/misc/ios/clangwrap.sh b/misc/ios/clangwrap.sh
index 9cad49f..9141c8c 100755
--- a/misc/ios/clangwrap.sh
+++ b/misc/ios/clangwrap.sh
@@ -17,4 +17,4 @@ else
 	exit 1
 fi
 
-exec $CLANG -arch $CLANGARCH -isysroot $SDK_PATH "$@"
+exec $CLANG -arch $CLANGARCH -isysroot $SDK_PATH -mios-version-min=6.0 "$@"
diff --git a/src/archive/zip/reader.go b/src/archive/zip/reader.go
index 9bbc9a9..f6c3ead 100644
--- a/src/archive/zip/reader.go
+++ b/src/archive/zip/reader.go
@@ -13,7 +13,6 @@ import (
 	"hash/crc32"
 	"io"
 	"os"
-	"time"
 )
 
 var (
@@ -290,16 +289,13 @@ func readDirectoryHeader(f *File, r io.Reader) error {
 		// Other zip authors might not even follow the basic format,
 		// and we'll just ignore the Extra content in that case.
 		b := readBuf(f.Extra)
-
-	Extras:
 		for len(b) >= 4 { // need at least tag and size
 			tag := b.uint16()
 			size := b.uint16()
 			if int(size) > len(b) {
 				break
 			}
-			switch tag {
-			case zip64ExtraId:
+			if tag == zip64ExtraId {
 				// update directory values from the zip64 extra block.
 				// They should only be consulted if the sizes read earlier
 				// are maxed out.
@@ -327,42 +323,7 @@ func readDirectoryHeader(f *File, r io.Reader) error {
 					}
 					f.headerOffset = int64(eb.uint64())
 				}
-				break Extras
-
-			case ntfsExtraId:
-				if size == 32 {
-					eb := readBuf(b[:size])
-					eb.uint32() // reserved
-					eb.uint16() // tag1
-					size1 := eb.uint16()
-					if size1 == 24 {
-						sub := readBuf(eb[:size1])
-						lo := sub.uint32()
-						hi := sub.uint32()
-						tick := (uint64(uint64(lo)|uint64(hi)<<32) - 116444736000000000) / 10000000
-						f.SetModTime(time.Unix(int64(tick), 0))
-					}
-				}
-				break Extras
-
-			case unixExtraId:
-				if size >= 12 {
-					eb := readBuf(b[:size])
-					eb.uint32()          // AcTime
-					epoch := eb.uint32() // ModTime
-					f.SetModTime(time.Unix(int64(epoch), 0))
-					break Extras
-				}
-			case exttsExtraId:
-				if size >= 3 {
-					eb := readBuf(b[:size])
-					flags := eb.uint8()  // Flags
-					epoch := eb.uint32() // AcTime/ModTime/CrTime
-					if flags&1 != 0 {
-						f.SetModTime(time.Unix(int64(epoch), 0))
-					}
-					break Extras
-				}
+				break
 			}
 			b = b[size:]
 		}
@@ -547,12 +508,6 @@ func findSignatureInBlock(b []byte) int {
 
 type readBuf []byte
 
-func (b *readBuf) uint8() uint8 {
-	v := uint8((*b)[0])
-	*b = (*b)[1:]
-	return v
-}
-
 func (b *readBuf) uint16() uint16 {
 	v := binary.LittleEndian.Uint16(*b)
 	*b = (*b)[2:]
diff --git a/src/archive/zip/reader_test.go b/src/archive/zip/reader_test.go
index 576a169..dfaae78 100644
--- a/src/archive/zip/reader_test.go
+++ b/src/archive/zip/reader_test.go
@@ -65,13 +65,13 @@ var tests = []ZipTest{
 			{
 				Name:    "test.txt",
 				Content: []byte("This is a test text file.\n"),
-				Mtime:   "09-05-10 02:12:00",
+				Mtime:   "09-05-10 12:12:02",
 				Mode:    0644,
 			},
 			{
 				Name:  "gophercolor16x16.png",
 				File:  "gophercolor16x16.png",
-				Mtime: "09-05-10 05:52:58",
+				Mtime: "09-05-10 15:52:58",
 				Mode:  0644,
 			},
 		},
@@ -83,13 +83,13 @@ var tests = []ZipTest{
 			{
 				Name:    "test.txt",
 				Content: []byte("This is a test text file.\n"),
-				Mtime:   "09-05-10 02:12:00",
+				Mtime:   "09-05-10 12:12:02",
 				Mode:    0644,
 			},
 			{
 				Name:  "gophercolor16x16.png",
 				File:  "gophercolor16x16.png",
-				Mtime: "09-05-10 05:52:58",
+				Mtime: "09-05-10 15:52:58",
 				Mode:  0644,
 			},
 		},
@@ -145,17 +145,6 @@ var tests = []ZipTest{
 		File: crossPlatform,
 	},
 	{
-		Name: "extra-timestamp.zip",
-		File: []ZipTestFile{
-			{
-				Name:    "hello.txt",
-				Content: []byte(""),
-				Mtime:   "01-06-16 12:25:56",
-				Mode:    0666,
-			},
-		},
-	},
-	{
 		// created by Go, before we wrote the "optional" data
 		// descriptor signatures (which are required by OS X)
 		Name: "go-no-datadesc-sig.zip",
@@ -163,13 +152,13 @@ var tests = []ZipTest{
 			{
 				Name:    "foo.txt",
 				Content: []byte("foo\n"),
-				Mtime:   "03-09-12 00:59:10",
+				Mtime:   "03-08-12 16:59:10",
 				Mode:    0644,
 			},
 			{
 				Name:    "bar.txt",
 				Content: []byte("bar\n"),
-				Mtime:   "03-09-12 00:59:12",
+				Mtime:   "03-08-12 16:59:12",
 				Mode:    0644,
 			},
 		},
@@ -216,13 +205,13 @@ var tests = []ZipTest{
 			{
 				Name:    "foo.txt",
 				Content: []byte("foo\n"),
-				Mtime:   "03-09-12 00:59:10",
+				Mtime:   "03-08-12 16:59:10",
 				Mode:    0644,
 			},
 			{
 				Name:    "bar.txt",
 				Content: []byte("bar\n"),
-				Mtime:   "03-09-12 00:59:12",
+				Mtime:   "03-08-12 16:59:12",
 				Mode:    0644,
 			},
 		},
@@ -236,14 +225,14 @@ var tests = []ZipTest{
 			{
 				Name:       "foo.txt",
 				Content:    []byte("foo\n"),
-				Mtime:      "03-09-12 00:59:10",
+				Mtime:      "03-08-12 16:59:10",
 				Mode:       0644,
 				ContentErr: ErrChecksum,
 			},
 			{
 				Name:    "bar.txt",
 				Content: []byte("bar\n"),
-				Mtime:   "03-09-12 00:59:12",
+				Mtime:   "03-08-12 16:59:12",
 				Mode:    0644,
 			},
 		},
diff --git a/src/archive/zip/struct.go b/src/archive/zip/struct.go
index 287571e..e92d02f 100644
--- a/src/archive/zip/struct.go
+++ b/src/archive/zip/struct.go
@@ -63,9 +63,6 @@ const (
 
 	// extra header id's
 	zip64ExtraId = 0x0001 // zip64 Extended Information Extra Field
-	ntfsExtraId  = 0x000a // NTFS Extra Field
-	unixExtraId  = 0x000d // UNIX Extra Field
-	exttsExtraId = 0x5455 // Extended Timestamp Extra Field
 )
 
 // FileHeader describes a file within a zip file.
diff --git a/src/archive/zip/testdata/extra-timestamp.zip b/src/archive/zip/testdata/extra-timestamp.zip
deleted file mode 100644
index 819e22c..0000000
Binary files a/src/archive/zip/testdata/extra-timestamp.zip and /dev/null differ
diff --git a/src/archive/zip/writer.go b/src/archive/zip/writer.go
index ea4559e..8940e25 100644
--- a/src/archive/zip/writer.go
+++ b/src/archive/zip/writer.go
@@ -103,18 +103,6 @@ func (w *Writer) Close() error {
 			b.uint32(h.UncompressedSize)
 		}
 
-		// use Extended Timestamp Extra Field.
-		if h.ModifiedTime != 0 || h.ModifiedDate != 0 {
-			mt := uint32(h.ModTime().Unix())
-			var mbuf [9]byte // 2x uint16 + uint8 + uint32
-			eb := writeBuf(mbuf[:])
-			eb.uint16(exttsExtraId)
-			eb.uint16(5)  // size = uint8 + uint32
-			eb.uint8(1)   // flags = modtime
-			eb.uint32(mt) // ModTime
-			h.Extra = append(h.Extra, mbuf[:]...)
-		}
-
 		b.uint16(uint16(len(h.Name)))
 		b.uint16(uint16(len(h.Extra)))
 		b.uint16(uint16(len(h.Comment)))
@@ -397,11 +385,6 @@ func (w nopCloser) Close() error {
 
 type writeBuf []byte
 
-func (b *writeBuf) uint8(v uint8) {
-	(*b)[0] = v
-	*b = (*b)[1:]
-}
-
 func (b *writeBuf) uint16(v uint16) {
 	binary.LittleEndian.PutUint16(*b, v)
 	*b = (*b)[2:]
diff --git a/src/archive/zip/writer_test.go b/src/archive/zip/writer_test.go
index f20daa0..86841c7 100644
--- a/src/archive/zip/writer_test.go
+++ b/src/archive/zip/writer_test.go
@@ -11,7 +11,6 @@ import (
 	"math/rand"
 	"os"
 	"testing"
-	"time"
 )
 
 // TODO(adg): a more sophisticated test suite
@@ -21,7 +20,6 @@ type WriteTest struct {
 	Data   []byte
 	Method uint16
 	Mode   os.FileMode
-	Mtime  string
 }
 
 var writeTests = []WriteTest{
@@ -30,35 +28,30 @@ var writeTests = []WriteTest{
 		Data:   []byte("Rabbits, guinea pigs, gophers, marsupial rats, and quolls."),
 		Method: Store,
 		Mode:   0666,
-		Mtime:  "02-01-08 00:01:02",
 	},
 	{
 		Name:   "bar",
 		Data:   nil, // large data set in the test
 		Method: Deflate,
 		Mode:   0644,
-		Mtime:  "03-02-08 01:02:03",
 	},
 	{
 		Name:   "setuid",
 		Data:   []byte("setuid file"),
 		Method: Deflate,
 		Mode:   0755 | os.ModeSetuid,
-		Mtime:  "04-03-08 02:03:04",
 	},
 	{
 		Name:   "setgid",
 		Data:   []byte("setgid file"),
 		Method: Deflate,
 		Mode:   0755 | os.ModeSetgid,
-		Mtime:  "05-04-08 03:04:04",
 	},
 	{
 		Name:   "symlink",
 		Data:   []byte("../link/target"),
 		Method: Deflate,
 		Mode:   0755 | os.ModeSymlink,
-		Mtime:  "03-02-08 11:22:33",
 	},
 }
 
@@ -155,11 +148,6 @@ func testCreate(t *testing.T, w *Writer, wt *WriteTest) {
 	if wt.Mode != 0 {
 		header.SetMode(wt.Mode)
 	}
-	mtime, err := time.Parse("01-02-06 15:04:05", wt.Mtime)
-	if err != nil {
-		t.Fatal("time.Parse:", err)
-	}
-	header.SetModTime(mtime)
 	f, err := w.CreateHeader(header)
 	if err != nil {
 		t.Fatal(err)
@@ -190,21 +178,6 @@ func testReadFile(t *testing.T, f *File, wt *WriteTest) {
 	if !bytes.Equal(b, wt.Data) {
 		t.Errorf("File contents %q, want %q", b, wt.Data)
 	}
-
-	mtime, err := time.Parse("01-02-06 15:04:05", wt.Mtime)
-	if err != nil {
-		t.Fatal("time.Parse:", err)
-	}
-
-	diff := mtime.Sub(f.ModTime())
-	if diff < 0 {
-		diff = -diff
-	}
-
-	// allow several time span
-	if diff > 5*time.Second {
-		t.Errorf("File modtime %v, want %v", mtime, f.ModTime())
-	}
 }
 
 func BenchmarkCompressedZipGarbage(b *testing.B) {
diff --git a/src/archive/zip/zip_test.go b/src/archive/zip/zip_test.go
index 8801e90..57edb2c 100644
--- a/src/archive/zip/zip_test.go
+++ b/src/archive/zip/zip_test.go
@@ -15,7 +15,6 @@ import (
 	"internal/testenv"
 	"io"
 	"io/ioutil"
-	"reflect"
 	"sort"
 	"strings"
 	"testing"
@@ -114,44 +113,6 @@ func TestFileHeaderRoundTrip64(t *testing.T) {
 	testHeaderRoundTrip(fh, uint32max, fh.UncompressedSize64, t)
 }
 
-func TestZeroFileRoundTrip(t *testing.T) {
-	var b bytes.Buffer
-	w := NewWriter(&b)
-	if _, err := w.Create(""); err != nil {
-		t.Fatal(err)
-	}
-	if err := w.Close(); err != nil {
-		t.Fatal(err)
-	}
-	r, err := NewReader(bytes.NewReader(b.Bytes()), int64(b.Len()))
-	if err != nil {
-		t.Fatal(err)
-	}
-
-	// Verify that fields that should reasonably be the zero value stays
-	// as the zero value.
-	var want FileHeader
-	if len(r.File) != 1 {
-		t.Fatalf("len(r.File) = %d, want 1", len(r.File))
-	}
-	fh := r.File[0].FileHeader
-	got := FileHeader{
-		Name:               fh.Name,
-		ModifiedTime:       fh.ModifiedTime,
-		ModifiedDate:       fh.ModifiedDate,
-		UncompressedSize:   fh.UncompressedSize,
-		UncompressedSize64: fh.UncompressedSize64,
-		ExternalAttrs:      fh.ExternalAttrs,
-		Comment:            fh.Comment,
-	}
-	if len(fh.Extra) > 0 {
-		got.Extra = fh.Extra
-	}
-	if !reflect.DeepEqual(got, want) {
-		t.Errorf("FileHeader mismatch:\ngot  %#v\nwant %#v", got, want)
-	}
-}
-
 type repeatedByte struct {
 	off int64
 	b   byte
diff --git a/src/bytes/buffer.go b/src/bytes/buffer.go
index 2ee3d73..196419d 100644
--- a/src/bytes/buffer.go
+++ b/src/bytes/buffer.go
@@ -23,7 +23,7 @@ type Buffer struct {
 
 // The readOp constants describe the last action performed on
 // the buffer, so that UnreadRune and UnreadByte can check for
-// invalid usage. opReadRuneX constants are choosen such that
+// invalid usage. opReadRuneX constants are chosen such that
 // converted to int they correspond to the rune size that was read.
 type readOp int
 
diff --git a/src/cmd/compile/internal/gc/asm_test.go b/src/cmd/compile/internal/gc/asm_test.go
index 2e5d7e7..db800ab 100644
--- a/src/cmd/compile/internal/gc/asm_test.go
+++ b/src/cmd/compile/internal/gc/asm_test.go
@@ -175,6 +175,14 @@ func f(b []byte, i int) uint64 {
 	},
 	{"amd64", "linux", `
 import "encoding/binary"
+func f(b []byte, v uint64) {
+	binary.BigEndian.PutUint64(b, v)
+}
+`,
+		[]string{"\tBSWAPQ\t"},
+	},
+	{"amd64", "linux", `
+import "encoding/binary"
 func f(b []byte) uint32 {
 	return binary.BigEndian.Uint32(b)
 }
@@ -189,6 +197,14 @@ func f(b []byte, i int) uint32 {
 `,
 		[]string{"\tBSWAPL\t"},
 	},
+	{"amd64", "linux", `
+import "encoding/binary"
+func f(b []byte, v uint32) {
+	binary.BigEndian.PutUint32(b, v)
+}
+`,
+		[]string{"\tBSWAPL\t"},
+	},
 	{"386", "linux", `
 import "encoding/binary"
 func f(b []byte) uint32 {
@@ -205,6 +221,19 @@ func f(b []byte, i int) uint32 {
 `,
 		[]string{"\tMOVL\t\\(.*\\)\\(.*\\*1\\),"},
 	},
+
+	// Structure zeroing.  See issue #18370.
+	{"amd64", "linux", `
+type T struct {
+	a, b, c int
+}
+func f(t *T) {
+	*t = T{}
+}
+`,
+		[]string{"\tMOVQ\t\\$0, \\(.*\\)", "\tMOVQ\t\\$0, 8\\(.*\\)", "\tMOVQ\t\\$0, 16\\(.*\\)"},
+	},
+	// TODO: add a test for *t = T{3,4,5} when we fix that.
 }
 
 // mergeEnvLists merges the two environment lists such that
diff --git a/src/cmd/compile/internal/gc/bexport.go b/src/cmd/compile/internal/gc/bexport.go
index 1da5b69..ffc5419 100644
--- a/src/cmd/compile/internal/gc/bexport.go
+++ b/src/cmd/compile/internal/gc/bexport.go
@@ -1000,7 +1000,7 @@ func parName(f *Field, numbered bool) string {
 		Fatalf("invalid symbol name: %s", name)
 	}
 
-	// Functions that can be inlined use numbered parameters so we can distingish them
+	// Functions that can be inlined use numbered parameters so we can distinguish them
 	// from other names in their context after inlining (i.e., the parameter numbering
 	// is a form of parameter rewriting). See issue 4326 for an example and test case.
 	if forceObjFileStability || numbered {
diff --git a/src/cmd/compile/internal/gc/builtin.go b/src/cmd/compile/internal/gc/builtin.go
index e02e2fe..71b323f 100644
--- a/src/cmd/compile/internal/gc/builtin.go
+++ b/src/cmd/compile/internal/gc/builtin.go
@@ -15,6 +15,7 @@ var runtimeDecls = [...]struct {
 	{"panicwrap", funcTag, 7},
 	{"gopanic", funcTag, 9},
 	{"gorecover", funcTag, 12},
+	{"goschedguarded", funcTag, 5},
 	{"printbool", funcTag, 14},
 	{"printfloat", funcTag, 16},
 	{"printint", funcTag, 18},
diff --git a/src/cmd/compile/internal/gc/builtin/runtime.go b/src/cmd/compile/internal/gc/builtin/runtime.go
index 98e25fe..6951115 100644
--- a/src/cmd/compile/internal/gc/builtin/runtime.go
+++ b/src/cmd/compile/internal/gc/builtin/runtime.go
@@ -21,6 +21,7 @@ func panicwrap(string, string, string)
 
 func gopanic(interface{})
 func gorecover(*int32) interface{}
+func goschedguarded()
 
 func printbool(bool)
 func printfloat(float64)
diff --git a/src/cmd/compile/internal/gc/noder.go b/src/cmd/compile/internal/gc/noder.go
index a501cb6..ca99ade 100644
--- a/src/cmd/compile/internal/gc/noder.go
+++ b/src/cmd/compile/internal/gc/noder.go
@@ -1055,6 +1055,7 @@ func (p *noder) pragma(pos, line int, text string) syntax.Pragma {
 		lookup(f[1]).Linkname = f[2]
 
 	case strings.HasPrefix(text, "go:cgo_"):
+		lineno = p.baseline + int32(line) - 1 // pragcgo may call yyerror
 		pragcgobuf += pragcgo(text)
 		fallthrough // because of //go:cgo_unsafe_args
 	default:
@@ -1062,6 +1063,7 @@ func (p *noder) pragma(pos, line int, text string) syntax.Pragma {
 		if i := strings.Index(text, " "); i >= 0 {
 			verb = verb[:i]
 		}
+		lineno = p.baseline + int32(line) - 1 // pragmaValue may call yyerror
 		return syntax.Pragma(pragmaValue(verb))
 	}
 
diff --git a/src/cmd/compile/internal/gc/reflect.go b/src/cmd/compile/internal/gc/reflect.go
index 4f9d92e..61ac67c 100644
--- a/src/cmd/compile/internal/gc/reflect.go
+++ b/src/cmd/compile/internal/gc/reflect.go
@@ -998,7 +998,6 @@ func itabname(t, itype *Type) *Node {
 		Fatalf("itabname(%v, %v)", t, itype)
 	}
 	s := Pkglookup(t.tconv(FmtLeft)+","+itype.tconv(FmtLeft), itabpkg)
-	Linksym(s).Set(obj.AttrLocal, true)
 	if s.Def == nil {
 		n := newname(s)
 		n.Type = Types[TUINT8]
@@ -1411,15 +1410,15 @@ func dumptypestructs() {
 		// }
 		o := dsymptr(i.sym, 0, dtypesym(i.itype), 0)
 		o = dsymptr(i.sym, o, dtypesym(i.t), 0)
-		o += Widthptr + 8                      // skip link/bad/unused fields
+		o += Widthptr + 8                      // skip link/bad/inhash fields
 		o += len(imethods(i.itype)) * Widthptr // skip fun method pointers
 		// at runtime the itab will contain pointers to types, other itabs and
 		// method functions. None are allocated on heap, so we can use obj.NOPTR.
-		ggloblsym(i.sym, int32(o), int16(obj.DUPOK|obj.NOPTR|obj.LOCAL))
+		ggloblsym(i.sym, int32(o), int16(obj.DUPOK|obj.NOPTR))
 
 		ilink := Pkglookup(i.t.tconv(FmtLeft)+","+i.itype.tconv(FmtLeft), itablinkpkg)
 		dsymptr(ilink, 0, i.sym, 0)
-		ggloblsym(ilink, int32(Widthptr), int16(obj.DUPOK|obj.RODATA|obj.LOCAL))
+		ggloblsym(ilink, int32(Widthptr), int16(obj.DUPOK|obj.RODATA))
 	}
 
 	// process ptabs
diff --git a/src/cmd/compile/internal/gc/sinit.go b/src/cmd/compile/internal/gc/sinit.go
index 350c867..6b3c426 100644
--- a/src/cmd/compile/internal/gc/sinit.go
+++ b/src/cmd/compile/internal/gc/sinit.go
@@ -1078,6 +1078,8 @@ func anylit(n *Node, var_ *Node, init *Nodes) {
 
 		var r *Node
 		if n.Right != nil {
+			// n.Right is stack temporary used as backing store.
+			init.Append(nod(OAS, n.Right, nil)) // zero backing store, just in case (#18410)
 			r = nod(OADDR, n.Right, nil)
 			r = typecheck(r, Erv)
 		} else {
@@ -1195,7 +1197,7 @@ func getlit(lit *Node) int {
 	return -1
 }
 
-// stataddr sets nam to the static address of n and reports whether it succeeeded.
+// stataddr sets nam to the static address of n and reports whether it succeeded.
 func stataddr(nam *Node, n *Node) bool {
 	if n == nil {
 		return false
diff --git a/src/cmd/compile/internal/gc/ssa.go b/src/cmd/compile/internal/gc/ssa.go
index 55ee3c0..bf483f8 100644
--- a/src/cmd/compile/internal/gc/ssa.go
+++ b/src/cmd/compile/internal/gc/ssa.go
@@ -64,6 +64,9 @@ func buildssa(fn *Node) *ssa.Func {
 	s.config = initssa()
 	s.f = s.config.NewFunc()
 	s.f.Name = name
+	if fn.Func.Pragma&Nosplit != 0 {
+		s.f.NoSplit = true
+	}
 	s.exitCode = fn.Func.Exit
 	s.panics = map[funcLine]*ssa.Block{}
 	s.config.DebugTest = s.config.DebugHashMatch("GOSSAHASH", name)
diff --git a/src/cmd/compile/internal/gc/type.go b/src/cmd/compile/internal/gc/type.go
index 29048f1..5f04f68 100644
--- a/src/cmd/compile/internal/gc/type.go
+++ b/src/cmd/compile/internal/gc/type.go
@@ -213,7 +213,7 @@ func (t *Type) FuncType() *FuncType {
 	return t.Extra.(*FuncType)
 }
 
-// InterMethType contains Type fields specific to interface method psuedo-types.
+// InterMethType contains Type fields specific to interface method pseudo-types.
 type InterMethType struct {
 	Nname *Node
 }
diff --git a/src/cmd/compile/internal/gc/typecheck.go b/src/cmd/compile/internal/gc/typecheck.go
index 23c60fa..5ec1c9e 100644
--- a/src/cmd/compile/internal/gc/typecheck.go
+++ b/src/cmd/compile/internal/gc/typecheck.go
@@ -859,7 +859,7 @@ OpSwitch:
 			}
 
 			if n.Type.Etype != TFUNC || !n.IsMethod() {
-				yyerror("type %v has no method %S", n.Left.Type, n.Right.Sym)
+				yyerror("type %v has no method %S", n.Left.Type, n.Sym)
 				n.Type = nil
 				return n
 			}
diff --git a/src/cmd/compile/internal/gc/walk.go b/src/cmd/compile/internal/gc/walk.go
index 8248d50..efe2016 100644
--- a/src/cmd/compile/internal/gc/walk.go
+++ b/src/cmd/compile/internal/gc/walk.go
@@ -694,6 +694,10 @@ opswitch:
 			break
 		}
 
+		if !instrumenting && iszero(n.Right) && !needwritebarrier(n.Left, n.Right) {
+			break
+		}
+
 		switch n.Right.Op {
 		default:
 			n.Right = walkexpr(n.Right, init)
diff --git a/src/cmd/compile/internal/ssa/checkbce.go b/src/cmd/compile/internal/ssa/checkbce.go
index 820ea6e..3b15d5a 100644
--- a/src/cmd/compile/internal/ssa/checkbce.go
+++ b/src/cmd/compile/internal/ssa/checkbce.go
@@ -6,7 +6,7 @@ package ssa
 
 // checkbce prints all bounds checks that are present in the function.
 // Useful to find regressions. checkbce is only activated when with
-// corresponsing debug options, so it's off by default.
+// corresponding debug options, so it's off by default.
 // See test/checkbce.go
 func checkbce(f *Func) {
 	if f.pass.debug <= 0 {
diff --git a/src/cmd/compile/internal/ssa/compile.go b/src/cmd/compile/internal/ssa/compile.go
index b9ec7eb..5b461ba 100644
--- a/src/cmd/compile/internal/ssa/compile.go
+++ b/src/cmd/compile/internal/ssa/compile.go
@@ -5,6 +5,7 @@
 package ssa
 
 import (
+	"cmd/internal/obj"
 	"fmt"
 	"log"
 	"os"
@@ -349,6 +350,8 @@ var passes = [...]pass{
 	{name: "writebarrier", fn: writebarrier, required: true}, // expand write barrier ops
 	{name: "fuse", fn: fuse},
 	{name: "dse", fn: dse},
+	{name: "insert resched checks", fn: insertLoopReschedChecks,
+		disabled: obj.Preemptibleloops_enabled == 0}, // insert resched checks in loops.
 	{name: "tighten", fn: tighten}, // move values closer to their uses
 	{name: "lower", fn: lower, required: true},
 	{name: "lowered cse", fn: cse},
@@ -378,7 +381,13 @@ type constraint struct {
 }
 
 var passOrder = [...]constraint{
-	// prove reliese on common-subexpression elimination for maximum benefits.
+	// "insert resched checks" uses mem, better to clean out stores first.
+	{"dse", "insert resched checks"},
+	// insert resched checks adds new blocks containing generic instructions
+	{"insert resched checks", "lower"},
+	{"insert resched checks", "tighten"},
+
+	// prove relies on common-subexpression elimination for maximum benefits.
 	{"generic cse", "prove"},
 	// deadcode after prove to eliminate all new dead blocks.
 	{"prove", "generic deadcode"},
diff --git a/src/cmd/compile/internal/ssa/config.go b/src/cmd/compile/internal/ssa/config.go
index 919386e..4931da8 100644
--- a/src/cmd/compile/internal/ssa/config.go
+++ b/src/cmd/compile/internal/ssa/config.go
@@ -93,7 +93,7 @@ type Logger interface {
 	// Warnl writes compiler messages in the form expected by "errorcheck" tests
 	Warnl(line int32, fmt_ string, args ...interface{})
 
-	// Fowards the Debug flags from gc
+	// Forwards the Debug flags from gc
 	Debug_checknil() bool
 	Debug_wb() bool
 }
diff --git a/src/cmd/compile/internal/ssa/func.go b/src/cmd/compile/internal/ssa/func.go
index 7b2097b..df29aa3 100644
--- a/src/cmd/compile/internal/ssa/func.go
+++ b/src/cmd/compile/internal/ssa/func.go
@@ -24,6 +24,7 @@ type Func struct {
 	vid        idAlloc     // value ID allocator
 
 	scheduled bool // Values in Blocks are in final order
+	NoSplit   bool // true if function is marked as nosplit.  Used by schedule check pass.
 
 	// when register allocation is done, maps value ids to locations
 	RegAlloc []Location
diff --git a/src/cmd/compile/internal/ssa/gen/ARM64Ops.go b/src/cmd/compile/internal/ssa/gen/ARM64Ops.go
index dce61e3..e8d5be2 100644
--- a/src/cmd/compile/internal/ssa/gen/ARM64Ops.go
+++ b/src/cmd/compile/internal/ssa/gen/ARM64Ops.go
@@ -12,7 +12,7 @@ import "strings"
 //  - Integer types live in the low portion of registers. Upper portions are junk.
 //  - Boolean types use the low-order byte of a register. 0=false, 1=true.
 //    Upper bytes are junk.
-//  - *const instructions may use a constant larger than the instuction can encode.
+//  - *const instructions may use a constant larger than the instruction can encode.
 //    In this case the assembler expands to multiple instructions and uses tmp
 //    register (R27).
 
diff --git a/src/cmd/compile/internal/ssa/gen/ARMOps.go b/src/cmd/compile/internal/ssa/gen/ARMOps.go
index 5bf3c00..e296d06 100644
--- a/src/cmd/compile/internal/ssa/gen/ARMOps.go
+++ b/src/cmd/compile/internal/ssa/gen/ARMOps.go
@@ -12,7 +12,7 @@ import "strings"
 //  - Integer types live in the low portion of registers. Upper portions are junk.
 //  - Boolean types use the low-order byte of a register. 0=false, 1=true.
 //    Upper bytes are junk.
-//  - *const instructions may use a constant larger than the instuction can encode.
+//  - *const instructions may use a constant larger than the instruction can encode.
 //    In this case the assembler expands to multiple instructions and uses tmp
 //    register (R11).
 
diff --git a/src/cmd/compile/internal/ssa/gen/MIPS64Ops.go b/src/cmd/compile/internal/ssa/gen/MIPS64Ops.go
index d7d7fec..020d693 100644
--- a/src/cmd/compile/internal/ssa/gen/MIPS64Ops.go
+++ b/src/cmd/compile/internal/ssa/gen/MIPS64Ops.go
@@ -12,7 +12,7 @@ import "strings"
 //  - Integer types live in the low portion of registers. Upper portions are junk.
 //  - Boolean types use the low-order byte of a register. 0=false, 1=true.
 //    Upper bytes are junk.
-//  - *const instructions may use a constant larger than the instuction can encode.
+//  - *const instructions may use a constant larger than the instruction can encode.
 //    In this case the assembler expands to multiple instructions and uses tmp
 //    register (R23).
 
diff --git a/src/cmd/compile/internal/ssa/gen/MIPSOps.go b/src/cmd/compile/internal/ssa/gen/MIPSOps.go
index c803c49..78b961f 100644
--- a/src/cmd/compile/internal/ssa/gen/MIPSOps.go
+++ b/src/cmd/compile/internal/ssa/gen/MIPSOps.go
@@ -13,7 +13,7 @@ import "strings"
 //  - Boolean types use the low-order byte of a register. 0=false, 1=true.
 //    Upper bytes are junk.
 //  - Unused portions of AuxInt are filled by sign-extending the used portion.
-//  - *const instructions may use a constant larger than the instuction can encode.
+//  - *const instructions may use a constant larger than the instruction can encode.
 //    In this case the assembler expands to multiple instructions and uses tmp
 //    register (R23).
 
diff --git a/src/cmd/compile/internal/ssa/gen/PPC64Ops.go b/src/cmd/compile/internal/ssa/gen/PPC64Ops.go
index d7a1363..0034797 100644
--- a/src/cmd/compile/internal/ssa/gen/PPC64Ops.go
+++ b/src/cmd/compile/internal/ssa/gen/PPC64Ops.go
@@ -12,7 +12,7 @@ import "strings"
 //  - Less-than-64-bit integer types live in the low portion of registers.
 //    For now, the upper portion is junk; sign/zero-extension might be optimized in the future, but not yet.
 //  - Boolean types are zero or 1; stored in a byte, but loaded with AMOVBZ so the upper bytes of a register are zero.
-//  - *const instructions may use a constant larger than the instuction can encode.
+//  - *const instructions may use a constant larger than the instruction can encode.
 //    In this case the assembler expands to multiple instructions and uses tmp
 //    register (R31).
 
diff --git a/src/cmd/compile/internal/ssa/loopreschedchecks.go b/src/cmd/compile/internal/ssa/loopreschedchecks.go
new file mode 100644
index 0000000..8f8055e
--- /dev/null
+++ b/src/cmd/compile/internal/ssa/loopreschedchecks.go
@@ -0,0 +1,517 @@
+// Copyright 2016 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package ssa
+
+import "fmt"
+
+// an edgeMemCtr records a backedge, together with the memory and
+// counter phi functions at the target of the backedge that must
+// be updated when a rescheduling check replaces the backedge.
+type edgeMemCtr struct {
+	e Edge
+	m *Value // phi for memory at dest of e
+	c *Value // phi for counter at dest of e
+}
+
+// a rewriteTarget is a a value-argindex pair indicating
+// where a rewrite is applied.  Note that this is for values,
+// not for block controls, because block controls are not targets
+// for the rewrites performed in inserting rescheduling checks.
+type rewriteTarget struct {
+	v *Value
+	i int
+}
+
+type rewrite struct {
+	before, after *Value          // before is the expected value before rewrite, after is the new value installed.
+	rewrites      []rewriteTarget // all the targets for this rewrite.
+}
+
+func (r *rewrite) String() string {
+	s := "\n\tbefore=" + r.before.String() + ", after=" + r.after.String()
+	for _, rw := range r.rewrites {
+		s += ", (i=" + fmt.Sprint(rw.i) + ", v=" + rw.v.LongString() + ")"
+	}
+	s += "\n"
+	return s
+}
+
+const initialRescheduleCounterValue = 1021 // Largest 10-bit prime. 97 nSec loop bodies will check every 100 uSec.
+
+// insertLoopReschedChecks inserts rescheduling checks on loop backedges.
+func insertLoopReschedChecks(f *Func) {
+	// TODO: when split information is recorded in export data, insert checks only on backedges that can be reached on a split-call-free path.
+
+	// Loop reschedule checks decrement a per-function counter
+	// shared by all loops, and when the counter becomes non-positive
+	// a call is made to a rescheduling check in the runtime.
+	//
+	// Steps:
+	// 1. locate backedges.
+	// 2. Record memory definitions at block end so that
+	//    the SSA graph for mem can be prperly modified.
+	// 3. Define a counter and record its future uses (at backedges)
+	//    (Same process as 2, applied to a single definition of the counter.
+	//     difference for mem is that there are zero-to-many existing mem
+	//     definitions, versus exactly one for the new counter.)
+	// 4. Ensure that phi functions that will-be-needed for mem and counter
+	//    are present in the graph, initially with trivial inputs.
+	// 5. Record all to-be-modified uses of mem and counter;
+	//    apply modifications (split into two steps to simplify and
+	//    avoided nagging order-dependences).
+	// 6. Rewrite backedges to include counter check, reschedule check,
+	//    and modify destination phi function appropriately with new
+	//    definitions for mem and counter.
+
+	if f.NoSplit { // nosplit functions don't reschedule.
+		return
+	}
+
+	backedges := backedges(f)
+	if len(backedges) == 0 { // no backedges means no rescheduling checks.
+		return
+	}
+
+	lastMems := findLastMems(f)
+
+	idom := f.Idom()
+	sdom := f.sdom()
+
+	if f.pass.debug > 2 {
+		fmt.Printf("before %s = %s\n", f.Name, sdom.treestructure(f.Entry))
+	}
+
+	tofixBackedges := []edgeMemCtr{}
+
+	for _, e := range backedges { // TODO: could filter here by calls in loops, if declared and inferred nosplit are recorded in export data.
+		tofixBackedges = append(tofixBackedges, edgeMemCtr{e, nil, nil})
+	}
+
+	// It's possible that there is no memory state (no global/pointer loads/stores or calls)
+	if lastMems[f.Entry.ID] == nil {
+		lastMems[f.Entry.ID] = f.Entry.NewValue0(f.Entry.Line, OpInitMem, TypeMem)
+	}
+
+	memDefsAtBlockEnds := make([]*Value, f.NumBlocks()) // For each block, the mem def seen at its bottom. Could be from earlier block.
+
+	// Propagate last mem definitions forward through successor blocks.
+	po := f.postorder()
+	for i := len(po) - 1; i >= 0; i-- {
+		b := po[i]
+		mem := lastMems[b.ID]
+		for j := 0; mem == nil; j++ { // if there's no def, then there's no phi, so the visible mem is identical in all predecessors.
+			// loop because there might be backedges that haven't been visited yet.
+			mem = memDefsAtBlockEnds[b.Preds[j].b.ID]
+		}
+		memDefsAtBlockEnds[b.ID] = mem
+	}
+
+	// Set up counter.  There are no phis etc pre-existing for it.
+	counter0 := f.Entry.NewValue0I(f.Entry.Line, OpConst32, f.Config.fe.TypeInt32(), initialRescheduleCounterValue)
+	ctrDefsAtBlockEnds := make([]*Value, f.NumBlocks()) // For each block, def visible at its end, if that def will be used.
+
+	// There's a minor difference between memDefsAtBlockEnds and ctrDefsAtBlockEnds;
+	// because the counter only matter for loops and code that reaches them, it is nil for blocks where the ctr is no
+	// longer live.  This will avoid creation of dead phi functions.  This optimization is ignored for the mem variable
+	// because it is harder and also less likely to be helpful, though dead code elimination ought to clean this out anyhow.
+
+	for _, emc := range tofixBackedges {
+		e := emc.e
+		// set initial uses of counter zero (note available-at-bottom and use are the same thing initially.)
+		// each back-edge will be rewritten to include a reschedule check, and that will use the counter.
+		src := e.b.Preds[e.i].b
+		ctrDefsAtBlockEnds[src.ID] = counter0
+	}
+
+	// Push uses towards root
+	for _, b := range f.postorder() {
+		bd := ctrDefsAtBlockEnds[b.ID]
+		if bd == nil {
+			continue
+		}
+		for _, e := range b.Preds {
+			p := e.b
+			if ctrDefsAtBlockEnds[p.ID] == nil {
+				ctrDefsAtBlockEnds[p.ID] = bd
+			}
+		}
+	}
+
+	// Maps from block to newly-inserted phi function in block.
+	newmemphis := make(map[*Block]rewrite)
+	newctrphis := make(map[*Block]rewrite)
+
+	// Insert phi functions as necessary for future changes to flow graph.
+	for i, emc := range tofixBackedges {
+		e := emc.e
+		h := e.b
+
+		// find the phi function for the memory input at "h", if there is one.
+		var headerMemPhi *Value // look for header mem phi
+
+		for _, v := range h.Values {
+			if v.Op == OpPhi && v.Type.IsMemory() {
+				headerMemPhi = v
+			}
+		}
+
+		if headerMemPhi == nil {
+			// if the header is nil, make a trivial phi from the dominator
+			mem0 := memDefsAtBlockEnds[idom[h.ID].ID]
+			headerMemPhi = newPhiFor(h, mem0)
+			newmemphis[h] = rewrite{before: mem0, after: headerMemPhi}
+			addDFphis(mem0, h, h, f, memDefsAtBlockEnds, newmemphis)
+
+		}
+		tofixBackedges[i].m = headerMemPhi
+
+		var headerCtrPhi *Value
+		rw, ok := newctrphis[h]
+		if !ok {
+			headerCtrPhi = newPhiFor(h, counter0)
+			newctrphis[h] = rewrite{before: counter0, after: headerCtrPhi}
+			addDFphis(counter0, h, h, f, ctrDefsAtBlockEnds, newctrphis)
+		} else {
+			headerCtrPhi = rw.after
+		}
+		tofixBackedges[i].c = headerCtrPhi
+	}
+
+	rewriteNewPhis(f.Entry, f.Entry, f, memDefsAtBlockEnds, newmemphis)
+	rewriteNewPhis(f.Entry, f.Entry, f, ctrDefsAtBlockEnds, newctrphis)
+
+	if f.pass.debug > 0 {
+		for b, r := range newmemphis {
+			fmt.Printf("b=%s, rewrite=%s\n", b, r.String())
+		}
+
+		for b, r := range newctrphis {
+			fmt.Printf("b=%s, rewrite=%s\n", b, r.String())
+		}
+	}
+
+	// Apply collected rewrites.
+	for _, r := range newmemphis {
+		for _, rw := range r.rewrites {
+			rw.v.SetArg(rw.i, r.after)
+		}
+	}
+
+	for _, r := range newctrphis {
+		for _, rw := range r.rewrites {
+			rw.v.SetArg(rw.i, r.after)
+		}
+	}
+
+	zero := f.Entry.NewValue0I(f.Entry.Line, OpConst32, f.Config.fe.TypeInt32(), 0)
+	one := f.Entry.NewValue0I(f.Entry.Line, OpConst32, f.Config.fe.TypeInt32(), 1)
+
+	// Rewrite backedges to include reschedule checks.
+	for _, emc := range tofixBackedges {
+		e := emc.e
+		headerMemPhi := emc.m
+		headerCtrPhi := emc.c
+		h := e.b
+		i := e.i
+		p := h.Preds[i]
+		bb := p.b
+		mem0 := headerMemPhi.Args[i]
+		ctr0 := headerCtrPhi.Args[i]
+		// bb e->p h,
+		// Because we're going to insert a rare-call, make sure the
+		// looping edge still looks likely.
+		likely := BranchLikely
+		if p.i != 0 {
+			likely = BranchUnlikely
+		}
+		bb.Likely = likely
+
+		// rewrite edge to include reschedule check
+		// existing edges:
+		//
+		// bb.Succs[p.i] == Edge{h, i}
+		// h.Preds[i] == p == Edge{bb,p.i}
+		//
+		// new block(s):
+		// test:
+		//    ctr1 := ctr0 - 1
+		//    if ctr1 <= 0 { goto sched }
+		//    goto join
+		// sched:
+		//    mem1 := call resched (mem0)
+		//    goto join
+		// join:
+		//    ctr2 := phi(ctr1, counter0) // counter0 is the constant
+		//    mem2 := phi(mem0, mem1)
+		//    goto h
+		//
+		// and correct arg i of headerMemPhi and headerCtrPhi
+		//
+		// EXCEPT: block containing only phi functions is bad
+		// for the register allocator.  Therefore, there is no
+		// join, and instead branches targeting join instead target
+		// the header, and the other phi functions within header are
+		// adjusted for the additional input.
+
+		test := f.NewBlock(BlockIf)
+		sched := f.NewBlock(BlockPlain)
+
+		test.Line = bb.Line
+		sched.Line = bb.Line
+
+		//    ctr1 := ctr0 - 1
+		//    if ctr1 <= 0 { goto sched }
+		//    goto header
+		ctr1 := test.NewValue2(bb.Line, OpSub32, f.Config.fe.TypeInt32(), ctr0, one)
+		cmp := test.NewValue2(bb.Line, OpLeq32, f.Config.fe.TypeBool(), ctr1, zero)
+		test.SetControl(cmp)
+		test.AddEdgeTo(sched) // if true
+		// if false -- rewrite edge to header.
+		// do NOT remove+add, because that will perturb all the other phi functions
+		// as well as messing up other edges to the header.
+		test.Succs = append(test.Succs, Edge{h, i})
+		h.Preds[i] = Edge{test, 1}
+		headerMemPhi.SetArg(i, mem0)
+		headerCtrPhi.SetArg(i, ctr1)
+
+		test.Likely = BranchUnlikely
+
+		// sched:
+		//    mem1 := call resched (mem0)
+		//    goto header
+		resched := f.Config.fe.Syslook("goschedguarded")
+		mem1 := sched.NewValue1A(bb.Line, OpStaticCall, TypeMem, resched, mem0)
+		sched.AddEdgeTo(h)
+		headerMemPhi.AddArg(mem1)
+		headerCtrPhi.AddArg(counter0)
+
+		bb.Succs[p.i] = Edge{test, 0}
+		test.Preds = append(test.Preds, Edge{bb, p.i})
+
+		// Must correct all the other phi functions in the header for new incoming edge.
+		// Except for mem and counter phis, it will be the same value seen on the original
+		// backedge at index i.
+		for _, v := range h.Values {
+			if v.Op == OpPhi && v != headerMemPhi && v != headerCtrPhi {
+				v.AddArg(v.Args[i])
+			}
+		}
+	}
+
+	f.invalidateCFG()
+
+	if f.pass.debug > 2 {
+		sdom = newSparseTree(f, f.Idom())
+		fmt.Printf("after %s = %s\n", f.Name, sdom.treestructure(f.Entry))
+	}
+
+	return
+}
+
+// newPhiFor inserts a new Phi function into b,
+// with all inputs set to v.
+func newPhiFor(b *Block, v *Value) *Value {
+	phiV := b.NewValue0(b.Line, OpPhi, v.Type)
+
+	for range b.Preds {
+		phiV.AddArg(v)
+	}
+	return phiV
+}
+
+// rewriteNewPhis updates newphis[h] to record all places where the new phi function inserted
+// in block h will replace a previous definition.  Block b is the block currently being processed;
+// if b has its own phi definition then it takes the place of h.
+// defsForUses provides information about other definitions of the variable that are present
+// (and if nil, indicates that the variable is no longer live)
+func rewriteNewPhis(h, b *Block, f *Func, defsForUses []*Value, newphis map[*Block]rewrite) {
+	// If b is a block with a new phi, then a new rewrite applies below it in the dominator tree.
+	if _, ok := newphis[b]; ok {
+		h = b
+	}
+	change := newphis[h]
+	x := change.before
+	y := change.after
+
+	// Apply rewrites to this block
+	if x != nil { // don't waste time on the common case of no definition.
+		p := &change.rewrites
+		for _, v := range b.Values {
+			if v == y { // don't rewrite self -- phi inputs are handled below.
+				continue
+			}
+			for i, w := range v.Args {
+				if w != x {
+					continue
+				}
+				*p = append(*p, rewriteTarget{v, i})
+			}
+		}
+
+		// Rewrite appropriate inputs of phis reached in successors
+		// in dominance frontier, self, and dominated.
+		// If the variable def reaching uses in b is itself defined in b, then the new phi function
+		// does not reach the successors of b.  (This assumes a bit about the structure of the
+		// phi use-def graph, but it's true for memory and the inserted counter.)
+		if dfu := defsForUses[b.ID]; dfu != nil && dfu.Block != b {
+			for _, e := range b.Succs {
+				s := e.b
+				if sphi, ok := newphis[s]; ok { // saves time to find the phi this way.
+					*p = append(*p, rewriteTarget{sphi.after, e.i})
+					continue
+				}
+				for _, v := range s.Values {
+					if v.Op == OpPhi && v.Args[e.i] == x {
+						*p = append(*p, rewriteTarget{v, e.i})
+						break
+					}
+				}
+			}
+		}
+		newphis[h] = change
+	}
+
+	sdom := f.sdom()
+
+	for c := sdom[b.ID].child; c != nil; c = sdom[c.ID].sibling {
+		rewriteNewPhis(h, c, f, defsForUses, newphis) // TODO: convert to explicit stack from recursion.
+	}
+}
+
+// addDFphis creates new trivial phis that are necessary to correctly reflect (within SSA)
+// a new definition for variable "x" inserted at h (usually but not necessarily a phi).
+// These new phis can only occur at the dominance frontier of h; block s is in the dominance
+// frontier of h if h does not strictly dominate s and if s is a successor of a block b where
+// either b = h or h strictly dominates b.
+// These newly created phis are themselves new definitions that may require addition of their
+// own trivial phi functions in their own dominance frontier, and this is handled recursively.
+func addDFphis(x *Value, h, b *Block, f *Func, defForUses []*Value, newphis map[*Block]rewrite) {
+	oldv := defForUses[b.ID]
+	if oldv != x { // either a new definition replacing x, or nil if it is proven that there are no uses reachable from b
+		return
+	}
+	sdom := f.sdom()
+	idom := f.Idom()
+outer:
+	for _, e := range b.Succs {
+		s := e.b
+		// check phi functions in the dominance frontier
+		if sdom.isAncestor(h, s) {
+			continue // h dominates s, successor of b, therefore s is not in the frontier.
+		}
+		if _, ok := newphis[s]; ok {
+			continue // successor s of b already has a new phi function, so there is no need to add another.
+		}
+		if x != nil {
+			for _, v := range s.Values {
+				if v.Op == OpPhi && v.Args[e.i] == x {
+					continue outer // successor s of b has an old phi function, so there is no need to add another.
+				}
+			}
+		}
+
+		old := defForUses[idom[s.ID].ID] // new phi function is correct-but-redundant, combining value "old" on all inputs.
+		headerPhi := newPhiFor(s, old)
+		// the new phi will replace "old" in block s and all blocks dominated by s.
+		newphis[s] = rewrite{before: old, after: headerPhi} // record new phi, to have inputs labeled "old" rewritten to "headerPhi"
+		addDFphis(old, s, s, f, defForUses, newphis)        // the new definition may also create new phi functions.
+	}
+	for c := sdom[b.ID].child; c != nil; c = sdom[c.ID].sibling {
+		addDFphis(x, h, c, f, defForUses, newphis) // TODO: convert to explicit stack from recursion.
+	}
+}
+
+// findLastMems maps block ids to last memory-output op in a block, if any
+func findLastMems(f *Func) []*Value {
+
+	var stores []*Value
+	lastMems := make([]*Value, f.NumBlocks())
+	storeUse := f.newSparseSet(f.NumValues())
+	defer f.retSparseSet(storeUse)
+	for _, b := range f.Blocks {
+		// Find all the stores in this block. Categorize their uses:
+		//  storeUse contains stores which are used by a subsequent store.
+		storeUse.clear()
+		stores = stores[:0]
+		var memPhi *Value
+		for _, v := range b.Values {
+			if v.Op == OpPhi {
+				if v.Type.IsMemory() {
+					memPhi = v
+				}
+				continue
+			}
+			if v.Type.IsMemory() {
+				stores = append(stores, v)
+				if v.Op == OpSelect1 {
+					// Use the arg of the tuple-generating op.
+					v = v.Args[0]
+				}
+				for _, a := range v.Args {
+					if a.Block == b && a.Type.IsMemory() {
+						storeUse.add(a.ID)
+					}
+				}
+			}
+		}
+		if len(stores) == 0 {
+			lastMems[b.ID] = memPhi
+			continue
+		}
+
+		// find last store in the block
+		var last *Value
+		for _, v := range stores {
+			if storeUse.contains(v.ID) {
+				continue
+			}
+			if last != nil {
+				b.Fatalf("two final stores - simultaneous live stores %s %s", last, v)
+			}
+			last = v
+		}
+		if last == nil {
+			b.Fatalf("no last store found - cycle?")
+		}
+		lastMems[b.ID] = last
+	}
+	return lastMems
+}
+
+type backedgesState struct {
+	b *Block
+	i int
+}
+
+// backedges returns a slice of successor edges that are back
+// edges.  For reducible loops, edge.b is the header.
+func backedges(f *Func) []Edge {
+	edges := []Edge{}
+	mark := make([]markKind, f.NumBlocks())
+	stack := []backedgesState{}
+
+	mark[f.Entry.ID] = notExplored
+	stack = append(stack, backedgesState{f.Entry, 0})
+
+	for len(stack) > 0 {
+		l := len(stack)
+		x := stack[l-1]
+		if x.i < len(x.b.Succs) {
+			e := x.b.Succs[x.i]
+			stack[l-1].i++
+			s := e.b
+			if mark[s.ID] == notFound {
+				mark[s.ID] = notExplored
+				stack = append(stack, backedgesState{s, 0})
+			} else if mark[s.ID] == notExplored {
+				edges = append(edges, e)
+			}
+		} else {
+			mark[x.b.ID] = done
+			stack = stack[0 : l-1]
+		}
+	}
+	return edges
+}
diff --git a/src/cmd/compile/internal/ssa/nilcheck.go b/src/cmd/compile/internal/ssa/nilcheck.go
index eb2d297..9f58db6 100644
--- a/src/cmd/compile/internal/ssa/nilcheck.go
+++ b/src/cmd/compile/internal/ssa/nilcheck.go
@@ -132,6 +132,8 @@ func nilcheckelim(f *Func) {
 }
 
 // All platforms are guaranteed to fault if we load/store to anything smaller than this address.
+//
+// This should agree with minLegalPointer in the runtime.
 const minZeroPage = 4096
 
 // nilcheckelim2 eliminates unnecessary nil checks.
diff --git a/src/cmd/compile/internal/ssa/op.go b/src/cmd/compile/internal/ssa/op.go
index 315d720..4c3164f 100644
--- a/src/cmd/compile/internal/ssa/op.go
+++ b/src/cmd/compile/internal/ssa/op.go
@@ -21,7 +21,7 @@ type opInfo struct {
 	name              string
 	reg               regInfo
 	auxType           auxType
-	argLen            int32 // the number of arugments, -1 if variable length
+	argLen            int32 // the number of arguments, -1 if variable length
 	asm               obj.As
 	generic           bool // this is a generic (arch-independent) opcode
 	rematerializeable bool // this op is rematerializeable
diff --git a/src/cmd/compile/internal/ssa/regalloc.go b/src/cmd/compile/internal/ssa/regalloc.go
index 2b66982..7bf7786 100644
--- a/src/cmd/compile/internal/ssa/regalloc.go
+++ b/src/cmd/compile/internal/ssa/regalloc.go
@@ -759,7 +759,7 @@ func (s *regAllocState) regalloc(f *Func) {
 			liveSet.add(e.ID)
 		}
 		if v := b.Control; v != nil && s.values[v.ID].needReg {
-			s.addUse(v.ID, int32(len(b.Values)), b.Line) // psuedo-use by control value
+			s.addUse(v.ID, int32(len(b.Values)), b.Line) // pseudo-use by control value
 			liveSet.add(v.ID)
 		}
 		for i := len(b.Values) - 1; i >= 0; i-- {
diff --git a/src/cmd/compile/internal/ssa/sparsetree.go b/src/cmd/compile/internal/ssa/sparsetree.go
index 7c82a60..8e5b9f3 100644
--- a/src/cmd/compile/internal/ssa/sparsetree.go
+++ b/src/cmd/compile/internal/ssa/sparsetree.go
@@ -4,7 +4,10 @@
 
 package ssa
 
-import "fmt"
+import (
+	"fmt"
+	"strings"
+)
 
 type SparseTreeNode struct {
 	child   *Block
@@ -67,6 +70,34 @@ func newSparseTree(f *Func, parentOf []*Block) SparseTree {
 	return t
 }
 
+// treestructure provides a string description of the dominator
+// tree and flow structure of block b and all blocks that it
+// dominates.
+func (t SparseTree) treestructure(b *Block) string {
+	return t.treestructure1(b, 0)
+}
+func (t SparseTree) treestructure1(b *Block, i int) string {
+	s := "\n" + strings.Repeat("\t", i) + b.String() + "->["
+	for i, e := range b.Succs {
+		if i > 0 {
+			s = s + ","
+		}
+		s = s + e.b.String()
+	}
+	s += "]"
+	if c0 := t[b.ID].child; c0 != nil {
+		s += "("
+		for c := c0; c != nil; c = t[c.ID].sibling {
+			if c != c0 {
+				s += " "
+			}
+			s += t.treestructure1(c, i+1)
+		}
+		s += ")"
+	}
+	return s
+}
+
 // numberBlock assigns entry and exit numbers for b and b's
 // children in an in-order walk from a gappy sequence, where n
 // is the first number not yet assigned or reserved. N should
diff --git a/src/cmd/cover/cover.go b/src/cmd/cover/cover.go
index b7d9125..ee14070 100644
--- a/src/cmd/cover/cover.go
+++ b/src/cmd/cover/cover.go
@@ -151,11 +151,12 @@ type Block struct {
 // File is a wrapper for the state of a file used in the parser.
 // The basic parse tree walker is a method of this type.
 type File struct {
-	fset      *token.FileSet
-	name      string // Name of file.
-	astFile   *ast.File
-	blocks    []Block
-	atomicPkg string // Package name for "sync/atomic" in this file.
+	fset       *token.FileSet
+	name       string // Name of file.
+	astFile    *ast.File
+	blocks     []Block
+	atomicPkg  string                // Package name for "sync/atomic" in this file.
+	directives map[*ast.Comment]bool // Map of compiler directives to whether it's processed in ast.Visitor or not.
 }
 
 // Visit implements the ast.Visitor interface.
@@ -247,8 +248,11 @@ func (f *File) Visit(node ast.Node) ast.Visitor {
 		// to appear in syntactically incorrect places. //go: appears at the beginning of
 		// the line and is syntactically safe.
 		for _, c := range n.List {
-			if strings.HasPrefix(c.Text, "//go:") && f.fset.Position(c.Slash).Column == 1 {
+			if f.isDirective(c) {
 				list = append(list, c)
+
+				// Mark compiler directive as handled.
+				f.directives[c] = true
 			}
 		}
 		n.List = list
@@ -360,17 +364,27 @@ func annotate(name string) {
 	if err != nil {
 		log.Fatalf("cover: %s: %s", name, err)
 	}
-	// Remove comments. Or else they interfere with new AST.
-	parsedFile.Comments = nil
 
 	file := &File{
-		fset:    fset,
-		name:    name,
-		astFile: parsedFile,
+		fset:       fset,
+		name:       name,
+		astFile:    parsedFile,
+		directives: map[*ast.Comment]bool{},
 	}
 	if *mode == "atomic" {
 		file.atomicPkg = file.addImport(atomicPackagePath)
 	}
+
+	for _, cg := range parsedFile.Comments {
+		for _, c := range cg.List {
+			if file.isDirective(c) {
+				file.directives[c] = false
+			}
+		}
+	}
+	// Remove comments. Or else they interfere with new AST.
+	parsedFile.Comments = nil
+
 	ast.Walk(file, file.astFile)
 	fd := os.Stdout
 	if *output != "" {
@@ -381,6 +395,17 @@ func annotate(name string) {
 		}
 	}
 	fd.Write(initialComments(content)) // Retain '// +build' directives.
+
+	// Retain compiler directives that are not processed in ast.Visitor.
+	// Some compiler directives like "go:linkname" and "go:cgo_"
+	// can be not attached to anything in the tree and hence will not be printed by printer.
+	// So, we have to explicitly print them here.
+	for cd, handled := range file.directives {
+		if !handled {
+			fmt.Fprintln(fd, cd.Text)
+		}
+	}
+
 	file.print(fd)
 	// After printing the source tree, add some declarations for the counters etc.
 	// We could do this by adding to the tree, but it's easier just to print the text.
@@ -391,6 +416,11 @@ func (f *File) print(w io.Writer) {
 	printer.Fprint(w, f.fset, f.astFile)
 }
 
+// isDirective reports whether a comment is a compiler directive.
+func (f *File) isDirective(c *ast.Comment) bool {
+	return strings.HasPrefix(c.Text, "//go:") && f.fset.Position(c.Slash).Column == 1
+}
+
 // intLiteral returns an ast.BasicLit representing the integer value.
 func (f *File) intLiteral(i int) *ast.BasicLit {
 	node := &ast.BasicLit{
diff --git a/src/cmd/cover/cover_test.go b/src/cmd/cover/cover_test.go
index 50a7ce8..81ac8ae 100644
--- a/src/cmd/cover/cover_test.go
+++ b/src/cmd/cover/cover_test.go
@@ -90,6 +90,11 @@ func TestCover(t *testing.T) {
 	if got, err := regexp.MatchString(".*\n//go:nosplit\nfunc someFunction().*", string(file)); err != nil || !got {
 		t.Errorf("misplaced compiler directive: got=(%v, %v); want=(true; nil)", got, err)
 	}
+	// "go:linkname" compiler directive should be present.
+	if got, err := regexp.MatchString(`.*go\:linkname some\_name some\_name.*`, string(file)); err != nil || !got {
+		t.Errorf("'go:linkname' compiler directive not found: got=(%v, %v); want=(true; nil)", got, err)
+	}
+
 	// No other comments should be present in generated code.
 	c := ".*// This comment shouldn't appear in generated go code.*"
 	if got, err := regexp.MatchString(c, string(file)); err != nil || got {
diff --git a/src/cmd/cover/testdata/test.go b/src/cmd/cover/testdata/test.go
index 61b40ea..5effa2d 100644
--- a/src/cmd/cover/testdata/test.go
+++ b/src/cmd/cover/testdata/test.go
@@ -10,6 +10,10 @@
 
 package main
 
+import _ "unsafe" // for go:linkname
+
+//go:linkname some_name some_name
+
 const anything = 1e9 // Just some unlikely value that means "we got here, don't care how often"
 
 func testAll() {
diff --git a/src/cmd/dist/test.go b/src/cmd/dist/test.go
index a552966..7d5f79f 100644
--- a/src/cmd/dist/test.go
+++ b/src/cmd/dist/test.go
@@ -704,7 +704,7 @@ func (t *tester) extLink() bool {
 		"darwin-arm", "darwin-arm64",
 		"dragonfly-386", "dragonfly-amd64",
 		"freebsd-386", "freebsd-amd64", "freebsd-arm",
-		"linux-386", "linux-amd64", "linux-arm", "linux-arm64", "linux-ppc64le", "linux-mips64", "linux-mips64le",
+		"linux-386", "linux-amd64", "linux-arm", "linux-arm64", "linux-ppc64le", "linux-mips64", "linux-mips64le", "linux-mips", "linux-mipsle", "linux-s390x",
 		"netbsd-386", "netbsd-amd64",
 		"openbsd-386", "openbsd-amd64",
 		"windows-386", "windows-amd64":
diff --git a/src/cmd/go/alldocs.go b/src/cmd/go/alldocs.go
index b480742..e93fd6e 100644
--- a/src/cmd/go/alldocs.go
+++ b/src/cmd/go/alldocs.go
@@ -935,6 +935,8 @@
 // unless that directory holds a Go distribution.
 // Run "go env GOPATH" to see the current GOPATH.
 //
+// See https://golang.org/wiki/SettingGOPATH to set a custom GOPATH.
+//
 // Each directory listed in GOPATH must have a prescribed structure:
 //
 // The src directory holds source code.  The path below src
@@ -1474,7 +1476,7 @@
 // 	    text from Log and Logf calls even if the test succeeds.
 //
 // The following flags are also recognized by 'go test' and can be used to
-// profile the tests during execution::
+// profile the tests during execution:
 //
 // 	-benchmem
 // 	    Print memory allocation statistics for benchmarks.
@@ -1517,7 +1519,7 @@
 // 	    Writes test binary as -c would.
 //
 // 	-mutexprofilefraction n
-//  	    Sample 1 in n stack traces of goroutines holding a
+// 	    Sample 1 in n stack traces of goroutines holding a
 // 	    contended mutex.
 //
 // 	-outputdir directory
@@ -1606,7 +1608,8 @@
 // is compared exactly against the comment (see examples below). If the last
 // comment begins with "Unordered output:" then the output is compared to the
 // comment, however the order of the lines is ignored. An example with no such
-// comment, or with no text after "Output:" is compiled but not executed.
+// comment is compiled but not executed. An example with no text after
+// "Output:" is compiled, executed, and expected to produce no output.
 //
 // Godoc displays the body of ExampleXXX to demonstrate the use
 // of the function, constant, or variable XXX.  An example of a method M with
diff --git a/src/cmd/go/go_test.go b/src/cmd/go/go_test.go
index 88c5443..5727eb0 100644
--- a/src/cmd/go/go_test.go
+++ b/src/cmd/go/go_test.go
@@ -1885,6 +1885,26 @@ func TestGoTestCpuprofileDashOControlsBinaryLocation(t *testing.T) {
 	tg.wantExecutable("myerrors.test"+exeSuffix, "go test -cpuprofile -o myerrors.test did not create myerrors.test")
 }
 
+func TestGoTestMutexprofileLeavesBinaryBehind(t *testing.T) {
+	tg := testgo(t)
+	defer tg.cleanup()
+	// TODO: tg.parallel()
+	tg.makeTempdir()
+	tg.cd(tg.path("."))
+	tg.run("test", "-mutexprofile", "errors.prof", "errors")
+	tg.wantExecutable("errors.test"+exeSuffix, "go test -mutexprofile did not create errors.test")
+}
+
+func TestGoTestMutexprofileDashOControlsBinaryLocation(t *testing.T) {
+	tg := testgo(t)
+	defer tg.cleanup()
+	// TODO: tg.parallel()
+	tg.makeTempdir()
+	tg.cd(tg.path("."))
+	tg.run("test", "-mutexprofile", "errors.prof", "-o", "myerrors.test"+exeSuffix, "errors")
+	tg.wantExecutable("myerrors.test"+exeSuffix, "go test -mutexprofile -o myerrors.test did not create myerrors.test")
+}
+
 func TestGoTestDashCDashOControlsBinaryLocation(t *testing.T) {
 	tg := testgo(t)
 	defer tg.cleanup()
@@ -2247,6 +2267,28 @@ func TestCoverageImportMainLoop(t *testing.T) {
 	tg.grepStderr("not an importable package", "did not detect import main")
 }
 
+func TestTestEmpty(t *testing.T) {
+	if !canRace {
+		t.Skip("no race detector")
+	}
+
+	wd, _ := os.Getwd()
+	testdata := filepath.Join(wd, "testdata")
+
+	for _, dir := range []string{"pkg", "test", "xtest", "pkgtest", "pkgxtest", "pkgtestxtest", "testxtest"} {
+		t.Run(dir, func(t *testing.T) {
+			tg := testgo(t)
+			defer tg.cleanup()
+			tg.setenv("GOPATH", testdata)
+			tg.cd(filepath.Join(testdata, "src/empty/"+dir))
+			tg.run("test", "-cover", "-coverpkg=.", "-race")
+		})
+		if testing.Short() {
+			break
+		}
+	}
+}
+
 func TestBuildDryRunWithCgo(t *testing.T) {
 	if !canCgo {
 		t.Skip("skipping because cgo not enabled")
@@ -3357,9 +3399,11 @@ func TestCgoConsistentResults(t *testing.T) {
 	if !canCgo {
 		t.Skip("skipping because cgo not enabled")
 	}
-	if runtime.GOOS == "solaris" {
-		// See https://golang.org/issue/13247
-		t.Skip("skipping because Solaris builds are known to be inconsistent; see #13247")
+	switch runtime.GOOS {
+	case "freebsd":
+		testenv.SkipFlaky(t, 15405)
+	case "solaris":
+		testenv.SkipFlaky(t, 13247)
 	}
 
 	tg := testgo(t)
diff --git a/src/cmd/go/help.go b/src/cmd/go/help.go
index fb69d8e..0c663ad 100644
--- a/src/cmd/go/help.go
+++ b/src/cmd/go/help.go
@@ -295,6 +295,8 @@ to a subdirectory named "go" in the user's home directory
 unless that directory holds a Go distribution.
 Run "go env GOPATH" to see the current GOPATH.
 
+See https://golang.org/wiki/SettingGOPATH to set a custom GOPATH.
+
 Each directory listed in GOPATH must have a prescribed structure:
 
 The src directory holds source code.  The path below src
diff --git a/src/cmd/go/http.go b/src/cmd/go/http.go
index 1dc2c12..dcb4e9f 100644
--- a/src/cmd/go/http.go
+++ b/src/cmd/go/http.go
@@ -33,6 +33,7 @@ var httpClient = http.DefaultClient
 var impatientInsecureHTTPClient = &http.Client{
 	Timeout: 5 * time.Second,
 	Transport: &http.Transport{
+		Proxy: http.ProxyFromEnvironment,
 		TLSClientConfig: &tls.Config{
 			InsecureSkipVerify: true,
 		},
diff --git a/src/cmd/go/pkg.go b/src/cmd/go/pkg.go
index 98e722b..d69fa51 100644
--- a/src/cmd/go/pkg.go
+++ b/src/cmd/go/pkg.go
@@ -955,6 +955,10 @@ func (p *Package) load(stk *importStack, bp *build.Package, err error) *Package
 		if p.Name == "main" && goarch == "arm" {
 			importPaths = append(importPaths, "math")
 		}
+		// In coverage atomic mode everything depends on sync/atomic.
+		if testCoverMode == "atomic" && (!p.Standard || (p.ImportPath != "runtime/cgo" && p.ImportPath != "runtime/race" && p.ImportPath != "sync/atomic")) {
+			importPaths = append(importPaths, "sync/atomic")
+		}
 	}
 
 	// Runtime and its internal packages depend on runtime/internal/sys,
diff --git a/src/cmd/go/test.go b/src/cmd/go/test.go
index f27144c..cdb167d 100644
--- a/src/cmd/go/test.go
+++ b/src/cmd/go/test.go
@@ -200,7 +200,7 @@ const testFlag2 = `
 	    text from Log and Logf calls even if the test succeeds.
 
 The following flags are also recognized by 'go test' and can be used to
-profile the tests during execution::
+profile the tests during execution:
 
 	-benchmem
 	    Print memory allocation statistics for benchmarks.
@@ -243,7 +243,7 @@ profile the tests during execution::
 	    Writes test binary as -c would.
 
 	-mutexprofilefraction n
- 	    Sample 1 in n stack traces of goroutines holding a
+	    Sample 1 in n stack traces of goroutines holding a
 	    contended mutex.
 
 	-outputdir directory
@@ -334,7 +334,8 @@ If the last comment in the function starts with "Output:" then the output
 is compared exactly against the comment (see examples below). If the last
 comment begins with "Unordered output:" then the output is compared to the
 comment, however the order of the lines is ignored. An example with no such
-comment, or with no text after "Output:" is compiled but not executed.
+comment is compiled but not executed. An example with no text after
+"Output:" is compiled, executed, and expected to produce no output.
 
 Godoc displays the body of ExampleXXX to demonstrate the use
 of the function, constant, or variable XXX.  An example of a method M with
diff --git a/src/cmd/go/testdata/src/empty/pkg/pkg.go b/src/cmd/go/testdata/src/empty/pkg/pkg.go
new file mode 100644
index 0000000..c89cd18
--- /dev/null
+++ b/src/cmd/go/testdata/src/empty/pkg/pkg.go
@@ -0,0 +1 @@
+package p
diff --git a/src/cmd/go/testdata/src/empty/pkgtest/pkg.go b/src/cmd/go/testdata/src/empty/pkgtest/pkg.go
new file mode 100644
index 0000000..c89cd18
--- /dev/null
+++ b/src/cmd/go/testdata/src/empty/pkgtest/pkg.go
@@ -0,0 +1 @@
+package p
diff --git a/src/cmd/go/testdata/src/empty/pkgtest/test_test.go b/src/cmd/go/testdata/src/empty/pkgtest/test_test.go
new file mode 100644
index 0000000..c89cd18
--- /dev/null
+++ b/src/cmd/go/testdata/src/empty/pkgtest/test_test.go
@@ -0,0 +1 @@
+package p
diff --git a/src/cmd/go/testdata/src/empty/pkgtestxtest/pkg.go b/src/cmd/go/testdata/src/empty/pkgtestxtest/pkg.go
new file mode 100644
index 0000000..c89cd18
--- /dev/null
+++ b/src/cmd/go/testdata/src/empty/pkgtestxtest/pkg.go
@@ -0,0 +1 @@
+package p
diff --git a/src/cmd/go/testdata/src/empty/pkgtestxtest/test_test.go b/src/cmd/go/testdata/src/empty/pkgtestxtest/test_test.go
new file mode 100644
index 0000000..c89cd18
--- /dev/null
+++ b/src/cmd/go/testdata/src/empty/pkgtestxtest/test_test.go
@@ -0,0 +1 @@
+package p
diff --git a/src/cmd/go/testdata/src/empty/pkgtestxtest/xtest_test.go b/src/cmd/go/testdata/src/empty/pkgtestxtest/xtest_test.go
new file mode 100644
index 0000000..9b64e8e
--- /dev/null
+++ b/src/cmd/go/testdata/src/empty/pkgtestxtest/xtest_test.go
@@ -0,0 +1 @@
+package p_test
diff --git a/src/cmd/go/testdata/src/empty/pkgxtest/pkg.go b/src/cmd/go/testdata/src/empty/pkgxtest/pkg.go
new file mode 100644
index 0000000..c89cd18
--- /dev/null
+++ b/src/cmd/go/testdata/src/empty/pkgxtest/pkg.go
@@ -0,0 +1 @@
+package p
diff --git a/src/cmd/go/testdata/src/empty/pkgxtest/xtest_test.go b/src/cmd/go/testdata/src/empty/pkgxtest/xtest_test.go
new file mode 100644
index 0000000..9b64e8e
--- /dev/null
+++ b/src/cmd/go/testdata/src/empty/pkgxtest/xtest_test.go
@@ -0,0 +1 @@
+package p_test
diff --git a/src/cmd/go/testdata/src/empty/test/test_test.go b/src/cmd/go/testdata/src/empty/test/test_test.go
new file mode 100644
index 0000000..c89cd18
--- /dev/null
+++ b/src/cmd/go/testdata/src/empty/test/test_test.go
@@ -0,0 +1 @@
+package p
diff --git a/src/cmd/go/testdata/src/empty/testxtest/test_test.go b/src/cmd/go/testdata/src/empty/testxtest/test_test.go
new file mode 100644
index 0000000..c89cd18
--- /dev/null
+++ b/src/cmd/go/testdata/src/empty/testxtest/test_test.go
@@ -0,0 +1 @@
+package p
diff --git a/src/cmd/go/testdata/src/empty/testxtest/xtest_test.go b/src/cmd/go/testdata/src/empty/testxtest/xtest_test.go
new file mode 100644
index 0000000..9b64e8e
--- /dev/null
+++ b/src/cmd/go/testdata/src/empty/testxtest/xtest_test.go
@@ -0,0 +1 @@
+package p_test
diff --git a/src/cmd/go/testdata/src/empty/xtest/xtest_test.go b/src/cmd/go/testdata/src/empty/xtest/xtest_test.go
new file mode 100644
index 0000000..9b64e8e
--- /dev/null
+++ b/src/cmd/go/testdata/src/empty/xtest/xtest_test.go
@@ -0,0 +1 @@
+package p_test
diff --git a/src/cmd/go/testflag.go b/src/cmd/go/testflag.go
index cf4d2b4..fa53bfc 100644
--- a/src/cmd/go/testflag.go
+++ b/src/cmd/go/testflag.go
@@ -151,10 +151,10 @@ func testFlags(args []string) (packageNames, passToTest []string) {
 				testBench = true
 			case "timeout":
 				testTimeout = value
-			case "blockprofile", "cpuprofile", "memprofile":
+			case "blockprofile", "cpuprofile", "memprofile", "mutexprofile":
 				testProfile = true
 				testNeedBinary = true
-			case "mutexprofile", "trace":
+			case "trace":
 				testProfile = true
 			case "coverpkg":
 				testCover = true
diff --git a/src/cmd/internal/obj/go.go b/src/cmd/internal/obj/go.go
index 1852dc7..732ce19 100644
--- a/src/cmd/internal/obj/go.go
+++ b/src/cmd/internal/obj/go.go
@@ -13,8 +13,9 @@ import (
 // go-specific code shared across loaders (5l, 6l, 8l).
 
 var (
-	framepointer_enabled int
-	Fieldtrack_enabled   int
+	framepointer_enabled     int
+	Fieldtrack_enabled       int
+	Preemptibleloops_enabled int
 )
 
 // Toolchain experiments.
@@ -27,6 +28,7 @@ var exper = []struct {
 }{
 	{"fieldtrack", &Fieldtrack_enabled},
 	{"framepointer", &framepointer_enabled},
+	{"preemptibleloops", &Preemptibleloops_enabled},
 }
 
 func addexp(s string) {
diff --git a/src/cmd/link/doc.go b/src/cmd/link/doc.go
index ba07da9..16fddf2 100644
--- a/src/cmd/link/doc.go
+++ b/src/cmd/link/doc.go
@@ -41,8 +41,6 @@ Flags:
 		Set the value of the string variable in importpath named name to value.
 		Note that before Go 1.5 this option took two separate arguments.
 		Now it takes one argument split on the first = sign.
-		To discover which name to use, run `go tool nm PROGRAM`;
-		usable variables will be tagged "D" or "d".
 	-buildmode mode
 		Set build mode (default exe).
 	-cpuprofile file
diff --git a/src/cmd/link/internal/arm/obj.go b/src/cmd/link/internal/arm/obj.go
index 4feaa09..05b90d2 100644
--- a/src/cmd/link/internal/arm/obj.go
+++ b/src/cmd/link/internal/arm/obj.go
@@ -104,7 +104,7 @@ func archinit(ctxt *ld.Link) {
 			*ld.FlagDataAddr = 0
 		}
 		if *ld.FlagRound == -1 {
-			*ld.FlagRound = 4096
+			*ld.FlagRound = 0x10000
 		}
 
 	case obj.Hnacl:
diff --git a/src/cmd/link/internal/ld/pcln.go b/src/cmd/link/internal/ld/pcln.go
index d317501..1ebd7de 100644
--- a/src/cmd/link/internal/ld/pcln.go
+++ b/src/cmd/link/internal/ld/pcln.go
@@ -248,6 +248,9 @@ func (ctxt *Link) pclntab() {
 		setaddr(ctxt, ftab, 8+int64(SysArch.PtrSize)+int64(nfunc)*2*int64(SysArch.PtrSize), s)
 		setuintxx(ctxt, ftab, 8+int64(SysArch.PtrSize)+int64(nfunc)*2*int64(SysArch.PtrSize)+int64(SysArch.PtrSize), uint64(funcstart), int64(SysArch.PtrSize))
 
+		// Write runtime._func. Keep in sync with ../../../../runtime/runtime2.go:/_func
+		// and package debug/gosym.
+
 		// fixed size of struct, checked below
 		off := funcstart
 
diff --git a/src/cmd/pprof/internal/report/report.go b/src/cmd/pprof/internal/report/report.go
index 14875c1..f897c90 100644
--- a/src/cmd/pprof/internal/report/report.go
+++ b/src/cmd/pprof/internal/report/report.go
@@ -123,7 +123,7 @@ func symbolsFromBinaries(prof *profile.Profile, g graph, rx *regexp.Regexp, addr
 	// Walk all mappings looking for matching functions with samples.
 	var objSyms []*objSymbol
 	for _, m := range prof.Mapping {
-		if !hasSamples[filepath.Base(m.File)] {
+		if !hasSamples[m.File] {
 			if address == nil || !(m.Start <= *address && *address <= m.Limit) {
 				continue
 			}
diff --git a/src/cmd/pprof/internal/report/source.go b/src/cmd/pprof/internal/report/source.go
index 7ab7e38..458985d 100644
--- a/src/cmd/pprof/internal/report/source.go
+++ b/src/cmd/pprof/internal/report/source.go
@@ -229,7 +229,7 @@ func assemblyPerSourceLine(objSyms []*objSymbol, rs nodes, src string, obj plugi
 func findMatchingSymbol(objSyms []*objSymbol, ns nodes) *objSymbol {
 	for _, n := range ns {
 		for _, o := range objSyms {
-			if filepath.Base(o.sym.File) == n.info.objfile &&
+			if o.sym.File == n.info.objfile &&
 				o.sym.Start <= n.info.address-o.base &&
 				n.info.address-o.base <= o.sym.End {
 				return o
diff --git a/src/cmd/vet/cgo.go b/src/cmd/vet/cgo.go
index d233e9a..984911c 100644
--- a/src/cmd/vet/cgo.go
+++ b/src/cmd/vet/cgo.go
@@ -44,7 +44,7 @@ func checkCgoCall(f *File, node ast.Node) {
 	}
 
 	for _, arg := range x.Args {
-		if !typeOKForCgoCall(cgoBaseType(f, arg)) {
+		if !typeOKForCgoCall(cgoBaseType(f, arg), make(map[types.Type]bool)) {
 			f.Badf(arg.Pos(), "possibly passing Go type with embedded pointer to C")
 		}
 
@@ -53,7 +53,7 @@ func checkCgoCall(f *File, node ast.Node) {
 			arg = conv.Args[0]
 		}
 		if u, ok := arg.(*ast.UnaryExpr); ok && u.Op == token.AND {
-			if !typeOKForCgoCall(cgoBaseType(f, u.X)) {
+			if !typeOKForCgoCall(cgoBaseType(f, u.X), make(map[types.Type]bool)) {
 				f.Badf(arg.Pos(), "possibly passing Go type with embedded pointer to C")
 			}
 		}
@@ -110,23 +110,24 @@ func cgoBaseType(f *File, arg ast.Expr) types.Type {
 	return f.pkg.types[arg].Type
 }
 
-// typeOKForCgoCall returns true if the type of arg is OK to pass to a
+// typeOKForCgoCall reports whether the type of arg is OK to pass to a
 // C function using cgo. This is not true for Go types with embedded
-// pointers.
-func typeOKForCgoCall(t types.Type) bool {
-	if t == nil {
+// pointers. m is used to avoid infinite recursion on recursive types.
+func typeOKForCgoCall(t types.Type, m map[types.Type]bool) bool {
+	if t == nil || m[t] {
 		return true
 	}
+	m[t] = true
 	switch t := t.Underlying().(type) {
 	case *types.Chan, *types.Map, *types.Signature, *types.Slice:
 		return false
 	case *types.Pointer:
-		return typeOKForCgoCall(t.Elem())
+		return typeOKForCgoCall(t.Elem(), m)
 	case *types.Array:
-		return typeOKForCgoCall(t.Elem())
+		return typeOKForCgoCall(t.Elem(), m)
 	case *types.Struct:
 		for i := 0; i < t.NumFields(); i++ {
-			if !typeOKForCgoCall(t.Field(i).Type()) {
+			if !typeOKForCgoCall(t.Field(i).Type(), m) {
 				return false
 			}
 		}
diff --git a/src/cmd/vet/copylock.go b/src/cmd/vet/copylock.go
index 31c1257..27eb5d4 100644
--- a/src/cmd/vet/copylock.go
+++ b/src/cmd/vet/copylock.go
@@ -93,13 +93,15 @@ func checkCopyLocksReturnStmt(f *File, rs *ast.ReturnStmt) {
 
 // checkCopyLocksCallExpr detects lock copy in the arguments to a function call
 func checkCopyLocksCallExpr(f *File, ce *ast.CallExpr) {
-	if id, ok := ce.Fun.(*ast.Ident); ok && id.Name == "new" && f.pkg.types[id].IsBuiltin() {
-		// Skip 'new(Type)' for built-in 'new'
-		return
+	if id, ok := ce.Fun.(*ast.Ident); ok && f.pkg.types[id].IsBuiltin() {
+		switch id.Name {
+		case "new", "len", "cap":
+			return
+		}
 	}
 	for _, x := range ce.Args {
 		if path := lockPathRhs(f, x); path != nil {
-			f.Badf(x.Pos(), "function call copies lock value: %v", path)
+			f.Badf(x.Pos(), "call of %s copies lock value: %v", f.gofmt(ce.Fun), path)
 		}
 	}
 }
diff --git a/src/cmd/vet/testdata/cgo/cgo.go b/src/cmd/vet/testdata/cgo/cgo.go
index 25d395b..d0df7cf 100644
--- a/src/cmd/vet/testdata/cgo/cgo.go
+++ b/src/cmd/vet/testdata/cgo/cgo.go
@@ -52,5 +52,8 @@ func CgoTests() {
 	C.f(*(*unsafe.Pointer)(unsafe.Pointer(&st2)))
 	C.f(unsafe.Pointer(&st2))
 
+	type cgoStruct struct{ p *cgoStruct }
+	C.f(unsafe.Pointer(&cgoStruct{}))
+
 	C.CBytes([]byte("hello"))
 }
diff --git a/src/cmd/vet/testdata/copylock.go b/src/cmd/vet/testdata/copylock.go
index 35ed766..6fabbc3 100644
--- a/src/cmd/vet/testdata/copylock.go
+++ b/src/cmd/vet/testdata/copylock.go
@@ -67,7 +67,7 @@ func BadFunc() {
 
 	// override 'new' keyword
 	new := func(interface{}) {}
-	new(t) // ERROR "function call copies lock value: testdata.Tlock contains sync.Once contains sync.Mutex"
+	new(t) // ERROR "call of new copies lock value: testdata.Tlock contains sync.Once contains sync.Mutex"
 
 	// copy of array of locks
 	var muA [5]sync.Mutex
@@ -88,6 +88,20 @@ func BadFunc() {
 	fmuSlice := fmuA[:] // OK
 }
 
+func LenAndCapOnLockArrays() {
+	var a [5]sync.Mutex
+	aLen := len(a) // OK
+	aCap := cap(a) // OK
+
+	// override 'len' and 'cap' keywords
+
+	len := func(interface{}) {}
+	len(a) // ERROR "call of len copies lock value: sync.Mutex"
+
+	cap := func(interface{}) {}
+	cap(a) // ERROR "call of cap copies lock value: sync.Mutex"
+}
+
 // SyncTypesCheck checks copying of sync.* types except sync.Mutex
 func SyncTypesCheck() {
 	// sync.RWMutex copying
diff --git a/src/cmd/vet/testdata/copylock_func.go b/src/cmd/vet/testdata/copylock_func.go
index bfafa12..d51ff27 100644
--- a/src/cmd/vet/testdata/copylock_func.go
+++ b/src/cmd/vet/testdata/copylock_func.go
@@ -86,8 +86,10 @@ func FuncCallInterfaceArg(f func(a int, b interface{})) {
 	f(1, "foo")
 	f(2, &t)
 	f(3, &sync.Mutex{})
-	f(4, m) // ERROR "function call copies lock value: sync.Mutex"
-	f(5, t) // ERROR "function call copies lock value: struct{lock sync.Mutex} contains sync.Mutex"
+	f(4, m) // ERROR "call of f copies lock value: sync.Mutex"
+	f(5, t) // ERROR "call of f copies lock value: struct{lock sync.Mutex} contains sync.Mutex"
+	var fntab []func(t)
+	fntab[0](t) // ERROR "call of fntab.0. copies lock value: struct{lock sync.Mutex} contains sync.Mutex"
 }
 
 // Returning lock via interface value
diff --git a/src/cmd/vet/vet_test.go b/src/cmd/vet/vet_test.go
index 725f013..b3d5c66 100644
--- a/src/cmd/vet/vet_test.go
+++ b/src/cmd/vet/vet_test.go
@@ -143,6 +143,7 @@ func TestVetDirs(t *testing.T) {
 		"divergent",
 		"buildtag",
 		"incomplete", // incomplete examples
+		"cgo",
 	} {
 		dir := dir
 		t.Run(dir, func(t *testing.T) {
diff --git a/src/crypto/sha1/sha1block_amd64.s b/src/crypto/sha1/sha1block_amd64.s
index 0cdb43b..77c8ec3 100644
--- a/src/crypto/sha1/sha1block_amd64.s
+++ b/src/crypto/sha1/sha1block_amd64.s
@@ -225,7 +225,7 @@ end:
 	RET
 
 
-// This is the implementation using AVX2. It is based on:
+// This is the implementation using AVX2, BMI1 and BMI2. It is based on:
 // "SHA-1 implementation with Intel(R) AVX2 instruction set extensions"
 // From http://software.intel.com/en-us/articles
 // (look for improving-the-performance-of-the-secure-hash-algorithm-1)
@@ -1459,15 +1459,19 @@ TEXT ·blockAVX2(SB),$1408-32
 
 
 // func checkAVX2() bool
-// returns whether AVX2 is supported
+// returns whether AVX2, BMI1 and BMI2 are supported
 TEXT ·checkAVX2(SB),NOSPLIT,$0
-	CMPB runtime·support_avx2(SB), $1
-	JE   has
-        MOVB    $0, ret+0(FP)
-	RET
-has:
+	CMPB runtime·support_avx2(SB), $0
+	JE   noavx2
+	CMPB runtime·support_bmi1(SB), $0  // check for ANDNL instruction
+	JE   noavx2
+	CMPB runtime·support_bmi2(SB), $0  // check for RORXL instruction
+	JE   noavx2
         MOVB    $1, ret+0(FP)
 	RET
+noavx2:
+        MOVB    $0, ret+0(FP)
+	RET
 
 
 DATA K_XMM_AR<>+0x00(SB)/4,$0x5a827999
diff --git a/src/crypto/sha256/sha256block_amd64.s b/src/crypto/sha256/sha256block_amd64.s
index edf7ad1..e9705b9 100644
--- a/src/crypto/sha256/sha256block_amd64.s
+++ b/src/crypto/sha256/sha256block_amd64.s
@@ -559,8 +559,11 @@
 	ADDL  y3, h                        // h = t1 + S0 + MAJ					// --
 
 TEXT ·block(SB), 0, $536-32
-	CMPB runtime·support_avx2(SB), $1
+	CMPB runtime·support_avx2(SB), $0
+	JE   noavx2bmi2
+	CMPB runtime·support_bmi2(SB), $1  // check for RORXL instruction
 	JE   avx2
+noavx2bmi2:
 
 	MOVQ p_base+8(FP), SI
 	MOVQ p_len+16(FP), DX
diff --git a/src/crypto/tls/conn.go b/src/crypto/tls/conn.go
index 4b2702a..03895a7 100644
--- a/src/crypto/tls/conn.go
+++ b/src/crypto/tls/conn.go
@@ -37,7 +37,7 @@ type Conn struct {
 	vers          uint16  // TLS version
 	haveVers      bool    // version has been negotiated
 	config        *Config // configuration passed to constructor
-	// handshakeComplete is true if the connection is currently transfering
+	// handshakeComplete is true if the connection is currently transferring
 	// application data (i.e. is not currently processing a handshake).
 	handshakeComplete bool
 	// handshakes counts the number of handshakes performed on the
diff --git a/src/crypto/x509/root_darwin.go b/src/crypto/x509/root_darwin.go
index 59b303d..66cdb5e 100644
--- a/src/crypto/x509/root_darwin.go
+++ b/src/crypto/x509/root_darwin.go
@@ -7,17 +7,22 @@
 package x509
 
 import (
+	"bufio"
 	"bytes"
+	"crypto/sha1"
 	"encoding/pem"
 	"fmt"
+	"io"
 	"io/ioutil"
 	"os"
 	"os/exec"
-	"strconv"
+	"path/filepath"
+	"strings"
 	"sync"
-	"syscall"
 )
 
+var debugExecDarwinRoots = strings.Contains(os.Getenv("GODEBUG"), "x509roots=1")
+
 func (c *Certificate) systemVerify(opts *VerifyOptions) (chains [][]*Certificate, err error) {
 	return nil, nil
 }
@@ -27,7 +32,35 @@ func (c *Certificate) systemVerify(opts *VerifyOptions) (chains [][]*Certificate
 // even if the tests are run with cgo enabled.
 // The linker will not include these unused functions in binaries built with cgo enabled.
 
+// execSecurityRoots finds the macOS list of trusted root certificates
+// using only command-line tools. This is our fallback path when cgo isn't available.
+//
+// The strategy is as follows:
+//
+// 1. Run "security trust-settings-export" and "security
+//    trust-settings-export -d" to discover the set of certs with some
+//    user-tweaked trust policy. We're too lazy to parse the XML (at
+//    least at this stage of Go 1.8) to understand what the trust
+//    policy actually is. We just learn that there is _some_ policy.
+//
+// 2. Run "security find-certificate" to dump the list of system root
+//    CAs in PEM format.
+//
+// 3. For each dumped cert, conditionally verify it with "security
+//    verify-cert" if that cert was in the set discovered in Step 1.
+//    Without the Step 1 optimization, running "security verify-cert"
+//    150-200 times takes 3.5 seconds. With the optimization, the
+//    whole process takes about 180 milliseconds with 1 untrusted root
+//    CA. (Compared to 110ms in the cgo path)
 func execSecurityRoots() (*CertPool, error) {
+	hasPolicy, err := getCertsWithTrustPolicy()
+	if err != nil {
+		return nil, err
+	}
+	if debugExecDarwinRoots {
+		println(fmt.Sprintf("crypto/x509: %d certs have a trust policy", len(hasPolicy)))
+	}
+
 	cmd := exec.Command("/usr/bin/security", "find-certificate", "-a", "-p", "/System/Library/Keychains/SystemRootCertificates.keychain")
 	data, err := cmd.Output()
 	if err != nil {
@@ -35,22 +68,49 @@ func execSecurityRoots() (*CertPool, error) {
 	}
 
 	var (
-		mu    sync.Mutex
-		roots = NewCertPool()
+		mu          sync.Mutex
+		roots       = NewCertPool()
+		numVerified int // number of execs of 'security verify-cert', for debug stats
 	)
-	add := func(cert *Certificate) {
-		mu.Lock()
-		defer mu.Unlock()
-		roots.AddCert(cert)
-	}
+
 	blockCh := make(chan *pem.Block)
 	var wg sync.WaitGroup
+
+	// Using 4 goroutines to pipe into verify-cert seems to be
+	// about the best we can do. The verify-cert binary seems to
+	// just RPC to another server with coarse locking anyway, so
+	// running 16 at a time for instance doesn't help at all. Due
+	// to the "if hasPolicy" check below, though, we will rarely
+	// (or never) call verify-cert on stock macOS systems, though.
+	// The hope is that we only call verify-cert when the user has
+	// tweaked their trust policy. These 4 goroutines are only
+	// defensive in the pathological case of many trust edits.
 	for i := 0; i < 4; i++ {
 		wg.Add(1)
 		go func() {
 			defer wg.Done()
 			for block := range blockCh {
-				verifyCertWithSystem(block, add)
+				cert, err := ParseCertificate(block.Bytes)
+				if err != nil {
+					continue
+				}
+				sha1CapHex := fmt.Sprintf("%X", sha1.Sum(block.Bytes))
+
+				valid := true
+				verifyChecks := 0
+				if hasPolicy[sha1CapHex] {
+					verifyChecks++
+					if !verifyCertWithSystem(block, cert) {
+						valid = false
+					}
+				}
+
+				mu.Lock()
+				numVerified += verifyChecks
+				if valid {
+					roots.AddCert(cert)
+				}
+				mu.Unlock()
 			}
 		}()
 	}
@@ -67,67 +127,118 @@ func execSecurityRoots() (*CertPool, error) {
 	}
 	close(blockCh)
 	wg.Wait()
+
+	if debugExecDarwinRoots {
+		mu.Lock()
+		defer mu.Unlock()
+		println(fmt.Sprintf("crypto/x509: ran security verify-cert %d times", numVerified))
+	}
+
 	return roots, nil
 }
 
-func verifyCertWithSystem(block *pem.Block, add func(*Certificate)) {
+func verifyCertWithSystem(block *pem.Block, cert *Certificate) bool {
 	data := pem.EncodeToMemory(block)
-	var cmd *exec.Cmd
-	if needsTmpFiles() {
-		f, err := ioutil.TempFile("", "cert")
-		if err != nil {
-			fmt.Fprintf(os.Stderr, "can't create temporary file for cert: %v", err)
-			return
-		}
-		defer os.Remove(f.Name())
-		if _, err := f.Write(data); err != nil {
-			fmt.Fprintf(os.Stderr, "can't write temporary file for cert: %v", err)
-			return
-		}
-		if err := f.Close(); err != nil {
-			fmt.Fprintf(os.Stderr, "can't write temporary file for cert: %v", err)
-			return
-		}
-		cmd = exec.Command("/usr/bin/security", "verify-cert", "-c", f.Name(), "-l")
-	} else {
-		cmd = exec.Command("/usr/bin/security", "verify-cert", "-c", "/dev/stdin", "-l")
-		cmd.Stdin = bytes.NewReader(data)
-	}
-	if cmd.Run() == nil {
-		// Non-zero exit means untrusted
-		cert, err := ParseCertificate(block.Bytes)
-		if err != nil {
-			return
-		}
 
-		add(cert)
+	f, err := ioutil.TempFile("", "cert")
+	if err != nil {
+		fmt.Fprintf(os.Stderr, "can't create temporary file for cert: %v", err)
+		return false
+	}
+	defer os.Remove(f.Name())
+	if _, err := f.Write(data); err != nil {
+		fmt.Fprintf(os.Stderr, "can't write temporary file for cert: %v", err)
+		return false
+	}
+	if err := f.Close(); err != nil {
+		fmt.Fprintf(os.Stderr, "can't write temporary file for cert: %v", err)
+		return false
+	}
+	cmd := exec.Command("/usr/bin/security", "verify-cert", "-c", f.Name(), "-l", "-L")
+	var stderr bytes.Buffer
+	if debugExecDarwinRoots {
+		cmd.Stderr = &stderr
+	}
+	if err := cmd.Run(); err != nil {
+		if debugExecDarwinRoots {
+			println(fmt.Sprintf("crypto/x509: verify-cert rejected %s: %q", cert.Subject.CommonName, bytes.TrimSpace(stderr.Bytes())))
+		}
+		return false
+	}
+	if debugExecDarwinRoots {
+		println(fmt.Sprintf("crypto/x509: verify-cert approved %s", cert.Subject.CommonName))
 	}
+	return true
 }
 
-var versionCache struct {
-	sync.Once
-	major int
-}
+// getCertsWithTrustPolicy returns the set of certs that have a
+// possibly-altered trust policy. The keys of the map are capitalized
+// sha1 hex of the raw cert.
+// They are the certs that should be checked against `security
+// verify-cert` to see whether the user altered the default trust
+// settings. This code is only used for cgo-disabled builds.
+func getCertsWithTrustPolicy() (map[string]bool, error) {
+	set := map[string]bool{}
+	td, err := ioutil.TempDir("", "x509trustpolicy")
+	if err != nil {
+		return nil, err
+	}
+	defer os.RemoveAll(td)
+	run := func(file string, args ...string) error {
+		file = filepath.Join(td, file)
+		args = append(args, file)
+		cmd := exec.Command("/usr/bin/security", args...)
+		var stderr bytes.Buffer
+		cmd.Stderr = &stderr
+		if err := cmd.Run(); err != nil {
+			// If there are no trust settings, the
+			// `security trust-settings-export` command
+			// fails with:
+			//    exit status 1, SecTrustSettingsCreateExternalRepresentation: No Trust Settings were found.
+			// Rather than match on English substrings that are probably
+			// localized on macOS, just interpret any failure to mean that
+			// there are no trust settings.
+			if debugExecDarwinRoots {
+				println(fmt.Sprintf("crypto/x509: exec %q: %v, %s", cmd.Args, err, stderr.Bytes()))
+			}
+			return nil
+		}
 
-// needsTmpFiles reports whether the OS is <= 10.11 (which requires real
-// files as arguments to the security command).
-func needsTmpFiles() bool {
-	versionCache.Do(func() {
-		release, err := syscall.Sysctl("kern.osrelease")
+		f, err := os.Open(file)
 		if err != nil {
-			return
+			return err
 		}
-		for i, c := range release {
-			if c == '.' {
-				release = release[:i]
+		defer f.Close()
+
+		// Gather all the runs of 40 capitalized hex characters.
+		br := bufio.NewReader(f)
+		var hexBuf bytes.Buffer
+		for {
+			b, err := br.ReadByte()
+			isHex := ('A' <= b && b <= 'F') || ('0' <= b && b <= '9')
+			if isHex {
+				hexBuf.WriteByte(b)
+			} else {
+				if hexBuf.Len() == 40 {
+					set[hexBuf.String()] = true
+				}
+				hexBuf.Reset()
+			}
+			if err == io.EOF {
 				break
 			}
+			if err != nil {
+				return err
+			}
 		}
-		major, err := strconv.Atoi(release)
-		if err != nil {
-			return
-		}
-		versionCache.major = major
-	})
-	return versionCache.major <= 15
+
+		return nil
+	}
+	if err := run("user", "trust-settings-export"); err != nil {
+		return nil, fmt.Errorf("dump-trust-settings (user): %v", err)
+	}
+	if err := run("admin", "trust-settings-export", "-d"); err != nil {
+		return nil, fmt.Errorf("dump-trust-settings (admin): %v", err)
+	}
+	return set, nil
 }
diff --git a/src/crypto/x509/root_darwin_test.go b/src/crypto/x509/root_darwin_test.go
index d6d8d07..2784ce2 100644
--- a/src/crypto/x509/root_darwin_test.go
+++ b/src/crypto/x509/root_darwin_test.go
@@ -7,6 +7,7 @@ package x509
 import (
 	"runtime"
 	"testing"
+	"time"
 )
 
 func TestSystemRoots(t *testing.T) {
@@ -15,13 +16,21 @@ func TestSystemRoots(t *testing.T) {
 		t.Skipf("skipping on %s/%s, no system root", runtime.GOOS, runtime.GOARCH)
 	}
 
-	sysRoots := systemRootsPool()         // actual system roots
+	t0 := time.Now()
+	sysRoots := systemRootsPool() // actual system roots
+	sysRootsDuration := time.Since(t0)
+
+	t1 := time.Now()
 	execRoots, err := execSecurityRoots() // non-cgo roots
+	execSysRootsDuration := time.Since(t1)
 
 	if err != nil {
 		t.Fatalf("failed to read system roots: %v", err)
 	}
 
+	t.Logf("    cgo sys roots: %v", sysRootsDuration)
+	t.Logf("non-cgo sys roots: %v", execSysRootsDuration)
+
 	for _, tt := range []*CertPool{sysRoots, execRoots} {
 		if tt == nil {
 			t.Fatal("no system roots")
diff --git a/src/database/sql/sql.go b/src/database/sql/sql.go
index 9602450..0fa7c34 100644
--- a/src/database/sql/sql.go
+++ b/src/database/sql/sql.go
@@ -1421,10 +1421,9 @@ func (tx *Tx) isDone() bool {
 // that has already been committed or rolled back.
 var ErrTxDone = errors.New("sql: Transaction has already been committed or rolled back")
 
+// close returns the connection to the pool and
+// must only be called by Tx.rollback or Tx.Commit.
 func (tx *Tx) close(err error) {
-	if !atomic.CompareAndSwapInt32(&tx.done, 0, 1) {
-		panic("double close") // internal error
-	}
 	tx.db.putConn(tx.dc, err)
 	tx.cancel()
 	tx.dc = nil
@@ -1449,7 +1448,7 @@ func (tx *Tx) closePrepared() {
 
 // Commit commits the transaction.
 func (tx *Tx) Commit() error {
-	if tx.isDone() {
+	if !atomic.CompareAndSwapInt32(&tx.done, 0, 1) {
 		return ErrTxDone
 	}
 	select {
@@ -1471,7 +1470,7 @@ func (tx *Tx) Commit() error {
 // rollback aborts the transaction and optionally forces the pool to discard
 // the connection.
 func (tx *Tx) rollback(discardConn bool) error {
-	if tx.isDone() {
+	if !atomic.CompareAndSwapInt32(&tx.done, 0, 1) {
 		return ErrTxDone
 	}
 	var err error
@@ -2087,7 +2086,7 @@ func (rs *Rows) Next() bool {
 		}
 		// The driver is at the end of the current result set.
 		// Test to see if there is another result set after the current one.
-		// Only close Rows if there is no futher result sets to read.
+		// Only close Rows if there is no further result sets to read.
 		if !nextResultSet.HasNextResultSet() {
 			rs.Close()
 		}
diff --git a/src/database/sql/sql_test.go b/src/database/sql/sql_test.go
index 422d219..63e1292 100644
--- a/src/database/sql/sql_test.go
+++ b/src/database/sql/sql_test.go
@@ -2607,6 +2607,54 @@ func TestIssue6081(t *testing.T) {
 	}
 }
 
+// TestIssue18429 attempts to stress rolling back the transaction from a
+// context cancel while simultaneously calling Tx.Rollback. Rolling back from a
+// context happens concurrently so tx.rollback and tx.Commit must guard against
+// double entry.
+//
+// In the test, a context is canceled while the query is in process so
+// the internal rollback will run concurrently with the explicitly called
+// Tx.Rollback.
+func TestIssue18429(t *testing.T) {
+	db := newTestDB(t, "people")
+	defer closeDB(t, db)
+
+	ctx := context.Background()
+	sem := make(chan bool, 20)
+	var wg sync.WaitGroup
+
+	const milliWait = 30
+
+	for i := 0; i < 100; i++ {
+		sem <- true
+		wg.Add(1)
+		go func() {
+			defer func() {
+				<-sem
+				wg.Done()
+			}()
+			qwait := (time.Duration(rand.Intn(milliWait)) * time.Millisecond).String()
+
+			ctx, cancel := context.WithTimeout(ctx, time.Duration(rand.Intn(milliWait))*time.Millisecond)
+			defer cancel()
+
+			tx, err := db.BeginTx(ctx, nil)
+			if err != nil {
+				return
+			}
+			rows, err := tx.QueryContext(ctx, "WAIT|"+qwait+"|SELECT|people|name|")
+			if rows != nil {
+				rows.Close()
+			}
+			// This call will race with the context cancel rollback to complete
+			// if the rollback itself isn't guarded.
+			tx.Rollback()
+		}()
+	}
+	wg.Wait()
+	time.Sleep(milliWait * 3 * time.Millisecond)
+}
+
 func TestConcurrency(t *testing.T) {
 	doConcurrentTest(t, new(concurrentDBQueryTest))
 	doConcurrentTest(t, new(concurrentDBExecTest))
diff --git a/src/go/build/build.go b/src/go/build/build.go
index ea37bbb..da12d50 100644
--- a/src/go/build/build.go
+++ b/src/go/build/build.go
@@ -439,16 +439,11 @@ func (ctxt *Context) ImportDir(dir string, mode ImportMode) (*Package, error) {
 // containing no buildable Go source files. (It may still contain
 // test files, files hidden by build tags, and so on.)
 type NoGoError struct {
-	Dir     string
-	Ignored bool // whether any Go files were ignored due to build tags
+	Dir string
 }
 
 func (e *NoGoError) Error() string {
-	msg := "no buildable Go source files in " + e.Dir
-	if e.Ignored {
-		msg += " (.go files ignored due to build tags)"
-	}
-	return msg
+	return "no buildable Go source files in " + e.Dir
 }
 
 // MultiplePackageError describes a directory containing
@@ -880,7 +875,7 @@ Found:
 		return p, badGoError
 	}
 	if len(p.GoFiles)+len(p.CgoFiles)+len(p.TestGoFiles)+len(p.XTestGoFiles) == 0 {
-		return p, &NoGoError{Dir: p.Dir, Ignored: len(p.IgnoredGoFiles) > 0}
+		return p, &NoGoError{p.Dir}
 	}
 
 	for tag := range allTags {
diff --git a/src/go/build/build_test.go b/src/go/build/build_test.go
index 8ca8e5e..a997241 100644
--- a/src/go/build/build_test.go
+++ b/src/go/build/build_test.go
@@ -93,17 +93,6 @@ func TestEmptyFolderImport(t *testing.T) {
 	}
 }
 
-func TestIgnoredGoFilesImport(t *testing.T) {
-	_, err := Import(".", "testdata/ignored", 0)
-	e, ok := err.(*NoGoError)
-	if !ok {
-		t.Fatal(`Import("testdata/ignored") did not return NoGoError.`)
-	}
-	if !e.Ignored {
-		t.Fatal(`Import("testdata/ignored") should have ignored Go files.`)
-	}
-}
-
 func TestMultiplePackageImport(t *testing.T) {
 	_, err := Import(".", "testdata/multi", 0)
 	mpe, ok := err.(*MultiplePackageError)
diff --git a/src/go/build/testdata/ignored/ignored.go b/src/go/build/testdata/ignored/ignored.go
deleted file mode 100644
index 48a2ae8..0000000
--- a/src/go/build/testdata/ignored/ignored.go
+++ /dev/null
@@ -1,3 +0,0 @@
-// +build alwaysignore
-
-package ignored
diff --git a/src/go/parser/interface.go b/src/go/parser/interface.go
index bff79ca..724d865 100644
--- a/src/go/parser/interface.go
+++ b/src/go/parser/interface.go
@@ -173,7 +173,7 @@ func ParseDir(fset *token.FileSet, path string, filter func(os.FileInfo) bool, m
 }
 
 // ParseExprFrom is a convenience function for parsing an expression.
-// The arguments have the same meaning as for Parse, but the source must
+// The arguments have the same meaning as for ParseFile, but the source must
 // be a valid Go (type or value) expression. Specifically, fset must not
 // be nil.
 //
diff --git a/src/go/types/api.go b/src/go/types/api.go
index 4494989..5b911cb 100644
--- a/src/go/types/api.go
+++ b/src/go/types/api.go
@@ -5,7 +5,7 @@
 // Package types declares the data types and implements
 // the algorithms for type-checking of Go packages. Use
 // Config.Check to invoke the type checker for a package.
-// Alternatively, create a new type checked with NewChecker
+// Alternatively, create a new type checker with NewChecker
 // and invoke it incrementally by calling Checker.Files.
 //
 // Type-checking consists of several interdependent phases:
diff --git a/src/go/types/stdlib_test.go b/src/go/types/stdlib_test.go
index 1c6d7b5..06d2c93 100644
--- a/src/go/types/stdlib_test.go
+++ b/src/go/types/stdlib_test.go
@@ -157,6 +157,7 @@ func TestStdFixed(t *testing.T) {
 		"issue11362.go", // canonical import path check
 		"issue15002.go", // uses Mmap; testTestDir should consult build tags
 		"issue16369.go", // go/types handles this correctly - not an issue
+		"issue18459.go", // go/types doesn't check validity of //go:xxx directives
 	)
 }
 
diff --git a/src/io/pipe.go b/src/io/pipe.go
index 6145872..b6e7755 100644
--- a/src/io/pipe.go
+++ b/src/io/pipe.go
@@ -85,6 +85,7 @@ func (p *pipe) write(b []byte) (n int, err error) {
 		}
 		if p.werr != nil {
 			err = ErrClosedPipe
+			break
 		}
 		p.wwait.Wait()
 	}
diff --git a/src/io/pipe_test.go b/src/io/pipe_test.go
index b16e653..95930e8 100644
--- a/src/io/pipe_test.go
+++ b/src/io/pipe_test.go
@@ -247,6 +247,18 @@ func TestPipeWriteClose(t *testing.T) {
 	}
 }
 
+// Test close on Write side during Write.
+func TestPipeWriteClose2(t *testing.T) {
+	c := make(chan int, 1)
+	_, w := Pipe()
+	go delayClose(t, w, c, pipeTest{})
+	n, err := w.Write(make([]byte, 64))
+	<-c
+	if n != 0 || err != ErrClosedPipe {
+		t.Errorf("write to closed pipe: %v, %v want %v, %v", n, err, 0, ErrClosedPipe)
+	}
+}
+
 func TestWriteEmpty(t *testing.T) {
 	r, w := Pipe()
 	go func() {
diff --git a/src/net/addrselect.go b/src/net/addrselect.go
index 0b9d160..1ab9fc5 100644
--- a/src/net/addrselect.go
+++ b/src/net/addrselect.go
@@ -188,33 +188,17 @@ func (s *byRFC6724) Less(i, j int) bool {
 
 	// Rule 9: Use longest matching prefix.
 	// When DA and DB belong to the same address family (both are IPv6 or
-	// both are IPv4): If CommonPrefixLen(Source(DA), DA) >
+	// both are IPv4 [but see below]): If CommonPrefixLen(Source(DA), DA) >
 	// CommonPrefixLen(Source(DB), DB), then prefer DA.  Similarly, if
 	// CommonPrefixLen(Source(DA), DA) < CommonPrefixLen(Source(DB), DB),
 	// then prefer DB.
-	da4 := DA.To4() != nil
-	db4 := DB.To4() != nil
-	if da4 == db4 {
+	//
+	// However, applying this rule to IPv4 addresses causes
+	// problems (see issues 13283 and 18518), so limit to IPv6.
+	if DA.To4() == nil && DB.To4() == nil {
 		commonA := commonPrefixLen(SourceDA, DA)
 		commonB := commonPrefixLen(SourceDB, DB)
 
-		// CommonPrefixLen doesn't really make sense for IPv4, and even
-		// causes problems for common load balancing practices
-		// (e.g., https://golang.org/issue/13283).  Glibc instead only
-		// uses CommonPrefixLen for IPv4 when the source and destination
-		// addresses are on the same subnet, but that requires extra
-		// work to find the netmask for our source addresses. As a
-		// simpler heuristic, we limit its use to when the source and
-		// destination belong to the same special purpose block.
-		if da4 {
-			if !sameIPv4SpecialPurposeBlock(SourceDA, DA) {
-				commonA = 0
-			}
-			if !sameIPv4SpecialPurposeBlock(SourceDB, DB) {
-				commonB = 0
-			}
-		}
-
 		if commonA > commonB {
 			return preferDA
 		}
@@ -404,28 +388,3 @@ func commonPrefixLen(a, b IP) (cpl int) {
 	}
 	return
 }
-
-// sameIPv4SpecialPurposeBlock reports whether a and b belong to the same
-// address block reserved by the IANA IPv4 Special-Purpose Address Registry:
-// http://www.iana.org/assignments/iana-ipv4-special-registry/iana-ipv4-special-registry.xhtml
-func sameIPv4SpecialPurposeBlock(a, b IP) bool {
-	a, b = a.To4(), b.To4()
-	if a == nil || b == nil || a[0] != b[0] {
-		return false
-	}
-	// IANA defines more special-purpose blocks, but these are the only
-	// ones likely to be relevant to typical Go systems.
-	switch a[0] {
-	case 10: // 10.0.0.0/8: Private-Use
-		return true
-	case 127: // 127.0.0.0/8: Loopback
-		return true
-	case 169: // 169.254.0.0/16: Link Local
-		return a[1] == 254 && b[1] == 254
-	case 172: // 172.16.0.0/12: Private-Use
-		return a[1]&0xf0 == 16 && b[1]&0xf0 == 16
-	case 192: // 192.168.0.0/16: Private-Use
-		return a[1] == 168 && b[1] == 168
-	}
-	return false
-}
diff --git a/src/net/addrselect_test.go b/src/net/addrselect_test.go
index 80aa4eb..d6e0e63 100644
--- a/src/net/addrselect_test.go
+++ b/src/net/addrselect_test.go
@@ -117,27 +117,6 @@ func TestSortByRFC6724(t *testing.T) {
 			},
 			reverse: false,
 		},
-
-		// Prefer longer common prefixes, but only for IPv4 address
-		// pairs in the same special-purpose block.
-		{
-			in: []IPAddr{
-				{IP: ParseIP("1.2.3.4")},
-				{IP: ParseIP("10.55.0.1")},
-				{IP: ParseIP("10.66.0.1")},
-			},
-			srcs: []IP{
-				ParseIP("1.2.3.5"),
-				ParseIP("10.66.1.2"),
-				ParseIP("10.66.1.2"),
-			},
-			want: []IPAddr{
-				{IP: ParseIP("10.66.0.1")},
-				{IP: ParseIP("10.55.0.1")},
-				{IP: ParseIP("1.2.3.4")},
-			},
-			reverse: true,
-		},
 	}
 	for i, tt := range tests {
 		inCopy := make([]IPAddr, len(tt.in))
@@ -268,67 +247,3 @@ func TestRFC6724CommonPrefixLength(t *testing.T) {
 	}
 
 }
-
-func mustParseCIDRs(t *testing.T, blocks ...string) []*IPNet {
-	res := make([]*IPNet, len(blocks))
-	for i, block := range blocks {
-		var err error
-		_, res[i], err = ParseCIDR(block)
-		if err != nil {
-			t.Fatalf("ParseCIDR(%s) failed: %v", block, err)
-		}
-	}
-	return res
-}
-
-func TestSameIPv4SpecialPurposeBlock(t *testing.T) {
-	blocks := mustParseCIDRs(t,
-		"10.0.0.0/8",
-		"127.0.0.0/8",
-		"169.254.0.0/16",
-		"172.16.0.0/12",
-		"192.168.0.0/16",
-	)
-
-	addrs := []struct {
-		ip    IP
-		block int // index or -1
-	}{
-		{IP{1, 2, 3, 4}, -1},
-		{IP{2, 3, 4, 5}, -1},
-		{IP{10, 2, 3, 4}, 0},
-		{IP{10, 6, 7, 8}, 0},
-		{IP{127, 0, 0, 1}, 1},
-		{IP{127, 255, 255, 255}, 1},
-		{IP{169, 254, 77, 99}, 2},
-		{IP{169, 254, 44, 22}, 2},
-		{IP{169, 255, 0, 1}, -1},
-		{IP{172, 15, 5, 6}, -1},
-		{IP{172, 16, 32, 41}, 3},
-		{IP{172, 31, 128, 9}, 3},
-		{IP{172, 32, 88, 100}, -1},
-		{IP{192, 168, 1, 1}, 4},
-		{IP{192, 168, 128, 42}, 4},
-		{IP{192, 169, 1, 1}, -1},
-	}
-
-	for i, addr := range addrs {
-		for j, block := range blocks {
-			got := block.Contains(addr.ip)
-			want := addr.block == j
-			if got != want {
-				t.Errorf("%d/%d. %s.Contains(%s): got %v, want %v", i, j, block, addr.ip, got, want)
-			}
-		}
-	}
-
-	for i, addr1 := range addrs {
-		for j, addr2 := range addrs {
-			got := sameIPv4SpecialPurposeBlock(addr1.ip, addr2.ip)
-			want := addr1.block >= 0 && addr1.block == addr2.block
-			if got != want {
-				t.Errorf("%d/%d. sameIPv4SpecialPurposeBlock(%s, %s): got %v, want %v", i, j, addr1.ip, addr2.ip, got, want)
-			}
-		}
-	}
-}
diff --git a/src/net/dial.go b/src/net/dial.go
index b73426f..50bba5a 100644
--- a/src/net/dial.go
+++ b/src/net/dial.go
@@ -163,7 +163,7 @@ func parseNetwork(ctx context.Context, net string) (afnet string, proto int, err
 	return "", 0, UnknownNetworkError(net)
 }
 
-// resolverAddrList resolves addr using hint and returns a list of
+// resolveAddrList resolves addr using hint and returns a list of
 // addresses. The result contains at least one address when error is
 // nil.
 func (r *Resolver) resolveAddrList(ctx context.Context, op, network, addr string, hint Addr) (addrList, error) {
diff --git a/src/net/dial_test.go b/src/net/dial_test.go
index 6ba8e95..9919d72 100644
--- a/src/net/dial_test.go
+++ b/src/net/dial_test.go
@@ -142,6 +142,8 @@ func TestDialerDualStackFDLeak(t *testing.T) {
 		t.Skipf("%s does not have full support of socktest", runtime.GOOS)
 	case "windows":
 		t.Skipf("not implemented a way to cancel dial racers in TCP SYN-SENT state on %s", runtime.GOOS)
+	case "openbsd":
+		testenv.SkipFlaky(t, 15157)
 	}
 	if !supportsIPv4 || !supportsIPv6 {
 		t.Skip("both IPv4 and IPv6 are required")
diff --git a/src/net/dnsclient_unix.go b/src/net/dnsclient_unix.go
index 2980302..4dd4e16 100644
--- a/src/net/dnsclient_unix.go
+++ b/src/net/dnsclient_unix.go
@@ -444,7 +444,7 @@ func goLookupHostOrder(ctx context.Context, name string, order hostLookupOrder)
 			return
 		}
 	}
-	ips, err := goLookupIPOrder(ctx, name, order)
+	ips, _, err := goLookupIPCNAMEOrder(ctx, name, order)
 	if err != nil {
 		return
 	}
@@ -472,27 +472,28 @@ func goLookupIPFiles(name string) (addrs []IPAddr) {
 // The libc versions are in cgo_*.go.
 func goLookupIP(ctx context.Context, host string) (addrs []IPAddr, err error) {
 	order := systemConf().hostLookupOrder(host)
-	return goLookupIPOrder(ctx, host, order)
+	addrs, _, err = goLookupIPCNAMEOrder(ctx, host, order)
+	return
 }
 
-func goLookupIPOrder(ctx context.Context, name string, order hostLookupOrder) (addrs []IPAddr, err error) {
+func goLookupIPCNAMEOrder(ctx context.Context, name string, order hostLookupOrder) (addrs []IPAddr, cname string, err error) {
 	if order == hostLookupFilesDNS || order == hostLookupFiles {
 		addrs = goLookupIPFiles(name)
 		if len(addrs) > 0 || order == hostLookupFiles {
-			return addrs, nil
+			return addrs, name, nil
 		}
 	}
 	if !isDomainName(name) {
 		// See comment in func lookup above about use of errNoSuchHost.
-		return nil, &DNSError{Err: errNoSuchHost.Error(), Name: name}
+		return nil, "", &DNSError{Err: errNoSuchHost.Error(), Name: name}
 	}
 	resolvConf.tryUpdate("/etc/resolv.conf")
 	resolvConf.mu.RLock()
 	conf := resolvConf.dnsConfig
 	resolvConf.mu.RUnlock()
 	type racer struct {
-		fqdn string
-		rrs  []dnsRR
+		cname string
+		rrs   []dnsRR
 		error
 	}
 	lane := make(chan racer, 1)
@@ -501,20 +502,23 @@ func goLookupIPOrder(ctx context.Context, name string, order hostLookupOrder) (a
 	for _, fqdn := range conf.nameList(name) {
 		for _, qtype := range qtypes {
 			go func(qtype uint16) {
-				_, rrs, err := tryOneName(ctx, conf, fqdn, qtype)
-				lane <- racer{fqdn, rrs, err}
+				cname, rrs, err := tryOneName(ctx, conf, fqdn, qtype)
+				lane <- racer{cname, rrs, err}
 			}(qtype)
 		}
 		for range qtypes {
 			racer := <-lane
 			if racer.error != nil {
 				// Prefer error for original name.
-				if lastErr == nil || racer.fqdn == name+"." {
+				if lastErr == nil || fqdn == name+"." {
 					lastErr = racer.error
 				}
 				continue
 			}
 			addrs = append(addrs, addrRecordList(racer.rrs)...)
+			if cname == "" {
+				cname = racer.cname
+			}
 		}
 		if len(addrs) > 0 {
 			break
@@ -532,24 +536,16 @@ func goLookupIPOrder(ctx context.Context, name string, order hostLookupOrder) (a
 			addrs = goLookupIPFiles(name)
 		}
 		if len(addrs) == 0 && lastErr != nil {
-			return nil, lastErr
+			return nil, "", lastErr
 		}
 	}
-	return addrs, nil
+	return addrs, cname, nil
 }
 
-// goLookupCNAME is the native Go implementation of LookupCNAME.
-// Used only if cgoLookupCNAME refuses to handle the request
-// (that is, only if cgoLookupCNAME is the stub in cgo_stub.go).
-// Normally we let cgo use the C library resolver instead of
-// depending on our lookup code, so that Go and C get the same
-// answers.
-func goLookupCNAME(ctx context.Context, name string) (cname string, err error) {
-	_, rrs, err := lookup(ctx, name, dnsTypeCNAME)
-	if err != nil {
-		return
-	}
-	cname = rrs[0].(*dnsRR_CNAME).Cname
+// goLookupCNAME is the native Go (non-cgo) implementation of LookupCNAME.
+func goLookupCNAME(ctx context.Context, host string) (cname string, err error) {
+	order := systemConf().hostLookupOrder(host)
+	_, cname, err = goLookupIPCNAMEOrder(ctx, host, order)
 	return
 }
 
diff --git a/src/net/dnsclient_unix_test.go b/src/net/dnsclient_unix_test.go
index 7dc364d..85267bb 100644
--- a/src/net/dnsclient_unix_test.go
+++ b/src/net/dnsclient_unix_test.go
@@ -455,14 +455,14 @@ func TestGoLookupIPOrderFallbackToFile(t *testing.T) {
 		name := fmt.Sprintf("order %v", order)
 
 		// First ensure that we get an error when contacting a non-existent host.
-		_, err := goLookupIPOrder(context.Background(), "notarealhost", order)
+		_, _, err := goLookupIPCNAMEOrder(context.Background(), "notarealhost", order)
 		if err == nil {
 			t.Errorf("%s: expected error while looking up name not in hosts file", name)
 			continue
 		}
 
 		// Now check that we get an address when the name appears in the hosts file.
-		addrs, err := goLookupIPOrder(context.Background(), "thor", order) // entry is in "testdata/hosts"
+		addrs, _, err := goLookupIPCNAMEOrder(context.Background(), "thor", order) // entry is in "testdata/hosts"
 		if err != nil {
 			t.Errorf("%s: expected to successfully lookup host entry", name)
 			continue
@@ -744,8 +744,11 @@ func TestRetryTimeout(t *testing.T) {
 	}
 	defer conf.teardown()
 
-	if err := conf.writeAndUpdate([]string{"nameserver 192.0.2.1", // the one that will timeout
-		"nameserver 192.0.2.2"}); err != nil {
+	testConf := []string{
+		"nameserver 192.0.2.1", // the one that will timeout
+		"nameserver 192.0.2.2",
+	}
+	if err := conf.writeAndUpdate(testConf); err != nil {
 		t.Fatal(err)
 	}
 
@@ -771,28 +774,10 @@ func TestRetryTimeout(t *testing.T) {
 			t.Error("deadline didn't change")
 		}
 
-		r := &dnsMsg{
-			dnsMsgHdr: dnsMsgHdr{
-				id:                  q.id,
-				response:            true,
-				recursion_available: true,
-			},
-			question: q.question,
-			answer: []dnsRR{
-				&dnsRR_CNAME{
-					Hdr: dnsRR_Header{
-						Name:   q.question[0].Name,
-						Rrtype: dnsTypeCNAME,
-						Class:  dnsClassINET,
-					},
-					Cname: "golang.org",
-				},
-			},
-		}
-		return r, nil
+		return mockTXTResponse(q), nil
 	}
 
-	_, err = goLookupCNAME(context.Background(), "www.golang.org")
+	_, err = LookupTXT("www.golang.org")
 	if err != nil {
 		t.Fatal(err)
 	}
@@ -838,36 +823,40 @@ func testRotate(t *testing.T, rotate bool, nameservers, wantServers []string) {
 	var usedServers []string
 	d.rh = func(s string, q *dnsMsg, _ time.Time) (*dnsMsg, error) {
 		usedServers = append(usedServers, s)
-
-		r := &dnsMsg{
-			dnsMsgHdr: dnsMsgHdr{
-				id:                  q.id,
-				response:            true,
-				recursion_available: true,
-			},
-			question: q.question,
-			answer: []dnsRR{
-				&dnsRR_CNAME{
-					Hdr: dnsRR_Header{
-						Name:   q.question[0].Name,
-						Rrtype: dnsTypeCNAME,
-						Class:  dnsClassINET,
-					},
-					Cname: "golang.org",
-				},
-			},
-		}
-		return r, nil
+		return mockTXTResponse(q), nil
 	}
 
 	// len(nameservers) + 1 to allow rotation to get back to start
 	for i := 0; i < len(nameservers)+1; i++ {
-		if _, err := goLookupCNAME(context.Background(), "www.golang.org"); err != nil {
+		if _, err := LookupTXT("www.golang.org"); err != nil {
 			t.Fatal(err)
 		}
 	}
 
 	if !reflect.DeepEqual(usedServers, wantServers) {
-		t.Fatalf("rotate=%t got used servers:\n%v\nwant:\n%v", rotate, usedServers, wantServers)
+		t.Errorf("rotate=%t got used servers:\n%v\nwant:\n%v", rotate, usedServers, wantServers)
 	}
 }
+
+func mockTXTResponse(q *dnsMsg) *dnsMsg {
+	r := &dnsMsg{
+		dnsMsgHdr: dnsMsgHdr{
+			id:                  q.id,
+			response:            true,
+			recursion_available: true,
+		},
+		question: q.question,
+		answer: []dnsRR{
+			&dnsRR_TXT{
+				Hdr: dnsRR_Header{
+					Name:   q.question[0].Name,
+					Rrtype: dnsTypeTXT,
+					Class:  dnsClassINET,
+				},
+				Txt: "ok",
+			},
+		},
+	}
+
+	return r
+}
diff --git a/src/net/http/client.go b/src/net/http/client.go
index 9308c5c..d368bae 100644
--- a/src/net/http/client.go
+++ b/src/net/http/client.go
@@ -413,19 +413,26 @@ func (c *Client) checkRedirect(req *Request, via []*Request) error {
 
 // redirectBehavior describes what should happen when the
 // client encounters a 3xx status code from the server
-func redirectBehavior(reqMethod string, resp *Response, via []*Request) (redirectMethod string, shouldRedirect bool) {
+func redirectBehavior(reqMethod string, resp *Response, ireq *Request) (redirectMethod string, shouldRedirect bool) {
 	switch resp.StatusCode {
 	case 301, 302, 303:
-		redirectMethod = "GET"
+		redirectMethod = reqMethod
 		shouldRedirect = true
+
+		// RFC 2616 allowed automatic redirection only with GET and
+		// HEAD requests. RFC 7231 lifts this restriction, but we still
+		// restrict other methods to GET to maintain compatibility.
+		// See Issue 18570.
+		if reqMethod != "GET" && reqMethod != "HEAD" {
+			redirectMethod = "GET"
+		}
 	case 307, 308:
 		redirectMethod = reqMethod
 		shouldRedirect = true
 
 		// Treat 307 and 308 specially, since they're new in
 		// Go 1.8, and they also require re-sending the request body.
-		loc := resp.Header.Get("Location")
-		if loc == "" {
+		if resp.Header.Get("Location") == "" {
 			// 308s have been observed in the wild being served
 			// without Location headers. Since Go 1.7 and earlier
 			// didn't follow these codes, just stop here instead
@@ -434,7 +441,6 @@ func redirectBehavior(reqMethod string, resp *Response, via []*Request) (redirec
 			shouldRedirect = false
 			break
 		}
-		ireq := via[0]
 		if ireq.GetBody == nil && ireq.outgoingLength() != 0 {
 			// We had a request body, and 307/308 require
 			// re-sending it, but GetBody is not defined. So just
@@ -443,7 +449,6 @@ func redirectBehavior(reqMethod string, resp *Response, via []*Request) (redirec
 			shouldRedirect = false
 		}
 	}
-
 	return redirectMethod, shouldRedirect
 }
 
@@ -470,6 +475,16 @@ func redirectBehavior(reqMethod string, resp *Response, via []*Request) (redirec
 // the returned Response.Body is already closed.
 //
 // Generally Get, Post, or PostForm will be used instead of Do.
+//
+// If the server replies with a redirect, the Client first uses the
+// CheckRedirect function to determine whether the redirect should be
+// followed. If permitted, a 301, 302, or 303 redirect causes
+// subsequent requests to use HTTP method GET
+// (or HEAD if the original request was HEAD), with no body.
+// A 307 or 308 redirect preserves the original HTTP method and body,
+// provided that the Request.GetBody function is defined.
+// The NewRequest function automatically sets GetBody for common
+// standard library body types.
 func (c *Client) Do(req *Request) (*Response, error) {
 	if req.URL == nil {
 		req.closeBody()
@@ -583,7 +598,7 @@ func (c *Client) Do(req *Request) (*Response, error) {
 		}
 
 		var shouldRedirect bool
-		redirectMethod, shouldRedirect = redirectBehavior(req.Method, resp, reqs)
+		redirectMethod, shouldRedirect = redirectBehavior(req.Method, resp, reqs[0])
 		if !shouldRedirect {
 			return resp, nil
 		}
@@ -673,6 +688,9 @@ func defaultCheckRedirect(req *Request, via []*Request) error {
 // Post is a wrapper around DefaultClient.Post.
 //
 // To set custom headers, use NewRequest and DefaultClient.Do.
+//
+// See the Client.Do method documentation for details on how redirects
+// are handled.
 func Post(url string, contentType string, body io.Reader) (resp *Response, err error) {
 	return DefaultClient.Post(url, contentType, body)
 }
@@ -685,6 +703,9 @@ func Post(url string, contentType string, body io.Reader) (resp *Response, err e
 // request.
 //
 // To set custom headers, use NewRequest and Client.Do.
+//
+// See the Client.Do method documentation for details on how redirects
+// are handled.
 func (c *Client) Post(url string, contentType string, body io.Reader) (resp *Response, err error) {
 	req, err := NewRequest("POST", url, body)
 	if err != nil {
@@ -704,6 +725,9 @@ func (c *Client) Post(url string, contentType string, body io.Reader) (resp *Res
 // Caller should close resp.Body when done reading from it.
 //
 // PostForm is a wrapper around DefaultClient.PostForm.
+//
+// See the Client.Do method documentation for details on how redirects
+// are handled.
 func PostForm(url string, data url.Values) (resp *Response, err error) {
 	return DefaultClient.PostForm(url, data)
 }
@@ -716,6 +740,9 @@ func PostForm(url string, data url.Values) (resp *Response, err error) {
 //
 // When err is nil, resp always contains a non-nil resp.Body.
 // Caller should close resp.Body when done reading from it.
+//
+// See the Client.Do method documentation for details on how redirects
+// are handled.
 func (c *Client) PostForm(url string, data url.Values) (resp *Response, err error) {
 	return c.Post(url, "application/x-www-form-urlencoded", strings.NewReader(data.Encode()))
 }
diff --git a/src/net/http/client_test.go b/src/net/http/client_test.go
index ca6e918..eaf2cdc 100644
--- a/src/net/http/client_test.go
+++ b/src/net/http/client_test.go
@@ -1665,9 +1665,9 @@ func TestClientRedirectTypes(t *testing.T) {
 		3: {method: "POST", serverStatus: 307, wantMethod: "POST"},
 		4: {method: "POST", serverStatus: 308, wantMethod: "POST"},
 
-		5: {method: "HEAD", serverStatus: 301, wantMethod: "GET"},
-		6: {method: "HEAD", serverStatus: 302, wantMethod: "GET"},
-		7: {method: "HEAD", serverStatus: 303, wantMethod: "GET"},
+		5: {method: "HEAD", serverStatus: 301, wantMethod: "HEAD"},
+		6: {method: "HEAD", serverStatus: 302, wantMethod: "HEAD"},
+		7: {method: "HEAD", serverStatus: 303, wantMethod: "HEAD"},
 		8: {method: "HEAD", serverStatus: 307, wantMethod: "HEAD"},
 		9: {method: "HEAD", serverStatus: 308, wantMethod: "HEAD"},
 
diff --git a/src/net/http/h2_bundle.go b/src/net/http/h2_bundle.go
index 2e0b3c9..4536b2f 100644
--- a/src/net/http/h2_bundle.go
+++ b/src/net/http/h2_bundle.go
@@ -3141,6 +3141,10 @@ func (s *http2Server) ServeConn(c net.Conn, opts *http2ServeConnOpts) {
 		pushEnabled:       true,
 	}
 
+	if sc.hs.WriteTimeout != 0 {
+		sc.conn.SetWriteDeadline(time.Time{})
+	}
+
 	if s.NewWriteScheduler != nil {
 		sc.writeSched = s.NewWriteScheduler()
 	} else {
diff --git a/src/net/http/httputil/dump.go b/src/net/http/httputil/dump.go
index 1511681..7104c37 100644
--- a/src/net/http/httputil/dump.go
+++ b/src/net/http/httputil/dump.go
@@ -18,11 +18,16 @@ import (
 	"time"
 )
 
-// One of the copies, say from b to r2, could be avoided by using a more
-// elaborate trick where the other copy is made during Request/Response.Write.
-// This would complicate things too much, given that these functions are for
-// debugging only.
+// drainBody reads all of b to memory and then returns two equivalent
+// ReadClosers yielding the same bytes.
+//
+// It returns an error if the initial slurp of all bytes fails. It does not attempt
+// to make the returned ReadClosers have identical error-matching behavior.
 func drainBody(b io.ReadCloser) (r1, r2 io.ReadCloser, err error) {
+	if b == http.NoBody {
+		// No copying needed. Preserve the magic sentinel meaning of NoBody.
+		return http.NoBody, http.NoBody, nil
+	}
 	var buf bytes.Buffer
 	if _, err = buf.ReadFrom(b); err != nil {
 		return nil, b, err
diff --git a/src/net/http/httputil/dump_test.go b/src/net/http/httputil/dump_test.go
index 2e980d3..f881020 100644
--- a/src/net/http/httputil/dump_test.go
+++ b/src/net/http/httputil/dump_test.go
@@ -184,6 +184,18 @@ var dumpTests = []dumpTest{
 		WantDump: "POST /v2/api/?login HTTP/1.1\r\n" +
 			"Host: passport.myhost.com\r\n\r\n",
 	},
+
+	// Issue 18506: make drainBody recognize NoBody. Otherwise
+	// this was turning into a chunked request.
+	{
+		Req: *mustNewRequest("POST", "http://example.com/foo", http.NoBody),
+
+		WantDumpOut: "POST /foo HTTP/1.1\r\n" +
+			"Host: example.com\r\n" +
+			"User-Agent: Go-http-client/1.1\r\n" +
+			"Content-Length: 0\r\n" +
+			"Accept-Encoding: gzip\r\n\r\n",
+	},
 }
 
 func TestDumpRequest(t *testing.T) {
diff --git a/src/net/http/httputil/reverseproxy.go b/src/net/http/httputil/reverseproxy.go
index 7867505..79c8fe2 100644
--- a/src/net/http/httputil/reverseproxy.go
+++ b/src/net/http/httputil/reverseproxy.go
@@ -30,6 +30,8 @@ type ReverseProxy struct {
 	// the request into a new request to be sent
 	// using Transport. Its response is then copied
 	// back to the original client unmodified.
+	// Director must not access the provided Request
+	// after returning.
 	Director func(*http.Request)
 
 	// The transport used to perform proxy requests.
diff --git a/src/net/http/request.go b/src/net/http/request.go
index 96fa619..fb6bb0a 100644
--- a/src/net/http/request.go
+++ b/src/net/http/request.go
@@ -341,6 +341,18 @@ func (r *Request) ProtoAtLeast(major, minor int) bool {
 		r.ProtoMajor == major && r.ProtoMinor >= minor
 }
 
+// protoAtLeastOutgoing is like ProtoAtLeast, but is for outgoing
+// requests (see issue 18407) where these fields aren't supposed to
+// matter.  As a minor fix for Go 1.8, at least treat (0, 0) as
+// matching HTTP/1.1 or HTTP/1.0.  Only HTTP/1.1 is used.
+// TODO(bradfitz): ideally remove this whole method. It shouldn't be used.
+func (r *Request) protoAtLeastOutgoing(major, minor int) bool {
+	if r.ProtoMajor == 0 && r.ProtoMinor == 0 && major == 1 && minor <= 1 {
+		return true
+	}
+	return r.ProtoAtLeast(major, minor)
+}
+
 // UserAgent returns the client's User-Agent, if sent in the request.
 func (r *Request) UserAgent() string {
 	return r.Header.Get("User-Agent")
@@ -600,6 +612,12 @@ func (req *Request) write(w io.Writer, usingProxy bool, extraHeaders Header, wai
 		}
 	}
 
+	if bw, ok := w.(*bufio.Writer); ok && tw.FlushHeaders {
+		if err := bw.Flush(); err != nil {
+			return err
+		}
+	}
+
 	// Write body and trailer
 	err = tw.WriteBody(w)
 	if err != nil {
@@ -731,6 +749,12 @@ func validMethod(method string) bool {
 // net/http/httptest package, use ReadRequest, or manually update the
 // Request fields. See the Request type's documentation for the
 // difference between inbound and outbound request fields.
+//
+// If body is of type *bytes.Buffer, *bytes.Reader, or
+// *strings.Reader, the returned request's ContentLength is set to its
+// exact value (instead of -1), GetBody is populated (so 307 and 308
+// redirects can replay the body), and Body is set to NoBody if the
+// ContentLength is 0.
 func NewRequest(method, urlStr string, body io.Reader) (*Request, error) {
 	if method == "" {
 		// We document that "" means "GET" for Request.Method, and people have
@@ -1293,3 +1317,18 @@ func (r *Request) outgoingLength() int64 {
 	}
 	return -1
 }
+
+// requestMethodUsuallyLacksBody reports whether the given request
+// method is one that typically does not involve a request body.
+// This is used by the Transport (via
+// transferWriter.shouldSendChunkedRequestBody) to determine whether
+// we try to test-read a byte from a non-nil Request.Body when
+// Request.outgoingLength() returns -1. See the comments in
+// shouldSendChunkedRequestBody.
+func requestMethodUsuallyLacksBody(method string) bool {
+	switch method {
+	case "GET", "HEAD", "DELETE", "OPTIONS", "PROPFIND", "SEARCH":
+		return true
+	}
+	return false
+}
diff --git a/src/net/http/requestwrite_test.go b/src/net/http/requestwrite_test.go
index c398e64..eb65b9f 100644
--- a/src/net/http/requestwrite_test.go
+++ b/src/net/http/requestwrite_test.go
@@ -5,14 +5,17 @@
 package http
 
 import (
+	"bufio"
 	"bytes"
 	"errors"
 	"fmt"
 	"io"
 	"io/ioutil"
+	"net"
 	"net/url"
 	"strings"
 	"testing"
+	"time"
 )
 
 type reqWriteTest struct {
@@ -566,6 +569,138 @@ func TestRequestWrite(t *testing.T) {
 	}
 }
 
+func TestRequestWriteTransport(t *testing.T) {
+	t.Parallel()
+
+	matchSubstr := func(substr string) func(string) error {
+		return func(written string) error {
+			if !strings.Contains(written, substr) {
+				return fmt.Errorf("expected substring %q in request: %s", substr, written)
+			}
+			return nil
+		}
+	}
+
+	noContentLengthOrTransferEncoding := func(req string) error {
+		if strings.Contains(req, "Content-Length: ") {
+			return fmt.Errorf("unexpected Content-Length in request: %s", req)
+		}
+		if strings.Contains(req, "Transfer-Encoding: ") {
+			return fmt.Errorf("unexpected Transfer-Encoding in request: %s", req)
+		}
+		return nil
+	}
+
+	all := func(checks ...func(string) error) func(string) error {
+		return func(req string) error {
+			for _, c := range checks {
+				if err := c(req); err != nil {
+					return err
+				}
+			}
+			return nil
+		}
+	}
+
+	type testCase struct {
+		method string
+		clen   int64 // ContentLength
+		body   io.ReadCloser
+		want   func(string) error
+
+		// optional:
+		init         func(*testCase)
+		afterReqRead func()
+	}
+
+	tests := []testCase{
+		{
+			method: "GET",
+			want:   noContentLengthOrTransferEncoding,
+		},
+		{
+			method: "GET",
+			body:   ioutil.NopCloser(strings.NewReader("")),
+			want:   noContentLengthOrTransferEncoding,
+		},
+		{
+			method: "GET",
+			clen:   -1,
+			body:   ioutil.NopCloser(strings.NewReader("")),
+			want:   noContentLengthOrTransferEncoding,
+		},
+		// A GET with a body, with explicit content length:
+		{
+			method: "GET",
+			clen:   7,
+			body:   ioutil.NopCloser(strings.NewReader("foobody")),
+			want: all(matchSubstr("Content-Length: 7"),
+				matchSubstr("foobody")),
+		},
+		// A GET with a body, sniffing the leading "f" from "foobody".
+		{
+			method: "GET",
+			clen:   -1,
+			body:   ioutil.NopCloser(strings.NewReader("foobody")),
+			want: all(matchSubstr("Transfer-Encoding: chunked"),
+				matchSubstr("\r\n1\r\nf\r\n"),
+				matchSubstr("oobody")),
+		},
+		// But a POST request is expected to have a body, so
+		// no sniffing happens:
+		{
+			method: "POST",
+			clen:   -1,
+			body:   ioutil.NopCloser(strings.NewReader("foobody")),
+			want: all(matchSubstr("Transfer-Encoding: chunked"),
+				matchSubstr("foobody")),
+		},
+		{
+			method: "POST",
+			clen:   -1,
+			body:   ioutil.NopCloser(strings.NewReader("")),
+			want:   all(matchSubstr("Transfer-Encoding: chunked")),
+		},
+		// Verify that a blocking Request.Body doesn't block forever.
+		{
+			method: "GET",
+			clen:   -1,
+			init: func(tt *testCase) {
+				pr, pw := io.Pipe()
+				tt.afterReqRead = func() {
+					pw.Close()
+				}
+				tt.body = ioutil.NopCloser(pr)
+			},
+			want: matchSubstr("Transfer-Encoding: chunked"),
+		},
+	}
+
+	for i, tt := range tests {
+		if tt.init != nil {
+			tt.init(&tt)
+		}
+		req := &Request{
+			Method: tt.method,
+			URL: &url.URL{
+				Scheme: "http",
+				Host:   "example.com",
+			},
+			Header:        make(Header),
+			ContentLength: tt.clen,
+			Body:          tt.body,
+		}
+		got, err := dumpRequestOut(req, tt.afterReqRead)
+		if err != nil {
+			t.Errorf("test[%d]: %v", i, err)
+			continue
+		}
+		if err := tt.want(string(got)); err != nil {
+			t.Errorf("test[%d]: %v", i, err)
+		}
+	}
+}
+
 type closeChecker struct {
 	io.Reader
 	closed bool
@@ -672,3 +807,76 @@ func TestRequestWriteError(t *testing.T) {
 		t.Fatalf("writeCalls constant is outdated in test")
 	}
 }
+
+// dumpRequestOut is a modified copy of net/http/httputil.DumpRequestOut.
+// Unlike the original, this version doesn't mutate the req.Body and
+// try to restore it. It always dumps the whole body.
+// And it doesn't support https.
+func dumpRequestOut(req *Request, onReadHeaders func()) ([]byte, error) {
+
+	// Use the actual Transport code to record what we would send
+	// on the wire, but not using TCP.  Use a Transport with a
+	// custom dialer that returns a fake net.Conn that waits
+	// for the full input (and recording it), and then responds
+	// with a dummy response.
+	var buf bytes.Buffer // records the output
+	pr, pw := io.Pipe()
+	defer pr.Close()
+	defer pw.Close()
+	dr := &delegateReader{c: make(chan io.Reader)}
+
+	t := &Transport{
+		Dial: func(net, addr string) (net.Conn, error) {
+			return &dumpConn{io.MultiWriter(&buf, pw), dr}, nil
+		},
+	}
+	defer t.CloseIdleConnections()
+
+	// Wait for the request before replying with a dummy response:
+	go func() {
+		req, err := ReadRequest(bufio.NewReader(pr))
+		if err == nil {
+			if onReadHeaders != nil {
+				onReadHeaders()
+			}
+			// Ensure all the body is read; otherwise
+			// we'll get a partial dump.
+			io.Copy(ioutil.Discard, req.Body)
+			req.Body.Close()
+		}
+		dr.c <- strings.NewReader("HTTP/1.1 204 No Content\r\nConnection: close\r\n\r\n")
+	}()
+
+	_, err := t.RoundTrip(req)
+	if err != nil {
+		return nil, err
+	}
+	return buf.Bytes(), nil
+}
+
+// delegateReader is a reader that delegates to another reader,
+// once it arrives on a channel.
+type delegateReader struct {
+	c chan io.Reader
+	r io.Reader // nil until received from c
+}
+
+func (r *delegateReader) Read(p []byte) (int, error) {
+	if r.r == nil {
+		r.r = <-r.c
+	}
+	return r.r.Read(p)
+}
+
+// dumpConn is a net.Conn that writes to Writer and reads from Reader.
+type dumpConn struct {
+	io.Writer
+	io.Reader
+}
+
+func (c *dumpConn) Close() error                       { return nil }
+func (c *dumpConn) LocalAddr() net.Addr                { return nil }
+func (c *dumpConn) RemoteAddr() net.Addr               { return nil }
+func (c *dumpConn) SetDeadline(t time.Time) error      { return nil }
+func (c *dumpConn) SetReadDeadline(t time.Time) error  { return nil }
+func (c *dumpConn) SetWriteDeadline(t time.Time) error { return nil }
diff --git a/src/net/http/serve_test.go b/src/net/http/serve_test.go
index 593b1f3..072da25 100644
--- a/src/net/http/serve_test.go
+++ b/src/net/http/serve_test.go
@@ -481,11 +481,11 @@ func TestServerTimeouts(t *testing.T) {
 	if err != nil {
 		t.Fatalf("http Get #1: %v", err)
 	}
-	got, _ := ioutil.ReadAll(r.Body)
+	got, err := ioutil.ReadAll(r.Body)
 	expected := "req=1"
-	if string(got) != expected {
-		t.Errorf("Unexpected response for request #1; got %q; expected %q",
-			string(got), expected)
+	if string(got) != expected || err != nil {
+		t.Errorf("Unexpected response for request #1; got %q ,%v; expected %q, nil",
+			string(got), err, expected)
 	}
 
 	// Slow client that should timeout.
@@ -496,6 +496,7 @@ func TestServerTimeouts(t *testing.T) {
 	}
 	buf := make([]byte, 1)
 	n, err := conn.Read(buf)
+	conn.Close()
 	latency := time.Since(t1)
 	if n != 0 || err != io.EOF {
 		t.Errorf("Read = %v, %v, wanted %v, %v", n, err, 0, io.EOF)
@@ -507,14 +508,14 @@ func TestServerTimeouts(t *testing.T) {
 	// Hit the HTTP server successfully again, verifying that the
 	// previous slow connection didn't run our handler.  (that we
 	// get "req=2", not "req=3")
-	r, err = Get(ts.URL)
+	r, err = c.Get(ts.URL)
 	if err != nil {
 		t.Fatalf("http Get #2: %v", err)
 	}
-	got, _ = ioutil.ReadAll(r.Body)
+	got, err = ioutil.ReadAll(r.Body)
 	expected = "req=2"
-	if string(got) != expected {
-		t.Errorf("Get #2 got %q, want %q", string(got), expected)
+	if string(got) != expected || err != nil {
+		t.Errorf("Get #2 got %q, %v, want %q, nil", string(got), err, expected)
 	}
 
 	if !testing.Short() {
@@ -534,6 +535,56 @@ func TestServerTimeouts(t *testing.T) {
 	}
 }
 
+// Test that the HTTP/2 server handles Server.WriteTimeout (Issue 18437)
+func TestHTTP2WriteDeadlineExtendedOnNewRequest(t *testing.T) {
+	if testing.Short() {
+		t.Skip("skipping in short mode")
+	}
+	setParallel(t)
+	defer afterTest(t)
+	ts := httptest.NewUnstartedServer(HandlerFunc(func(res ResponseWriter, req *Request) {}))
+	ts.Config.WriteTimeout = 250 * time.Millisecond
+	ts.TLS = &tls.Config{NextProtos: []string{"h2"}}
+	ts.StartTLS()
+	defer ts.Close()
+
+	tr := newTLSTransport(t, ts)
+	defer tr.CloseIdleConnections()
+	if err := ExportHttp2ConfigureTransport(tr); err != nil {
+		t.Fatal(err)
+	}
+	c := &Client{Transport: tr}
+
+	for i := 1; i <= 3; i++ {
+		req, err := NewRequest("GET", ts.URL, nil)
+		if err != nil {
+			t.Fatal(err)
+		}
+
+		// fail test if no response after 1 second
+		ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
+		defer cancel()
+		req = req.WithContext(ctx)
+
+		r, err := c.Do(req)
+		select {
+		case <-ctx.Done():
+			if ctx.Err() == context.DeadlineExceeded {
+				t.Fatalf("http2 Get #%d response timed out", i)
+			}
+		default:
+		}
+		if err != nil {
+			t.Fatalf("http2 Get #%d: %v", i, err)
+		}
+		r.Body.Close()
+		if r.ProtoMajor != 2 {
+			t.Fatalf("http2 Get expected HTTP/2.0, got %q", r.Proto)
+		}
+		time.Sleep(ts.Config.WriteTimeout / 2)
+	}
+}
+
 // golang.org/issue/4741 -- setting only a write timeout that triggers
 // shouldn't cause a handler to block forever on reads (next HTTP
 // request) that will never happen.
@@ -5038,3 +5089,87 @@ func testServerKeepAlivesEnabled(t *testing.T, h2 bool) {
 		t.Fatalf("test server has active conns")
 	}
 }
+
+// Issue 18447: test that the Server's ReadTimeout is stopped while
+// the server's doing its 1-byte background read between requests,
+// waiting for the connection to maybe close.
+func TestServerCancelsReadTimeoutWhenIdle(t *testing.T) {
+	setParallel(t)
+	defer afterTest(t)
+	const timeout = 250 * time.Millisecond
+	ts := httptest.NewUnstartedServer(HandlerFunc(func(w ResponseWriter, r *Request) {
+		select {
+		case <-time.After(2 * timeout):
+			fmt.Fprint(w, "ok")
+		case <-r.Context().Done():
+			fmt.Fprint(w, r.Context().Err())
+		}
+	}))
+	ts.Config.ReadTimeout = timeout
+	ts.Start()
+	defer ts.Close()
+
+	tr := &Transport{}
+	defer tr.CloseIdleConnections()
+	c := &Client{Transport: tr}
+
+	res, err := c.Get(ts.URL)
+	if err != nil {
+		t.Fatal(err)
+	}
+	slurp, err := ioutil.ReadAll(res.Body)
+	res.Body.Close()
+	if err != nil {
+		t.Fatal(err)
+	}
+	if string(slurp) != "ok" {
+		t.Fatalf("Got: %q, want ok", slurp)
+	}
+}
+
+// Issue 18535: test that the Server doesn't try to do a background
+// read if it's already done one.
+func TestServerDuplicateBackgroundRead(t *testing.T) {
+	setParallel(t)
+	defer afterTest(t)
+
+	const goroutines = 5
+	const requests = 2000
+
+	hts := httptest.NewServer(HandlerFunc(NotFound))
+	defer hts.Close()
+
+	reqBytes := []byte("GET / HTTP/1.1\r\nHost: e.com\r\n\r\n")
+
+	var wg sync.WaitGroup
+	for i := 0; i < goroutines; i++ {
+		wg.Add(1)
+		go func() {
+			defer wg.Done()
+			cn, err := net.Dial("tcp", hts.Listener.Addr().String())
+			if err != nil {
+				t.Error(err)
+				return
+			}
+			defer cn.Close()
+
+			wg.Add(1)
+			go func() {
+				defer wg.Done()
+				io.Copy(ioutil.Discard, cn)
+			}()
+
+			for j := 0; j < requests; j++ {
+				if t.Failed() {
+					return
+				}
+				_, err := cn.Write(reqBytes)
+				if err != nil {
+					t.Error(err)
+					return
+				}
+			}
+		}()
+	}
+	wg.Wait()
+}
diff --git a/src/net/http/server.go b/src/net/http/server.go
index 6df9c26..9623648 100644
--- a/src/net/http/server.go
+++ b/src/net/http/server.go
@@ -636,7 +636,11 @@ func (cr *connReader) startBackgroundRead() {
 	if cr.inRead {
 		panic("invalid concurrent Body.Read call")
 	}
+	if cr.hasByte {
+		return
+	}
 	cr.inRead = true
+	cr.conn.rwc.SetReadDeadline(time.Time{})
 	go cr.backgroundRead()
 }
 
diff --git a/src/net/http/transfer.go b/src/net/http/transfer.go
index beafb7a..4f47637 100644
--- a/src/net/http/transfer.go
+++ b/src/net/http/transfer.go
@@ -17,6 +17,7 @@ import (
 	"strconv"
 	"strings"
 	"sync"
+	"time"
 
 	"golang_org/x/net/lex/httplex"
 )
@@ -33,6 +34,23 @@ func (r errorReader) Read(p []byte) (n int, err error) {
 	return 0, r.err
 }
 
+type byteReader struct {
+	b    byte
+	done bool
+}
+
+func (br *byteReader) Read(p []byte) (n int, err error) {
+	if br.done {
+		return 0, io.EOF
+	}
+	if len(p) == 0 {
+		return 0, nil
+	}
+	br.done = true
+	p[0] = br.b
+	return 1, io.EOF
+}
+
 // transferWriter inspects the fields of a user-supplied Request or Response,
 // sanitizes them without changing the user object and provides methods for
 // writing the respective header, body and trailer in wire format.
@@ -46,6 +64,9 @@ type transferWriter struct {
 	TransferEncoding []string
 	Trailer          Header
 	IsResponse       bool
+
+	FlushHeaders bool            // flush headers to network before body
+	ByteReadCh   chan readResult // non-nil if probeRequestBody called
 }
 
 func newTransferWriter(r interface{}) (t *transferWriter, err error) {
@@ -62,14 +83,11 @@ func newTransferWriter(r interface{}) (t *transferWriter, err error) {
 		t.Close = rr.Close
 		t.TransferEncoding = rr.TransferEncoding
 		t.Trailer = rr.Trailer
-		atLeastHTTP11 = rr.ProtoAtLeast(1, 1)
-
+		atLeastHTTP11 = rr.protoAtLeastOutgoing(1, 1)
 		t.Body = rr.Body
+		t.BodyCloser = rr.Body
 		t.ContentLength = rr.outgoingLength()
-		if t.Body != nil {
-			t.BodyCloser = rr.Body
-		}
-		if t.ContentLength < 0 && len(t.TransferEncoding) == 0 && atLeastHTTP11 {
+		if t.ContentLength < 0 && len(t.TransferEncoding) == 0 && atLeastHTTP11 && t.shouldSendChunkedRequestBody() {
 			t.TransferEncoding = []string{"chunked"}
 		}
 	case *Response:
@@ -84,7 +102,7 @@ func newTransferWriter(r interface{}) (t *transferWriter, err error) {
 		t.TransferEncoding = rr.TransferEncoding
 		t.Trailer = rr.Trailer
 		atLeastHTTP11 = rr.ProtoAtLeast(1, 1)
-		t.ResponseToHEAD = noBodyExpected(t.Method)
+		t.ResponseToHEAD = noResponseBodyExpected(t.Method)
 	}
 
 	// Sanitize Body,ContentLength,TransferEncoding
@@ -112,7 +130,100 @@ func newTransferWriter(r interface{}) (t *transferWriter, err error) {
 	return t, nil
 }
 
-func noBodyExpected(requestMethod string) bool {
+// shouldSendChunkedRequestBody reports whether we should try to send a
+// chunked request body to the server. In particular, the case we really
+// want to prevent is sending a GET or other typically-bodyless request to a
+// server with a chunked body when the body has zero bytes, since GETs with
+// bodies (while acceptable according to specs), even zero-byte chunked
+// bodies, are approximately never seen in the wild and confuse most
+// servers. See Issue 18257, as one example.
+//
+// The only reason we'd send such a request is if the user set the Body to a
+// non-nil value (say, ioutil.NopCloser(bytes.NewReader(nil))) and didn't
+// set ContentLength, or NewRequest set it to -1 (unknown), so then we assume
+// there's bytes to send.
+//
+// This code tries to read a byte from the Request.Body in such cases to see
+// whether the body actually has content (super rare) or is actually just
+// a non-nil content-less ReadCloser (the more common case). In that more
+// common case, we act as if their Body were nil instead, and don't send
+// a body.
+func (t *transferWriter) shouldSendChunkedRequestBody() bool {
+	// Note that t.ContentLength is the corrected content length
+	// from rr.outgoingLength, so 0 actually means zero, not unknown.
+	if t.ContentLength >= 0 || t.Body == nil { // redundant checks; caller did them
+		return false
+	}
+	if requestMethodUsuallyLacksBody(t.Method) {
+		// Only probe the Request.Body for GET/HEAD/DELETE/etc
+		// requests, because it's only those types of requests
+		// that confuse servers.
+		t.probeRequestBody() // adjusts t.Body, t.ContentLength
+		return t.Body != nil
+	}
+	// For all other request types (PUT, POST, PATCH, or anything
+	// made-up we've never heard of), assume it's normal and the server
+	// can deal with a chunked request body. Maybe we'll adjust this
+	// later.
+	return true
+}
+
+// probeRequestBody reads a byte from t.Body to see whether it's empty
+// (returns io.EOF right away).
+//
+// But because we've had problems with this blocking users in the past
+// (issue 17480) when the body is a pipe (perhaps waiting on the response
+// headers before the pipe is fed data), we need to be careful and bound how
+// long we wait for it. This delay will only affect users if all the following
+// are true:
+//   * the request body blocks
+//   * the content length is not set (or set to -1)
+//   * the method doesn't usually have a body (GET, HEAD, DELETE, ...)
+//   * there is no transfer-encoding=chunked already set.
+// In other words, this delay will not normally affect anybody, and there
+// are workarounds if it does.
+func (t *transferWriter) probeRequestBody() {
+	t.ByteReadCh = make(chan readResult, 1)
+	go func(body io.Reader) {
+		var buf [1]byte
+		var rres readResult
+		rres.n, rres.err = body.Read(buf[:])
+		if rres.n == 1 {
+			rres.b = buf[0]
+		}
+		t.ByteReadCh <- rres
+	}(t.Body)
+	timer := time.NewTimer(200 * time.Millisecond)
+	select {
+	case rres := <-t.ByteReadCh:
+		timer.Stop()
+		if rres.n == 0 && rres.err == io.EOF {
+			// It was empty.
+			t.Body = nil
+			t.ContentLength = 0
+		} else if rres.n == 1 {
+			if rres.err != nil {
+				t.Body = io.MultiReader(&byteReader{b: rres.b}, errorReader{rres.err})
+			} else {
+				t.Body = io.MultiReader(&byteReader{b: rres.b}, t.Body)
+			}
+		} else if rres.err != nil {
+			t.Body = errorReader{rres.err}
+		}
+	case <-timer.C:
+		// Too slow. Don't wait. Read it later, and keep
+		// assuming that this is ContentLength == -1
+		// (unknown), which means we'll send a
+		// "Transfer-Encoding: chunked" header.
+		t.Body = io.MultiReader(finishAsyncByteRead{t}, t.Body)
+		// Request that Request.Write flush the headers to the
+		// network before writing the body, since our body may not
+		// become readable until it's seen the response headers.
+		t.FlushHeaders = true
+	}
+}
+
+func noResponseBodyExpected(requestMethod string) bool {
 	return requestMethod == "HEAD"
 }
 
@@ -216,7 +327,9 @@ func (t *transferWriter) WriteBody(w io.Writer) error {
 		if err != nil {
 			return err
 		}
-		if err = t.BodyCloser.Close(); err != nil {
+	}
+	if t.BodyCloser != nil {
+		if err := t.BodyCloser.Close(); err != nil {
 			return err
 		}
 	}
@@ -366,7 +479,7 @@ func readTransfer(msg interface{}, r *bufio.Reader) (err error) {
 	// or close connection when finished, since multipart is not supported yet
 	switch {
 	case chunked(t.TransferEncoding):
-		if noBodyExpected(t.RequestMethod) {
+		if noResponseBodyExpected(t.RequestMethod) {
 			t.Body = NoBody
 		} else {
 			t.Body = &body{src: internal.NewChunkedReader(r), hdr: msg, r: r, closing: t.Close}
@@ -498,7 +611,7 @@ func fixLength(isResponse bool, status int, requestMethod string, header Header,
 	}
 
 	// Logic based on response type or status
-	if noBodyExpected(requestMethod) {
+	if noResponseBodyExpected(requestMethod) {
 		// For HTTP requests, as part of hardening against request
 		// smuggling (RFC 7230), don't allow a Content-Length header for
 		// methods which don't permit bodies. As an exception, allow
@@ -861,3 +974,21 @@ func parseContentLength(cl string) (int64, error) {
 	return n, nil
 
 }
+
+// finishAsyncByteRead finishes reading the 1-byte sniff
+// from the ContentLength==0, Body!=nil case.
+type finishAsyncByteRead struct {
+	tw *transferWriter
+}
+
+func (fr finishAsyncByteRead) Read(p []byte) (n int, err error) {
+	if len(p) == 0 {
+		return
+	}
+	rres := <-fr.tw.ByteReadCh
+	n, err = rres.n, rres.err
+	if n == 1 {
+		p[0] = rres.b
+	}
+	return
+}
diff --git a/src/net/http/transport_test.go b/src/net/http/transport_test.go
index 5a40265..d5ddf6a 100644
--- a/src/net/http/transport_test.go
+++ b/src/net/http/transport_test.go
@@ -1083,8 +1083,10 @@ func waitNumGoroutine(nmax int) int {
 func TestTransportPersistConnLeak(t *testing.T) {
 	// Not parallel: counts goroutines
 	defer afterTest(t)
-	gotReqCh := make(chan bool)
-	unblockCh := make(chan bool)
+
+	const numReq = 25
+	gotReqCh := make(chan bool, numReq)
+	unblockCh := make(chan bool, numReq)
 	ts := httptest.NewServer(HandlerFunc(func(w ResponseWriter, r *Request) {
 		gotReqCh <- true
 		<-unblockCh
@@ -1098,14 +1100,15 @@ func TestTransportPersistConnLeak(t *testing.T) {
 
 	n0 := runtime.NumGoroutine()
 
-	const numReq = 25
-	didReqCh := make(chan bool)
+	didReqCh := make(chan bool, numReq)
+	failed := make(chan bool, numReq)
 	for i := 0; i < numReq; i++ {
 		go func() {
 			res, err := c.Get(ts.URL)
 			didReqCh <- true
 			if err != nil {
 				t.Errorf("client fetch error: %v", err)
+				failed <- true
 				return
 			}
 			res.Body.Close()
@@ -1114,7 +1117,13 @@ func TestTransportPersistConnLeak(t *testing.T) {
 
 	// Wait for all goroutines to be stuck in the Handler.
 	for i := 0; i < numReq; i++ {
-		<-gotReqCh
+		select {
+		case <-gotReqCh:
+			// ok
+		case <-failed:
+			close(unblockCh)
+			return
+		}
 	}
 
 	nhigh := runtime.NumGoroutine()
diff --git a/src/net/interface.go b/src/net/interface.go
index 301a5cf..b3297f2 100644
--- a/src/net/interface.go
+++ b/src/net/interface.go
@@ -172,6 +172,9 @@ func InterfaceByName(name string) (*Interface, error) {
 // An ipv6ZoneCache represents a cache holding partial network
 // interface information. It is used for reducing the cost of IPv6
 // addressing scope zone resolution.
+//
+// Multiple names sharing the index are managed by first-come
+// first-served basis for consistency.
 type ipv6ZoneCache struct {
 	sync.RWMutex                // guard the following
 	lastFetched  time.Time      // last time routing information was fetched
@@ -202,7 +205,9 @@ func (zc *ipv6ZoneCache) update(ift []Interface) {
 	zc.toName = make(map[int]string, len(ift))
 	for _, ifi := range ift {
 		zc.toIndex[ifi.Name] = ifi.Index
-		zc.toName[ifi.Index] = ifi.Name
+		if _, ok := zc.toName[ifi.Index]; !ok {
+			zc.toName[ifi.Index] = ifi.Name
+		}
 	}
 }
 
diff --git a/src/net/ip.go b/src/net/ip.go
index 4a7774a..db3364c 100644
--- a/src/net/ip.go
+++ b/src/net/ip.go
@@ -153,6 +153,12 @@ func (ip IP) IsLinkLocalUnicast() bool {
 
 // IsGlobalUnicast reports whether ip is a global unicast
 // address.
+//
+// The identification of global unicast addresses uses address type
+// identification as defined in RFC 1122, RFC 4632 and RFC 4291 with
+// the exception of IPv4 directed broadcast addresses.
+// It returns true even if ip is in IPv4 private address space or
+// local IPv6 unicast address space.
 func (ip IP) IsGlobalUnicast() bool {
 	return (len(ip) == IPv4len || len(ip) == IPv6len) &&
 		!ip.Equal(IPv4bcast) &&
diff --git a/src/net/iprawsock.go b/src/net/iprawsock.go
index b3cc03e..d994fc6 100644
--- a/src/net/iprawsock.go
+++ b/src/net/iprawsock.go
@@ -9,6 +9,18 @@ import (
 	"syscall"
 )
 
+// BUG(mikio): On every POSIX platform, reads from the "ip4" network
+// using the ReadFrom or ReadFromIP method might not return a complete
+// IPv4 packet, including its header, even if there is space
+// available. This can occur even in cases where Read or ReadMsgIP
+// could return a complete packet. For this reason, it is recommended
+// that you do not use these methods if it is important to receive a
+// full packet.
+//
+// The Go 1 compatibility guidelines make it impossible for us to
+// change the behavior of these methods; use Read or ReadMsgIP
+// instead.
+
 // BUG(mikio): On NaCl, Plan 9 and Windows, the ReadMsgIP and
 // WriteMsgIP methods of IPConn are not implemented.
 
diff --git a/src/net/iprawsock_posix.go b/src/net/iprawsock_posix.go
index d5e229f..8f4b702 100644
--- a/src/net/iprawsock_posix.go
+++ b/src/net/iprawsock_posix.go
@@ -11,18 +11,6 @@ import (
 	"syscall"
 )
 
-// BUG(mikio): On every POSIX platform, reads from the "ip4" network
-// using the ReadFrom or ReadFromIP method might not return a complete
-// IPv4 packet, including its header, even if there is space
-// available. This can occur even in cases where Read or ReadMsgIP
-// could return a complete packet. For this reason, it is recommended
-// that you do not uses these methods if it is important to receive a
-// full packet.
-//
-// The Go 1 compatibility guidelines make it impossible for us to
-// change the behavior of these methods; use Read or ReadMsgIP
-// instead.
-
 func sockaddrToIP(sa syscall.Sockaddr) Addr {
 	switch sa := sa.(type) {
 	case *syscall.SockaddrInet4:
diff --git a/src/net/iprawsock_test.go b/src/net/iprawsock_test.go
index 29cd4b6..5d33b26 100644
--- a/src/net/iprawsock_test.go
+++ b/src/net/iprawsock_test.go
@@ -43,6 +43,13 @@ var resolveIPAddrTests = []resolveIPAddrTest{
 	{"l2tp", "127.0.0.1", nil, UnknownNetworkError("l2tp")},
 	{"l2tp:gre", "127.0.0.1", nil, UnknownNetworkError("l2tp:gre")},
 	{"tcp", "1.2.3.4:123", nil, UnknownNetworkError("tcp")},
+
+	{"ip4", "2001:db8::1", nil, &AddrError{Err: errNoSuitableAddress.Error(), Addr: "2001:db8::1"}},
+	{"ip4:icmp", "2001:db8::1", nil, &AddrError{Err: errNoSuitableAddress.Error(), Addr: "2001:db8::1"}},
+	{"ip6", "127.0.0.1", nil, &AddrError{Err: errNoSuitableAddress.Error(), Addr: "127.0.0.1"}},
+	{"ip6", "::ffff:127.0.0.1", nil, &AddrError{Err: errNoSuitableAddress.Error(), Addr: "::ffff:127.0.0.1"}},
+	{"ip6:ipv6-icmp", "127.0.0.1", nil, &AddrError{Err: errNoSuitableAddress.Error(), Addr: "127.0.0.1"}},
+	{"ip6:ipv6-icmp", "::ffff:127.0.0.1", nil, &AddrError{Err: errNoSuitableAddress.Error(), Addr: "::ffff:127.0.0.1"}},
 }
 
 func TestResolveIPAddr(t *testing.T) {
@@ -54,21 +61,17 @@ func TestResolveIPAddr(t *testing.T) {
 	defer func() { testHookLookupIP = origTestHookLookupIP }()
 	testHookLookupIP = lookupLocalhost
 
-	for i, tt := range resolveIPAddrTests {
+	for _, tt := range resolveIPAddrTests {
 		addr, err := ResolveIPAddr(tt.network, tt.litAddrOrName)
-		if err != tt.err {
-			t.Errorf("#%d: %v", i, err)
-		} else if !reflect.DeepEqual(addr, tt.addr) {
-			t.Errorf("#%d: got %#v; want %#v", i, addr, tt.addr)
-		}
-		if err != nil {
+		if !reflect.DeepEqual(addr, tt.addr) || !reflect.DeepEqual(err, tt.err) {
+			t.Errorf("ResolveIPAddr(%q, %q) = %#v, %v, want %#v, %v", tt.network, tt.litAddrOrName, addr, err, tt.addr, tt.err)
 			continue
 		}
-		rtaddr, err := ResolveIPAddr(addr.Network(), addr.String())
-		if err != nil {
-			t.Errorf("#%d: %v", i, err)
-		} else if !reflect.DeepEqual(rtaddr, addr) {
-			t.Errorf("#%d: got %#v; want %#v", i, rtaddr, addr)
+		if err == nil {
+			addr2, err := ResolveIPAddr(addr.Network(), addr.String())
+			if !reflect.DeepEqual(addr2, tt.addr) || err != tt.err {
+				t.Errorf("(%q, %q): ResolveIPAddr(%q, %q) = %#v, %v, want %#v, %v", tt.network, tt.litAddrOrName, addr.Network(), addr.String(), addr2, err, tt.addr, tt.err)
+			}
 		}
 	}
 }
diff --git a/src/net/ipsock.go b/src/net/ipsock.go
index c91e201..f1394a7 100644
--- a/src/net/ipsock.go
+++ b/src/net/ipsock.go
@@ -10,6 +10,13 @@ import (
 	"context"
 )
 
+// BUG(rsc,mikio): On DragonFly BSD and OpenBSD, listening on the
+// "tcp" and "udp" networks does not listen for both IPv4 and IPv6
+// connections. This is due to the fact that IPv4 traffic will not be
+// routed to an IPv6 socket - two separate sockets are required if
+// both address families are to be supported.
+// See inet6(4) for details.
+
 var (
 	// supportsIPv4 reports whether the platform supports IPv4
 	// networking functionality.
diff --git a/src/net/ipsock_posix.go b/src/net/ipsock_posix.go
index f4fab3f..ff280c3 100644
--- a/src/net/ipsock_posix.go
+++ b/src/net/ipsock_posix.go
@@ -12,13 +12,6 @@ import (
 	"syscall"
 )
 
-// BUG(rsc,mikio): On DragonFly BSD and OpenBSD, listening on the
-// "tcp" and "udp" networks does not listen for both IPv4 and IPv6
-// connections. This is due to the fact that IPv4 traffic will not be
-// routed to an IPv6 socket - two separate sockets are required if
-// both address families are to be supported.
-// See inet6(4) for details.
-
 func probeIPv4Stack() bool {
 	s, err := socketFunc(syscall.AF_INET, syscall.SOCK_STREAM, syscall.IPPROTO_TCP)
 	switch err {
diff --git a/src/net/lookup.go b/src/net/lookup.go
index 8b5cab0..cc2013e 100644
--- a/src/net/lookup.go
+++ b/src/net/lookup.go
@@ -233,20 +233,32 @@ func (r *Resolver) LookupPort(ctx context.Context, network, service string) (por
 	return port, nil
 }
 
-// LookupCNAME returns the canonical DNS host for the given name.
+// LookupCNAME returns the canonical name for the given host.
 // Callers that do not care about the canonical name can call
 // LookupHost or LookupIP directly; both take care of resolving
 // the canonical name as part of the lookup.
-func LookupCNAME(name string) (cname string, err error) {
-	return DefaultResolver.lookupCNAME(context.Background(), name)
+//
+// A canonical name is the final name after following zero
+// or more CNAME records.
+// LookupCNAME does not return an error if host does not
+// contain DNS "CNAME" records, as long as host resolves to
+// address records.
+func LookupCNAME(host string) (cname string, err error) {
+	return DefaultResolver.lookupCNAME(context.Background(), host)
 }
 
-// LookupCNAME returns the canonical DNS host for the given name.
+// LookupCNAME returns the canonical name for the given host.
 // Callers that do not care about the canonical name can call
 // LookupHost or LookupIP directly; both take care of resolving
 // the canonical name as part of the lookup.
-func (r *Resolver) LookupCNAME(ctx context.Context, name string) (cname string, err error) {
-	return r.lookupCNAME(ctx, name)
+//
+// A canonical name is the final name after following zero
+// or more CNAME records.
+// LookupCNAME does not return an error if host does not
+// contain DNS "CNAME" records, as long as host resolves to
+// address records.
+func (r *Resolver) LookupCNAME(ctx context.Context, host string) (cname string, err error) {
+	return r.lookupCNAME(ctx, host)
 }
 
 // LookupSRV tries to resolve an SRV query of the given service,
diff --git a/src/net/lookup_plan9.go b/src/net/lookup_plan9.go
index 11f2349..f81e220 100644
--- a/src/net/lookup_plan9.go
+++ b/src/net/lookup_plan9.go
@@ -198,6 +198,10 @@ func (*Resolver) lookupPort(ctx context.Context, network, service string) (port
 func (*Resolver) lookupCNAME(ctx context.Context, name string) (cname string, err error) {
 	lines, err := queryDNS(ctx, name, "cname")
 	if err != nil {
+		if stringsHasSuffix(err.Error(), "dns failure") {
+			cname = name + "."
+			err = nil
+		}
 		return
 	}
 	if len(lines) > 0 {
diff --git a/src/net/lookup_test.go b/src/net/lookup_test.go
index 656bebb..36db56a 100644
--- a/src/net/lookup_test.go
+++ b/src/net/lookup_test.go
@@ -243,14 +243,15 @@ func TestLookupIPv6LinkLocalAddr(t *testing.T) {
 	}
 }
 
-var lookupIANACNAMETests = []struct {
+var lookupCNAMETests = []struct {
 	name, cname string
 }{
 	{"www.iana.org", "icann.org."},
 	{"www.iana.org.", "icann.org."},
+	{"www.google.com", "google.com."},
 }
 
-func TestLookupIANACNAME(t *testing.T) {
+func TestLookupCNAME(t *testing.T) {
 	if testenv.Builder() == "" {
 		testenv.MustHaveExternalNetwork(t)
 	}
@@ -259,7 +260,7 @@ func TestLookupIANACNAME(t *testing.T) {
 		t.Skip("IPv4 is required")
 	}
 
-	for _, tt := range lookupIANACNAMETests {
+	for _, tt := range lookupCNAMETests {
 		cname, err := LookupCNAME(tt.name)
 		if err != nil {
 			t.Fatal(err)
diff --git a/src/net/lookup_unix.go b/src/net/lookup_unix.go
index 609adbf..be2ced9 100644
--- a/src/net/lookup_unix.go
+++ b/src/net/lookup_unix.go
@@ -72,7 +72,8 @@ func (r *Resolver) lookupIP(ctx context.Context, host string) (addrs []IPAddr, e
 		// cgo not available (or netgo); fall back to Go's DNS resolver
 		order = hostLookupFilesDNS
 	}
-	return goLookupIPOrder(ctx, host, order)
+	addrs, _, err = goLookupIPCNAMEOrder(ctx, host, order)
+	return
 }
 
 func (r *Resolver) lookupPort(ctx context.Context, network, service string) (int, error) {
diff --git a/src/net/lookup_windows_test.go b/src/net/lookup_windows_test.go
index bc9ffe1..cebb2d0 100644
--- a/src/net/lookup_windows_test.go
+++ b/src/net/lookup_windows_test.go
@@ -24,7 +24,7 @@ func toJson(v interface{}) string {
 	return string(data)
 }
 
-func TestLookupMX(t *testing.T) {
+func TestNSLookupMX(t *testing.T) {
 	testenv.MustHaveExternalNetwork(t)
 
 	for _, server := range nslookupTestServers {
@@ -49,7 +49,7 @@ func TestLookupMX(t *testing.T) {
 	}
 }
 
-func TestLookupCNAME(t *testing.T) {
+func TestNSLookupCNAME(t *testing.T) {
 	testenv.MustHaveExternalNetwork(t)
 
 	for _, server := range nslookupTestServers {
@@ -72,7 +72,7 @@ func TestLookupCNAME(t *testing.T) {
 	}
 }
 
-func TestLookupNS(t *testing.T) {
+func TestNSLookupNS(t *testing.T) {
 	testenv.MustHaveExternalNetwork(t)
 
 	for _, server := range nslookupTestServers {
@@ -98,7 +98,7 @@ func TestLookupNS(t *testing.T) {
 	}
 }
 
-func TestLookupTXT(t *testing.T) {
+func TestNSLookupTXT(t *testing.T) {
 	testenv.MustHaveExternalNetwork(t)
 
 	for _, server := range nslookupTestServers {
diff --git a/src/net/tcpsock_test.go b/src/net/tcpsock_test.go
index 573e834..54bf0cf 100644
--- a/src/net/tcpsock_test.go
+++ b/src/net/tcpsock_test.go
@@ -317,10 +317,11 @@ var resolveTCPAddrTests = []resolveTCPAddrTest{
 	{"tcp", "[2001:db8::1]:http", &TCPAddr{IP: ParseIP("2001:db8::1"), Port: 80}, nil},
 	{"tcp4", "127.0.0.1:http", &TCPAddr{IP: ParseIP("127.0.0.1"), Port: 80}, nil},
 	{"tcp4", "[::ffff:127.0.0.1]:http", &TCPAddr{IP: ParseIP("127.0.0.1"), Port: 80}, nil},
+	{"tcp6", "[2001:db8::1]:http", &TCPAddr{IP: ParseIP("2001:db8::1"), Port: 80}, nil},
+
 	{"tcp4", "[2001:db8::1]:http", nil, &AddrError{Err: errNoSuitableAddress.Error(), Addr: "2001:db8::1"}},
 	{"tcp6", "127.0.0.1:http", nil, &AddrError{Err: errNoSuitableAddress.Error(), Addr: "127.0.0.1"}},
 	{"tcp6", "[::ffff:127.0.0.1]:http", nil, &AddrError{Err: errNoSuitableAddress.Error(), Addr: "::ffff:127.0.0.1"}},
-	{"tcp6", "[2001:db8::1]:http", &TCPAddr{IP: ParseIP("2001:db8::1"), Port: 80}, nil},
 }
 
 func TestResolveTCPAddr(t *testing.T) {
@@ -331,13 +332,13 @@ func TestResolveTCPAddr(t *testing.T) {
 	for _, tt := range resolveTCPAddrTests {
 		addr, err := ResolveTCPAddr(tt.network, tt.litAddrOrName)
 		if !reflect.DeepEqual(addr, tt.addr) || !reflect.DeepEqual(err, tt.err) {
-			t.Errorf("ResolveTCPAddr(%q, %q) = %v, %v, want %v, %v", tt.network, tt.litAddrOrName, addr, err, tt.addr, tt.err)
+			t.Errorf("ResolveTCPAddr(%q, %q) = %#v, %v, want %#v, %v", tt.network, tt.litAddrOrName, addr, err, tt.addr, tt.err)
 			continue
 		}
 		if err == nil {
 			addr2, err := ResolveTCPAddr(addr.Network(), addr.String())
 			if !reflect.DeepEqual(addr2, tt.addr) || err != tt.err {
-				t.Errorf("(%q, %q): ResolveTCPAddr(%q, %q) = %v, %v, want %v, %v", tt.network, tt.litAddrOrName, addr.Network(), addr.String(), addr2, err, tt.addr, tt.err)
+				t.Errorf("(%q, %q): ResolveTCPAddr(%q, %q) = %#v, %v, want %#v, %v", tt.network, tt.litAddrOrName, addr.Network(), addr.String(), addr2, err, tt.addr, tt.err)
 			}
 		}
 	}
diff --git a/src/net/udpsock_test.go b/src/net/udpsock_test.go
index 29d769c..708cc10 100644
--- a/src/net/udpsock_test.go
+++ b/src/net/udpsock_test.go
@@ -72,6 +72,17 @@ var resolveUDPAddrTests = []resolveUDPAddrTest{
 	{"udp", ":12345", &UDPAddr{Port: 12345}, nil},
 
 	{"http", "127.0.0.1:0", nil, UnknownNetworkError("http")},
+
+	{"udp", "127.0.0.1:domain", &UDPAddr{IP: ParseIP("127.0.0.1"), Port: 53}, nil},
+	{"udp", "[::ffff:127.0.0.1]:domain", &UDPAddr{IP: ParseIP("::ffff:127.0.0.1"), Port: 53}, nil},
+	{"udp", "[2001:db8::1]:domain", &UDPAddr{IP: ParseIP("2001:db8::1"), Port: 53}, nil},
+	{"udp4", "127.0.0.1:domain", &UDPAddr{IP: ParseIP("127.0.0.1"), Port: 53}, nil},
+	{"udp4", "[::ffff:127.0.0.1]:domain", &UDPAddr{IP: ParseIP("127.0.0.1"), Port: 53}, nil},
+	{"udp6", "[2001:db8::1]:domain", &UDPAddr{IP: ParseIP("2001:db8::1"), Port: 53}, nil},
+
+	{"udp4", "[2001:db8::1]:domain", nil, &AddrError{Err: errNoSuitableAddress.Error(), Addr: "2001:db8::1"}},
+	{"udp6", "127.0.0.1:domain", nil, &AddrError{Err: errNoSuitableAddress.Error(), Addr: "127.0.0.1"}},
+	{"udp6", "[::ffff:127.0.0.1]:domain", nil, &AddrError{Err: errNoSuitableAddress.Error(), Addr: "::ffff:127.0.0.1"}},
 }
 
 func TestResolveUDPAddr(t *testing.T) {
@@ -79,21 +90,17 @@ func TestResolveUDPAddr(t *testing.T) {
 	defer func() { testHookLookupIP = origTestHookLookupIP }()
 	testHookLookupIP = lookupLocalhost
 
-	for i, tt := range resolveUDPAddrTests {
+	for _, tt := range resolveUDPAddrTests {
 		addr, err := ResolveUDPAddr(tt.network, tt.litAddrOrName)
-		if err != tt.err {
-			t.Errorf("#%d: %v", i, err)
-		} else if !reflect.DeepEqual(addr, tt.addr) {
-			t.Errorf("#%d: got %#v; want %#v", i, addr, tt.addr)
-		}
-		if err != nil {
+		if !reflect.DeepEqual(addr, tt.addr) || !reflect.DeepEqual(err, tt.err) {
+			t.Errorf("ResolveUDPAddr(%q, %q) = %#v, %v, want %#v, %v", tt.network, tt.litAddrOrName, addr, err, tt.addr, tt.err)
 			continue
 		}
-		rtaddr, err := ResolveUDPAddr(addr.Network(), addr.String())
-		if err != nil {
-			t.Errorf("#%d: %v", i, err)
-		} else if !reflect.DeepEqual(rtaddr, addr) {
-			t.Errorf("#%d: got %#v; want %#v", i, rtaddr, addr)
+		if err == nil {
+			addr2, err := ResolveUDPAddr(addr.Network(), addr.String())
+			if !reflect.DeepEqual(addr2, tt.addr) || err != tt.err {
+				t.Errorf("(%q, %q): ResolveUDPAddr(%q, %q) = %#v, %v, want %#v, %v", tt.network, tt.litAddrOrName, addr.Network(), addr.String(), addr2, err, tt.addr, tt.err)
+			}
 		}
 	}
 }
diff --git a/src/os/user/user.go b/src/os/user/user.go
index 7b44397..ad61992 100644
--- a/src/os/user/user.go
+++ b/src/os/user/user.go
@@ -15,31 +15,39 @@ var (
 )
 
 // User represents a user account.
-//
-// On POSIX systems Uid and Gid contain a decimal number
-// representing uid and gid. On windows Uid and Gid
-// contain security identifier (SID) in a string format.
-// On Plan 9, Uid, Gid, Username, and Name will be the
-// contents of /dev/user.
 type User struct {
-	Uid      string // user ID
-	Gid      string // primary group ID
+	// Uid is the user ID.
+	// On POSIX systems, this is a decimal number representing the uid.
+	// On Windows, this is a security identifier (SID) in a string format.
+	// On Plan 9, this is the contents of /dev/user.
+	Uid string
+	// Gid is the primary group ID.
+	// On POSIX systems, this is a decimal number representing the gid.
+	// On Windows, this is a SID in a string format.
+	// On Plan 9, this is the contents of /dev/user.
+	Gid string
+	// Username is the login name.
 	Username string
-	Name     string
-	HomeDir  string
+	// Name is the user's real or display name.
+	// It might be blank.
+	// On POSIX systems, this is the first (or only) entry in the GECOS field
+	// list.
+	// On Windows, this is the user's display name.
+	// On Plan 9, this is the contents of /dev/user.
+	Name string
+	// HomeDir is the path to the user's home directory (if they have one).
+	HomeDir string
 }
 
 // Group represents a grouping of users.
 //
-// On POSIX systems Gid contains a decimal number
-// representing the group ID.
+// On POSIX systems Gid contains a decimal number representing the group ID.
 type Group struct {
 	Gid  string // group ID
 	Name string // group name
 }
 
-// UnknownUserIdError is returned by LookupId when
-// a user cannot be found.
+// UnknownUserIdError is returned by LookupId when a user cannot be found.
 type UnknownUserIdError int
 
 func (e UnknownUserIdError) Error() string {
diff --git a/src/path/filepath/path_plan9.go b/src/path/filepath/path_plan9.go
index 60d46d9..ec792fc 100644
--- a/src/path/filepath/path_plan9.go
+++ b/src/path/filepath/path_plan9.go
@@ -18,6 +18,9 @@ func volumeNameLen(path string) int {
 }
 
 // HasPrefix exists for historical compatibility and should not be used.
+//
+// Deprecated: HasPrefix does not respect path boundaries and
+// does not ignore case when required.
 func HasPrefix(p, prefix string) bool {
 	return strings.HasPrefix(p, prefix)
 }
diff --git a/src/path/filepath/path_unix.go b/src/path/filepath/path_unix.go
index dddcac0..d77ff24 100644
--- a/src/path/filepath/path_unix.go
+++ b/src/path/filepath/path_unix.go
@@ -21,7 +21,8 @@ func volumeNameLen(path string) int {
 
 // HasPrefix exists for historical compatibility and should not be used.
 //
-// Deprecated: Use strings.HasPrefix instead.
+// Deprecated: HasPrefix does not respect path boundaries and
+// does not ignore case when required.
 func HasPrefix(p, prefix string) bool {
 	return strings.HasPrefix(p, prefix)
 }
diff --git a/src/path/filepath/path_windows.go b/src/path/filepath/path_windows.go
index 359703d..0d8b620 100644
--- a/src/path/filepath/path_windows.go
+++ b/src/path/filepath/path_windows.go
@@ -65,6 +65,9 @@ func volumeNameLen(path string) int {
 }
 
 // HasPrefix exists for historical compatibility and should not be used.
+//
+// Deprecated: HasPrefix does not respect path boundaries and
+// does not ignore case when required.
 func HasPrefix(p, prefix string) bool {
 	if strings.HasPrefix(p, prefix) {
 		return true
diff --git a/src/path/filepath/symlink_windows.go b/src/path/filepath/symlink_windows.go
index bb05aab..f771fe3 100644
--- a/src/path/filepath/symlink_windows.go
+++ b/src/path/filepath/symlink_windows.go
@@ -47,7 +47,7 @@ func baseIsDotDot(path string) bool {
 	return path[i+1:] == ".."
 }
 
-// toNorm returns the normalized path that is guranteed to be unique.
+// toNorm returns the normalized path that is guaranteed to be unique.
 // It should accept the following formats:
 //   * UNC paths                              (e.g \\server\share\foo\bar)
 //   * absolute paths                         (e.g C:\foo\bar)
diff --git a/src/reflect/makefunc.go b/src/reflect/makefunc.go
index a7efeb8..885966d 100644
--- a/src/reflect/makefunc.go
+++ b/src/reflect/makefunc.go
@@ -12,9 +12,12 @@ import (
 
 // makeFuncImpl is the closure value implementing the function
 // returned by MakeFunc.
+// The first two words of this type must be kept in sync with
+// methodValue and runtime.reflectMethodValue.
+// Any changes should be reflected in all three.
 type makeFuncImpl struct {
 	code  uintptr
-	stack *bitVector // stack bitmap for args - offset known to runtime
+	stack *bitVector
 	typ   *funcType
 	fn    func([]Value) []Value
 }
@@ -70,11 +73,12 @@ func MakeFunc(typ Type, fn func(args []Value) (results []Value)) Value {
 // word in the passed-in argument frame.
 func makeFuncStub()
 
-// This type is partially duplicated as runtime.reflectMethodValue.
-// Any changes should be reflected in both.
+// The first two words of this type must be kept in sync with
+// makeFuncImpl and runtime.reflectMethodValue.
+// Any changes should be reflected in all three.
 type methodValue struct {
 	fn     uintptr
-	stack  *bitVector // stack bitmap for args - offset known to runtime
+	stack  *bitVector
 	method int
 	rcvr   Value
 }
diff --git a/src/runtime/HACKING.md b/src/runtime/HACKING.md
index 88fb708..ea7c5c1 100644
--- a/src/runtime/HACKING.md
+++ b/src/runtime/HACKING.md
@@ -1,6 +1,139 @@
-This is a very incomplete and probably out-of-date guide to
-programming in the Go runtime and how it differs from writing normal
-Go.
+This is a living document and at times it will be out of date. It is
+intended to articulate how programming in the Go runtime differs from
+writing normal Go. It focuses on pervasive concepts rather than
+details of particular interfaces.
+
+Scheduler structures
+====================
+
+The scheduler manages three types of resources that pervade the
+runtime: Gs, Ms, and Ps. It's important to understand these even if
+you're not working on the scheduler.
+
+Gs, Ms, Ps
+----------
+
+A "G" is simply a goroutine. It's represented by type `g`. When a
+goroutine exits, its `g` object is returned to a pool of free `g`s and
+can later be reused for some other goroutine.
+
+An "M" is an OS thread that can be executing user Go code, runtime
+code, a system call, or be idle. It's represented by type `m`. There
+can be any number of Ms at a time since any number of threads may be
+blocked in system calls.
+
+Finally, a "P" represents the resources required to execute user Go
+code, such as scheduler and memory allocator state. It's represented
+by type `p`. There are exactly `GOMAXPROCS` Ps. A P can be thought of
+like a CPU in the OS scheduler and the contents of the `p` type like
+per-CPU state. This is a good place to put state that needs to be
+sharded for efficiency, but doesn't need to be per-thread or
+per-goroutine.
+
+The scheduler's job is to match up a G (the code to execute), an M
+(where to execute it), and a P (the rights and resources to execute
+it). When an M stops executing user Go code, for example by entering a
+system call, it returns its P to the idle P pool. In order to resume
+executing user Go code, for example on return from a system call, it
+must acquire a P from the idle pool.
+
+All `g`, `m`, and `p` objects are heap allocated, but are never freed,
+so their memory remains type stable. As a result, the runtime can
+avoid write barriers in the depths of the scheduler.
+
+User stacks and system stacks
+-----------------------------
+
+Every non-dead G has a *user stack* associated with it, which is what
+user Go code executes on. User stacks start small (e.g., 2K) and grow
+or shrink dynamically.
+
+Every M has a *system stack* associated with it (also known as the M's
+"g0" stack because it's implemented as a stub G) and, on Unix
+platforms, a *signal stack* (also known as the M's "gsignal" stack).
+System and signal stacks cannot grow, but are large enough to execute
+runtime and cgo code (8K in a pure Go binary; system-allocated in a
+cgo binary).
+
+Runtime code often temporarily switches to the system stack using
+`systemstack`, `mcall`, or `asmcgocall` to perform tasks that must not
+be preempted, that must not grow the user stack, or that switch user
+goroutines. Code running on the system stack is implicitly
+non-preemptible and the garbage collector does not scan system stacks.
+While running on the system stack, the current user stack is not used
+for execution.
+
+`getg()` and `getg().m.curg`
+----------------------------
+
+To get the current user `g`, use `getg().m.curg`.
+
+`getg()` alone returns the current `g`, but when executing on the
+system or signal stacks, this will return the current M's "g0" or
+"gsignal", respectively. This is usually not what you want.
+
+To determine if you're running on the user stack or the system stack,
+use `getg() == getg().m.curg`.
+
+Error handling and reporting
+============================
+
+Errors that can reasonably be recovered from in user code should use
+`panic` like usual. However, there are some situations where `panic`
+will cause an immediate fatal error, such as when called on the system
+stack or when called during `mallocgc`.
+
+Most errors in the runtime are not recoverable. For these, use
+`throw`, which dumps the traceback and immediately terminates the
+process. In general, `throw` should be passed a string constant to
+avoid allocating in perilous situations. By convention, additional
+details are printed before `throw` using `print` or `println` and the
+messages are prefixed with "runtime:".
+
+For runtime error debugging, it's useful to run with
+`GOTRACEBACK=system` or `GOTRACEBACK=crash`.
+
+Synchronization
+===============
+
+The runtime has multiple synchronization mechanisms. They differ in
+semantics and, in particular, in whether they interact with the
+goroutine scheduler or the OS scheduler.
+
+The simplest is `mutex`, which is manipulated using `lock` and
+`unlock`. This should be used to protect shared structures for short
+periods. Blocking on a `mutex` directly blocks the M, without
+interacting with the Go scheduler. This means it is safe to use from
+the lowest levels of the runtime, but also prevents any associated G
+and P from being rescheduled.
+
+For one-shot notifications, use `note`, which provides `notesleep` and
+`notewakeup`. Unlike traditional UNIX `sleep`/`wakeup`, `note`s are
+race-free, so `notesleep` returns immediately if the `notewakeup` has
+already happened. A `note` can be reset after use with `noteclear`,
+which must not race with a sleep or wakeup. Like `mutex`, blocking on
+a `note` blocks the M. However, there are different ways to sleep on a
+`note`:`notesleep` also prevents rescheduling of any associated G and
+P, while `notetsleepg` acts like a blocking system call that allows
+the P to be reused to run another G. This is still less efficient than
+blocking the G directly since it consumes an M.
+
+To interact directly with the goroutine scheduler, use `gopark` and
+`goready`. `gopark` parks the current goroutine—putting it in the
+"waiting" state and removing it from the scheduler's run queue—and
+schedules another goroutine on the current M/P. `goready` puts a
+parked goroutine back in the "runnable" state and adds it to the run
+queue.
+
+In summary,
+
+<table>
+<tr><th></th><th colspan="3">Blocks</th></tr>
+<tr><th>Interface</th><th>G</th><th>M</th><th>P</th></tr>
+<tr><td>mutex</td><td>Y</td><td>Y</td><td>Y</td></tr>
+<tr><td>note</td><td>Y</td><td>Y</td><td>Y/N</td></tr>
+<tr><td>park</td><td>Y</td><td>N</td><td>N</td></tr>
+</table>
 
 Unmanaged memory
 ================
diff --git a/src/runtime/asm_amd64.s b/src/runtime/asm_amd64.s
index 0070e9d..cb428d6 100644
--- a/src/runtime/asm_amd64.s
+++ b/src/runtime/asm_amd64.s
@@ -75,11 +75,24 @@ no7:
 	TESTL   $(1<<5), runtime·cpuid_ebx7(SB) // check for AVX2 bit
 	JEQ     noavx2
 	MOVB    $1, runtime·support_avx2(SB)
-	JMP     nocpuinfo
+	JMP     testbmi1
 noavx:
 	MOVB    $0, runtime·support_avx(SB)
 noavx2:
 	MOVB    $0, runtime·support_avx2(SB)
+testbmi1:
+	// Detect BMI1 and BMI2 extensions as per
+	// 5.1.16.1 Detection of VEX-encoded GPR Instructions,
+	//   LZCNT and TZCNT, PREFETCHW chapter of [1]
+	MOVB    $0, runtime·support_bmi1(SB)
+	TESTL   $(1<<3), runtime·cpuid_ebx7(SB) // check for BMI1 bit
+	JEQ     testbmi2
+	MOVB    $1, runtime·support_bmi1(SB)
+testbmi2:
+	MOVB    $0, runtime·support_bmi2(SB)
+	TESTL   $(1<<8), runtime·cpuid_ebx7(SB) // check for BMI2 bit
+	JEQ     nocpuinfo
+	MOVB    $1, runtime·support_bmi2(SB)
 nocpuinfo:	
 	
 	// if there is an _cgo_init, call it.
diff --git a/src/runtime/fastlog2.go b/src/runtime/fastlog2.go
index b22e825..5f3fb53 100644
--- a/src/runtime/fastlog2.go
+++ b/src/runtime/fastlog2.go
@@ -8,7 +8,7 @@ import "unsafe"
 
 // fastlog2 implements a fast approximation to the base 2 log of a
 // float64. This is used to compute a geometric distribution for heap
-// sampling, without introducing dependences into package math. This
+// sampling, without introducing dependencies into package math. This
 // uses a very rough approximation using the float64 exponent and the
 // first 25 bits of the mantissa. The top 5 bits of the mantissa are
 // used to load limits from a table of constants and the rest are used
@@ -29,5 +29,5 @@ func fastlog2(x float64) float64 {
 }
 
 // float64bits returns the IEEE 754 binary representation of f.
-// Taken from math.Float64bits to avoid dependences into package math.
+// Taken from math.Float64bits to avoid dependencies into package math.
 func float64bits(f float64) uint64 { return *(*uint64)(unsafe.Pointer(&f)) }
diff --git a/src/runtime/iface.go b/src/runtime/iface.go
index 18f5c58..46010d5 100644
--- a/src/runtime/iface.go
+++ b/src/runtime/iface.go
@@ -138,11 +138,8 @@ func additab(m *itab, locked, canfail bool) {
 		throw("invalid itab locking")
 	}
 	h := itabhash(inter, typ)
-	if m == hash[h] {
-		println("duplicate itab for", typ.string(), "and", inter.typ.string())
-		throw("duplicate itabs")
-	}
 	m.link = hash[h]
+	m.inhash = 1
 	atomicstorep(unsafe.Pointer(&hash[h]), unsafe.Pointer(m))
 }
 
@@ -150,7 +147,14 @@ func itabsinit() {
 	lock(&ifaceLock)
 	for _, md := range activeModules() {
 		for _, i := range md.itablinks {
-			additab(i, true, false)
+			// itablinks is a slice of pointers to the itabs used in this
+			// module. A given itab may be used in more than one module
+			// and thanks to the way global symbol resolution works, the
+			// pointed-to itab may already have been inserted into the
+			// global 'hash'.
+			if i.inhash == 0 {
+				additab(i, true, false)
+			}
 		}
 	}
 	unlock(&ifaceLock)
diff --git a/src/runtime/malloc.go b/src/runtime/malloc.go
index 1c9efc3..da39dac 100644
--- a/src/runtime/malloc.go
+++ b/src/runtime/malloc.go
@@ -157,6 +157,13 @@ const (
 	_MaxGcproc = 32
 
 	_MaxArena32 = 1<<32 - 1
+
+	// minLegalPointer is the smallest possible legal pointer.
+	// This is the smallest possible architectural page size,
+	// since we assume that the first page is never mapped.
+	//
+	// This should agree with minZeroPage in the compiler.
+	minLegalPointer uintptr = 4096
 )
 
 // physPageSize is the size in bytes of the OS's physical pages.
diff --git a/src/runtime/mgc.go b/src/runtime/mgc.go
index 0f0b096..64a2f3a 100644
--- a/src/runtime/mgc.go
+++ b/src/runtime/mgc.go
@@ -2,9 +2,6 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// TODO(rsc): The code having to do with the heap bitmap needs very serious cleanup.
-// It has gotten completely out of control.
-
 // Garbage collector (GC).
 //
 // The GC runs concurrently with mutator threads, is type accurate (aka precise), allows multiple
@@ -24,67 +21,73 @@
 // Hudson, R., and Moss, J.E.B. Copying Garbage Collection without stopping the world.
 // Concurrency and Computation: Practice and Experience 15(3-5), 2003.
 //
-// TODO(austin): The rest of this comment is woefully out of date and
-// needs to be rewritten. There is no distinct scan phase any more and
-// we allocate black during GC.
+// 1. GC performs sweep termination.
+//
+//    a. Stop the world. This causes all Ps to reach a GC safe-point.
+//
+//    b. Sweep any unswept spans. There will only be unswept spans if
+//    this GC cycle was forced before the expected time.
+//
+// 2. GC performs the "mark 1" sub-phase. In this sub-phase, Ps are
+// allowed to locally cache parts of the work queue.
+//
+//    a. Prepare for the mark phase by setting gcphase to _GCmark
+//    (from _GCoff), enabling the write barrier, enabling mutator
+//    assists, and enqueueing root mark jobs. No objects may be
+//    scanned until all Ps have enabled the write barrier, which is
+//    accomplished using STW.
+//
+//    b. Start the world. From this point, GC work is done by mark
+//    workers started by the scheduler and by assists performed as
+//    part of allocation. The write barrier shades both the
+//    overwritten pointer and the new pointer value for any pointer
+//    writes (see mbarrier.go for details). Newly allocated objects
+//    are immediately marked black.
+//
+//    c. GC performs root marking jobs. This includes scanning all
+//    stacks, shading all globals, and shading any heap pointers in
+//    off-heap runtime data structures. Scanning a stack stops a
+//    goroutine, shades any pointers found on its stack, and then
+//    resumes the goroutine.
+//
+//    d. GC drains the work queue of grey objects, scanning each grey
+//    object to black and shading all pointers found in the object
+//    (which in turn may add those pointers to the work queue).
+//
+// 3. Once the global work queue is empty (but local work queue caches
+// may still contain work), GC performs the "mark 2" sub-phase.
+//
+//    a. GC stops all workers, disables local work queue caches,
+//    flushes each P's local work queue cache to the global work queue
+//    cache, and reenables workers.
+//
+//    b. GC again drains the work queue, as in 2d above.
+//
+// 4. Once the work queue is empty, GC performs mark termination.
+//
+//    a. Stop the world.
+//
+//    b. Set gcphase to _GCmarktermination, and disable workers and
+//    assists.
+//
+//    c. Drain any remaining work from the work queue (typically there
+//    will be none).
+//
+//    d. Perform other housekeeping like flushing mcaches.
+//
+// 5. GC performs the sweep phase.
+//
+//    a. Prepare for the sweep phase by setting gcphase to _GCoff,
+//    setting up sweep state and disabling the write barrier.
+//
+//    b. Start the world. From this point on, newly allocated objects
+//    are white, and allocating sweeps spans before use if necessary.
+//
+//    c. GC does concurrent sweeping in the background and in response
+//    to allocation. See description below.
 //
-//  0. Set phase = GCscan from GCoff.
-//  1. Wait for all P's to acknowledge phase change.
-//         At this point all goroutines have passed through a GC safepoint and
-//         know we are in the GCscan phase.
-//  2. GC scans all goroutine stacks, mark and enqueues all encountered pointers
-//       (marking avoids most duplicate enqueuing but races may produce benign duplication).
-//       Preempted goroutines are scanned before P schedules next goroutine.
-//  3. Set phase = GCmark.
-//  4. Wait for all P's to acknowledge phase change.
-//  5. Now write barrier marks and enqueues black, grey, or white to white pointers.
-//       Malloc still allocates white (non-marked) objects.
-//  6. Meanwhile GC transitively walks the heap marking reachable objects.
-//  7. When GC finishes marking heap, it preempts P's one-by-one and
-//       retakes partial wbufs (filled by write barrier or during a stack scan of the goroutine
-//       currently scheduled on the P).
-//  8. Once the GC has exhausted all available marking work it sets phase = marktermination.
-//  9. Wait for all P's to acknowledge phase change.
-// 10. Malloc now allocates black objects, so number of unmarked reachable objects
-//        monotonically decreases.
-// 11. GC preempts P's one-by-one taking partial wbufs and marks all unmarked yet
-//        reachable objects.
-// 12. When GC completes a full cycle over P's and discovers no new grey
-//         objects, (which means all reachable objects are marked) set phase = GCoff.
-// 13. Wait for all P's to acknowledge phase change.
-// 14. Now malloc allocates white (but sweeps spans before use).
-//         Write barrier becomes nop.
-// 15. GC does background sweeping, see description below.
-// 16. When sufficient allocation has taken place replay the sequence starting at 0 above,
-//         see discussion of GC rate below.
-
-// Changing phases.
-// Phases are changed by setting the gcphase to the next phase and possibly calling ackgcphase.
-// All phase action must be benign in the presence of a change.
-// Starting with GCoff
-// GCoff to GCscan
-//     GSscan scans stacks and globals greying them and never marks an object black.
-//     Once all the P's are aware of the new phase they will scan gs on preemption.
-//     This means that the scanning of preempted gs can't start until all the Ps
-//     have acknowledged.
-//     When a stack is scanned, this phase also installs stack barriers to
-//     track how much of the stack has been active.
-//     This transition enables write barriers because stack barriers
-//     assume that writes to higher frames will be tracked by write
-//     barriers. Technically this only needs write barriers for writes
-//     to stack slots, but we enable write barriers in general.
-// GCscan to GCmark
-//     In GCmark, work buffers are drained until there are no more
-//     pointers to scan.
-//     No scanning of objects (making them black) can happen until all
-//     Ps have enabled the write barrier, but that already happened in
-//     the transition to GCscan.
-// GCmark to GCmarktermination
-//     The only change here is that we start allocating black so the Ps must acknowledge
-//     the change before we begin the termination algorithm
-// GCmarktermination to GSsweep
-//     Object currently on the freelist must be marked black for this to work.
-//     Are things on the free lists black or white? How does the sweep phase work?
+// 6. When sufficient allocation has taken place, replay the sequence
+// starting with 1 above. See discussion of GC rate below.
 
 // Concurrent sweep.
 //
diff --git a/src/runtime/mgcsweep.go b/src/runtime/mgcsweep.go
index e74a451..fb5c488 100644
--- a/src/runtime/mgcsweep.go
+++ b/src/runtime/mgcsweep.go
@@ -405,7 +405,10 @@ func reimburseSweepCredit(unusableBytes uintptr) {
 		// Nobody cares about the credit. Avoid the atomic.
 		return
 	}
-	if int64(atomic.Xadd64(&mheap_.spanBytesAlloc, -int64(unusableBytes))) < 0 {
+	nval := atomic.Xadd64(&mheap_.spanBytesAlloc, -int64(unusableBytes))
+	if int64(nval) < 0 {
+		// Debugging for #18043.
+		print("runtime: bad spanBytesAlloc=", nval, " (was ", nval+uint64(unusableBytes), ") unusableBytes=", unusableBytes, " sweepPagesPerByte=", mheap_.sweepPagesPerByte, "\n")
 		throw("spanBytesAlloc underflow")
 	}
 }
diff --git a/src/runtime/mksizeclasses.go b/src/runtime/mksizeclasses.go
index 587d3c7..0f897ba 100644
--- a/src/runtime/mksizeclasses.go
+++ b/src/runtime/mksizeclasses.go
@@ -54,6 +54,8 @@ func main() {
 	fmt.Fprintln(&b, "package runtime")
 	classes := makeClasses()
 
+	printComment(&b, classes)
+
 	printClasses(&b, classes)
 
 	out, err := format.Source(b.Bytes())
@@ -239,6 +241,20 @@ nextk:
 	}
 }
 
+func printComment(w io.Writer, classes []class) {
+	fmt.Fprintf(w, "// %-5s  %-9s  %-10s  %-7s  %-11s\n", "class", "bytes/obj", "bytes/span", "objects", "waste bytes")
+	for i, c := range classes {
+		if i == 0 {
+			continue
+		}
+		spanSize := c.npages * pageSize
+		objects := spanSize / c.size
+		waste := spanSize - c.size*(spanSize/c.size)
+		fmt.Fprintf(w, "// %5d  %9d  %10d  %7d  %11d\n", i, c.size, spanSize, objects, waste)
+	}
+	fmt.Fprintf(w, "\n")
+}
+
 func printClasses(w io.Writer, classes []class) {
 	fmt.Fprintln(w, "const (")
 	fmt.Fprintf(w, "_MaxSmallSize = %d\n", maxSmallSize)
diff --git a/src/runtime/mstats.go b/src/runtime/mstats.go
index 4e111a1..41b9005 100644
--- a/src/runtime/mstats.go
+++ b/src/runtime/mstats.go
@@ -174,6 +174,7 @@ type MemStats struct {
 	Lookups uint64
 
 	// Mallocs is the cumulative count of heap objects allocated.
+	// The number of live objects is Mallocs - Frees.
 	Mallocs uint64
 
 	// Frees is the cumulative count of heap objects freed.
@@ -397,9 +398,19 @@ type MemStats struct {
 	//
 	// This does not report allocations larger than BySize[60].Size.
 	BySize [61]struct {
-		Size    uint32
+		// Size is the maximum byte size of an object in this
+		// size class.
+		Size uint32
+
+		// Mallocs is the cumulative count of heap objects
+		// allocated in this size class. The cumulative bytes
+		// of allocation is Size*Mallocs. The number of live
+		// objects in this size class is Mallocs - Frees.
 		Mallocs uint64
-		Frees   uint64
+
+		// Frees is the cumulative count of heap objects freed
+		// in this size class.
+		Frees uint64
 	}
 }
 
diff --git a/src/runtime/os_linux.go b/src/runtime/os_linux.go
index 320c128..a6efc0e 100644
--- a/src/runtime/os_linux.go
+++ b/src/runtime/os_linux.go
@@ -91,6 +91,9 @@ func getproccount() int32 {
 	const maxCPUs = 64 * 1024
 	var buf [maxCPUs / (sys.PtrSize * 8)]uintptr
 	r := sched_getaffinity(0, unsafe.Sizeof(buf), &buf[0])
+	if r < 0 {
+		return 1
+	}
 	n := int32(0)
 	for _, v := range buf[:r/sys.PtrSize] {
 		for v != 0 {
@@ -208,6 +211,26 @@ func sysargs(argc int32, argv **byte) {
 		// Fall back to /proc/self/auxv.
 		fd := open(&procAuxv[0], 0 /* O_RDONLY */, 0)
 		if fd < 0 {
+			// On Android, /proc/self/auxv might be unreadable (issue 9229), so we fallback to
+			// try using mincore to detect the physical page size.
+			// mincore should return EINVAL when address is not a multiple of system page size.
+			const size = 256 << 10 // size of memory region to allocate
+			p := mmap(nil, size, _PROT_READ|_PROT_WRITE, _MAP_ANON|_MAP_PRIVATE, -1, 0)
+			if uintptr(p) < 4096 {
+				return
+			}
+			var n uintptr
+			for n = 4 << 10; n < size; n <<= 1 {
+				err := mincore(unsafe.Pointer(uintptr(p)+n), 1, &addrspace_vec[0])
+				if err == 0 {
+					physPageSize = n
+					break
+				}
+			}
+			if physPageSize == 0 {
+				physPageSize = size
+			}
+			munmap(p, size)
 			return
 		}
 		var buf [128]uintptr
diff --git a/src/runtime/os_linux_arm.go b/src/runtime/os_linux_arm.go
index 2b0834a..896ec15 100644
--- a/src/runtime/os_linux_arm.go
+++ b/src/runtime/os_linux_arm.go
@@ -18,6 +18,12 @@ var armArch uint8 = 6 // we default to ARMv6
 var hwcap uint32      // set by setup_auxv
 
 func checkgoarm() {
+	// On Android, /proc/self/auxv might be unreadable and hwcap won't
+	// reflect the CPU capabilities. Assume that every Android arm device
+	// has the necessary floating point hardware available.
+	if GOOS == "android" {
+		return
+	}
 	if goarm > 5 && hwcap&_HWCAP_VFP == 0 {
 		print("runtime: this CPU has no floating point hardware, so it cannot run\n")
 		print("this GOARM=", goarm, " binary. Recompile using GOARM=5.\n")
diff --git a/src/runtime/os_windows.go b/src/runtime/os_windows.go
index 10cab90..75b8acd 100644
--- a/src/runtime/os_windows.go
+++ b/src/runtime/os_windows.go
@@ -332,8 +332,12 @@ func goenvs() {
 	stdcall1(_FreeEnvironmentStringsW, uintptr(strings))
 }
 
+// exiting is set to non-zero when the process is exiting.
+var exiting uint32
+
 //go:nosplit
 func exit(code int32) {
+	atomic.Store(&exiting, 1)
 	stdcall1(_ExitProcess, uintptr(code))
 }
 
@@ -519,6 +523,14 @@ func newosproc(mp *m, stk unsafe.Pointer) {
 		_STACK_SIZE_PARAM_IS_A_RESERVATION, 0)
 
 	if thandle == 0 {
+		if atomic.Load(&exiting) != 0 {
+			// CreateThread may fail if called
+			// concurrently with ExitProcess. If this
+			// happens, just freeze this thread and let
+			// the process exit. See issue #18253.
+			lock(&deadlock)
+			lock(&deadlock)
+		}
 		print("runtime: failed to create new OS thread (have ", mcount(), " already; errno=", getlasterror(), ")\n")
 		throw("runtime.newosproc")
 	}
diff --git a/src/runtime/pprof/pprof_test.go b/src/runtime/pprof/pprof_test.go
index fd06607..8372283 100644
--- a/src/runtime/pprof/pprof_test.go
+++ b/src/runtime/pprof/pprof_test.go
@@ -204,7 +204,11 @@ func profileOk(t *testing.T, need []string, prof bytes.Buffer, duration time.Dur
 	}
 
 	// Check that we got a reasonable number of samples.
-	if ideal := uintptr(duration * 100 / time.Second); samples == 0 || samples < ideal/4 {
+	// We used to always require at least ideal/4 samples,
+	// but that is too hard to guarantee on a loaded system.
+	// Now we accept 10 or more samples, which we take to be
+	// enough to show that at least some profiling is occurring.
+	if ideal := uintptr(duration * 100 / time.Second); samples == 0 || (samples < ideal/4 && samples < 10) {
 		t.Logf("too few samples; got %d, want at least %d, ideally %d", samples, ideal/4, ideal)
 		ok = false
 	}
diff --git a/src/runtime/proc.go b/src/runtime/proc.go
index cad1b1c..f41672d 100644
--- a/src/runtime/proc.go
+++ b/src/runtime/proc.go
@@ -240,6 +240,16 @@ func Gosched() {
 	mcall(gosched_m)
 }
 
+var alwaysFalse bool
+
+// goschedguarded does nothing, but is written in a way that guarantees a preemption check in its prologue.
+// Calls to this function are inserted by the compiler in otherwise uninterruptible loops (see insertLoopReschedChecks).
+func goschedguarded() {
+	if alwaysFalse {
+		goschedguarded()
+	}
+}
+
 // Puts the current goroutine into a waiting state and calls unlockf.
 // If unlockf returns false, the goroutine is resumed.
 // unlockf must not access this G's stack, as it may be moved between
@@ -632,10 +642,15 @@ func helpgc(nproc int32) {
 // sched.stopwait to in order to request that all Gs permanently stop.
 const freezeStopWait = 0x7fffffff
 
+// freezing is set to non-zero if the runtime is trying to freeze the
+// world.
+var freezing uint32
+
 // Similar to stopTheWorld but best-effort and can be called several times.
 // There is no reverse operation, used during crashing.
 // This function must not lock any mutexes.
 func freezetheworld() {
+	atomic.Store(&freezing, 1)
 	// stopwait and preemption requests can be lost
 	// due to races with concurrently executing threads,
 	// so try several times
@@ -1018,15 +1033,30 @@ func stopTheWorldWithSema() {
 			preemptall()
 		}
 	}
+
+	// sanity checks
+	bad := ""
 	if sched.stopwait != 0 {
-		throw("stopTheWorld: not stopped")
-	}
-	for i := 0; i < int(gomaxprocs); i++ {
-		p := allp[i]
-		if p.status != _Pgcstop {
-			throw("stopTheWorld: not stopped")
+		bad = "stopTheWorld: not stopped (stopwait != 0)"
+	} else {
+		for i := 0; i < int(gomaxprocs); i++ {
+			p := allp[i]
+			if p.status != _Pgcstop {
+				bad = "stopTheWorld: not stopped (status != _Pgcstop)"
+			}
 		}
 	}
+	if atomic.Load(&freezing) != 0 {
+		// Some other thread is panicking. This can cause the
+		// sanity checks above to fail if the panic happens in
+		// the signal handler on a stopped thread. Either way,
+		// we should halt this thread.
+		lock(&deadlock)
+		lock(&deadlock)
+	}
+	if bad != "" {
+		throw(bad)
+	}
 }
 
 func mhelpgc() {
diff --git a/src/runtime/runtime2.go b/src/runtime/runtime2.go
index 696ea81..1ceab0a 100644
--- a/src/runtime/runtime2.go
+++ b/src/runtime/runtime2.go
@@ -615,7 +615,7 @@ const (
 
 // Layout of in-memory per-function information prepared by linker
 // See https://golang.org/s/go12symtab.
-// Keep in sync with linker
+// Keep in sync with linker (../cmd/link/internal/ld/pcln.go:/pclntab)
 // and with package debug/gosym and with symtab.go in package runtime.
 type _func struct {
 	entry   uintptr // start pc
@@ -640,7 +640,7 @@ type itab struct {
 	_type  *_type
 	link   *itab
 	bad    int32
-	unused int32
+	inhash int32      // has this itab been added to hash?
 	fun    [1]uintptr // variable sized
 }
 
@@ -745,6 +745,8 @@ var (
 	lfenceBeforeRdtsc bool
 	support_avx       bool
 	support_avx2      bool
+	support_bmi1      bool
+	support_bmi2      bool
 
 	goarm                uint8 // set by cmd/link on arm systems
 	framepointer_enabled bool  // set by cmd/link
diff --git a/src/runtime/select.go b/src/runtime/select.go
index 03e9e4a..0d846b1 100644
--- a/src/runtime/select.go
+++ b/src/runtime/select.go
@@ -422,8 +422,62 @@ loop:
 	gp.param = nil
 	gopark(selparkcommit, nil, "select", traceEvGoBlockSelect, 2)
 
-	// someone woke us up
-	sellock(scases, lockorder)
+	// While we were asleep, some goroutine came along and completed
+	// one of the cases in the select and woke us up (called ready).
+	// As part of that process, the goroutine did a cas on done above
+	// (aka *sg.selectdone for all queued sg) to win the right to
+	// complete the select. Now done = 1.
+	//
+	// If we copy (grow) our own stack, we will update the
+	// selectdone pointers inside the gp.waiting sudog list to point
+	// at the new stack. Another goroutine attempting to
+	// complete one of our (still linked in) select cases might
+	// see the new selectdone pointer (pointing at the new stack)
+	// before the new stack has real data; if the new stack has done = 0
+	// (before the old values are copied over), the goroutine might
+	// do a cas via sg.selectdone and incorrectly believe that it has
+	// won the right to complete the select, executing a second
+	// communication and attempting to wake us (call ready) again.
+	//
+	// Then things break.
+	//
+	// The best break is that the goroutine doing ready sees the
+	// _Gcopystack status and throws, as in #17007.
+	// A worse break would be for us to continue on, start running real code,
+	// block in a semaphore acquisition (sema.go), and have the other
+	// goroutine wake us up without having really acquired the semaphore.
+	// That would result in the goroutine spuriously running and then
+	// queue up another spurious wakeup when the semaphore really is ready.
+	// In general the situation can cascade until something notices the
+	// problem and causes a crash.
+	//
+	// A stack shrink does not have this problem, because it locks
+	// all the channels that are involved first, blocking out the
+	// possibility of a cas on selectdone.
+	//
+	// A stack growth before gopark above does not have this
+	// problem, because we hold those channel locks (released by
+	// selparkcommit).
+	//
+	// A stack growth after sellock below does not have this
+	// problem, because again we hold those channel locks.
+	//
+	// The only problem is a stack growth during sellock.
+	// To keep that from happening, run sellock on the system stack.
+	//
+	// It might be that we could avoid this if copystack copied the
+	// stack before calling adjustsudogs. In that case,
+	// syncadjustsudogs would need to recopy the tiny part that
+	// it copies today, resulting in a little bit of extra copying.
+	//
+	// An even better fix, not for the week before a release candidate,
+	// would be to put space in every sudog and make selectdone
+	// point at (say) the space in the first sudog.
+
+	systemstack(func() {
+		sellock(scases, lockorder)
+	})
+
 	sg = (*sudog)(gp.param)
 	gp.param = nil
 
@@ -464,8 +518,15 @@ loop:
 	}
 
 	if cas == nil {
-		// This can happen if we were woken up by a close().
-		// TODO: figure that out explicitly so we don't need this loop.
+		// We can wake up with gp.param == nil (so cas == nil)
+		// when a channel involved in the select has been closed.
+		// It is easiest to loop and re-run the operation;
+		// we'll see that it's now closed.
+		// Maybe some day we can signal the close explicitly,
+		// but we'd have to distinguish close-on-reader from close-on-writer.
+		// It's easiest not to duplicate the code and just recheck above.
+		// We know that something closed, and things never un-close,
+		// so we won't block again.
 		goto loop
 	}
 
diff --git a/src/runtime/sizeclasses.go b/src/runtime/sizeclasses.go
index ec30d15..e616e95 100644
--- a/src/runtime/sizeclasses.go
+++ b/src/runtime/sizeclasses.go
@@ -3,6 +3,74 @@
 
 package runtime
 
+// class  bytes/obj  bytes/span  objects  waste bytes
+//     1          8        8192     1024            0
+//     2         16        8192      512            0
+//     3         32        8192      256            0
+//     4         48        8192      170           32
+//     5         64        8192      128            0
+//     6         80        8192      102           32
+//     7         96        8192       85           32
+//     8        112        8192       73           16
+//     9        128        8192       64            0
+//    10        144        8192       56          128
+//    11        160        8192       51           32
+//    12        176        8192       46           96
+//    13        192        8192       42          128
+//    14        208        8192       39           80
+//    15        224        8192       36          128
+//    16        240        8192       34           32
+//    17        256        8192       32            0
+//    18        288        8192       28          128
+//    19        320        8192       25          192
+//    20        352        8192       23           96
+//    21        384        8192       21          128
+//    22        416        8192       19          288
+//    23        448        8192       18          128
+//    24        480        8192       17           32
+//    25        512        8192       16            0
+//    26        576        8192       14          128
+//    27        640        8192       12          512
+//    28        704        8192       11          448
+//    29        768        8192       10          512
+//    30        896        8192        9          128
+//    31       1024        8192        8            0
+//    32       1152        8192        7          128
+//    33       1280        8192        6          512
+//    34       1408       16384       11          896
+//    35       1536        8192        5          512
+//    36       1792       16384        9          256
+//    37       2048        8192        4            0
+//    38       2304       16384        7          256
+//    39       2688        8192        3          128
+//    40       3072       24576        8            0
+//    41       3200       16384        5          384
+//    42       3456       24576        7          384
+//    43       4096        8192        2            0
+//    44       4864       24576        5          256
+//    45       5376       16384        3          256
+//    46       6144       24576        4            0
+//    47       6528       32768        5          128
+//    48       6784       40960        6          256
+//    49       6912       49152        7          768
+//    50       8192        8192        1            0
+//    51       9472       57344        6          512
+//    52       9728       49152        5          512
+//    53      10240       40960        4            0
+//    54      10880       32768        3          128
+//    55      12288       24576        2            0
+//    56      13568       40960        3          256
+//    57      14336       57344        4            0
+//    58      16384       16384        1            0
+//    59      18432       73728        4            0
+//    60      19072       57344        3          128
+//    61      20480       40960        2            0
+//    62      21760       65536        3          256
+//    63      24576       24576        1            0
+//    64      27264       81920        3          128
+//    65      28672       57344        2            0
+//    66      32768       32768        1            0
+
 const (
 	_MaxSmallSize   = 32768
 	smallSizeDiv    = 8
diff --git a/src/runtime/stack.go b/src/runtime/stack.go
index b77a311..0f1a5c1 100644
--- a/src/runtime/stack.go
+++ b/src/runtime/stack.go
@@ -601,7 +601,7 @@ func adjustpointers(scanp unsafe.Pointer, cbv *bitvector, adjinfo *adjustinfo, f
 			pp := (*uintptr)(add(scanp, i*sys.PtrSize))
 		retry:
 			p := *pp
-			if f != nil && 0 < p && p < _PageSize && debug.invalidptr != 0 {
+			if f != nil && 0 < p && p < minLegalPointer && debug.invalidptr != 0 {
 				// Looks like a junk value in a pointer slot.
 				// Live analysis wrong?
 				getg().m.traceback = 2
diff --git a/src/runtime/sys_dragonfly_amd64.s b/src/runtime/sys_dragonfly_amd64.s
index 88c7f9d..b950b69 100644
--- a/src/runtime/sys_dragonfly_amd64.s
+++ b/src/runtime/sys_dragonfly_amd64.s
@@ -200,11 +200,28 @@ TEXT runtime·sigfwd(SB),NOSPLIT,$0-32
 	POPQ	BP
 	RET
 
-TEXT runtime·sigtramp(SB),NOSPLIT,$24
-	MOVQ	DI, 0(SP)
-	MOVQ	SI, 8(SP)
-	MOVQ	DX, 16(SP)
+TEXT runtime·sigtramp(SB),NOSPLIT,$72
+	// Save callee-saved C registers, since the caller may be a C signal handler.
+	MOVQ	BX,  bx-8(SP)
+	MOVQ	BP,  bp-16(SP)  // save in case GOEXPERIMENT=noframepointer is set
+	MOVQ	R12, r12-24(SP)
+	MOVQ	R13, r13-32(SP)
+	MOVQ	R14, r14-40(SP)
+	MOVQ	R15, r15-48(SP)
+	// We don't save mxcsr or the x87 control word because sigtrampgo doesn't
+	// modify them.
+
+	MOVQ	DX, ctx-56(SP)
+	MOVQ	SI, info-64(SP)
+	MOVQ	DI, signum-72(SP)
 	CALL	runtime·sigtrampgo(SB)
+
+	MOVQ	r15-48(SP), R15
+	MOVQ	r14-40(SP), R14
+	MOVQ	r13-32(SP), R13
+	MOVQ	r12-24(SP), R12
+	MOVQ	bp-16(SP),  BP
+	MOVQ	bx-8(SP),   BX
 	RET
 
 TEXT runtime·mmap(SB),NOSPLIT,$0
diff --git a/src/runtime/sys_freebsd_amd64.s b/src/runtime/sys_freebsd_amd64.s
index 19007dc..158a60d 100644
--- a/src/runtime/sys_freebsd_amd64.s
+++ b/src/runtime/sys_freebsd_amd64.s
@@ -196,11 +196,28 @@ TEXT runtime·sigfwd(SB),NOSPLIT,$0-32
 	POPQ	BP
 	RET
 
-TEXT runtime·sigtramp(SB),NOSPLIT,$24
-	MOVQ	DI, 0(SP)
-	MOVQ	SI, 8(SP)
-	MOVQ	DX, 16(SP)
+TEXT runtime·sigtramp(SB),NOSPLIT,$72
+	// Save callee-saved C registers, since the caller may be a C signal handler.
+	MOVQ	BX, bx-8(SP)
+	MOVQ	BP, bp-16(SP)  // save in case GOEXPERIMENT=noframepointer is set
+	MOVQ	R12, r12-24(SP)
+	MOVQ	R13, r13-32(SP)
+	MOVQ	R14, r14-40(SP)
+	MOVQ	R15, r15-48(SP)
+	// We don't save mxcsr or the x87 control word because sigtrampgo doesn't
+	// modify them.
+
+	MOVQ	DX, ctx-56(SP)
+	MOVQ	SI, info-64(SP)
+	MOVQ	DI, signum-72(SP)
 	CALL	runtime·sigtrampgo(SB)
+
+	MOVQ	r15-48(SP), R15
+	MOVQ	r14-40(SP), R14
+	MOVQ	r13-32(SP), R13
+	MOVQ	r12-24(SP), R12
+	MOVQ	bp-16(SP),  BP
+	MOVQ	bx-8(SP),   BX
 	RET
 
 TEXT runtime·mmap(SB),NOSPLIT,$0
diff --git a/src/runtime/sys_linux_386.s b/src/runtime/sys_linux_386.s
index 1d798c7..45320c0 100644
--- a/src/runtime/sys_linux_386.s
+++ b/src/runtime/sys_linux_386.s
@@ -228,7 +228,15 @@ TEXT runtime·sigfwd(SB),NOSPLIT,$12-16
 	MOVL	AX, SP
 	RET
 
-TEXT runtime·sigtramp(SB),NOSPLIT,$12
+TEXT runtime·sigtramp(SB),NOSPLIT,$28
+	// Save callee-saved C registers, since the caller may be a C signal handler.
+	MOVL	BX, bx-4(SP)
+	MOVL	BP, bp-8(SP)
+	MOVL	SI, si-12(SP)
+	MOVL	DI, di-16(SP)
+	// We don't save mxcsr or the x87 control word because sigtrampgo doesn't
+	// modify them.
+
 	MOVL	sig+0(FP), BX
 	MOVL	BX, 0(SP)
 	MOVL	info+4(FP), BX
@@ -236,6 +244,11 @@ TEXT runtime·sigtramp(SB),NOSPLIT,$12
 	MOVL	ctx+8(FP), BX
 	MOVL	BX, 8(SP)
 	CALL	runtime·sigtrampgo(SB)
+
+	MOVL	di-16(SP), DI
+	MOVL	si-12(SP), SI
+	MOVL	bp-8(SP),  BP
+	MOVL	bx-4(SP),  BX
 	RET
 
 TEXT runtime·cgoSigtramp(SB),NOSPLIT,$0
diff --git a/src/runtime/sys_linux_amd64.s b/src/runtime/sys_linux_amd64.s
index 832b98b..839df16 100644
--- a/src/runtime/sys_linux_amd64.s
+++ b/src/runtime/sys_linux_amd64.s
@@ -244,12 +244,29 @@ TEXT runtime·sigfwd(SB),NOSPLIT,$0-32
 	POPQ	BP
 	RET
 
-TEXT runtime·sigtramp(SB),NOSPLIT,$24
-	MOVQ	DI, 0(SP)   // signum
-	MOVQ	SI, 8(SP)   // info
-	MOVQ	DX, 16(SP)  // ctx
+TEXT runtime·sigtramp(SB),NOSPLIT,$72
+	// Save callee-saved C registers, since the caller may be a C signal handler.
+	MOVQ	BX,  bx-8(SP)
+	MOVQ	BP,  bp-16(SP)  // save in case GOEXPERIMENT=noframepointer is set
+	MOVQ	R12, r12-24(SP)
+	MOVQ	R13, r13-32(SP)
+	MOVQ	R14, r14-40(SP)
+	MOVQ	R15, r15-48(SP)
+	// We don't save mxcsr or the x87 control word because sigtrampgo doesn't
+	// modify them.
+
+	MOVQ	DX, ctx-56(SP)
+	MOVQ	SI, info-64(SP)
+	MOVQ	DI, signum-72(SP)
 	MOVQ	$runtime·sigtrampgo(SB), AX
 	CALL AX
+
+	MOVQ	r15-48(SP), R15
+	MOVQ	r14-40(SP), R14
+	MOVQ	r13-32(SP), R13
+	MOVQ	r12-24(SP), R12
+	MOVQ	bp-16(SP),  BP
+	MOVQ	bx-8(SP),   BX
 	RET
 
 // Used instead of sigtramp in programs that use cgo.
diff --git a/src/runtime/sys_linux_mipsx.s b/src/runtime/sys_linux_mipsx.s
index 6f089f5..73ce061 100644
--- a/src/runtime/sys_linux_mipsx.s
+++ b/src/runtime/sys_linux_mipsx.s
@@ -249,7 +249,7 @@ TEXT runtime·sigfwd(SB),NOSPLIT,$0-16
 	MOVW	fn+0(FP), R25
 	MOVW	R29, R22
 	SUBU	$16, R29
-	AND	$0x7, R29	// shadow space for 4 args aligned to 8 bytes as per O32 ABI
+	AND	$~7, R29	// shadow space for 4 args aligned to 8 bytes as per O32 ABI
 	JAL	(R25)
 	MOVW	R22, R29
 	RET
diff --git a/src/runtime/sys_netbsd_386.s b/src/runtime/sys_netbsd_386.s
index 50d35e5..8c4f004 100644
--- a/src/runtime/sys_netbsd_386.s
+++ b/src/runtime/sys_netbsd_386.s
@@ -232,7 +232,15 @@ TEXT runtime·sigfwd(SB),NOSPLIT,$12-16
 	MOVL	AX, SP
 	RET
 
-TEXT runtime·sigtramp(SB),NOSPLIT,$12
+TEXT runtime·sigtramp(SB),NOSPLIT,$28
+	// Save callee-saved C registers, since the caller may be a C signal handler.
+	MOVL	BX, bx-4(SP)
+	MOVL	BP, bp-8(SP)
+	MOVL	SI, si-12(SP)
+	MOVL	DI, di-16(SP)
+	// We don't save mxcsr or the x87 control word because sigtrampgo doesn't
+	// modify them.
+
 	MOVL	signo+0(FP), BX
 	MOVL	BX, 0(SP)
 	MOVL	info+4(FP), BX
@@ -240,6 +248,11 @@ TEXT runtime·sigtramp(SB),NOSPLIT,$12
 	MOVL	context+8(FP), BX
 	MOVL	BX, 8(SP)
 	CALL	runtime·sigtrampgo(SB)
+
+	MOVL	di-16(SP), DI
+	MOVL	si-12(SP), SI
+	MOVL	bp-8(SP),  BP
+	MOVL	bx-4(SP),  BX
 	RET
 
 // int32 lwp_create(void *context, uintptr flags, void *lwpid);
diff --git a/src/runtime/sys_netbsd_amd64.s b/src/runtime/sys_netbsd_amd64.s
index 2c50adb..7c7771b 100644
--- a/src/runtime/sys_netbsd_amd64.s
+++ b/src/runtime/sys_netbsd_amd64.s
@@ -250,13 +250,28 @@ TEXT runtime·sigfwd(SB),NOSPLIT,$0-32
 	POPQ	BP
 	RET
 
-TEXT runtime·sigtramp(SB),NOSPLIT,$32
-	MOVQ	DI, 0(SP)   // signum
-	MOVQ	SI, 8(SP)   // info
-	MOVQ	DX, 16(SP)  // ctx
-	MOVQ	R15, 24(SP) // for sigreturn
+TEXT runtime·sigtramp(SB),NOSPLIT,$72
+	// Save callee-saved C registers, since the caller may be a C signal handler.
+	MOVQ	BX,  bx-8(SP)
+	MOVQ	BP,  bp-16(SP)  // save in case GOEXPERIMENT=noframepointer is set
+	MOVQ	R12, r12-24(SP)
+	MOVQ	R13, r13-32(SP)
+	MOVQ	R14, r14-40(SP)
+	MOVQ	R15, r15-48(SP)
+	// We don't save mxcsr or the x87 control word because sigtrampgo doesn't
+	// modify them.
+
+	MOVQ	DX, ctx-56(SP)
+	MOVQ	SI, info-64(SP)
+	MOVQ	DI, signum-72(SP)
 	CALL	runtime·sigtrampgo(SB)
-	MOVQ	24(SP), R15
+
+	MOVQ	r15-48(SP), R15
+	MOVQ	r14-40(SP), R14
+	MOVQ	r13-32(SP), R13
+	MOVQ	r12-24(SP), R12
+	MOVQ	bp-16(SP),  BP
+	MOVQ	bx-8(SP),   BX
 	RET
 
 TEXT runtime·mmap(SB),NOSPLIT,$0
diff --git a/src/runtime/sys_openbsd_386.s b/src/runtime/sys_openbsd_386.s
index 997c07f..76d22b0 100644
--- a/src/runtime/sys_openbsd_386.s
+++ b/src/runtime/sys_openbsd_386.s
@@ -213,7 +213,15 @@ TEXT runtime·sigfwd(SB),NOSPLIT,$12-16
 	MOVL	AX, SP
 	RET
 
-TEXT runtime·sigtramp(SB),NOSPLIT,$12
+TEXT runtime·sigtramp(SB),NOSPLIT,$28
+	// Save callee-saved C registers, since the caller may be a C signal handler.
+	MOVL	BX, bx-4(SP)
+	MOVL	BP, bp-8(SP)
+	MOVL	SI, si-12(SP)
+	MOVL	DI, di-16(SP)
+	// We don't save mxcsr or the x87 control word because sigtrampgo doesn't
+	// modify them.
+
 	MOVL	signo+0(FP), BX
 	MOVL	BX, 0(SP)
 	MOVL	info+4(FP), BX
@@ -221,6 +229,11 @@ TEXT runtime·sigtramp(SB),NOSPLIT,$12
 	MOVL	context+8(FP), BX
 	MOVL	BX, 8(SP)
 	CALL	runtime·sigtrampgo(SB)
+
+	MOVL	di-16(SP), DI
+	MOVL	si-12(SP), SI
+	MOVL	bp-8(SP),  BP
+	MOVL	bx-4(SP),  BX
 	RET
 
 // int32 tfork(void *param, uintptr psize, M *mp, G *gp, void (*fn)(void));
diff --git a/src/runtime/sys_openbsd_amd64.s b/src/runtime/sys_openbsd_amd64.s
index 6ca5a81..cf7a3fb 100644
--- a/src/runtime/sys_openbsd_amd64.s
+++ b/src/runtime/sys_openbsd_amd64.s
@@ -242,11 +242,28 @@ TEXT runtime·sigfwd(SB),NOSPLIT,$0-32
 	POPQ	BP
 	RET
 
-TEXT runtime·sigtramp(SB),NOSPLIT,$24
-	MOVQ	DI, 0(SP)
-	MOVQ	SI, 8(SP)
-	MOVQ	DX, 16(SP)
+TEXT runtime·sigtramp(SB),NOSPLIT,$72
+	// Save callee-saved C registers, since the caller may be a C signal handler.
+	MOVQ	BX,  bx-8(SP)
+	MOVQ	BP,  bp-16(SP)  // save in case GOEXPERIMENT=noframepointer is set
+	MOVQ	R12, r12-24(SP)
+	MOVQ	R13, r13-32(SP)
+	MOVQ	R14, r14-40(SP)
+	MOVQ	R15, r15-48(SP)
+	// We don't save mxcsr or the x87 control word because sigtrampgo doesn't
+	// modify them.
+
+	MOVQ	DX, ctx-56(SP)
+	MOVQ	SI, info-64(SP)
+	MOVQ	DI, signum-72(SP)
 	CALL	runtime·sigtrampgo(SB)
+
+	MOVQ	r15-48(SP), R15
+	MOVQ	r14-40(SP), R14
+	MOVQ	r13-32(SP), R13
+	MOVQ	r12-24(SP), R12
+	MOVQ	bp-16(SP),  BP
+	MOVQ	bx-8(SP),   BX
 	RET
 
 TEXT runtime·mmap(SB),NOSPLIT,$0
diff --git a/src/runtime/traceback.go b/src/runtime/traceback.go
index 0049e82..180489f 100644
--- a/src/runtime/traceback.go
+++ b/src/runtime/traceback.go
@@ -546,7 +546,8 @@ func gentraceback(pc0, sp0, lr0 uintptr, gp *g, skip int, pcbuf *uintptr, max in
 	return n
 }
 
-// reflectMethodValue is a partial duplicate of reflect.methodValue.
+// reflectMethodValue is a partial duplicate of reflect.makeFuncImpl
+// and reflect.methodValue.
 type reflectMethodValue struct {
 	fn    uintptr
 	stack *bitvector // args bitmap
diff --git a/src/testing/sub_test.go b/src/testing/sub_test.go
index 2a24aaa..8d5d920 100644
--- a/src/testing/sub_test.go
+++ b/src/testing/sub_test.go
@@ -357,7 +357,7 @@ func TestTRun(t *T) {
 		want := strings.TrimSpace(tc.output)
 		re := makeRegexp(want)
 		if ok, err := regexp.MatchString(re, got); !ok || err != nil {
-			t.Errorf("%s:ouput:\ngot:\n%s\nwant:\n%s", tc.desc, got, want)
+			t.Errorf("%s:output:\ngot:\n%s\nwant:\n%s", tc.desc, got, want)
 		}
 	}
 }
@@ -498,7 +498,7 @@ func TestBRun(t *T) {
 		want := strings.TrimSpace(tc.output)
 		re := makeRegexp(want)
 		if ok, err := regexp.MatchString(re, got); !ok || err != nil {
-			t.Errorf("%s:ouput:\ngot:\n%s\nwant:\n%s", tc.desc, got, want)
+			t.Errorf("%s:output:\ngot:\n%s\nwant:\n%s", tc.desc, got, want)
 		}
 	}
 }
diff --git a/src/testing/testing.go b/src/testing/testing.go
index 8fb6d83..c972b27 100644
--- a/src/testing/testing.go
+++ b/src/testing/testing.go
@@ -895,11 +895,11 @@ func (m *M) before() {
 	if *cpuProfile != "" {
 		f, err := os.Create(toOutputDir(*cpuProfile))
 		if err != nil {
-			fmt.Fprintf(os.Stderr, "testing: %s", err)
+			fmt.Fprintf(os.Stderr, "testing: %s\n", err)
 			return
 		}
 		if err := m.deps.StartCPUProfile(f); err != nil {
-			fmt.Fprintf(os.Stderr, "testing: can't start cpu profile: %s", err)
+			fmt.Fprintf(os.Stderr, "testing: can't start cpu profile: %s\n", err)
 			f.Close()
 			return
 		}
@@ -908,11 +908,11 @@ func (m *M) before() {
 	if *traceFile != "" {
 		f, err := os.Create(toOutputDir(*traceFile))
 		if err != nil {
-			fmt.Fprintf(os.Stderr, "testing: %s", err)
+			fmt.Fprintf(os.Stderr, "testing: %s\n", err)
 			return
 		}
 		if err := trace.Start(f); err != nil {
-			fmt.Fprintf(os.Stderr, "testing: can't start tracing: %s", err)
+			fmt.Fprintf(os.Stderr, "testing: can't start tracing: %s\n", err)
 			f.Close()
 			return
 		}
diff --git a/src/vendor/golang_org/x/crypto/chacha20poly1305/chacha20poly1305_amd64.go b/src/vendor/golang_org/x/crypto/chacha20poly1305/chacha20poly1305_amd64.go
index f0d3485..4755033 100644
--- a/src/vendor/golang_org/x/crypto/chacha20poly1305/chacha20poly1305_amd64.go
+++ b/src/vendor/golang_org/x/crypto/chacha20poly1305/chacha20poly1305_amd64.go
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build amd64,go1.7
+// +build go1.7,amd64,!gccgo,!appengine
 
 package chacha20poly1305
 
diff --git a/src/vendor/golang_org/x/crypto/chacha20poly1305/chacha20poly1305_amd64.s b/src/vendor/golang_org/x/crypto/chacha20poly1305/chacha20poly1305_amd64.s
index 2fa9b55..39c58b4 100644
--- a/src/vendor/golang_org/x/crypto/chacha20poly1305/chacha20poly1305_amd64.s
+++ b/src/vendor/golang_org/x/crypto/chacha20poly1305/chacha20poly1305_amd64.s
@@ -4,7 +4,7 @@
 
 // This file was originally from https://golang.org/cl/24717 by Vlad Krasnov of CloudFlare.
 
-// +build go1.7
+// +build go1.7,amd64,!gccgo,!appengine
 
 #include "textflag.h"
 // General register allocation
@@ -278,8 +278,15 @@ TEXT ·chacha20Poly1305Open(SB), 0, $288-97
 	MOVQ ad+72(FP), adp
 
 	// Check for AVX2 support
-	CMPB runtime·support_avx2(SB), $1
-	JE   chacha20Poly1305Open_AVX2
+	CMPB runtime·support_avx2(SB), $0
+	JE   noavx2bmi2Open
+
+	// Check BMI2 bit for MULXQ.
+	// runtime·cpuid_ebx7 is always available here
+	// because it passed avx2 check
+	TESTL $(1<<8), runtime·cpuid_ebx7(SB)
+	JNE   chacha20Poly1305Open_AVX2
+noavx2bmi2Open:
 
 	// Special optimization, for very short buffers
 	CMPQ inl, $128
@@ -1485,8 +1492,15 @@ TEXT ·chacha20Poly1305Seal(SB), 0, $288-96
 	MOVQ ad+72(FP), adp
 
 	// Check for AVX2 support
-	CMPB runtime·support_avx2(SB), $1
-	JE   chacha20Poly1305Seal_AVX2
+	CMPB runtime·support_avx2(SB), $0
+	JE   noavx2bmi2Seal
+
+	// Check BMI2 bit for MULXQ.
+	// runtime·cpuid_ebx7 is always available here
+	// because it passed avx2 check
+	TESTL $(1<<8), runtime·cpuid_ebx7(SB)
+	JNE   chacha20Poly1305Seal_AVX2
+noavx2bmi2Seal:
 
 	// Special optimization, for very short buffers
 	CMPQ inl, $128
@@ -1691,7 +1705,7 @@ sealSSETail64:
 	MOVO  D1, ctr0Store
 
 sealSSETail64LoopA:
-	// Perform ChaCha rounds, while hashing the prevsiosly encrpyted ciphertext
+	// Perform ChaCha rounds, while hashing the previously encrypted ciphertext
 	polyAdd(0(oup))
 	polyMul
 	LEAQ 16(oup), oup
@@ -1725,7 +1739,7 @@ sealSSETail128:
 	MOVO A0, A1; MOVO B0, B1; MOVO C0, C1; MOVO D0, D1; PADDL ·sseIncMask<>(SB), D1; MOVO D1, ctr1Store
 
 sealSSETail128LoopA:
-	// Perform ChaCha rounds, while hashing the prevsiosly encrpyted ciphertext
+	// Perform ChaCha rounds, while hashing the previously encrypted ciphertext
 	polyAdd(0(oup))
 	polyMul
 	LEAQ 16(oup), oup
@@ -1771,7 +1785,7 @@ sealSSETail192:
 	MOVO A1, A2; MOVO B1, B2; MOVO C1, C2; MOVO D1, D2; PADDL ·sseIncMask<>(SB), D2; MOVO D2, ctr2Store
 
 sealSSETail192LoopA:
-	// Perform ChaCha rounds, while hashing the prevsiosly encrpyted ciphertext
+	// Perform ChaCha rounds, while hashing the previously encrypted ciphertext
 	polyAdd(0(oup))
 	polyMul
 	LEAQ 16(oup), oup
diff --git a/src/vendor/golang_org/x/crypto/chacha20poly1305/chacha20poly1305_noasm.go b/src/vendor/golang_org/x/crypto/chacha20poly1305/chacha20poly1305_noasm.go
index 1d4dcd3..4c2eb70 100644
--- a/src/vendor/golang_org/x/crypto/chacha20poly1305/chacha20poly1305_noasm.go
+++ b/src/vendor/golang_org/x/crypto/chacha20poly1305/chacha20poly1305_noasm.go
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build !amd64 !go1.7
+// +build !amd64 !go1.7 gccgo appengine
 
 package chacha20poly1305
 
diff --git a/test/fixedbugs/gcc78763.go b/test/fixedbugs/gcc78763.go
new file mode 100644
index 0000000..3e34127
--- /dev/null
+++ b/test/fixedbugs/gcc78763.go
@@ -0,0 +1,19 @@
+// compile
+
+// Copyright 2016 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// The gccgo compiler crashed while compiling this code.
+// https://gcc.gnu.org/PR78763.
+
+package p
+
+import "unsafe"
+
+func F() int {
+	if unsafe.Sizeof(0) == 8 {
+		return 8
+	}
+	return 0
+}
diff --git a/test/fixedbugs/issue10958.go b/test/fixedbugs/issue10958.go
new file mode 100644
index 0000000..86d2057
--- /dev/null
+++ b/test/fixedbugs/issue10958.go
@@ -0,0 +1,95 @@
+// +build !nacl,disabled
+// buildrun -t 10  -gcflags=-d=ssa/insert_resched_checks/on,ssa/check/on
+
+// Copyright 2016 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Test is disabled because it flakes when run in all.bash
+// on some platforms, but is useful standalone to verify
+// that rescheduling checks are working (and we may wish
+// to investigate the flake, since it suggests that the
+// loop rescheduling check may not work right on those
+// platforms).
+
+// This checks to see that call-free infinite loops do not
+// block garbage collection.  IF YOU RUN IT STANDALONE without
+// -gcflags=-d=ssa/insert_resched_checks/on in a not-experimental
+// build, it should hang.
+
+package main
+
+import (
+	"runtime"
+)
+
+var someglobal1 int
+var someglobal2 int
+var someglobal3 int
+
+//go:noinline
+func f() {}
+
+func standinacorner1() {
+	for someglobal1&1 == 0 {
+		someglobal1++
+		someglobal1++
+	}
+}
+
+func standinacorner2(i int) {
+	// contains an irreducible loop containing changes to memory
+	if i != 0 {
+		goto midloop
+	}
+
+loop:
+	if someglobal2&1 != 0 {
+		goto done
+	}
+	someglobal2++
+midloop:
+	someglobal2++
+	goto loop
+
+done:
+	return
+}
+
+func standinacorner3() {
+	for someglobal3&1 == 0 {
+		if someglobal3&2 != 0 {
+			for someglobal3&3 == 2 {
+				someglobal3++
+				someglobal3++
+				someglobal3++
+				someglobal3++
+			}
+		}
+		someglobal3++
+		someglobal3++
+		someglobal3++
+		someglobal3++
+	}
+}
+
+func main() {
+	go standinacorner1()
+	go standinacorner2(0)
+	go standinacorner3()
+	// println("About to stand in a corner1")
+	for someglobal1 == 0 {
+		runtime.Gosched()
+	}
+	// println("About to stand in a corner2")
+	for someglobal2 == 0 {
+		runtime.Gosched()
+	}
+	// println("About to stand in a corner3")
+	for someglobal3 == 0 {
+		runtime.Gosched()
+	}
+	// println("About to GC")
+	runtime.GC()
+	// println("Success")
+}
diff --git a/test/fixedbugs/issue18392.go b/test/fixedbugs/issue18392.go
new file mode 100644
index 0000000..ad64238
--- /dev/null
+++ b/test/fixedbugs/issue18392.go
@@ -0,0 +1,11 @@
+// errorcheck
+
+// Copyright 2017 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package p
+
+type A interface {
+	Fn(A.Fn) // ERROR "type A has no method A.Fn"
+}
diff --git a/test/fixedbugs/issue18410.go b/test/fixedbugs/issue18410.go
new file mode 100644
index 0000000..e9c6f86
--- /dev/null
+++ b/test/fixedbugs/issue18410.go
@@ -0,0 +1,40 @@
+// run
+
+// Copyright 2016 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// This checks partially initialized structure literals
+// used to create value.method functions have their
+// non-initialized fields properly zeroed/nil'd
+
+package main
+
+type X struct {
+	A, B, C *int
+}
+
+//go:noinline
+func (t X) Print() {
+	if t.B != nil {
+		panic("t.B must be nil")
+	}
+}
+
+//go:noinline
+func caller(f func()) {
+	f()
+}
+
+//go:noinline
+func test() {
+	var i, j int
+	x := X{A: &i, C: &j}
+	caller(func() { X{A: &i, C: &j}.Print() })
+	caller(X{A: &i, C: &j}.Print)
+	caller(x.Print)
+}
+
+func main() {
+	test()
+}
diff --git a/test/fixedbugs/issue18459.go b/test/fixedbugs/issue18459.go
new file mode 100644
index 0000000..ac07661
--- /dev/null
+++ b/test/fixedbugs/issue18459.go
@@ -0,0 +1,13 @@
+// errorcheck
+
+// Copyright 2016 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Verify that we have a line number for this error.
+
+package main
+
+//go:nowritebarrier // ERROR "go:nowritebarrier only allowed in runtime"
+func main() {
+}
diff --git a/test/fixedbugs/issue6772.go b/test/fixedbugs/issue6772.go
new file mode 100644
index 0000000..4d0001c
--- /dev/null
+++ b/test/fixedbugs/issue6772.go
@@ -0,0 +1,21 @@
+// errorcheck
+
+// Copyright 2016 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package p
+
+func f1() {
+	for a, a := range []int{1, 2, 3} { // ERROR "a repeated on left side of :="
+		println(a)
+	}
+}
+
+func f2() {
+	var a int
+	for a, a := range []int{1, 2, 3} { // ERROR "a repeated on left side of :="
+		println(a)
+	}
+	println(a)
+}
diff --git a/test/live.go b/test/live.go
index 4fb231c..b23e150 100644
--- a/test/live.go
+++ b/test/live.go
@@ -1,6 +1,7 @@
-// errorcheckwithauto -0 -l -live -wb=0
+// errorcheckwithauto -0 -l -live -wb=0 -d=ssa/insert_resched_checks/off
 // +build !ppc64,!ppc64le
 // ppc64 needs a better tighten pass to make f18 pass
+// rescheduling checks need to be turned off because there are some live variables across the inserted check call
 
 // Copyright 2014 The Go Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style
diff --git a/test/nosplit.go b/test/nosplit.go
index 5f4e62f..e0d531c 100644
--- a/test/nosplit.go
+++ b/test/nosplit.go
@@ -261,6 +261,8 @@ TestCases:
 		var buf bytes.Buffer
 		ptrSize := 4
 		switch goarch {
+		case "mips", "mipsle":
+			fmt.Fprintf(&buf, "#define CALL JAL\n#define REGISTER (R0)\n")
 		case "mips64", "mips64le":
 			ptrSize = 8
 			fmt.Fprintf(&buf, "#define CALL JAL\n#define REGISTER (R0)\n")
diff --git a/test/opt_branchlikely.go b/test/opt_branchlikely.go
index 5781253..84de321 100644
--- a/test/opt_branchlikely.go
+++ b/test/opt_branchlikely.go
@@ -1,5 +1,6 @@
 // +build amd64
-// errorcheck -0 -d=ssa/likelyadjust/debug=1
+// errorcheck -0 -d=ssa/likelyadjust/debug=1,ssa/insert_resched_checks/off
+// rescheduling check insertion is turend off because the inserted conditional branches perturb the errorcheck
 
 // Copyright 2016 The Go Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style
diff --git a/test/run.go b/test/run.go
index 0dee6b5..19ca328 100644
--- a/test/run.go
+++ b/test/run.go
@@ -463,6 +463,7 @@ func (t *test) run() {
 	}
 
 	var args, flags []string
+	var tim int
 	wantError := false
 	wantAuto := false
 	singlefilepkgs := false
@@ -478,7 +479,7 @@ func (t *test) run() {
 		action = "rundir"
 	case "cmpout":
 		action = "run" // the run case already looks for <dir>/<test>.out files
-	case "compile", "compiledir", "build", "run", "runoutput", "rundir":
+	case "compile", "compiledir", "build", "run", "buildrun", "runoutput", "rundir":
 		// nothing to do
 	case "errorcheckandrundir":
 		wantError = false // should be no error if also will run
@@ -505,6 +506,14 @@ func (t *test) run() {
 			wantError = false
 		case "-s":
 			singlefilepkgs = true
+		case "-t": // timeout in seconds
+			args = args[1:]
+			var err error
+			tim, err = strconv.Atoi(args[0])
+			if err != nil {
+				t.err = fmt.Errorf("need number of seconds for -t timeout, got %s instead", args[0])
+			}
+
 		default:
 			flags = append(flags, args[0])
 		}
@@ -539,7 +548,31 @@ func (t *test) run() {
 		} else {
 			cmd.Env = os.Environ()
 		}
-		err := cmd.Run()
+
+		var err error
+
+		if tim != 0 {
+			err = cmd.Start()
+			// This command-timeout code adapted from cmd/go/test.go
+			if err == nil {
+				tick := time.NewTimer(time.Duration(tim) * time.Second)
+				done := make(chan error)
+				go func() {
+					done <- cmd.Wait()
+				}()
+				select {
+				case err = <-done:
+					// ok
+				case <-tick.C:
+					cmd.Process.Kill()
+					err = <-done
+					// err = errors.New("Test timeout")
+				}
+				tick.Stop()
+			}
+		} else {
+			err = cmd.Run()
+		}
 		if err != nil {
 			err = fmt.Errorf("%s\n%s", err, buf.Bytes())
 		}
@@ -671,6 +704,32 @@ func (t *test) run() {
 			t.err = err
 		}
 
+	case "buildrun": // build binary, then run binary, instead of go run. Useful for timeout tests where failure mode is infinite loop.
+		// TODO: not supported on NaCl
+		useTmp = true
+		cmd := []string{"go", "build", "-o", "a.exe"}
+		if *linkshared {
+			cmd = append(cmd, "-linkshared")
+		}
+		longdirgofile := filepath.Join(filepath.Join(cwd, t.dir), t.gofile)
+		cmd = append(cmd, flags...)
+		cmd = append(cmd, longdirgofile)
+		out, err := runcmd(cmd...)
+		if err != nil {
+			t.err = err
+			return
+		}
+		cmd = []string{"./a.exe"}
+		out, err = runcmd(append(cmd, args...)...)
+		if err != nil {
+			t.err = err
+			return
+		}
+
+		if strings.Replace(string(out), "\r\n", "\n", -1) != t.expectedOutput() {
+			t.err = fmt.Errorf("incorrect output\n%s", out)
+		}
+
 	case "run":
 		useTmp = false
 		cmd := []string{"go", "run"}
diff --git a/test/zerodivide.go b/test/zerodivide.go
index 9ab2713..214d481 100644
--- a/test/zerodivide.go
+++ b/test/zerodivide.go
@@ -28,6 +28,8 @@ var (
 	i32, j32, k32 int32 = 0, 0, 1
 	i64, j64, k64 int64 = 0, 0, 1
 
+	bb = []int16{2, 0}
+
 	u, v, w       uint    = 0, 0, 1
 	u8, v8, w8    uint8   = 0, 0, 1
 	u16, v16, w16 uint16  = 0, 0, 1
@@ -124,6 +126,10 @@ var errorTests = []ErrorTest{
 	ErrorTest{"int32 1/0", func() { use(k32 / j32) }, "divide"},
 	ErrorTest{"int64 1/0", func() { use(k64 / j64) }, "divide"},
 
+	// From issue 5790, we should ensure that _ assignments
+	// still evaluate and generate zerodivide panics.
+	ErrorTest{"int16 _ = bb[0]/bb[1]", func() { _ = bb[0] / bb[1] }, "divide"},
+
 	ErrorTest{"uint 0/0", func() { use(u / v) }, "divide"},
 	ErrorTest{"uint8 0/0", func() { use(u8 / v8) }, "divide"},
 	ErrorTest{"uint16 0/0", func() { use(u16 / v16) }, "divide"},
@@ -195,9 +201,6 @@ func alike(a, b float64) bool {
 func main() {
 	bad := false
 	for _, t := range errorTests {
-		if t.err != "" {
-			continue
-		}
 		err := error_(t.fn)
 		switch {
 		case t.err == "" && err == "":

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-golang/golang.git



More information about the pkg-golang-commits mailing list