[Pkg-golang-commits] [golang] 01/03: Imported Upstream version 1.8~beta2

Michael Hudson-Doyle mwhudson-guest at moszumanska.debian.org
Mon Jan 16 02:07:58 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 051e65f7a08fc4c88715703c17427ed4b0edf00d
Author: Michael Hudson-Doyle <michael.hudson at canonical.com>
Date:   Tue Dec 20 11:36:29 2016 +1300

    Imported Upstream version 1.8~beta2
---
 AUTHORS                                            |  17 +
 CONTRIBUTORS                                       |  21 ++
 VERSION                                            |   2 +-
 api/except.txt                                     |   4 +
 api/go1.8.txt                                      |  25 +-
 doc/conduct.html                                   |   1 -
 doc/devel/release.html                             |  25 +-
 doc/devel/weekly.html                              |   6 +-
 doc/go1.8.html                                     | 397 +++++++++++----------
 doc/go1.8.txt                                      |   1 -
 doc/help.html                                      |   7 +-
 doc/install-source.html                            |  31 +-
 doc/install.html                                   |   4 +-
 misc/cgo/test/cgo_unix_test.go                     |   1 +
 misc/cgo/test/issue17537.go                        |  16 +
 misc/cgo/test/issue18146.go                        | 103 ++++++
 misc/cgo/test/issue9400/asm_mipsx.s                |  31 ++
 misc/cgo/testcarchive/carchive_test.go             |  19 -
 misc/cgo/testcarchive/main2.c                      |  36 +-
 misc/cgo/testcarchive/main3.c                      |   7 -
 misc/cgo/testcarchive/main5.c                      |  18 -
 misc/cgo/testcarchive/src/libgo2/libgo2.go         |  30 --
 misc/cgo/testcarchive/src/libgo3/libgo3.go         |  12 -
 misc/cgo/testplugin/src/plugin1/plugin1.go         |   5 +-
 misc/cgo/testplugin/src/plugin2/plugin2.go         |  13 +-
 misc/cgo/testsanitizers/test.bash                  |   1 +
 misc/cgo/testsanitizers/tsan9.go                   |  60 ++++
 misc/cgo/testshared/src/exe/exe.go                 |   5 +
 src/cmd/cgo/gcc.go                                 |  11 +
 src/cmd/compile/internal/gc/inl.go                 |   6 +
 src/cmd/compile/internal/gc/noder.go               |   5 +-
 src/cmd/compile/internal/gc/pgen.go                |   3 +
 src/cmd/compile/internal/gc/sinit.go               |   4 +-
 src/cmd/compile/internal/gc/subr.go                |   2 +
 src/cmd/compile/internal/gc/syntax.go              |   1 +
 src/cmd/compile/internal/gc/testdata/array.go      |   4 +-
 src/cmd/compile/internal/gc/testdata/string.go     |   6 +-
 src/cmd/compile/internal/ssa/export_test.go        |   9 +-
 src/cmd/compile/internal/ssa/type_test.go          |   2 +-
 src/cmd/compile/internal/ssa/writebarrier.go       |  58 ++-
 src/cmd/compile/internal/ssa/writebarrier_test.go  |  29 ++
 src/cmd/compile/internal/syntax/parser.go          |   2 -
 src/cmd/dist/build.go                              |   4 +-
 src/cmd/dist/test.go                               |  36 +-
 src/cmd/dist/test_linux.go                         |  27 ++
 src/cmd/dist/util.go                               |   8 +
 src/cmd/dist/util_gc.go                            |   5 +
 src/cmd/dist/util_gccgo.go                         |   2 +
 src/cmd/dist/vfp_arm.s                             |   9 +
 src/cmd/dist/vfp_default.s                         |   3 +
 src/cmd/go/bug.go                                  |   6 +-
 src/cmd/go/build.go                                |  27 +-
 src/cmd/go/get.go                                  |  54 +--
 src/cmd/go/go_test.go                              |  39 +-
 src/cmd/go/pkg.go                                  |   4 +-
 src/cmd/go/test.go                                 |  15 +-
 .../go/testdata/testterminal18153/terminal_test.go |  39 ++
 src/cmd/go/vendor_test.go                          |  36 ++
 src/cmd/internal/obj/{obj.go => line.go}           |   0
 src/cmd/internal/obj/mips/obj0.go                  |  38 ++
 src/cmd/internal/obj/pcln.go                       |  13 +-
 src/cmd/internal/obj/reloctype_string.go           |   4 +-
 src/cmd/internal/obj/x86/obj6.go                   |  24 +-
 src/cmd/internal/objfile/goobj.go                  |  51 ++-
 src/cmd/link/doc.go                                |   2 +
 src/cmd/link/internal/ld/config.go                 |   2 +-
 src/cmd/link/internal/ld/data.go                   |  10 +-
 src/cmd/link/internal/ld/elf.go                    |   7 +-
 src/cmd/link/internal/ld/lib.go                    |  47 ++-
 src/cmd/link/internal/ld/link.go                   |   2 +-
 src/cmd/link/internal/ld/macho.go                  |  37 +-
 src/cmd/link/internal/ld/pcln.go                   |  18 +-
 src/cmd/link/internal/ld/symtab.go                 |   3 +-
 src/cmd/link/internal/mips/asm.go                  | 107 +++++-
 src/cmd/objdump/objdump_test.go                    |   2 +-
 src/cmd/pprof/internal/driver/driver.go            |  24 +-
 src/cmd/pprof/internal/svg/svgpan.go               |   2 +-
 src/cmd/vet/structtag.go                           |  25 +-
 src/cmd/vet/testdata/structtag.go                  |  24 +-
 src/context/context_test.go                        |   4 +-
 src/crypto/aes/cipher_s390x.go                     |   2 +-
 src/crypto/aes/const.go                            |   7 +
 src/crypto/aes/gcm_s390x.go                        |   2 +-
 src/crypto/cipher/gcm.go                           |   6 +-
 src/crypto/dsa/dsa.go                              |  20 +-
 src/crypto/dsa/dsa_test.go                         |  38 ++
 src/crypto/elliptic/elliptic.go                    |   6 +
 src/crypto/elliptic/p224.go                        |   4 +-
 src/crypto/rsa/rsa.go                              |   2 +
 src/crypto/x509/root_cgo_darwin.go                 |  81 ++++-
 src/crypto/x509/root_darwin.go                     | 114 +++++-
 src/crypto/x509/root_darwin_test.go                |  12 +-
 src/crypto/x509/verify.go                          |   4 +-
 src/crypto/x509/x509.go                            |   9 +-
 src/crypto/x509/x509_test.go                       |  24 +-
 src/database/sql/convert.go                        |  19 +
 src/database/sql/ctxutil.go                        |  31 +-
 src/database/sql/driver/driver.go                  |  56 ++-
 src/database/sql/fakedb_test.go                    |   4 +-
 src/database/sql/internal/types.go                 |  11 -
 src/database/sql/sql.go                            |  80 +++--
 src/database/sql/sql_test.go                       |  37 +-
 src/debug/gosym/pclntab.go                         |   7 -
 src/encoding/asn1/marshal.go                       |   2 +-
 src/fmt/fmt_test.go                                |  27 +-
 src/fmt/print.go                                   |  23 +-
 src/go/build/build.go                              |   5 +-
 src/go/build/deps_test.go                          |   2 +-
 src/go/internal/gccgoimporter/importer_test.go     |   7 +-
 src/go/internal/gccgoimporter/parser.go            |  16 +-
 src/go/internal/gccgoimporter/testdata/time.gox    | Bin 0 -> 7977 bytes
 src/go/internal/gccgoimporter/testdata/unicode.gox | Bin 0 -> 7945 bytes
 src/html/template/js.go                            |   6 +-
 src/html/template/js_test.go                       |   1 +
 src/io/io.go                                       |   1 +
 src/io/multi.go                                    |  12 +-
 src/io/multi_test.go                               |  24 ++
 src/math/big/int.go                                |   5 +-
 src/net/dial.go                                    |  11 +
 src/net/http/client.go                             |  35 +-
 src/net/http/client_test.go                        |  74 ++++
 src/net/http/h2_bundle.go                          | 224 ++++++++----
 src/net/http/httptrace/trace.go                    |   3 +-
 src/net/http/request.go                            |  14 +-
 src/net/http/request_test.go                       |  15 +-
 src/net/http/requestwrite_test.go                  |  10 +-
 src/net/http/transport.go                          |  20 +-
 src/net/ip.go                                      |  11 +-
 src/net/lookup_unix.go                             |  12 +-
 src/net/port_unix.go                               |   5 +-
 src/net/writev_test.go                             |   2 +-
 src/os/exec/exec_test.go                           |  14 +-
 src/os/file.go                                     |   2 +-
 src/os/os_test.go                                  |  91 ++---
 src/os/path_windows.go                             |   7 +-
 src/os/signal/doc.go                               |   9 +-
 src/plugin/plugin.go                               |   2 +-
 src/reflect/example_test.go                        |  41 +++
 src/runtime/asm_amd64.s                            |   2 +-
 src/runtime/asm_mipsx.s                            | 206 ++++++++++-
 src/runtime/cgo/asm_mipsx.s                        |  67 ++++
 src/runtime/cgo/gcc_darwin_386.c                   |   3 +-
 src/runtime/cgo/gcc_darwin_amd64.c                 |   3 +-
 src/runtime/cgo/gcc_darwin_arm.c                   |   3 +-
 src/runtime/cgo/gcc_darwin_arm64.c                 |   3 +-
 src/runtime/cgo/gcc_dragonfly_amd64.c              |   3 +-
 src/runtime/cgo/gcc_freebsd_386.c                  |   3 +-
 src/runtime/cgo/gcc_freebsd_amd64.c                |   3 +-
 src/runtime/cgo/gcc_freebsd_arm.c                  |   3 +-
 src/runtime/cgo/gcc_libinit.c                      |  25 +-
 src/runtime/cgo/gcc_libinit_openbsd.c              |  24 ++
 src/runtime/cgo/gcc_linux_386.c                    |   3 +-
 src/runtime/cgo/gcc_linux_amd64.c                  |   3 +-
 src/runtime/cgo/gcc_linux_arm.c                    |   3 +-
 src/runtime/cgo/gcc_linux_arm64.c                  |   3 +-
 src/runtime/cgo/gcc_linux_mips64x.c                |   3 +-
 .../cgo/{gcc_linux_mips64x.c => gcc_linux_mipsx.c} |   7 +-
 src/runtime/cgo/gcc_linux_ppc64x.c                 |   3 +-
 src/runtime/cgo/gcc_linux_s390x.c                  |   3 +-
 src/runtime/cgo/gcc_mipsx.S                        |  68 ++++
 src/runtime/cgo/gcc_netbsd_386.c                   |   3 +-
 src/runtime/cgo/gcc_netbsd_amd64.c                 |   3 +-
 src/runtime/cgo/gcc_netbsd_arm.c                   |   3 +-
 src/runtime/cgo/gcc_openbsd_386.c                  |   3 +-
 src/runtime/cgo/gcc_openbsd_amd64.c                |   3 +-
 src/runtime/cgo/gcc_signal_darwin_armx.c           |   3 +-
 src/runtime/cgo/gcc_solaris_amd64.c                |   3 +-
 src/runtime/cgo/libcgo_unix.h                      |  15 +
 src/runtime/cgocall.go                             |   6 +-
 src/runtime/crash_cgo_test.go                      |   2 -
 src/runtime/iface.go                               |   2 +-
 src/runtime/malloc_test.go                         |  11 +-
 src/runtime/mgc.go                                 |   9 +-
 src/runtime/mstats.go                              |   7 +-
 src/runtime/os_windows.go                          |   4 +-
 src/runtime/panic.go                               |   2 +-
 src/runtime/plugin.go                              |  32 ++
 src/runtime/pprof/pprof.go                         |  12 +-
 src/runtime/rt0_linux_mipsx.s                      |   9 +-
 src/runtime/runtime-gdb_test.go                    |  19 +-
 src/runtime/runtime_test.go                        |   9 +
 src/runtime/signal_unix.go                         | 102 ++++--
 src/runtime/stack.go                               |  25 ++
 src/runtime/symtab.go                              |   2 +-
 src/runtime/sys_openbsd_386.s                      |   9 +-
 src/runtime/sys_openbsd_amd64.s                    |   7 +-
 src/runtime/sys_openbsd_arm.s                      |   7 +-
 src/runtime/tls_mipsx.s                            |  10 +-
 src/sort/example_test.go                           |  19 +
 src/syscall/zsysnum_openbsd_386.go                 |   2 +-
 src/syscall/zsysnum_openbsd_amd64.go               |   2 +-
 src/syscall/zsysnum_openbsd_arm.go                 |   2 +-
 src/testing/benchmark.go                           |   4 -
 src/testing/sub_test.go                            |  51 ++-
 src/testing/testing.go                             |  35 +-
 src/testing/testing_test.go                        |  38 +-
 src/time/format.go                                 |   5 +-
 src/time/format_test.go                            |   1 +
 .../chacha20poly1305/chacha20poly1305_amd64.s      |  18 +-
 test/bench/go1/fasta_test.go                       |   4 +-
 test/fixedbugs/bug500.go                           |  41 +++
 test/fixedbugs/bug501.go                           |  24 ++
 test/fixedbugs/issue10607.go                       |   2 +-
 test/fixedbugs/issue11656.go                       |   4 +-
 .../plugin2.go => test/fixedbugs/issue13263.go     |  23 +-
 test/fixedbugs/issue16130.go                       |   2 +-
 test/fixedbugs/issue18149.go                       |  33 ++
 207 files changed, 3126 insertions(+), 1059 deletions(-)

diff --git a/AUTHORS b/AUTHORS
index cb487d5..6e61db2 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -45,6 +45,7 @@ Alex Sergeyev <abc at alexsergeyev.com>
 Alexander Demakin <alexander.demakin at gmail.com>
 Alexander Döring <email at alexd.ch>
 Alexander Larsson <alexander.larsson at gmail.com>
+Alexander Menzhinsky <amenzhinsky at gmail.com>
 Alexander Morozov <lk4d4math at gmail.com>
 Alexander Neumann <alexander at bumpern.de>
 Alexander Orlov <alexander.orlov at loxal.net>
@@ -98,6 +99,7 @@ Anthony Canino <anthony.canino1 at gmail.com>
 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>
 Apisak Darakananda <pongad at gmail.com>
 Aram Hăvărneanu <aram at mgk.ro>
 Areski Belaid <areski at gmail.com>
@@ -163,6 +165,7 @@ Chris Jones <chris at cjones.org>
 Chris Kastorff <encryptio at gmail.com>
 Chris Lennert <calennert at gmail.com>
 Chris McGee <sirnewton_01 at yahoo.ca> <newton688 at gmail.com>
+Chris Stockton <chrisstocktonaz at gmail.com>
 Christian Couder <chriscool at tuxfamily.org>
 Christian Himpel <chressie at googlemail.com>
 Christine Hansmann <chhansmann at gmail.com>
@@ -258,6 +261,7 @@ Egon Elbre <egonelbre at gmail.com>
 Ehren Kret <ehren.kret at gmail.com>
 Eivind Uggedal <eivind at uggedal.com>
 Elias Naur <elias.naur at gmail.com>
+Elliot Morrison-Reed <elliotmr at gmail.com>
 Emil Hessman <c.emil.hessman at gmail.com> <emil at hessman.se>
 Emmanuel Odeke <emm.odeke at gmail.com> <odeke at ualberta.ca>
 Empirical Interfaces Inc.
@@ -395,6 +399,7 @@ Jens Frederich <jfrederich at gmail.com>
 Jeremy Jackins <jeremyjackins at gmail.com>
 Jeroen Bobbeldijk <jerbob92 at gmail.com>
 Jess Frazelle <me at jessfraz.com>
+Jesse Szwedko <jesse.szwedko at gmail.com>
 Jihyun Yu <yjh0502 at gmail.com>
 Jim McGrath <jimmc2 at gmail.com>
 Jimmy Zelinskie <jimmyzelinskie at gmail.com>
@@ -429,6 +434,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>
+Jordan Lewis <jordanthelewis at gmail.com>
 Jose Luis Vázquez González <josvazg at gmail.com>
 Joseph Holsten <joseph at josephholsten.com>
 Josh Bleecher Snyder <josharian at gmail.com>
@@ -450,6 +456,8 @@ Kamil Kisiel <kamil at kamilkisiel.net> <kamil.kisiel at gmail.com>
 Kang Hu <hukangustc at gmail.com>
 Kato Kazuyoshi <kato.kazuyoshi at gmail.com>
 Katrina Owen <katrina.owen at gmail.com>
+Kaviraj Kanagaraj <kavirajkanagaraj at gmail.com>
+Keegan Carruthers-Smith <keegan.csmith at gmail.com>
 Kei Son <hey.calmdown at gmail.com>
 Keith Ball <inflatablewoman at gmail.com>
 Keith Rarick <kr at xph.us>
@@ -497,7 +505,9 @@ Manfred Touron <m at 42.am>
 Manu S Ajith <neo at codingarena.in>
 Manuel Mendez <mmendez534 at gmail.com>
 Marc Weistroff <marc at weistroff.net>
+Marcel Edmund Franke <marcel.edmund.franke at gmail.com>
 Marco Hennings <marco.hennings at freiheit.com>
+Marin Bašić <marin.basic02 at gmail.com>
 Mark Bucciarelli <mkbucc at gmail.com>
 Mark Severson <miquella at gmail.com>
 Mark Theunissen <mark.theunissen at gmail.com>
@@ -535,6 +545,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>
+Max Riveiro <kavu13 at gmail.com>
 Maxim Khitrov <max at mxcrypt.com>
 Maxwell Krohn <themax at gmail.com>
 MediaMath, Inc
@@ -610,6 +621,7 @@ Niko Dziemba <niko at dziemba.com>
 Nikolay Turpitko <nikolay at turpitko.com>
 Noah Campbell <noahcampbell at gmail.com>
 Norberto Lopes <nlopes.ml at gmail.com>
+Odin Ugedal <odin at ugedal.com>
 Oleg Vakheta <helginet at gmail.com>
 Oleku Konko <oleku.konko at gmail.com>
 Oling Cat <olingcat at gmail.com>
@@ -630,6 +642,7 @@ Pascal S. de Kloe <pascal at quies.net>
 Patrick Crosby <patrick at stathat.com>
 Patrick Gavlin <pgavlin at gmail.com>
 Patrick Higgins <patrick.allen.higgins at gmail.com>
+Patrick Lee <pattyshack101 at gmail.com>
 Patrick Mézard <patrick at mezard.eu>
 Patrick Mylund Nielsen <patrick at patrickmn.com>
 Patrick Smith <pat42smith at gmail.com>
@@ -710,6 +723,7 @@ Ryan Hitchman <hitchmanr at gmail.com>
 Ryan Lower <rpjlower at gmail.com>
 Ryan Seys <ryan at ryanseys.com>
 Ryan Slade <ryanslade at gmail.com>
+Ryuzo Yamamoto <ryuzo.yamamoto at gmail.com>
 S.Çağlar Onur <caglar at 10ur.org>
 Salmān Aljammāz <s at 0x65.net>
 Sam Hug <samuel.b.hug at gmail.com>
@@ -767,6 +781,7 @@ Szabolcs Nagy <nsz at port70.net>
 Tad Glines <tad.glines at gmail.com>
 Taj Khattra <taj.khattra at gmail.com>
 Takeshi YAMANASHI <9.nashi at gmail.com>
+Takuya Ueda <uedatakuya at gmail.com>
 Tal Shprecher <tshprecher at gmail.com>
 Tamir Duberstein <tamird at gmail.com>
 Tarmigan Casebolt <tarmigan at gmail.com>
@@ -780,6 +795,7 @@ Thomas de Zeeuw <thomasdezeeuw at gmail.com>
 Thomas Desrosiers <thomasdesr at gmail.com>
 Thomas Kappler <tkappler at gmail.com>
 Thorben Krueger <thorben.krueger at gmail.com>
+Thordur Bjornsson <thorduri at secnorth.net>
 Tilman Dilo <tilman.dilo at gmail.com>
 Tim Cooijmans <timcooijmans at gmail.com>
 Tim Ebringer <tim.ebringer at gmail.com>
@@ -845,6 +861,7 @@ Yoshiyuki Kanno <nekotaroh at gmail.com> <yoshiyuki.kanno at stoic.co.jp>
 Yusuke Kagiwada <block.rxckin.beats at gmail.com>
 Yuusei Kuwana <kuwana at kumama.org>
 Yuval Pavel Zholkover <paulzhol at gmail.com>
+Zac Bergquist <zbergquist99 at gmail.com>
 Zemanta d.o.o.
 Zev Goldstein <zev.goldstein at gmail.com>
 Ziad Hatahet <hatahet at gmail.com>
diff --git a/CONTRIBUTORS b/CONTRIBUTORS
index 43d1d9a..64cc592 100644
--- a/CONTRIBUTORS
+++ b/CONTRIBUTORS
@@ -73,6 +73,7 @@ Alex Vaghin <crhyme at google.com>
 Alexander Demakin <alexander.demakin at gmail.com>
 Alexander Döring <email at alexd.ch>
 Alexander Larsson <alexander.larsson at gmail.com>
+Alexander Menzhinsky <amenzhinsky at gmail.com>
 Alexander Morozov <lk4d4math at gmail.com>
 Alexander Neumann <alexander at bumpern.de>
 Alexander Orlov <alexander.orlov at loxal.net>
@@ -133,6 +134,7 @@ Anthony Canino <anthony.canino1 at gmail.com>
 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 Murdaca <runcom at redhat.com>
 Apisak Darakananda <pongad at gmail.com>
 Aram Hăvărneanu <aram at mgk.ro>
@@ -233,6 +235,7 @@ Chris Kastorff <encryptio at gmail.com>
 Chris Lennert <calennert at gmail.com>
 Chris Manghane <cmang at golang.org>
 Chris McGee <sirnewton_01 at yahoo.ca> <newton688 at gmail.com>
+Chris Stockton <chrisstocktonaz at gmail.com>
 Chris Zou <chriszou at ca.ibm.com>
 Christian Couder <chriscool at tuxfamily.org>
 Christian Himpel <chressie at googlemail.com> <chressie at gmail.com>
@@ -305,6 +308,7 @@ David Glasser <glasser at meteor.com>
 David Howden <dhowden at gmail.com>
 David Hubbard <dsp at google.com>
 David Jakob Fritz <david.jakob.fritz at gmail.com>
+David Lazar <lazard at golang.org>
 David Leon Gil <coruus at gmail.com>
 David McLeish <davemc at google.com>
 David Presotto <presotto at gmail.com>
@@ -360,6 +364,7 @@ Egon Elbre <egonelbre at gmail.com>
 Ehren Kret <ehren.kret at gmail.com>
 Eivind Uggedal <eivind at uggedal.com>
 Elias Naur <elias.naur at gmail.com>
+Elliot Morrison-Reed <elliotmr at gmail.com>
 Emil Hessman <c.emil.hessman at gmail.com> <emil at hessman.se>
 Emmanuel Odeke <emm.odeke at gmail.com> <odeke at ualberta.ca>
 Eoghan Sherry <ejsherry at gmail.com>
@@ -470,6 +475,7 @@ Ian Gudger <ian at loosescre.ws>
 Ian Lance Taylor <iant at golang.org>
 Icarus Sparry <golang at icarus.freeuk.com>
 Idora Shinatose <idora.shinatose at gmail.com>
+Igor Bernstein <igorbernstein at google.com>
 Igor Dolzhikov <bluesriverz at gmail.com>
 Ilya Tocar <ilya.tocar at intel.com>
 INADA Naoki <songofacandy at gmail.com>
@@ -537,6 +543,7 @@ Jeremy Jackins <jeremyjackins at gmail.com>
 Jeremy Schlatter <jeremy.schlatter at gmail.com>
 Jeroen Bobbeldijk <jerbob92 at gmail.com>
 Jess Frazelle <me at jessfraz.com>
+Jesse Szwedko <jesse.szwedko at gmail.com>
 Jihyun Yu <yjh0502 at gmail.com>
 Jim Cote <jfcote87 at gmail.com>
 Jim Kingdon <jim at bolt.me>
@@ -586,6 +593,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>
+Jordan Lewis <jordanthelewis at gmail.com>
 Jos Visser <josv at google.com>
 Jose Luis Vázquez González <josvazg at gmail.com>
 Joseph Bonneau <jcb at google.com>
@@ -617,8 +625,10 @@ Kang Hu <hukangustc at gmail.com>
 Karan Dhiman <karandhi at ca.ibm.com>
 Kato Kazuyoshi <kato.kazuyoshi at gmail.com>
 Katrina Owen <katrina.owen at gmail.com>
+Kaviraj Kanagaraj <kavirajkanagaraj at gmail.com>
 Kay Zhu <kayzhu at google.com>
 KB Sriram <kbsriram at google.com>
+Keegan Carruthers-Smith <keegan.csmith at gmail.com>
 Kei Son <hey.calmdown at gmail.com>
 Keith Ball <inflatablewoman at gmail.com>
 Keith Randall <khr at golang.org>
@@ -678,9 +688,11 @@ Manu S Ajith <neo at codingarena.in>
 Manuel Mendez <mmendez534 at gmail.com>
 Marc Weistroff <marc at weistroff.net>
 Marc-Antoine Ruel <maruel at chromium.org>
+Marcel Edmund Franke <marcel.edmund.franke at gmail.com>
 Marcel van Lohuizen <mpvl at golang.org>
 Marco Hennings <marco.hennings at freiheit.com>
 Marga Manterola <marga at google.com>
+Marin Bašić <marin.basic02 at gmail.com>
 Marius Nuennerich <mnu at google.com>
 Mark Bucciarelli <mkbucc at gmail.com>
 Mark Severson <miquella at gmail.com>
@@ -695,6 +707,7 @@ Markus Zimmermann <zimmski at gmail.com>
 Martin Bertschler <mbertschler at gmail.com>
 Martin Garton <garton at gmail.com>
 Martin Hamrle <martin.hamrle at gmail.com>
+Martin Kreichgauer <martinkr at google.com>
 Martin Möhrmann <moehrmann at google.com> <martisch at uos.de>
 Martin Neubauer <m.ne at gmx.net>
 Martin Olsson <martin at minimum.se>
@@ -723,6 +736,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>
+Max Riveiro <kavu13 at gmail.com>
 Maxim Khitrov <max at mxcrypt.com>
 Maxim Pimenov <mpimenov at google.com>
 Maxim Ushakov <ushakov at google.com>
@@ -819,6 +833,7 @@ Nikolay Turpitko <nikolay at turpitko.com>
 Noah Campbell <noahcampbell at gmail.com>
 Nodir Turakulov <nodir at google.com>
 Norberto Lopes <nlopes.ml at gmail.com>
+Odin Ugedal <odin at ugedal.com>
 Oleg Vakheta <helginet at gmail.com>
 Oleku Konko <oleku.konko at gmail.com>
 Oling Cat <olingcat at gmail.com>
@@ -837,6 +852,7 @@ Pascal S. de Kloe <pascal at quies.net>
 Patrick Crosby <patrick at stathat.com>
 Patrick Gavlin <pgavlin at gmail.com>
 Patrick Higgins <patrick.allen.higgins at gmail.com>
+Patrick Lee <pattyshack101 at gmail.com>
 Patrick Mézard <patrick at mezard.eu>
 Patrick Mylund Nielsen <patrick at patrickmn.com>
 Patrick Riley <pfr at google.com>
@@ -903,6 +919,7 @@ Ralph Corderoy <ralph at inputplus.co.uk>
 Ramesh Dharan <dharan at google.com>
 Raph Levien <raph at google.com>
 Raul Silvera <rsilvera at google.com>
+Rebecca Stambler <rstambler at golang.org>
 Reinaldo de Souza Jr <juniorz at gmail.com>
 Rémy Oudompheng <oudomphe at phare.normalesup.org> <remyoudompheng at gmail.com>
 Rhys Hiltner <rhys at justin.tv>
@@ -949,6 +966,7 @@ Ryan Hitchman <hitchmanr at gmail.com>
 Ryan Lower <rpjlower at gmail.com>
 Ryan Seys <ryan at ryanseys.com>
 Ryan Slade <ryanslade at gmail.com>
+Ryuzo Yamamoto <ryuzo.yamamoto at gmail.com>
 S.Çağlar Onur <caglar at 10ur.org>
 Sai Cheemalapati <saicheems at google.com>
 Salmān Aljammāz <s at 0x65.net>
@@ -1029,6 +1047,7 @@ Tad Glines <tad.glines at gmail.com>
 Taj Khattra <taj.khattra at gmail.com>
 Takashi Matsuo <tmatsuo at google.com>
 Takeshi YAMANASHI <9.nashi at gmail.com>
+Takuya Ueda <uedatakuya at gmail.com>
 Tal Shprecher <tshprecher at gmail.com>
 Tamir Duberstein <tamird at gmail.com>
 Tarmigan Casebolt <tarmigan at gmail.com>
@@ -1044,6 +1063,7 @@ Thomas Desrosiers <thomasdesr at gmail.com>
 Thomas Habets <habets at google.com>
 Thomas Kappler <tkappler at gmail.com>
 Thorben Krueger <thorben.krueger at gmail.com>
+Thordur Bjornsson <thorduri at secnorth.net>
 Tilman Dilo <tilman.dilo at gmail.com>
 Tim Cooijmans <timcooijmans at gmail.com>
 Tim Ebringer <tim.ebringer at gmail.com>
@@ -1132,6 +1152,7 @@ Yusuke Kagiwada <block.rxckin.beats at gmail.com>
 Yuusei Kuwana <kuwana at kumama.org>
 Yuval Pavel Zholkover <paulzhol at gmail.com>
 Yves Junqueira <yvesj at google.com> <yves.junqueira at gmail.com>
+Zac Bergquist <zbergquist99 at gmail.com>
 Zev Goldstein <zev.goldstein at gmail.com>
 Zhongwei Yao <zhongwei.yao at arm.com>
 Ziad Hatahet <hatahet at gmail.com>
diff --git a/VERSION b/VERSION
index 6ec9dfa..de57d7f 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-go1.8beta1
\ No newline at end of file
+go1.8beta2
\ No newline at end of file
diff --git a/api/except.txt b/api/except.txt
index 2062cbf..857ebb5 100644
--- a/api/except.txt
+++ b/api/except.txt
@@ -338,3 +338,7 @@ pkg unicode, const Version = "6.2.0"
 pkg unicode, const Version = "6.3.0"
 pkg unicode, const Version = "7.0.0"
 pkg unicode, const Version = "8.0.0"
+pkg syscall (openbsd-386), const SYS_KILL = 37
+pkg syscall (openbsd-386-cgo), const SYS_KILL = 37
+pkg syscall (openbsd-amd64), const SYS_KILL = 37
+pkg syscall (openbsd-amd64-cgo), const SYS_KILL = 37
diff --git a/api/go1.8.txt b/api/go1.8.txt
index e9ddc28..5e21b07 100644
--- a/api/go1.8.txt
+++ b/api/go1.8.txt
@@ -73,10 +73,8 @@ pkg database/sql, const LevelSnapshot = 5
 pkg database/sql, const LevelSnapshot IsolationLevel
 pkg database/sql, const LevelWriteCommitted = 3
 pkg database/sql, const LevelWriteCommitted IsolationLevel
-pkg database/sql/driver, func IsolationFromContext(context.Context) (IsolationLevel, bool)
-pkg database/sql/driver, func ReadOnlyFromContext(context.Context) bool
-pkg database/sql/driver, type ConnBeginContext interface { BeginContext }
-pkg database/sql/driver, type ConnBeginContext interface, BeginContext(context.Context) (Tx, error)
+pkg database/sql/driver, type ConnBeginTx interface { BeginTx }
+pkg database/sql/driver, type ConnBeginTx interface, BeginTx(context.Context, TxOptions) (Tx, error)
 pkg database/sql/driver, type ConnPrepareContext interface { PrepareContext }
 pkg database/sql/driver, type ConnPrepareContext interface, PrepareContext(context.Context, string) (Stmt, error)
 pkg database/sql/driver, type ExecerContext interface { ExecContext }
@@ -125,16 +123,17 @@ pkg database/sql/driver, type StmtExecContext interface { ExecContext }
 pkg database/sql/driver, type StmtExecContext interface, ExecContext(context.Context, []NamedValue) (Result, error)
 pkg database/sql/driver, type StmtQueryContext interface { QueryContext }
 pkg database/sql/driver, type StmtQueryContext interface, QueryContext(context.Context, []NamedValue) (Rows, error)
-pkg database/sql, func IsolationContext(context.Context, IsolationLevel) context.Context
+pkg database/sql/driver, type TxOptions struct
+pkg database/sql/driver, type TxOptions struct, Isolation IsolationLevel
+pkg database/sql/driver, type TxOptions struct, ReadOnly bool
 pkg database/sql, func Named(string, interface{}) NamedArg
-pkg database/sql, func ReadOnlyContext(context.Context) context.Context
 pkg database/sql, method (*ColumnType) DatabaseTypeName() string
 pkg database/sql, method (*ColumnType) DecimalSize() (int64, int64, bool)
 pkg database/sql, method (*ColumnType) Length() (int64, bool)
 pkg database/sql, method (*ColumnType) Name() string
 pkg database/sql, method (*ColumnType) Nullable() (bool, bool)
 pkg database/sql, method (*ColumnType) ScanType() reflect.Type
-pkg database/sql, method (*DB) BeginContext(context.Context) (*Tx, error)
+pkg database/sql, method (*DB) BeginTx(context.Context, *TxOptions) (*Tx, error)
 pkg database/sql, method (*DB) ExecContext(context.Context, string, ...interface{}) (Result, error)
 pkg database/sql, method (*DB) PingContext(context.Context) error
 pkg database/sql, method (*DB) PrepareContext(context.Context, string) (*Stmt, error)
@@ -155,7 +154,9 @@ pkg database/sql, type IsolationLevel int
 pkg database/sql, type NamedArg struct
 pkg database/sql, type NamedArg struct, Name string
 pkg database/sql, type NamedArg struct, Value interface{}
-pkg debug/gosym, func PCValue([]uint8, uint64, int) int
+pkg database/sql, type TxOptions struct
+pkg database/sql, type TxOptions struct, Isolation IsolationLevel
+pkg database/sql, type TxOptions struct, ReadOnly bool
 pkg debug/pe, method (*COFFSymbol) FullName(StringTable) (string, error)
 pkg debug/pe, method (StringTable) String(uint32) (string, error)
 pkg debug/pe, type File struct, COFFSymbols []COFFSymbol
@@ -239,21 +240,23 @@ pkg plugin, type Symbol interface {}
 pkg reflect, func Swapper(interface{}) func(int, int)
 pkg runtime, func MutexProfile([]BlockProfileRecord) (int, bool)
 pkg runtime, func SetMutexProfileFraction(int) int
+pkg runtime, type MemStats struct, NumForcedGC uint32
 pkg sort, func Slice(interface{}, func(int, int) bool)
 pkg sort, func SliceIsSorted(interface{}, func(int, int) bool) bool
 pkg sort, func SliceStable(interface{}, func(int, int) bool)
 pkg syscall (linux-arm-cgo), func TimevalToNsec(Timeval) int64
 pkg syscall (linux-arm), func TimevalToNsec(Timeval) int64
+pkg syscall (openbsd-386), const SYS_KILL = 122
+pkg syscall (openbsd-386-cgo), const SYS_KILL = 122
+pkg syscall (openbsd-amd64), const SYS_KILL = 122
+pkg syscall (openbsd-amd64-cgo), const SYS_KILL = 122
 pkg syscall (windows-386), const ERROR_DIR_NOT_EMPTY = 145
 pkg syscall (windows-386), const ERROR_DIR_NOT_EMPTY Errno
 pkg syscall (windows-amd64), const ERROR_DIR_NOT_EMPTY = 145
 pkg syscall (windows-amd64), const ERROR_DIR_NOT_EMPTY Errno
 pkg testing, func CoverMode() string
 pkg testing, func MainStart(testDeps, []InternalTest, []InternalBenchmark, []InternalExample) *M
-pkg testing, method (*B) Context() context.Context
 pkg testing, method (*B) Name() string
-pkg testing, method (*T) Context() context.Context
 pkg testing, method (*T) Name() string
-pkg testing, type TB interface, Context() context.Context
 pkg testing, type TB interface, Name() string
 pkg time, func Until(Time) Duration
diff --git a/doc/conduct.html b/doc/conduct.html
index c749266..5b81681 100644
--- a/doc/conduct.html
+++ b/doc/conduct.html
@@ -67,7 +67,6 @@ official forums operated by the Go project (“Go spaces”):
     <li>The <a href="https://groups.google.com/group/golang-nuts">golang-nuts</a> and
         <a href="https://groups.google.com/group/golang-dev">golang-dev</a> mailing lists.
 <li>The #go-nuts IRC channel on Freenode.
-<li>The <a href="https://reddit.com/r/golang">/r/golang subreddit</a>.
 </ul>
 
 <p>
diff --git a/doc/devel/release.html b/doc/devel/release.html
index 773f889..51957df 100644
--- a/doc/devel/release.html
+++ b/doc/devel/release.html
@@ -50,11 +50,23 @@ See the <a href="https://github.com/golang/go/issues?q=milestone%3AGo1.7.1">Go
 </p>
 
 <p>
-go1.7.2 (released 2016/10/17) includes fixes to the compiler, runtime,
+go1.7.2 should not be used. It was tagged but not fully released.
+The release was deferred due to a last minute bug report.
+Use go1.7.3 instead, and refer to the summary of changes below.
+</p>
+
+<p>
+go1.7.3 (released 2016/10/19) includes fixes to the compiler, runtime,
 and the <code>crypto/cipher</code>, <code>crypto/tls</code>,
 <code>net/http</code>, and <code>strings</code> packages.
-See the <a href="https://github.com/golang/go/issues?q=milestone%3AGo1.7.2">Go
-1.7.2 milestone</a> on our issue tracker for details.
+See the <a href="https://github.com/golang/go/issues?q=milestone%3AGo1.7.3">Go
+1.7.3 milestone</a> on our issue tracker for details.
+</p>
+
+<p>
+go1.7.4 (released 2016/12/01) includes two security fixes.
+See the <a href="https://github.com/golang/go/issues?q=milestone%3AGo1.7.4">Go
+1.7.4 milestone</a> on our issue tracker for details.
 </p>
 
 <h2 id="go1.6">go1.6 (released 2016/02/17)</h2>
@@ -88,6 +100,13 @@ See the <a href="https://github.com/golang/go/issues?q=milestone%3AGo1.6.3">Go
 1.6.3 milestone</a> on our issue tracker for details.
 </p>
 
+<p>
+go1.6.4 (released 2016/12/01) includes two security fixes.
+It contains the same fixes as Go 1.7.4 and was released at the same time.
+See the <a href="https://github.com/golang/go/issues?q=milestone%3AGo1.7.4">Go
+1.7.4 milestone</a> on our issue tracker for details.
+</p>
+
 <h2 id="go1.5">go1.5 (released 2015/08/19)</h2>
 
 <p>
diff --git a/doc/devel/weekly.html b/doc/devel/weekly.html
index 7166a76..e17461d 100644
--- a/doc/devel/weekly.html
+++ b/doc/devel/weekly.html
@@ -519,7 +519,7 @@ Other changes:
 	fix FreeBSD signal handling around thread creation (thanks Devon H. O'Dell),
 	goroutine profile, stack dumps,
 	implement runtime.osyield on FreeBSD 386, amd64 (thanks Devon H. O'Dell),
-	permit default behaviour of SIGTSTP, SIGTTIN, SIGTTOU,
+	permit default behavior of SIGTSTP, SIGTTIN, SIGTTOU,
 	release unused memory to the OS (thanks Sébastien Paolacci),
 	remove an obsolete file (thanks Mikio Hara).
 * spec: make all comparison results untyped bool,
@@ -4157,7 +4157,7 @@ Other changes in this release:
 * suffixarray: use binary search for both ends of Lookup (thanks Eric Eisner).
 * syscall: add missing network interface constants (thanks Mikio Hara).
 * template: treat map keys as zero, not non-existent (thanks Roger Peppe).
-* time: allow cancelling of After events (thanks Roger Peppe),
+* time: allow canceling of After events (thanks Roger Peppe),
         support Solaris zoneinfo directory.
 * token/position: added SetLinesForContent.
 * unicode: update to unicode 6.0.0.
@@ -5696,7 +5696,7 @@ This release contains many changes:
 * cmath: new complex math library (thanks Charles L. Dorian).
 * docs: update to match current coding style (thanks Christopher Wedgwood).
 * exp/eval: fix example and add target to Makefile (thanks Evan Shaw).
-* fmt: change behaviour of format verb %b to match %x when negative (thanks Andrei Vieru).
+* fmt: change behavior of format verb %b to match %x when negative (thanks Andrei Vieru).
 * gc: compile s == "" as len(s) == 0,
 	distinguish fatal compiler bug from error+exit,
 	fix alignment on non-amd64,
diff --git a/doc/go1.8.html b/doc/go1.8.html
index 22176a2..1ea0188 100644
--- a/doc/go1.8.html
+++ b/doc/go1.8.html
@@ -25,7 +25,7 @@ release notes. Go 1.8 is expected to be released in February 2017.
 <p>
 The latest Go release, version 1.8, arrives six months after <a href="go1.7">Go 1.7</a>.
 Most of its changes are in the implementation of the toolchain, runtime, and libraries.
-There is one minor change to the language specification.
+There are <a href="#language">two minor changes</a> to the language specification.
 As always, the release maintains the Go 1 <a href="/doc/go1compat.html">promise of compatibility</a>.
 We expect almost all Go programs to continue to compile and run as before.
 </p>
@@ -44,8 +44,9 @@ and <a href="#sort_slice">simplifies sorting slices</a>.
 <h2 id="language">Changes to the language</h2>
 
 <p>
-  When explicitly converting a value from one struct type to another, as of Go 1. 8 the tags are ignored.
-  Thus two structs that differ only in their tags may be converted from one to the other:
+  When explicitly converting a value from one struct type to another,
+  as of Go 1.8 the tags are ignored. Thus two structs that differ
+  only in their tags may be converted from one to the other:
 </p>
 
 <pre>
@@ -76,7 +77,9 @@ func example() {
 <p>
 Go now supports 32-bit MIPS on Linux for both big-endian
 (<code>linux/mips</code>) and little-endian machines
-(<code>linux/mipsle</code>).
+(<code>linux/mipsle</code>) that implement the MIPS32r1 instruction set with FPU
+or kernel FPU emulation. Note that many common MIPS-based routers lack an FPU and
+have firmware that doesn't enable kernel FPU emulation; Go won't run on such machines.
 </p>
 
 <p>
@@ -84,6 +87,10 @@ On DragonFly BSD, Go now requires DragonFly 4.4.4 or later. <!-- CL 29491, CL 29
 </p>
 
 <p>
+On OpenBSD, Go now requires OpenBSD 5.9 or later. <!-- CL 34093 -->
+</p>
+
+<p>
 The Plan 9 port's networking support is now much more complete
 and matches the behavior of Unix and Windows with respect to deadlines
 and cancelation.
@@ -95,6 +102,18 @@ and cancelation.
   binaries on older OS X versions is untested.
 </p>
 
+<p>
+  Go 1.8 will be the last release to support Linux on ARMv5E and ARMv6 processors:
+  Go 1.9 will likely require the ARMv6K (as found in the Raspberry Pi 1) or later.
+  To identify whether a Linux system is ARMv6K or later, run
+  “<code>go</code> <code>tool</code> <code>dist</code> <code>-check-armv6k</code>”
+  (to facilitate testing, it is also possible to just copy the <code>dist</code> command to the
+  system without installing a full copy of Go 1.8)
+  and if the program terminates with output "ARMv6K supported." then the system
+  implements ARMv6K or later.
+  Go on non-Linux ARM systems already requires ARMv6K or later.
+</p>
+
 
 <h3 id="known_issues">Known Issues</h3>
 
@@ -102,8 +121,7 @@ and cancelation.
 There are some instabilities on FreeBSD and NetBSD that are known but not understood.
 These can lead to program crashes in rare cases.
 See
-<a href="https://golang.org/issue/15658">issue 15658</a>,
-<a href="https://golang.org/issue/16396">issue 16396</a>, and
+<a href="https://golang.org/issue/15658">issue 15658</a> and
 <a href="https://golang.org/issue/16511">issue 16511</a>.
 Any help in solving these issues would be appreciated.
 </p>
@@ -120,8 +138,9 @@ For 64-bit x86 systems, the following instructions have been added:
 <code>MOVSHDUP</code>,
 <code>MOVSLDUP</code>,
 <code>VMOVDDUP</code>,
-<code>VMOVSHDUP</code>,
-and <code>VMOVSLDUP</code>.</p>
+<code>VMOVSHDUP</code>, and
+<code>VMOVSLDUP</code>.
+</p>
 
 <p>
 For 64-bit PPC systems, the common vector scalar instructions have been
@@ -203,7 +222,7 @@ added:
 <code>XXSEL</code>,
 <code>XXSI</code>,
 <code>XXSLDWI</code>,
-<code>XXSPLT</code>, and 
+<code>XXSPLT</code>, and
 <code>XXSPLTW</code>.
 </p>
 
@@ -211,8 +230,8 @@ added:
 
 <p> <!-- CL 27324, CL 27325 -->
 The <code>yacc</code> tool (previously available by running
-“<code>go</code> <code>tool</code> <code>yacc</code>”)
-has been removed. As of Go 1.7 it was no longer used by the Go compiler.
+“<code>go</code> <code>tool</code> <code>yacc</code>”) has been removed.
+As of Go 1.7 it was no longer used by the Go compiler.
 It has moved to the “tools” repository and is now available at
 <code><a href="https://godoc.org/golang.org/x/tools/cmd/goyacc">golang.org/x/tools/cmd/goyacc</a></code>.
 </p>
@@ -229,7 +248,7 @@ It has moved to the “tools” repository and is now available at
 
 <p> <!-- CL 33157 -->
   The <code>pprof</code> tool can now profile TLS servers
-  and skip certificate validation by using the "<code>https+insecure</code>"
+  and skip certificate validation by using the “<code>https+insecure</code>”
   URL scheme.
 </p>
 
@@ -237,37 +256,32 @@ It has moved to the “tools” repository and is now available at
   The callgrind output now has instruction-level granularity.
 </p>
 
-<p>
-  TODO: more. proto? standalone profiles with symbols?
-<pre>
-runtime/pprof: output CPU profiles in pprof protobuf format (CL 33071)
-runtime/pprof: write profiles in protobuf format. (CL 32257)
-</pre>
-</p>
-
 <h3 id="tool_trace">Trace</h3>
 
-<p>TODO:</p>
-<pre>
-cmd/trace: add option to output pprof files (CL 23324)
-cmd/trace: fix a runnable goroutine count bug (CL 25552)
-cmd/trace: move process-wide GC events to their own row (CL 30017)
-internal/trace: fix analysis of EvGoWaiting/EvGoInSyscall events (CL 25572)
-cmd/trace: annotate different mark worker types (CL 30702)
-</pre>
+<p> <!-- CL 23324 -->
+  The <code>trace</code> tool has a new <code>-pprof</code> flag for
+  producing pprof-compatible blocking and latency profiles from an
+  execution trace.
+</p>
+
+<p> <!-- CL 30017, CL 30702 -->
+  Garbage collection events are now shown more clearly in the
+  execution trace viewer. Garbage collection activity is shown on its
+  own row and GC helper goroutines are annotated with their roles.
+</p>
 
 <h3 id="tool_vet">Vet</h3>
 
 <p>Vet is stricter in some ways and looser where it
   previously caused false positives.</p>
 
-<p>Vet now checks copying of array of locks,
+<p>Vet now checks for copying an array of locks,
   duplicate JSON and XML struct field tags,
   non-space-separated struct tags,
   deferred calls to HTTP <code>Response.Body.Close</code>
-  before checking errors,
-  indexed arguments in <code>Printf</code>,
-  and improves existing checks.</p>
+  before checking errors, and
+  indexed arguments in <code>Printf</code>.
+  It also improves existing checks.</p>
 </p>
 
 <h3 id="compiler">Compiler Toolchain</h3>
@@ -286,14 +300,14 @@ and provides a better platform for optimizations
 such as bounds check elimination.
 The new back end reduces the CPU time required by
 <a href="https://golang.org/test/bench/go1/">our benchmark programs</a> by 20-30%
-on 32-bit ARM systems. For 64-bit x86 systems, which already used the SSA backend in
+on 32-bit ARM systems. For 64-bit x86 systems, which already used the SSA back end in
 Go 1.7, the gains are a more modest 0-10%. Other architectures will likely
 see improvements closer to the 32-bit ARM numbers.
 </p>
 
 <p>
   The temporary <code>-ssa=0</code> compiler flag introduced in Go 1.7
-  to disable the new backend has been removed in Go 1.8.
+  to disable the new back end has been removed in Go 1.8.
 </p>
 
 <p>
@@ -315,7 +329,7 @@ see improvements closer to the 32-bit ARM numbers.
 
 <p> <!-- CL 29991 -->
 The environment variable <code>PKG_CONFIG</code> may now be used to
-set the program to run to handle <code>#cgo pkg-config</code>
+set the program to run to handle <code>#cgo</code> <code>pkg-config</code>
 directives.  The default is <code>pkg-config</code>, the program
 always used by earlier releases.  This is intended to make it easier
 to cross-compile
@@ -369,8 +383,8 @@ version of gccgo.
 
 <p>
   The new
-  “<a href="/cmd/go/#hdr-Print_information_for_bug_reports"><code>go</code>
-   <code>bug</code></a>” command starts a bug report on GitHub, prefilled
+  “<a href="/cmd/go/#hdr-Print_information_for_bug_reports"><code>go</code> <code>bug</code></a>”
+  command starts a bug report on GitHub, prefilled
   with information about the current system.
 </p>
 
@@ -378,9 +392,8 @@ version of gccgo.
 
 <p> <!-- CL 25419 -->
   The
-  “<a href="/cmd/go/#hdr-Show_documentation_for_package_or_symbol"><code>go</code>
-   <code>doc</code></a>” command
-  now groups constants and variables with their type,
+  “<a href="/cmd/go/#hdr-Show_documentation_for_package_or_symbol"><code>go</code> <code>doc</code></a>”
+  command now groups constants and variables with their type,
   following the behavior of
   <a href="/cmd/godoc/"><code>godoc</code></a>.
 </p>
@@ -404,7 +417,7 @@ version of gccgo.
   plugins written in Go, and a
   new <a href="/pkg/plugin/"><code>plugin</code></a> package for
   loading such plugins at run time. Plugin support is only currently
-  available on Linux and macOS.
+  available on Linux.
 </p>
 
 <h2 id="runtime">Runtime</h2>
@@ -429,10 +442,30 @@ version of gccgo.
   documentation</a> and its example for more details.
 </p>
 
+<h3 id="mapiter">Concurrent Map Misuse</h3>
+
+<p>
+In Go 1.6, the runtime
+<a href="/doc/go1.6#runtime">added lightweight,
+best-effort detection of concurrent misuse of maps</a>. This release
+improves that detector with support for detecting programs that
+concurrently write to and iterate over a map.
+</p>
+<p>
+As always, if one goroutine is writing to a map, no other goroutine should be
+reading (which includes iterating) or writing the map concurrently.
+If the runtime detects this condition, it prints a diagnosis and crashes the program.
+The best way to find out more about the problem is to run the program
+under the
+<a href="https://blog.golang.org/race-detector">race detector</a>,
+which will more reliably identify the race
+and give more detail.
+</p>
+
 <h3 id="memstats">MemStats Documentation</h3>
 
 <p> <!-- CL 28972 -->
-  The runtime's <a href="/pkg/runtime/#MemStats"><code>MemStats</code></a>
+  The <a href="/pkg/runtime/#MemStats"><code>runtime.MemStats</code></a>
   type has been more thoroughly documented.
 </p>
 
@@ -470,7 +503,7 @@ There have been optimizations to implementations in the
 <a href="/pkg/strings/"><code>strings</code></a>,
 <a href="/pkg/syscall/"><code>syscall</code></a>,
 <a href="/pkg/text/template/"><code>text/template</code></a>, and
-<a href="/pkg/unicode/utf8/"><code>unicode/utf8</code></a>,
+<a href="/pkg/unicode/utf8/"><code>unicode/utf8</code></a>
 packages.
 </p>
 
@@ -562,9 +595,6 @@ now implements the new
     takes a context argument.</li>
   <li>There have been <a href="#database_sql">significant additions</a> to the
     <a href="/pkg/database/sql/">database/sql</a> package with context support.</li>
-  <li>The new <a href="/pkg/testing/#T.Context"><code>T.Context</code></a>
-    method in the <a href="/pkg/testing/">testing</a> package now returns a context for
-    the active test or benchmark.</li>
   <li>All nine of the new <code>Lookup</code> methods on the new
     <a href="/pkg/net/#Resolver"><code>net.Resolver</code></a> now
     take a context.</li>
@@ -578,7 +608,7 @@ now implements the new
 
 <p>
   Most users will want to use the new <code>-mutexprofile</code>
-  flag with <a href="/cmd/go/#hdr-Description_of_testing_flags"><code>go</code> <code>test</code></a>,
+  flag with “<a href="/cmd/go/#hdr-Description_of_testing_flags"><code>go</code> <code>test</code></a>”,
   and then use <a href="/cmd/pprof/">pprof</a> on the resultant file.
 </p>
 
@@ -594,8 +624,8 @@ now implements the new
 <p>
 As always, there are various minor changes and updates to the library,
 made with the Go 1 <a href="/doc/go1compat">promise of compatibility</a>
-in mind. The follow sections list the user visible changes and additions.
-Optimizations and bug fixes are not listed.
+in mind. The following sections list the user visible changes and additions.
+Optimizations and minor bug fixes are not listed.
 </p>
 
 <dl id="archive_tar"><dt><a href="/pkg/archive/tar/">archive/tar</a></dt>
@@ -616,11 +646,14 @@ Optimizations and bug fixes are not listed.
   <dd>
 
     <p> <!-- CL 18274 -->
-      The zip <code>Reader</code> now supports modification times in
+      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 -->
-      When writing zip files, the Extended Time Stamp field is written
-      for files with non-zero modification times.
+      The
+      <a href="/pkg/archive/zip/#Writer"><code>Writer</code></a>
+      now writes Extended Time Stamp fields.
     </p>
 
   </dd>
@@ -633,11 +666,11 @@ Optimizations and bug fixes are not listed.
       There have been some minor fixes to the encoder to improve the
       compression ratio in certain situations. As a result, the exact
       encoded output of <code>DEFLATE</code> may be different from Go 1.7. Since
-      DEFLATE is the underlying compression of gzip, png, zlib, and zip,
+      <code>DEFLATE</code> is the underlying compression of gzip, png, zlib, and zip,
       those formats may have changed outputs.
     </p>
 
-    <p>
+    <p> <!-- CL 31174 -->
       The encoder, when operating in
       <a href="/pkg/compress/flate/#NoCompression"><code>NoCompression</code></a>
       mode, now produces a consistent output that is not dependent on
@@ -751,14 +784,14 @@ Optimizations and bug fixes are not listed.
       X25519 and <!-- CL 30824, CL 30825 -->
       ChaCha20-Poly1305.  <!-- CL 30957, CL 30958 -->
       ChaCha20-Poly1305 is now prioritized unless <!-- CL 32871 -->
-      AES-GCM when hardware support is present.
+      hardware support for AES-GCM is present.
     </p>
 
     <p> <!-- CL 27315 -->
       AES-128-CBC cipher suites with SHA-256 are also
       now supported.
     </p>
-    
+
   </dd>
 </dl>
 
@@ -799,87 +832,85 @@ crypto/x509: return error for missing SerialNumber (CL 27238)
       at <code>/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem</code>
       on Linux, to support RHEL and CentOS.
     </p>
-    
+
   </dd>
 </dl>
-    
+
 <dl id="database_sql"><dt><a href="/pkg/database/sql/">database/sql</a></dt>
   <dd>
     <p>
-	  The package now supports <code>context.Context</code>. There are new methods
-	  ending in <code>Context</code> such as
-	  <a href="/pkg/database/sql/#DB.QueryContext"><code>DB.QueryContext</code></a> and
-	  <a href="/pkg/database/sql/#DB.PrepareContext"><code>DB.PrepareContext</code></a>
-	  that take context arguments. Using the new <code>Context</code> methods ensures that
-	  connections are closed and returned to the connection pool when the
-	  request is done; enables canceling in-progress queries
-	  should the driver support that; and allows the database
-	  pool to cancel waiting for the next available connection.
+      The package now supports <code>context.Context</code>. There are new methods
+      ending in <code>Context</code> such as
+      <a href="/pkg/database/sql/#DB.QueryContext"><code>DB.QueryContext</code></a> and
+      <a href="/pkg/database/sql/#DB.PrepareContext"><code>DB.PrepareContext</code></a>
+      that take context arguments. Using the new <code>Context</code> methods ensures that
+      connections are closed and returned to the connection pool when the
+      request is done; enables canceling in-progress queries
+      should the driver support that; and allows the database
+      pool to cancel waiting for the next available connection.
     </p>
     <p>
       The <a href="/pkg/database/sql#IsolationLevel"><code>IsolationLevel</code></a>
-	  can now be set when starting a transaction by setting the isolation level
-	  on the <code>Context</code> then passing that <code>Context</code> to
-	  <a href="/pkg/database/sql#DB.BeginContext"><code>DB.BeginContext</code></a>.
-	  An error will be returned if an isolation level is selected that the driver
-	  does not support. A read-only attribute may also be set on the transaction
-	  with <a href="/pkg/database/sql/#ReadOnlyContext"><code>ReadOnlyContext</code></a>.
-	</p>
-	<p>
+      can now be set when starting a transaction by setting the isolation level
+      on the <code>Context</code> then passing that <code>Context</code> to
+      <a href="/pkg/database/sql#DB.BeginContext"><code>DB.BeginContext</code></a>.
+      An error will be returned if an isolation level is selected that the driver
+      does not support. A read-only attribute may also be set on the transaction
+      with <a href="/pkg/database/sql/#ReadOnlyContext"><code>ReadOnlyContext</code></a>.
+    </p>
+    <p>
       Queries now expose the SQL column type information for drivers that support it.
-	  Rows can return <a href="/pkg/database/sql#Rows.ColumnTypes"><code>ColumnTypes</code></a>
-	  which can include SQL type information, column type lengths, and the Go type.
-    </p>
-	<p>
-          A <a href="/pkg/database/sql/#Rows"><code>Rows</code></a>
-          can now represent multiple result sets. After
-	  <a href="/pkg/database/sql/#Rows.Next"><code>Rows.Next</code></a> returns false,
-	  <a href="/pkg/database/sql/#Rows.NextResultSet"><code>Rows.NextResultSet</code></a>
-	  may be called to advance to the next result set. The existing <code>Rows</code>
-	  should continue to be used after it advances to the next result set.
-    </p>
-	<p>
-	  <a href="/pkg/database/sql/#NamedParam"><code>NamedParam</code></a> may be used
-	  as query arguments. The new function <a href="/pkg/database/sql/#Param"><code>Param</code></a>
-	  helps create a <a href="/pkg/database/sql/#NamedParam"><code>NamedParam</code></a>
-	  more succinctly.
-	<p>
-          If a driver supports the new
-          <a href="/pkg/database/sql/driver/#Pinger"><code>Pinger</code></a>
-          interface, the <code>DB</code>'s
-	  <a href="/pkg/database/sql/#DB.Ping"><code>DB.Ping</code></a>
-	  and
-          <a href="/pkg/database/sql/#DB.PingContext"><code>DB.PingContext</code></a>
-          methods will use that interface to check whether a
-          database connection is still valid.
-	</p>
+      Rows can return <a href="/pkg/database/sql#Rows.ColumnTypes"><code>ColumnTypes</code></a>
+      which can include SQL type information, column type lengths, and the Go type.
+    </p>
     <p>
-	  The new <code>Context</code> query methods work for all drivers, but
-	  <code>Context</code> cancelation is not responsive unless the driver has been
-	  updated to use them. The other features require driver support in
-	  <a href="/pkg/database/sql/driver"><code>database/sql/driver</code></a>.
-	  Driver authors should review the new interfaces. Users of existing
-	  driver should review the driver documentation to see what
-	  it supports and any system specific documentation on each feature.
-	</p>
+      A <a href="/pkg/database/sql/#Rows"><code>Rows</code></a>
+      can now represent multiple result sets. After
+      <a href="/pkg/database/sql/#Rows.Next"><code>Rows.Next</code></a> returns false,
+      <a href="/pkg/database/sql/#Rows.NextResultSet"><code>Rows.NextResultSet</code></a>
+      may be called to advance to the next result set. The existing <code>Rows</code>
+      should continue to be used after it advances to the next result set.
+      </p>
+    <p>
+      <a href="/pkg/database/sql/#NamedArg"><code>NamedArg</code></a> may be used
+      as query arguments. The new function <a href="/pkg/database/sql/#Named"><code>Named</code></a>
+      helps create a <a href="/pkg/database/sql/#NamedArg"><code>NamedArg</code></a>
+      more succinctly.
+    <p>
+      If a driver supports the new
+      <a href="/pkg/database/sql/driver/#Pinger"><code>Pinger</code></a>
+      interface, the
+      <a href="/pkg/database/sql/#DB.Ping"><code>DB.Ping</code></a>
+      and
+      <a href="/pkg/database/sql/#DB.PingContext"><code>DB.PingContext</code></a>
+      methods will use that interface to check whether a
+      database connection is still valid.
+    </p>
+    <p>
+      The new <code>Context</code> query methods work for all drivers, but
+      <code>Context</code> cancelation is not responsive unless the driver has been
+      updated to use them. The other features require driver support in
+      <a href="/pkg/database/sql/driver"><code>database/sql/driver</code></a>.
+      Driver authors should review the new interfaces. Users of existing
+      driver should review the driver documentation to see what
+      it supports and any system specific documentation on each feature.
+    </p>
   </dd>
 </dl>
 
 <dl id="debug_pe"><dt><a href="/pkg/debug/pe/">debug/pe</a></dt>
   <dd>
     <p> <!-- CL 22720, CL 27212, CL 22181, CL 22332, CL 22336, Issue 15345 -->
-      The package has been fleshed out and is now used by <a href="/cmd/link/">the Go linker</a>.
-      New are
-      <a href="/pkg/debug/pe/#Reloc"><code>Reloc</code></a>,
-      <a href="/pkg/debug/pe/#Section"><code>Section</code></a>,
-      <a href="/pkg/debug/pe/#StringTable"><code>StringTable</code></a>,
-      the method
-      <a href="/pkg/debug/pe/#COFFSymbol.FullName"><code>COFFSymbol.FullName</code></a>,
+      The package has been extended and is now used by
+      <a href="/cmd/link/">the Go linker</a> to read <code>gcc</code>-generated object files.
+      The new
+      <a href="/pkg/debug/pe/#File.StringTable"><code>File.StringTable</code></a>
       and
-      <a href="/pkg/debug/pe/#File"><code>File</code></a>
-      fields
-      <a href="/pkg/debug/pe/#File.COFFSymbols"><code>COFFSymbols</code></a> and
-      <a href="/pkg/debug/pe/#File.StringTable"><code>StringTable</code></a>.
+      <a href="/pkg/debug/pe/#Section.Relocs"><code>Section.Relocs</code></a>
+      fields provide access to the COFF string table and COFF relocations.
+      The new
+      <a href="/pkg/debug/pe/#File.COFFSymbols"><code>File.COFFSymbols</code></a>
+      allows low-level access to the COFF symbol table.
       </p>
   </dd>
 </dl>
@@ -933,9 +964,8 @@ crypto/x509: return error for missing SerialNumber (CL 27238)
     </p>
 
     <p> <!-- CL 30944 -->
-
       In previous versions of Go, unmarshaling a JSON <code>null</code> into an
-      of <a href="/pkg/encoding/json/#Unmarshaler"><code>Unmarshaler</code></a>
+      <a href="/pkg/encoding/json/#Unmarshaler"><code>Unmarshaler</code></a>
       was considered a no-op; now the <code>Unmarshaler</code>'s
       <code>UnmarshalJSON</code> method is called with the JSON literal
       <code>null</code> and can define the semantics of that case.
@@ -1065,7 +1095,7 @@ crypto/x509: return error for missing SerialNumber (CL 27238)
       <a href="/pkg/math/big/#Int.ModInverse"><code>Int.ModInverse</code></a>
       now supports negative numbers.
     </p>
-    
+
   </dd>
 </dl>
 
@@ -1092,9 +1122,9 @@ crypto/x509: return error for missing SerialNumber (CL 27238)
     <a href="/pkg/mime/#ParseMediaType"><code>ParseMediaType</code></a>
     now preserves unnecessary backslash escapes as literals,
     in order to support MSIE.
-    When MSIE sends a full file path (in "intranet mode"), it does not
-    escape backslashes: <code>"C:\dev\go\foo.txt"</code>, not
-    <code>"C:\\dev\\go\\foo.txt"</code>.
+    When MSIE sends a full file path (in “intranet mode”), it does not
+    escape backslashes: “<code>C:\dev\go\foo.txt</code>”, not
+    “<code>C:\\dev\\go\\foo.txt</code>”.
     If we see an unnecessary backslash escape, we now assume it is from MSIE
     and intended as a literal backslash.
     No known MIME generators emit unnecessary backslash escapes
@@ -1126,7 +1156,7 @@ crypto/x509: return error for missing SerialNumber (CL 27238)
 
 <dl id="net"><dt><a href="/pkg/net/">net</a></dt>
   <dd>
-    
+
     <p><!-- CL 30164, CL 33473 -->
       The <a href="/pkg/net/#Conn"><code>Conn</code></a> documentation
       has been updated to clarify expectations of an interface
@@ -1147,8 +1177,8 @@ crypto/x509: return error for missing SerialNumber (CL 27238)
     </p>
 
     <p><!-- CL 29951 -->
-      The new <a href="/pkg/net/#Buffers"><code>Buffers</code></a> types permits
-      more efficiently writing to the network from multiple discontiguous buffers
+      The new <a href="/pkg/net/#Buffers"><code>Buffers</code></a> type permits
+      writing to the network more efficiently from multiple discontiguous buffers
       in memory. On certain machines, for certain types of connections,
       this is optimized into an OS-specific batch write operation (such as <code>writev</code>).
     </p>
@@ -1165,8 +1195,8 @@ crypto/x509: return error for missing SerialNumber (CL 27238)
     </p>
 
     <p><!-- CL 29233, CL 24901 -->
-      The Go DNS resolver now supports <code>resolv.conf</code>'s "<code>rotate</code>"
-      and "<code>option ndots:0</code>" options. The "<code>ndots</code>" option is
+      The Go DNS resolver now supports <code>resolv.conf</code>'s “<code>rotate</code>”
+      and “<code>option</code> <code>ndots:0</code>” options. The “<code>ndots</code>” option is
       now respected in the same way as <code>libresolve</code>.
     </p>
 
@@ -1193,7 +1223,7 @@ crypto/x509: return error for missing SerialNumber (CL 27238)
         <a href="/pkg/net/http/#ServeContent"><code>ServeContent</code></a>
         now support HTTP <code>If-Match</code> conditional requests,
         in addition to the previous <code>If-None-Match</code>
-        support.
+        support for ETags properly formatted according to RFC 7232, section 2.3.
       </li>
     </ul>
 
@@ -1213,11 +1243,11 @@ crypto/x509: return error for missing SerialNumber (CL 27238)
         existing <a href="/pkg/net/http/#CloseNotifier"><code>CloseNotifier</code></a>
         support. This functionality requires that the underlying
         <a href="/pkg/net/#Conn"><code>net.Conn</code></a> implements
-        <a href="#net">recently-clarified interface documentation</a>.
+        <a href="#net">recently clarified interface documentation</a>.
       </li>
 
       <li><!-- CL 32479 -->
-        To serve trailers known after the header has been written,
+        To serve trailers produced after the header has already been written,
         see the new
         <a href="/pkg/net/http/#TrailerPrefix"><code>TrailerPrefix</code></a>
         mechanism.
@@ -1244,7 +1274,7 @@ crypto/x509: return error for missing SerialNumber (CL 27238)
 
     <p>Client & Transport changes:</p>
     <ul>
-      <li><!-- CL 28930 -->
+      <li><!-- CL 28930, CL 31435 -->
         The <a href="/pkg/net/http/#Client"><code>Client</code></a>
         now copies most request headers on redirect. See
         <a href="/pkg/net/http/#Client">the documentation</a>
@@ -1275,7 +1305,8 @@ crypto/x509: return error for missing SerialNumber (CL 27238)
 
       <li><!-- CL 27117 -->
         The <code>Transport</code> will now retry non-idempotent
-        requests if no bytes were written before a network failure.
+        requests if no bytes were written before a network failure
+        and the request has no body.
       </li>
 
       <li><!-- CL 32481 -->
@@ -1288,9 +1319,25 @@ crypto/x509: return error for missing SerialNumber (CL 27238)
       <li> <!-- CL 28077 -->
         The <a href="/pkg/net/http/#DefaultTransport"><code>DefaultTransport.Dialer</code></a>
         now enables <code>DualStack</code> ("<a href="https://tools.ietf.org/html/rfc6555">Happy Eyeballs</a>") support,
-        to use IPv4 as a backup if it looks like IPv6 might be
+        allowing the use of IPv4 as a backup if it looks like IPv6 might be
         failing.
       </li>
+
+      <li> <!-- CL 31726 -->
+        The <a href="/pkg/net/http/#Transport"><code>Transport</code></a>
+        no longer reads a byte of a non-nil
+        <a href="/pkg/net/http/#Request.Body"><code>Request.Body</code></a>
+        when the
+        <a href="/pkg/net/http/#Request.ContentLength"><code>Request.ContentLength</code></a>
+        is zero to determine whether the <code>ContentLength</code>
+        is actually zero or just undefined.
+        To explicitly signal that a body has zero length,
+        either set it to <code>nil</code>, or set it to the new value
+        <a href="/pkg/net/http/#NoBody"><code>NoBody</code></a>.
+        The new <code>NoBody</code> value is intended for use by <code>Request</code>
+        constructor functions; it is used by
+        <a href="/pkg/net/http/#NewRequest"><code>NewRequest</code></a>.
+      </li>
     </ul>
 
   </dd>
@@ -1314,9 +1361,9 @@ crypto/x509: return error for missing SerialNumber (CL 27238)
     The <a href="/pkg/net/http/httputil/#ReverseProxy"><code>ReverseProxy</code></a>
     has a new optional hook,
     <a href="/pkg/net/http/httputil/#ReverseProxy.ModifyResponse"><code>ModifyResponse</code></a>,
-    for modifying the response from the backend before proxying it to the client.
+    for modifying the response from the back end before proxying it to the client.
     </p>
-    
+
   </dd>
 </dl>
 
@@ -1326,7 +1373,7 @@ crypto/x509: return error for missing SerialNumber (CL 27238)
     <p> <!-- CL 32176 -->
       Empty quoted strings are once again allowed in the name part of
       an address. That is, Go 1.4 and earlier accepted
-      <code>"" <gopher at example.com></code>,
+      <code>""</code> <code><gopher at example.com></code>,
       but Go 1.5 introduced a bug that rejected this address.
       The address is recognized again.
     </p>
@@ -1341,7 +1388,7 @@ crypto/x509: return error for missing SerialNumber (CL 27238)
       allows parsing dates found in other
       header lines, such as the <code>Resent-Date:</code> header.
     </p>
-    
+
   </dd>
 </dl>
 
@@ -1349,10 +1396,10 @@ crypto/x509: return error for missing SerialNumber (CL 27238)
   <dd>
 
     <p> <!-- CL 33143 -->
-      If an implementation of
-      the <a href="/pkg/net/smtp/#Auth"><code>Auth</code></a>
-      interface's <code>Start</code> method returns an
-      empty <code>toServer</code> value, the package no longer sends
+      If an implementation of the
+      <a href="/pkg/net/smtp/#Auth"><code>Auth.Start</code></a>
+      method returns an empty <code>toServer</code> value,
+      the package no longer sends
       trailing whitespace in the SMTP <code>AUTH</code> command,
       which some servers rejected.
     </p>
@@ -1363,14 +1410,17 @@ crypto/x509: return error for missing SerialNumber (CL 27238)
 <dl id="net_url"><dt><a href="/pkg/net/url/">net/url</a></dt>
   <dd>
 
-    <p> <!-- CL 31322 --> The new functions
+    <p> <!-- CL 31322 -->
+      The new functions
       <a href="/pkg/net/url/#PathEscape"><code>PathEscape</code></a>
       and
       <a href="/pkg/net/url/#PathUnescape"><code>PathUnescape</code></a>
       are similar to the query escaping and unescaping functions but
-      for path elements.</p>
+      for path elements.
+    </p>
 
-    <p> <!-- CL 28933 --> The new methods
+    <p> <!-- CL 28933 -->
+      The new methods
       <a href="/pkg/net/url/#URL.Hostname"><code>URL.Hostname</code></a>
       and
       <a href="/pkg/net/url/#URL.Port"><code>URL.Port</code></a>
@@ -1378,7 +1428,8 @@ crypto/x509: return error for missing SerialNumber (CL 27238)
       correctly handling the case where the port may not be present.
     </p>
 
-    <p> <!-- CL 28343 --> The existing method
+    <p> <!-- CL 28343 -->
+      The existing method
       <a href="/pkg/net/url/#URL.ResolveReference"><code>URL.ResolveReference</code></a>
       now properly handles paths with escaped bytes without losing
       the escaping.
@@ -1397,7 +1448,7 @@ crypto/x509: return error for missing SerialNumber (CL 27238)
       now rejects URLs like <code>this_that:other/thing</code> instead of
       interpreting them as relative paths (<code>this_that</code> is not a valid scheme).
       To force interpretation as a relative path,
-      such URLs should be prefixed with <code>"./"</code>.
+      such URLs should be prefixed with “<code>./</code>”.
       The <code>URL.String</code> method now inserts this prefix as needed.
     </p>
 
@@ -1406,7 +1457,7 @@ crypto/x509: return error for missing SerialNumber (CL 27238)
 
 <dl id="os"><dt><a href="/pkg/os/">os</a></dt>
   <dd>
-    <p>
+    <p> <!-- CL 16551 -->
       The new function
       <a href="/pkg/os/#Executable"><code>Executable</code></a> returns
       the path name of the running executable.
@@ -1427,12 +1478,12 @@ crypto/x509: return error for missing SerialNumber (CL 27238)
       existing empty directory.
       Previously it would fail when renaming to a non-empty directory
       but succeed when renaming to an empty directory.
-      This makes the behavior on Unix correspond to that on other systems.
+      This makes the behavior on Unix correspond to that of other systems.
     </p>
 
     <p> <!-- CL 32451 -->
       On Windows, long absolute paths are now transparently converted to
-      extended-length paths (paths that start with <code>\\?\</code>).
+      extended-length paths (paths that start with “<code>\\?\</code>”).
       This permits the package to work with files whose path names are
       longer than 260 characters.
     </p>
@@ -1454,32 +1505,18 @@ crypto/x509: return error for missing SerialNumber (CL 27238)
   </dd>
 </dl>
 
-<dl id="os_signal"><dt><a href="/pkg/os/signal/">os/signal</a></dt>
-  <dd>
-    <p> <!-- CL 32796 -->
-      In a Go library built with <code>-buildmode=c-archive</code>
-      or <code>c-shared</code>, when C code calls a Go function,
-      the <code>SIGPIPE</code> signal will be treated as usual for Go code.
-      In particular, when <code>SIGPIPE</code> is triggered by a write
-      to a closed Go network connection, it will not cause the program
-      to exit.
-    </p>
-  </dd>
-</dl>
-
 <dl id="path_filepath"><dt><a href="/pkg/path/filepath/">path/filepath</a></dt>
   <dd>
     <p>
-    <p>A number of bugs and corner cases on Windows were fixed:
-      <a href="/pkg/path/filepath/#Abs"><code>Abs</code></a> now calls <code>Clean</code> paths as documented,
+      A number of bugs and corner cases on Windows were fixed:
+      <a href="/pkg/path/filepath/#Abs"><code>Abs</code></a> now calls <code>Clean</code> as documented,
       <a href="/pkg/path/filepath/#Glob"><code>Glob</code></a> now matches
-      "<code>\\?\c:\*</code>",
+      “<code>\\?\c:\*</code>”,
       <a href="/pkg/path/filepath/#EvalSymlinks"><code>EvalSymlinks</code></a> now
-      correctly handles "<code>C:.</code>", and
+      correctly handles “<code>C:.</code>”, and
       <a href="/pkg/path/filepath/#Clean"><code>Clean</code></a> now properly
-      handles a leading "<code>..</code>" in the path.
-    <p>
-
+      handles a leading “<code>..</code>” in the path.
+    </p>
   </dd>
 </dl>
 
@@ -1580,14 +1617,6 @@ crypto/x509: return error for missing SerialNumber (CL 27238)
       test or benchmark.
     </p>
 
-    <p><!-- CL 31724 -->
-      The new method
-      <a href="/pkg/testing/#T.Context"><code>T.Context</code></a>
-      (and <code>B.Context</code>) returns
-      a <a href="/pkg/context/#Context"><code>Context</code></a> for
-      the current running test or benchmark.
-    </p>
-
     <p><!-- CL 32483 -->
       The new function
       <a href="/pkg/testing/#CoverMode"><code>CoverMode</code></a>
@@ -1600,15 +1629,15 @@ crypto/x509: return error for missing SerialNumber (CL 27238)
       Previously, individual test cases would appear to pass,
       and only the overall execution of the test binary would fail.
     </p>
-   
+
   </dd>
 </dl>
 
 <dl id="unicode"><dt><a href="/pkg/unicode/">unicode</a></dt>
   <dd>
     <p><!-- CL 30935 -->
-      <code>SimpleFold</code> now returns its argument unchanged
-      if the provided input was an invalid rune.
+      <a href="/pkg/unicode/#SimpleFold"><code>SimpleFold</code></a>
+      now returns its argument unchanged if the provided input was an invalid rune.
       Previously, the implementation failed with an index bounds check panic.
     </p>
   </dd>
diff --git a/doc/go1.8.txt b/doc/go1.8.txt
index e66ad38..caa9a72 100644
--- a/doc/go1.8.txt
+++ b/doc/go1.8.txt
@@ -29,7 +29,6 @@ cmd/link: fix -buildmode=pie / -linkshared combination (CL 28996)
 cmd/link: for -buildmode=exe pass -no-pie to external linker (CL 33106)
 cmd/link: insert trampolines for too-far jumps on ARM (CL 29397)
 cmd/link: non-executable stack support for Solaris (CL 24142)
-cmd/link: plugin support on darwin/amd64 (CL 29394)
 cmd/link: put text at address 0x1000000 on darwin/amd64 (CL 32185)
 cmd/link: remove the -shared flag (CL 28852)
 cmd/link: split large elf text sections on ppc64x (CL 27790)
diff --git a/doc/help.html b/doc/help.html
index 6448191..62d9a4a 100644
--- a/doc/help.html
+++ b/doc/help.html
@@ -11,6 +11,9 @@
 
 <h3 id="mailinglist"><a href="https://groups.google.com/group/golang-nuts">Go Nuts Mailing List</a></h3>
 <p>
+Get help from Go users, and share your work on the official mailing list.
+</p>
+<p>
 Search the <a href="https://groups.google.com/group/golang-nuts">golang-nuts</a>
 archives and consult the <a href="/doc/go_faq.html">FAQ</a> and
 <a href="//golang.org/wiki">wiki</a> before posting.
@@ -18,12 +21,12 @@ archives and consult the <a href="/doc/go_faq.html">FAQ</a> and
 
 <h3 id="forum"><a href="https://forum.golangbridge.org/">Go Forum</a></h3>
 <p>
-The <a href="https://forum.golangbridge.org/">Go Forum</a> is an alternate discussion
+The <a href="https://forum.golangbridge.org/">Go Forum</a> is a discussion
 forum for Go programmers.
 </p>
 
 <h3 id="slack"><a href="https://blog.gopheracademy.com/gophers-slack-community/">Gopher Slack</a></h3>
-<p>Get live support from the official Go slack channel.</p>
+<p>Get live support from other users in the Go slack channel.</p>
 
 <h3 id="irc"><a href="irc:irc.freenode.net/go-nuts">Go IRC Channel</a></h3>
 <p>Get live support at <b>#go-nuts</b> on <b>irc.freenode.net</b>, the official
diff --git a/doc/install-source.html b/doc/install-source.html
index 4a25e37..4bf0ba3 100644
--- a/doc/install-source.html
+++ b/doc/install-source.html
@@ -33,7 +33,7 @@ compiler using the GCC back end, see
 </p>
 
 <p>
-The Go compilers support seven instruction sets.
+The Go compilers support eight instruction sets.
 There are important differences in the quality of the compilers for the different
 architectures.
 </p>
@@ -55,7 +55,7 @@ architectures.
 	<code>arm</code> (<code>ARM</code>)
 </dt>
 <dd>
-	Supports Linux, FreeBSD, NetBSD and Darwin binaries. Less widely used than the other ports.
+	Supports Linux, FreeBSD, NetBSD, OpenBSD and Darwin binaries. Less widely used than the other ports.
 </dd>
 <dt>
 	<code>arm64</code> (<code>AArch64</code>)
@@ -70,6 +70,12 @@ architectures.
 	Supports Linux binaries. New in 1.5 and not as well exercised as other ports.
 </dd>
 <dt>
+	<code>mips, mipsle</code> (32-bit MIPS big- and little-endian)
+</dt>
+<dd>
+	Supports Linux binaries. New in 1.8 and not as well exercised as other ports.
+</dd>
+<dt>
 	<code>mips64, mips64le</code> (64-bit MIPS big- and little-endian)
 </dt>
 <dd>
@@ -212,7 +218,7 @@ To build without <code>cgo</code>, set the environment variable
 Change to the directory that will be its parent
 and make sure the <code>go</code> directory does not exist.
 Then clone the repository and check out the latest release tag
-(<code class="versionTag">go1.7.2</code>, for example):</p>
+(<code class="versionTag">go1.7.4</code>, for example):</p>
 
 <pre>
 $ git clone https://go.googlesource.com/go
@@ -329,7 +335,7 @@ You just need to do a little more setup.
 </p>
 
 <p>
-The <a href="/doc/code.html">How to Write Go Code</a> document 
+The <a href="/doc/code.html">How to Write Go Code</a> document
 provides <b>essential setup instructions</b> for using the Go tools.
 </p>
 
@@ -355,7 +361,7 @@ $ go get golang.org/x/tools/cmd/godoc
 </pre>
 
 <p>
-To install these tools, the <code>go</code> <code>get</code> command requires 
+To install these tools, the <code>go</code> <code>get</code> command requires
 that <a href="#git">Git</a> be installed locally.
 </p>
 
@@ -400,7 +406,7 @@ New releases are announced on the
 <a href="//groups.google.com/group/golang-announce">golang-announce</a>
 mailing list.
 Each announcement mentions the latest release tag, for instance,
-<code class="versionTag">go1.7.2</code>.
+<code class="versionTag">go1.7.4</code>.
 </p>
 
 <p>
@@ -443,7 +449,7 @@ The value assumed by installed binaries and scripts when
 <code>$GOROOT</code> is not set explicitly.
 It defaults to the value of <code>$GOROOT</code>.
 If you want to build the Go tree in one location
-but move it elsewhere after the build, set 
+but move it elsewhere after the build, set
 <code>$GOROOT_FINAL</code> to the eventual location.
 </p>
 
@@ -463,6 +469,7 @@ Choices for <code>$GOARCH</code> are
 <code>386</code> (32-bit x86), <code>arm</code> (32-bit ARM), <code>arm64</code> (64-bit ARM),
 <code>ppc64le</code> (PowerPC 64-bit, little-endian), <code>ppc64</code> (PowerPC 64-bit, big-endian),
 <code>mips64le</code> (MIPS 64-bit, little-endian), and <code>mips64</code> (MIPS 64-bit, big-endian).
+<code>mipsle</code> (MIPS 32-bit, little-endian), and <code>mips</code> (MIPS 32-bit, big-endian).
 The valid combinations of <code>$GOOS</code> and <code>$GOARCH</code> are:
 <table cellpadding="0">
 <tr>
@@ -514,6 +521,12 @@ The valid combinations of <code>$GOOS</code> and <code>$GOARCH</code> are:
 <td></td><td><code>linux</code></td> <td><code>ppc64le</code></td>
 </tr>
 <tr>
+<td></td><td><code>linux</code></td> <td><code>mips</code></td>
+</tr>
+<tr>
+<td></td><td><code>linux</code></td> <td><code>mipsle</code></td>
+</tr>
+<tr>
 <td></td><td><code>linux</code></td> <td><code>mips64</code></td>
 </tr>
 <tr>
@@ -566,7 +579,7 @@ architecture.
 Valid choices are the same as for <code>$GOOS</code> and
 <code>$GOARCH</code>, listed above.
 The specified values must be compatible with the local system.
-For example, you should not set <code>$GOHOSTARCH</code> to 
+For example, you should not set <code>$GOHOSTARCH</code> to
 <code>arm</code> on an x86 system.
 </p>
 
@@ -627,7 +640,7 @@ not <code>amd64</code>.
 <p>
 If you choose to override the defaults,
 set these variables in your shell profile (<code>$HOME/.bashrc</code>,
-<code>$HOME/.profile</code>, or equivalent). The settings might look 
+<code>$HOME/.profile</code>, or equivalent). The settings might look
 something like this:
 </p>
 
diff --git a/doc/install.html b/doc/install.html
index ebe66c0..d8e04b7 100644
--- a/doc/install.html
+++ b/doc/install.html
@@ -47,8 +47,8 @@ If your OS or architecture is not on the list, you may be able to
 <th align="center">Notes</th>
 </tr>
 <tr><td colspan="3"><hr></td></tr>
-<tr><td>FreeBSD 8-STABLE or later</td> <td>amd64</td> <td>Debian GNU/kFreeBSD not supported</td></tr>
-<tr><td>Linux 2.6.23 or later with glibc</td> <td>amd64, 386, arm</td> <td>CentOS/RHEL 5.x not supported</td></tr>
+<tr><td>FreeBSD 8-STABLE or later</td> <td>amd64, 386</td> <td>Debian GNU/kFreeBSD not supported</td></tr>
+<tr><td>Linux 2.6.23 or later with glibc</td> <td>amd64, 386, arm, s390x, ppc64le</td> <td>CentOS/RHEL 5.x not supported</td></tr>
 <tr><td>Mac OS X 10.8 or later</td> <td>amd64</td> <td>use the clang or gcc<sup>†</sup> that comes with Xcode<sup>‡</sup> for <code>cgo</code> support</td></tr>
 <tr><td>Windows XP or later</td> <td>amd64, 386</td> <td>use MinGW gcc<sup>†</sup>. No need for cygwin or msys.</td></tr>
 </table>
diff --git a/misc/cgo/test/cgo_unix_test.go b/misc/cgo/test/cgo_unix_test.go
index b3633b7..e3d5916 100644
--- a/misc/cgo/test/cgo_unix_test.go
+++ b/misc/cgo/test/cgo_unix_test.go
@@ -10,3 +10,4 @@ import "testing"
 
 func TestSigaltstack(t *testing.T) { testSigaltstack(t) }
 func TestSigprocmask(t *testing.T) { testSigprocmask(t) }
+func Test18146(t *testing.T)       { test18146(t) }
diff --git a/misc/cgo/test/issue17537.go b/misc/cgo/test/issue17537.go
index debdbfe..777104e 100644
--- a/misc/cgo/test/issue17537.go
+++ b/misc/cgo/test/issue17537.go
@@ -23,6 +23,18 @@ int I17537(S17537 *p);
 const int F17537(const char **p) {
 	return **p;
 }
+
+// Calling this function used to trigger an error from the C compiler
+// (issue 18298).
+void F18298(const void *const *p) {
+}
+
+// Test that conversions between typedefs work as they used to.
+typedef const void *T18298_1;
+struct S18298 { int i; };
+typedef const struct S18298 *T18298_2;
+void G18298(T18298_1 t) {
+}
 */
 import "C"
 
@@ -39,4 +51,8 @@ func test17537(t *testing.T) {
 	if got, want := C.F17537(&p), C.int(17); got != want {
 		t.Errorf("got %d, want %d", got, want)
 	}
+
+	C.F18298(nil)
+	var v18298 C.T18298_2
+	C.G18298(C.T18298_1(v18298))
 }
diff --git a/misc/cgo/test/issue18146.go b/misc/cgo/test/issue18146.go
new file mode 100644
index 0000000..19c52b6
--- /dev/null
+++ b/misc/cgo/test/issue18146.go
@@ -0,0 +1,103 @@
+// 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.
+
+// +build !windows
+
+// Issue 18146: pthread_create failure during syscall.Exec.
+
+package cgotest
+
+import "C"
+
+import (
+	"bytes"
+	"crypto/md5"
+	"os"
+	"os/exec"
+	"runtime"
+	"syscall"
+	"testing"
+	"time"
+)
+
+func test18146(t *testing.T) {
+	if runtime.GOOS == "darwin" {
+		t.Skipf("skipping flaky test on %s; see golang.org/issue/18202", runtime.GOOS)
+	}
+
+	if runtime.GOARCH == "mips" || runtime.GOARCH == "mips64" {
+		t.Skipf("skipping on %s", runtime.GOARCH)
+	}
+
+	attempts := 1000
+	threads := 4
+
+	if testing.Short() {
+		attempts = 100
+	}
+
+	if os.Getenv("test18146") == "exec" {
+		runtime.GOMAXPROCS(1)
+		for n := threads; n > 0; n-- {
+			go func() {
+				for {
+					_ = md5.Sum([]byte("Hello, !"))
+				}
+			}()
+		}
+		runtime.GOMAXPROCS(threads)
+		argv := append(os.Args, "-test.run=NoSuchTestExists")
+		if err := syscall.Exec(os.Args[0], argv, nil); err != nil {
+			t.Fatal(err)
+		}
+	}
+
+	var cmds []*exec.Cmd
+	defer func() {
+		for _, cmd := range cmds {
+			cmd.Process.Kill()
+		}
+	}()
+
+	args := append(append([]string(nil), os.Args[1:]...), "-test.run=Test18146")
+	for n := attempts; n > 0; n-- {
+		cmd := exec.Command(os.Args[0], args...)
+		cmd.Env = append(os.Environ(), "test18146=exec")
+		buf := bytes.NewBuffer(nil)
+		cmd.Stdout = buf
+		cmd.Stderr = buf
+		if err := cmd.Start(); err != nil {
+			// We are starting so many processes that on
+			// some systems (problem seen on Darwin,
+			// Dragonfly, OpenBSD) the fork call will fail
+			// with EAGAIN.
+			if pe, ok := err.(*os.PathError); ok {
+				err = pe.Err
+			}
+			if se, ok := err.(syscall.Errno); ok && (se == syscall.EAGAIN || se == syscall.EMFILE) {
+				time.Sleep(time.Millisecond)
+				continue
+			}
+
+			t.Error(err)
+			return
+		}
+		cmds = append(cmds, cmd)
+	}
+
+	failures := 0
+	for _, cmd := range cmds {
+		err := cmd.Wait()
+		if err == nil {
+			continue
+		}
+
+		t.Errorf("syscall.Exec failed: %v\n%s", err, cmd.Stdout)
+		failures++
+	}
+
+	if failures > 0 {
+		t.Logf("Failed %v of %v attempts.", failures, len(cmds))
+	}
+}
diff --git a/misc/cgo/test/issue9400/asm_mipsx.s b/misc/cgo/test/issue9400/asm_mipsx.s
new file mode 100644
index 0000000..ddf33e9
--- /dev/null
+++ b/misc/cgo/test/issue9400/asm_mipsx.s
@@ -0,0 +1,31 @@
+// 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.
+
+// +build mips mipsle
+// +build !gccgo
+
+#include "textflag.h"
+
+TEXT ·RewindAndSetgid(SB),NOSPLIT,$-4-0
+	// Rewind stack pointer so anything that happens on the stack
+	// will clobber the test pattern created by the caller
+	ADDU	$(1024*8), R29
+
+	// Ask signaller to setgid
+	MOVW	$1, R1
+	SYNC
+	MOVW	R1, ·Baton(SB)
+	SYNC
+
+	// Wait for setgid completion
+loop:
+	SYNC
+	MOVW	·Baton(SB), R1
+	OR	R2, R2, R2	// hint that we're in a spin loop
+	BNE	R1, loop
+	SYNC
+
+	// Restore stack
+	ADDU	$(-1024*8), R29
+	RET
diff --git a/misc/cgo/testcarchive/carchive_test.go b/misc/cgo/testcarchive/carchive_test.go
index 3c768a0..4999929 100644
--- a/misc/cgo/testcarchive/carchive_test.go
+++ b/misc/cgo/testcarchive/carchive_test.go
@@ -265,25 +265,6 @@ func TestSignalForwarding(t *testing.T) {
 		t.Logf("%s", out)
 		t.Errorf("got %v; expected SIGSEGV", ee)
 	}
-
-	// Test SIGPIPE forwarding
-	cmd = exec.Command(bin[0], append(bin[1:], "3")...)
-
-	out, err = cmd.CombinedOutput()
-
-	if err == nil {
-		t.Logf("%s", out)
-		t.Error("test program succeeded unexpectedly")
-	} else if ee, ok := err.(*exec.ExitError); !ok {
-		t.Logf("%s", out)
-		t.Errorf("error (%v) has type %T; expected exec.ExitError", err, err)
-	} else if ws, ok := ee.Sys().(syscall.WaitStatus); !ok {
-		t.Logf("%s", out)
-		t.Errorf("error.Sys (%v) has type %T; expected syscall.WaitStatus", ee.Sys(), ee.Sys())
-	} else if !ws.Signaled() || ws.Signal() != syscall.SIGPIPE {
-		t.Logf("%s", out)
-		t.Errorf("got %v; expected SIGPIPE", ee)
-	}
 }
 
 func TestSignalForwardingExternal(t *testing.T) {
diff --git a/misc/cgo/testcarchive/main2.c b/misc/cgo/testcarchive/main2.c
index 55625c5..774e014 100644
--- a/misc/cgo/testcarchive/main2.c
+++ b/misc/cgo/testcarchive/main2.c
@@ -17,7 +17,6 @@
 #include <unistd.h>
 #include <sched.h>
 #include <time.h>
-#include <errno.h>
 
 #include "libgo2.h"
 
@@ -27,7 +26,6 @@ static void die(const char* msg) {
 }
 
 static volatile sig_atomic_t sigioSeen;
-static volatile sig_atomic_t sigpipeSeen;
 
 // Use up some stack space.
 static void recur(int i, char *p) {
@@ -40,11 +38,6 @@ static void recur(int i, char *p) {
 }
 
 // Signal handler that uses up more stack space than a goroutine will have.
-static void pipeHandler(int signo, siginfo_t* info, void* ctxt) {
-	sigpipeSeen = 1;
-}
-
-// Signal handler that uses up more stack space than a goroutine will have.
 static void ioHandler(int signo, siginfo_t* info, void* ctxt) {
 	char a[1024];
 
@@ -113,10 +106,6 @@ static void init() {
 		die("sigaction");
 	}
 
-	sa.sa_sigaction = pipeHandler;
-	if (sigaction(SIGPIPE, &sa, NULL) < 0) {
-		die("sigaction");
-	}
 }
 
 int main(int argc, char** argv) {
@@ -178,30 +167,7 @@ int main(int argc, char** argv) {
 		nanosleep(&ts, NULL);
 		i++;
 		if (i > 5000) {
-			fprintf(stderr, "looping too long waiting for SIGIO\n");
-			exit(EXIT_FAILURE);
-		}
-	}
-
-	if (verbose) {
-		printf("provoking SIGPIPE\n");
-	}
-
-	GoRaiseSIGPIPE();
-
-	if (verbose) {
-		printf("waiting for sigpipeSeen\n");
-	}
-
-	// Wait until the signal has been delivered.
-	i = 0;
-	while (!sigpipeSeen) {
-		ts.tv_sec = 0;
-		ts.tv_nsec = 1000000;
-		nanosleep(&ts, NULL);
-		i++;
-		if (i > 1000) {
-			fprintf(stderr, "looping too long waiting for SIGPIPE\n");
+			fprintf(stderr, "looping too long waiting for signal\n");
 			exit(EXIT_FAILURE);
 		}
 	}
diff --git a/misc/cgo/testcarchive/main3.c b/misc/cgo/testcarchive/main3.c
index 07d5d1e..0a6c0d3 100644
--- a/misc/cgo/testcarchive/main3.c
+++ b/misc/cgo/testcarchive/main3.c
@@ -35,13 +35,6 @@ int main(int argc, char** argv) {
 	setvbuf(stdout, NULL, _IONBF, 0);
 
 	if (verbose) {
-		printf("raising SIGPIPE\n");
-	}
-
-	// Test that the Go runtime handles SIGPIPE.
-	ProvokeSIGPIPE();
-
-	if (verbose) {
 		printf("calling sigaction\n");
 	}
 
diff --git a/misc/cgo/testcarchive/main5.c b/misc/cgo/testcarchive/main5.c
index 2437bf0..9fadf08 100644
--- a/misc/cgo/testcarchive/main5.c
+++ b/misc/cgo/testcarchive/main5.c
@@ -68,24 +68,6 @@ int main(int argc, char** argv) {
 
 			break;
 		}
-		case 3: {
-			if (verbose) {
-				printf("attempting SIGPIPE\n");
-			}
-
-			int fd[2];
-			if (pipe(fd) != 0) {
-				printf("pipe(2) failed\n");
-				return 0;
-			}
-			// Close the reading end.
-			close(fd[0]);
-			// Expect that write(2) fails (EPIPE)
-			if (write(fd[1], "some data", 9) != -1) {
-				printf("write(2) unexpectedly succeeded\n");
-				return 0;
-			}
-		}
 		default:
 			printf("Unknown test: %d\n", test);
 			return 0;
diff --git a/misc/cgo/testcarchive/src/libgo2/libgo2.go b/misc/cgo/testcarchive/src/libgo2/libgo2.go
index 19c8e1a..fbed493 100644
--- a/misc/cgo/testcarchive/src/libgo2/libgo2.go
+++ b/misc/cgo/testcarchive/src/libgo2/libgo2.go
@@ -4,30 +4,6 @@
 
 package main
 
-/*
-#include <signal.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <stdio.h>
-
-// Raise SIGPIPE.
-static void CRaiseSIGPIPE() {
-	int fds[2];
-
-	if (pipe(fds) == -1) {
-		perror("pipe");
-		exit(EXIT_FAILURE);
-	}
-	// Close the reader end
-	close(fds[0]);
-	// Write to the writer end to provoke a SIGPIPE
-	if (write(fds[1], "some data", 9) != -1) {
-		fprintf(stderr, "write to a closed pipe succeeded\n");
-		exit(EXIT_FAILURE);
-	}
-	close(fds[1]);
-}
-*/
 import "C"
 
 import (
@@ -70,11 +46,5 @@ func TestSEGV() {
 func Noop() {
 }
 
-// Raise SIGPIPE.
-//export GoRaiseSIGPIPE
-func GoRaiseSIGPIPE() {
-	C.CRaiseSIGPIPE()
-}
-
 func main() {
 }
diff --git a/misc/cgo/testcarchive/src/libgo3/libgo3.go b/misc/cgo/testcarchive/src/libgo3/libgo3.go
index 19fcc7f..94e5d21 100644
--- a/misc/cgo/testcarchive/src/libgo3/libgo3.go
+++ b/misc/cgo/testcarchive/src/libgo3/libgo3.go
@@ -40,17 +40,5 @@ func SawSIGIO() C.int {
 	}
 }
 
-// ProvokeSIGPIPE provokes a kernel-initiated SIGPIPE
-//export ProvokeSIGPIPE
-func ProvokeSIGPIPE() {
-	r, w, err := os.Pipe()
-	if err != nil {
-		panic(err)
-	}
-	r.Close()
-	defer w.Close()
-	w.Write([]byte("some data"))
-}
-
 func main() {
 }
diff --git a/misc/cgo/testplugin/src/plugin1/plugin1.go b/misc/cgo/testplugin/src/plugin1/plugin1.go
index 7a62242..edcef2c 100644
--- a/misc/cgo/testplugin/src/plugin1/plugin1.go
+++ b/misc/cgo/testplugin/src/plugin1/plugin1.go
@@ -9,7 +9,10 @@ import "C"
 
 import "common"
 
-func F() int { return 3 }
+func F() int {
+	_ = make([]byte, 1<<21) // trigger stack unwind, Issue #18190.
+	return 3
+}
 
 func ReadCommonX() int {
 	return common.X
diff --git a/misc/cgo/testplugin/src/plugin2/plugin2.go b/misc/cgo/testplugin/src/plugin2/plugin2.go
index 6c23a5e..9c507fc 100644
--- a/misc/cgo/testplugin/src/plugin2/plugin2.go
+++ b/misc/cgo/testplugin/src/plugin2/plugin2.go
@@ -4,12 +4,21 @@
 
 package main
 
-// // No C code required.
+//#include <errno.h>
+//#include <string.h>
 import "C"
 
-import "common"
+// #include
+// void cfunc() {} // uses cgo_topofstack
+
+import (
+	"common"
+	"strings"
+)
 
 func init() {
+	_ = strings.NewReplacer() // trigger stack unwind, Issue #18190.
+	C.strerror(C.EIO)         // uses cgo_topofstack
 	common.X = 2
 }
 
diff --git a/misc/cgo/testsanitizers/test.bash b/misc/cgo/testsanitizers/test.bash
index 01cce95..9853875 100755
--- a/misc/cgo/testsanitizers/test.bash
+++ b/misc/cgo/testsanitizers/test.bash
@@ -145,6 +145,7 @@ if test "$tsan" = "yes"; then
     testtsan tsan3.go
     testtsan tsan4.go
     testtsan tsan8.go
+    testtsan tsan9.go
 
     # These tests are only reliable using clang or GCC version 7 or later.
     # Otherwise runtime/cgo/libcgo.h can't tell whether TSAN is in use.
diff --git a/misc/cgo/testsanitizers/tsan9.go b/misc/cgo/testsanitizers/tsan9.go
new file mode 100644
index 0000000..7cd0ac7
--- /dev/null
+++ b/misc/cgo/testsanitizers/tsan9.go
@@ -0,0 +1,60 @@
+// 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 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.
+
+/*
+#cgo CFLAGS: -g -fsanitize=thread
+#cgo LDFLAGS: -g -fsanitize=thread
+
+#include <stdlib.h>
+#include <sys/time.h>
+
+void spin() {
+	size_t n;
+	struct timeval tvstart, tvnow;
+	int diff;
+
+	gettimeofday(&tvstart, NULL);
+	for (n = 0; n < 1<<20; n++) {
+		free(malloc(n));
+		gettimeofday(&tvnow, NULL);
+		diff = (tvnow.tv_sec - tvstart.tv_sec) * 1000 * 1000 + (tvnow.tv_usec - tvstart.tv_usec);
+
+		// Profile frequency is 100Hz so we should definitely
+		// get a signal in 50 milliseconds.
+		if (diff > 50 * 1000) {
+			break;
+		}
+	}
+}
+*/
+import "C"
+
+import (
+	"io/ioutil"
+	"runtime/pprof"
+	"time"
+)
+
+func goSpin() {
+	start := time.Now()
+	for n := 0; n < 1<<20; n++ {
+		_ = make([]byte, n)
+		if time.Since(start) > 50*time.Millisecond {
+			break
+		}
+	}
+}
+
+func main() {
+	pprof.StartCPUProfile(ioutil.Discard)
+	go C.spin()
+	goSpin()
+	pprof.StopCPUProfile()
+}
diff --git a/misc/cgo/testshared/src/exe/exe.go b/misc/cgo/testshared/src/exe/exe.go
index 31fbedd..f01ad8a 100644
--- a/misc/cgo/testshared/src/exe/exe.go
+++ b/misc/cgo/testshared/src/exe/exe.go
@@ -7,6 +7,11 @@ import (
 	"runtime"
 )
 
+// Having a function declared in the main package triggered
+// golang.org/issue/18250
+func DeclaredInMain() {
+}
+
 func main() {
 	defer depBase.ImplementedInAsm()
 	// This code below causes various go.itab.* symbols to be generated in
diff --git a/src/cmd/cgo/gcc.go b/src/cmd/cgo/gcc.go
index 670a73f..5ea2d94 100644
--- a/src/cmd/cgo/gcc.go
+++ b/src/cmd/cgo/gcc.go
@@ -1210,6 +1210,8 @@ func (p *Package) gccMachine() []string {
 		return []string{"-m64"}
 	case "mips64", "mips64le":
 		return []string{"-mabi=64"}
+	case "mips", "mipsle":
+		return []string{"-mabi=32"}
 	}
 	return nil
 }
@@ -1727,6 +1729,15 @@ func (c *typeConv) Type(dtype dwarf.Type, pos token.Pos) *Type {
 		if _, ok := base(dt.Type).(*dwarf.VoidType); ok {
 			t.Go = c.goVoidPtr
 			t.C.Set("void*")
+			dq := dt.Type
+			for {
+				if d, ok := dq.(*dwarf.QualType); ok {
+					t.C.Set(d.Qual + " " + t.C.String())
+					dq = d.Type
+				} else {
+					break
+				}
+			}
 			break
 		}
 
diff --git a/src/cmd/compile/internal/gc/inl.go b/src/cmd/compile/internal/gc/inl.go
index d8f1f24..7b2fcf8 100644
--- a/src/cmd/compile/internal/gc/inl.go
+++ b/src/cmd/compile/internal/gc/inl.go
@@ -107,6 +107,12 @@ func caninl(fn *Node) {
 		return
 	}
 
+	// If marked "go:cgo_unsafe_args", don't inline
+	if fn.Func.Pragma&CgoUnsafeArgs != 0 {
+		reason = "marked go:cgo_unsafe_args"
+		return
+	}
+
 	// If fn has no body (is defined outside of Go), cannot inline it.
 	if fn.Nbody.Len() == 0 {
 		reason = "no function body"
diff --git a/src/cmd/compile/internal/gc/noder.go b/src/cmd/compile/internal/gc/noder.go
index f9de48a..a501cb6 100644
--- a/src/cmd/compile/internal/gc/noder.go
+++ b/src/cmd/compile/internal/gc/noder.go
@@ -1022,13 +1022,14 @@ func (p *noder) error(err error) {
 func (p *noder) pragma(pos, line int, text string) syntax.Pragma {
 	switch {
 	case strings.HasPrefix(text, "line "):
-		i := strings.IndexByte(text, ':')
+		// Want to use LastIndexByte below but it's not defined in Go1.4 and bootstrap fails.
+		i := strings.LastIndex(text, ":") // look from right (Windows filenames may contain ':')
 		if i < 0 {
 			break
 		}
 		n, err := strconv.Atoi(text[i+1:])
 		if err != nil {
-			// todo: make this an error instead? it is almost certainly a bug.
+			// TODO: make this an error instead? it is almost certainly a bug.
 			break
 		}
 		if n > 1e8 {
diff --git a/src/cmd/compile/internal/gc/pgen.go b/src/cmd/compile/internal/gc/pgen.go
index acea790..643ba79 100644
--- a/src/cmd/compile/internal/gc/pgen.go
+++ b/src/cmd/compile/internal/gc/pgen.go
@@ -380,6 +380,9 @@ func compile(fn *Node) {
 	if fn.Func.Wrapper {
 		ptxt.From3.Offset |= obj.WRAPPER
 	}
+	if fn.Func.NoFramePointer {
+		ptxt.From3.Offset |= obj.NOFRAME
+	}
 	if fn.Func.Needctxt {
 		ptxt.From3.Offset |= obj.NEEDCTXT
 	}
diff --git a/src/cmd/compile/internal/gc/sinit.go b/src/cmd/compile/internal/gc/sinit.go
index 1192f3f..350c867 100644
--- a/src/cmd/compile/internal/gc/sinit.go
+++ b/src/cmd/compile/internal/gc/sinit.go
@@ -295,7 +295,9 @@ func staticcopy(l *Node, r *Node, out *[]*Node) bool {
 		if staticcopy(l, r, out) {
 			return true
 		}
-		*out = append(*out, nod(OAS, l, r))
+		// We may have skipped past one or more OCONVNOPs, so
+		// use conv to ensure r is assignable to l (#13263).
+		*out = append(*out, nod(OAS, l, conv(r, l.Type)))
 		return true
 
 	case OLITERAL:
diff --git a/src/cmd/compile/internal/gc/subr.go b/src/cmd/compile/internal/gc/subr.go
index a53ba1f..9b9a3f1 100644
--- a/src/cmd/compile/internal/gc/subr.go
+++ b/src/cmd/compile/internal/gc/subr.go
@@ -1810,6 +1810,8 @@ func genwrapper(rcvr *Type, method *Field, newnam *Sym, iface int) {
 		n := nod(ORETJMP, nil, nil)
 		n.Left = newname(methodsym(method.Sym, methodrcvr, 0))
 		fn.Nbody.Append(n)
+		// When tail-calling, we can't use a frame pointer.
+		fn.Func.NoFramePointer = true
 	} else {
 		fn.Func.Wrapper = true // ignore frame for panic+recover matching
 		call := nod(OCALL, dot, nil)
diff --git a/src/cmd/compile/internal/gc/syntax.go b/src/cmd/compile/internal/gc/syntax.go
index 8b06d3a..8848bb5 100644
--- a/src/cmd/compile/internal/gc/syntax.go
+++ b/src/cmd/compile/internal/gc/syntax.go
@@ -317,6 +317,7 @@ type Func struct {
 	Needctxt        bool   // function uses context register (has closure variables)
 	ReflectMethod   bool   // function calls reflect.Type.Method or MethodByName
 	IsHiddenClosure bool
+	NoFramePointer  bool // Must not use a frame pointer for this function
 }
 
 type Op uint8
diff --git a/src/cmd/compile/internal/gc/testdata/array.go b/src/cmd/compile/internal/gc/testdata/array.go
index 0334339..6be8d91 100644
--- a/src/cmd/compile/internal/gc/testdata/array.go
+++ b/src/cmd/compile/internal/gc/testdata/array.go
@@ -106,7 +106,7 @@ func testSliceSetElement() {
 func testSlicePanic1() {
 	defer func() {
 		if r := recover(); r != nil {
-			println("paniced as expected")
+			println("panicked as expected")
 		}
 	}()
 
@@ -119,7 +119,7 @@ func testSlicePanic1() {
 func testSlicePanic2() {
 	defer func() {
 		if r := recover(); r != nil {
-			println("paniced as expected")
+			println("panicked as expected")
 		}
 	}()
 
diff --git a/src/cmd/compile/internal/gc/testdata/string.go b/src/cmd/compile/internal/gc/testdata/string.go
index 897e874..03053a6 100644
--- a/src/cmd/compile/internal/gc/testdata/string.go
+++ b/src/cmd/compile/internal/gc/testdata/string.go
@@ -73,7 +73,7 @@ func testStructSlice() {
 func testStringSlicePanic() {
 	defer func() {
 		if r := recover(); r != nil {
-			println("paniced as expected")
+			println("panicked as expected")
 		}
 	}()
 
@@ -148,7 +148,7 @@ func testInt64Index() {
 func testInt64IndexPanic() {
 	defer func() {
 		if r := recover(); r != nil {
-			println("paniced as expected")
+			println("panicked as expected")
 		}
 	}()
 
@@ -161,7 +161,7 @@ func testInt64IndexPanic() {
 func testInt64SlicePanic() {
 	defer func() {
 		if r := recover(); r != nil {
-			println("paniced as expected")
+			println("panicked as expected")
 		}
 	}()
 
diff --git a/src/cmd/compile/internal/ssa/export_test.go b/src/cmd/compile/internal/ssa/export_test.go
index 010c4d7..3a9357d 100644
--- a/src/cmd/compile/internal/ssa/export_test.go
+++ b/src/cmd/compile/internal/ssa/export_test.go
@@ -6,6 +6,7 @@ package ssa
 
 import (
 	"cmd/internal/obj"
+	"cmd/internal/obj/x86"
 	"testing"
 )
 
@@ -16,7 +17,7 @@ var Deadcode = deadcode
 var Copyelim = copyelim
 
 func testConfig(t testing.TB) *Config {
-	testCtxt := &obj.Link{}
+	testCtxt := &obj.Link{Arch: &x86.Linkamd64}
 	return NewConfig("amd64", DummyFrontend{t}, testCtxt, true)
 }
 
@@ -67,7 +68,7 @@ func (DummyFrontend) Line(line int32) string {
 func (DummyFrontend) AllocFrame(f *Func) {
 }
 func (DummyFrontend) Syslook(s string) interface{} {
-	return nil
+	return DummySym(s)
 }
 
 func (d DummyFrontend) Logf(msg string, args ...interface{}) { d.t.Logf(msg, args...) }
@@ -98,3 +99,7 @@ func (d DummyFrontend) CanSSA(t Type) bool {
 	// There are no un-SSAable types in dummy land.
 	return true
 }
+
+type DummySym string
+
+func (s DummySym) String() string { return string(s) }
diff --git a/src/cmd/compile/internal/ssa/type_test.go b/src/cmd/compile/internal/ssa/type_test.go
index a76a065..2f91728 100644
--- a/src/cmd/compile/internal/ssa/type_test.go
+++ b/src/cmd/compile/internal/ssa/type_test.go
@@ -44,7 +44,7 @@ func (t *TypeImpl) IsVoid() bool           { return false }
 func (t *TypeImpl) String() string         { return t.Name }
 func (t *TypeImpl) SimpleString() string   { return t.Name }
 func (t *TypeImpl) ElemType() Type         { return t.Elem_ }
-func (t *TypeImpl) PtrTo() Type            { panic("not implemented") }
+func (t *TypeImpl) PtrTo() Type            { return TypeBytePtr }
 func (t *TypeImpl) NumFields() int         { panic("not implemented") }
 func (t *TypeImpl) FieldType(i int) Type   { panic("not implemented") }
 func (t *TypeImpl) FieldOff(i int) int64   { panic("not implemented") }
diff --git a/src/cmd/compile/internal/ssa/writebarrier.go b/src/cmd/compile/internal/ssa/writebarrier.go
index b914154..1eb4d7b 100644
--- a/src/cmd/compile/internal/ssa/writebarrier.go
+++ b/src/cmd/compile/internal/ssa/writebarrier.go
@@ -78,7 +78,6 @@ func writebarrier(f *Func) {
 					defer f.retSparseSet(wbs)
 				}
 
-				mem := v.Args[2]
 				line := v.Line
 
 				// there may be a sequence of WB stores in the current block. find them.
@@ -106,6 +105,20 @@ func writebarrier(f *Func) {
 					}
 				}
 
+				// find the memory before the WB stores
+				// this memory is not a WB store but it is used in a WB store.
+				var mem *Value
+				for _, w := range storeWBs {
+					a := w.Args[len(w.Args)-1]
+					if wbs.contains(a.ID) {
+						continue
+					}
+					if mem != nil {
+						b.Fatalf("two stores live simultaneously: %s, %s", mem, a)
+					}
+					mem = a
+				}
+
 				b.Values = append(b.Values[:i], others...) // move WB ops out of this block
 
 				bThen := f.NewBlock(BlockPlain)
@@ -177,20 +190,39 @@ func writebarrier(f *Func) {
 				// which may be used in subsequent blocks. Other memories in the
 				// sequence must be dead after this block since there can be only
 				// one memory live.
-				v = storeWBs[len(storeWBs)-1]
-				bEnd.Values = append(bEnd.Values, v)
-				v.Block = bEnd
-				v.reset(OpPhi)
-				v.Type = TypeMem
-				v.AddArg(memThen)
-				v.AddArg(memElse)
-				for _, w := range storeWBs[:len(storeWBs)-1] {
-					for _, a := range w.Args {
-						a.Uses--
+				last := storeWBs[0]
+				if len(storeWBs) > 1 {
+					// find the last store
+					last = nil
+					wbs.clear() // we reuse wbs to record WB stores that is used in another WB store
+					for _, w := range storeWBs {
+						wbs.add(w.Args[len(w.Args)-1].ID)
+					}
+					for _, w := range storeWBs {
+						if wbs.contains(w.ID) {
+							continue
+						}
+						if last != nil {
+							b.Fatalf("two stores live simultaneously: %s, %s", last, w)
+						}
+						last = w
 					}
 				}
-				for _, w := range storeWBs[:len(storeWBs)-1] {
-					f.freeValue(w)
+				bEnd.Values = append(bEnd.Values, last)
+				last.Block = bEnd
+				last.reset(OpPhi)
+				last.Type = TypeMem
+				last.AddArg(memThen)
+				last.AddArg(memElse)
+				for _, w := range storeWBs {
+					if w != last {
+						w.resetArgs()
+					}
+				}
+				for _, w := range storeWBs {
+					if w != last {
+						f.freeValue(w)
+					}
 				}
 
 				if f.Config.fe.Debug_wb() {
diff --git a/src/cmd/compile/internal/ssa/writebarrier_test.go b/src/cmd/compile/internal/ssa/writebarrier_test.go
new file mode 100644
index 0000000..c2ba695
--- /dev/null
+++ b/src/cmd/compile/internal/ssa/writebarrier_test.go
@@ -0,0 +1,29 @@
+// 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 "testing"
+
+func TestWriteBarrierStoreOrder(t *testing.T) {
+	// Make sure writebarrier phase works even StoreWB ops are not in dependency order
+	c := testConfig(t)
+	ptrType := &TypeImpl{Size_: 8, Ptr: true, Name: "testptr"} // dummy for testing
+	fun := Fun(c, "entry",
+		Bloc("entry",
+			Valu("start", OpInitMem, TypeMem, 0, nil),
+			Valu("sb", OpSB, TypeInvalid, 0, nil),
+			Valu("sp", OpSP, TypeInvalid, 0, nil),
+			Valu("v", OpConstNil, ptrType, 0, nil),
+			Valu("addr1", OpAddr, ptrType, 0, nil, "sb"),
+			Valu("wb2", OpStoreWB, TypeMem, 8, nil, "addr1", "v", "wb1"),
+			Valu("wb1", OpStoreWB, TypeMem, 8, nil, "addr1", "v", "start"), // wb1 and wb2 are out of order
+			Goto("exit")),
+		Bloc("exit",
+			Exit("wb2")))
+
+	CheckFunc(fun.f)
+	writebarrier(fun.f)
+	CheckFunc(fun.f)
+}
diff --git a/src/cmd/compile/internal/syntax/parser.go b/src/cmd/compile/internal/syntax/parser.go
index a2e307f..121dfb7 100644
--- a/src/cmd/compile/internal/syntax/parser.go
+++ b/src/cmd/compile/internal/syntax/parser.go
@@ -26,8 +26,6 @@ type parser struct {
 	indent []byte // tracing support
 }
 
-type parserError string // for error recovery if no error handler was installed
-
 func (p *parser) init(src io.Reader, errh ErrorHandler, pragh PragmaHandler) {
 	p.scanner.init(src, errh, pragh)
 
diff --git a/src/cmd/dist/build.go b/src/cmd/dist/build.go
index 6fb7884..4d0b1a0 100644
--- a/src/cmd/dist/build.go
+++ b/src/cmd/dist/build.go
@@ -1107,8 +1107,8 @@ var cgoEnabled = map[string]bool{
 	"linux/arm64":     true,
 	"linux/ppc64":     false,
 	"linux/ppc64le":   true,
-	"linux/mips":      false,
-	"linux/mipsle":    false,
+	"linux/mips":      true,
+	"linux/mipsle":    true,
 	"linux/mips64":    true,
 	"linux/mips64le":  true,
 	"linux/s390x":     true,
diff --git a/src/cmd/dist/test.go b/src/cmd/dist/test.go
index 508863f..a552966 100644
--- a/src/cmd/dist/test.go
+++ b/src/cmd/dist/test.go
@@ -15,6 +15,7 @@ import (
 	"os/exec"
 	"path/filepath"
 	"regexp"
+	"runtime"
 	"strconv"
 	"strings"
 	"sync"
@@ -152,8 +153,11 @@ func (t *tester) run() {
 	}
 
 	t.timeoutScale = 1
-	if t.goarch == "arm" || t.goos == "windows" {
+	switch t.goarch {
+	case "arm":
 		t.timeoutScale = 2
+	case "mips", "mipsle", "mips64", "mips64le":
+		t.timeoutScale = 4
 	}
 	if s := os.Getenv("GO_TEST_TIMEOUT_SCALE"); s != "" {
 		t.timeoutScale, err = strconv.Atoi(s)
@@ -328,6 +332,10 @@ func (t *tester) registerRaceBenchTest(pkg string) {
 	})
 }
 
+// stdOutErrAreTerminals is defined in test_linux.go, to report
+// whether stdout & stderr are terminals.
+var stdOutErrAreTerminals func() bool
+
 func (t *tester) registerTests() {
 	if strings.HasSuffix(os.Getenv("GO_BUILDER_NAME"), "-vetall") {
 		// Run vet over std and cmd and call it quits.
@@ -344,6 +352,27 @@ func (t *tester) registerTests() {
 		return
 	}
 
+	// This test needs its stdout/stderr to be terminals, so we don't run it from cmd/go's tests.
+	// See issue 18153.
+	if runtime.GOOS == "linux" {
+		t.tests = append(t.tests, distTest{
+			name:    "cmd_go_test_terminal",
+			heading: "cmd/go terminal test",
+			fn: func(dt *distTest) error {
+				t.runPending(dt)
+				if !stdOutErrAreTerminals() {
+					fmt.Println("skipping terminal test; stdout/stderr not terminals")
+					return nil
+				}
+				cmd := exec.Command("go", "test")
+				cmd.Dir = filepath.Join(os.Getenv("GOROOT"), "src/cmd/go/testdata/testterminal18153")
+				cmd.Stdout = os.Stdout
+				cmd.Stderr = os.Stderr
+				return cmd.Run()
+			},
+		})
+	}
+
 	// Fast path to avoid the ~1 second of `go list std cmd` when
 	// the caller lists specific tests to run. (as the continuous
 	// build coordinator does).
@@ -712,7 +741,7 @@ func (t *tester) internalLink() bool {
 	// Internally linking cgo is incomplete on some architectures.
 	// https://golang.org/issue/10373
 	// https://golang.org/issue/14449
-	if t.goarch == "arm64" || t.goarch == "mips64" || t.goarch == "mips64le" {
+	if t.goarch == "arm64" || t.goarch == "mips64" || t.goarch == "mips64le" || t.goarch == "mips" || t.goarch == "mipsle" {
 		return false
 	}
 	return true
@@ -757,8 +786,7 @@ func (t *tester) supportedBuildmode(mode string) bool {
 		// linux-arm64 is missing because it causes the external linker
 		// to crash, see https://golang.org/issue/17138
 		switch pair {
-		case "linux-386", "linux-amd64", "linux-arm",
-			"darwin-amd64":
+		case "linux-386", "linux-amd64", "linux-arm":
 			return true
 		}
 		return false
diff --git a/src/cmd/dist/test_linux.go b/src/cmd/dist/test_linux.go
new file mode 100644
index 0000000..b6d0aed
--- /dev/null
+++ b/src/cmd/dist/test_linux.go
@@ -0,0 +1,27 @@
+// 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.
+
+// +build linux
+
+package main
+
+import (
+	"syscall"
+	"unsafe"
+)
+
+const ioctlReadTermios = syscall.TCGETS
+
+// isTerminal reports whether fd is a terminal.
+func isTerminal(fd uintptr) bool {
+	var termios syscall.Termios
+	_, _, err := syscall.Syscall6(syscall.SYS_IOCTL, fd, ioctlReadTermios, uintptr(unsafe.Pointer(&termios)), 0, 0, 0)
+	return err == 0
+}
+
+func init() {
+	stdOutErrAreTerminals = func() bool {
+		return isTerminal(1) && isTerminal(2)
+	}
+}
diff --git a/src/cmd/dist/util.go b/src/cmd/dist/util.go
index e2f22df..511978f 100644
--- a/src/cmd/dist/util.go
+++ b/src/cmd/dist/util.go
@@ -393,6 +393,14 @@ func errprintf(format string, args ...interface{}) {
 func main() {
 	os.Setenv("TERM", "dumb") // disable escape codes in clang errors
 
+	// provide -check-armv6k first, before checking for $GOROOT so that
+	// it is possible to run this check without having $GOROOT available.
+	if len(os.Args) > 1 && os.Args[1] == "-check-armv6k" {
+		useARMv6K() // might fail with SIGILL
+		println("ARMv6K supported.")
+		os.Exit(0)
+	}
+
 	slash = string(filepath.Separator)
 
 	gohostos = runtime.GOOS
diff --git a/src/cmd/dist/util_gc.go b/src/cmd/dist/util_gc.go
index 6e099e5..698beef 100644
--- a/src/cmd/dist/util_gc.go
+++ b/src/cmd/dist/util_gc.go
@@ -25,3 +25,8 @@ func useVFPv1()
 // useVFPv3 tries to execute one VFPv3 instruction on ARM.
 // It will crash the current process if VFPv3 is missing.
 func useVFPv3()
+
+// useARMv6K tries to run ARMv6K instructions on ARM.
+// It will crash the current process if it doesn't implement
+// ARMv6K or above.
+func useARMv6K()
diff --git a/src/cmd/dist/util_gccgo.go b/src/cmd/dist/util_gccgo.go
index 5edb473..f9f01dc 100644
--- a/src/cmd/dist/util_gccgo.go
+++ b/src/cmd/dist/util_gccgo.go
@@ -22,3 +22,5 @@ func cansse2() bool { return C.supports_sse2() != 0 }
 func useVFPv1() {}
 
 func useVFPv3() {}
+
+func useARMv6K() {}
diff --git a/src/cmd/dist/vfp_arm.s b/src/cmd/dist/vfp_arm.s
index c42b593..d571f8b 100644
--- a/src/cmd/dist/vfp_arm.s
+++ b/src/cmd/dist/vfp_arm.s
@@ -15,3 +15,12 @@ TEXT ·useVFPv1(SB),NOSPLIT,$0
 TEXT ·useVFPv3(SB),NOSPLIT,$0
 	WORD $0xeeb70b00	// vmov.f64 d0, #112
 	RET
+
+// try to run ARMv6K (or above) "ldrexd" instruction
+TEXT ·useARMv6K(SB),NOSPLIT,$32
+	MOVW R13, R2
+	BIC  $15, R13
+	WORD $0xe1bd0f9f	// ldrexd r0, r1, [sp]
+	WORD $0xf57ff01f	// clrex
+	MOVW R2, R13
+	RET
diff --git a/src/cmd/dist/vfp_default.s b/src/cmd/dist/vfp_default.s
index 95ccbe3..84829be 100644
--- a/src/cmd/dist/vfp_default.s
+++ b/src/cmd/dist/vfp_default.s
@@ -11,3 +11,6 @@ TEXT ·useVFPv1(SB),NOSPLIT,$0
 
 TEXT ·useVFPv3(SB),NOSPLIT,$0
 	RET
+
+TEXT ·useARMv6K(SB),NOSPLIT,$0
+	RET
diff --git a/src/cmd/go/bug.go b/src/cmd/go/bug.go
index 2977c94..cbd258b 100644
--- a/src/cmd/go/bug.go
+++ b/src/cmd/go/bug.go
@@ -42,7 +42,11 @@ func runBug(cmd *Command, args []string) {
 	env := newEnv
 	env = append(env, extraEnvVars()...)
 	for _, e := range env {
-		fmt.Fprintf(&buf, "%s=\"%s\"\n", e.name, e.value)
+		// Hide the TERM environment variable from "go bug".
+		// See issue #18128
+		if e.name != "TERM" {
+			fmt.Fprintf(&buf, "%s=\"%s\"\n", e.name, e.value)
+		}
 	}
 	printGoDetails(&buf)
 	printOSDetails(&buf)
diff --git a/src/cmd/go/build.go b/src/cmd/go/build.go
index 684d033..98a6509 100644
--- a/src/cmd/go/build.go
+++ b/src/cmd/go/build.go
@@ -413,8 +413,7 @@ func buildModeInit() {
 		} else {
 			switch platform {
 			case "linux/amd64", "linux/arm", "linux/arm64", "linux/386",
-				"android/amd64", "android/arm", "android/arm64", "android/386",
-				"darwin/amd64":
+				"android/amd64", "android/arm", "android/arm64", "android/386":
 			default:
 				fatalf("-buildmode=plugin not supported on %s\n", platform)
 			}
@@ -2406,8 +2405,7 @@ func (gcToolchain) gc(b *builder, p *Package, archive, obj string, asmhdr bool,
 func (gcToolchain) asm(b *builder, p *Package, obj string, sfiles []string) ([]string, error) {
 	// Add -I pkg/GOOS_GOARCH so #include "textflag.h" works in .s files.
 	inc := filepath.Join(goroot, "pkg", "include")
-	ofile := obj + "asm.o"
-	args := []interface{}{buildToolExec, tool("asm"), "-o", ofile, "-trimpath", b.work, "-I", obj, "-I", inc, "-D", "GOOS_" + goos, "-D", "GOARCH_" + goarch, buildAsmflags}
+	args := []interface{}{buildToolExec, tool("asm"), "-trimpath", b.work, "-I", obj, "-I", inc, "-D", "GOOS_" + goos, "-D", "GOARCH_" + goarch, buildAsmflags}
 	if p.ImportPath == "runtime" && goarch == "386" {
 		for _, arg := range buildAsmflags {
 			if arg == "-dynlink" {
@@ -2415,13 +2413,16 @@ func (gcToolchain) asm(b *builder, p *Package, obj string, sfiles []string) ([]s
 			}
 		}
 	}
+	var ofiles []string
 	for _, sfile := range sfiles {
-		args = append(args, mkAbs(p.Dir, sfile))
-	}
-	if err := b.run(p.Dir, p.ImportPath, nil, args...); err != nil {
-		return nil, err
+		ofile := obj + sfile[:len(sfile)-len(".s")] + ".o"
+		ofiles = append(ofiles, ofile)
+		a := append(args, "-o", ofile, mkAbs(p.Dir, sfile))
+		if err := b.run(p.Dir, p.ImportPath, nil, a...); err != nil {
+			return nil, err
+		}
 	}
-	return []string{ofile}, nil
+	return ofiles, nil
 }
 
 // toolVerify checks that the command line args writes the same output file
@@ -3218,6 +3219,8 @@ func (b *builder) gccArchArgs() []string {
 		return []string{"-m64", "-march=z196"}
 	case "mips64", "mips64le":
 		return []string{"-mabi=64"}
+	case "mips", "mipsle":
+		return []string{"-mabi=32", "-march=mips32"}
 	}
 	return nil
 }
@@ -3773,7 +3776,11 @@ func instrumentInit() {
 		return
 	}
 	if buildRace && buildMSan {
-		fmt.Fprintf(os.Stderr, "go %s: may not use -race and -msan simultaneously", flag.Args()[0])
+		fmt.Fprintf(os.Stderr, "go %s: may not use -race and -msan simultaneously\n", flag.Args()[0])
+		os.Exit(2)
+	}
+	if buildMSan && (goos != "linux" || goarch != "amd64") {
+		fmt.Fprintf(os.Stderr, "-msan is not supported on %s/%s\n", goos, goarch)
 		os.Exit(2)
 	}
 	if goarch != "amd64" || goos != "linux" && goos != "freebsd" && goos != "darwin" && goos != "windows" {
diff --git a/src/cmd/go/get.go b/src/cmd/go/get.go
index 82408d6..1d7677c 100644
--- a/src/cmd/go/get.go
+++ b/src/cmd/go/get.go
@@ -205,6 +205,10 @@ var downloadRootCache = map[string]bool{}
 // download runs the download half of the get command
 // for the package named by the argument.
 func download(arg string, parent *Package, stk *importStack, mode int) {
+	if mode&useVendor != 0 {
+		// Caller is responsible for expanding vendor paths.
+		panic("internal error: download mode has useVendor set")
+	}
 	load := func(path string, mode int) *Package {
 		if parent == nil {
 			return loadPackage(path, stk)
@@ -315,32 +319,42 @@ func download(arg string, parent *Package, stk *importStack, mode int) {
 		}
 
 		// Process dependencies, now that we know what they are.
-		for _, path := range p.Imports {
+		imports := p.Imports
+		if mode&getTestDeps != 0 {
+			// Process test dependencies when -t is specified.
+			// (But don't get test dependencies for test dependencies:
+			// we always pass mode 0 to the recursive calls below.)
+			imports = stringList(imports, p.TestImports, p.XTestImports)
+		}
+		for i, path := range imports {
 			if path == "C" {
 				continue
 			}
-			// Don't get test dependencies recursively.
-			// Imports is already vendor-expanded.
-			download(path, p, stk, 0)
-		}
-		if mode&getTestDeps != 0 {
-			// Process test dependencies when -t is specified.
-			// (Don't get test dependencies for test dependencies.)
-			// We pass useVendor here because p.load does not
-			// vendor-expand TestImports and XTestImports.
-			// The call to loadImport inside download needs to do that.
-			for _, path := range p.TestImports {
-				if path == "C" {
-					continue
-				}
-				download(path, p, stk, useVendor)
+			// Fail fast on import naming full vendor path.
+			// Otherwise expand path as needed for test imports.
+			// Note that p.Imports can have additional entries beyond p.build.Imports.
+			orig := path
+			if i < len(p.build.Imports) {
+				orig = p.build.Imports[i]
 			}
-			for _, path := range p.XTestImports {
-				if path == "C" {
-					continue
+			if j, ok := findVendor(orig); ok {
+				stk.push(path)
+				err := &PackageError{
+					ImportStack: stk.copy(),
+					Err:         "must be imported as " + path[j+len("vendor/"):],
 				}
-				download(path, p, stk, useVendor)
+				stk.pop()
+				errorf("%s", err)
+				continue
+			}
+			// If this is a test import, apply vendor lookup now.
+			// We cannot pass useVendor to download, because
+			// download does caching based on the value of path,
+			// so it must be the fully qualified path already.
+			if i >= len(p.Imports) {
+				path = vendoredImportPath(p, path)
 			}
+			download(path, p, stk, 0)
 		}
 
 		if isWildcard {
diff --git a/src/cmd/go/go_test.go b/src/cmd/go/go_test.go
index 5731066..88c5443 100644
--- a/src/cmd/go/go_test.go
+++ b/src/cmd/go/go_test.go
@@ -1700,6 +1700,8 @@ func TestMissingGOPATHEnvShowsDefault(t *testing.T) {
 
 // Test go get missing GOPATH causes go get to warn if directory doesn't exist.
 func TestMissingGOPATHGetWarnsIfNotExists(t *testing.T) {
+	testenv.MustHaveExternalNetwork(t)
+
 	if _, err := exec.LookPath("git"); err != nil {
 		t.Skip("skipping because git binary not found")
 	}
@@ -1727,6 +1729,8 @@ func TestMissingGOPATHGetWarnsIfNotExists(t *testing.T) {
 
 // Test go get missing GOPATH causes no warning if directory exists.
 func TestMissingGOPATHGetDoesntWarnIfExists(t *testing.T) {
+	testenv.MustHaveExternalNetwork(t)
+
 	if _, err := exec.LookPath("git"); err != nil {
 		t.Skip("skipping because git binary not found")
 	}
@@ -1757,6 +1761,8 @@ func TestMissingGOPATHGetDoesntWarnIfExists(t *testing.T) {
 
 // Test go get missing GOPATH fails if pointed file is not a directory.
 func TestMissingGOPATHGetFailsIfItsNotDirectory(t *testing.T) {
+	testenv.MustHaveExternalNetwork(t)
+
 	tg := testgo(t)
 	defer tg.cleanup()
 
@@ -2067,9 +2073,7 @@ func TestCaseCollisions(t *testing.T) {
 
 // Issue 8181.
 func TestGoGetDashTIssue8181(t *testing.T) {
-	if testing.Short() {
-		t.Skip("skipping test that uses network in short mode")
-	}
+	testenv.MustHaveExternalNetwork(t)
 
 	tg := testgo(t)
 	defer tg.cleanup()
@@ -2083,9 +2087,7 @@ func TestGoGetDashTIssue8181(t *testing.T) {
 
 func TestIssue11307(t *testing.T) {
 	// go get -u was not working except in checkout directory
-	if testing.Short() {
-		t.Skip("skipping test that uses network in short mode")
-	}
+	testenv.MustHaveExternalNetwork(t)
 
 	tg := testgo(t)
 	defer tg.cleanup()
@@ -3716,3 +3718,28 @@ func TestLinkXImportPathEscape(t *testing.T) {
 		tg.t.Fatal(`incorrect output: expected "linkXworked\n"`)
 	}
 }
+
+// Issue 18044.
+func TestLdBindNow(t *testing.T) {
+	tg := testgo(t)
+	defer tg.cleanup()
+	tg.parallel()
+	tg.setenv("LD_BIND_NOW", "1")
+	tg.run("help")
+}
+
+// Issue 18225.
+// This is really a cmd/asm issue but this is a convenient place to test it.
+func TestConcurrentAsm(t *testing.T) {
+	tg := testgo(t)
+	defer tg.cleanup()
+	tg.parallel()
+	asm := `DATA ·constants<>+0x0(SB)/8,$0
+GLOBL ·constants<>(SB),8,$8
+`
+	tg.tempFile("go/src/p/a.s", asm)
+	tg.tempFile("go/src/p/b.s", asm)
+	tg.tempFile("go/src/p/p.go", `package p`)
+	tg.setenv("GOPATH", tg.path("go"))
+	tg.run("build", "p")
+}
diff --git a/src/cmd/go/pkg.go b/src/cmd/go/pkg.go
index 852a1a0..98e722b 100644
--- a/src/cmd/go/pkg.go
+++ b/src/cmd/go/pkg.go
@@ -178,7 +178,9 @@ func (p *Package) copyBuild(pp *build.Package) {
 	p.CgoCXXFLAGS = pp.CgoCXXFLAGS
 	p.CgoLDFLAGS = pp.CgoLDFLAGS
 	p.CgoPkgConfig = pp.CgoPkgConfig
-	p.Imports = pp.Imports
+	// We modify p.Imports in place, so make copy now.
+	p.Imports = make([]string, len(pp.Imports))
+	copy(p.Imports, pp.Imports)
 	p.TestGoFiles = pp.TestGoFiles
 	p.TestImports = pp.TestImports
 	p.XTestGoFiles = pp.XTestGoFiles
diff --git a/src/cmd/go/test.go b/src/cmd/go/test.go
index 95914d5..f27144c 100644
--- a/src/cmd/go/test.go
+++ b/src/cmd/go/test.go
@@ -13,7 +13,6 @@ import (
 	"go/doc"
 	"go/parser"
 	"go/token"
-	"io"
 	"os"
 	"os/exec"
 	"path"
@@ -1122,12 +1121,8 @@ func (b *builder) runTest(a *action) error {
 	cmd.Env = envForDir(cmd.Dir, origEnv)
 	var buf bytes.Buffer
 	if testStreamOutput {
-		// The only way to keep the ordering of the messages and still
-		// intercept its contents. os/exec will share the same Pipe for
-		// both Stdout and Stderr when running the test program.
-		mw := io.MultiWriter(os.Stdout, &buf)
-		cmd.Stdout = mw
-		cmd.Stderr = mw
+		cmd.Stdout = os.Stdout
+		cmd.Stderr = os.Stderr
 	} else {
 		cmd.Stdout = &buf
 		cmd.Stderr = &buf
@@ -1192,7 +1187,7 @@ func (b *builder) runTest(a *action) error {
 	t := fmt.Sprintf("%.3fs", time.Since(t0).Seconds())
 	if err == nil {
 		norun := ""
-		if testShowPass && !testStreamOutput {
+		if testShowPass {
 			a.testOutput.Write(out)
 		}
 		if bytes.HasPrefix(out, noTestsToRun[1:]) || bytes.Contains(out, noTestsToRun) {
@@ -1204,9 +1199,7 @@ func (b *builder) runTest(a *action) error {
 
 	setExitStatus(1)
 	if len(out) > 0 {
-		if !testStreamOutput {
-			a.testOutput.Write(out)
-		}
+		a.testOutput.Write(out)
 		// assume printing the test binary's exit status is superfluous
 	} else {
 		fmt.Fprintf(a.testOutput, "%s\n", err)
diff --git a/src/cmd/go/testdata/testterminal18153/terminal_test.go b/src/cmd/go/testdata/testterminal18153/terminal_test.go
new file mode 100644
index 0000000..d662e55
--- /dev/null
+++ b/src/cmd/go/testdata/testterminal18153/terminal_test.go
@@ -0,0 +1,39 @@
+// 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.
+
+// +build linux
+
+// This test is run by src/cmd/dist/test.go (cmd_go_test_terminal),
+// and not by cmd/go's tests. This is because this test requires that
+// that it be called with its stdout and stderr being a terminal.
+// dist doesn't run `cmd/go test` against this test directory if
+// dist's stdout/stderr aren't terminals.
+//
+// See issue 18153.
+
+package p
+
+import (
+	"syscall"
+	"testing"
+	"unsafe"
+)
+
+const ioctlReadTermios = syscall.TCGETS
+
+// isTerminal reports whether fd is a terminal.
+func isTerminal(fd uintptr) bool {
+	var termios syscall.Termios
+	_, _, err := syscall.Syscall6(syscall.SYS_IOCTL, fd, ioctlReadTermios, uintptr(unsafe.Pointer(&termios)), 0, 0, 0)
+	return err == 0
+}
+
+func TestIsTerminal(t *testing.T) {
+	if !isTerminal(1) {
+		t.Errorf("stdout is not a terminal")
+	}
+	if !isTerminal(2) {
+		t.Errorf("stderr is not a terminal")
+	}
+}
diff --git a/src/cmd/go/vendor_test.go b/src/cmd/go/vendor_test.go
index 226b537..deec02e 100644
--- a/src/cmd/go/vendor_test.go
+++ b/src/cmd/go/vendor_test.go
@@ -188,6 +188,42 @@ func TestVendorGetUpdate(t *testing.T) {
 	tg.run("get", "-u", "github.com/rsc/go-get-issue-11864")
 }
 
+func TestVendorGetU(t *testing.T) {
+	testenv.MustHaveExternalNetwork(t)
+
+	tg := testgo(t)
+	defer tg.cleanup()
+	tg.makeTempdir()
+	tg.setenv("GOPATH", tg.path("."))
+	tg.run("get", "-u", "github.com/rsc/go-get-issue-11864")
+}
+
+func TestVendorGetTU(t *testing.T) {
+	testenv.MustHaveExternalNetwork(t)
+
+	tg := testgo(t)
+	defer tg.cleanup()
+	tg.makeTempdir()
+	tg.setenv("GOPATH", tg.path("."))
+	tg.run("get", "-t", "-u", "github.com/rsc/go-get-issue-11864/...")
+}
+
+func TestVendorGetBadVendor(t *testing.T) {
+	testenv.MustHaveExternalNetwork(t)
+
+	for _, suffix := range []string{"bad/imp", "bad/imp2", "bad/imp3", "..."} {
+		t.Run(suffix, func(t *testing.T) {
+			tg := testgo(t)
+			defer tg.cleanup()
+			tg.makeTempdir()
+			tg.setenv("GOPATH", tg.path("."))
+			tg.runFail("get", "-t", "-u", "github.com/rsc/go-get-issue-18219/"+suffix)
+			tg.grepStderr("must be imported as", "did not find error about vendor import")
+			tg.mustNotExist(tg.path("src/github.com/rsc/vendor"))
+		})
+	}
+}
+
 func TestGetSubmodules(t *testing.T) {
 	testenv.MustHaveExternalNetwork(t)
 
diff --git a/src/cmd/internal/obj/obj.go b/src/cmd/internal/obj/line.go
similarity index 100%
rename from src/cmd/internal/obj/obj.go
rename to src/cmd/internal/obj/line.go
diff --git a/src/cmd/internal/obj/mips/obj0.go b/src/cmd/internal/obj/mips/obj0.go
index 221fd42..12cfb31 100644
--- a/src/cmd/internal/obj/mips/obj0.go
+++ b/src/cmd/internal/obj/mips/obj0.go
@@ -32,6 +32,7 @@ package mips
 import (
 	"cmd/internal/obj"
 	"cmd/internal/sys"
+	"encoding/binary"
 	"fmt"
 	"math"
 )
@@ -533,6 +534,43 @@ func preprocess(ctxt *obj.Link, cursym *obj.LSym) {
 		}
 	}
 
+	if ctxt.Mode&Mips32 != 0 {
+		// rewrite MOVD into two MOVF in 32-bit mode to avoid unaligned memory access
+		for p = cursym.Text; p != nil; p = p1 {
+			p1 = p.Link
+
+			if p.As != AMOVD {
+				continue
+			}
+			if p.From.Type != obj.TYPE_MEM && p.To.Type != obj.TYPE_MEM {
+				continue
+			}
+
+			p.As = AMOVF
+			q = ctxt.NewProg()
+			*q = *p
+			q.Link = p.Link
+			p.Link = q
+			p1 = q.Link
+
+			var regOff int16
+			if ctxt.Arch.ByteOrder == binary.BigEndian {
+				regOff = 1 // load odd register first
+			}
+			if p.From.Type == obj.TYPE_MEM {
+				reg := REG_F0 + (p.To.Reg-REG_F0)&^1
+				p.To.Reg = reg + regOff
+				q.To.Reg = reg + 1 - regOff
+				q.From.Offset += 4
+			} else if p.To.Type == obj.TYPE_MEM {
+				reg := REG_F0 + (p.From.Reg-REG_F0)&^1
+				p.From.Reg = reg + regOff
+				q.From.Reg = reg + 1 - regOff
+				q.To.Offset += 4
+			}
+		}
+	}
+
 	if nosched {
 		// if we don't do instruction scheduling, simply add
 		// NOP after each branch instruction.
diff --git a/src/cmd/internal/obj/pcln.go b/src/cmd/internal/obj/pcln.go
index d9893e4..e4a724a 100644
--- a/src/cmd/internal/obj/pcln.go
+++ b/src/cmd/internal/obj/pcln.go
@@ -6,9 +6,8 @@ package obj
 
 import "log"
 
-func addvarint(ctxt *Link, d *Pcdata, val uint32) {
-	var v uint32
-	for v = val; v >= 0x80; v >>= 7 {
+func addvarint(d *Pcdata, v uint32) {
+	for ; v >= 0x80; v >>= 7 {
 		d.P = append(d.P, uint8(v|0x80))
 	}
 	d.P = append(d.P, uint8(v))
@@ -98,7 +97,7 @@ func funcpctab(ctxt *Link, dst *Pcdata, func_ *LSym, desc string, valfunc func(*
 		}
 
 		if started != 0 {
-			addvarint(ctxt, dst, uint32((p.Pc-pc)/int64(ctxt.Arch.MinLC)))
+			addvarint(dst, uint32((p.Pc-pc)/int64(ctxt.Arch.MinLC)))
 			pc = p.Pc
 		}
 
@@ -108,7 +107,7 @@ func funcpctab(ctxt *Link, dst *Pcdata, func_ *LSym, desc string, valfunc func(*
 		} else {
 			delta <<= 1
 		}
-		addvarint(ctxt, dst, delta)
+		addvarint(dst, delta)
 		oldval = val
 		started = 1
 		val = valfunc(ctxt, func_, val, p, 1, arg)
@@ -118,8 +117,8 @@ func funcpctab(ctxt *Link, dst *Pcdata, func_ *LSym, desc string, valfunc func(*
 		if ctxt.Debugpcln != 0 {
 			ctxt.Logf("%6x done\n", uint64(func_.Text.Pc+func_.Size))
 		}
-		addvarint(ctxt, dst, uint32((func_.Size-pc)/int64(ctxt.Arch.MinLC)))
-		addvarint(ctxt, dst, 0) // terminator
+		addvarint(dst, uint32((func_.Size-pc)/int64(ctxt.Arch.MinLC)))
+		addvarint(dst, 0) // terminator
 	}
 
 	if ctxt.Debugpcln != 0 {
diff --git a/src/cmd/internal/obj/reloctype_string.go b/src/cmd/internal/obj/reloctype_string.go
index 6de617c..09c1312 100644
--- a/src/cmd/internal/obj/reloctype_string.go
+++ b/src/cmd/internal/obj/reloctype_string.go
@@ -4,9 +4,9 @@ package obj
 
 import "fmt"
 
-const _RelocType_name = "R_ADDRR_ADDRPOWERR_ADDRARM64R_ADDRMIPSR_ADDROFFR_SIZER_CALLR_CALLARMR_CALLARM64R_CALLINDR_CALLPOWERR_CALLMIPSR_CONSTR_PCRELR_TLS_LER_TLS_IER_GOTOFFR_PLT0R_PLT1R_PLT2R_USEFIELDR_USETYPER_METHODOFFR_POWER_TOCR_GOTPCRELR_JMPMIPSR_DWARFREFR_ARM64_TLS_LER_ARM64_TLS_IER_ARM64_GOTPCRELR_POWER_TLS_LER_POWER_TLS_IER_POWER_TLSR_ADDRPOWER_DSR_ADDRPOWER_GOTR_ADDRPOWER_PCRELR_ADDRPOWER_TOCRELR_ADDRPOWER_TOCREL_DSR_PCRELDBLR_ADDRMIPSUR_ADDRMIPSTLS"
+const _RelocType_name = "R_ADDRR_ADDRPOWERR_ADDRARM64R_ADDRMIPSR_ADDROFFR_WEAKADDROFFR_SIZER_CALLR_CALLARMR_CALLARM64R_CALLINDR_CALLPOWERR_CALLMIPSR_CONSTR_PCRELR_TLS_LER_TLS_IER_GOTOFFR_PLT0R_PLT1R_PLT2R_USEFIELDR_USETYPER_METHODOFFR_POWER_TOCR_GOTPCRELR_JMPMIPSR_DWARFREFR_ARM64_TLS_LER_ARM64_TLS_IER_ARM64_GOTPCRELR_POWER_TLS_LER_POWER_TLS_IER_POWER_TLSR_ADDRPOWER_DSR_ADDRPOWER_GOTR_ADDRPOWER_PCRELR_ADDRPOWER_TOCRELR_ADDRPOWER_TOCREL_DSR_PCRELDBLR_ADDRMIPSUR_ADDRMIPSTLS"
 
-var _RelocType_index = [...]uint16{0, 6, 17, 28, 38, 47, 53, 59, 68, 79, 88, 99, 109, 116, 123, 131, 139, 147, 153, 159, 165, 175, 184, 195, 206, 216, 225, 235, 249, 263, 279, 293, 307, 318, 332, 347, 364, 382, 403, 413, 424, 437}
+var _RelocType_index = [...]uint16{0, 6, 17, 28, 38, 47, 60, 66, 72, 81, 92, 101, 112, 122, 129, 136, 144, 152, 160, 166, 172, 178, 188, 197, 208, 219, 229, 238, 248, 262, 276, 292, 306, 320, 331, 345, 360, 377, 395, 416, 426, 437, 450}
 
 func (i RelocType) String() string {
 	i -= 1
diff --git a/src/cmd/internal/obj/x86/obj6.go b/src/cmd/internal/obj/x86/obj6.go
index 102d8c3..eb6f867 100644
--- a/src/cmd/internal/obj/x86/obj6.go
+++ b/src/cmd/internal/obj/x86/obj6.go
@@ -632,11 +632,27 @@ func preprocess(ctxt *obj.Link, cursym *obj.LSym) {
 		autoffset = 0
 	}
 
+	hasCall := false
+	for q := p; q != nil; q = q.Link {
+		if q.As == obj.ACALL || q.As == obj.ADUFFCOPY || q.As == obj.ADUFFZERO {
+			hasCall = true
+			break
+		}
+	}
+
 	var bpsize int
-	if p.Mode == 64 && ctxt.Framepointer_enabled && autoffset > 0 && p.From3.Offset&obj.NOFRAME == 0 {
-		// Make room for to save a base pointer. If autoffset == 0,
-		// this might do something special like a tail jump to
-		// another function, so in that case we omit this.
+	if p.Mode == 64 && ctxt.Framepointer_enabled &&
+		p.From3.Offset&obj.NOFRAME == 0 && // (1) below
+		!(autoffset == 0 && p.From3.Offset&obj.NOSPLIT != 0) && // (2) below
+		!(autoffset == 0 && !hasCall) { // (3) below
+		// Make room to save a base pointer.
+		// There are 2 cases we must avoid:
+		// 1) If noframe is set (which we do for functions which tail call).
+		// 2) Scary runtime internals which would be all messed up by frame pointers.
+		//    We detect these using a heuristic: frameless nosplit functions.
+		//    TODO: Maybe someday we label them all with NOFRAME and get rid of this heuristic.
+		// For performance, we also want to avoid:
+		// 3) Frameless leaf functions
 		bpsize = ctxt.Arch.PtrSize
 		autoffset += int32(bpsize)
 		p.To.Offset += int64(bpsize)
diff --git a/src/cmd/internal/objfile/goobj.go b/src/cmd/internal/objfile/goobj.go
index 230137e..c04987c 100644
--- a/src/cmd/internal/objfile/goobj.go
+++ b/src/cmd/internal/objfile/goobj.go
@@ -114,14 +114,14 @@ func (f *goobjFile) PCToLine(pc uint64) (string, int, *gosym.Func) {
 		if err != nil {
 			return "", 0, nil
 		}
-		fileID := gosym.PCValue(pcfile, pc-uint64(s.Data.Offset), arch.MinLC)
+		fileID := int(pcValue(pcfile, pc-uint64(s.Data.Offset), arch))
 		fileName := s.Func.File[fileID]
 		pcline := make([]byte, s.Func.PCLine.Size)
 		_, err = f.f.ReadAt(pcline, s.Func.PCLine.Offset)
 		if err != nil {
 			return "", 0, nil
 		}
-		line := gosym.PCValue(pcline, pc-uint64(s.Data.Offset), arch.MinLC)
+		line := int(pcValue(pcline, pc-uint64(s.Data.Offset), arch))
 		// Note: we provide only the name in the Func structure.
 		// We could provide more if needed.
 		return fileName, line, &gosym.Func{Sym: &gosym.Sym{Name: s.Name}}
@@ -129,6 +129,53 @@ func (f *goobjFile) PCToLine(pc uint64) (string, int, *gosym.Func) {
 	return "", 0, nil
 }
 
+// pcValue looks up the given PC in a pc value table. target is the
+// offset of the pc from the entry point.
+func pcValue(tab []byte, target uint64, arch *sys.Arch) int32 {
+	val := int32(-1)
+	var pc uint64
+	for step(&tab, &pc, &val, pc == 0, arch) {
+		if target < pc {
+			return val
+		}
+	}
+	return -1
+}
+
+// step advances to the next pc, value pair in the encoded table.
+func step(p *[]byte, pc *uint64, val *int32, first bool, arch *sys.Arch) bool {
+	uvdelta := readvarint(p)
+	if uvdelta == 0 && !first {
+		return false
+	}
+	if uvdelta&1 != 0 {
+		uvdelta = ^(uvdelta >> 1)
+	} else {
+		uvdelta >>= 1
+	}
+	vdelta := int32(uvdelta)
+	pcdelta := readvarint(p) * uint32(arch.MinLC)
+	*pc += uint64(pcdelta)
+	*val += vdelta
+	return true
+}
+
+// readvarint reads, removes, and returns a varint from *p.
+func readvarint(p *[]byte) uint32 {
+	var v, shift uint32
+	s := *p
+	for shift = 0; ; shift += 7 {
+		b := s[0]
+		s = s[1:]
+		v |= (uint32(b) & 0x7F) << shift
+		if b&0x80 == 0 {
+			break
+		}
+	}
+	*p = s
+	return v
+}
+
 // We treat the whole object file as the text section.
 func (f *goobjFile) text() (textStart uint64, text []byte, err error) {
 	var info os.FileInfo
diff --git a/src/cmd/link/doc.go b/src/cmd/link/doc.go
index 16fddf2..ba07da9 100644
--- a/src/cmd/link/doc.go
+++ b/src/cmd/link/doc.go
@@ -41,6 +41,8 @@ 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/ld/config.go b/src/cmd/link/internal/ld/config.go
index c9ee884..7d00ff1 100644
--- a/src/cmd/link/internal/ld/config.go
+++ b/src/cmd/link/internal/ld/config.go
@@ -184,7 +184,7 @@ func mustLinkExternal(ctxt *Link) (res bool, reason string) {
 	// Internally linking cgo is incomplete on some architectures.
 	// https://golang.org/issue/10373
 	// https://golang.org/issue/14449
-	if iscgo && SysArch.InFamily(sys.ARM64, sys.MIPS64) {
+	if iscgo && SysArch.InFamily(sys.ARM64, sys.MIPS64, sys.MIPS) {
 		return true, obj.GOARCH + " does not support internal cgo"
 	}
 
diff --git a/src/cmd/link/internal/ld/data.go b/src/cmd/link/internal/ld/data.go
index eaf6aa2..aca8973 100644
--- a/src/cmd/link/internal/ld/data.go
+++ b/src/cmd/link/internal/ld/data.go
@@ -1250,7 +1250,7 @@ func (p *GCProg) AddSym(s *Symbol) {
 }
 
 // dataSortKey is used to sort a slice of data symbol *Symbol pointers.
-// The sort keys are kept inline to improve cache behaviour while sorting.
+// The sort keys are kept inline to improve cache behavior while sorting.
 type dataSortKey struct {
 	size int64
 	name string
@@ -1976,6 +1976,13 @@ func dodataSect(ctxt *Link, symn obj.SymKind, syms []*Symbol) (result []*Symbol,
 			copy(syms[first+2:], syms[first+1:second])
 			syms[first+0] = rel
 			syms[first+1] = plt
+
+			// Make sure alignment doesn't introduce a gap.
+			// Setting the alignment explicitly prevents
+			// symalign from basing it on the size and
+			// getting it wrong.
+			rel.Align = int32(SysArch.RegSize)
+			plt.Align = int32(SysArch.RegSize)
 		}
 	}
 
@@ -2107,6 +2114,7 @@ func assignAddress(ctxt *Link, sect *Section, n int, sym *Symbol, va uint64) (*S
 		// Create new section, set the starting Vaddr
 		sect = addsection(&Segtext, ".text", 05)
 		sect.Vaddr = va
+		sym.Sect = sect
 
 		// Create a symbol for the start of the secondary text sections
 		ctxt.Syms.Lookup(fmt.Sprintf("runtime.text.%d", n), 0).Sect = sect
diff --git a/src/cmd/link/internal/ld/elf.go b/src/cmd/link/internal/ld/elf.go
index b4d5aae..1d8a5dd 100644
--- a/src/cmd/link/internal/ld/elf.go
+++ b/src/cmd/link/internal/ld/elf.go
@@ -10,6 +10,7 @@ import (
 	"crypto/sha1"
 	"encoding/binary"
 	"encoding/hex"
+	"io"
 	"path/filepath"
 	"sort"
 	"strings"
@@ -961,7 +962,7 @@ func Elfinit(ctxt *Link) {
 				ehdr.flags = 0x5000002 // has entry point, Version5 EABI
 			}
 		} else if SysArch.Family == sys.MIPS {
-			ehdr.flags = 0x50000000 /* MIPS 32 */
+			ehdr.flags = 0x50001004 /* MIPS 32 CPIC O32*/
 		}
 		fallthrough
 	default:
@@ -2130,7 +2131,7 @@ func (ctxt *Link) doelf() {
 		sort.Sort(byPkg(ctxt.Library))
 		h := sha1.New()
 		for _, l := range ctxt.Library {
-			h.Write(l.hash)
+			io.WriteString(h, l.hash)
 		}
 		addgonote(ctxt, ".note.go.abihash", ELF_NOTE_GOABIHASH_TAG, h.Sum([]byte{}))
 		addgonote(ctxt, ".note.go.pkg-list", ELF_NOTE_GOPKGLIST_TAG, pkglistfornote)
@@ -2776,7 +2777,7 @@ func Elfadddynsym(ctxt *Link, s *Symbol) {
 		/* type */
 		t := STB_GLOBAL << 4
 
-		// TODO(mwhudson): presumably the behaviour should actually be the same on both arm and 386.
+		// TODO(mwhudson): presumably the behavior should actually be the same on both arm and 386.
 		if SysArch.Family == sys.I386 && s.Attr.CgoExport() && s.Type&obj.SMASK == obj.STEXT {
 			t |= STT_FUNC
 		} else if SysArch.Family == sys.ARM && s.Attr.CgoExportDynamic() && s.Type&obj.SMASK == obj.STEXT {
diff --git a/src/cmd/link/internal/ld/lib.go b/src/cmd/link/internal/ld/lib.go
index fb32190..74d79d3 100644
--- a/src/cmd/link/internal/ld/lib.go
+++ b/src/cmd/link/internal/ld/lib.go
@@ -39,6 +39,7 @@ import (
 	"crypto/sha1"
 	"debug/elf"
 	"encoding/binary"
+	"encoding/hex"
 	"fmt"
 	"io"
 	"io/ioutil"
@@ -603,6 +604,16 @@ func (ctxt *Link) loadlib() {
 		}
 	}
 
+	// If package versioning is required, generate a hash of the
+	// the packages used in the link.
+	if Buildmode == BuildmodeShared || Buildmode == BuildmodePlugin || ctxt.Syms.ROLookup("plugin.Open", 0) != nil {
+		for i = 0; i < len(ctxt.Library); i++ {
+			if ctxt.Library[i].Shlib == "" {
+				genhash(ctxt, ctxt.Library[i])
+			}
+		}
+	}
+
 	if SysArch == sys.Arch386 {
 		if (Buildmode == BuildmodeCArchive && Iself) || Buildmode == BuildmodeCShared || Buildmode == BuildmodePIE || ctxt.DynlinkingGo() {
 			got := ctxt.Syms.Lookup("_GLOBAL_OFFSET_TABLE_", 0)
@@ -678,6 +689,29 @@ func nextar(bp *bio.Reader, off int64, a *ArHdr) int64 {
 	return arsize + SAR_HDR
 }
 
+func genhash(ctxt *Link, lib *Library) {
+	f, err := bio.Open(lib.File)
+	if err != nil {
+		Errorf(nil, "cannot open file %s for hash generation: %v", lib.File, err)
+		return
+	}
+	defer f.Close()
+
+	var arhdr ArHdr
+	l := nextar(f, int64(len(ARMAG)), &arhdr)
+	if l <= 0 {
+		Errorf(nil, "%s: short read on archive file symbol header", lib.File)
+		return
+	}
+
+	h := sha1.New()
+	if _, err := io.CopyN(h, f, atolwhex(arhdr.size)); err != nil {
+		Errorf(nil, "bad read of %s for hash generation: %v", lib.File, err)
+		return
+	}
+	lib.hash = hex.EncodeToString(h.Sum(nil))
+}
+
 func objfile(ctxt *Link, lib *Library) {
 	pkg := pathtoprefix(lib.Pkg)
 
@@ -720,17 +754,6 @@ func objfile(ctxt *Link, lib *Library) {
 		goto out
 	}
 
-	if Buildmode == BuildmodeShared || Buildmode == BuildmodePlugin || ctxt.Syms.ROLookup("plugin.Open", 0) != nil {
-		before := f.Offset()
-		pkgdefBytes := make([]byte, atolwhex(arhdr.size))
-		if _, err := io.ReadFull(f, pkgdefBytes); err != nil {
-			Errorf(nil, "%s: short read on archive file symbol header: %v", lib.File, err)
-		}
-		hash := sha1.Sum(pkgdefBytes)
-		lib.hash = hash[:]
-		f.Seek(before, 0)
-	}
-
 	off += l
 
 	ldpkg(ctxt, f, pkg, atolwhex(arhdr.size), lib.File, Pkgdef)
@@ -1234,6 +1257,8 @@ func hostlinkArchArgs() []string {
 		// nothing needed
 	case sys.MIPS64:
 		return []string{"-mabi=64"}
+	case sys.MIPS:
+		return []string{"-mabi=32"}
 	}
 	return nil
 }
diff --git a/src/cmd/link/internal/ld/link.go b/src/cmd/link/internal/ld/link.go
index ab7e49b..ffe0873 100644
--- a/src/cmd/link/internal/ld/link.go
+++ b/src/cmd/link/internal/ld/link.go
@@ -223,7 +223,7 @@ type Library struct {
 	File        string
 	Pkg         string
 	Shlib       string
-	hash        []byte
+	hash        string
 	imports     []*Library
 	textp       []*Symbol // text symbols defined in this library
 	dupTextSyms []*Symbol // dupok text symbols defined in this library
diff --git a/src/cmd/link/internal/ld/macho.go b/src/cmd/link/internal/ld/macho.go
index c88af64..f3687da 100644
--- a/src/cmd/link/internal/ld/macho.go
+++ b/src/cmd/link/internal/ld/macho.go
@@ -684,6 +684,29 @@ func machosymorder(ctxt *Link) {
 	}
 }
 
+// machoShouldExport reports whether a symbol needs to be exported.
+//
+// When dynamically linking, all non-local variables and plugin-exported
+// symbols need to be exported.
+func machoShouldExport(ctxt *Link, s *Symbol) bool {
+	if !ctxt.DynlinkingGo() || s.Attr.Local() {
+		return false
+	}
+	if Buildmode == BuildmodePlugin && strings.HasPrefix(s.Extname, *flagPluginPath) {
+		return true
+	}
+	if strings.HasPrefix(s.Name, "type.") && !strings.HasPrefix(s.Name, "type..") {
+		// reduce runtime typemap pressure, but do not
+		// export alg functions (type..*), as these
+		// appear in pclntable.
+		return true
+	}
+	if strings.HasPrefix(s.Name, "go.link.pkghash") {
+		return true
+	}
+	return s.Type >= obj.SELFSECT // only writable sections
+}
+
 func machosymtab(ctxt *Link) {
 	symtab := ctxt.Syms.Lookup(".machosymtab", 0)
 	symstr := ctxt.Syms.Lookup(".machosymstr", 0)
@@ -692,13 +715,17 @@ func machosymtab(ctxt *Link) {
 		s := sortsym[i]
 		Adduint32(ctxt, symtab, uint32(symstr.Size))
 
+		export := machoShouldExport(ctxt, s)
+
 		// In normal buildmodes, only add _ to C symbols, as
 		// Go symbols have dot in the name.
 		//
-		// When dynamically linking, prefix all non-local
-		// symbols with _ as dlsym on darwin requires it to
-		// resolve any symbol.
-		if !strings.Contains(s.Extname, ".") || (ctxt.DynlinkingGo() && !s.Attr.Local()) {
+		// Do not export C symbols in plugins, as runtime C
+		// symbols like crosscall2 are in pclntab and end up
+		// pointing at the host binary, breaking unwinding.
+		// See Issue #18190.
+		cexport := !strings.Contains(s.Extname, ".") && (Buildmode != BuildmodePlugin || onlycsymbol(s))
+		if cexport || export {
 			Adduint8(ctxt, symstr, '_')
 		}
 
@@ -711,7 +738,7 @@ func machosymtab(ctxt *Link) {
 			Adduint16(ctxt, symtab, 0)                  // desc
 			adduintxx(ctxt, symtab, 0, SysArch.PtrSize) // no value
 		} else {
-			if s.Attr.CgoExport() || (ctxt.DynlinkingGo() && !s.Attr.Local()) {
+			if s.Attr.CgoExport() || export {
 				Adduint8(ctxt, symtab, 0x0f)
 			} else {
 				Adduint8(ctxt, symtab, 0x0e)
diff --git a/src/cmd/link/internal/ld/pcln.go b/src/cmd/link/internal/ld/pcln.go
index 5a6c425..d317501 100644
--- a/src/cmd/link/internal/ld/pcln.go
+++ b/src/cmd/link/internal/ld/pcln.go
@@ -154,10 +154,26 @@ func renumberfiles(ctxt *Link, files []*Symbol, d *Pcdata) {
 	*d = out
 }
 
+// onlycsymbol reports whether this is a cgo symbol provided by the
+// runtime and only used from C code.
+func onlycsymbol(s *Symbol) bool {
+	switch s.Name {
+	case "_cgo_topofstack", "_cgo_panic", "crosscall2":
+		return true
+	}
+	return false
+}
+
 func container(s *Symbol) int {
+	if s == nil {
+		return 0
+	}
+	if Buildmode == BuildmodePlugin && onlycsymbol(s) {
+		return 1
+	}
 	// We want to generate func table entries only for the "lowest level" symbols,
 	// not containers of subsymbols.
-	if s != nil && s.Type&obj.SCONTAINER != 0 {
+	if s.Type&obj.SCONTAINER != 0 {
 		return 1
 	}
 	return 0
diff --git a/src/cmd/link/internal/ld/symtab.go b/src/cmd/link/internal/ld/symtab.go
index 98ce3ad..dd0e540 100644
--- a/src/cmd/link/internal/ld/symtab.go
+++ b/src/cmd/link/internal/ld/symtab.go
@@ -602,8 +602,7 @@ func (ctxt *Link) symtab() {
 	adduint(ctxt, moduledata, uint64(nitablinks))
 	adduint(ctxt, moduledata, uint64(nitablinks))
 	// The ptab slice
-	if ptab := ctxt.Syms.ROLookup("go.plugin.tabs", 0); ptab != nil {
-		ptab.Attr |= AttrReachable
+	if ptab := ctxt.Syms.ROLookup("go.plugin.tabs", 0); ptab != nil && ptab.Attr.Reachable() {
 		ptab.Attr |= AttrLocal
 		ptab.Type = obj.SRODATA
 
diff --git a/src/cmd/link/internal/mips/asm.go b/src/cmd/link/internal/mips/asm.go
index b2c7289..a591b06 100644
--- a/src/cmd/link/internal/mips/asm.go
+++ b/src/cmd/link/internal/mips/asm.go
@@ -47,7 +47,33 @@ func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool {
 }
 
 func elfreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) int {
-	return -1
+	ld.Thearch.Lput(uint32(sectoff))
+
+	elfsym := r.Xsym.ElfsymForReloc()
+	switch r.Type {
+	default:
+		return -1
+
+	case obj.R_ADDR:
+		if r.Siz != 4 {
+			return -1
+		}
+		ld.Thearch.Lput(ld.R_MIPS_32 | uint32(elfsym)<<8)
+
+	case obj.R_ADDRMIPS:
+		ld.Thearch.Lput(ld.R_MIPS_LO16 | uint32(elfsym)<<8)
+
+	case obj.R_ADDRMIPSU:
+		ld.Thearch.Lput(ld.R_MIPS_HI16 | uint32(elfsym)<<8)
+
+	case obj.R_ADDRMIPSTLS:
+		ld.Thearch.Lput(ld.R_MIPS_TLS_TPREL_LO16 | uint32(elfsym)<<8)
+
+	case obj.R_CALLMIPS, obj.R_JMPMIPS:
+		ld.Thearch.Lput(ld.R_MIPS_26 | uint32(elfsym)<<8)
+	}
+
+	return 0
 }
 
 func elfsetupplt(ctxt *ld.Link) {
@@ -58,9 +84,50 @@ func machoreloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) int {
 	return -1
 }
 
+func applyrel(r *ld.Reloc, s *ld.Symbol, val *int64, t int64) {
+	o := ld.SysArch.ByteOrder.Uint32(s.P[r.Off:])
+	switch r.Type {
+	case obj.R_ADDRMIPS, obj.R_ADDRMIPSTLS:
+		*val = int64(o&0xffff0000 | uint32(t)&0xffff)
+	case obj.R_ADDRMIPSU:
+		*val = int64(o&0xffff0000 | uint32((t+(1<<15))>>16)&0xffff)
+	case obj.R_CALLMIPS, obj.R_JMPMIPS:
+		*val = int64(o&0xfc000000 | uint32(t>>2)&^0xfc000000)
+	}
+}
+
 func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int {
 	if ld.Linkmode == ld.LinkExternal {
-		return -1
+		switch r.Type {
+		default:
+			return -1
+
+		case obj.R_ADDRMIPS, obj.R_ADDRMIPSU:
+
+			r.Done = 0
+
+			// set up addend for eventual relocation via outer symbol.
+			rs := r.Sym
+			r.Xadd = r.Add
+			for rs.Outer != nil {
+				r.Xadd += ld.Symaddr(rs) - ld.Symaddr(rs.Outer)
+				rs = rs.Outer
+			}
+
+			if rs.Type != obj.SHOSTOBJ && rs.Type != obj.SDYNIMPORT && rs.Sect == nil {
+				ld.Errorf(s, "missing section for %s", rs.Name)
+			}
+			r.Xsym = rs
+			applyrel(r, s, val, r.Xadd)
+			return 0
+
+		case obj.R_ADDRMIPSTLS, obj.R_CALLMIPS, obj.R_JMPMIPS:
+			r.Done = 0
+			r.Xsym = r.Sym
+			r.Xadd = r.Add
+			applyrel(r, s, val, r.Add)
+			return 0
+		}
 	}
 
 	switch r.Type {
@@ -72,23 +139,33 @@ func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int {
 		*val = ld.Symaddr(r.Sym) + r.Add - ld.Symaddr(ctxt.Syms.Lookup(".got", 0))
 		return 0
 
-	case obj.R_ADDRMIPS,
-		obj.R_ADDRMIPSU:
+	case obj.R_ADDRMIPS, obj.R_ADDRMIPSU:
 		t := ld.Symaddr(r.Sym) + r.Add
-		o1 := ld.SysArch.ByteOrder.Uint32(s.P[r.Off:])
-		if r.Type == obj.R_ADDRMIPS {
-			*val = int64(o1&0xffff0000 | uint32(t)&0xffff)
-		} else {
-			*val = int64(o1&0xffff0000 | uint32((t+1<<15)>>16)&0xffff)
-		}
+		applyrel(r, s, val, t)
 		return 0
 
-	case obj.R_CALLMIPS,
-		obj.R_JMPMIPS:
-		// Low 26 bits = (S + A) >> 2
+	case obj.R_CALLMIPS, obj.R_JMPMIPS:
 		t := ld.Symaddr(r.Sym) + r.Add
-		o1 := ld.SysArch.ByteOrder.Uint32(s.P[r.Off:])
-		*val = int64(o1&0xfc000000 | uint32(t>>2)&^0xfc000000)
+
+		if t&3 != 0 {
+			ld.Errorf(s, "direct call is not aligned: %s %x", r.Sym.Name, t)
+		}
+
+		// check if target address is in the same 256 MB region as the next instruction
+		if (s.Value+int64(r.Off)+4)&0xf0000000 != (t & 0xf0000000) {
+			ld.Errorf(s, "direct call too far: %s %x", r.Sym.Name, t)
+		}
+
+		applyrel(r, s, val, t)
+		return 0
+
+	case obj.R_ADDRMIPSTLS:
+		// thread pointer is at 0x7000 offset from the start of TLS data area
+		t := ld.Symaddr(r.Sym) + r.Add - 0x7000
+		if t < -32768 || t >= 32678 {
+			ld.Errorf(s, "TLS offset out of range %d", t)
+		}
+		applyrel(r, s, val, t)
 		return 0
 	}
 
diff --git a/src/cmd/objdump/objdump_test.go b/src/cmd/objdump/objdump_test.go
index 30b964d..10fc716 100644
--- a/src/cmd/objdump/objdump_test.go
+++ b/src/cmd/objdump/objdump_test.go
@@ -166,7 +166,7 @@ func TestDisasmExtld(t *testing.T) {
 		t.Skipf("skipping on %s, no support for external linking, issue 9038", runtime.GOARCH)
 	case "arm64":
 		t.Skipf("skipping on %s, issue 10106", runtime.GOARCH)
-	case "mips64", "mips64le":
+	case "mips64", "mips64le", "mips", "mipsle":
 		t.Skipf("skipping on %s, issue 12559 and 12560", runtime.GOARCH)
 	case "s390x":
 		t.Skipf("skipping on %s, issue 15255", runtime.GOARCH)
diff --git a/src/cmd/pprof/internal/driver/driver.go b/src/cmd/pprof/internal/driver/driver.go
index 931985a..0f1ed6e 100644
--- a/src/cmd/pprof/internal/driver/driver.go
+++ b/src/cmd/pprof/internal/driver/driver.go
@@ -780,14 +780,14 @@ func processFlags(p *profile.Profile, ui plugin.UI, f *flags) error {
 
 	var err error
 	si, sm := *f.flagSampleIndex, *f.flagMean || *f.flagMeanDelay
-	si, err = sampleIndex(p, &f.flagTotalDelay, si, 1, "delay", "-total_delay", err)
-	si, err = sampleIndex(p, &f.flagMeanDelay, si, 1, "delay", "-mean_delay", err)
-	si, err = sampleIndex(p, &f.flagContentions, si, 0, "contentions", "-contentions", err)
+	si, err = sampleIndex(p, &f.flagTotalDelay, si, "delay", "-total_delay", err)
+	si, err = sampleIndex(p, &f.flagMeanDelay, si, "delay", "-mean_delay", err)
+	si, err = sampleIndex(p, &f.flagContentions, si, "contentions", "-contentions", err)
 
-	si, err = sampleIndex(p, &f.flagInUseSpace, si, 1, "inuse_space", "-inuse_space", err)
-	si, err = sampleIndex(p, &f.flagInUseObjects, si, 0, "inuse_objects", "-inuse_objects", err)
-	si, err = sampleIndex(p, &f.flagAllocSpace, si, 1, "alloc_space", "-alloc_space", err)
-	si, err = sampleIndex(p, &f.flagAllocObjects, si, 0, "alloc_objects", "-alloc_objects", err)
+	si, err = sampleIndex(p, &f.flagInUseSpace, si, "inuse_space", "-inuse_space", err)
+	si, err = sampleIndex(p, &f.flagInUseObjects, si, "inuse_objects", "-inuse_objects", err)
+	si, err = sampleIndex(p, &f.flagAllocSpace, si, "alloc_space", "-alloc_space", err)
+	si, err = sampleIndex(p, &f.flagAllocObjects, si, "alloc_objects", "-alloc_objects", err)
 
 	if si == -1 {
 		// Use last value if none is requested.
@@ -806,7 +806,6 @@ func processFlags(p *profile.Profile, ui plugin.UI, f *flags) error {
 
 func sampleIndex(p *profile.Profile, flag **bool,
 	sampleIndex int,
-	newSampleIndex int,
 	sampleType, option string,
 	err error) (int, error) {
 	if err != nil || !**flag {
@@ -816,11 +815,12 @@ func sampleIndex(p *profile.Profile, flag **bool,
 	if sampleIndex != -1 {
 		return 0, fmt.Errorf("set at most one sample value selection option")
 	}
-	if newSampleIndex >= len(p.SampleType) ||
-		p.SampleType[newSampleIndex].Type != sampleType {
-		return 0, fmt.Errorf("option %s not valid for this profile", option)
+	for index, s := range p.SampleType {
+		if sampleType == s.Type {
+			return index, nil
+		}
 	}
-	return newSampleIndex, nil
+	return 0, fmt.Errorf("option %s not valid for this profile", option)
 }
 
 func countFlags(bs []*bool) int {
diff --git a/src/cmd/pprof/internal/svg/svgpan.go b/src/cmd/pprof/internal/svg/svgpan.go
index 4975b10..d8f12af 100644
--- a/src/cmd/pprof/internal/svg/svgpan.go
+++ b/src/cmd/pprof/internal/svg/svgpan.go
@@ -17,7 +17,7 @@ const svgPanJS = `
  *  - Mouse zooming (using the wheel)
  *  - Object dragging
  *
- * You can configure the behaviour of the pan/zoom/drag with the variables
+ * You can configure the behavior of the pan/zoom/drag with the variables
  * listed in the CONFIGURATION section of this file.
  *
  * Known issues:
diff --git a/src/cmd/vet/structtag.go b/src/cmd/vet/structtag.go
index 814bbda..872fde7 100644
--- a/src/cmd/vet/structtag.go
+++ b/src/cmd/vet/structtag.go
@@ -54,14 +54,37 @@ func checkCanonicalFieldTag(f *File, field *ast.Field, seen *map[[2]string]token
 		if val == "" || val == "-" || val[0] == ',' {
 			continue
 		}
+		if key == "xml" && len(field.Names) > 0 && field.Names[0].Name == "XMLName" {
+			// XMLName defines the XML element name of the struct being
+			// checked. That name cannot collide with element or attribute
+			// names defined on other fields of the struct. Vet does not have a
+			// check for untagged fields of type struct defining their own name
+			// by containing a field named XMLName; see issue 18256.
+			continue
+		}
 		if i := strings.Index(val, ","); i >= 0 {
+			if key == "xml" {
+				// Use a separate namespace for XML attributes.
+				for _, opt := range strings.Split(val[i:], ",") {
+					if opt == "attr" {
+						key += " attribute" // Key is part of the error message.
+						break
+					}
+				}
+			}
 			val = val[:i]
 		}
 		if *seen == nil {
 			*seen = map[[2]string]token.Pos{}
 		}
 		if pos, ok := (*seen)[[2]string{key, val}]; ok {
-			f.Badf(field.Pos(), "struct field %s repeats %s tag %q also at %s", field.Names[0].Name, key, val, f.loc(pos))
+			var name string
+			if len(field.Names) > 0 {
+				name = field.Names[0].Name
+			} else {
+				name = field.Type.(*ast.Ident).Name
+			}
+			f.Badf(field.Pos(), "struct field %s repeats %s tag %q also at %s", name, key, val, f.loc(pos))
 		} else {
 			(*seen)[[2]string{key, val}] = field.Pos()
 		}
diff --git a/src/cmd/vet/testdata/structtag.go b/src/cmd/vet/testdata/structtag.go
index cba990f..363aa89 100644
--- a/src/cmd/vet/testdata/structtag.go
+++ b/src/cmd/vet/testdata/structtag.go
@@ -6,6 +6,8 @@
 
 package testdata
 
+import "encoding/xml"
+
 type StructTagTest struct {
 	A   int "hello"            // ERROR "not compatible with reflect.StructTag.Get: bad syntax for struct tag pair"
 	B   int "\tx:\"y\""        // ERROR "not compatible with reflect.StructTag.Get: bad syntax for struct tag key"
@@ -37,30 +39,44 @@ type JSONEmbeddedField struct {
 	unexp                     `is:"embedded,notexported" json:"unexp"` // OK for now, see issue 7363
 }
 
+type AnonymousJSON struct{}
+type AnonymousXML struct{}
+
 type DuplicateJSONFields struct {
 	JSON              int `json:"a"`
-	DuplicateJSON     int `json:"a"` // ERROR "struct field DuplicateJSON repeats json tag .a. also at testdata/structtag.go:41"
+	DuplicateJSON     int `json:"a"` // ERROR "struct field DuplicateJSON repeats json tag .a. also at testdata/structtag.go:46"
 	IgnoredJSON       int `json:"-"`
 	OtherIgnoredJSON  int `json:"-"`
 	OmitJSON          int `json:",omitempty"`
 	OtherOmitJSON     int `json:",omitempty"`
-	DuplicateOmitJSON int `json:"a,omitempty"` // ERROR "struct field DuplicateOmitJSON repeats json tag .a. also at testdata/structtag.go:41"
+	DuplicateOmitJSON int `json:"a,omitempty"` // ERROR "struct field DuplicateOmitJSON repeats json tag .a. also at testdata/structtag.go:46"
 	NonJSON           int `foo:"a"`
 	DuplicateNonJSON  int `foo:"a"`
 	Embedded          struct {
 		DuplicateJSON int `json:"a"` // OK because its not in the same struct type
 	}
+	AnonymousJSON `json:"a"` // ERROR "struct field AnonymousJSON repeats json tag .a. also at testdata/structtag.go:46"
 
 	XML              int `xml:"a"`
-	DuplicateXML     int `xml:"a"` // ERROR "struct field DuplicateXML repeats xml tag .a. also at testdata/structtag.go:54"
+	DuplicateXML     int `xml:"a"` // ERROR "struct field DuplicateXML repeats xml tag .a. also at testdata/structtag.go:60"
 	IgnoredXML       int `xml:"-"`
 	OtherIgnoredXML  int `xml:"-"`
 	OmitXML          int `xml:",omitempty"`
 	OtherOmitXML     int `xml:",omitempty"`
-	DuplicateOmitXML int `xml:"a,omitempty"` // ERROR "struct field DuplicateOmitXML repeats xml tag .a. also at testdata/structtag.go:54"
+	DuplicateOmitXML int `xml:"a,omitempty"` // ERROR "struct field DuplicateOmitXML repeats xml tag .a. also at testdata/structtag.go:60"
 	NonXML           int `foo:"a"`
 	DuplicateNonXML  int `foo:"a"`
 	Embedded         struct {
 		DuplicateXML int `xml:"a"` // OK because its not in the same struct type
 	}
+	AnonymousXML `xml:"a"` // ERROR "struct field AnonymousXML repeats xml tag .a. also at testdata/structtag.go:60"
+	Attribute    struct {
+		XMLName     xml.Name `xml:"b"`
+		NoDup       int      `xml:"b"`                // OK because XMLName above affects enclosing struct.
+		Attr        int      `xml:"b,attr"`           // OK because <b b="0"><b>0</b></b> is valid.
+		DupAttr     int      `xml:"b,attr"`           // ERROR "struct field DupAttr repeats xml attribute tag .b. also at testdata/structtag.go:76"
+		DupOmitAttr int      `xml:"b,omitempty,attr"` // ERROR "struct field DupOmitAttr repeats xml attribute tag .b. also at testdata/structtag.go:76"
+
+		AnonymousXML `xml:"b,attr"` // ERROR "struct field AnonymousXML repeats xml attribute tag .b. also at testdata/structtag.go:76"
+	}
 }
diff --git a/src/context/context_test.go b/src/context/context_test.go
index 2d604a0..6efc06c 100644
--- a/src/context/context_test.go
+++ b/src/context/context_test.go
@@ -595,14 +595,14 @@ func XTestCancelRemoves(t testingT) {
 	_, cancel := WithCancel(ctx)
 	checkChildren("with WithCancel child ", ctx, 1)
 	cancel()
-	checkChildren("after cancelling WithCancel child", ctx, 0)
+	checkChildren("after canceling WithCancel child", ctx, 0)
 
 	ctx, _ = WithCancel(Background())
 	checkChildren("after creation", ctx, 0)
 	_, cancel = WithTimeout(ctx, 60*time.Minute)
 	checkChildren("with WithTimeout child ", ctx, 1)
 	cancel()
-	checkChildren("after cancelling WithTimeout child", ctx, 0)
+	checkChildren("after canceling WithTimeout child", ctx, 0)
 }
 
 func XTestWithCancelCanceledParent(t testingT) {
diff --git a/src/crypto/aes/cipher_s390x.go b/src/crypto/aes/cipher_s390x.go
index 6030c25..28d0ac9 100644
--- a/src/crypto/aes/cipher_s390x.go
+++ b/src/crypto/aes/cipher_s390x.go
@@ -27,7 +27,7 @@ type aesCipherAsm struct {
 // cryptBlocks invokes the cipher message (KM) instruction with
 // the given function code. This is equivalent to AES in ECB
 // mode. The length must be a multiple of BlockSize (16).
-//go:noesape
+//go:noescape
 func cryptBlocks(c code, key, dst, src *byte, length int)
 
 var useAsm = cipherhw.AESGCMSupport()
diff --git a/src/crypto/aes/const.go b/src/crypto/aes/const.go
index aee73a7..cbac5ff 100644
--- a/src/crypto/aes/const.go
+++ b/src/crypto/aes/const.go
@@ -4,6 +4,13 @@
 
 // Package aes implements AES encryption (formerly Rijndael), as defined in
 // U.S. Federal Information Processing Standards Publication 197.
+//
+// The AES operations in this package are not implemented using constant-time algorithms.
+// An exception is when running on systems with enabled hardware support for AES
+// that makes these operations constant-time. Examples include amd64 systems using AES-NI
+// extensions and s390x systems using Message-Security-Assist extensions.
+// On such systems, when the result of NewCipher is passed to cipher.NewGCM,
+// the GHASH operation used by GCM is also constant-time.
 package aes
 
 // This file contains AES constants - 8720 bytes of initialized data.
diff --git a/src/crypto/aes/gcm_s390x.go b/src/crypto/aes/gcm_s390x.go
index 9eaaf7c..438310d 100644
--- a/src/crypto/aes/gcm_s390x.go
+++ b/src/crypto/aes/gcm_s390x.go
@@ -257,7 +257,7 @@ func (g *gcmAsm) Open(dst, nonce, ciphertext, data []byte) ([]byte, error) {
 	if subtle.ConstantTimeCompare(expectedTag[:], tag) != 1 {
 		// The AESNI code decrypts and authenticates concurrently, and
 		// so overwrites dst in the event of a tag mismatch. That
-		// behaviour is mimicked here in order to be consistent across
+		// behavior is mimicked here in order to be consistent across
 		// platforms.
 		for i := range out {
 			out[i] = 0
diff --git a/src/crypto/cipher/gcm.go b/src/crypto/cipher/gcm.go
index cfc5769..62085aa 100644
--- a/src/crypto/cipher/gcm.go
+++ b/src/crypto/cipher/gcm.go
@@ -74,6 +74,10 @@ type gcm struct {
 
 // NewGCM returns the given 128-bit, block cipher wrapped in Galois Counter Mode
 // with the standard nonce length.
+//
+// In general, the GHASH operation performed by this implementation of GCM is not constant-time.
+// An exception is when the underlying Block was created by aes.NewCipher
+// on systems with hardware support for AES. See the crypto/aes package documentation for details.
 func NewGCM(cipher Block) (AEAD, error) {
 	return NewGCMWithNonceSize(cipher, gcmStandardNonceSize)
 }
@@ -184,7 +188,7 @@ func (g *gcm) Open(dst, nonce, ciphertext, data []byte) ([]byte, error) {
 	if subtle.ConstantTimeCompare(expectedTag[:], tag) != 1 {
 		// The AESNI code decrypts and authenticates concurrently, and
 		// so overwrites dst in the event of a tag mismatch. That
-		// behaviour is mimicked here in order to be consistent across
+		// behavior is mimicked here in order to be consistent across
 		// platforms.
 		for i := range out {
 			out[i] = 0
diff --git a/src/crypto/dsa/dsa.go b/src/crypto/dsa/dsa.go
index e9b6a0c..bc0c3e3 100644
--- a/src/crypto/dsa/dsa.go
+++ b/src/crypto/dsa/dsa.go
@@ -3,6 +3,8 @@
 // license that can be found in the LICENSE file.
 
 // Package dsa implements the Digital Signature Algorithm, as defined in FIPS 186-3.
+//
+// The DSA operations in this package are not implemented using constant-time algorithms.
 package dsa
 
 import (
@@ -189,17 +191,21 @@ func fermatInverse(k, P *big.Int) *big.Int {
 // Note that FIPS 186-3 section 4.6 specifies that the hash should be truncated
 // to the byte-length of the subgroup. This function does not perform that
 // truncation itself.
+//
+// Be aware that calling Sign with an attacker-controlled PrivateKey may
+// require an arbitrary amount of CPU.
 func Sign(rand io.Reader, priv *PrivateKey, hash []byte) (r, s *big.Int, err error) {
 	// FIPS 186-3, section 4.6
 
 	n := priv.Q.BitLen()
-	if n&7 != 0 {
+	if priv.Q.Sign() <= 0 || priv.P.Sign() <= 0 || priv.G.Sign() <= 0 || priv.X.Sign() <= 0 || n&7 != 0 {
 		err = ErrInvalidPublicKey
 		return
 	}
 	n >>= 3
 
-	for {
+	var attempts int
+	for attempts = 10; attempts > 0; attempts-- {
 		k := new(big.Int)
 		buf := make([]byte, n)
 		for {
@@ -208,6 +214,10 @@ func Sign(rand io.Reader, priv *PrivateKey, hash []byte) (r, s *big.Int, err err
 				return
 			}
 			k.SetBytes(buf)
+			// priv.Q must be >= 128 because the test above
+			// requires it to be > 0 and that
+			//    ceil(log_2(Q)) mod 8 = 0
+			// Thus this loop will quickly terminate.
 			if k.Sign() > 0 && k.Cmp(priv.Q) < 0 {
 				break
 			}
@@ -235,6 +245,12 @@ func Sign(rand io.Reader, priv *PrivateKey, hash []byte) (r, s *big.Int, err err
 		}
 	}
 
+	// Only degenerate private keys will require more than a handful of
+	// attempts.
+	if attempts == 0 {
+		return nil, nil, ErrInvalidPublicKey
+	}
+
 	return
 }
 
diff --git a/src/crypto/dsa/dsa_test.go b/src/crypto/dsa/dsa_test.go
index 568416d..b89aeae 100644
--- a/src/crypto/dsa/dsa_test.go
+++ b/src/crypto/dsa/dsa_test.go
@@ -73,6 +73,14 @@ func TestParameterGeneration(t *testing.T) {
 	testParameterGeneration(t, L3072N256, 3072, 256)
 }
 
+func fromHex(s string) *big.Int {
+	result, ok := new(big.Int).SetString(s, 16)
+	if !ok {
+		panic(s)
+	}
+	return result
+}
+
 func TestSignAndVerify(t *testing.T) {
 	var priv PrivateKey
 	priv.P, _ = new(big.Int).SetString("A9B5B793FB4785793D246BAE77E8FF63CA52F442DA763C440259919FE1BC1D6065A9350637A04F75A2F039401D49F08E066C4D275A5A65DA5684BC563C14289D7AB8A67163BFBF79D85972619AD2CFF55AB0EE77A9002B0EF96293BDD0F42685EBB2C66C327079F6C98000FBCB79AACDE1BC6F9D5C7B1A97E3D9D54ED7951FEF", 16)
@@ -83,3 +91,33 @@ func TestSignAndVerify(t *testing.T) {
 
 	testSignAndVerify(t, 0, &priv)
 }
+
+func TestSigningWithDegenerateKeys(t *testing.T) {
+	// Signing with degenerate private keys should not cause an infinite
+	// loop.
+	badKeys := []struct{
+		p, q, g, y, x string
+	}{
+		{"00", "01", "00", "00", "00"},
+		{"01", "ff", "00", "00", "00"},
+	}
+
+	for i, test := range badKeys {
+		priv := PrivateKey{
+			PublicKey: PublicKey{
+				Parameters: Parameters {
+					P: fromHex(test.p),
+					Q: fromHex(test.q),
+					G: fromHex(test.g),
+				},
+				Y: fromHex(test.y),
+			},
+			X: fromHex(test.x),
+		}
+
+		hashed := []byte("testing")
+		if _, _, err := Sign(rand.Reader, &priv, hashed); err == nil {
+			t.Errorf("#%d: unexpected success", i)
+		}
+	}
+}
diff --git a/src/crypto/elliptic/elliptic.go b/src/crypto/elliptic/elliptic.go
index c02df45..d352724 100644
--- a/src/crypto/elliptic/elliptic.go
+++ b/src/crypto/elliptic/elliptic.go
@@ -367,18 +367,24 @@ func initP521() {
 }
 
 // P256 returns a Curve which implements P-256 (see FIPS 186-3, section D.2.3)
+//
+// The cryptographic operations are implemented using constant-time algorithms.
 func P256() Curve {
 	initonce.Do(initAll)
 	return p256
 }
 
 // P384 returns a Curve which implements P-384 (see FIPS 186-3, section D.2.4)
+//
+// The cryptographic operations do not use constant-time algorithms.
 func P384() Curve {
 	initonce.Do(initAll)
 	return p384
 }
 
 // P521 returns a Curve which implements P-521 (see FIPS 186-3, section D.2.5)
+//
+// The cryptographic operations do not use constant-time algorithms.
 func P521() Curve {
 	initonce.Do(initAll)
 	return p521
diff --git a/src/crypto/elliptic/p224.go b/src/crypto/elliptic/p224.go
index de266ca..22d0e24 100644
--- a/src/crypto/elliptic/p224.go
+++ b/src/crypto/elliptic/p224.go
@@ -35,7 +35,9 @@ func initP224() {
 	p224FromBig(&p224.b, p224.B)
 }
 
-// P224 returns a Curve which implements P-224 (see FIPS 186-3, section D.2.2)
+// P224 returns a Curve which implements P-224 (see FIPS 186-3, section D.2.2).
+//
+// The cryptographic operations are implemented using constant-time algorithms.
 func P224() Curve {
 	initonce.Do(initAll)
 	return p224
diff --git a/src/crypto/rsa/rsa.go b/src/crypto/rsa/rsa.go
index f809a9b..1de4fcb 100644
--- a/src/crypto/rsa/rsa.go
+++ b/src/crypto/rsa/rsa.go
@@ -18,6 +18,8 @@
 // with v1.5/OAEP and signing/verifying with v1.5/PSS. If one needs to abstract
 // over the public-key primitive, the PrivateKey struct implements the
 // Decrypter and Signer interfaces from the crypto package.
+//
+// The RSA operations in this package are not implemented using constant-time algorithms.
 package rsa
 
 import (
diff --git a/src/crypto/x509/root_cgo_darwin.go b/src/crypto/x509/root_cgo_darwin.go
index ea86b60..8e80533 100644
--- a/src/crypto/x509/root_cgo_darwin.go
+++ b/src/crypto/x509/root_cgo_darwin.go
@@ -73,10 +73,11 @@ int useOldCode() {
 //
 // On success it returns 0 and fills pemRoots with a CFDataRef that contains the extracted root
 // certificates of the system. On failure, the function returns -1.
+// Additionally, it fills untrustedPemRoots with certs that must be removed from pemRoots.
 //
-// Note: The CFDataRef returned in pemRoots must be released (using CFRelease) after
-// we've consumed its content.
-int FetchPEMRoots(CFDataRef *pemRoots) {
+// Note: The CFDataRef returned in pemRoots and untrustedPemRoots must
+// be released (using CFRelease) after we've consumed its content.
+int FetchPEMRoots(CFDataRef *pemRoots, CFDataRef *untrustedPemRoots) {
 	if (useOldCode()) {
 		return FetchPEMRoots_MountainLion(pemRoots);
 	}
@@ -93,23 +94,69 @@ int FetchPEMRoots(CFDataRef *pemRoots) {
 		return -1;
 	}
 
+	// kSecTrustSettingsResult is defined as CFSTR("kSecTrustSettingsResult"),
+	// but the Go linker's internal linking mode can't handle CFSTR relocations.
+	// Create our own dynamic string instead and release it below.
+	CFStringRef policy = CFStringCreateWithCString(NULL, "kSecTrustSettingsResult", kCFStringEncodingUTF8);
+
 	CFMutableDataRef combinedData = CFDataCreateMutable(kCFAllocatorDefault, 0);
+	CFMutableDataRef combinedUntrustedData = CFDataCreateMutable(kCFAllocatorDefault, 0);
 	for (int i = 0; i < numDomains; i++) {
 		CFArrayRef certs = NULL;
-		// Only get certificates from domain that are trusted
 		OSStatus err = SecTrustSettingsCopyCertificates(domains[i], &certs);
 		if (err != noErr) {
 			continue;
 		}
 
-		int numCerts = CFArrayGetCount(certs);
+		CFIndex numCerts = CFArrayGetCount(certs);
 		for (int j = 0; j < numCerts; j++) {
 			CFDataRef data = NULL;
 			CFErrorRef errRef = NULL;
+			CFArrayRef trustSettings = NULL;
 			SecCertificateRef cert = (SecCertificateRef)CFArrayGetValueAtIndex(certs, j);
 			if (cert == NULL) {
 				continue;
 			}
+			// We only want trusted certs.
+			int untrusted = 0;
+			if (i != 0) {
+				// Certs found in the system domain are always trusted. If the user
+				// configures "Never Trust" on such a cert, it will also be found in the
+				// admin or user domain, causing it to be added to untrustedPemRoots. The
+				// Go code will then clean this up.
+
+				// Trust may be stored in any of the domains. According to Apple's
+				// SecTrustServer.c, "user trust settings overrule admin trust settings",
+				// so take the last trust settings array we find.
+				// Skip the system domain since it is always trusted.
+				for (int k = 1; k < numDomains; k++) {
+					CFArrayRef domainTrustSettings = NULL;
+					err = SecTrustSettingsCopyTrustSettings(cert, domains[k], &domainTrustSettings);
+					if (err == errSecSuccess && domainTrustSettings != NULL) {
+						if (trustSettings) {
+							CFRelease(trustSettings);
+						}
+						trustSettings = domainTrustSettings;
+					}
+				}
+				if (trustSettings == NULL) {
+					// "this certificate must be verified to a known trusted certificate"; aka not a root.
+					continue;
+				}
+				for (CFIndex k = 0; k < CFArrayGetCount(trustSettings); k++) {
+					CFNumberRef cfNum;
+					CFDictionaryRef tSetting = (CFDictionaryRef)CFArrayGetValueAtIndex(trustSettings, k);
+					if (CFDictionaryGetValueIfPresent(tSetting, policy, (const void**)&cfNum)){
+						SInt32 result = 0;
+						CFNumberGetValue(cfNum, kCFNumberSInt32Type, &result);
+						// TODO: The rest of the dictionary specifies conditions for evaluation.
+						if (result == kSecTrustSettingsResultDeny) {
+							untrusted = 1;
+						}
+					}
+				}
+				CFRelease(trustSettings);
+			}
 			// We only want to add Root CAs, so make sure Subject and Issuer Name match
 			CFDataRef subjectName = SecCertificateCopyNormalizedSubjectContent(cert, &errRef);
 			if (errRef != NULL) {
@@ -138,13 +185,16 @@ int FetchPEMRoots(CFDataRef *pemRoots) {
 			}
 
 			if (data != NULL) {
-				CFDataAppendBytes(combinedData, CFDataGetBytePtr(data), CFDataGetLength(data));
+				CFMutableDataRef appendTo = untrusted ? combinedUntrustedData : combinedData;
+				CFDataAppendBytes(appendTo, CFDataGetBytePtr(data), CFDataGetLength(data));
 				CFRelease(data);
 			}
 		}
 		CFRelease(certs);
 	}
+	CFRelease(policy);
 	*pemRoots = combinedData;
+	*untrustedPemRoots = combinedUntrustedData;
 	return 0;
 }
 */
@@ -158,7 +208,8 @@ func loadSystemRoots() (*CertPool, error) {
 	roots := NewCertPool()
 
 	var data C.CFDataRef = nil
-	err := C.FetchPEMRoots(&data)
+	var untrustedData C.CFDataRef = nil
+	err := C.FetchPEMRoots(&data, &untrustedData)
 	if err == -1 {
 		// TODO: better error message
 		return nil, errors.New("crypto/x509: failed to load darwin system roots with cgo")
@@ -167,5 +218,19 @@ func loadSystemRoots() (*CertPool, error) {
 	defer C.CFRelease(C.CFTypeRef(data))
 	buf := C.GoBytes(unsafe.Pointer(C.CFDataGetBytePtr(data)), C.int(C.CFDataGetLength(data)))
 	roots.AppendCertsFromPEM(buf)
-	return roots, nil
+	if untrustedData == nil {
+		return roots, nil
+	}
+	defer C.CFRelease(C.CFTypeRef(untrustedData))
+	buf = C.GoBytes(unsafe.Pointer(C.CFDataGetBytePtr(untrustedData)), C.int(C.CFDataGetLength(untrustedData)))
+	untrustedRoots := NewCertPool()
+	untrustedRoots.AppendCertsFromPEM(buf)
+
+	trustedRoots := NewCertPool()
+	for _, c := range roots.certs {
+		if !untrustedRoots.contains(c) {
+			trustedRoots.AddCert(c)
+		}
+	}
+	return trustedRoots, nil
 }
diff --git a/src/crypto/x509/root_darwin.go b/src/crypto/x509/root_darwin.go
index 78de56c..59b303d 100644
--- a/src/crypto/x509/root_darwin.go
+++ b/src/crypto/x509/root_darwin.go
@@ -6,12 +6,27 @@
 
 package x509
 
-import "os/exec"
+import (
+	"bytes"
+	"encoding/pem"
+	"fmt"
+	"io/ioutil"
+	"os"
+	"os/exec"
+	"strconv"
+	"sync"
+	"syscall"
+)
 
 func (c *Certificate) systemVerify(opts *VerifyOptions) (chains [][]*Certificate, err error) {
 	return nil, nil
 }
 
+// This code is only used when compiling without cgo.
+// It is here, instead of root_nocgo_darwin.go, so that tests can check it
+// even if the tests are run with cgo enabled.
+// The linker will not include these unused functions in binaries built with cgo enabled.
+
 func execSecurityRoots() (*CertPool, error) {
 	cmd := exec.Command("/usr/bin/security", "find-certificate", "-a", "-p", "/System/Library/Keychains/SystemRootCertificates.keychain")
 	data, err := cmd.Output()
@@ -19,7 +34,100 @@ func execSecurityRoots() (*CertPool, error) {
 		return nil, err
 	}
 
-	roots := NewCertPool()
-	roots.AppendCertsFromPEM(data)
+	var (
+		mu    sync.Mutex
+		roots = NewCertPool()
+	)
+	add := func(cert *Certificate) {
+		mu.Lock()
+		defer mu.Unlock()
+		roots.AddCert(cert)
+	}
+	blockCh := make(chan *pem.Block)
+	var wg sync.WaitGroup
+	for i := 0; i < 4; i++ {
+		wg.Add(1)
+		go func() {
+			defer wg.Done()
+			for block := range blockCh {
+				verifyCertWithSystem(block, add)
+			}
+		}()
+	}
+	for len(data) > 0 {
+		var block *pem.Block
+		block, data = pem.Decode(data)
+		if block == nil {
+			break
+		}
+		if block.Type != "CERTIFICATE" || len(block.Headers) != 0 {
+			continue
+		}
+		blockCh <- block
+	}
+	close(blockCh)
+	wg.Wait()
 	return roots, nil
 }
+
+func verifyCertWithSystem(block *pem.Block, add func(*Certificate)) {
+	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)
+	}
+}
+
+var versionCache struct {
+	sync.Once
+	major int
+}
+
+// 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")
+		if err != nil {
+			return
+		}
+		for i, c := range release {
+			if c == '.' {
+				release = release[:i]
+				break
+			}
+		}
+		major, err := strconv.Atoi(release)
+		if err != nil {
+			return
+		}
+		versionCache.major = major
+	})
+	return versionCache.major <= 15
+}
diff --git a/src/crypto/x509/root_darwin_test.go b/src/crypto/x509/root_darwin_test.go
index 8b6b151..d6d8d07 100644
--- a/src/crypto/x509/root_darwin_test.go
+++ b/src/crypto/x509/root_darwin_test.go
@@ -26,10 +26,14 @@ func TestSystemRoots(t *testing.T) {
 		if tt == nil {
 			t.Fatal("no system roots")
 		}
-		// On Mavericks, there are 212 bundled certs; require only
-		// 150 here, since this is just a sanity check, and the
-		// exact number will vary over time.
-		if want, have := 150, len(tt.certs); have < want {
+		// On Mavericks, there are 212 bundled certs, at least
+		// there was at one point in time on one machine.
+		// (Maybe it was a corp laptop with extra certs?)
+		// Other OS X users report
+		// 135, 142, 145...  Let's try requiring at least 100,
+		// since this is just a sanity check.
+		t.Logf("got %d roots", len(tt.certs))
+		if want, have := 100, len(tt.certs); have < want {
 			t.Fatalf("want at least %d system roots, have %d", want, have)
 		}
 	}
diff --git a/src/crypto/x509/verify.go b/src/crypto/x509/verify.go
index 0d3de30..29345a1 100644
--- a/src/crypto/x509/verify.go
+++ b/src/crypto/x509/verify.go
@@ -153,7 +153,7 @@ type VerifyOptions struct {
 	CurrentTime   time.Time // if zero, the current time is used
 	// KeyUsage specifies which Extended Key Usage values are acceptable.
 	// An empty list means ExtKeyUsageServerAuth. Key usage is considered a
-	// constraint down the chain which mirrors Windows CryptoAPI behaviour,
+	// constraint down the chain which mirrors Windows CryptoAPI behavior,
 	// but not the spec. To accept any key usage, include ExtKeyUsageAny.
 	KeyUsages []ExtKeyUsage
 }
@@ -262,7 +262,7 @@ func (c *Certificate) isValid(certType int, currentChain []*Certificate, opts *V
 // WARNING: this doesn't do any revocation checking.
 func (c *Certificate) Verify(opts VerifyOptions) (chains [][]*Certificate, err error) {
 	// Platform-specific verification needs the ASN.1 contents so
-	// this makes the behaviour consistent across platforms.
+	// this makes the behavior consistent across platforms.
 	if len(c.Raw) == 0 {
 		return nil, errNotParsed
 	}
diff --git a/src/crypto/x509/x509.go b/src/crypto/x509/x509.go
index d9077db..949ce01 100644
--- a/src/crypto/x509/x509.go
+++ b/src/crypto/x509/x509.go
@@ -1850,13 +1850,20 @@ func (c *Certificate) CreateCRL(rand io.Reader, priv interface{}, revokedCerts [
 		return nil, err
 	}
 
+	// Force revocation times to UTC per RFC 5280.
+	revokedCertsUTC := make([]pkix.RevokedCertificate, len(revokedCerts))
+	for i, rc := range revokedCerts {
+		rc.RevocationTime = rc.RevocationTime.UTC()
+		revokedCertsUTC[i] = rc
+	}
+
 	tbsCertList := pkix.TBSCertificateList{
 		Version:             1,
 		Signature:           signatureAlgorithm,
 		Issuer:              c.Subject.ToRDNSequence(),
 		ThisUpdate:          now.UTC(),
 		NextUpdate:          expiry.UTC(),
-		RevokedCertificates: revokedCerts,
+		RevokedCertificates: revokedCertsUTC,
 	}
 
 	// Authority Key Id
diff --git a/src/crypto/x509/x509_test.go b/src/crypto/x509/x509_test.go
index 354545c..aa30d85 100644
--- a/src/crypto/x509/x509_test.go
+++ b/src/crypto/x509/x509_test.go
@@ -850,17 +850,31 @@ func TestCRLCreation(t *testing.T) {
 	block, _ = pem.Decode([]byte(pemCertificate))
 	cert, _ := ParseCertificate(block.Bytes)
 
-	now := time.Unix(1000, 0)
+	loc := time.FixedZone("Oz/Atlantis", int((2 * time.Hour).Seconds()))
+
+	now := time.Unix(1000, 0).In(loc)
+	nowUTC := now.UTC()
 	expiry := time.Unix(10000, 0)
 
 	revokedCerts := []pkix.RevokedCertificate{
 		{
 			SerialNumber:   big.NewInt(1),
+			RevocationTime: nowUTC,
+		},
+		{
+			SerialNumber: big.NewInt(42),
+			// RevocationTime should be converted to UTC before marshaling.
 			RevocationTime: now,
 		},
+	}
+	expectedCerts := []pkix.RevokedCertificate{
+		{
+			SerialNumber:   big.NewInt(1),
+			RevocationTime: nowUTC,
+		},
 		{
 			SerialNumber:   big.NewInt(42),
-			RevocationTime: now,
+			RevocationTime: nowUTC,
 		},
 	}
 
@@ -869,10 +883,14 @@ func TestCRLCreation(t *testing.T) {
 		t.Errorf("error creating CRL: %s", err)
 	}
 
-	_, err = ParseDERCRL(crlBytes)
+	parsedCRL, err := ParseDERCRL(crlBytes)
 	if err != nil {
 		t.Errorf("error reparsing CRL: %s", err)
 	}
+	if !reflect.DeepEqual(parsedCRL.TBSCertList.RevokedCertificates, expectedCerts) {
+		t.Errorf("RevokedCertificates mismatch: got %v; want %v.",
+			parsedCRL.TBSCertList.RevokedCertificates, expectedCerts)
+	}
 }
 
 func fromBase64(in string) []byte {
diff --git a/src/database/sql/convert.go b/src/database/sql/convert.go
index 4b4dfc4..ea2f377 100644
--- a/src/database/sql/convert.go
+++ b/src/database/sql/convert.go
@@ -13,6 +13,8 @@ import (
 	"reflect"
 	"strconv"
 	"time"
+	"unicode"
+	"unicode/utf8"
 )
 
 var errNilPtr = errors.New("destination pointer is nil") // embedded in descriptive error
@@ -24,6 +26,17 @@ func describeNamedValue(nv *driver.NamedValue) string {
 	return fmt.Sprintf("with name %q", nv.Name)
 }
 
+func validateNamedValueName(name string) error {
+	if len(name) == 0 {
+		return nil
+	}
+	r, _ := utf8.DecodeRuneInString(name)
+	if unicode.IsLetter(r) {
+		return nil
+	}
+	return fmt.Errorf("name %q does not begin with a letter", name)
+}
+
 // driverArgs converts arguments from callers of Stmt.Exec and
 // Stmt.Query into driver Values.
 //
@@ -43,6 +56,9 @@ func driverArgs(ds *driverStmt, args []interface{}) ([]driver.NamedValue, error)
 			nv := &nvargs[n]
 			nv.Ordinal = n + 1
 			if np, ok := arg.(NamedArg); ok {
+				if err := validateNamedValueName(np.Name); err != nil {
+					return nil, err
+				}
 				arg = np.Value
 				nvargs[n].Name = np.Name
 			}
@@ -60,6 +76,9 @@ func driverArgs(ds *driverStmt, args []interface{}) ([]driver.NamedValue, error)
 		nv := &nvargs[n]
 		nv.Ordinal = n + 1
 		if np, ok := arg.(NamedArg); ok {
+			if err := validateNamedValueName(np.Name); err != nil {
+				return nil, err
+			}
 			arg = np.Value
 			nv.Name = np.Name
 		}
diff --git a/src/database/sql/ctxutil.go b/src/database/sql/ctxutil.go
index 7c05ce2..1071446 100644
--- a/src/database/sql/ctxutil.go
+++ b/src/database/sql/ctxutil.go
@@ -111,25 +111,32 @@ func ctxDriverStmtQuery(ctx context.Context, si driver.Stmt, nvdargs []driver.Na
 
 var errLevelNotSupported = errors.New("sql: selected isolation level is not supported")
 
-func ctxDriverBegin(ctx context.Context, ci driver.Conn) (driver.Tx, error) {
-	if ciCtx, is := ci.(driver.ConnBeginContext); is {
-		return ciCtx.BeginContext(ctx)
+func ctxDriverBegin(ctx context.Context, opts *TxOptions, ci driver.Conn) (driver.Tx, error) {
+	if ciCtx, is := ci.(driver.ConnBeginTx); is {
+		dopts := driver.TxOptions{}
+		if opts != nil {
+			dopts.Isolation = driver.IsolationLevel(opts.Isolation)
+			dopts.ReadOnly = opts.ReadOnly
+		}
+		return ciCtx.BeginTx(ctx, dopts)
 	}
 
 	if ctx.Done() == context.Background().Done() {
 		return ci.Begin()
 	}
 
-	// Check the transaction level in ctx. If set and non-default
-	// then return an error here as the BeginContext driver value is not supported.
-	if level, ok := driver.IsolationFromContext(ctx); ok && level != driver.IsolationLevel(LevelDefault) {
-		return nil, errors.New("sql: driver does not support non-default isolation level")
-	}
+	if opts != nil {
+		// Check the transaction level. If the transaction level is non-default
+		// then return an error here as the BeginTx driver value is not supported.
+		if opts.Isolation != LevelDefault {
+			return nil, errors.New("sql: driver does not support non-default isolation level")
+		}
 
-	// Check for a read-only parameter in ctx. If a read-only transaction is
-	// requested return an error as the BeginContext driver value is not supported.
-	if ro := driver.ReadOnlyFromContext(ctx); ro {
-		return nil, errors.New("sql: driver does not support read-only transactions")
+		// If a read-only transaction is requested return an error as the
+		// BeginTx driver value is not supported.
+		if opts.ReadOnly {
+			return nil, errors.New("sql: driver does not support read-only transactions")
+		}
 	}
 
 	txi, err := ci.Begin()
diff --git a/src/database/sql/driver/driver.go b/src/database/sql/driver/driver.go
index c8cbbf0..d66196f 100644
--- a/src/database/sql/driver/driver.go
+++ b/src/database/sql/driver/driver.go
@@ -10,7 +10,6 @@ package driver
 
 import (
 	"context"
-	"database/sql/internal"
 	"errors"
 	"reflect"
 )
@@ -27,13 +26,18 @@ import (
 type Value interface{}
 
 // NamedValue holds both the value name and value.
-// The Ordinal is the position of the parameter starting from one and is always set.
-// If the Name is not empty it should be used for the parameter identifier and
-// not the ordinal position.
 type NamedValue struct {
-	Name    string
+	// If the Name is not empty it should be used for the parameter identifier and
+	// not the ordinal position.
+	//
+	// Name will not have a symbol prefix.
+	Name string
+
+	// Ordinal position of the parameter starting from one and is always set.
 	Ordinal int
-	Value   Value
+
+	// Value is the parameter value.
+	Value Value
 }
 
 // Driver is the interface that must be implemented by a database
@@ -152,7 +156,7 @@ type Conn interface {
 
 	// Begin starts and returns a new transaction.
 	//
-	// Deprecated: Drivers should implement ConnBeginContext instead (or additionally).
+	// Deprecated: Drivers should implement ConnBeginTx instead (or additionally).
 	Begin() (Tx, error)
 }
 
@@ -164,41 +168,35 @@ type ConnPrepareContext interface {
 	PrepareContext(ctx context.Context, query string) (Stmt, error)
 }
 
-// IsolationLevel is the transaction isolation level stored in Context.
+// IsolationLevel is the transaction isolation level stored in TxOptions.
 //
 // This type should be considered identical to sql.IsolationLevel along
 // with any values defined on it.
 type IsolationLevel int
 
-// IsolationFromContext extracts the isolation level from a Context.
-func IsolationFromContext(ctx context.Context) (level IsolationLevel, ok bool) {
-	level, ok = ctx.Value(internal.IsolationLevelKey{}).(IsolationLevel)
-	return level, ok
-}
-
-// ReadOnlyFromContext extracts the read-only property from a Context.
-// When readonly is true the transaction must be set to read-only
-// or return an error.
-func ReadOnlyFromContext(ctx context.Context) (readonly bool) {
-	readonly, _ = ctx.Value(internal.ReadOnlyKey{}).(bool)
-	return readonly
+// TxOptions holds the transaction options.
+//
+// This type should be considered identical to sql.TxOptions.
+type TxOptions struct {
+	Isolation IsolationLevel
+	ReadOnly  bool
 }
 
-// ConnBeginContext enhances the Conn interface with context.
-type ConnBeginContext interface {
-	// BeginContext starts and returns a new transaction.
+// ConnBeginTx enhances the Conn interface with context and TxOptions.
+type ConnBeginTx interface {
+	// BeginTx starts and returns a new transaction.
 	// If the context is canceled by the user the sql package will
 	// call Tx.Rollback before discarding and closing the connection.
 	//
-	// This must call IsolationFromContext to determine if there is a set
-	// isolation level. If the driver does not support setting the isolation
-	// level and one is set or if there is a set isolation level
-	// but the set level is not supported, an error must be returned.
+	// This must check opts.Isolation to determine if there is a set
+	// isolation level. If the driver does not support a non-default
+	// level and one is set or if there is a non-default isolation level
+	// that is not supported, an error must be returned.
 	//
-	// This must also call ReadOnlyFromContext to determine if the read-only
+	// This must also check opts.ReadOnly to determine if the read-only
 	// value is true to either set the read-only transaction property if supported
 	// or return an error if it is not supported.
-	BeginContext(ctx context.Context) (Tx, error)
+	BeginTx(ctx context.Context, opts TxOptions) (Tx, error)
 }
 
 // Result is the result of a query execution.
diff --git a/src/database/sql/fakedb_test.go b/src/database/sql/fakedb_test.go
index 416b97d..4b15f5b 100644
--- a/src/database/sql/fakedb_test.go
+++ b/src/database/sql/fakedb_test.go
@@ -713,7 +713,7 @@ func (s *fakeStmt) execInsert(args []driver.NamedValue, doInsert bool) (driver.R
 			} else {
 				// Assign value from argument placeholder name.
 				for _, a := range args {
-					if a.Name == strvalue {
+					if a.Name == strvalue[1:] {
 						val = a.Value
 						break
 					}
@@ -818,7 +818,7 @@ func (s *fakeStmt) QueryContext(ctx context.Context, args []driver.NamedValue) (
 				} else {
 					// Assign arg value from placeholder name.
 					for _, a := range args {
-						if a.Name == wcol.Placeholder {
+						if a.Name == wcol.Placeholder[1:] {
 							argValue = a.Value
 							break
 						}
diff --git a/src/database/sql/internal/types.go b/src/database/sql/internal/types.go
deleted file mode 100644
index 1895144..0000000
--- a/src/database/sql/internal/types.go
+++ /dev/null
@@ -1,11 +0,0 @@
-// 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 internal
-
-// Context keys that set transaction properties for sql.BeginContext.
-type (
-	IsolationLevelKey struct{} // context value is driver.IsolationLevel
-	ReadOnlyKey       struct{} // context value is bool
-)
diff --git a/src/database/sql/sql.go b/src/database/sql/sql.go
index a620707..9602450 100644
--- a/src/database/sql/sql.go
+++ b/src/database/sql/sql.go
@@ -8,14 +8,16 @@
 // The sql package must be used in conjunction with a database driver.
 // See https://golang.org/s/sqldrivers for a list of drivers.
 //
-// For more usage examples, see the wiki page at
+// Drivers that do not support context cancelation will not return until
+// after the query is completed.
+//
+// For usage examples, see the wiki page at
 // https://golang.org/s/sqlwiki.
 package sql
 
 import (
 	"context"
 	"database/sql/driver"
-	"database/sql/internal"
 	"errors"
 	"fmt"
 	"io"
@@ -69,17 +71,26 @@ func Drivers() []string {
 	return list
 }
 
-// A NamedArg used as an argument to Query or Exec
-// binds to the corresponding named parameter in the SQL statement.
+// A NamedArg is a named argument. NamedArg values may be used as
+// arguments to Query or Exec and bind to the corresponding named
+// parameter in the SQL statement.
+//
+// For a more concise way to create NamedArg values, see
+// the Named function.
 type NamedArg struct {
 	_Named_Fields_Required struct{}
 
-	// Name of the parameter placeholder. If empty the ordinal position in the
-	// argument list will be used.
+	// Name is the name of the parameter placeholder.
+	//
+	// If empty, the ordinal position in the argument list will be
+	// used.
+	//
+	// Name must omit any symbol prefix.
 	Name string
 
-	// Value of the parameter. It may be assigned the same value types as
-	// the query arguments.
+	// Value is the value of the parameter.
+	// It may be assigned the same value types as the query
+	// arguments.
 	Value interface{}
 }
 
@@ -103,12 +114,10 @@ func Named(name string, value interface{}) NamedArg {
 	return NamedArg{Name: name, Value: value}
 }
 
-// IsolationLevel is the transaction isolation level stored in Context.
-// The IsolationLevel is set with IsolationContext and the context
-// should be passed to BeginContext.
+// IsolationLevel is the transaction isolation level used in TxOptions.
 type IsolationLevel int
 
-// Various isolation levels that drivers may support in BeginContext.
+// Various isolation levels that drivers may support in BeginTx.
 // If a driver does not support a given isolation level an error may be returned.
 //
 // See https://en.wikipedia.org/wiki/Isolation_(database_systems)#Isolation_levels.
@@ -123,18 +132,12 @@ const (
 	LevelLinearizable
 )
 
-// IsolationContext returns a new Context that carries the provided isolation level.
-// The context must contain the isolation level before beginning the transaction
-// with BeginContext.
-func IsolationContext(ctx context.Context, level IsolationLevel) context.Context {
-	return context.WithValue(ctx, internal.IsolationLevelKey{}, driver.IsolationLevel(level))
-}
-
-// ReadOnlyWithContext returns a new Context that carries the provided
-// read-only transaction property. The context must contain the read-only property
-// before beginning the transaction with BeginContext.
-func ReadOnlyContext(ctx context.Context) context.Context {
-	return context.WithValue(ctx, internal.ReadOnlyKey{}, true)
+// TxOptions holds the transaction options to be used in DB.BeginTx.
+type TxOptions struct {
+	// Isolation is the transaction isolation level.
+	// If zero, the driver or database's default level is used.
+	Isolation IsolationLevel
+	ReadOnly  bool
 }
 
 // RawBytes is a byte slice that holds a reference to memory owned by
@@ -1299,28 +1302,27 @@ func (db *DB) QueryRow(query string, args ...interface{}) *Row {
 	return db.QueryRowContext(context.Background(), query, args...)
 }
 
-// BeginContext starts a transaction.
+// BeginTx starts a transaction.
 //
 // The provided context is used until the transaction is committed or rolled back.
 // If the context is canceled, the sql package will roll back
 // the transaction. Tx.Commit will return an error if the context provided to
-// BeginContext is canceled.
+// BeginTx is canceled.
 //
-// An isolation level may be set by setting the value in the context
-// before calling this. If a non-default isolation level is used
-// that the driver doesn't support an error will be returned. Different drivers
-// may have slightly different meanings for the same isolation level.
-func (db *DB) BeginContext(ctx context.Context) (*Tx, error) {
+// The provided TxOptions is optional and may be nil if defaults should be used.
+// If a non-default isolation level is used that the driver doesn't support,
+// an error will be returned.
+func (db *DB) BeginTx(ctx context.Context, opts *TxOptions) (*Tx, error) {
 	var tx *Tx
 	var err error
 	for i := 0; i < maxBadConnRetries; i++ {
-		tx, err = db.begin(ctx, cachedOrNewConn)
+		tx, err = db.begin(ctx, opts, cachedOrNewConn)
 		if err != driver.ErrBadConn {
 			break
 		}
 	}
 	if err == driver.ErrBadConn {
-		return db.begin(ctx, alwaysNewConn)
+		return db.begin(ctx, opts, alwaysNewConn)
 	}
 	return tx, err
 }
@@ -1328,17 +1330,17 @@ func (db *DB) BeginContext(ctx context.Context) (*Tx, error) {
 // Begin starts a transaction. The default isolation level is dependent on
 // the driver.
 func (db *DB) Begin() (*Tx, error) {
-	return db.BeginContext(context.Background())
+	return db.BeginTx(context.Background(), nil)
 }
 
-func (db *DB) begin(ctx context.Context, strategy connReuseStrategy) (tx *Tx, err error) {
+func (db *DB) begin(ctx context.Context, opts *TxOptions, strategy connReuseStrategy) (tx *Tx, err error) {
 	dc, err := db.conn(ctx, strategy)
 	if err != nil {
 		return nil, err
 	}
 	var txi driver.Tx
 	withLock(dc, func() {
-		txi, err = ctxDriverBegin(ctx, dc.ci)
+		txi, err = ctxDriverBegin(ctx, opts, dc.ci)
 	})
 	if err != nil {
 		db.putConn(dc, err)
@@ -1447,14 +1449,14 @@ func (tx *Tx) closePrepared() {
 
 // Commit commits the transaction.
 func (tx *Tx) Commit() error {
+	if tx.isDone() {
+		return ErrTxDone
+	}
 	select {
 	default:
 	case <-tx.ctx.Done():
 		return tx.ctx.Err()
 	}
-	if tx.isDone() {
-		return ErrTxDone
-	}
 	var err error
 	withLock(tx.dc, func() {
 		err = tx.txi.Commit()
diff --git a/src/database/sql/sql_test.go b/src/database/sql/sql_test.go
index 27fb765..422d219 100644
--- a/src/database/sql/sql_test.go
+++ b/src/database/sql/sql_test.go
@@ -375,7 +375,7 @@ func TestTxContextWait(t *testing.T) {
 
 	ctx, _ := context.WithTimeout(context.Background(), time.Millisecond*15)
 
-	tx, err := db.BeginContext(ctx)
+	tx, err := db.BeginTx(ctx, nil)
 	if err != nil {
 		t.Fatal(err)
 	}
@@ -486,8 +486,8 @@ func TestQueryNamedArg(t *testing.T) {
 	rows, err := db.Query(
 		// Ensure the name and age parameters only match on placeholder name, not position.
 		"SELECT|people|age,name|name=?name,age=?age",
-		Named("?age", 2),
-		Named("?name", "Bob"),
+		Named("age", 2),
+		Named("name", "Bob"),
 	)
 	if err != nil {
 		t.Fatalf("Query: %v", err)
@@ -683,6 +683,37 @@ func TestQueryRow(t *testing.T) {
 	}
 }
 
+func TestTxRollbackCommitErr(t *testing.T) {
+	db := newTestDB(t, "people")
+	defer closeDB(t, db)
+
+	tx, err := db.Begin()
+	if err != nil {
+		t.Fatal(err)
+	}
+	err = tx.Rollback()
+	if err != nil {
+		t.Errorf("expected nil error from Rollback; got %v", err)
+	}
+	err = tx.Commit()
+	if err != ErrTxDone {
+		t.Errorf("expected %q from Commit; got %q", ErrTxDone, err)
+	}
+
+	tx, err = db.Begin()
+	if err != nil {
+		t.Fatal(err)
+	}
+	err = tx.Commit()
+	if err != nil {
+		t.Errorf("expected nil error from Commit; got %v", err)
+	}
+	err = tx.Rollback()
+	if err != ErrTxDone {
+		t.Errorf("expected %q from Rollback; got %q", ErrTxDone, err)
+	}
+}
+
 func TestStatementErrorAfterClose(t *testing.T) {
 	db := newTestDB(t, "people")
 	defer closeDB(t, db)
diff --git a/src/debug/gosym/pclntab.go b/src/debug/gosym/pclntab.go
index e94ed19..ba1cf8b 100644
--- a/src/debug/gosym/pclntab.go
+++ b/src/debug/gosym/pclntab.go
@@ -291,13 +291,6 @@ func (t *LineTable) step(p *[]byte, pc *uint64, val *int32, first bool) bool {
 	return true
 }
 
-// PCValue looks up the given PC in a pc value table. target is the
-// offset of the pc from the entry point.
-func PCValue(tab []byte, target uint64, quantum int) int {
-	t := LineTable{Data: tab, quantum: uint32(quantum)}
-	return int(t.pcvalue(0, 0, target))
-}
-
 // pcvalue reports the value associated with the target pc.
 // off is the offset to the beginning of the pc-value table,
 // and entry is the start PC for the corresponding function.
diff --git a/src/encoding/asn1/marshal.go b/src/encoding/asn1/marshal.go
index 76d0b0c..225fd08 100644
--- a/src/encoding/asn1/marshal.go
+++ b/src/encoding/asn1/marshal.go
@@ -535,7 +535,7 @@ func makeField(v reflect.Value, params fieldParameters) (e encoder, err error) {
 
 	// If no default value is given then the zero value for the type is
 	// assumed to be the default value. This isn't obviously the correct
-	// behaviour, but it's what Go has traditionally done.
+	// behavior, but it's what Go has traditionally done.
 	if params.optional && params.defaultValue == nil {
 		if reflect.DeepEqual(v.Interface(), reflect.Zero(v.Type()).Interface()) {
 			return bytesEncoder(nil), nil
diff --git a/src/fmt/fmt_test.go b/src/fmt/fmt_test.go
index 6f8c155..b7089be 100644
--- a/src/fmt/fmt_test.go
+++ b/src/fmt/fmt_test.go
@@ -1561,18 +1561,23 @@ func TestWidthAndPrecision(t *testing.T) {
 	}
 }
 
-// Panic is a type that panics in String.
-type Panic struct {
+// PanicS is a type that panics in String.
+type PanicS struct {
 	message interface{}
 }
 
 // Value receiver.
-func (p Panic) GoString() string {
+func (p PanicS) String() string {
 	panic(p.message)
 }
 
+// PanicGo is a type that panics in GoString.
+type PanicGo struct {
+	message interface{}
+}
+
 // Value receiver.
-func (p Panic) String() string {
+func (p PanicGo) GoString() string {
 	panic(p.message)
 }
 
@@ -1592,13 +1597,15 @@ var panictests = []struct {
 	out string
 }{
 	// String
-	{"%s", (*Panic)(nil), "<nil>"}, // nil pointer special case
-	{"%s", Panic{io.ErrUnexpectedEOF}, "%!s(PANIC=unexpected EOF)"},
-	{"%s", Panic{3}, "%!s(PANIC=3)"},
+	{"%s", (*PanicS)(nil), "<nil>"}, // nil pointer special case
+	{"%s", PanicS{io.ErrUnexpectedEOF}, "%!s(PANIC=unexpected EOF)"},
+	{"%s", PanicS{3}, "%!s(PANIC=3)"},
 	// GoString
-	{"%#v", (*Panic)(nil), "<nil>"}, // nil pointer special case
-	{"%#v", Panic{io.ErrUnexpectedEOF}, "%!v(PANIC=unexpected EOF)"},
-	{"%#v", Panic{3}, "%!v(PANIC=3)"},
+	{"%#v", (*PanicGo)(nil), "<nil>"}, // nil pointer special case
+	{"%#v", PanicGo{io.ErrUnexpectedEOF}, "%!v(PANIC=unexpected EOF)"},
+	{"%#v", PanicGo{3}, "%!v(PANIC=3)"},
+	// Issue 18282. catchPanic should not clear fmtFlags permanently.
+	{"%#v", []interface{}{PanicGo{3}, PanicGo{3}}, "[]interface {}{%!v(PANIC=3), %!v(PANIC=3)}"},
 	// Format
 	{"%s", (*PanicF)(nil), "<nil>"}, // nil pointer special case
 	{"%s", PanicF{io.ErrUnexpectedEOF}, "%!s(PANIC=unexpected EOF)"},
diff --git a/src/fmt/print.go b/src/fmt/print.go
index 75301a2..a7ef2e5 100644
--- a/src/fmt/print.go
+++ b/src/fmt/print.go
@@ -535,7 +535,11 @@ func (p *pp) catchPanic(arg interface{}, verb rune) {
 			// Nested panics; the recursion in printArg cannot succeed.
 			panic(err)
 		}
-		p.fmt.clearflags() // We are done, and for this output we want default behavior.
+
+		oldFlags := p.fmt.fmtFlags
+		// For this output we want default behavior.
+		p.fmt.clearflags()
+
 		p.buf.WriteString(percentBangString)
 		p.buf.WriteRune(verb)
 		p.buf.WriteString(panicString)
@@ -543,6 +547,8 @@ func (p *pp) catchPanic(arg interface{}, verb rune) {
 		p.printArg(err, 'v')
 		p.panicking = false
 		p.buf.WriteByte(')')
+
+		p.fmt.fmtFlags = oldFlags
 	}
 }
 
@@ -813,16 +819,15 @@ func (p *pp) printValue(value reflect.Value, verb rune, depth int) {
 			if f.Kind() == reflect.Slice && f.IsNil() {
 				p.buf.WriteString(nilParenString)
 				return
-			} else {
-				p.buf.WriteByte('{')
-				for i := 0; i < f.Len(); i++ {
-					if i > 0 {
-						p.buf.WriteString(commaSpaceString)
-					}
-					p.printValue(f.Index(i), verb, depth+1)
+			}
+			p.buf.WriteByte('{')
+			for i := 0; i < f.Len(); i++ {
+				if i > 0 {
+					p.buf.WriteString(commaSpaceString)
 				}
-				p.buf.WriteByte('}')
+				p.printValue(f.Index(i), verb, depth+1)
 			}
+			p.buf.WriteByte('}')
 		} else {
 			p.buf.WriteByte('[')
 			for i := 0; i < f.Len(); i++ {
diff --git a/src/go/build/build.go b/src/go/build/build.go
index f6aabcb..ea37bbb 100644
--- a/src/go/build/build.go
+++ b/src/go/build/build.go
@@ -76,8 +76,9 @@ type Context struct {
 	// If IsDir is nil, Import calls os.Stat and uses the result's IsDir method.
 	IsDir func(path string) bool
 
-	// HasSubdir reports whether dir is a subdirectory of
-	// (perhaps multiple levels below) root.
+	// HasSubdir reports whether dir is lexically a subdirectory of
+	// root, perhaps multiple levels below. It does not try to check
+	// whether dir exists.
 	// If so, HasSubdir sets rel to a slash-separated path that
 	// can be joined to root to produce a path equivalent to dir.
 	// If HasSubdir is nil, Import uses an implementation built on
diff --git a/src/go/build/deps_test.go b/src/go/build/deps_test.go
index e6f2288..147eaf6 100644
--- a/src/go/build/deps_test.go
+++ b/src/go/build/deps_test.go
@@ -179,7 +179,7 @@ var pkgDeps = map[string][]string{
 	"runtime/trace":                     {"L0"},
 	"text/tabwriter":                    {"L2"},
 
-	"testing":          {"L2", "context", "flag", "fmt", "internal/race", "os", "runtime/debug", "runtime/pprof", "runtime/trace", "time"},
+	"testing":          {"L2", "flag", "fmt", "internal/race", "os", "runtime/debug", "runtime/pprof", "runtime/trace", "time"},
 	"testing/iotest":   {"L2", "log"},
 	"testing/quick":    {"L2", "flag", "fmt", "reflect"},
 	"internal/testenv": {"L2", "OS", "flag", "testing", "syscall"},
diff --git a/src/go/internal/gccgoimporter/importer_test.go b/src/go/internal/gccgoimporter/importer_test.go
index 58abbba..2b45470 100644
--- a/src/go/internal/gccgoimporter/importer_test.go
+++ b/src/go/internal/gccgoimporter/importer_test.go
@@ -96,8 +96,11 @@ var importerTests = [...]importerTest{
 	{pkgpath: "complexnums", name: "PN", want: "const PN untyped complex", wantval: "(1 + -1i)"},
 	{pkgpath: "complexnums", name: "PP", want: "const PP untyped complex", wantval: "(1 + 1i)"},
 	{pkgpath: "conversions", name: "Bits", want: "const Bits Units", wantval: `"bits"`},
-	// TODO: enable this entry once bug has been tracked down
-	//{pkgpath: "imports", wantinits: []string{"imports..import", "fmt..import", "math..import"}},
+	{pkgpath: "time", name: "Duration", want: "type Duration int64"},
+	{pkgpath: "time", name: "Nanosecond", want: "const Nanosecond Duration", wantval: "1"},
+	{pkgpath: "unicode", name: "IsUpper", want: "func IsUpper(r rune) bool"},
+	{pkgpath: "unicode", name: "MaxRune", want: "const MaxRune untyped rune", wantval: "1114111"},
+	{pkgpath: "imports", wantinits: []string{"imports..import", "fmt..import", "math..import"}},
 }
 
 func TestGoxImporter(t *testing.T) {
diff --git a/src/go/internal/gccgoimporter/parser.go b/src/go/internal/gccgoimporter/parser.go
index 7312cb4..3b97c96 100644
--- a/src/go/internal/gccgoimporter/parser.go
+++ b/src/go/internal/gccgoimporter/parser.go
@@ -711,7 +711,10 @@ func (p *parser) parseType(pkg *types.Package) (t types.Type) {
 func (p *parser) parsePackageInit() PackageInit {
 	name := p.parseUnquotedString()
 	initfunc := p.parseUnquotedString()
-	priority := int(p.parseInt())
+	priority := -1
+	if p.version == "v1" {
+		priority = int(p.parseInt())
+	}
 	return PackageInit{Name: name, InitFunc: initfunc, Priority: priority}
 }
 
@@ -766,6 +769,15 @@ func (p *parser) parseInitDataDirective() {
 		}
 		p.expect(';')
 
+	case "init_graph":
+		p.next()
+		// The graph data is thrown away for now.
+		for p.tok != ';' && p.tok != scanner.EOF {
+			p.parseInt()
+			p.parseInt()
+		}
+		p.expect(';')
+
 	case "checksum":
 		// Don't let the scanner try to parse the checksum as a number.
 		defer func(mode uint) {
@@ -797,7 +809,7 @@ func (p *parser) parseDirective() {
 	}
 
 	switch p.lit {
-	case "v1", "v2", "priority", "init", "checksum":
+	case "v1", "v2", "priority", "init", "init_graph", "checksum":
 		p.parseInitDataDirective()
 
 	case "package":
diff --git a/src/go/internal/gccgoimporter/testdata/time.gox b/src/go/internal/gccgoimporter/testdata/time.gox
new file mode 100644
index 0000000..80c2dbc
Binary files /dev/null and b/src/go/internal/gccgoimporter/testdata/time.gox differ
diff --git a/src/go/internal/gccgoimporter/testdata/unicode.gox b/src/go/internal/gccgoimporter/testdata/unicode.gox
new file mode 100644
index 0000000..e70e539
Binary files /dev/null and b/src/go/internal/gccgoimporter/testdata/unicode.gox differ
diff --git a/src/html/template/js.go b/src/html/template/js.go
index 8f1185c..6434fa3 100644
--- a/src/html/template/js.go
+++ b/src/html/template/js.go
@@ -368,9 +368,10 @@ func isJSIdentPart(r rune) bool {
 // It is used to determine whether a script tag with a type attribute is a javascript container.
 func isJSType(mimeType string) bool {
 	// per
-	//   http://www.w3.org/TR/html5/scripting-1.html#attr-script-type
+	//   https://www.w3.org/TR/html5/scripting-1.html#attr-script-type
 	//   https://tools.ietf.org/html/rfc7231#section-3.1.1
-	//   http://tools.ietf.org/html/rfc4329#section-3
+	//   https://tools.ietf.org/html/rfc4329#section-3
+	//   https://www.ietf.org/rfc/rfc4627.txt
 
 	// discard parameters
 	if i := strings.Index(mimeType, ";"); i >= 0 {
@@ -381,6 +382,7 @@ func isJSType(mimeType string) bool {
 	case
 		"application/ecmascript",
 		"application/javascript",
+		"application/json",
 		"application/x-ecmascript",
 		"application/x-javascript",
 		"text/ecmascript",
diff --git a/src/html/template/js_test.go b/src/html/template/js_test.go
index 58fc37a..7484f60 100644
--- a/src/html/template/js_test.go
+++ b/src/html/template/js_test.go
@@ -341,6 +341,7 @@ func TestIsJsMimeType(t *testing.T) {
 		{"application/javascript;version=1.8;foo=bar", true},
 		{"application/javascript/version=1.8", false},
 		{"text/javascript", true},
+		{"application/json", true},
 	}
 
 	for _, test := range tests {
diff --git a/src/io/io.go b/src/io/io.go
index 3cab728..9e4b865 100644
--- a/src/io/io.go
+++ b/src/io/io.go
@@ -420,6 +420,7 @@ func LimitReader(r Reader, n int64) Reader { return &LimitedReader{r, n} }
 // A LimitedReader reads from R but limits the amount of
 // data returned to just N bytes. Each call to Read
 // updates N to reflect the new amount remaining.
+// Read returns EOF when N <= 0 or when the underlying R returns EOF.
 type LimitedReader struct {
 	R Reader // underlying reader
 	N int64  // max bytes remaining
diff --git a/src/io/multi.go b/src/io/multi.go
index 46e45a6..d784846 100644
--- a/src/io/multi.go
+++ b/src/io/multi.go
@@ -4,13 +4,19 @@
 
 package io
 
+type eofReader struct{}
+
+func (eofReader) Read([]byte) (int, error) {
+	return 0, EOF
+}
+
 type multiReader struct {
 	readers []Reader
 }
 
 func (mr *multiReader) Read(p []byte) (n int, err error) {
 	for len(mr.readers) > 0 {
-		// Optimization to flatten nested multiReaders (Issue 13558)
+		// Optimization to flatten nested multiReaders (Issue 13558).
 		if len(mr.readers) == 1 {
 			if r, ok := mr.readers[0].(*multiReader); ok {
 				mr.readers = r.readers
@@ -19,7 +25,9 @@ func (mr *multiReader) Read(p []byte) (n int, err error) {
 		}
 		n, err = mr.readers[0].Read(p)
 		if err == EOF {
-			mr.readers[0] = nil // permit earlier GC
+			// Use eofReader instead of nil to avoid nil panic
+			// after performing flatten (Issue 18232).
+			mr.readers[0] = eofReader{} // permit earlier GC
 			mr.readers = mr.readers[1:]
 		}
 		if n > 0 || err != EOF {
diff --git a/src/io/multi_test.go b/src/io/multi_test.go
index 16e351a..1a6292f 100644
--- a/src/io/multi_test.go
+++ b/src/io/multi_test.go
@@ -264,3 +264,27 @@ func TestMultiReaderFreesExhaustedReaders(t *testing.T) {
 		t.Fatalf(`ReadFull = %d (%q), %v; want 2, "ar", nil`, n, buf[:n], err)
 	}
 }
+
+func TestInterleavedMultiReader(t *testing.T) {
+	r1 := strings.NewReader("123")
+	r2 := strings.NewReader("45678")
+
+	mr1 := MultiReader(r1, r2)
+	mr2 := MultiReader(mr1)
+
+	buf := make([]byte, 4)
+
+	// Have mr2 use mr1's []Readers.
+	// Consume r1 (and clear it for GC to handle) and consume part of r2.
+	n, err := ReadFull(mr2, buf)
+	if got := string(buf[:n]); got != "1234" || err != nil {
+		t.Errorf(`ReadFull(mr2) = (%q, %v), want ("1234", nil)`, got, err)
+	}
+
+	// Consume the rest of r2 via mr1.
+	// This should not panic even though mr2 cleared r1.
+	n, err = ReadFull(mr1, buf)
+	if got := string(buf[:n]); got != "5678" || err != nil {
+		t.Errorf(`ReadFull(mr1) = (%q, %v), want ("5678", nil)`, got, err)
+	}
+}
diff --git a/src/math/big/int.go b/src/math/big/int.go
index a2c1b58..1d8dabc 100644
--- a/src/math/big/int.go
+++ b/src/math/big/int.go
@@ -404,8 +404,11 @@ func (x *Int) BitLen() int {
 
 // Exp sets z = x**y mod |m| (i.e. the sign of m is ignored), and returns z.
 // If y <= 0, the result is 1 mod |m|; if m == nil or m == 0, z = x**y.
-// See Knuth, volume 2, section 4.6.3.
+//
+// Modular exponentation of inputs of a particular size is not a
+// cryptographically constant-time operation.
 func (z *Int) Exp(x, y, m *Int) *Int {
+	// See Knuth, volume 2, section 4.6.3.
 	var yWords nat
 	if !y.neg {
 		yWords = y.abs
diff --git a/src/net/dial.go b/src/net/dial.go
index 5db3585..b73426f 100644
--- a/src/net/dial.go
+++ b/src/net/dial.go
@@ -265,6 +265,9 @@ func (r *Resolver) resolveAddrList(ctx context.Context, op, network, addr string
 //	Dial("ip6:ipv6-icmp", "2001:db8::1")
 //
 // For Unix networks, the address must be a file system path.
+//
+// If the host is resolved to multiple addresses,
+// Dial will try each address in order until one succeeds.
 func Dial(network, address string) (Conn, error) {
 	var d Dialer
 	return d.Dial(network, address)
@@ -299,6 +302,14 @@ func (d *Dialer) Dial(network, address string) (Conn, error) {
 // connected, any expiration of the context will not affect the
 // connection.
 //
+// When using TCP, and the host in the address parameter resolves to multiple
+// network addresses, any dial timeout (from d.Timeout or ctx) is spread
+// over each consecutive dial, such that each is given an appropriate
+// fraction of the time to connect.
+// For example, if a host has 4 IP addresses and the timeout is 1 minute,
+// the connect to each single address will be given 15 seconds to complete
+// before trying the next one.
+//
 // See func Dial for a description of the network and address
 // parameters.
 func (d *Dialer) DialContext(ctx context.Context, network, address string) (Conn, error) {
diff --git a/src/net/http/client.go b/src/net/http/client.go
index fe2b019..9308c5c 100644
--- a/src/net/http/client.go
+++ b/src/net/http/client.go
@@ -163,22 +163,23 @@ func refererForURL(lastReq, newReq *url.URL) string {
 	return referer
 }
 
-func (c *Client) send(req *Request, deadline time.Time) (*Response, error) {
+// didTimeout is non-nil only if err != nil.
+func (c *Client) send(req *Request, deadline time.Time) (resp *Response, didTimeout func() bool, err error) {
 	if c.Jar != nil {
 		for _, cookie := range c.Jar.Cookies(req.URL) {
 			req.AddCookie(cookie)
 		}
 	}
-	resp, err := send(req, c.transport(), deadline)
+	resp, didTimeout, err = send(req, c.transport(), deadline)
 	if err != nil {
-		return nil, err
+		return nil, didTimeout, err
 	}
 	if c.Jar != nil {
 		if rc := resp.Cookies(); len(rc) > 0 {
 			c.Jar.SetCookies(req.URL, rc)
 		}
 	}
-	return resp, nil
+	return resp, nil, nil
 }
 
 func (c *Client) deadline() time.Time {
@@ -197,22 +198,22 @@ func (c *Client) transport() RoundTripper {
 
 // send issues an HTTP request.
 // Caller should close resp.Body when done reading from it.
-func send(ireq *Request, rt RoundTripper, deadline time.Time) (*Response, error) {
+func send(ireq *Request, rt RoundTripper, deadline time.Time) (resp *Response, didTimeout func() bool, err error) {
 	req := ireq // req is either the original request, or a modified fork
 
 	if rt == nil {
 		req.closeBody()
-		return nil, errors.New("http: no Client.Transport or DefaultTransport")
+		return nil, alwaysFalse, errors.New("http: no Client.Transport or DefaultTransport")
 	}
 
 	if req.URL == nil {
 		req.closeBody()
-		return nil, errors.New("http: nil Request.URL")
+		return nil, alwaysFalse, errors.New("http: nil Request.URL")
 	}
 
 	if req.RequestURI != "" {
 		req.closeBody()
-		return nil, errors.New("http: Request.RequestURI can't be set in client requests.")
+		return nil, alwaysFalse, errors.New("http: Request.RequestURI can't be set in client requests.")
 	}
 
 	// forkReq forks req into a shallow clone of ireq the first
@@ -245,7 +246,7 @@ func send(ireq *Request, rt RoundTripper, deadline time.Time) (*Response, error)
 	}
 	stopTimer, didTimeout := setRequestCancel(req, rt, deadline)
 
-	resp, err := rt.RoundTrip(req)
+	resp, err = rt.RoundTrip(req)
 	if err != nil {
 		stopTimer()
 		if resp != nil {
@@ -259,7 +260,7 @@ func send(ireq *Request, rt RoundTripper, deadline time.Time) (*Response, error)
 				err = errors.New("http: server gave HTTP response to HTTPS client")
 			}
 		}
-		return nil, err
+		return nil, didTimeout, err
 	}
 	if !deadline.IsZero() {
 		resp.Body = &cancelTimerBody{
@@ -268,12 +269,17 @@ func send(ireq *Request, rt RoundTripper, deadline time.Time) (*Response, error)
 			reqDidTimeout: didTimeout,
 		}
 	}
-	return resp, nil
+	return resp, nil, nil
 }
 
 // setRequestCancel sets the Cancel field of req, if deadline is
 // non-zero. The RoundTripper's type is used to determine whether the legacy
 // CancelRequest behavior should be used.
+//
+// As background, there are three ways to cancel a request:
+// First was Transport.CancelRequest. (deprecated)
+// Second was Request.Cancel (this mechanism).
+// Third was Request.Context.
 func setRequestCancel(req *Request, rt RoundTripper, deadline time.Time) (stopTimer func(), didTimeout func() bool) {
 	if deadline.IsZero() {
 		return nop, alwaysFalse
@@ -285,7 +291,7 @@ func setRequestCancel(req *Request, rt RoundTripper, deadline time.Time) (stopTi
 	req.Cancel = cancel
 
 	doCancel := func() {
-		// The new way:
+		// The newer way (the second way in the func comment):
 		close(cancel)
 
 		// The legacy compatibility way, used only
@@ -565,8 +571,9 @@ func (c *Client) Do(req *Request) (*Response, error) {
 
 		reqs = append(reqs, req)
 		var err error
-		if resp, err = c.send(req, deadline); err != nil {
-			if !deadline.IsZero() && !time.Now().Before(deadline) {
+		var didTimeout func() bool
+		if resp, didTimeout, err = c.send(req, deadline); err != nil {
+			if !deadline.IsZero() && didTimeout() {
 				err = &httpError{
 					err:     err.Error() + " (Client.Timeout exceeded while awaiting headers)",
 					timeout: true,
diff --git a/src/net/http/client_test.go b/src/net/http/client_test.go
index a5f58cb..ca6e918 100644
--- a/src/net/http/client_test.go
+++ b/src/net/http/client_test.go
@@ -26,6 +26,7 @@ import (
 	"strconv"
 	"strings"
 	"sync"
+	"sync/atomic"
 	"testing"
 	"time"
 )
@@ -1738,3 +1739,76 @@ func TestClientRedirectTypes(t *testing.T) {
 		res.Body.Close()
 	}
 }
+
+// issue18239Body is an io.ReadCloser for TestTransportBodyReadError.
+// Its Read returns readErr and increments *readCalls atomically.
+// Its Close returns nil and increments *closeCalls atomically.
+type issue18239Body struct {
+	readCalls  *int32
+	closeCalls *int32
+	readErr    error
+}
+
+func (b issue18239Body) Read([]byte) (int, error) {
+	atomic.AddInt32(b.readCalls, 1)
+	return 0, b.readErr
+}
+
+func (b issue18239Body) Close() error {
+	atomic.AddInt32(b.closeCalls, 1)
+	return nil
+}
+
+// Issue 18239: make sure the Transport doesn't retry requests with bodies.
+// (Especially if Request.GetBody is not defined.)
+func TestTransportBodyReadError(t *testing.T) {
+	setParallel(t)
+	defer afterTest(t)
+	ts := httptest.NewServer(HandlerFunc(func(w ResponseWriter, r *Request) {
+		if r.URL.Path == "/ping" {
+			return
+		}
+		buf := make([]byte, 1)
+		n, err := r.Body.Read(buf)
+		w.Header().Set("X-Body-Read", fmt.Sprintf("%v, %v", n, err))
+	}))
+	defer ts.Close()
+	tr := &Transport{}
+	defer tr.CloseIdleConnections()
+	c := &Client{Transport: tr}
+
+	// Do one initial successful request to create an idle TCP connection
+	// for the subsequent request to reuse. (The Transport only retries
+	// requests on reused connections.)
+	res, err := c.Get(ts.URL + "/ping")
+	if err != nil {
+		t.Fatal(err)
+	}
+	res.Body.Close()
+
+	var readCallsAtomic int32
+	var closeCallsAtomic int32 // atomic
+	someErr := errors.New("some body read error")
+	body := issue18239Body{&readCallsAtomic, &closeCallsAtomic, someErr}
+
+	req, err := NewRequest("POST", ts.URL, body)
+	if err != nil {
+		t.Fatal(err)
+	}
+	_, err = tr.RoundTrip(req)
+	if err != someErr {
+		t.Errorf("Got error: %v; want Request.Body read error: %v", err, someErr)
+	}
+
+	// And verify that our Body wasn't used multiple times, which
+	// would indicate retries. (as it buggily was during part of
+	// Go 1.8's dev cycle)
+	readCalls := atomic.LoadInt32(&readCallsAtomic)
+	closeCalls := atomic.LoadInt32(&closeCallsAtomic)
+	if readCalls != 1 {
+		t.Errorf("read calls = %d; want 1", readCalls)
+	}
+	if closeCalls != 1 {
+		t.Errorf("close calls = %d; want 1", closeCalls)
+	}
+}
diff --git a/src/net/http/h2_bundle.go b/src/net/http/h2_bundle.go
index bb7f05d..2e0b3c9 100644
--- a/src/net/http/h2_bundle.go
+++ b/src/net/http/h2_bundle.go
@@ -855,10 +855,12 @@ type http2Framer struct {
 	// If the limit is hit, MetaHeadersFrame.Truncated is set true.
 	MaxHeaderListSize uint32
 
-	logReads bool
+	logReads, logWrites bool
 
-	debugFramer    *http2Framer // only use for logging written writes
-	debugFramerBuf *bytes.Buffer
+	debugFramer       *http2Framer // only use for logging written writes
+	debugFramerBuf    *bytes.Buffer
+	debugReadLoggerf  func(string, ...interface{})
+	debugWriteLoggerf func(string, ...interface{})
 }
 
 func (fr *http2Framer) maxHeaderListSize() uint32 {
@@ -892,7 +894,7 @@ func (f *http2Framer) endWrite() error {
 		byte(length>>16),
 		byte(length>>8),
 		byte(length))
-	if http2logFrameWrites {
+	if f.logWrites {
 		f.logWrite()
 	}
 
@@ -914,10 +916,10 @@ func (f *http2Framer) logWrite() {
 	f.debugFramerBuf.Write(f.wbuf)
 	fr, err := f.debugFramer.ReadFrame()
 	if err != nil {
-		log.Printf("http2: Framer %p: failed to decode just-written frame", f)
+		f.debugWriteLoggerf("http2: Framer %p: failed to decode just-written frame", f)
 		return
 	}
-	log.Printf("http2: Framer %p: wrote %v", f, http2summarizeFrame(fr))
+	f.debugWriteLoggerf("http2: Framer %p: wrote %v", f, http2summarizeFrame(fr))
 }
 
 func (f *http2Framer) writeByte(v byte) { f.wbuf = append(f.wbuf, v) }
@@ -938,9 +940,12 @@ const (
 // NewFramer returns a Framer that writes frames to w and reads them from r.
 func http2NewFramer(w io.Writer, r io.Reader) *http2Framer {
 	fr := &http2Framer{
-		w:        w,
-		r:        r,
-		logReads: http2logFrameReads,
+		w:                 w,
+		r:                 r,
+		logReads:          http2logFrameReads,
+		logWrites:         http2logFrameWrites,
+		debugReadLoggerf:  log.Printf,
+		debugWriteLoggerf: log.Printf,
 	}
 	fr.getReadBuf = func(size uint32) []byte {
 		if cap(fr.readBuf) >= int(size) {
@@ -1022,7 +1027,7 @@ func (fr *http2Framer) ReadFrame() (http2Frame, error) {
 		return nil, err
 	}
 	if fr.logReads {
-		log.Printf("http2: Framer %p: read %v", fr, http2summarizeFrame(f))
+		fr.debugReadLoggerf("http2: Framer %p: read %v", fr, http2summarizeFrame(f))
 	}
 	if fh.Type == http2FrameHeaders && fr.ReadMetaHeaders != nil {
 		return fr.readMetaFrame(f.(*http2HeadersFrame))
@@ -1922,8 +1927,8 @@ func (fr *http2Framer) readMetaFrame(hf *http2HeadersFrame) (*http2MetaHeadersFr
 	hdec.SetEmitEnabled(true)
 	hdec.SetMaxStringLength(fr.maxHeaderStringLen())
 	hdec.SetEmitFunc(func(hf hpack.HeaderField) {
-		if http2VerboseLogs && http2logFrameReads {
-			log.Printf("http2: decoded hpack field %+v", hf)
+		if http2VerboseLogs && fr.logReads {
+			fr.debugReadLoggerf("http2: decoded hpack field %+v", hf)
 		}
 		if !httplex.ValidHeaderFieldValue(hf.Value) {
 			invalid = http2headerFieldValueError(hf.Value)
@@ -2188,6 +2193,14 @@ func http2shouldLogPanic(panicValue interface{}) bool {
 	return panicValue != nil && panicValue != ErrAbortHandler
 }
 
+func http2reqGetBody(req *Request) func() (io.ReadCloser, error) {
+	return req.GetBody
+}
+
+func http2reqBodyIsNoBody(body io.ReadCloser) bool {
+	return body == NoBody
+}
+
 var http2DebugGoroutines = os.Getenv("DEBUG_HTTP2_GOROUTINES") == "1"
 
 type http2goroutineLock uint64
@@ -3247,6 +3260,11 @@ func (sc *http2serverConn) maxHeaderListSize() uint32 {
 	return uint32(n + typicalHeaders*perFieldOverhead)
 }
 
+func (sc *http2serverConn) curOpenStreams() uint32 {
+	sc.serveG.check()
+	return sc.curClientStreams + sc.curPushedStreams
+}
+
 // stream represents a stream. This is the minimal metadata needed by
 // the serve goroutine. Most of the actual stream state is owned by
 // the http.Handler's goroutine in the responseWriter. Because the
@@ -3272,8 +3290,7 @@ type http2stream struct {
 	numTrailerValues int64
 	weight           uint8
 	state            http2streamState
-	sentReset        bool   // only true once detached from streams map
-	gotReset         bool   // only true once detacted from streams map
+	resetQueued      bool   // RST_STREAM queued for write; set by sc.resetStream
 	gotTrailerHeader bool   // HEADER frame for trailers was seen
 	wroteHeaders     bool   // whether we wrote headers (not status 100)
 	reqBuf           []byte // if non-nil, body pipe buffer to return later at EOF
@@ -3560,7 +3577,7 @@ func (sc *http2serverConn) serve() {
 			fn(loopNum)
 		}
 
-		if sc.inGoAway && sc.curClientStreams == 0 && !sc.needToSendGoAway && !sc.writingFrame {
+		if sc.inGoAway && sc.curOpenStreams() == 0 && !sc.needToSendGoAway && !sc.writingFrame {
 			return
 		}
 	}
@@ -3669,13 +3686,25 @@ func (sc *http2serverConn) writeFrameFromHandler(wr http2FrameWriteRequest) erro
 func (sc *http2serverConn) writeFrame(wr http2FrameWriteRequest) {
 	sc.serveG.check()
 
+	// If true, wr will not be written and wr.done will not be signaled.
 	var ignoreWrite bool
 
+	if wr.StreamID() != 0 {
+		_, isReset := wr.write.(http2StreamError)
+		if state, _ := sc.state(wr.StreamID()); state == http2stateClosed && !isReset {
+			ignoreWrite = true
+		}
+	}
+
 	switch wr.write.(type) {
 	case *http2writeResHeaders:
 		wr.stream.wroteHeaders = true
 	case http2write100ContinueHeadersFrame:
 		if wr.stream.wroteHeaders {
+
+			if wr.done != nil {
+				panic("wr.done != nil for write100ContinueHeadersFrame")
+			}
 			ignoreWrite = true
 		}
 	}
@@ -3699,14 +3728,14 @@ func (sc *http2serverConn) startFrameWrite(wr http2FrameWriteRequest) {
 	if st != nil {
 		switch st.state {
 		case http2stateHalfClosedLocal:
-			panic("internal error: attempt to send frame on half-closed-local stream")
-		case http2stateClosed:
-			if st.sentReset || st.gotReset {
+			switch wr.write.(type) {
+			case http2StreamError, http2handlerPanicRST, http2writeWindowUpdate:
 
-				sc.scheduleFrameWrite()
-				return
+			default:
+				panic(fmt.Sprintf("internal error: attempt to send frame on a half-closed-local stream: %v", wr))
 			}
-			panic(fmt.Sprintf("internal error: attempt to send a write %v on a closed stream", wr))
+		case http2stateClosed:
+			panic(fmt.Sprintf("internal error: attempt to send frame on a closed stream: %v", wr))
 		}
 	}
 	if wpp, ok := wr.write.(*http2writePushPromise); ok {
@@ -3714,9 +3743,7 @@ func (sc *http2serverConn) startFrameWrite(wr http2FrameWriteRequest) {
 		wpp.promisedID, err = wpp.allocatePromisedID()
 		if err != nil {
 			sc.writingFrameAsync = false
-			if wr.done != nil {
-				wr.done <- err
-			}
+			wr.replyToWriter(err)
 			return
 		}
 	}
@@ -3749,24 +3776,9 @@ func (sc *http2serverConn) wroteFrame(res http2frameWriteResult) {
 	sc.writingFrameAsync = false
 
 	wr := res.wr
-	st := wr.stream
-
-	closeStream := http2endsStream(wr.write)
-
-	if _, ok := wr.write.(http2handlerPanicRST); ok {
-		sc.closeStream(st, http2errHandlerPanicked)
-	}
-
-	if ch := wr.done; ch != nil {
-		select {
-		case ch <- res.err:
-		default:
-			panic(fmt.Sprintf("unbuffered done channel passed in for type %T", wr.write))
-		}
-	}
-	wr.write = nil
 
-	if closeStream {
+	if http2writeEndsStream(wr.write) {
+		st := wr.stream
 		if st == nil {
 			panic("internal error: expecting non-nil stream")
 		}
@@ -3774,13 +3786,24 @@ func (sc *http2serverConn) wroteFrame(res http2frameWriteResult) {
 		case http2stateOpen:
 
 			st.state = http2stateHalfClosedLocal
-			errCancel := http2streamError(st.id, http2ErrCodeCancel)
-			sc.resetStream(errCancel)
+			sc.resetStream(http2streamError(st.id, http2ErrCodeCancel))
 		case http2stateHalfClosedRemote:
 			sc.closeStream(st, http2errHandlerComplete)
 		}
+	} else {
+		switch v := wr.write.(type) {
+		case http2StreamError:
+
+			if st, ok := sc.streams[v.StreamID]; ok {
+				sc.closeStream(st, v)
+			}
+		case http2handlerPanicRST:
+			sc.closeStream(wr.stream, http2errHandlerPanicked)
+		}
 	}
 
+	wr.replyToWriter(res.err)
+
 	sc.scheduleFrameWrite()
 }
 
@@ -3877,8 +3900,7 @@ func (sc *http2serverConn) resetStream(se http2StreamError) {
 	sc.serveG.check()
 	sc.writeFrame(http2FrameWriteRequest{write: se})
 	if st, ok := sc.streams[se.StreamID]; ok {
-		st.sentReset = true
-		sc.closeStream(st, se)
+		st.resetQueued = true
 	}
 }
 
@@ -4017,7 +4039,6 @@ func (sc *http2serverConn) processResetStream(f *http2RSTStreamFrame) error {
 		return http2ConnectionError(http2ErrCodeProtocol)
 	}
 	if st != nil {
-		st.gotReset = true
 		st.cancelCtx()
 		sc.closeStream(st, http2streamError(f.StreamID, f.ErrCode))
 	}
@@ -4132,7 +4153,7 @@ func (sc *http2serverConn) processData(f *http2DataFrame) error {
 
 		return http2ConnectionError(http2ErrCodeProtocol)
 	}
-	if st == nil || state != http2stateOpen || st.gotTrailerHeader {
+	if st == nil || state != http2stateOpen || st.gotTrailerHeader || st.resetQueued {
 
 		if sc.inflow.available() < int32(f.Length) {
 			return http2streamError(id, http2ErrCodeFlowControl)
@@ -4141,6 +4162,10 @@ func (sc *http2serverConn) processData(f *http2DataFrame) error {
 		sc.inflow.take(int32(f.Length))
 		sc.sendWindowUpdate(nil, int(f.Length))
 
+		if st != nil && st.resetQueued {
+
+			return nil
+		}
 		return http2streamError(id, http2ErrCodeStreamClosed)
 	}
 	if st.body == nil {
@@ -4238,6 +4263,10 @@ func (sc *http2serverConn) processHeaders(f *http2MetaHeadersFrame) error {
 	}
 
 	if st := sc.streams[f.StreamID]; st != nil {
+		if st.resetQueued {
+
+			return nil
+		}
 		return st.processTrailerHeaders(f)
 	}
 
@@ -4373,7 +4402,7 @@ func (sc *http2serverConn) newStream(id, pusherID uint32, state http2streamState
 	} else {
 		sc.curClientStreams++
 	}
-	if sc.curClientStreams+sc.curPushedStreams == 1 {
+	if sc.curOpenStreams() == 1 {
 		sc.setConnState(StateActive)
 	}
 
@@ -5114,7 +5143,7 @@ func (w *http2responseWriter) push(target string, opts http2pushOptions) error {
 	}
 	for k := range opts.Header {
 		if strings.HasPrefix(k, ":") {
-			return fmt.Errorf("promised request headers cannot include psuedo header %q", k)
+			return fmt.Errorf("promised request headers cannot include pseudo header %q", k)
 		}
 
 		switch strings.ToLower(k) {
@@ -5203,7 +5232,7 @@ func (sc *http2serverConn) startPush(msg http2startPushRequest) {
 			scheme:    msg.url.Scheme,
 			authority: msg.url.Host,
 			path:      msg.url.RequestURI(),
-			header:    msg.header,
+			header:    http2cloneHeader(msg.header),
 		})
 		if err != nil {
 
@@ -5510,6 +5539,7 @@ type http2clientStream struct {
 	ID            uint32
 	resc          chan http2resAndError
 	bufPipe       http2pipe // buffered pipe with the flow-controlled response payload
+	startedWrite  bool      // started request body write; guarded by cc.mu
 	requestedGzip bool
 	on100         func() // optional code to run if get a 100 continue response
 
@@ -5633,6 +5663,10 @@ func http2authorityAddr(scheme string, authority string) (addr string) {
 	if a, err := idna.ToASCII(host); err == nil {
 		host = a
 	}
+
+	if strings.HasPrefix(host, "[") && strings.HasSuffix(host, "]") {
+		return host + ":" + port
+	}
 	return net.JoinHostPort(host, port)
 }
 
@@ -5651,8 +5685,10 @@ func (t *http2Transport) RoundTripOpt(req *Request, opt http2RoundTripOpt) (*Res
 		}
 		http2traceGotConn(req, cc)
 		res, err := cc.RoundTrip(req)
-		if http2shouldRetryRequest(req, err) {
-			continue
+		if err != nil {
+			if req, err = http2shouldRetryRequest(req, err); err == nil {
+				continue
+			}
 		}
 		if err != nil {
 			t.vlogf("RoundTrip failure: %v", err)
@@ -5674,11 +5710,39 @@ func (t *http2Transport) CloseIdleConnections() {
 var (
 	http2errClientConnClosed   = errors.New("http2: client conn is closed")
 	http2errClientConnUnusable = errors.New("http2: client conn not usable")
+
+	http2errClientConnGotGoAway                 = errors.New("http2: Transport received Server's graceful shutdown GOAWAY")
+	http2errClientConnGotGoAwayAfterSomeReqBody = errors.New("http2: Transport received Server's graceful shutdown GOAWAY; some request body already written")
 )
 
-func http2shouldRetryRequest(req *Request, err error) bool {
+// shouldRetryRequest is called by RoundTrip when a request fails to get
+// response headers. It is always called with a non-nil error.
+// It returns either a request to retry (either the same request, or a
+// modified clone), or an error if the request can't be replayed.
+func http2shouldRetryRequest(req *Request, err error) (*Request, error) {
+	switch err {
+	default:
+		return nil, err
+	case http2errClientConnUnusable, http2errClientConnGotGoAway:
+		return req, nil
+	case http2errClientConnGotGoAwayAfterSomeReqBody:
+
+		if req.Body == nil || http2reqBodyIsNoBody(req.Body) {
+			return req, nil
+		}
 
-	return err == http2errClientConnUnusable
+		getBody := http2reqGetBody(req)
+		if getBody == nil {
+			return nil, errors.New("http2: Transport: peer server initiated graceful shutdown after some of Request.Body was written; define Request.GetBody to avoid this error")
+		}
+		body, err := getBody()
+		if err != nil {
+			return nil, err
+		}
+		newReq := *req
+		newReq.Body = body
+		return &newReq, nil
+	}
 }
 
 func (t *http2Transport) dialClientConn(addr string, singleUse bool) (*http2ClientConn, error) {
@@ -5826,6 +5890,15 @@ func (cc *http2ClientConn) setGoAway(f *http2GoAwayFrame) {
 	if old != nil && old.ErrCode != http2ErrCodeNo {
 		cc.goAway.ErrCode = old.ErrCode
 	}
+	last := f.LastStreamID
+	for streamID, cs := range cc.streams {
+		if streamID > last {
+			select {
+			case cs.resc <- http2resAndError{err: http2errClientConnGotGoAway}:
+			default:
+			}
+		}
+	}
 }
 
 func (cc *http2ClientConn) CanTakeNewRequest() bool {
@@ -6059,6 +6132,13 @@ func (cc *http2ClientConn) RoundTrip(req *Request) (*Response, error) {
 			cs.abortRequestBodyWrite(http2errStopReqBodyWrite)
 		}
 		if re.err != nil {
+			if re.err == http2errClientConnGotGoAway {
+				cc.mu.Lock()
+				if cs.startedWrite {
+					re.err = http2errClientConnGotGoAwayAfterSomeReqBody
+				}
+				cc.mu.Unlock()
+			}
 			cc.forgetStreamID(cs.ID)
 			return nil, re.err
 		}
@@ -7225,6 +7305,9 @@ func (t *http2Transport) getBodyWriterState(cs *http2clientStream, body io.Reade
 	resc := make(chan error, 1)
 	s.resc = resc
 	s.fn = func() {
+		cs.cc.mu.Lock()
+		cs.startedWrite = true
+		cs.cc.mu.Unlock()
 		resc <- cs.writeRequestBody(body, cs.req.Body)
 	}
 	s.delay = t.expectContinueTimeout()
@@ -7313,9 +7396,10 @@ type http2writeContext interface {
 	HeaderEncoder() (*hpack.Encoder, *bytes.Buffer)
 }
 
-// endsStream reports whether the given frame writer w will locally
-// close the stream.
-func http2endsStream(w http2writeFramer) bool {
+// writeEndsStream reports whether w writes a frame that will transition
+// the stream to a half-closed local state. This returns false for RST_STREAM,
+// which closes the entire stream (not just the local half).
+func http2writeEndsStream(w http2writeFramer) bool {
 	switch v := w.(type) {
 	case *http2writeData:
 		return v.endStream
@@ -7323,7 +7407,7 @@ func http2endsStream(w http2writeFramer) bool {
 		return v.endStream
 	case nil:
 
-		panic("endsStream called on nil writeFramer")
+		panic("writeEndsStream called on nil writeFramer")
 	}
 	return false
 }
@@ -7644,7 +7728,9 @@ type http2WriteScheduler interface {
 	// https://tools.ietf.org/html/rfc7540#section-5.1
 	AdjustStream(streamID uint32, priority http2PriorityParam)
 
-	// Push queues a frame in the scheduler.
+	// Push queues a frame in the scheduler. In most cases, this will not be
+	// called with wr.StreamID()!=0 unless that stream is currently open. The one
+	// exception is RST_STREAM frames, which may be sent on idle or closed streams.
 	Push(wr http2FrameWriteRequest)
 
 	// Pop dequeues the next frame to write. Returns false if no frames can
@@ -7767,6 +7853,20 @@ func (wr http2FrameWriteRequest) String() string {
 	return fmt.Sprintf("[FrameWriteRequest stream=%d, ch=%v, writer=%v]", wr.StreamID(), wr.done != nil, des)
 }
 
+// replyToWriter sends err to wr.done and panics if the send must block
+// This does nothing if wr.done is nil.
+func (wr *http2FrameWriteRequest) replyToWriter(err error) {
+	if wr.done == nil {
+		return
+	}
+	select {
+	case wr.done <- err:
+	default:
+		panic(fmt.Sprintf("unbuffered done channel passed in for type %T", wr.write))
+	}
+	wr.write = nil
+}
+
 // writeQueue is used by implementations of WriteScheduler.
 type http2writeQueue struct {
 	s []http2FrameWriteRequest
@@ -8183,7 +8283,11 @@ func (ws *http2priorityWriteScheduler) Push(wr http2FrameWriteRequest) {
 	} else {
 		n = ws.nodes[id]
 		if n == nil {
-			panic("add on non-open stream")
+
+			if wr.DataSize() > 0 {
+				panic("add DATA on non-open stream")
+			}
+			n = &ws.root
 		}
 	}
 	n.q.push(wr)
diff --git a/src/net/http/httptrace/trace.go b/src/net/http/httptrace/trace.go
index 3b74179..ea7b38c 100644
--- a/src/net/http/httptrace/trace.go
+++ b/src/net/http/httptrace/trace.go
@@ -146,7 +146,8 @@ type ClientTrace struct {
 	Wait100Continue func()
 
 	// WroteRequest is called with the result of writing the
-	// request and any body.
+	// request and any body. It may be called multiple times
+	// in the case of retried requests.
 	WroteRequest func(WroteRequestInfo)
 }
 
diff --git a/src/net/http/request.go b/src/net/http/request.go
index fd9ea54..96fa619 100644
--- a/src/net/http/request.go
+++ b/src/net/http/request.go
@@ -171,7 +171,7 @@ type Request struct {
 	Body io.ReadCloser
 
 	// GetBody defines an optional func to return a new copy of
-	// Body. It used for client requests when a redirect requires
+	// Body. It is used for client requests when a redirect requires
 	// reading the body more than once. Use of GetBody still
 	// requires setting Body.
 	//
@@ -313,8 +313,8 @@ type Request struct {
 // For outgoing client requests, the context controls cancelation.
 //
 // For incoming server requests, the context is canceled when the
-// ServeHTTP method returns. For its associated values, see
-// ServerContextKey and LocalAddrContextKey.
+// client's connection closes, the request is canceled (with HTTP/2),
+// or when the ServeHTTP method returns.
 func (r *Request) Context() context.Context {
 	if r.ctx != nil {
 		return r.ctx
@@ -785,7 +785,11 @@ func NewRequest(method, urlStr string, body io.Reader) (*Request, error) {
 				return ioutil.NopCloser(&r), nil
 			}
 		default:
-			req.ContentLength = -1 // unknown
+			// This is where we'd set it to -1 (at least
+			// if body != NoBody) to mean unknown, but
+			// that broke people during the Go 1.8 testing
+			// period. People depend on it being 0 I
+			// guess. Maybe retry later. See Issue 18117.
 		}
 		// For client requests, Request.ContentLength of 0
 		// means either actually 0, or unknown. The only way
@@ -795,7 +799,7 @@ func NewRequest(method, urlStr string, body io.Reader) (*Request, error) {
 		// so we use a well-known ReadCloser variable instead
 		// and have the http package also treat that sentinel
 		// variable to mean explicitly zero.
-		if req.ContentLength == 0 {
+		if req.GetBody != nil && req.ContentLength == 0 {
 			req.Body = NoBody
 			req.GetBody = func() (io.ReadCloser, error) { return NoBody, nil }
 		}
diff --git a/src/net/http/request_test.go b/src/net/http/request_test.go
index 3c965c1..e674837 100644
--- a/src/net/http/request_test.go
+++ b/src/net/http/request_test.go
@@ -498,10 +498,14 @@ func TestNewRequestContentLength(t *testing.T) {
 		{bytes.NewBuffer([]byte("1234")), 4},
 		{strings.NewReader("12345"), 5},
 		{strings.NewReader(""), 0},
-		// Not detected:
-		{struct{ io.Reader }{strings.NewReader("xyz")}, -1},
-		{io.NewSectionReader(strings.NewReader("x"), 0, 6), -1},
-		{readByte(io.NewSectionReader(strings.NewReader("xy"), 0, 6)), -1},
+		{NoBody, 0},
+
+		// Not detected. During Go 1.8 we tried to make these set to -1, but
+		// due to Issue 18117, we keep these returning 0, even though they're
+		// unknown.
+		{struct{ io.Reader }{strings.NewReader("xyz")}, 0},
+		{io.NewSectionReader(strings.NewReader("x"), 0, 6), 0},
+		{readByte(io.NewSectionReader(strings.NewReader("xy"), 0, 6)), 0},
 	}
 	for i, tt := range tests {
 		req, err := NewRequest("POST", "http://localhost/", tt.r)
@@ -511,9 +515,6 @@ func TestNewRequestContentLength(t *testing.T) {
 		if req.ContentLength != tt.want {
 			t.Errorf("test[%d]: ContentLength(%T) = %d; want %d", i, tt.r, req.ContentLength, tt.want)
 		}
-		if (req.ContentLength == 0) != (req.Body == NoBody) {
-			t.Errorf("test[%d]: ContentLength = %d but Body non-nil is %v", i, req.ContentLength, req.Body != nil)
-		}
 	}
 }
 
diff --git a/src/net/http/requestwrite_test.go b/src/net/http/requestwrite_test.go
index d13e37a..c398e64 100644
--- a/src/net/http/requestwrite_test.go
+++ b/src/net/http/requestwrite_test.go
@@ -581,12 +581,14 @@ func (rc *closeChecker) Close() error {
 // inside a NopCloser, and that it serializes it correctly.
 func TestRequestWriteClosesBody(t *testing.T) {
 	rc := &closeChecker{Reader: strings.NewReader("my body")}
-	req, _ := NewRequest("POST", "http://foo.com/", rc)
-	if req.ContentLength != -1 {
-		t.Errorf("got req.ContentLength %d, want -1", req.ContentLength)
+	req, err := NewRequest("POST", "http://foo.com/", rc)
+	if err != nil {
+		t.Fatal(err)
 	}
 	buf := new(bytes.Buffer)
-	req.Write(buf)
+	if err := req.Write(buf); err != nil {
+		t.Error(err)
+	}
 	if !rc.closed {
 		t.Error("body not closed after write")
 	}
diff --git a/src/net/http/transport.go b/src/net/http/transport.go
index e484548..571943d 100644
--- a/src/net/http/transport.go
+++ b/src/net/http/transport.go
@@ -923,6 +923,9 @@ func (t *Transport) getConn(treq *transportRequest, cm connectMethod) (*persistC
 		// value.
 		select {
 		case <-req.Cancel:
+			// It was an error due to cancelation, so prioritize that
+			// error value. (Issue 16049)
+			return nil, errRequestCanceledConn
 		case <-req.Context().Done():
 			return nil, req.Context().Err()
 		case err := <-cancelc:
@@ -935,9 +938,6 @@ func (t *Transport) getConn(treq *transportRequest, cm connectMethod) (*persistC
 			// return the original error message:
 			return nil, v.err
 		}
-		// It was an error due to cancelation, so prioritize that
-		// error value. (Issue 16049)
-		return nil, errRequestCanceledConn
 	case pc := <-idleConnCh:
 		// Another request finished first and its net.Conn
 		// became available before our dial. Or somebody
@@ -1384,7 +1384,7 @@ func (pc *persistConn) closeConnIfStillIdle() {
 //
 // The startBytesWritten value should be the value of pc.nwrite before the roundTrip
 // started writing the request.
-func (pc *persistConn) mapRoundTripErrorFromReadLoop(startBytesWritten int64, err error) (out error) {
+func (pc *persistConn) mapRoundTripErrorFromReadLoop(req *Request, startBytesWritten int64, err error) (out error) {
 	if err == nil {
 		return nil
 	}
@@ -1399,7 +1399,7 @@ func (pc *persistConn) mapRoundTripErrorFromReadLoop(startBytesWritten int64, er
 	}
 	if pc.isBroken() {
 		<-pc.writeLoopDone
-		if pc.nwrite == startBytesWritten {
+		if pc.nwrite == startBytesWritten && req.outgoingLength() == 0 {
 			return nothingWrittenError{err}
 		}
 	}
@@ -1410,7 +1410,7 @@ func (pc *persistConn) mapRoundTripErrorFromReadLoop(startBytesWritten int64, er
 // up to Transport.RoundTrip method when persistConn.roundTrip sees
 // its pc.closech channel close, indicating the persistConn is dead.
 // (after closech is closed, pc.closed is valid).
-func (pc *persistConn) mapRoundTripErrorAfterClosed(startBytesWritten int64) error {
+func (pc *persistConn) mapRoundTripErrorAfterClosed(req *Request, startBytesWritten int64) error {
 	if err := pc.canceled(); err != nil {
 		return err
 	}
@@ -1428,7 +1428,7 @@ func (pc *persistConn) mapRoundTripErrorAfterClosed(startBytesWritten int64) err
 	// see if we actually managed to write anything. If not, we
 	// can retry the request.
 	<-pc.writeLoopDone
-	if pc.nwrite == startBytesWritten {
+	if pc.nwrite == startBytesWritten && req.outgoingLength() == 0 {
 		return nothingWrittenError{err}
 	}
 
@@ -1710,7 +1710,7 @@ func (pc *persistConn) writeLoop() {
 			}
 			if err != nil {
 				wr.req.Request.closeBody()
-				if pc.nwrite == startBytesWritten {
+				if pc.nwrite == startBytesWritten && wr.req.outgoingLength() == 0 {
 					err = nothingWrittenError{err}
 				}
 			}
@@ -1911,14 +1911,14 @@ WaitResponse:
 				respHeaderTimer = timer.C
 			}
 		case <-pc.closech:
-			re = responseAndError{err: pc.mapRoundTripErrorAfterClosed(startBytesWritten)}
+			re = responseAndError{err: pc.mapRoundTripErrorAfterClosed(req.Request, startBytesWritten)}
 			break WaitResponse
 		case <-respHeaderTimer:
 			pc.close(errTimeout)
 			re = responseAndError{err: errTimeout}
 			break WaitResponse
 		case re = <-resc:
-			re.err = pc.mapRoundTripErrorFromReadLoop(startBytesWritten, re.err)
+			re.err = pc.mapRoundTripErrorFromReadLoop(req.Request, startBytesWritten, re.err)
 			break WaitResponse
 		case <-cancelChan:
 			pc.t.CancelRequest(req.Request)
diff --git a/src/net/ip.go b/src/net/ip.go
index c5b454d..4a7774a 100644
--- a/src/net/ip.go
+++ b/src/net/ip.go
@@ -90,7 +90,7 @@ func CIDRMask(ones, bits int) IPMask {
 
 // Well-known IPv4 addresses
 var (
-	IPv4bcast     = IPv4(255, 255, 255, 255) // broadcast
+	IPv4bcast     = IPv4(255, 255, 255, 255) // limited broadcast
 	IPv4allsys    = IPv4(224, 0, 0, 1)       // all systems
 	IPv4allrouter = IPv4(224, 0, 0, 2)       // all routers
 	IPv4zero      = IPv4(0, 0, 0, 0)         // all zeros
@@ -654,13 +654,14 @@ func ParseIP(s string) IP {
 	return nil
 }
 
-// ParseCIDR parses s as a CIDR notation IP address and mask,
+// ParseCIDR parses s as a CIDR notation IP address and prefix length,
 // like "192.0.2.0/24" or "2001:db8::/32", as defined in
 // RFC 4632 and RFC 4291.
 //
-// It returns the IP address and the network implied by the IP
-// and mask. For example, ParseCIDR("198.51.100.1/24") returns
-// the IP address 198.51.100.1 and the network 198.51.100.0/24.
+// It returns the IP address and the network implied by the IP and
+// prefix length.
+// For example, ParseCIDR("192.0.2.1/24") returns the IP address
+// 198.0.2.1 and the network 198.0.2.0/24.
 func ParseCIDR(s string) (IP, *IPNet, error) {
 	i := byteIndex(s, '/')
 	if i < 0 {
diff --git a/src/net/lookup_unix.go b/src/net/lookup_unix.go
index 35f253c..609adbf 100644
--- a/src/net/lookup_unix.go
+++ b/src/net/lookup_unix.go
@@ -76,13 +76,15 @@ func (r *Resolver) lookupIP(ctx context.Context, host string) (addrs []IPAddr, e
 }
 
 func (r *Resolver) lookupPort(ctx context.Context, network, service string) (int, error) {
-	// TODO: use the context if there ever becomes a need. Related
-	// is issue 15321. But port lookup generally just involves
-	// local files, and the os package has no context support. The
-	// files might be on a remote filesystem, though. This should
-	// probably race goroutines if ctx != context.Background().
 	if !r.PreferGo && systemConf().canUseCgo() {
 		if port, err, ok := cgoLookupPort(ctx, network, service); ok {
+			if err != nil {
+				// Issue 18213: if cgo fails, first check to see whether we
+				// have the answer baked-in to the net package.
+				if port, err := goLookupPort(network, service); err == nil {
+					return port, nil
+				}
+			}
 			return port, err
 		}
 	}
diff --git a/src/net/port_unix.go b/src/net/port_unix.go
index 4e04781..868d1e4 100644
--- a/src/net/port_unix.go
+++ b/src/net/port_unix.go
@@ -10,12 +10,11 @@ package net
 
 import "sync"
 
-var servicesError error
 var onceReadServices sync.Once
 
 func readServices() {
-	var file *file
-	if file, servicesError = open("/etc/services"); servicesError != nil {
+	file, err := open("/etc/services")
+	if err != nil {
 		return
 	}
 	for line, ok := file.readLine(); ok; line, ok = file.readLine() {
diff --git a/src/net/writev_test.go b/src/net/writev_test.go
index 4d2fc39..7160d28 100644
--- a/src/net/writev_test.go
+++ b/src/net/writev_test.go
@@ -151,7 +151,7 @@ func testBuffer_writeTo(t *testing.T, chunks int, useCopy bool) {
 
 		var wantSum int
 		switch runtime.GOOS {
-		case "darwin", "dragonfly", "freebsd", "linux", "netbsd", "openbsd":
+		case "android", "darwin", "dragonfly", "freebsd", "linux", "netbsd", "openbsd":
 			var wantMinCalls int
 			wantSum = want.Len()
 			v := chunks
diff --git a/src/os/exec/exec_test.go b/src/os/exec/exec_test.go
index d3ac7ab..3433745 100644
--- a/src/os/exec/exec_test.go
+++ b/src/os/exec/exec_test.go
@@ -247,6 +247,11 @@ func TestStdinClose(t *testing.T) {
 }
 
 // Issue 17647.
+// It used to be the case that TestStdinClose, above, would fail when
+// run under the race detector. This test is a variant of TestStdinClose
+// that also used to fail when run under the race detector.
+// This test is run by cmd/dist under the race detector to verify that
+// the race detector no longer reports any problems.
 func TestStdinCloseRace(t *testing.T) {
 	cmd := helperCommand(t, "stdinClose")
 	stdin, err := cmd.StdinPipe()
@@ -262,7 +267,12 @@ func TestStdinCloseRace(t *testing.T) {
 		}
 	}()
 	go func() {
-		io.Copy(stdin, strings.NewReader(stdinCloseTestString))
+		// Send the wrong string, so that the child fails even
+		// if the other goroutine doesn't manage to kill it first.
+		// This test is to check that the race detector does not
+		// falsely report an error, so it doesn't matter how the
+		// child process fails.
+		io.Copy(stdin, strings.NewReader("unexpected string"))
 		if err := stdin.Close(); err != nil {
 			t.Errorf("stdin.Close: %v", err)
 		}
@@ -978,7 +988,7 @@ func TestContextCancel(t *testing.T) {
 			break
 		}
 		if time.Since(start) > time.Second {
-			t.Fatal("cancelling context did not stop program")
+			t.Fatal("canceling context did not stop program")
 		}
 		time.Sleep(time.Millisecond)
 	}
diff --git a/src/os/file.go b/src/os/file.go
index de245c5..d45a00b 100644
--- a/src/os/file.go
+++ b/src/os/file.go
@@ -260,7 +260,7 @@ func Create(name string) (*File, error) {
 var lstat = Lstat
 
 // Rename renames (moves) oldpath to newpath.
-// If newpath already exists, Rename replaces it.
+// If newpath already exists and is not a directory, Rename replaces it.
 // OS-specific restrictions may apply when oldpath and newpath are in different directories.
 // If there is an error, it will be of type *LinkError.
 func Rename(oldpath, newpath string) error {
diff --git a/src/os/os_test.go b/src/os/os_test.go
index b1e20b7..b7300cd 100644
--- a/src/os/os_test.go
+++ b/src/os/os_test.go
@@ -1708,51 +1708,62 @@ func TestLongPath(t *testing.T) {
 			t.Fatalf("RemoveAll failed: %v", err)
 		}
 	}(tmpdir)
+
+	// Test the boundary of 247 and fewer bytes (normal) and 248 and more bytes (adjusted).
+	sizes := []int{247, 248, 249, 400}
 	for len(tmpdir) < 400 {
 		tmpdir += "/dir3456789"
 	}
-	if err := MkdirAll(tmpdir, 0755); err != nil {
-		t.Fatalf("MkdirAll failed: %v", err)
-	}
-	data := []byte("hello world\n")
-	if err := ioutil.WriteFile(tmpdir+"/foo.txt", data, 0644); err != nil {
-		t.Fatalf("ioutil.WriteFile() failed: %v", err)
-	}
-	if err := Rename(tmpdir+"/foo.txt", tmpdir+"/bar.txt"); err != nil {
-		t.Fatalf("Rename failed: %v", err)
-	}
-	mtime := time.Now().Truncate(time.Minute)
-	if err := Chtimes(tmpdir+"/bar.txt", mtime, mtime); err != nil {
-		t.Fatalf("Chtimes failed: %v", err)
-	}
-	names := []string{"bar.txt"}
-	if testenv.HasSymlink() {
-		if err := Symlink(tmpdir+"/bar.txt", tmpdir+"/symlink.txt"); err != nil {
-			t.Fatalf("Symlink failed: %v", err)
-		}
-		names = append(names, "symlink.txt")
-	}
-	if testenv.HasLink() {
-		if err := Link(tmpdir+"/bar.txt", tmpdir+"/link.txt"); err != nil {
-			t.Fatalf("Link failed: %v", err)
-		}
-		names = append(names, "link.txt")
-	}
-	for _, wantSize := range []int64{int64(len(data)), 0} {
-		for _, name := range names {
-			path := tmpdir + "/" + name
-			dir, err := Stat(path)
-			if err != nil {
-				t.Fatalf("Stat(%q) failed: %v", path, err)
+	for _, sz := range sizes {
+		t.Run(fmt.Sprintf("length=%d", sz), func(t *testing.T) {
+			sizedTempDir := tmpdir[:sz-1] + "x" // Ensure it does not end with a slash.
+
+			// The various sized runs are for this call to trigger the boundary
+			// condition.
+			if err := MkdirAll(sizedTempDir, 0755); err != nil {
+				t.Fatalf("MkdirAll failed: %v", err)
 			}
-			filesize := size(path, t)
-			if dir.Size() != filesize || filesize != wantSize {
-				t.Errorf("Size(%q) is %d, len(ReadFile()) is %d, want %d", path, dir.Size(), filesize, wantSize)
+			data := []byte("hello world\n")
+			if err := ioutil.WriteFile(sizedTempDir+"/foo.txt", data, 0644); err != nil {
+				t.Fatalf("ioutil.WriteFile() failed: %v", err)
 			}
-		}
-		if err := Truncate(tmpdir+"/bar.txt", 0); err != nil {
-			t.Fatalf("Truncate failed: %v", err)
-		}
+			if err := Rename(sizedTempDir+"/foo.txt", sizedTempDir+"/bar.txt"); err != nil {
+				t.Fatalf("Rename failed: %v", err)
+			}
+			mtime := time.Now().Truncate(time.Minute)
+			if err := Chtimes(sizedTempDir+"/bar.txt", mtime, mtime); err != nil {
+				t.Fatalf("Chtimes failed: %v", err)
+			}
+			names := []string{"bar.txt"}
+			if testenv.HasSymlink() {
+				if err := Symlink(sizedTempDir+"/bar.txt", sizedTempDir+"/symlink.txt"); err != nil {
+					t.Fatalf("Symlink failed: %v", err)
+				}
+				names = append(names, "symlink.txt")
+			}
+			if testenv.HasLink() {
+				if err := Link(sizedTempDir+"/bar.txt", sizedTempDir+"/link.txt"); err != nil {
+					t.Fatalf("Link failed: %v", err)
+				}
+				names = append(names, "link.txt")
+			}
+			for _, wantSize := range []int64{int64(len(data)), 0} {
+				for _, name := range names {
+					path := sizedTempDir + "/" + name
+					dir, err := Stat(path)
+					if err != nil {
+						t.Fatalf("Stat(%q) failed: %v", path, err)
+					}
+					filesize := size(path, t)
+					if dir.Size() != filesize || filesize != wantSize {
+						t.Errorf("Size(%q) is %d, len(ReadFile()) is %d, want %d", path, dir.Size(), filesize, wantSize)
+					}
+				}
+				if err := Truncate(sizedTempDir+"/bar.txt", 0); err != nil {
+					t.Fatalf("Truncate failed: %v", err)
+				}
+			}
+		})
 	}
 }
 
diff --git a/src/os/path_windows.go b/src/os/path_windows.go
index ccac1c0..101b026 100644
--- a/src/os/path_windows.go
+++ b/src/os/path_windows.go
@@ -139,13 +139,16 @@ func dirname(path string) string {
 func fixLongPath(path string) string {
 	// Do nothing (and don't allocate) if the path is "short".
 	// Empirically (at least on the Windows Server 2013 builder),
-	// the kernel is arbitrarily okay with <= 248 bytes. That
+	// the kernel is arbitrarily okay with < 248 bytes. That
 	// matches what the docs above say:
 	// "When using an API to create a directory, the specified
 	// path cannot be so long that you cannot append an 8.3 file
 	// name (that is, the directory name cannot exceed MAX_PATH
 	// minus 12)." Since MAX_PATH is 260, 260 - 12 = 248.
-	if len(path) <= 248 {
+	//
+	// The MSDN docs appear to say that a normal path that is 248 bytes long
+	// will work; empirically the path must be less then 248 bytes long.
+	if len(path) < 248 {
 		// Don't fix. (This is how Go 1.7 and earlier worked,
 		// not automatically generating the \\?\ form)
 		return path
diff --git a/src/os/signal/doc.go b/src/os/signal/doc.go
index 16f49c7..73b01a2 100644
--- a/src/os/signal/doc.go
+++ b/src/os/signal/doc.go
@@ -181,11 +181,10 @@ If the Go runtime sees an existing signal handler for the SIGCANCEL or
 SIGSETXID signals (which are used only on GNU/Linux), it will turn on
 the SA_ONSTACK flag and otherwise keep the signal handler.
 
-For the synchronous signals and SIGPIPE, the Go runtime will install a
-signal handler. It will save any existing signal handler. If a
-synchronous signal arrives while executing non-Go code, the Go runtime
-will invoke the existing signal handler instead of the Go signal
-handler.
+For the synchronous signals, the Go runtime will install a signal
+handler. It will save any existing signal handler. If a synchronous
+signal arrives while executing non-Go code, the Go runtime will invoke
+the existing signal handler instead of the Go signal handler.
 
 Go code built with -buildmode=c-archive or -buildmode=c-shared will
 not install any other signal handlers by default. If there is an
diff --git a/src/plugin/plugin.go b/src/plugin/plugin.go
index 5c822bd..b86099a 100644
--- a/src/plugin/plugin.go
+++ b/src/plugin/plugin.go
@@ -4,7 +4,7 @@
 
 // Package plugin implements loading and symbol resolution of Go plugins.
 //
-// Currently plugins only work on Linux and Darwin.
+// Currently plugins only work on Linux.
 //
 // A plugin is a Go main package with exported functions and variables that
 // has been built with:
diff --git a/src/reflect/example_test.go b/src/reflect/example_test.go
index 9e2b9b3..f959b95 100644
--- a/src/reflect/example_test.go
+++ b/src/reflect/example_test.go
@@ -5,6 +5,8 @@
 package reflect_test
 
 import (
+	"bytes"
+	"encoding/json"
 	"fmt"
 	"io"
 	"os"
@@ -107,3 +109,42 @@ func ExampleTypeOf() {
 	// Output:
 	// true
 }
+
+func ExampleStructOf() {
+	typ := reflect.StructOf([]reflect.StructField{
+		{
+			Name: "Height",
+			Type: reflect.TypeOf(float64(0)),
+			Tag:  `json:"height"`,
+		},
+		{
+			Name: "Age",
+			Type: reflect.TypeOf(int(0)),
+			Tag:  `json:"age"`,
+		},
+	})
+
+	v := reflect.New(typ).Elem()
+	v.Field(0).SetFloat(0.4)
+	v.Field(1).SetInt(2)
+	s := v.Addr().Interface()
+
+	w := new(bytes.Buffer)
+	if err := json.NewEncoder(w).Encode(s); err != nil {
+		panic(err)
+	}
+
+	fmt.Printf("value: %+v\n", s)
+	fmt.Printf("json:  %s", w.Bytes())
+
+	r := bytes.NewReader([]byte(`{"height":1.5,"age":10}`))
+	if err := json.NewDecoder(r).Decode(s); err != nil {
+		panic(err)
+	}
+	fmt.Printf("value: %+v\n", s)
+
+	// Output:
+	// value: &{Height:0.4 Age:2}
+	// json:  {"height":0.4,"age":2}
+	// value: &{Height:1.5 Age:10}
+}
diff --git a/src/runtime/asm_amd64.s b/src/runtime/asm_amd64.s
index 9ffd297..0070e9d 100644
--- a/src/runtime/asm_amd64.s
+++ b/src/runtime/asm_amd64.s
@@ -742,7 +742,7 @@ havem:
 	MOVQ	(g_sched+gobuf_pc)(SI), BX
 	MOVQ	BX, -8(DI)
 	// Compute the size of the frame, including return PC and, if
-	// GOEXPERIMENT=framepointer, the saved based pointer
+	// GOEXPERIMENT=framepointer, the saved base pointer
 	MOVQ	ctxt+24(FP), BX
 	LEAQ	fv+0(FP), AX
 	SUBQ	SP, AX
diff --git a/src/runtime/asm_mipsx.s b/src/runtime/asm_mipsx.s
index cd855c7..73da768 100644
--- a/src/runtime/asm_mipsx.s
+++ b/src/runtime/asm_mipsx.s
@@ -12,11 +12,11 @@
 #define	REGCTXT	R22
 
 TEXT runtime·rt0_go(SB),NOSPLIT,$0
-	// R29 = stack; R1 = argc; R2 = argv
+	// R29 = stack; R4 = argc; R5 = argv
 
 	ADDU	$-12, R29
-	MOVW	R1, 4(R29)	// argc
-	MOVW	R2, 8(R29)	// argv
+	MOVW	R4, 4(R29)	// argc
+	MOVW	R5, 8(R29)	// argv
 
 	// create istack out of the given (operating system) stack.
 	// _cgo_init may update stackguard.
@@ -28,7 +28,16 @@ TEXT runtime·rt0_go(SB),NOSPLIT,$0
 	MOVW	R1, (g_stack+stack_lo)(g)
 	MOVW	R29, (g_stack+stack_hi)(g)
 
-// TODO(mips32): cgo
+	// if there is a _cgo_init, call it using the gcc ABI.
+	MOVW	_cgo_init(SB), R25
+	BEQ	R25, nocgo
+	ADDU	$-16, R29
+	MOVW	R0, R7	// arg 3: not used
+	MOVW	R0, R6	// arg 2: not used
+	MOVW	$setg_gcc<>(SB), R5	// arg 1: setg
+	MOVW	g, R4	// arg 0: G
+	JAL	(R25)
+	ADDU	$16, R29
 
 nocgo:
 	// update stackguard after _cgo_init
@@ -434,7 +443,7 @@ TEXT runtime·jmpdefer(SB),NOSPLIT,$0-8
 	JMP	(R4)
 
 // Save state of caller into g->sched. Smashes R1.
-TEXT gosave<>(SB),NOSPLIT,$0
+TEXT gosave<>(SB),NOSPLIT,$-4
 	MOVW	R31, (g_sched+gobuf_pc)(g)
 	MOVW	R29, (g_sched+gobuf_sp)(g)
 	MOVW	R0, (g_sched+gobuf_lr)(g)
@@ -449,22 +458,168 @@ TEXT gosave<>(SB),NOSPLIT,$0
 // Call fn(arg) on the scheduler stack,
 // aligned appropriately for the gcc ABI.
 // See cgocall.go for more details.
-// Not implemented.
 TEXT ·asmcgocall(SB),NOSPLIT,$0-12
-	UNDEF
+	MOVW	fn+0(FP), R25
+	MOVW	arg+4(FP), R4
+
+	MOVW	R29, R3	// save original stack pointer
+	MOVW	g, R2
+
+	// Figure out if we need to switch to m->g0 stack.
+	// We get called to create new OS threads too, and those
+	// come in on the m->g0 stack already.
+	MOVW	g_m(g), R5
+	MOVW	m_g0(R5), R6
+	BEQ	R6, g, g0
+
+	JAL	gosave<>(SB)
+	MOVW	R6, g
+	JAL	runtime·save_g(SB)
+	MOVW	(g_sched+gobuf_sp)(g), R29
+
+	// Now on a scheduling stack (a pthread-created stack).
+g0:
+	// Save room for two of our pointers and O32 frame.
+	ADDU	$-24, R29
+	AND	$~7, R29	// O32 ABI expects 8-byte aligned stack on function entry
+	MOVW	R2, 16(R29)	// save old g on stack
+	MOVW	(g_stack+stack_hi)(R2), R2
+	SUBU	R3, R2
+	MOVW	R2, 20(R29)	// save depth in old g stack (can't just save SP, as stack might be copied during a callback)
+	JAL	(R25)
+
+	// Restore g, stack pointer. R2 is return value.
+	MOVW	16(R29), g
+	JAL	runtime·save_g(SB)
+	MOVW	(g_stack+stack_hi)(g), R5
+	MOVW	20(R29), R6
+	SUBU	R6, R5
+	MOVW	R5, R29
+
+	MOVW	R2, ret+8(FP)
+	RET
 
 // cgocallback(void (*fn)(void*), void *frame, uintptr framesize)
 // Turn the fn into a Go func (by taking its address) and call
 // cgocallback_gofunc.
-// Not implemented.
-TEXT runtime·cgocallback(SB),NOSPLIT,$0-16
-	UNDEF
+TEXT runtime·cgocallback(SB),NOSPLIT,$16-16
+	MOVW	$fn+0(FP), R1
+	MOVW	R1, 4(R29)
+	MOVW	frame+4(FP), R1
+	MOVW	R1, 8(R29)
+	MOVW	framesize+8(FP), R1
+	MOVW	R1, 12(R29)
+	MOVW	ctxt+12(FP), R1
+	MOVW	R1, 16(R29)
+	MOVW	$runtime·cgocallback_gofunc(SB), R1
+	JAL	(R1)
+	RET
 
-// cgocallback_gofunc(FuncVal*, void *frame, uintptr framesize)
+// cgocallback_gofunc(FuncVal*, void *frame, uintptr framesize, uintptr ctxt)
 // See cgocall.go for more details.
-// Not implemented.
-TEXT ·cgocallback_gofunc(SB),NOSPLIT,$0-16
-	UNDEF
+TEXT ·cgocallback_gofunc(SB),NOSPLIT,$8-16
+	NO_LOCAL_POINTERS
+
+	// Load m and g from thread-local storage.
+	MOVB	runtime·iscgo(SB), R1
+	BEQ	R1, nocgo
+	JAL	runtime·load_g(SB)
+nocgo:
+
+	// If g is nil, Go did not create the current thread.
+	// Call needm to obtain one for temporary use.
+	// In this case, we're running on the thread stack, so there's
+	// lots of space, but the linker doesn't know. Hide the call from
+	// the linker analysis by using an indirect call.
+	BEQ	g, needm
+
+	MOVW	g_m(g), R3
+	MOVW	R3, savedm-4(SP)
+	JMP	havem
+
+needm:
+	MOVW	g, savedm-4(SP) // g is zero, so is m.
+	MOVW	$runtime·needm(SB), R4
+	JAL	(R4)
+
+	// Set m->sched.sp = SP, so that if a panic happens
+	// during the function we are about to execute, it will
+	// have a valid SP to run on the g0 stack.
+	// The next few lines (after the havem label)
+	// will save this SP onto the stack and then write
+	// the same SP back to m->sched.sp. That seems redundant,
+	// but if an unrecovered panic happens, unwindm will
+	// restore the g->sched.sp from the stack location
+	// and then systemstack will try to use it. If we don't set it here,
+	// that restored SP will be uninitialized (typically 0) and
+	// will not be usable.
+	MOVW	g_m(g), R3
+	MOVW	m_g0(R3), R1
+	MOVW	R29, (g_sched+gobuf_sp)(R1)
+
+havem:
+	// Now there's a valid m, and we're running on its m->g0.
+	// Save current m->g0->sched.sp on stack and then set it to SP.
+	// Save current sp in m->g0->sched.sp in preparation for
+	// switch back to m->curg stack.
+	// NOTE: unwindm knows that the saved g->sched.sp is at 4(R29) aka savedsp-8(SP).
+	MOVW	m_g0(R3), R1
+	MOVW	(g_sched+gobuf_sp)(R1), R2
+	MOVW	R2, savedsp-8(SP)
+	MOVW	R29, (g_sched+gobuf_sp)(R1)
+
+	// Switch to m->curg stack and call runtime.cgocallbackg.
+	// Because we are taking over the execution of m->curg
+	// but *not* resuming what had been running, we need to
+	// save that information (m->curg->sched) so we can restore it.
+	// We can restore m->curg->sched.sp easily, because calling
+	// runtime.cgocallbackg leaves SP unchanged upon return.
+	// To save m->curg->sched.pc, we push it onto the stack.
+	// This has the added benefit that it looks to the traceback
+	// routine like cgocallbackg is going to return to that
+	// PC (because the frame we allocate below has the same
+	// size as cgocallback_gofunc's frame declared above)
+	// so that the traceback will seamlessly trace back into
+	// the earlier calls.
+	//
+	// In the new goroutine, -4(SP) is unused (where SP refers to
+	// m->curg's SP while we're setting it up, before we've adjusted it).
+	MOVW	m_curg(R3), g
+	JAL	runtime·save_g(SB)
+	MOVW	(g_sched+gobuf_sp)(g), R2 // prepare stack as R2
+	MOVW	(g_sched+gobuf_pc)(g), R4
+	MOVW	R4, -12(R2)
+	MOVW    ctxt+12(FP), R1
+	MOVW    R1, -8(R2)
+	MOVW	$-12(R2), R29
+	JAL	runtime·cgocallbackg(SB)
+
+	// Restore g->sched (== m->curg->sched) from saved values.
+	MOVW	0(R29), R4
+	MOVW	R4, (g_sched+gobuf_pc)(g)
+	MOVW	$12(R29), R2
+	MOVW	R2, (g_sched+gobuf_sp)(g)
+
+	// Switch back to m->g0's stack and restore m->g0->sched.sp.
+	// (Unlike m->curg, the g0 goroutine never uses sched.pc,
+	// so we do not have to restore it.)
+	MOVW	g_m(g), R3
+	MOVW	m_g0(R3), g
+	JAL	runtime·save_g(SB)
+	MOVW	(g_sched+gobuf_sp)(g), R29
+	MOVW	savedsp-8(SP), R2
+	MOVW	R2, (g_sched+gobuf_sp)(g)
+
+	// If the m on entry was nil, we called needm above to borrow an m
+	// for the duration of the call. Since the call is over, return it with dropm.
+	MOVW	savedm-4(SP), R3
+	BNE	R3, droppedm
+	MOVW	$runtime·dropm(SB), R4
+	JAL	(R4)
+droppedm:
+
+	// Done!
+	RET
 
 // void setg(G*); set g. for use by needm.
 // This only happens if iscgo, so jump straight to save_g
@@ -475,9 +630,10 @@ TEXT runtime·setg(SB),NOSPLIT,$0-4
 
 // void setg_gcc(G*); set g in C TLS.
 // Must obey the gcc calling convention.
-// Not implemented.
 TEXT setg_gcc<>(SB),NOSPLIT,$0
-	UNDEF
+	MOVW	R4, g
+	JAL	runtime·save_g(SB)
+	RET
 
 TEXT runtime·getcallerpc(SB),NOSPLIT,$4-8
 	MOVW	8(R29), R1	// LR saved by caller
@@ -764,9 +920,23 @@ TEXT runtime·return0(SB),NOSPLIT,$0
 
 // Called from cgo wrappers, this function returns g->m->curg.stack.hi.
 // Must obey the gcc calling convention.
-// Not implemented.
 TEXT _cgo_topofstack(SB),NOSPLIT,$-4
-	UNDEF
+	// g (R30), R3 and REGTMP (R23) might be clobbered by load_g. R30 and R23
+	// are callee-save in the gcc calling convention, so save them.
+	MOVW	R23, R8
+	MOVW	g, R9
+	MOVW	R31, R10 // this call frame does not save LR
+
+	JAL	runtime·load_g(SB)
+	MOVW	g_m(g), R1
+	MOVW	m_curg(R1), R1
+	MOVW	(g_stack+stack_hi)(R1), R2 // return value in R2
+
+	MOVW	R8, R23
+	MOVW	R9, g
+	MOVW	R10, R31
+
+	RET
 
 // The top-most function running on a goroutine
 // returns to goexit+PCQuantum.
diff --git a/src/runtime/cgo/asm_mipsx.s b/src/runtime/cgo/asm_mipsx.s
new file mode 100644
index 0000000..dd16af6
--- /dev/null
+++ b/src/runtime/cgo/asm_mipsx.s
@@ -0,0 +1,67 @@
+// 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.
+
+// +build mips mipsle
+
+#include "textflag.h"
+
+/*
+ * void crosscall2(void (*fn)(void*, int32, uintptr), void*, int32, uintptr)
+ * Save registers and call fn with two arguments.
+ */
+TEXT crosscall2(SB),NOSPLIT,$-4
+	/*
+	 * We still need to save all callee save register as before, and then
+	 *  push 3 args for fn (R5, R6, R7).
+	 * Also note that at procedure entry in gc world, 4(R29) will be the
+	 *  first arg.
+	 */
+
+	// Space for 9 caller-saved GPR + LR + 6 caller-saved FPR.
+	// O32 ABI allows us to smash 16 bytes argument area of caller frame.
+	SUBU	$(4*14+8*6-16), R29
+	MOVW	R5, (4*1)(R29)
+	MOVW	R6, (4*2)(R29)
+	MOVW	R7, (4*3)(R29)
+	MOVW	R16, (4*4)(R29)
+	MOVW	R17, (4*5)(R29)
+	MOVW	R18, (4*6)(R29)
+	MOVW	R19, (4*7)(R29)
+	MOVW	R20, (4*8)(R29)
+	MOVW	R21, (4*9)(R29)
+	MOVW	R22, (4*10)(R29)
+	MOVW	R23, (4*11)(R29)
+	MOVW	g, (4*12)(R29)
+	MOVW	R31, (4*13)(R29)
+
+	MOVD	F20, (4*14)(R29)
+	MOVD	F22, (4*14+8*1)(R29)
+	MOVD	F24, (4*14+8*2)(R29)
+	MOVD	F26, (4*14+8*3)(R29)
+	MOVD	F28, (4*14+8*4)(R29)
+	MOVD	F30, (4*14+8*5)(R29)
+
+	JAL	runtime·load_g(SB)
+	JAL	(R4)
+
+	MOVW	(4*4)(R29), R16
+	MOVW	(4*5)(R29), R17
+	MOVW	(4*6)(R29), R18
+	MOVW	(4*7)(R29), R19
+	MOVW	(4*8)(R29), R20
+	MOVW	(4*9)(R29), R21
+	MOVW	(4*10)(R29), R22
+	MOVW	(4*11)(R29), R23
+	MOVW	(4*12)(R29), g
+	MOVW	(4*13)(R29), R31
+
+	MOVD	(4*14)(R29), F20
+	MOVD	(4*14+8*1)(R29), F22
+	MOVD	(4*14+8*2)(R29), F24
+	MOVD	(4*14+8*3)(R29), F26
+	MOVD	(4*14+8*4)(R29), F28
+	MOVD	(4*14+8*5)(R29), F30
+
+	ADDU	$(4*14+8*6-16), R29
+	RET
diff --git a/src/runtime/cgo/gcc_darwin_386.c b/src/runtime/cgo/gcc_darwin_386.c
index effbcdf..83092db 100644
--- a/src/runtime/cgo/gcc_darwin_386.c
+++ b/src/runtime/cgo/gcc_darwin_386.c
@@ -6,6 +6,7 @@
 #include <pthread.h>
 #include <signal.h>
 #include "libcgo.h"
+#include "libcgo_unix.h"
 
 static void* threadentry(void*);
 static pthread_key_t k1;
@@ -123,7 +124,7 @@ _cgo_sys_thread_start(ThreadStart *ts)
 	pthread_attr_getstacksize(&attr, &size);
 	// Leave stacklo=0 and set stackhi=size; mstack will do the rest.
 	ts->g->stackhi = size;
-	err = pthread_create(&p, &attr, threadentry, ts);
+	err = _cgo_try_pthread_create(&p, &attr, threadentry, ts);
 
 	pthread_sigmask(SIG_SETMASK, &oset, nil);
 
diff --git a/src/runtime/cgo/gcc_darwin_amd64.c b/src/runtime/cgo/gcc_darwin_amd64.c
index 15396b0..93a6b8e 100644
--- a/src/runtime/cgo/gcc_darwin_amd64.c
+++ b/src/runtime/cgo/gcc_darwin_amd64.c
@@ -6,6 +6,7 @@
 #include <pthread.h>
 #include <signal.h>
 #include "libcgo.h"
+#include "libcgo_unix.h"
 
 static void* threadentry(void*);
 static pthread_key_t k1;
@@ -94,7 +95,7 @@ _cgo_sys_thread_start(ThreadStart *ts)
 	pthread_attr_getstacksize(&attr, &size);
 	// Leave stacklo=0 and set stackhi=size; mstack will do the rest.
 	ts->g->stackhi = size;
-	err = pthread_create(&p, &attr, threadentry, ts);
+	err = _cgo_try_pthread_create(&p, &attr, threadentry, ts);
 
 	pthread_sigmask(SIG_SETMASK, &oset, nil);
 
diff --git a/src/runtime/cgo/gcc_darwin_arm.c b/src/runtime/cgo/gcc_darwin_arm.c
index dbf88c3..b3f8046 100644
--- a/src/runtime/cgo/gcc_darwin_arm.c
+++ b/src/runtime/cgo/gcc_darwin_arm.c
@@ -10,6 +10,7 @@
 #include <unistd.h>
 
 #include "libcgo.h"
+#include "libcgo_unix.h"
 
 #include <CoreFoundation/CFBundle.h>
 #include <CoreFoundation/CFString.h>
@@ -65,7 +66,7 @@ _cgo_sys_thread_start(ThreadStart *ts)
 	pthread_attr_getstacksize(&attr, &size);
 	// Leave stacklo=0 and set stackhi=size; mstack will do the rest.
 	ts->g->stackhi = size;
-	err = pthread_create(&p, &attr, threadentry, ts);
+	err = _cgo_try_pthread_create(&p, &attr, threadentry, ts);
 
 	pthread_sigmask(SIG_SETMASK, &oset, nil);
 
diff --git a/src/runtime/cgo/gcc_darwin_arm64.c b/src/runtime/cgo/gcc_darwin_arm64.c
index a9eb4f2..039dcc0 100644
--- a/src/runtime/cgo/gcc_darwin_arm64.c
+++ b/src/runtime/cgo/gcc_darwin_arm64.c
@@ -11,6 +11,7 @@
 #include <stdlib.h>
 
 #include "libcgo.h"
+#include "libcgo_unix.h"
 
 #include <CoreFoundation/CFBundle.h>
 #include <CoreFoundation/CFString.h>
@@ -67,7 +68,7 @@ _cgo_sys_thread_start(ThreadStart *ts)
 	pthread_attr_getstacksize(&attr, &size);
 	// Leave stacklo=0 and set stackhi=size; mstack will do the rest.
 	ts->g->stackhi = size;
-	err = pthread_create(&p, &attr, threadentry, ts);
+	err = _cgo_try_pthread_create(&p, &attr, threadentry, ts);
 
 	pthread_sigmask(SIG_SETMASK, &oset, nil);
 
diff --git a/src/runtime/cgo/gcc_dragonfly_amd64.c b/src/runtime/cgo/gcc_dragonfly_amd64.c
index e532ad6..bdfbf6b 100644
--- a/src/runtime/cgo/gcc_dragonfly_amd64.c
+++ b/src/runtime/cgo/gcc_dragonfly_amd64.c
@@ -8,6 +8,7 @@
 #include <signal.h>
 #include <string.h>
 #include "libcgo.h"
+#include "libcgo_unix.h"
 
 static void* threadentry(void*);
 static void (*setg_gcc)(void*);
@@ -42,7 +43,7 @@ _cgo_sys_thread_start(ThreadStart *ts)
 
 	// Leave stacklo=0 and set stackhi=size; mstack will do the rest.
 	ts->g->stackhi = size;
-	err = pthread_create(&p, &attr, threadentry, ts);
+	err = _cgo_try_pthread_create(&p, &attr, threadentry, ts);
 
 	pthread_sigmask(SIG_SETMASK, &oset, nil);
 
diff --git a/src/runtime/cgo/gcc_freebsd_386.c b/src/runtime/cgo/gcc_freebsd_386.c
index d288666..c6d4f25 100644
--- a/src/runtime/cgo/gcc_freebsd_386.c
+++ b/src/runtime/cgo/gcc_freebsd_386.c
@@ -8,6 +8,7 @@
 #include <signal.h>
 #include <string.h>
 #include "libcgo.h"
+#include "libcgo_unix.h"
 
 static void* threadentry(void*);
 static void (*setg_gcc)(void*);
@@ -42,7 +43,7 @@ _cgo_sys_thread_start(ThreadStart *ts)
 	pthread_attr_getstacksize(&attr, &size);
 	// Leave stacklo=0 and set stackhi=size; mstack will do the rest.
 	ts->g->stackhi = size;
-	err = pthread_create(&p, &attr, threadentry, ts);
+	err = _cgo_try_pthread_create(&p, &attr, threadentry, ts);
 
 	pthread_sigmask(SIG_SETMASK, &oset, nil);
 
diff --git a/src/runtime/cgo/gcc_freebsd_amd64.c b/src/runtime/cgo/gcc_freebsd_amd64.c
index e532ad6..bdfbf6b 100644
--- a/src/runtime/cgo/gcc_freebsd_amd64.c
+++ b/src/runtime/cgo/gcc_freebsd_amd64.c
@@ -8,6 +8,7 @@
 #include <signal.h>
 #include <string.h>
 #include "libcgo.h"
+#include "libcgo_unix.h"
 
 static void* threadentry(void*);
 static void (*setg_gcc)(void*);
@@ -42,7 +43,7 @@ _cgo_sys_thread_start(ThreadStart *ts)
 
 	// Leave stacklo=0 and set stackhi=size; mstack will do the rest.
 	ts->g->stackhi = size;
-	err = pthread_create(&p, &attr, threadentry, ts);
+	err = _cgo_try_pthread_create(&p, &attr, threadentry, ts);
 
 	pthread_sigmask(SIG_SETMASK, &oset, nil);
 
diff --git a/src/runtime/cgo/gcc_freebsd_arm.c b/src/runtime/cgo/gcc_freebsd_arm.c
index c4e7574..746ca89 100644
--- a/src/runtime/cgo/gcc_freebsd_arm.c
+++ b/src/runtime/cgo/gcc_freebsd_arm.c
@@ -9,6 +9,7 @@
 #include <signal.h>
 #include <string.h>
 #include "libcgo.h"
+#include "libcgo_unix.h"
 
 #ifdef ARM_TP_ADDRESS
 // ARM_TP_ADDRESS is (ARM_VECTORS_HIGH + 0x1000) or 0xffff1000
@@ -58,7 +59,7 @@ _cgo_sys_thread_start(ThreadStart *ts)
 	pthread_attr_getstacksize(&attr, &size);
 	// Leave stacklo=0 and set stackhi=size; mstack will do the rest.
 	ts->g->stackhi = size;
-	err = pthread_create(&p, &attr, threadentry, ts);
+	err = _cgo_try_pthread_create(&p, &attr, threadentry, ts);
 
 	pthread_sigmask(SIG_SETMASK, &oset, nil);
 
diff --git a/src/runtime/cgo/gcc_libinit.c b/src/runtime/cgo/gcc_libinit.c
index 0bdf40a..f6fbaa3 100644
--- a/src/runtime/cgo/gcc_libinit.c
+++ b/src/runtime/cgo/gcc_libinit.c
@@ -6,10 +6,13 @@
 // +build darwin dragonfly freebsd linux netbsd solaris
 
 #include <pthread.h>
+#include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h> // strerror
+#include <time.h>
 #include "libcgo.h"
+#include "libcgo_unix.h"
 
 static pthread_cond_t runtime_init_cond = PTHREAD_COND_INITIALIZER;
 static pthread_mutex_t runtime_init_mu = PTHREAD_MUTEX_INITIALIZER;
@@ -21,7 +24,7 @@ static void (*cgo_context_function)(struct context_arg*);
 void
 x_cgo_sys_thread_create(void* (*func)(void*), void* arg) {
 	pthread_t p;
-	int err = pthread_create(&p, NULL, func, arg);
+	int err = _cgo_try_pthread_create(&p, NULL, func, arg);
 	if (err != 0) {
 		fprintf(stderr, "pthread_create failed: %s", strerror(err));
 		abort();
@@ -84,3 +87,23 @@ void (*(_cgo_get_context_function(void)))(struct context_arg*) {
 	pthread_mutex_unlock(&runtime_init_mu);
 	return ret;
 }
+
+// _cgo_try_pthread_create retries pthread_create if it fails with
+// EAGAIN.
+int
+_cgo_try_pthread_create(pthread_t* thread, const pthread_attr_t* attr, void* (*pfn)(void*), void* arg) {
+	int tries;
+	int err;
+	struct timespec ts;
+
+	for (tries = 0; tries < 20; tries++) {
+		err = pthread_create(thread, attr, pfn, arg);
+		if (err != EAGAIN) {
+			return err;
+		}
+		ts.tv_sec = 0;
+		ts.tv_nsec = (tries + 1) * 1000 * 1000; // Milliseconds.
+		nanosleep(&ts, nil);
+	}
+	return EAGAIN;
+}
diff --git a/src/runtime/cgo/gcc_libinit_openbsd.c b/src/runtime/cgo/gcc_libinit_openbsd.c
index 626bf8a..c8308e5 100644
--- a/src/runtime/cgo/gcc_libinit_openbsd.c
+++ b/src/runtime/cgo/gcc_libinit_openbsd.c
@@ -2,6 +2,9 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
+#include <sys/types.h>
+#include <errno.h>
+#include <pthread.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include "libcgo.h"
@@ -48,3 +51,24 @@ void x_cgo_set_context_function(void (*context)(struct context_arg*)) {
 void (*(_cgo_get_context_function(void)))(struct context_arg*) {
 	return cgo_context_function;
 }
+
+// _cgo_try_pthread_create retries sys_pthread_create if it fails with
+// EAGAIN.
+int
+_cgo_openbsd_try_pthread_create(int (*sys_pthread_create)(pthread_t*, const pthread_attr_t*, void* (*)(void*), void*),
+	pthread_t* thread, const pthread_attr_t* attr, void* (*pfn)(void*), void* arg) {
+	int tries;
+	int err;
+	struct timespec ts;
+
+	for (tries = 0; tries < 100; tries++) {
+		err = sys_pthread_create(thread, attr, pfn, arg);
+		if (err != EAGAIN) {
+			return err;
+		}
+		ts.tv_sec = 0;
+		ts.tv_nsec = (tries + 1) * 1000 * 1000; // Milliseconds.
+		nanosleep(&ts, nil);
+	}
+	return EAGAIN;
+}
diff --git a/src/runtime/cgo/gcc_linux_386.c b/src/runtime/cgo/gcc_linux_386.c
index 30fe92b..457a2c7 100644
--- a/src/runtime/cgo/gcc_linux_386.c
+++ b/src/runtime/cgo/gcc_linux_386.c
@@ -6,6 +6,7 @@
 #include <string.h>
 #include <signal.h>
 #include "libcgo.h"
+#include "libcgo_unix.h"
 
 static void *threadentry(void*);
 static void (*setg_gcc)(void*);
@@ -53,7 +54,7 @@ _cgo_sys_thread_start(ThreadStart *ts)
 	pthread_attr_getstacksize(&attr, &size);
 	// Leave stacklo=0 and set stackhi=size; mstack will do the rest.
 	ts->g->stackhi = size;
-	err = pthread_create(&p, &attr, threadentry, ts);
+	err = _cgo_try_pthread_create(&p, &attr, threadentry, ts);
 
 	pthread_sigmask(SIG_SETMASK, &oset, nil);
 
diff --git a/src/runtime/cgo/gcc_linux_amd64.c b/src/runtime/cgo/gcc_linux_amd64.c
index 0c34c66..5d8ff10 100644
--- a/src/runtime/cgo/gcc_linux_amd64.c
+++ b/src/runtime/cgo/gcc_linux_amd64.c
@@ -8,6 +8,7 @@
 #include <signal.h>
 #include <stdlib.h>
 #include "libcgo.h"
+#include "libcgo_unix.h"
 
 static void* threadentry(void*);
 static void (*setg_gcc)(void*);
@@ -70,7 +71,7 @@ _cgo_sys_thread_start(ThreadStart *ts)
 	pthread_attr_getstacksize(&attr, &size);
 	// Leave stacklo=0 and set stackhi=size; mstack will do the rest.
 	ts->g->stackhi = size;
-	err = pthread_create(&p, &attr, threadentry, ts);
+	err = _cgo_try_pthread_create(&p, &attr, threadentry, ts);
 
 	pthread_sigmask(SIG_SETMASK, &oset, nil);
 
diff --git a/src/runtime/cgo/gcc_linux_arm.c b/src/runtime/cgo/gcc_linux_arm.c
index 945c3f1..31ced5e 100644
--- a/src/runtime/cgo/gcc_linux_arm.c
+++ b/src/runtime/cgo/gcc_linux_arm.c
@@ -6,6 +6,7 @@
 #include <string.h>
 #include <signal.h>
 #include "libcgo.h"
+#include "libcgo_unix.h"
 
 static void *threadentry(void*);
 
@@ -33,7 +34,7 @@ _cgo_sys_thread_start(ThreadStart *ts)
 	pthread_attr_getstacksize(&attr, &size);
 	// Leave stacklo=0 and set stackhi=size; mstack will do the rest.
 	ts->g->stackhi = size;
-	err = pthread_create(&p, &attr, threadentry, ts);
+	err = _cgo_try_pthread_create(&p, &attr, threadentry, ts);
 
 	pthread_sigmask(SIG_SETMASK, &oset, nil);
 
diff --git a/src/runtime/cgo/gcc_linux_arm64.c b/src/runtime/cgo/gcc_linux_arm64.c
index ca9ba0b..35b8e27 100644
--- a/src/runtime/cgo/gcc_linux_arm64.c
+++ b/src/runtime/cgo/gcc_linux_arm64.c
@@ -6,6 +6,7 @@
 #include <string.h>
 #include <signal.h>
 #include "libcgo.h"
+#include "libcgo_unix.h"
 
 static void *threadentry(void*);
 
@@ -33,7 +34,7 @@ _cgo_sys_thread_start(ThreadStart *ts)
 	pthread_attr_getstacksize(&attr, &size);
 	// Leave stacklo=0 and set stackhi=size; mstack will do the rest.
 	ts->g->stackhi = size;
-	err = pthread_create(&p, &attr, threadentry, ts);
+	err = _cgo_try_pthread_create(&p, &attr, threadentry, ts);
 
 	pthread_sigmask(SIG_SETMASK, &oset, nil);
 
diff --git a/src/runtime/cgo/gcc_linux_mips64x.c b/src/runtime/cgo/gcc_linux_mips64x.c
index 8a95629..e0ce08f 100644
--- a/src/runtime/cgo/gcc_linux_mips64x.c
+++ b/src/runtime/cgo/gcc_linux_mips64x.c
@@ -10,6 +10,7 @@
 #include <string.h>
 #include <signal.h>
 #include "libcgo.h"
+#include "libcgo_unix.h"
 
 static void *threadentry(void*);
 
@@ -37,7 +38,7 @@ _cgo_sys_thread_start(ThreadStart *ts)
 	pthread_attr_getstacksize(&attr, &size);
 	// Leave stacklo=0 and set stackhi=size; mstack will do the rest.
 	ts->g->stackhi = size;
-	err = pthread_create(&p, &attr, threadentry, ts);
+	err = _cgo_try_pthread_create(&p, &attr, threadentry, ts);
 
 	pthread_sigmask(SIG_SETMASK, &oset, nil);
 
diff --git a/src/runtime/cgo/gcc_linux_mips64x.c b/src/runtime/cgo/gcc_linux_mipsx.c
similarity index 91%
copy from src/runtime/cgo/gcc_linux_mips64x.c
copy to src/runtime/cgo/gcc_linux_mipsx.c
index 8a95629..7ed9d87 100644
--- a/src/runtime/cgo/gcc_linux_mips64x.c
+++ b/src/runtime/cgo/gcc_linux_mipsx.c
@@ -4,12 +4,13 @@
 
 // +build cgo
 // +build linux
-// +build mips64 mips64le
+// +build mips mipsle
 
 #include <pthread.h>
 #include <string.h>
 #include <signal.h>
 #include "libcgo.h"
+#include "libcgo_unix.h"
 
 static void *threadentry(void*);
 
@@ -37,7 +38,7 @@ _cgo_sys_thread_start(ThreadStart *ts)
 	pthread_attr_getstacksize(&attr, &size);
 	// Leave stacklo=0 and set stackhi=size; mstack will do the rest.
 	ts->g->stackhi = size;
-	err = pthread_create(&p, &attr, threadentry, ts);
+	err = _cgo_try_pthread_create(&p, &attr, threadentry, ts);
 
 	pthread_sigmask(SIG_SETMASK, &oset, nil);
 
@@ -66,6 +67,8 @@ x_cgo_init(G *g, void (*setg)(void*), void **tlsg, void **tlsbase)
 	size_t size;
 
 	setg_gcc = setg;
+
+	memset(&attr, 0, sizeof attr);
 	pthread_attr_init(&attr);
 	pthread_attr_getstacksize(&attr, &size);
 	g->stacklo = (uintptr)&attr - size + 4096;
diff --git a/src/runtime/cgo/gcc_linux_ppc64x.c b/src/runtime/cgo/gcc_linux_ppc64x.c
index fb19805..fcf77cf 100644
--- a/src/runtime/cgo/gcc_linux_ppc64x.c
+++ b/src/runtime/cgo/gcc_linux_ppc64x.c
@@ -8,6 +8,7 @@
 #include <string.h>
 #include <signal.h>
 #include "libcgo.h"
+#include "libcgo_unix.h"
 
 static void *threadentry(void*);
 
@@ -43,7 +44,7 @@ _cgo_sys_thread_start(ThreadStart *ts)
 	pthread_attr_getstacksize(&attr, &size);
 	// Leave stacklo=0 and set stackhi=size; mstack will do the rest.
 	ts->g->stackhi = size;
-	err = pthread_create(&p, &attr, threadentry, ts);
+	err = _cgo_try_pthread_create(&p, &attr, threadentry, ts);
 
 	pthread_sigmask(SIG_SETMASK, &oset, nil);
 
diff --git a/src/runtime/cgo/gcc_linux_s390x.c b/src/runtime/cgo/gcc_linux_s390x.c
index 81e3b33..cdc9c23 100644
--- a/src/runtime/cgo/gcc_linux_s390x.c
+++ b/src/runtime/cgo/gcc_linux_s390x.c
@@ -6,6 +6,7 @@
 #include <string.h>
 #include <signal.h>
 #include "libcgo.h"
+#include "libcgo_unix.h"
 
 static void *threadentry(void*);
 
@@ -41,7 +42,7 @@ _cgo_sys_thread_start(ThreadStart *ts)
 	pthread_attr_getstacksize(&attr, &size);
 	// Leave stacklo=0 and set stackhi=size; mstack will do the rest.
 	ts->g->stackhi = size;
-	err = pthread_create(&p, &attr, threadentry, ts);
+	err = _cgo_try_pthread_create(&p, &attr, threadentry, ts);
 
 	pthread_sigmask(SIG_SETMASK, &oset, nil);
 
diff --git a/src/runtime/cgo/gcc_mipsx.S b/src/runtime/cgo/gcc_mipsx.S
new file mode 100644
index 0000000..c51c36a
--- /dev/null
+++ b/src/runtime/cgo/gcc_mipsx.S
@@ -0,0 +1,68 @@
+// 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.
+
+// +build mips mipsle
+
+/*
+ * void crosscall1(void (*fn)(void), void (*setg_gcc)(void *g), void *g)
+ *
+ * Calling into the gc tool chain, where all registers are caller save.
+ * Called from standard MIPS O32 ABI, where $16-$23, $30, and $f20-$f31
+ * are callee-save, so they must be saved explicitly, along with $31 (LR).
+ */
+.globl crosscall1
+.set noat
+crosscall1:
+	addiu	$29, $29, -88
+
+	sw	$31, 0($29)
+	sw	$16, 4($29)
+	sw	$17, 8($29)
+	sw	$18, 12($29)
+	sw	$19, 16($29)
+	sw	$20, 20($29)
+	sw	$21, 24($29)
+	sw	$22, 28($29)
+	sw	$23, 32($29)
+	sw	$30, 36($29)
+
+	sdc1	$f20, 40($29)
+	sdc1	$f22, 48($29)
+	sdc1	$f24, 56($29)
+	sdc1	$f26, 64($29)
+	sdc1	$f28, 72($29)
+	sdc1	$f30, 80($29)
+
+
+	move	$20, $4 // save R4
+	move	$4, $6
+	jalr	$5	// call setg_gcc
+	jalr	$20	// call fn
+
+	lw	$16, 4($29)
+	lw	$17, 8($29)
+	lw	$18, 12($29)
+	lw	$19, 16($29)
+	lw	$20, 20($29)
+	lw	$21, 24($29)
+	lw	$22, 28($29)
+	lw	$23, 32($29)
+	lw	$30, 36($29)
+	ldc1	$f20, 40($29)
+	ldc1	$f22, 48($29)
+	ldc1	$f24, 56($29)
+	ldc1	$f26, 64($29)
+	ldc1	$f28, 72($29)
+	ldc1	$f30, 80($29)
+
+	lw	$31, 0($29)
+
+	addiu	$29, $29, 88
+	jr	$31
+
+.set at
+
+#ifdef __ELF__
+.section .note.GNU-stack,"",%progbits
+#endif
diff --git a/src/runtime/cgo/gcc_netbsd_386.c b/src/runtime/cgo/gcc_netbsd_386.c
index 99558ea..fb317c1 100644
--- a/src/runtime/cgo/gcc_netbsd_386.c
+++ b/src/runtime/cgo/gcc_netbsd_386.c
@@ -7,6 +7,7 @@
 #include <signal.h>
 #include <string.h>
 #include "libcgo.h"
+#include "libcgo_unix.h"
 
 static void* threadentry(void*);
 static void (*setg_gcc)(void*);
@@ -41,7 +42,7 @@ _cgo_sys_thread_start(ThreadStart *ts)
 	pthread_attr_getstacksize(&attr, &size);
 	// Leave stacklo=0 and set stackhi=size; mstack will do the rest.
 	ts->g->stackhi = size;
-	err = pthread_create(&p, &attr, threadentry, ts);
+	err = _cgo_try_pthread_create(&p, &attr, threadentry, ts);
 
 	pthread_sigmask(SIG_SETMASK, &oset, nil);
 
diff --git a/src/runtime/cgo/gcc_netbsd_amd64.c b/src/runtime/cgo/gcc_netbsd_amd64.c
index f5c8b1e..77a553f 100644
--- a/src/runtime/cgo/gcc_netbsd_amd64.c
+++ b/src/runtime/cgo/gcc_netbsd_amd64.c
@@ -7,6 +7,7 @@
 #include <signal.h>
 #include <string.h>
 #include "libcgo.h"
+#include "libcgo_unix.h"
 
 static void* threadentry(void*);
 static void (*setg_gcc)(void*);
@@ -42,7 +43,7 @@ _cgo_sys_thread_start(ThreadStart *ts)
 
 	// Leave stacklo=0 and set stackhi=size; mstack will do the rest.
 	ts->g->stackhi = size;
-	err = pthread_create(&p, &attr, threadentry, ts);
+	err = _cgo_try_pthread_create(&p, &attr, threadentry, ts);
 
 	pthread_sigmask(SIG_SETMASK, &oset, nil);
 
diff --git a/src/runtime/cgo/gcc_netbsd_arm.c b/src/runtime/cgo/gcc_netbsd_arm.c
index 97ce908..672f49c 100644
--- a/src/runtime/cgo/gcc_netbsd_arm.c
+++ b/src/runtime/cgo/gcc_netbsd_arm.c
@@ -7,6 +7,7 @@
 #include <signal.h>
 #include <string.h>
 #include "libcgo.h"
+#include "libcgo_unix.h"
 
 static void *threadentry(void*);
 
@@ -42,7 +43,7 @@ _cgo_sys_thread_start(ThreadStart *ts)
 	pthread_attr_getstacksize(&attr, &size);
 	// Leave stacklo=0 and set stackhi=size; mstack will do the rest.
 	ts->g->stackhi = size;
-	err = pthread_create(&p, &attr, threadentry, ts);
+	err = _cgo_try_pthread_create(&p, &attr, threadentry, ts);
 
 	pthread_sigmask(SIG_SETMASK, &oset, nil);
 
diff --git a/src/runtime/cgo/gcc_openbsd_386.c b/src/runtime/cgo/gcc_openbsd_386.c
index 1bc61ff..0cac047 100644
--- a/src/runtime/cgo/gcc_openbsd_386.c
+++ b/src/runtime/cgo/gcc_openbsd_386.c
@@ -9,6 +9,7 @@
 #include <signal.h>
 #include <string.h>
 #include "libcgo.h"
+#include "libcgo_unix.h"
 
 static void* threadentry(void*);
 static void (*setg_gcc)(void*);
@@ -170,7 +171,7 @@ _cgo_sys_thread_start(ThreadStart *ts)
 
 	// Leave stacklo=0 and set stackhi=size; mstack will do the rest.
 	ts->g->stackhi = size;
-	err = sys_pthread_create(&p, &attr, threadentry, ts);
+	err = _cgo_openbsd_try_pthread_create(sys_pthread_create, &p, &attr, threadentry, ts);
 
 	pthread_sigmask(SIG_SETMASK, &oset, nil);
 
diff --git a/src/runtime/cgo/gcc_openbsd_amd64.c b/src/runtime/cgo/gcc_openbsd_amd64.c
index 4d4d143..86a9185 100644
--- a/src/runtime/cgo/gcc_openbsd_amd64.c
+++ b/src/runtime/cgo/gcc_openbsd_amd64.c
@@ -9,6 +9,7 @@
 #include <signal.h>
 #include <string.h>
 #include "libcgo.h"
+#include "libcgo_unix.h"
 
 static void* threadentry(void*);
 static void (*setg_gcc)(void*);
@@ -170,7 +171,7 @@ _cgo_sys_thread_start(ThreadStart *ts)
 
 	// Leave stacklo=0 and set stackhi=size; mstack will do the rest.
 	ts->g->stackhi = size;
-	err = sys_pthread_create(&p, &attr, threadentry, ts);
+	err = _cgo_openbsd_try_pthread_create(sys_pthread_create, &p, &attr, threadentry, ts);
 
 	pthread_sigmask(SIG_SETMASK, &oset, nil);
 
diff --git a/src/runtime/cgo/gcc_signal_darwin_armx.c b/src/runtime/cgo/gcc_signal_darwin_armx.c
index 02c54d8..a2d520b 100644
--- a/src/runtime/cgo/gcc_signal_darwin_armx.c
+++ b/src/runtime/cgo/gcc_signal_darwin_armx.c
@@ -37,6 +37,7 @@
 #include <mach/thread_status.h>
 
 #include "libcgo.h"
+#include "libcgo_unix.h"
 
 uintptr_t x_cgo_panicmem;
 
@@ -201,7 +202,7 @@ darwin_arm_init_mach_exception_handler()
 	uintptr_t port_set = (uintptr_t)mach_exception_handler_port_set;
 	pthread_attr_init(&attr);
 	pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
-	ret = pthread_create(&thr, &attr, mach_exception_handler, (void*)port_set);
+	ret = _cgo_try_pthread_create(&thr, &attr, mach_exception_handler, (void*)port_set);
 
 	pthread_sigmask(SIG_SETMASK, &oset, nil);
 
diff --git a/src/runtime/cgo/gcc_solaris_amd64.c b/src/runtime/cgo/gcc_solaris_amd64.c
index 98a1a8b..079bd12 100644
--- a/src/runtime/cgo/gcc_solaris_amd64.c
+++ b/src/runtime/cgo/gcc_solaris_amd64.c
@@ -7,6 +7,7 @@
 #include <signal.h>
 #include <ucontext.h>
 #include "libcgo.h"
+#include "libcgo_unix.h"
 
 static void* threadentry(void*);
 static void (*setg_gcc)(void*);
@@ -53,7 +54,7 @@ _cgo_sys_thread_start(ThreadStart *ts)
 		ts->g->stackhi = size;
 	}
 	pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
-	err = pthread_create(&p, &attr, threadentry, ts);
+	err = _cgo_try_pthread_create(&p, &attr, threadentry, ts);
 
 	pthread_sigmask(SIG_SETMASK, &oset, nil);
 
diff --git a/src/runtime/cgo/libcgo_unix.h b/src/runtime/cgo/libcgo_unix.h
new file mode 100644
index 0000000..a56a366
--- /dev/null
+++ b/src/runtime/cgo/libcgo_unix.h
@@ -0,0 +1,15 @@
+// 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.
+
+/*
+ * Call pthread_create, retrying on EAGAIN.
+ */
+extern int _cgo_try_pthread_create(pthread_t*, const pthread_attr_t*, void* (*)(void*), void*);
+
+/*
+ * Same as _cgo_try_pthread_create, but passing on the pthread_create function.
+ * Only defined on OpenBSD.
+ */
+extern int _cgo_openbsd_try_pthread_create(int (*)(pthread_t*, const pthread_attr_t*, void *(*pfn)(void*), void*),
+	pthread_t*, const pthread_attr_t*, void* (*)(void*), void* arg);
diff --git a/src/runtime/cgocall.go b/src/runtime/cgocall.go
index 007406b..69e29ef 100644
--- a/src/runtime/cgocall.go
+++ b/src/runtime/cgocall.go
@@ -286,6 +286,10 @@ func cgocallbackg1(ctxt uintptr) {
 		// On mips64x, stack frame is two words and there's a saved LR between
 		// SP and the stack frame and between the stack frame and the arguments.
 		cb = (*args)(unsafe.Pointer(sp + 4*sys.PtrSize))
+	case "mips", "mipsle":
+		// On mipsx, stack frame is two words and there's a saved LR between
+		// SP and the stack frame and between the stack frame and the arguments.
+		cb = (*args)(unsafe.Pointer(sp + 4*sys.PtrSize))
 	}
 
 	// Invoke callback.
@@ -323,7 +327,7 @@ func unwindm(restore *bool) {
 	switch GOARCH {
 	default:
 		throw("unwindm not implemented")
-	case "386", "amd64", "arm", "ppc64", "ppc64le", "mips64", "mips64le", "s390x":
+	case "386", "amd64", "arm", "ppc64", "ppc64le", "mips64", "mips64le", "s390x", "mips", "mipsle":
 		sched.sp = *(*uintptr)(unsafe.Pointer(sched.sp + sys.MinFrameSize))
 	case "arm64":
 		sched.sp = *(*uintptr)(unsafe.Pointer(sched.sp + 16))
diff --git a/src/runtime/crash_cgo_test.go b/src/runtime/crash_cgo_test.go
index 7014f11..347b820 100644
--- a/src/runtime/crash_cgo_test.go
+++ b/src/runtime/crash_cgo_test.go
@@ -49,8 +49,6 @@ func TestCgoCallbackGC(t *testing.T) {
 	switch runtime.GOOS {
 	case "plan9", "windows":
 		t.Skipf("no pthreads on %s", runtime.GOOS)
-	case "freebsd":
-		testenv.SkipFlaky(t, 16396)
 	}
 	if testing.Short() {
 		switch {
diff --git a/src/runtime/iface.go b/src/runtime/iface.go
index c932e14..18f5c58 100644
--- a/src/runtime/iface.go
+++ b/src/runtime/iface.go
@@ -179,7 +179,7 @@ func panicnildottype(want *_type) {
 
 // The conv and assert functions below do very similar things.
 // The convXXX functions are guaranteed by the compiler to succeed.
-// The assertXXX functions may fail (either panicing or returning false,
+// The assertXXX functions may fail (either panicking or returning false,
 // depending on whether they are 1-result or 2-result).
 // The convXXX functions succeed on a nil input, whereas the assertXXX
 // functions fail on a nil input.
diff --git a/src/runtime/malloc_test.go b/src/runtime/malloc_test.go
index 767b51f..0cf9cfb 100644
--- a/src/runtime/malloc_test.go
+++ b/src/runtime/malloc_test.go
@@ -13,6 +13,9 @@ import (
 )
 
 func TestMemStats(t *testing.T) {
+	// Make sure there's at least one forced GC.
+	GC()
+
 	// Test that MemStats has sane values.
 	st := new(MemStats)
 	ReadMemStats(st)
@@ -24,7 +27,7 @@ func TestMemStats(t *testing.T) {
 		st.HeapInuse == 0 || st.HeapObjects == 0 || st.StackInuse == 0 ||
 		st.StackSys == 0 || st.MSpanInuse == 0 || st.MSpanSys == 0 || st.MCacheInuse == 0 ||
 		st.MCacheSys == 0 || st.BuckHashSys == 0 || st.GCSys == 0 || st.OtherSys == 0 ||
-		st.NextGC == 0 {
+		st.NextGC == 0 || st.NumForcedGC == 0 {
 		t.Fatalf("Zero value: %+v", *st)
 	}
 
@@ -33,7 +36,7 @@ func TestMemStats(t *testing.T) {
 		st.HeapIdle > 1e10 || st.HeapInuse > 1e10 || st.HeapObjects > 1e10 || st.StackInuse > 1e10 ||
 		st.StackSys > 1e10 || st.MSpanInuse > 1e10 || st.MSpanSys > 1e10 || st.MCacheInuse > 1e10 ||
 		st.MCacheSys > 1e10 || st.BuckHashSys > 1e10 || st.GCSys > 1e10 || st.OtherSys > 1e10 ||
-		st.NextGC > 1e10 || st.NumGC > 1e9 || st.PauseTotalNs > 1e11 {
+		st.NextGC > 1e10 || st.NumGC > 1e9 || st.NumForcedGC > 1e9 || st.PauseTotalNs > 1e11 {
 		t.Fatalf("Insanely high value (overflow?): %+v", *st)
 	}
 
@@ -72,6 +75,10 @@ func TestMemStats(t *testing.T) {
 			t.Fatalf("PauseTotalNs(%d) < sum PauseNs(%d)", st.PauseTotalNs, pauseTotal)
 		}
 	}
+
+	if st.NumForcedGC > st.NumGC {
+		t.Fatalf("NumForcedGC(%d) > NumGC(%d)", st.NumForcedGC, st.NumGC)
+	}
 }
 
 func TestStringConcatenationAllocs(t *testing.T) {
diff --git a/src/runtime/mgc.go b/src/runtime/mgc.go
index cc79d4c..0f0b096 100644
--- a/src/runtime/mgc.go
+++ b/src/runtime/mgc.go
@@ -902,7 +902,7 @@ type gcMode int
 const (
 	gcBackgroundMode gcMode = iota // concurrent GC and sweep
 	gcForceMode                    // stop-the-world GC now, concurrent sweep
-	gcForceBlockMode               // stop-the-world GC now and STW sweep
+	gcForceBlockMode               // stop-the-world GC now and STW sweep (forced by user)
 )
 
 // gcShouldStart returns true if the exit condition for the _GCoff
@@ -966,6 +966,9 @@ func gcStart(mode gcMode, forceTrigger bool) {
 		}
 	}
 
+	// For stats, check if this GC was forced by the user.
+	forced := mode != gcBackgroundMode
+
 	// In gcstoptheworld debug mode, upgrade the mode accordingly.
 	// We do this after re-checking the transition condition so
 	// that multiple goroutines that detect the heap trigger don't
@@ -1070,6 +1073,10 @@ func gcStart(mode gcMode, forceTrigger bool) {
 		work.tMark, work.tMarkTerm = t, t
 		work.heapGoal = work.heap0
 
+		if forced {
+			memstats.numforcedgc++
+		}
+
 		// Perform mark termination. This will restart the world.
 		gcMarkTermination()
 	}
diff --git a/src/runtime/mstats.go b/src/runtime/mstats.go
index b80ab11..4e111a1 100644
--- a/src/runtime/mstats.go
+++ b/src/runtime/mstats.go
@@ -77,6 +77,7 @@ type mstats struct {
 	pause_ns        [256]uint64 // circular buffer of recent gc pause lengths
 	pause_end       [256]uint64 // circular buffer of recent gc end times (nanoseconds since 1970)
 	numgc           uint32
+	numforcedgc     uint32  // number of user-forced GCs
 	gc_cpu_fraction float64 // fraction of CPU time used by GC
 	enablegc        bool
 	debuggc         bool
@@ -100,8 +101,6 @@ type mstats struct {
 	// must be complete.
 	gc_trigger uint64
 
-	_ uint32 // force 8-byte alignment of heap_live and prevent an alignment check crash on MIPS32.
-
 	// heap_live is the number of bytes considered live by the GC.
 	// That is: retained by the most recent GC plus allocated
 	// since then. heap_live <= heap_alloc, since heap_alloc
@@ -365,6 +364,10 @@ type MemStats struct {
 	// NumGC is the number of completed GC cycles.
 	NumGC uint32
 
+	// NumForcedGC is the number of GC cycles that were forced by
+	// the application calling the GC function.
+	NumForcedGC uint32
+
 	// GCCPUFraction is the fraction of this program's available
 	// CPU time used by the GC since the program started.
 	//
diff --git a/src/runtime/os_windows.go b/src/runtime/os_windows.go
index 0db57f8..10cab90 100644
--- a/src/runtime/os_windows.go
+++ b/src/runtime/os_windows.go
@@ -510,7 +510,7 @@ func semacreate(mp *m) {
 // May run with m.p==nil, so write barriers are not allowed. This
 // function is called by newosproc0, so it is also required to
 // operate without stack guards.
-//go:nowritebarrierc
+//go:nowritebarrierrec
 //go:nosplit
 func newosproc(mp *m, stk unsafe.Pointer) {
 	const _STACK_SIZE_PARAM_IS_A_RESERVATION = 0x00010000
@@ -527,7 +527,7 @@ func newosproc(mp *m, stk unsafe.Pointer) {
 // Used by the C library build mode. On Linux this function would allocate a
 // stack, but that's not necessary for Windows. No stack guards are present
 // and the GC has not been initialized, so write barriers will fail.
-//go:nowritebarrierc
+//go:nowritebarrierrec
 //go:nosplit
 func newosproc0(mp *m, stk unsafe.Pointer) {
 	newosproc(mp, stk)
diff --git a/src/runtime/panic.go b/src/runtime/panic.go
index 7392436..876bca7 100644
--- a/src/runtime/panic.go
+++ b/src/runtime/panic.go
@@ -646,7 +646,7 @@ func startpanic_m() {
 		freezetheworld()
 		return
 	case 1:
-		// Something failed while panicing, probably the print of the
+		// Something failed while panicking, probably the print of the
 		// argument to panic().  Just print a stack trace and exit.
 		_g_.m.dying = 2
 		print("panic during panic\n")
diff --git a/src/runtime/plugin.go b/src/runtime/plugin.go
index 845bf76..80869e1 100644
--- a/src/runtime/plugin.go
+++ b/src/runtime/plugin.go
@@ -51,6 +51,9 @@ func plugin_lastmoduleinit() (path string, syms map[string]interface{}, mismatch
 	modulesinit()
 	typelinksinit()
 
+	pluginftabverify(md)
+	moduledataverify1(md)
+
 	lock(&ifaceLock)
 	for _, i := range md.itablinks {
 		additab(i, true, false)
@@ -82,6 +85,35 @@ func plugin_lastmoduleinit() (path string, syms map[string]interface{}, mismatch
 	return md.pluginpath, syms, ""
 }
 
+func pluginftabverify(md *moduledata) {
+	badtable := false
+	for i := 0; i < len(md.ftab); i++ {
+		entry := md.ftab[i].entry
+		if md.minpc <= entry && entry <= md.maxpc {
+			continue
+		}
+
+		f := (*_func)(unsafe.Pointer(&md.pclntable[md.ftab[i].funcoff]))
+		name := funcname(f)
+
+		// A common bug is f.entry has a relocation to a duplicate
+		// function symbol, meaning if we search for its PC we get
+		// a valid entry with a name that is useful for debugging.
+		name2 := "none"
+		entry2 := uintptr(0)
+		f2 := findfunc(entry)
+		if f2 != nil {
+			name2 = funcname(f2)
+			entry2 = f2.entry
+		}
+		badtable = true
+		println("ftab entry outside pc range: ", hex(entry), "/", hex(entry2), ": ", name, "/", name2)
+	}
+	if badtable {
+		throw("runtime: plugin has bad symbol table")
+	}
+}
+
 // inRange reports whether v0 or v1 are in the range [r0, r1].
 func inRange(r0, r1, v0, v1 uintptr) bool {
 	return (v0 >= r0 && v0 <= r1) || (v1 >= r0 && v1 <= r1)
diff --git a/src/runtime/pprof/pprof.go b/src/runtime/pprof/pprof.go
index aed5b8d..871fba0 100644
--- a/src/runtime/pprof/pprof.go
+++ b/src/runtime/pprof/pprof.go
@@ -386,12 +386,22 @@ func printCountProfile(w io.Writer, debug int, name string, p countProfile) erro
 		Sample:     make([]*profile.Sample, 0, len(keys)),
 		SampleType: []*profile.ValueType{{Type: name, Unit: "count"}},
 	}
+	locMap := make(map[uintptr]*profile.Location)
 	for _, k := range keys {
 		stk := p.Stack(index[k])
 		c := count[k]
 		locs := make([]*profile.Location, len(stk))
 		for i, addr := range stk {
-			locs[i] = &profile.Location{Address: uint64(addr) - 1}
+			loc := locMap[addr]
+			if loc == nil {
+				loc = &profile.Location{
+					ID:      uint64(len(locMap) + 1),
+					Address: uint64(addr - 1),
+				}
+				prof.Location = append(prof.Location, loc)
+				locMap[addr] = loc
+			}
+			locs[i] = loc
 		}
 		prof.Sample = append(prof.Sample, &profile.Sample{
 			Location: locs,
diff --git a/src/runtime/rt0_linux_mipsx.s b/src/runtime/rt0_linux_mipsx.s
index 5e8c5c3..9a2e561 100644
--- a/src/runtime/rt0_linux_mipsx.s
+++ b/src/runtime/rt0_linux_mipsx.s
@@ -18,10 +18,11 @@ TEXT _main<>(SB),NOSPLIT,$-4
 	// argv as argc string pointers followed by a NULL, envv as a
 	// sequence of string pointers followed by a NULL, and auxv.
 	// There is no TLS base pointer.
-	MOVW	0(R29), R1	// argc
-	ADD	$4, R29, R2	// argv
+	MOVW	0(R29), R4 // argc
+	ADD	$4, R29, R5 // argv
 	JMP	main(SB)
 
 TEXT main(SB),NOSPLIT,$-4
-	MOVW	$runtime·rt0_go(SB), R4
-	JMP	(R4)
+        // In external linking, libc jumps to main with argc in R4, argv in R5
+	MOVW	$runtime·rt0_go(SB), R1
+	JMP	(R1)
diff --git a/src/runtime/runtime-gdb_test.go b/src/runtime/runtime-gdb_test.go
index 94ba879..c284437 100644
--- a/src/runtime/runtime-gdb_test.go
+++ b/src/runtime/runtime-gdb_test.go
@@ -85,6 +85,10 @@ func main() {
 `
 
 func TestGdbPython(t *testing.T) {
+	if runtime.GOARCH == "mips64" {
+		testenv.SkipFlaky(t, 18173)
+	}
+
 	t.Parallel()
 	checkGdbEnvironment(t)
 	checkGdbVersion(t)
@@ -220,13 +224,16 @@ func main() {
 // TestGdbBacktrace tests that gdb can unwind the stack correctly
 // using only the DWARF debug info.
 func TestGdbBacktrace(t *testing.T) {
-	t.Parallel()
-	checkGdbEnvironment(t)
-	checkGdbVersion(t)
-
 	if runtime.GOOS == "netbsd" {
 		testenv.SkipFlaky(t, 15603)
 	}
+	if runtime.GOARCH == "mips64" {
+		testenv.SkipFlaky(t, 18173)
+	}
+
+	t.Parallel()
+	checkGdbEnvironment(t)
+	checkGdbVersion(t)
 
 	dir, err := ioutil.TempDir("", "go-build")
 	if err != nil {
@@ -294,6 +301,10 @@ func main() {
 // TestGdbAutotmpTypes ensures that types of autotmp variables appear in .debug_info
 // See bug #17830.
 func TestGdbAutotmpTypes(t *testing.T) {
+	if runtime.GOARCH == "mips64" {
+		testenv.SkipFlaky(t, 18173)
+	}
+
 	t.Parallel()
 	checkGdbEnvironment(t)
 	checkGdbVersion(t)
diff --git a/src/runtime/runtime_test.go b/src/runtime/runtime_test.go
index cd078c7..9febbe6 100644
--- a/src/runtime/runtime_test.go
+++ b/src/runtime/runtime_test.go
@@ -8,6 +8,7 @@ import (
 	"io"
 	. "runtime"
 	"runtime/debug"
+	"strings"
 	"testing"
 	"unsafe"
 )
@@ -329,3 +330,11 @@ func TestGoroutineProfileTrivial(t *testing.T) {
 		}
 	}
 }
+
+func TestVersion(t *testing.T) {
+	// Test that version does not contain \r or \n.
+	vers := Version()
+	if strings.Contains(vers, "\r") || strings.Contains(vers, "\n") {
+		t.Fatalf("cr/nl in version: %q", vers)
+	}
+}
diff --git a/src/runtime/signal_unix.go b/src/runtime/signal_unix.go
index 78381e5..49c7579 100644
--- a/src/runtime/signal_unix.go
+++ b/src/runtime/signal_unix.go
@@ -111,8 +111,8 @@ func sigInstallGoHandler(sig uint32) bool {
 	}
 
 	// When built using c-archive or c-shared, only install signal
-	// handlers for synchronous signals and SIGPIPE.
-	if (isarchive || islibrary) && t.flags&_SigPanic == 0 && sig != _SIGPIPE {
+	// handlers for synchronous signals.
+	if (isarchive || islibrary) && t.flags&_SigPanic == 0 {
 		return false
 	}
 
@@ -212,25 +212,43 @@ func sigtrampgo(sig uint32, info *siginfo, ctx unsafe.Pointer) {
 	}
 
 	// If some non-Go code called sigaltstack, adjust.
+	setStack := false
+	var gsignalStack gsignalStack
 	sp := uintptr(unsafe.Pointer(&sig))
 	if sp < g.m.gsignal.stack.lo || sp >= g.m.gsignal.stack.hi {
-		var st stackt
-		sigaltstack(nil, &st)
-		if st.ss_flags&_SS_DISABLE != 0 {
-			setg(nil)
-			needm(0)
-			noSignalStack(sig)
-			dropm()
-		}
-		stsp := uintptr(unsafe.Pointer(st.ss_sp))
-		if sp < stsp || sp >= stsp+st.ss_size {
-			setg(nil)
-			needm(0)
-			sigNotOnStack(sig)
-			dropm()
+		if sp >= g.m.g0.stack.lo && sp < g.m.g0.stack.hi {
+			// The signal was delivered on the g0 stack.
+			// This can happen when linked with C code
+			// using the thread sanitizer, which collects
+			// signals then delivers them itself by calling
+			// the signal handler directly when C code,
+			// including C code called via cgo, calls a
+			// TSAN-intercepted function such as malloc.
+			st := stackt{ss_size: g.m.g0.stack.hi - g.m.g0.stack.lo}
+			setSignalstackSP(&st, g.m.g0.stack.lo)
+			setGsignalStack(&st, &gsignalStack)
+			g.m.gsignal.stktopsp = getcallersp(unsafe.Pointer(&sig))
+			setStack = true
+		} else {
+			var st stackt
+			sigaltstack(nil, &st)
+			if st.ss_flags&_SS_DISABLE != 0 {
+				setg(nil)
+				needm(0)
+				noSignalStack(sig)
+				dropm()
+			}
+			stsp := uintptr(unsafe.Pointer(st.ss_sp))
+			if sp < stsp || sp >= stsp+st.ss_size {
+				setg(nil)
+				needm(0)
+				sigNotOnStack(sig)
+				dropm()
+			}
+			setGsignalStack(&st, &gsignalStack)
+			g.m.gsignal.stktopsp = getcallersp(unsafe.Pointer(&sig))
+			setStack = true
 		}
-		setGsignalStack(&st)
-		g.m.gsignal.stktopsp = getcallersp(unsafe.Pointer(&sig))
 	}
 
 	setg(g.m.gsignal)
@@ -238,6 +256,9 @@ func sigtrampgo(sig uint32, info *siginfo, ctx unsafe.Pointer) {
 	c.fixsigcode(sig)
 	sighandler(sig, info, ctx, g)
 	setg(g)
+	if setStack {
+		restoreGsignalStack(&gsignalStack)
+	}
 }
 
 // sigpanic turns a synchronous signal into a run-time panic.
@@ -497,15 +518,9 @@ func sigfwdgo(sig uint32, info *siginfo, ctx unsafe.Pointer) bool {
 		return true
 	}
 
+	// Only forward synchronous signals.
 	c := &sigctxt{info, ctx}
-	// Only forward signals from the kernel.
-	// On Linux and Darwin there is no way to distinguish a SIGPIPE raised by a write
-	// to a closed socket or pipe from a SIGPIPE raised by kill or pthread_kill
-	// so we'll treat every SIGPIPE as kernel-generated.
-	userSig := c.sigcode() == _SI_USER &&
-		(sig != _SIGPIPE || GOOS != "linux" && GOOS != "android" && GOOS != "darwin")
-	// Only forward synchronous signals and SIGPIPE.
-	if userSig || flags&_SigPanic == 0 && sig != _SIGPIPE {
+	if c.sigcode() == _SI_USER || flags&_SigPanic == 0 {
 		return false
 	}
 	// Determine if the signal occurred inside Go code. We test that:
@@ -591,7 +606,7 @@ func minitSignalStack() {
 		signalstack(&_g_.m.gsignal.stack)
 		_g_.m.newSigstack = true
 	} else {
-		setGsignalStack(&st)
+		setGsignalStack(&st, nil)
 		_g_.m.newSigstack = false
 	}
 }
@@ -624,14 +639,32 @@ func unminitSignals() {
 	}
 }
 
+// gsignalStack saves the fields of the gsignal stack changed by
+// setGsignalStack.
+type gsignalStack struct {
+	stack       stack
+	stackguard0 uintptr
+	stackguard1 uintptr
+	stackAlloc  uintptr
+	stktopsp    uintptr
+}
+
 // setGsignalStack sets the gsignal stack of the current m to an
 // alternate signal stack returned from the sigaltstack system call.
+// It saves the old values in *old for use by restoreGsignalStack.
 // This is used when handling a signal if non-Go code has set the
 // alternate signal stack.
 //go:nosplit
 //go:nowritebarrierrec
-func setGsignalStack(st *stackt) {
+func setGsignalStack(st *stackt, old *gsignalStack) {
 	g := getg()
+	if old != nil {
+		old.stack = g.m.gsignal.stack
+		old.stackguard0 = g.m.gsignal.stackguard0
+		old.stackguard1 = g.m.gsignal.stackguard1
+		old.stackAlloc = g.m.gsignal.stackAlloc
+		old.stktopsp = g.m.gsignal.stktopsp
+	}
 	stsp := uintptr(unsafe.Pointer(st.ss_sp))
 	g.m.gsignal.stack.lo = stsp
 	g.m.gsignal.stack.hi = stsp + st.ss_size
@@ -640,6 +673,19 @@ func setGsignalStack(st *stackt) {
 	g.m.gsignal.stackAlloc = st.ss_size
 }
 
+// restoreGsignalStack restores the gsignal stack to the value it had
+// before entering the signal handler.
+//go:nosplit
+//go:nowritebarrierrec
+func restoreGsignalStack(st *gsignalStack) {
+	gp := getg().m.gsignal
+	gp.stack = st.stack
+	gp.stackguard0 = st.stackguard0
+	gp.stackguard1 = st.stackguard1
+	gp.stackAlloc = st.stackAlloc
+	gp.stktopsp = st.stktopsp
+}
+
 // signalstack sets the current thread's alternate signal stack to s.
 //go:nosplit
 func signalstack(s *stack) {
diff --git a/src/runtime/stack.go b/src/runtime/stack.go
index ea9a69a..b77a311 100644
--- a/src/runtime/stack.go
+++ b/src/runtime/stack.go
@@ -123,6 +123,9 @@ const (
 	stackPoisonCopy  = 0 // fill stack that should not be accessed with garbage, to detect bad dereferences during copy
 
 	stackCache = 1
+
+	// check the BP links during traceback.
+	debugCheckBP = false
 )
 
 const (
@@ -688,6 +691,16 @@ func adjustframe(frame *stkframe, arg unsafe.Pointer) bool {
 		if stackDebug >= 3 {
 			print("      saved bp\n")
 		}
+		if debugCheckBP {
+			// Frame pointers should always point to the next higher frame on
+			// the Go stack (or be nil, for the top frame on the stack).
+			bp := *(*uintptr)(unsafe.Pointer(frame.varp))
+			if bp != 0 && (bp < adjinfo.old.lo || bp >= adjinfo.old.hi) {
+				println("runtime: found invalid frame pointer")
+				print("bp=", hex(bp), " min=", hex(adjinfo.old.lo), " max=", hex(adjinfo.old.hi), "\n")
+				throw("bad frame pointer")
+			}
+		}
 		adjustpointer(adjinfo, unsafe.Pointer(frame.varp))
 	}
 
@@ -719,6 +732,18 @@ func adjustframe(frame *stkframe, arg unsafe.Pointer) bool {
 
 func adjustctxt(gp *g, adjinfo *adjustinfo) {
 	adjustpointer(adjinfo, unsafe.Pointer(&gp.sched.ctxt))
+	if !framepointer_enabled {
+		return
+	}
+	if debugCheckBP {
+		bp := gp.sched.bp
+		if bp != 0 && (bp < adjinfo.old.lo || bp >= adjinfo.old.hi) {
+			println("runtime: found invalid top frame pointer")
+			print("bp=", hex(bp), " min=", hex(adjinfo.old.lo), " max=", hex(adjinfo.old.hi), "\n")
+			throw("bad top frame pointer")
+		}
+	}
+	adjustpointer(adjinfo, unsafe.Pointer(&gp.sched.bp))
 }
 
 func adjustdefers(gp *g, adjinfo *adjustinfo) {
diff --git a/src/runtime/symtab.go b/src/runtime/symtab.go
index 8a5b0df..f521906 100644
--- a/src/runtime/symtab.go
+++ b/src/runtime/symtab.go
@@ -666,7 +666,7 @@ func readvarint(p []byte) (newp []byte, val uint32) {
 type stackmap struct {
 	n        int32   // number of bitmaps
 	nbit     int32   // number of bits in each bitmap
-	bytedata [1]byte // bitmaps, each starting on a 32-bit boundary
+	bytedata [1]byte // bitmaps, each starting on a byte boundary
 }
 
 //go:nowritebarrier
diff --git a/src/runtime/sys_openbsd_386.s b/src/runtime/sys_openbsd_386.s
index e969395..997c07f 100644
--- a/src/runtime/sys_openbsd_386.s
+++ b/src/runtime/sys_openbsd_386.s
@@ -79,14 +79,15 @@ TEXT runtime·usleep(SB),NOSPLIT,$24
 	INT	$0x80
 	RET
 
-TEXT runtime·raise(SB),NOSPLIT,$12
+TEXT runtime·raise(SB),NOSPLIT,$16
 	MOVL	$299, AX		// sys_getthrid
 	INT	$0x80
 	MOVL	$0, 0(SP)
-	MOVL	AX, 4(SP)		// arg 1 - pid
+	MOVL	AX, 4(SP)		// arg 1 - tid
 	MOVL	sig+0(FP), AX
 	MOVL	AX, 8(SP)		// arg 2 - signum
-	MOVL	$37, AX			// sys_kill
+	MOVL	$0, 12(SP)		// arg 3 - tcb
+	MOVL	$119, AX		// sys_thrkill
 	INT	$0x80
 	RET
 
@@ -97,7 +98,7 @@ TEXT runtime·raiseproc(SB),NOSPLIT,$12
 	MOVL	AX, 4(SP)		// arg 1 - pid
 	MOVL	sig+0(FP), AX
 	MOVL	AX, 8(SP)		// arg 2 - signum
-	MOVL	$37, AX			// sys_kill
+	MOVL	$122, AX		// sys_kill
 	INT	$0x80
 	RET
 
diff --git a/src/runtime/sys_openbsd_amd64.s b/src/runtime/sys_openbsd_amd64.s
index 01d6bd8..6ca5a81 100644
--- a/src/runtime/sys_openbsd_amd64.s
+++ b/src/runtime/sys_openbsd_amd64.s
@@ -156,9 +156,10 @@ TEXT runtime·usleep(SB),NOSPLIT,$16
 TEXT runtime·raise(SB),NOSPLIT,$16
 	MOVL	$299, AX		// sys_getthrid
 	SYSCALL
-	MOVQ	AX, DI			// arg 1 - pid
+	MOVQ	AX, DI			// arg 1 - tid
 	MOVL	sig+0(FP), SI		// arg 2 - signum
-	MOVL	$37, AX			// sys_kill
+	MOVQ	$0, DX			// arg 3 - tcb
+	MOVL	$119, AX		// sys_thrkill
 	SYSCALL
 	RET
 
@@ -167,7 +168,7 @@ TEXT runtime·raiseproc(SB),NOSPLIT,$16
 	SYSCALL
 	MOVQ	AX, DI			// arg 1 - pid
 	MOVL	sig+0(FP), SI		// arg 2 - signum
-	MOVL	$37, AX			// sys_kill
+	MOVL	$122, AX		// sys_kill
 	SYSCALL
 	RET
 
diff --git a/src/runtime/sys_openbsd_arm.s b/src/runtime/sys_openbsd_arm.s
index e0f775d..f573a02 100644
--- a/src/runtime/sys_openbsd_arm.s
+++ b/src/runtime/sys_openbsd_arm.s
@@ -87,9 +87,10 @@ TEXT runtime·usleep(SB),NOSPLIT,$16
 TEXT runtime·raise(SB),NOSPLIT,$12
 	MOVW	$0x12B, R12
 	SWI	$0			// sys_getthrid
-					// arg 1 - pid, already in R0
+					// arg 1 - tid, already in R0
 	MOVW	sig+0(FP), R1		// arg 2 - signum
-	MOVW	$37, R12		// sys_kill
+	MOVW	$0, R2			// arg 3 - tcb
+	MOVW	$119, R12		// sys_thrkill
 	SWI	$0
 	RET
 
@@ -98,7 +99,7 @@ TEXT runtime·raiseproc(SB),NOSPLIT,$12
 	SWI	$0			// sys_getpid
 					// arg 1 - pid, already in R0
 	MOVW	sig+0(FP), R1		// arg 2 - signum
-	MOVW	$37, R12		// sys_kill
+	MOVW	$122, R12		// sys_kill
 	SWI	$0
 	RET
 
diff --git a/src/runtime/tls_mipsx.s b/src/runtime/tls_mipsx.s
index 95fbc32..a2c01d2 100644
--- a/src/runtime/tls_mipsx.s
+++ b/src/runtime/tls_mipsx.s
@@ -10,12 +10,20 @@
 #include "textflag.h"
 
 // If !iscgo, this is a no-op.
+// NOTE: gogo asumes load_g only clobers g (R30) and REGTMP (R23)
 TEXT runtime·save_g(SB),NOSPLIT,$-4-0
 	MOVB	runtime·iscgo(SB), R23
 	BEQ	R23, nocgo
-	UNDEF
+
+	MOVW	R3, R23
+	MOVW	g, runtime·tls_g(SB) // TLS relocation clobbers R3
+	MOVW	R23, R3
+
 nocgo:
 	RET
 
 TEXT runtime·load_g(SB),NOSPLIT,$-4-0
+	MOVW	runtime·tls_g(SB), g // TLS relocation clobbers R3
 	RET
+
+GLOBL runtime·tls_g(SB), TLSBSS, $4
diff --git a/src/sort/example_test.go b/src/sort/example_test.go
index f7372be..980c0d0 100644
--- a/src/sort/example_test.go
+++ b/src/sort/example_test.go
@@ -22,3 +22,22 @@ func ExampleReverse() {
 	fmt.Println(s)
 	// Output: [6 5 4 3 2 1]
 }
+
+func ExampleSlice() {
+	people := []struct {
+		Name string
+		Age  int
+	}{
+		{"Gopher", 7},
+		{"Alice", 55},
+		{"Vera", 24},
+		{"Bob", 75},
+	}
+	sort.Slice(people, func(i, j int) bool { return people[i].Name < people[j].Name })
+	fmt.Println("By name:", people)
+
+	sort.Slice(people, func(i, j int) bool { return people[i].Age < people[j].Age })
+	fmt.Println("By age:", people)
+	// Output: By name: [{Alice 55} {Bob 75} {Gopher 7} {Vera 24}]
+	// By age: [{Gopher 7} {Vera 24} {Alice 55} {Bob 75}]
+}
diff --git a/src/syscall/zsysnum_openbsd_386.go b/src/syscall/zsysnum_openbsd_386.go
index c19f6de..c172534 100644
--- a/src/syscall/zsysnum_openbsd_386.go
+++ b/src/syscall/zsysnum_openbsd_386.go
@@ -41,7 +41,6 @@ const (
 	SYS_CHFLAGS        = 34  // { int sys_chflags(const char *path, u_int flags); }
 	SYS_FCHFLAGS       = 35  // { int sys_fchflags(int fd, u_int flags); }
 	SYS_SYNC           = 36  // { void sys_sync(void); }
-	SYS_KILL           = 37  // { int sys_kill(int pid, int signum); }
 	SYS_STAT           = 38  // { int sys_stat(const char *path, struct stat *ub); }
 	SYS_GETPPID        = 39  // { pid_t sys_getppid(void); }
 	SYS_LSTAT          = 40  // { int sys_lstat(const char *path, struct stat *ub); }
@@ -113,6 +112,7 @@ const (
 	SYS_READV          = 120 // { ssize_t sys_readv(int fd, \
 	SYS_WRITEV         = 121 // { ssize_t sys_writev(int fd, \
 	SYS_FCHOWN         = 123 // { int sys_fchown(int fd, uid_t uid, gid_t gid); }
+	SYS_KILL           = 122 // { int sys_kill(int pid, int signum); }
 	SYS_FCHMOD         = 124 // { int sys_fchmod(int fd, mode_t mode); }
 	SYS_SETREUID       = 126 // { int sys_setreuid(uid_t ruid, uid_t euid); }
 	SYS_SETREGID       = 127 // { int sys_setregid(gid_t rgid, gid_t egid); }
diff --git a/src/syscall/zsysnum_openbsd_amd64.go b/src/syscall/zsysnum_openbsd_amd64.go
index 86e04cd..356c187 100644
--- a/src/syscall/zsysnum_openbsd_amd64.go
+++ b/src/syscall/zsysnum_openbsd_amd64.go
@@ -41,7 +41,6 @@ const (
 	SYS_CHFLAGS        = 34  // { int sys_chflags(const char *path, u_int flags); }
 	SYS_FCHFLAGS       = 35  // { int sys_fchflags(int fd, u_int flags); }
 	SYS_SYNC           = 36  // { void sys_sync(void); }
-	SYS_KILL           = 37  // { int sys_kill(int pid, int signum); }
 	SYS_STAT           = 38  // { int sys_stat(const char *path, struct stat *ub); }
 	SYS_GETPPID        = 39  // { pid_t sys_getppid(void); }
 	SYS_LSTAT          = 40  // { int sys_lstat(const char *path, struct stat *ub); }
@@ -112,6 +111,7 @@ const (
 	SYS_GETSOCKOPT     = 118 // { int sys_getsockopt(int s, int level, int name, \
 	SYS_READV          = 120 // { ssize_t sys_readv(int fd, \
 	SYS_WRITEV         = 121 // { ssize_t sys_writev(int fd, \
+	SYS_KILL           = 122 // { int sys_kill(int pid, int signum); }
 	SYS_FCHOWN         = 123 // { int sys_fchown(int fd, uid_t uid, gid_t gid); }
 	SYS_FCHMOD         = 124 // { int sys_fchmod(int fd, mode_t mode); }
 	SYS_SETREUID       = 126 // { int sys_setreuid(uid_t ruid, uid_t euid); }
diff --git a/src/syscall/zsysnum_openbsd_arm.go b/src/syscall/zsysnum_openbsd_arm.go
index 38b43ca..3e6b984 100644
--- a/src/syscall/zsysnum_openbsd_arm.go
+++ b/src/syscall/zsysnum_openbsd_arm.go
@@ -42,7 +42,6 @@ const (
 	SYS_CHFLAGS        = 34  // { int sys_chflags(const char *path, u_int flags); }
 	SYS_FCHFLAGS       = 35  // { int sys_fchflags(int fd, u_int flags); }
 	SYS_SYNC           = 36  // { void sys_sync(void); }
-	SYS_KILL           = 37  // { int sys_kill(int pid, int signum); }
 	SYS_STAT           = 38  // { int sys_stat(const char *path, struct stat *ub); }
 	SYS_GETPPID        = 39  // { pid_t sys_getppid(void); }
 	SYS_LSTAT          = 40  // { int sys_lstat(const char *path, struct stat *ub); }
@@ -118,6 +117,7 @@ const (
 	SYS_GETSOCKOPT     = 118 // { int sys_getsockopt(int s, int level, int name, \
 	SYS_READV          = 120 // { ssize_t sys_readv(int fd, \
 	SYS_WRITEV         = 121 // { ssize_t sys_writev(int fd, \
+	SYS_KILL           = 122 // { int sys_kill(int pid, int signum); }
 	SYS_FCHOWN         = 123 // { int sys_fchown(int fd, uid_t uid, gid_t gid); }
 	SYS_FCHMOD         = 124 // { int sys_fchmod(int fd, mode_t mode); }
 	SYS_SETREUID       = 126 // { int sys_setreuid(uid_t ruid, uid_t euid); }
diff --git a/src/testing/benchmark.go b/src/testing/benchmark.go
index b1c6d2e..c033ce5 100644
--- a/src/testing/benchmark.go
+++ b/src/testing/benchmark.go
@@ -5,7 +5,6 @@
 package testing
 
 import (
-	"context"
 	"flag"
 	"fmt"
 	"internal/race"
@@ -128,9 +127,6 @@ func (b *B) nsPerOp() int64 {
 
 // runN runs a single benchmark for the specified number of iterations.
 func (b *B) runN(n int) {
-	b.ctx, b.cancel = context.WithCancel(b.parentContext())
-	defer b.cancel()
-
 	benchmarkLock.Lock()
 	defer benchmarkLock.Unlock()
 	// Try to get a comparable environment for each run
diff --git a/src/testing/sub_test.go b/src/testing/sub_test.go
index 563e865..2a24aaa 100644
--- a/src/testing/sub_test.go
+++ b/src/testing/sub_test.go
@@ -6,7 +6,6 @@ package testing
 
 import (
 	"bytes"
-	"context"
 	"regexp"
 	"strings"
 	"sync/atomic"
@@ -278,33 +277,28 @@ func TestTRun(t *T) {
 		ok:     true,
 		maxPar: 4,
 		f: func(t *T) {
-			// t.Parallel doesn't work in the pseudo-T we start with:
-			// it leaks a goroutine.
-			// Call t.Run to get a real one.
-			t.Run("X", func(t *T) {
-				t.Parallel()
-				for i := 0; i < 12; i++ {
-					t.Run("a", func(t *T) {
-						t.Parallel()
-						time.Sleep(time.Nanosecond)
-						for i := 0; i < 12; i++ {
-							t.Run("b", func(t *T) {
-								time.Sleep(time.Nanosecond)
-								for i := 0; i < 12; i++ {
-									t.Run("c", func(t *T) {
-										t.Parallel()
-										time.Sleep(time.Nanosecond)
-										t.Run("d1", func(t *T) {})
-										t.Run("d2", func(t *T) {})
-										t.Run("d3", func(t *T) {})
-										t.Run("d4", func(t *T) {})
-									})
-								}
-							})
-						}
-					})
-				}
-			})
+			t.Parallel()
+			for i := 0; i < 12; i++ {
+				t.Run("a", func(t *T) {
+					t.Parallel()
+					time.Sleep(time.Nanosecond)
+					for i := 0; i < 12; i++ {
+						t.Run("b", func(t *T) {
+							time.Sleep(time.Nanosecond)
+							for i := 0; i < 12; i++ {
+								t.Run("c", func(t *T) {
+									t.Parallel()
+									time.Sleep(time.Nanosecond)
+									t.Run("d1", func(t *T) {})
+									t.Run("d2", func(t *T) {})
+									t.Run("d3", func(t *T) {})
+									t.Run("d4", func(t *T) {})
+								})
+							}
+						})
+					}
+				})
+			}
 		},
 	}, {
 		desc:   "skip output",
@@ -347,7 +341,6 @@ func TestTRun(t *T) {
 			},
 			context: ctx,
 		}
-		root.ctx, root.cancel = context.WithCancel(context.Background())
 		ok := root.Run(tc.desc, tc.f)
 		ctx.release()
 
diff --git a/src/testing/testing.go b/src/testing/testing.go
index f08c5c6..8fb6d83 100644
--- a/src/testing/testing.go
+++ b/src/testing/testing.go
@@ -204,7 +204,6 @@ package testing
 
 import (
 	"bytes"
-	"context"
 	"errors"
 	"flag"
 	"fmt"
@@ -262,14 +261,12 @@ type common struct {
 	mu         sync.RWMutex // guards output, failed, and done.
 	output     []byte       // Output generated by test or benchmark.
 	w          io.Writer    // For flushToParent.
-	ctx        context.Context
-	cancel     context.CancelFunc
-	chatty     bool // A copy of the chatty flag.
-	ran        bool // Test or benchmark (or one of its subtests) was executed.
-	failed     bool // Test or benchmark has failed.
-	skipped    bool // Test of benchmark has been skipped.
-	finished   bool // Test function has completed.
-	done       bool // Test is finished and all subtests have completed.
+	chatty     bool         // A copy of the chatty flag.
+	ran        bool         // Test or benchmark (or one of its subtests) was executed.
+	failed     bool         // Test or benchmark has failed.
+	skipped    bool         // Test of benchmark has been skipped.
+	finished   bool         // Test function has completed.
+	done       bool         // Test is finished and all subtests have completed.
 	hasSub     bool
 	raceErrors int // number of races detected during test
 
@@ -283,13 +280,6 @@ type common struct {
 	sub      []*T      // Queue of subtests to be run in parallel.
 }
 
-func (c *common) parentContext() context.Context {
-	if c == nil || c.parent == nil || c.parent.ctx == nil {
-		return context.Background()
-	}
-	return c.parent.ctx
-}
-
 // Short reports whether the -test.short flag is set.
 func Short() bool {
 	return *short
@@ -386,7 +376,6 @@ func fmtDuration(d time.Duration) string {
 
 // TB is the interface common to T and B.
 type TB interface {
-	Context() context.Context
 	Error(args ...interface{})
 	Errorf(format string, args ...interface{})
 	Fail()
@@ -434,15 +423,6 @@ func (c *common) Name() string {
 	return c.name
 }
 
-// Context returns the context for the current test or benchmark.
-// The context is cancelled when the test or benchmark finishes.
-// A goroutine started during a test or benchmark can wait for the
-// context's Done channel to become readable as a signal that the
-// test or benchmark is over, so that the goroutine can exit.
-func (c *common) Context() context.Context {
-	return c.ctx
-}
-
 func (c *common) setRan() {
 	if c.parent != nil {
 		c.parent.setRan()
@@ -619,9 +599,6 @@ type InternalTest struct {
 }
 
 func tRunner(t *T, fn func(t *T)) {
-	t.ctx, t.cancel = context.WithCancel(t.parentContext())
-	defer t.cancel()
-
 	// When this goroutine is done, either because fn(t)
 	// returned normally or because a test failure triggered
 	// a call to runtime.Goexit, record the duration and send
diff --git a/src/testing/testing_test.go b/src/testing/testing_test.go
index 9954f9a..45e4468 100644
--- a/src/testing/testing_test.go
+++ b/src/testing/testing_test.go
@@ -5,42 +5,14 @@
 package testing_test
 
 import (
-	"fmt"
 	"os"
-	"runtime"
 	"testing"
-	"time"
 )
 
-func TestMain(m *testing.M) {
-	g0 := runtime.NumGoroutine()
-
-	code := m.Run()
-	if code != 0 {
-		os.Exit(code)
-	}
+// This is exactly what a test would do without a TestMain.
+// It's here only so that there is at least one package in the
+// standard library with a TestMain, so that code is executed.
 
-	// Check that there are no goroutines left behind.
-	t0 := time.Now()
-	stacks := make([]byte, 1<<20)
-	for {
-		g1 := runtime.NumGoroutine()
-		if g1 == g0 {
-			return
-		}
-		stacks = stacks[:runtime.Stack(stacks, true)]
-		time.Sleep(50 * time.Millisecond)
-		if time.Since(t0) > 2*time.Second {
-			fmt.Fprintf(os.Stderr, "Unexpected leftover goroutines detected: %v -> %v\n%s\n", g0, g1, stacks)
-			os.Exit(1)
-		}
-	}
-}
-
-func TestContextCancel(t *testing.T) {
-	ctx := t.Context()
-	// Tests we don't leak this goroutine:
-	go func() {
-		<-ctx.Done()
-	}()
+func TestMain(m *testing.M) {
+	os.Exit(m.Run())
 }
diff --git a/src/time/format.go b/src/time/format.go
index 3fbfa73..b903e14 100644
--- a/src/time/format.go
+++ b/src/time/format.go
@@ -1101,8 +1101,9 @@ func parseTimeZone(value string) (length int, ok bool) {
 		if value[4] == 'T' {
 			return 5, true
 		}
-	case 4: // Must end in T to match.
-		if value[3] == 'T' {
+	case 4:
+		// Must end in T, except one special case.
+		if value[3] == 'T' || value[:4] == "WITA" {
 			return 4, true
 		}
 	case 3:
diff --git a/src/time/format_test.go b/src/time/format_test.go
index aa4434a..219c2ca 100644
--- a/src/time/format_test.go
+++ b/src/time/format_test.go
@@ -405,6 +405,7 @@ var parseTimeZoneTests = []ParseTimeZoneTest{
 	{"ESAST hi", 5, true},
 	{"ESASTT hi", 0, false}, // run of upper-case letters too long.
 	{"ESATY hi", 0, false},  // five letters must end in T.
+	{"WITA hi", 4, true},    // Issue #18251
 }
 
 func TestParseTimeZone(t *testing.T) {
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 ac95844..2fa9b55 100644
--- a/src/vendor/golang_org/x/crypto/chacha20poly1305/chacha20poly1305_amd64.s
+++ b/src/vendor/golang_org/x/crypto/chacha20poly1305/chacha20poly1305_amd64.s
@@ -209,7 +209,7 @@ GLOBL ·andMask<>(SB), (NOPTR+RODATA), $240
 #define polyMul polyMulStage1; polyMulStage2; polyMulStage3; polyMulReduceStage
 #define polyMulAVX2 polyMulStage1_AVX2; polyMulStage2_AVX2; polyMulStage3_AVX2; polyMulReduceStage
 // ----------------------------------------------------------------------------
-TEXT polyHashADInternal(SB), NOSPLIT, $0
+TEXT polyHashADInternal<>(SB), NOSPLIT, $0
 	// adp points to beginning of additional data
 	// itr2 holds ad length
 	XORQ acc0, acc0
@@ -315,7 +315,7 @@ openSSEPreparePolyKey:
 
 	// Hash AAD
 	MOVQ ad_len+80(FP), itr2
-	CALL polyHashADInternal(SB)
+	CALL polyHashADInternal<>(SB)
 
 openSSEMainLoop:
 	CMPQ inl, $256
@@ -476,7 +476,7 @@ openSSE128InnerCipherLoop:
 
 	// Hash
 	MOVQ ad_len+80(FP), itr2
-	CALL polyHashADInternal(SB)
+	CALL polyHashADInternal<>(SB)
 
 openSSE128Open:
 	CMPQ inl, $16
@@ -822,7 +822,7 @@ openAVX2PreparePolyKey:
 
 	// Hash AD + first 64 bytes
 	MOVQ ad_len+80(FP), itr2
-	CALL polyHashADInternal(SB)
+	CALL polyHashADInternal<>(SB)
 	XORQ itr1, itr1
 
 openAVX2InitialHash64:
@@ -1014,7 +1014,7 @@ openAVX2192InnerCipherLoop:
 openAVX2ShortOpen:
 	// Hash
 	MOVQ ad_len+80(FP), itr2
-	CALL polyHashADInternal(SB)
+	CALL polyHashADInternal<>(SB)
 
 openAVX2ShortOpenLoop:
 	CMPQ inl, $32
@@ -1547,7 +1547,7 @@ sealSSEIntroLoop:
 
 	// Hash AAD
 	MOVQ ad_len+80(FP), itr2
-	CALL polyHashADInternal(SB)
+	CALL polyHashADInternal<>(SB)
 
 	MOVOU (0*16)(inp), A0; MOVOU (1*16)(inp), B0; MOVOU (2*16)(inp), C0; MOVOU (3*16)(inp), D0
 	PXOR  A0, A1; PXOR B0, B1; PXOR C0, C1; PXOR D0, D1
@@ -1852,7 +1852,7 @@ sealSSE128InnerCipherLoop:
 
 	// Hash
 	MOVQ ad_len+80(FP), itr2
-	CALL polyHashADInternal(SB)
+	CALL polyHashADInternal<>(SB)
 	XORQ itr1, itr1
 
 sealSSE128SealHash:
@@ -2027,7 +2027,7 @@ sealAVX2IntroLoop:
 
 	// Hash AD
 	MOVQ ad_len+80(FP), itr2
-	CALL polyHashADInternal(SB)
+	CALL polyHashADInternal<>(SB)
 
 	// Can store at least 320 bytes
 	VPXOR   (0*32)(inp), AA0, AA0
@@ -2290,7 +2290,7 @@ sealAVX2192InnerCipherLoop:
 sealAVX2ShortSeal:
 	// Hash aad
 	MOVQ ad_len+80(FP), itr2
-	CALL polyHashADInternal(SB)
+	CALL polyHashADInternal<>(SB)
 	XORQ itr1, itr1
 
 sealAVX2SealHash:
diff --git a/test/bench/go1/fasta_test.go b/test/bench/go1/fasta_test.go
index 99d8c97..af4fbac 100644
--- a/test/bench/go1/fasta_test.go
+++ b/test/bench/go1/fasta_test.go
@@ -12,10 +12,10 @@ var fastabytes = makefasta()
 
 func makefasta() []byte {
 	var n int = 25e6
-	if runtime.GOARCH == "arm" {
+	if runtime.GOARCH == "arm" || runtime.GOARCH == "mips" || runtime.GOARCH == "mips64" {
 		// TODO(dfc) remove this limitation after precise gc.
 		// A value of 25e6 consumes 465mb of heap on 32bit
-		// platforms, which is too much for most ARM systems.
+		// platforms, which is too much for some systems.
 		// A value of 25e5 produces a memory layout that
 		// confuses the gc on 32bit platforms. So 25e4 it is.
 		n = 25e4
diff --git a/test/fixedbugs/bug500.go b/test/fixedbugs/bug500.go
new file mode 100644
index 0000000..2dd5df1
--- /dev/null
+++ b/test/fixedbugs/bug500.go
@@ -0,0 +1,41 @@
+// 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.
+
+// Gccgo generated incorrect GC info when a global variable was
+// initialized to a slice of a value containing pointers.  The initial
+// backing array for the slice was allocated in the .data section,
+// which is fine, but the backing array was not registered as a GC
+// root.
+
+package main
+
+import (
+	"runtime"
+)
+
+type s struct {
+	str string
+}
+
+var a = []struct {
+	str string
+}{
+	{""},
+}
+
+var b = "b"
+var c = "c"
+
+func init() {
+	a[0].str = b + c
+}
+
+func main() {
+	runtime.GC()
+	if a[0].str != b + c {
+		panic(a[0].str)
+	}
+}
diff --git a/test/fixedbugs/bug501.go b/test/fixedbugs/bug501.go
new file mode 100644
index 0000000..8e951b1
--- /dev/null
+++ b/test/fixedbugs/bug501.go
@@ -0,0 +1,24 @@
+// 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.
+
+// Gccgo got a compiler crash compiling the addition of more than five
+// strings with mixed constants and variables.
+
+package main
+
+func F(s string) (string, error) {
+	return s, nil
+}
+
+func G(a, b, c string) (string, error) {
+	return F("a" + a + "b" + b + "c" + c)
+}
+
+func main() {
+	if got, _ := G("x", "y", "z"); got != "axbycz" {
+		panic(got)
+	}
+}
diff --git a/test/fixedbugs/issue10607.go b/test/fixedbugs/issue10607.go
index 52fb51a..8831547 100644
--- a/test/fixedbugs/issue10607.go
+++ b/test/fixedbugs/issue10607.go
@@ -1,4 +1,4 @@
-// +build linux,!mips,!mipsle,!ppc64
+// +build linux,!ppc64
 // run
 
 // Copyright 2015 The Go Authors. All rights reserved.
diff --git a/test/fixedbugs/issue11656.go b/test/fixedbugs/issue11656.go
index e0ef097..c04a662 100644
--- a/test/fixedbugs/issue11656.go
+++ b/test/fixedbugs/issue11656.go
@@ -61,9 +61,9 @@ func f(n int) {
 		binary.BigEndian.PutUint32(ill, 0x7fe00008) // trap
 	case "ppc64le":
 		binary.LittleEndian.PutUint32(ill, 0x7fe00008) // trap
-	case "mips64":
+	case "mips", "mips64":
 		binary.BigEndian.PutUint32(ill, 0x00000034) // trap
-	case "mips64le":
+	case "mipsle", "mips64le":
 		binary.LittleEndian.PutUint32(ill, 0x00000034) // trap
 	case "s390x":
 		binary.BigEndian.PutUint32(ill, 0) // undefined instruction
diff --git a/misc/cgo/testplugin/src/plugin2/plugin2.go b/test/fixedbugs/issue13263.go
similarity index 52%
copy from misc/cgo/testplugin/src/plugin2/plugin2.go
copy to test/fixedbugs/issue13263.go
index 6c23a5e..1933f2b 100644
--- a/misc/cgo/testplugin/src/plugin2/plugin2.go
+++ b/test/fixedbugs/issue13263.go
@@ -1,18 +1,15 @@
+// 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.
 
-package main
-
-// // No C code required.
-import "C"
-
-import "common"
-
-func init() {
-	common.X = 2
-}
+package b
 
-func main() {
-	panic("plugin1.main called")
-}
+var (
+	x uint
+	y = x
+	z = uintptr(y)
+	a = uint32(y)
+	b = uint64(y)
+)
diff --git a/test/fixedbugs/issue16130.go b/test/fixedbugs/issue16130.go
index 19c8264..c4e3ffd 100644
--- a/test/fixedbugs/issue16130.go
+++ b/test/fixedbugs/issue16130.go
@@ -5,7 +5,7 @@
 // license that can be found in the LICENSE file.
 
 // Test that an interface conversion error panics with an "interface
-// conversion" run-time error. It was (incorrectly) panicing with a
+// conversion" run-time error. It was (incorrectly) panicking with a
 // "nil pointer dereference."
 
 package main
diff --git a/test/fixedbugs/issue18149.go b/test/fixedbugs/issue18149.go
new file mode 100644
index 0000000..112cd52
--- /dev/null
+++ b/test/fixedbugs/issue18149.go
@@ -0,0 +1,33 @@
+// 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.
+
+// Verify that //line directives with filenames
+// containing ':' (Windows) are correctly parsed.
+// (For a related issue, see test/fixedbugs/bug305.go)
+
+package main
+
+import (
+	"fmt"
+	"runtime"
+)
+
+func check(file string, line int) {
+	_, f, l, ok := runtime.Caller(1)
+	if !ok {
+		panic("runtime.Caller(1) failed")
+	}
+	if f != file || l != line {
+		panic(fmt.Sprintf("got %s:%d; want %s:%d", f, l, file, line))
+	}
+}
+
+func main() {
+//line /foo/bar.go:123
+	check(`/foo/bar.go`, 123)
+//line c:/foo/bar.go:987
+	check(`c:/foo/bar.go`, 987)
+}

-- 
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