public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-7205] libgo: update to Go1.18beta2
@ 2022-02-11 23:01 Ian Lance Taylor
  0 siblings, 0 replies; only message in thread
From: Ian Lance Taylor @ 2022-02-11 23:01 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:8dc2499aa62f768c6395c9754b8cabc1ce25c494

commit r12-7205-g8dc2499aa62f768c6395c9754b8cabc1ce25c494
Author: Ian Lance Taylor <iant@golang.org>
Date:   Fri Feb 11 14:53:56 2022 -0800

    libgo: update to Go1.18beta2
    
    gotools/
            * Makefile.am (go_cmd_cgo_files): Add ast_go118.go
            (check-go-tool): Copy golang.org/x/tools directories.
            * Makefile.in: Regenerate.
    
    Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/384695

Diff:
---
 gcc/go/gofrontend/MERGE                            |     2 +-
 gotools/Makefile.am                                |     2 +
 gotools/Makefile.in                                |     2 +
 libgo/MERGE                                        |     2 +-
 libgo/Makefile.am                                  |    84 +-
 libgo/Makefile.in                                  |    91 +-
 libgo/VERSION                                      |     2 +-
 libgo/check-packages.txt                           |    10 +-
 libgo/configure                                    |    13 +-
 libgo/configure.ac                                 |     8 +-
 libgo/go/archive/tar/common.go                     |    40 +-
 libgo/go/archive/tar/format.go                     |   138 +-
 libgo/go/archive/tar/fuzz_test.go                  |    80 +
 libgo/go/archive/tar/reader.go                     |   102 +-
 libgo/go/archive/tar/reader_test.go                |    30 +-
 libgo/go/archive/tar/stat_actime1.go               |     1 -
 libgo/go/archive/tar/stat_actime2.go               |     1 -
 libgo/go/archive/tar/stat_unix.go                  |     1 -
 libgo/go/archive/tar/strconv.go                    |    43 +-
 libgo/go/archive/tar/tar_test.go                   |     2 +-
 libgo/go/archive/tar/writer.go                     |    89 +-
 libgo/go/archive/tar/writer_test.go                |    24 +-
 libgo/go/archive/zip/fuzz_test.go                  |    81 +
 libgo/go/archive/zip/reader.go                     |   106 +-
 libgo/go/archive/zip/reader_test.go                |   248 +-
 libgo/go/archive/zip/struct.go                     |    10 +-
 libgo/go/archive/zip/writer_test.go                |     2 +-
 libgo/go/bufio/bufio.go                            |    52 +-
 libgo/go/bufio/bufio_test.go                       |   142 +-
 libgo/go/bufio/example_test.go                     |    12 +
 libgo/go/builtin/builtin.go                        |    14 +-
 libgo/go/bytes/boundary_test.go                    |    19 +-
 libgo/go/bytes/bytes.go                            |   146 +-
 libgo/go/bytes/bytes_test.go                       |    32 +
 libgo/go/bytes/example_test.go                     |   194 +-
 libgo/go/bytes/reader_test.go                      |     2 +-
 libgo/go/cmd/cgo/ast.go                            |     3 +-
 libgo/go/cmd/cgo/ast_go1.go                        |    17 +
 libgo/go/cmd/cgo/ast_go118.go                      |    25 +
 libgo/go/cmd/cgo/gcc.go                            |   146 +-
 libgo/go/cmd/cgo/main.go                           |     8 +-
 libgo/go/cmd/cgo/out.go                            |    16 +-
 libgo/go/cmd/go.mod                                |    22 +-
 libgo/go/cmd/go/alldocs.go                         |   421 +-
 libgo/go/cmd/go/go11.go                            |     1 -
 libgo/go/cmd/go/go_test.go                         |    34 +-
 libgo/go/cmd/go/go_unix_test.go                    |     1 -
 libgo/go/cmd/go/internal/base/base.go              |     6 +-
 libgo/go/cmd/go/internal/base/flag.go              |    11 +-
 libgo/go/cmd/go/internal/base/signal_notunix.go    |     1 -
 libgo/go/cmd/go/internal/base/signal_unix.go       |     1 -
 libgo/go/cmd/go/internal/base/tool.go              |     2 +-
 libgo/go/cmd/go/internal/bug/bug.go                |     7 +-
 libgo/go/cmd/go/internal/cache/cache.go            |    12 +
 libgo/go/cmd/go/internal/cache/default.go          |     1 +
 libgo/go/cmd/go/internal/cfg/cfg.go                |    43 +-
 libgo/go/cmd/go/internal/clean/clean.go            |    39 +-
 libgo/go/cmd/go/internal/cmdflag/flag.go           |     2 +-
 libgo/go/cmd/go/internal/doc/doc.go                |     5 +-
 libgo/go/cmd/go/internal/envcmd/env.go             |    74 +-
 libgo/go/cmd/go/internal/fix/fix.go                |    30 +-
 libgo/go/cmd/go/internal/fmtcmd/fmt.go             |    36 +-
 libgo/go/cmd/go/internal/fsys/fsys.go              |     6 +-
 libgo/go/cmd/go/internal/fsys/fsys_test.go         |     3 +-
 libgo/go/cmd/go/internal/generate/generate.go      |     4 +-
 libgo/go/cmd/go/internal/get/get.go                |    35 +-
 libgo/go/cmd/go/internal/help/help.go              |     2 +-
 libgo/go/cmd/go/internal/help/helpdoc.go           |    11 +
 libgo/go/cmd/go/internal/imports/build.go          |   216 +-
 libgo/go/cmd/go/internal/imports/scan_test.go      |     2 +-
 .../cmd/go/internal/imports/testdata/android/e.go  |     1 +
 .../cmd/go/internal/imports/testdata/android/f.go  |     1 +
 .../cmd/go/internal/imports/testdata/android/g.go  |     1 +
 .../cmd/go/internal/imports/testdata/illumos/e.go  |     1 +
 .../cmd/go/internal/imports/testdata/illumos/f.go  |     1 +
 .../cmd/go/internal/imports/testdata/illumos/g.go  |     1 +
 .../go/cmd/go/internal/imports/testdata/star/x1.go |     7 +-
 libgo/go/cmd/go/internal/list/list.go              |    19 +-
 libgo/go/cmd/go/internal/load/flag.go              |    10 +-
 libgo/go/cmd/go/internal/load/pkg.go               |   285 +-
 libgo/go/cmd/go/internal/load/test.go              |    26 +-
 .../lockedfile/internal/filelock/filelock_fcntl.go |     1 -
 .../lockedfile/internal/filelock/filelock_other.go |     1 -
 .../lockedfile/internal/filelock/filelock_plan9.go |     1 -
 .../lockedfile/internal/filelock/filelock_test.go  |     1 -
 .../lockedfile/internal/filelock/filelock_unix.go  |     1 -
 .../internal/filelock/filelock_windows.go          |     1 -
 .../go/internal/lockedfile/lockedfile_filelock.go  |     1 -
 .../cmd/go/internal/lockedfile/lockedfile_plan9.go |     1 -
 .../cmd/go/internal/lockedfile/lockedfile_test.go  |     1 -
 .../cmd/go/internal/lockedfile/transform_test.go   |     1 -
 libgo/go/cmd/go/internal/modcmd/download.go        |   105 +-
 libgo/go/cmd/go/internal/modcmd/edit.go            |    50 +-
 libgo/go/cmd/go/internal/modcmd/graph.go           |     5 +-
 libgo/go/cmd/go/internal/modcmd/init.go            |     2 +-
 libgo/go/cmd/go/internal/modcmd/tidy.go            |     6 +-
 libgo/go/cmd/go/internal/modcmd/vendor.go          |    62 +-
 libgo/go/cmd/go/internal/modcmd/verify.go          |     5 +-
 libgo/go/cmd/go/internal/modcmd/why.go             |    15 +-
 libgo/go/cmd/go/internal/modfetch/bootstrap.go     |     1 -
 libgo/go/cmd/go/internal/modfetch/cache.go         |    16 +-
 .../cmd/go/internal/modfetch/codehost/codehost.go  |    19 +-
 libgo/go/cmd/go/internal/modfetch/codehost/git.go  |   261 +-
 .../go/cmd/go/internal/modfetch/codehost/shell.go  |     1 -
 libgo/go/cmd/go/internal/modfetch/codehost/vcs.go  |    17 +-
 libgo/go/cmd/go/internal/modfetch/coderepo.go      |    10 +-
 libgo/go/cmd/go/internal/modfetch/fetch.go         |   120 +-
 libgo/go/cmd/go/internal/modfetch/repo.go          |     6 +-
 libgo/go/cmd/go/internal/modfetch/sumdb.go         |     7 +-
 libgo/go/cmd/go/internal/modget/get.go             |   220 +-
 libgo/go/cmd/go/internal/modget/query.go           |    14 +-
 libgo/go/cmd/go/internal/modload/build.go          |   124 +-
 libgo/go/cmd/go/internal/modload/buildlist.go      |   457 +-
 libgo/go/cmd/go/internal/modload/edit.go           |   164 +-
 libgo/go/cmd/go/internal/modload/import.go         |   146 +-
 libgo/go/cmd/go/internal/modload/import_test.go    |     2 +-
 libgo/go/cmd/go/internal/modload/init.go           |  1025 +-
 libgo/go/cmd/go/internal/modload/list.go           |    15 +-
 libgo/go/cmd/go/internal/modload/load.go           |   343 +-
 libgo/go/cmd/go/internal/modload/modfile.go        |   291 +-
 libgo/go/cmd/go/internal/modload/mvs.go            |     6 +-
 libgo/go/cmd/go/internal/modload/query.go          |   206 +-
 libgo/go/cmd/go/internal/modload/search.go         |    15 +-
 libgo/go/cmd/go/internal/modload/stat_openfile.go  |     1 -
 libgo/go/cmd/go/internal/modload/stat_unix.go      |     1 -
 libgo/go/cmd/go/internal/modload/stat_windows.go   |     1 -
 libgo/go/cmd/go/internal/modload/vendor.go         |    12 +-
 libgo/go/cmd/go/internal/mvs/mvs.go                |    36 +-
 libgo/go/cmd/go/internal/mvs/mvs_test.go           |     2 +-
 libgo/go/cmd/go/internal/par/work.go               |    32 +-
 libgo/go/cmd/go/internal/par/work_test.go          |    12 +-
 .../go/cmd/go/internal/robustio/robustio_flaky.go  |     1 -
 .../go/cmd/go/internal/robustio/robustio_other.go  |     1 -
 libgo/go/cmd/go/internal/run/run.go                |    17 +-
 libgo/go/cmd/go/internal/search/search.go          |    33 +-
 libgo/go/cmd/go/internal/str/path.go               |    14 +
 libgo/go/cmd/go/internal/str/str.go                |    46 +-
 libgo/go/cmd/go/internal/str/str_test.go           |     4 +-
 libgo/go/cmd/go/internal/test/flagdefs.go          |    37 +
 libgo/go/cmd/go/internal/test/flagdefs_test.go     |    24 +-
 libgo/go/cmd/go/internal/test/genflags.go          |    24 +-
 .../go/internal/test/internal/genflags/vetflag.go  |    68 +
 libgo/go/cmd/go/internal/test/test.go              |   272 +-
 libgo/go/cmd/go/internal/test/testflag.go          |    76 +-
 libgo/go/cmd/go/internal/tool/tool.go              |     6 +-
 libgo/go/cmd/go/internal/txtar/archive_test.go     |    67 -
 libgo/go/cmd/go/internal/vcs/vcs.go                |   394 +-
 libgo/go/cmd/go/internal/vcs/vcs_test.go           |    63 +-
 libgo/go/cmd/go/internal/version/exe.go            |   263 -
 libgo/go/cmd/go/internal/version/version.go        |   101 +-
 libgo/go/cmd/go/internal/vet/vet.go                |     2 +-
 libgo/go/cmd/go/internal/vet/vetflag.go            |     4 +-
 libgo/go/cmd/go/internal/web/bootstrap.go          |     1 -
 libgo/go/cmd/go/internal/web/http.go               |    13 +-
 libgo/go/cmd/go/internal/web/url_other.go          |     1 -
 libgo/go/cmd/go/internal/web/url_other_test.go     |     1 -
 libgo/go/cmd/go/internal/work/action.go            |    12 +-
 libgo/go/cmd/go/internal/work/build.go             |    66 +-
 libgo/go/cmd/go/internal/work/build_test.go        |     2 +-
 libgo/go/cmd/go/internal/work/buildid.go           |     4 +
 libgo/go/cmd/go/internal/work/exec.go              |   146 +-
 libgo/go/cmd/go/internal/work/exec_test.go         |     5 +-
 libgo/go/cmd/go/internal/work/gc.go                |   116 +-
 libgo/go/cmd/go/internal/work/init.go              |    76 +-
 libgo/go/cmd/go/internal/work/testgo.go            |     1 -
 libgo/go/cmd/go/internal/workcmd/edit.go           |   315 +
 libgo/go/cmd/go/internal/workcmd/init.go           |    52 +
 libgo/go/cmd/go/internal/workcmd/sync.go           |   130 +
 libgo/go/cmd/go/internal/workcmd/use.go            |   119 +
 libgo/go/cmd/go/internal/workcmd/work.go           |    72 +
 libgo/go/cmd/go/main.go                            |     2 +
 libgo/go/cmd/go/proxy_test.go                      |     6 +-
 libgo/go/cmd/go/script_test.go                     |   232 +-
 libgo/go/cmd/go/stop_other_test.go                 |     9 -
 libgo/go/cmd/go/stop_unix_test.go                  |     1 -
 libgo/go/cmd/go/testdata/addmod.go                 |     5 +-
 ....com_split-incompatible_v2.0.0+incompatible.txt |     2 +-
 ..._split-incompatible_v2.1.0-pre+incompatible.txt |     2 +-
 libgo/go/cmd/go/testdata/savedir.go                |     3 +-
 libgo/go/cmd/go/testdata/script/README             |    17 +-
 .../go/testdata/script/build_cache_disabled.txt    |     2 +-
 .../go/testdata/script/build_cache_trimpath.txt    |     4 +-
 .../testdata/script/build_concurrent_backend.txt   |    12 +
 .../cmd/go/testdata/script/build_gcflags_order.txt |    20 +
 .../cmd/go/testdata/script/build_i_deprecate.txt   |     6 +-
 .../go/cmd/go/testdata/script/build_issue48319.txt |    47 +
 .../go/cmd/go/testdata/script/build_negative_p.txt |     5 +
 libgo/go/cmd/go/testdata/script/build_overlay.txt  |    28 +-
 .../go/testdata/script/build_runtime_gcflags.txt   |     2 +-
 .../cmd/go/testdata/script/build_single_error.txt  |    18 +
 libgo/go/cmd/go/testdata/script/build_trimpath.txt |     3 +-
 .../go/testdata/script/cgo_path_space_quote.txt    |    58 +
 .../go/testdata/script/cgo_stale_precompiled.txt   |    28 +
 libgo/go/cmd/go/testdata/script/embed.txt          |    20 +
 libgo/go/cmd/go/testdata/script/env_unset.txt      |     6 +-
 libgo/go/cmd/go/testdata/script/env_write.txt      |    18 +-
 .../go/cmd/go/testdata/script/gcflags_patterns.txt |    25 +-
 libgo/go/cmd/go/testdata/script/get_404_meta.txt   |     8 +-
 libgo/go/cmd/go/testdata/script/get_go_file.txt    |    12 +-
 .../script/get_insecure_no_longer_supported.txt    |     4 +-
 libgo/go/cmd/go/testdata/script/go_version.txt     |     9 +
 libgo/go/cmd/go/testdata/script/goflags.txt        |     2 +-
 libgo/go/cmd/go/testdata/script/gopath_install.txt |     2 +-
 libgo/go/cmd/go/testdata/script/gopath_local.txt   |     4 +-
 libgo/go/cmd/go/testdata/script/govcs.txt          |    28 +-
 .../script/install_msan_and_race_require_cgo.txt   |     6 +-
 .../cmd/go/testdata/script/link_external_undef.txt |    49 +
 .../go/cmd/go/testdata/script/list_all_gobuild.txt |    41 +
 .../script/list_cgo_compiled_importmap.txt         |     2 +-
 libgo/go/cmd/go/testdata/script/list_reserved.txt  |     7 +
 libgo/go/cmd/go/testdata/script/list_shadow.txt    |     2 +-
 libgo/go/cmd/go/testdata/script/list_swigcxx.txt   |     6 +-
 libgo/go/cmd/go/testdata/script/list_test_err.txt  |    14 +
 libgo/go/cmd/go/testdata/script/mod_all.txt        |    69 +-
 libgo/go/cmd/go/testdata/script/mod_bad_domain.txt |     6 +-
 .../cmd/go/testdata/script/mod_build_info_err.txt  |     2 +-
 .../script/mod_build_trimpath_issue48557.txt       |    52 +
 .../cmd/go/testdata/script/mod_build_versioned.txt |     2 +-
 libgo/go/cmd/go/testdata/script/mod_cache_dir.txt  |     4 +-
 libgo/go/cmd/go/testdata/script/mod_cache_rw.txt   |     4 +-
 libgo/go/cmd/go/testdata/script/mod_case.txt       |     4 +-
 libgo/go/cmd/go/testdata/script/mod_case_cgo.txt   |     2 +-
 libgo/go/cmd/go/testdata/script/mod_concurrent.txt |     2 +-
 .../go/testdata/script/mod_deprecate_message.txt   |     8 +-
 .../go/cmd/go/testdata/script/mod_domain_root.txt  |     2 +-
 libgo/go/cmd/go/testdata/script/mod_dot.txt        |     6 +-
 libgo/go/cmd/go/testdata/script/mod_download.txt   |    54 +-
 ...rect.txt => mod_download_insecure_redirect.txt} |    10 +-
 .../go/testdata/script/mod_download_partial.txt    |     2 +-
 ...rivate_vcs.txt => mod_download_private_vcs.txt} |     8 +-
 .../{mod_get_svn.txt => mod_download_svn.txt}      |    15 +-
 ...cts.txt => mod_download_too_many_redirects.txt} |     4 +-
 libgo/go/cmd/go/testdata/script/mod_e.txt          |    23 +-
 libgo/go/cmd/go/testdata/script/mod_edit.txt       |    10 +-
 libgo/go/cmd/go/testdata/script/mod_edit_go.txt    |     4 +-
 .../go/testdata/script/mod_get_ambiguous_arg.txt   |     8 +-
 .../testdata/script/mod_get_ambiguous_import.txt   |     4 +-
 .../go/testdata/script/mod_get_ambiguous_pkg.txt   |    14 +-
 .../go/cmd/go/testdata/script/mod_get_changes.txt  |    18 +-
 libgo/go/cmd/go/testdata/script/mod_get_cmd.txt    |    20 -
 libgo/go/cmd/go/testdata/script/mod_get_commit.txt |    19 +-
 .../testdata/script/mod_get_deprecate_install.txt  |    19 +-
 .../cmd/go/testdata/script/mod_get_deprecated.txt  |    16 +-
 libgo/go/cmd/go/testdata/script/mod_get_direct.txt |     2 +-
 .../testdata/script/mod_get_downadd_indirect.txt   |     2 +-
 .../cmd/go/testdata/script/mod_get_downgrade.txt   |    16 +-
 .../testdata/script/mod_get_downgrade_missing.txt  |    10 +-
 .../go/testdata/script/mod_get_downup_artifact.txt |     2 +-
 .../go/testdata/script/mod_get_downup_indirect.txt |     2 +-
 .../script/mod_get_downup_pseudo_artifact.txt      |     2 +-
 libgo/go/cmd/go/testdata/script/mod_get_errors.txt |    22 +-
 libgo/go/cmd/go/testdata/script/mod_get_extra.txt  |     4 +-
 .../go/cmd/go/testdata/script/mod_get_fallback.txt |     7 +-
 libgo/go/cmd/go/testdata/script/mod_get_fossil.txt |     3 +-
 .../go/cmd/go/testdata/script/mod_get_go_file.txt  |    15 +-
 .../go/testdata/script/mod_get_incompatible.txt    |     6 +-
 .../go/cmd/go/testdata/script/mod_get_indirect.txt |     2 +-
 .../cmd/go/testdata/script/mod_get_issue37438.txt  |     2 +-
 .../cmd/go/testdata/script/mod_get_issue47979.txt  |   117 +
 .../cmd/go/testdata/script/mod_get_issue48511.txt  |    68 +
 .../go/testdata/script/mod_get_latest_pseudo.txt   |     2 +-
 .../testdata/script/mod_get_lazy_upgrade_lazy.txt  |    68 +
 libgo/go/cmd/go/testdata/script/mod_get_local.txt  |    22 +-
 libgo/go/cmd/go/testdata/script/mod_get_main.txt   |    36 +-
 libgo/go/cmd/go/testdata/script/mod_get_major.txt  |     4 +-
 .../go/testdata/script/mod_get_missing_ziphash.txt |     4 +-
 libgo/go/cmd/go/testdata/script/mod_get_moved.txt  |    12 +-
 .../go/cmd/go/testdata/script/mod_get_newcycle.txt |     2 +-
 libgo/go/cmd/go/testdata/script/mod_get_none.txt   |     4 +-
 libgo/go/cmd/go/testdata/script/mod_get_nopkgs.txt |    12 +-
 libgo/go/cmd/go/testdata/script/mod_get_patch.txt  |    12 +-
 .../cmd/go/testdata/script/mod_get_patchbound.txt  |     2 +-
 .../cmd/go/testdata/script/mod_get_patchcycle.txt  |     2 +-
 .../go/cmd/go/testdata/script/mod_get_patchmod.txt |    14 +-
 .../go/cmd/go/testdata/script/mod_get_patterns.txt |    14 +-
 .../go/cmd/go/testdata/script/mod_get_pkgtags.txt  |    20 +-
 .../script/mod_get_prefer_incompatible.txt         |     2 +-
 .../testdata/script/mod_get_promote_implicit.txt   |     4 +-
 libgo/go/cmd/go/testdata/script/mod_get_pseudo.txt |    26 +-
 .../script/mod_get_pseudo_other_branch.txt         |     2 +-
 .../go/testdata/script/mod_get_pseudo_prefix.txt   |     4 +-
 .../go/cmd/go/testdata/script/mod_get_replaced.txt |    24 +-
 .../go/cmd/go/testdata/script/mod_get_retract.txt  |    14 +-
 .../testdata/script/mod_get_retract_ambiguous.txt  |     2 +-
 libgo/go/cmd/go/testdata/script/mod_get_split.txt  |    26 +-
 .../cmd/go/testdata/script/mod_get_sum_noroot.txt  |     2 +-
 libgo/go/cmd/go/testdata/script/mod_get_tags.txt   |    13 +-
 libgo/go/cmd/go/testdata/script/mod_get_test.txt   |    14 +-
 .../go/testdata/script/mod_get_trailing_slash.txt  |     9 +-
 .../script/mod_get_update_unrelated_sum.txt        |    10 +-
 .../go/cmd/go/testdata/script/mod_get_upgrade.txt  |    14 +-
 .../go/testdata/script/mod_get_upgrade_pseudo.txt  |    20 +-
 libgo/go/cmd/go/testdata/script/mod_get_wild.txt   |     6 +-
 .../cmd/go/testdata/script/mod_getmode_vendor.txt  |     9 +-
 libgo/go/cmd/go/testdata/script/mod_getx.txt       |     7 +-
 .../go/testdata/script/mod_go_version_missing.txt  |     2 +-
 libgo/go/cmd/go/testdata/script/mod_gomodcache.txt |    17 +-
 libgo/go/cmd/go/testdata/script/mod_gonoproxy.txt  |    18 +-
 .../cmd/go/testdata/script/mod_gopkg_unstable.txt  |     4 +-
 libgo/go/cmd/go/testdata/script/mod_import.txt     |     2 +-
 .../cmd/go/testdata/script/mod_import_v1suffix.txt |     2 +-
 .../cmd/go/testdata/script/mod_in_testdata_dir.txt |     2 +-
 .../go/testdata/script/mod_init_invalid_major.txt  |    82 +
 .../go/testdata/script/mod_install_pkg_version.txt |    26 +-
 .../go/testdata/script/mod_install_versioned.txt   |     4 +-
 libgo/go/cmd/go/testdata/script/mod_internal.txt   |    20 +-
 .../go/cmd/go/testdata/script/mod_invalid_path.txt |     6 +-
 .../testdata/script/mod_invalid_path_dotname.txt   |     6 +-
 .../go/testdata/script/mod_invalid_path_plus.txt   |     6 +-
 .../cmd/go/testdata/script/mod_invalid_version.txt |    46 +-
 libgo/go/cmd/go/testdata/script/mod_issue35317.txt |     2 +-
 .../cmd/go/testdata/script/mod_lazy_downgrade.txt  |    12 +-
 .../go/testdata/script/mod_lazy_import_allmod.txt  |     2 +-
 .../cmd/go/testdata/script/mod_lazy_new_import.txt |     2 +-
 libgo/go/cmd/go/testdata/script/mod_list.txt       |     4 +-
 .../script/mod_list_command_line_arguments.txt     |    35 +
 .../script/mod_list_compiled_concurrent.txt        |     1 +
 .../cmd/go/testdata/script/mod_list_deprecated.txt |     2 +-
 libgo/go/cmd/go/testdata/script/mod_list_dir.txt   |     4 +-
 .../go/cmd/go/testdata/script/mod_list_direct.txt  |     2 +-
 .../go/testdata/script/mod_list_replace_dir.txt    |     2 +-
 .../go/cmd/go/testdata/script/mod_list_retract.txt |     4 +-
 libgo/go/cmd/go/testdata/script/mod_list_sums.txt  |     2 +-
 .../testdata/script/mod_list_update_nolatest.txt   |     2 +-
 .../go/testdata/script/mod_list_upgrade_pseudo.txt |     4 +-
 .../cmd/go/testdata/script/mod_load_badchain.txt   |    10 +-
 .../go/cmd/go/testdata/script/mod_load_badzip.txt  |     2 +-
 .../go/cmd/go/testdata/script/mod_missing_repo.txt |     4 +-
 libgo/go/cmd/go/testdata/script/mod_multirepo.txt  |     2 +-
 libgo/go/cmd/go/testdata/script/mod_no_gopath.txt  |    15 +
 libgo/go/cmd/go/testdata/script/mod_outside.txt    |    66 +-
 libgo/go/cmd/go/testdata/script/mod_overlay.txt    |    14 +-
 .../go/cmd/go/testdata/script/mod_permissions.txt  |     2 +-
 .../go/testdata/script/mod_prefer_compatible.txt   |     2 +-
 .../cmd/go/testdata/script/mod_proxy_invalid.txt   |     4 +-
 libgo/go/cmd/go/testdata/script/mod_proxy_list.txt |    14 +-
 libgo/go/cmd/go/testdata/script/mod_query.txt      |     2 +-
 .../go/cmd/go/testdata/script/mod_query_empty.txt  |    12 +-
 .../cmd/go/testdata/script/mod_query_exclude.txt   |     8 +-
 libgo/go/cmd/go/testdata/script/mod_query_main.txt |    10 +-
 libgo/go/cmd/go/testdata/script/mod_readonly.txt   |     6 +-
 libgo/go/cmd/go/testdata/script/mod_replace.txt    |     2 +-
 .../cmd/go/testdata/script/mod_replace_gopkgin.txt |     2 +-
 .../cmd/go/testdata/script/mod_replace_import.txt  |     2 +-
 .../go/testdata/script/mod_replace_readonly.txt    |     4 +-
 libgo/go/cmd/go/testdata/script/mod_retention.txt  |    30 +-
 libgo/go/cmd/go/testdata/script/mod_retract.txt    |     2 +-
 .../go/testdata/script/mod_retract_fix_version.txt |     2 +-
 .../testdata/script/mod_retract_incompatible.txt   |     4 +-
 .../go/testdata/script/mod_retract_pseudo_base.txt |     6 +-
 .../go/testdata/script/mod_retract_rationale.txt   |    14 +-
 .../cmd/go/testdata/script/mod_retract_rename.txt  |     6 +-
 .../cmd/go/testdata/script/mod_retract_replace.txt |     2 +-
 .../go/cmd/go/testdata/script/mod_run_nonmain.txt  |     2 +-
 .../cmd/go/testdata/script/mod_run_pkg_version.txt |     6 +-
 libgo/go/cmd/go/testdata/script/mod_skip_write.txt |    92 +
 libgo/go/cmd/go/testdata/script/mod_sum_lookup.txt |     2 +-
 .../go/cmd/go/testdata/script/mod_sum_readonly.txt |     6 +-
 .../go/cmd/go/testdata/script/mod_sum_replaced.txt |     4 +-
 libgo/go/cmd/go/testdata/script/mod_sumdb.txt      |    12 +-
 .../go/cmd/go/testdata/script/mod_sumdb_cache.txt  |    14 +-
 .../cmd/go/testdata/script/mod_sumdb_file_path.txt |    12 +-
 .../go/cmd/go/testdata/script/mod_sumdb_golang.txt |     2 +-
 .../go/cmd/go/testdata/script/mod_sumdb_proxy.txt  |    14 +-
 libgo/go/cmd/go/testdata/script/mod_symlink.txt    |     6 +-
 .../go/cmd/go/testdata/script/mod_tidy_compat.txt  |     4 +-
 .../testdata/script/mod_tidy_compat_ambiguous.txt  |     9 +-
 .../script/mod_tidy_compat_incompatible.txt        |     7 +-
 .../go/testdata/script/mod_tidy_convergence.txt    |     4 +-
 .../testdata/script/mod_tidy_convergence_loop.txt  |     4 +-
 .../script/mod_tidy_downgrade_ambiguous.txt        |    58 +
 libgo/go/cmd/go/testdata/script/mod_tidy_error.txt |     4 +-
 .../go/cmd/go/testdata/script/mod_tidy_replace.txt |     2 +-
 libgo/go/cmd/go/testdata/script/mod_tidy_sum.txt   |     4 +-
 .../go/cmd/go/testdata/script/mod_tidy_too_new.txt |     4 +-
 .../cmd/go/testdata/script/mod_upgrade_patch.txt   |    32 +-
 .../go/cmd/go/testdata/script/mod_vcs_missing.txt  |     2 +-
 libgo/go/cmd/go/testdata/script/mod_vendor.txt     |    48 +-
 .../go/cmd/go/testdata/script/mod_vendor_auto.txt  |    10 +-
 .../go/cmd/go/testdata/script/mod_vendor_build.txt |     2 +-
 .../go/cmd/go/testdata/script/mod_vendor_embed.txt |     4 +-
 .../go/testdata/script/mod_vendor_goversion.txt    |     4 +-
 .../script/mod_vendor_redundant_requirement.txt    |    29 +
 .../cmd/go/testdata/script/mod_vendor_replace.txt  |     5 +-
 .../cmd/go/testdata/script/mod_vendor_trimpath.txt |     6 +-
 .../go/testdata/script/mod_vendor_unused_only.txt  |     2 +
 libgo/go/cmd/go/testdata/script/mod_verify.txt     |     7 +-
 libgo/go/cmd/go/testdata/script/modfile_flag.txt   |     9 +-
 libgo/go/cmd/go/testdata/script/run_dirs.txt       |    14 +-
 libgo/go/cmd/go/testdata/script/run_wildcard.txt   |     2 +-
 .../cmd/go/testdata/script/test_benchmark_1x.txt   |    37 +
 .../cmd/go/testdata/script/test_build_failure.txt  |     2 +-
 .../cmd/go/testdata/script/test_cache_inputs.txt   |     6 +
 .../cmd/go/testdata/script/test_fail_newline.txt   |    65 +
 libgo/go/cmd/go/testdata/script/test_flag.txt      |     6 +-
 libgo/go/cmd/go/testdata/script/test_fuzz.txt      |   498 +
 .../go/cmd/go/testdata/script/test_fuzz_cache.txt  |    97 +
 .../go/cmd/go/testdata/script/test_fuzz_chatty.txt |   102 +
 .../cmd/go/testdata/script/test_fuzz_cleanup.txt   |    66 +
 libgo/go/cmd/go/testdata/script/test_fuzz_cov.txt  |    33 +
 .../cmd/go/testdata/script/test_fuzz_deadline.txt  |    35 +
 .../cmd/go/testdata/script/test_fuzz_fuzztime.txt  |   121 +
 .../cmd/go/testdata/script/test_fuzz_io_error.txt  |   101 +
 .../go/cmd/go/testdata/script/test_fuzz_match.txt  |    38 +
 .../cmd/go/testdata/script/test_fuzz_minimize.txt  |   203 +
 .../script/test_fuzz_minimize_interesting.txt      |   251 +
 .../cmd/go/testdata/script/test_fuzz_modcache.txt  |    58 +
 .../cmd/go/testdata/script/test_fuzz_multiple.txt  |    49 +
 .../go/testdata/script/test_fuzz_mutate_crash.txt  |   323 +
 .../go/testdata/script/test_fuzz_mutate_fail.txt   |   102 +
 .../cmd/go/testdata/script/test_fuzz_mutator.txt   |   165 +
 .../testdata/script/test_fuzz_mutator_repeat.txt   |    74 +
 .../testdata/script/test_fuzz_non_crash_signal.txt |    75 +
 .../cmd/go/testdata/script/test_fuzz_parallel.txt  |    66 +
 .../go/testdata/script/test_fuzz_profile_flags.txt |    38 +
 libgo/go/cmd/go/testdata/script/test_fuzz_run.txt  |   143 +
 .../go/testdata/script/test_fuzz_seed_corpus.txt   |   203 +
 .../go/cmd/go/testdata/script/test_fuzz_setenv.txt |    45 +
 .../cmd/go/testdata/script/test_fuzz_test_race.txt |    39 +
 .../go/testdata/script/test_fuzz_unsupported.txt   |    18 +
 .../go/cmd/go/testdata/script/test_issue45477.txt  |    12 +
 .../cmd/go/testdata/script/test_race_install.txt   |     2 +-
 .../go/testdata/script/test_relative_cmdline.txt   |     3 +-
 libgo/go/cmd/go/testdata/script/test_vet.txt       |    31 +
 .../go/testdata/script/vendor_list_issue11977.txt  |     2 +-
 libgo/go/cmd/go/testdata/script/version.txt        |    22 +-
 .../go/testdata/script/version_build_settings.txt  |    70 +
 .../go/testdata/script/version_buildvcs_bzr.txt    |   107 +
 .../go/testdata/script/version_buildvcs_fossil.txt |    93 +
 .../go/testdata/script/version_buildvcs_git.txt    |   164 +
 .../testdata/script/version_buildvcs_git_gpg.txt   |   105 +
 .../cmd/go/testdata/script/version_buildvcs_hg.txt |    91 +
 .../go/testdata/script/version_buildvcs_nested.txt |    51 +
 .../go/cmd/go/testdata/script/version_replace.txt  |     2 +-
 libgo/go/cmd/go/testdata/script/work.txt           |   147 +
 .../go/testdata/script/work_build_no_modules.txt   |    13 +
 libgo/go/cmd/go/testdata/script/work_edit.txt      |   161 +
 libgo/go/cmd/go/testdata/script/work_env.txt       |    24 +
 .../go/testdata/script/work_install_submodule.txt  |    36 +
 libgo/go/cmd/go/testdata/script/work_prune.txt     |   104 +
 libgo/go/cmd/go/testdata/script/work_prune_all.txt |   176 +
 .../go/testdata/script/work_regression_hang.txt    |    71 +
 libgo/go/cmd/go/testdata/script/work_replace.txt   |    55 +
 .../go/testdata/script/work_replace_conflict.txt   |    53 +
 .../script/work_replace_conflict_override.txt      |    57 +
 .../testdata/script/work_replace_main_module.txt   |    45 +
 libgo/go/cmd/go/testdata/script/work_sum.txt       |    34 +
 .../cmd/go/testdata/script/work_sum_mismatch.txt   |    61 +
 libgo/go/cmd/go/testdata/script/work_sync.txt      |   119 +
 .../script/work_sync_irrelevant_dependency.txt     |   119 +
 .../testdata/script/work_sync_missing_module.txt   |    12 +
 .../script/work_sync_relevant_dependency.txt       |   106 +
 libgo/go/cmd/go/testdata/script/work_sync_sum.txt  |    40 +
 libgo/go/cmd/go/testdata/script/work_use.txt       |    32 +
 .../go/testdata/script/work_why_download_graph.txt |    59 +
 libgo/go/cmd/go/testdata/script/work_workfile.txt  |    21 +
 .../go/testdata/testterminal18153/terminal_test.go |     1 +
 libgo/go/cmd/gofmt/gofmt.go                        |   306 +-
 libgo/go/cmd/gofmt/gofmt_test.go                   |    31 +-
 libgo/go/cmd/gofmt/rewrite.go                      |     8 +-
 libgo/go/cmd/internal/buildid/buildid_test.go      |    10 +-
 libgo/go/cmd/internal/buildid/rewrite.go           |     5 +-
 libgo/go/cmd/internal/objabi/flag.go               |   164 +
 libgo/go/cmd/internal/objabi/funcdata.go           |     2 +
 libgo/go/cmd/internal/objabi/funcid.go             |     4 +-
 libgo/go/cmd/internal/objabi/reloctype.go          |    18 +-
 libgo/go/cmd/internal/objabi/reloctype_string.go   |    52 +-
 libgo/go/cmd/internal/objabi/symkind.go            |     7 -
 libgo/go/cmd/internal/objabi/symkind_string.go     |     7 +-
 libgo/go/cmd/internal/objabi/util.go               |     3 +-
 libgo/go/cmd/internal/quoted/quoted.go             |   127 +
 libgo/go/cmd/internal/quoted/quoted_test.go        |    88 +
 libgo/go/cmd/internal/sys/arch.go                  |   213 +-
 libgo/go/cmd/internal/sys/args.go                  |    13 +
 libgo/go/cmd/internal/sys/supported.go             |    39 +-
 libgo/go/cmd/internal/test2json/test2json_test.go  |     2 +-
 libgo/go/cmd/internal/traceviewer/format.go        |    28 +-
 libgo/go/cmd/vendor/modules.txt                    |    23 +-
 libgo/go/cmd/vet/testdata/print/print.go           |     8 +-
 libgo/go/cmd/vet/vet_test.go                       |     4 +-
 libgo/go/compress/gzip/fuzz_test.go                |    92 +
 libgo/go/compress/gzip/issue14937_test.go          |     4 +
 libgo/go/compress/lzw/writer.go                    |    20 +-
 libgo/go/compress/lzw/writer_test.go               |    28 +
 libgo/go/container/heap/heap.go                    |    10 +-
 libgo/go/container/heap/heap_test.go               |     4 +-
 libgo/go/container/list/list.go                    |    27 +-
 libgo/go/container/list/list_test.go               |    47 +-
 libgo/go/container/ring/example_test.go            |     8 +-
 libgo/go/container/ring/ring.go                    |     4 +-
 libgo/go/container/ring/ring_test.go               |     2 +-
 libgo/go/context/benchmark_test.go                 |    36 +
 libgo/go/context/context.go                        |    44 +-
 libgo/go/context/context_test.go                   |    20 +-
 libgo/go/crypto/aes/aes_gcm.go                     |     3 +-
 libgo/go/crypto/aes/cipher_asm.go                  |     3 +-
 libgo/go/crypto/aes/cipher_generic.go              |     1 -
 libgo/go/crypto/aes/gcm_ppc64le.go                 |     3 +-
 libgo/go/crypto/cipher/xor_generic.go              |     1 -
 libgo/go/crypto/cipher/xor_ppc64x.go               |     3 +-
 libgo/go/crypto/crypto.go                          |    26 +-
 libgo/go/crypto/ecdsa/ecdsa.go                     |     8 +-
 libgo/go/crypto/ecdsa/ecdsa_noasm.go               |     1 -
 libgo/go/crypto/ecdsa/ecdsa_s390x_test.go          |     3 +-
 libgo/go/crypto/ecdsa/ecdsa_test.go                |     6 +-
 .../internal/edwards25519/field/fe_amd64.go        |     1 -
 .../internal/edwards25519/field/fe_amd64_noasm.go  |     1 -
 .../internal/edwards25519/field/fe_arm64.go        |     1 -
 .../internal/edwards25519/field/fe_arm64_noasm.go  |     1 -
 .../internal/edwards25519/scalar_alias_test.go     |     2 +-
 .../crypto/ed25519/internal/edwards25519/tables.go |     2 +-
 libgo/go/crypto/elliptic/elliptic.go               |    41 +-
 libgo/go/crypto/elliptic/elliptic_test.go          |    50 +-
 libgo/go/crypto/elliptic/export_generate.go        |    16 +
 libgo/go/crypto/elliptic/fuzz_test.go              |     1 -
 libgo/go/crypto/elliptic/gen_p256_table.go         |   110 +
 .../go/crypto/elliptic/internal/fiat/fiat_test.go  |    64 +
 libgo/go/crypto/elliptic/internal/fiat/generate.go |   330 +
 libgo/go/crypto/elliptic/internal/fiat/p224.go     |   135 +
 .../crypto/elliptic/internal/fiat/p224_fiat64.go   |  1429 ++
 .../crypto/elliptic/internal/fiat/p224_invert.go   |    87 +
 libgo/go/crypto/elliptic/internal/fiat/p384.go     |   135 +
 .../crypto/elliptic/internal/fiat/p384_fiat64.go   |  3004 ++++
 .../crypto/elliptic/internal/fiat/p384_invert.go   |   102 +
 libgo/go/crypto/elliptic/internal/fiat/p521.go     |   170 +-
 .../crypto/elliptic/internal/fiat/p521_fiat64.go   |  6141 +++++++--
 .../crypto/elliptic/internal/fiat/p521_invert.go   |    89 +
 .../go/crypto/elliptic/internal/fiat/p521_test.go  |    37 -
 .../crypto/elliptic/internal/nistec/nistec_test.go |    98 +
 libgo/go/crypto/elliptic/internal/nistec/p224.go   |   293 +
 libgo/go/crypto/elliptic/internal/nistec/p384.go   |   298 +
 libgo/go/crypto/elliptic/internal/nistec/p521.go   |   310 +
 libgo/go/crypto/elliptic/p224.go                   |   824 +-
 libgo/go/crypto/elliptic/p224_test.go              |   306 +-
 libgo/go/crypto/elliptic/p256.go                   |     4 +-
 libgo/go/crypto/elliptic/p256_asm.go               |    11 +-
 libgo/go/crypto/elliptic/p256_asm_table.go         |  2889 ++--
 libgo/go/crypto/elliptic/p256_asm_table_test.go    |    11 +-
 libgo/go/crypto/elliptic/p256_generic.go           |     1 -
 libgo/go/crypto/elliptic/p256_ppc64le.go           |     3 +-
 libgo/go/crypto/elliptic/p256_s390x.go             |     3 +-
 libgo/go/crypto/elliptic/p256_test.go              |    19 +-
 libgo/go/crypto/elliptic/p384.go                   |   141 +
 libgo/go/crypto/elliptic/p521.go                   |   321 +-
 libgo/go/crypto/internal/subtle/aliasing.go        |     1 -
 .../crypto/internal/subtle/aliasing_appengine.go   |     1 -
 libgo/go/crypto/md5/gen.go                         |     1 -
 libgo/go/crypto/md5/md5_test.go                    |    14 +
 libgo/go/crypto/md5/md5block_decl.go               |     3 +-
 libgo/go/crypto/md5/md5block_generic.go            |     5 +-
 libgo/go/crypto/rand/eagain.go                     |     1 -
 libgo/go/crypto/rand/rand.go                       |     5 +-
 libgo/go/crypto/rand/rand_batched.go               |     1 -
 libgo/go/crypto/rand/rand_batched_test.go          |     1 -
 libgo/go/crypto/rand/rand_getentropy.go            |     1 -
 libgo/go/crypto/rand/rand_js.go                    |     1 -
 libgo/go/crypto/rand/rand_unix.go                  |     1 -
 libgo/go/crypto/sha1/fallback_test.go              |     3 +-
 libgo/go/crypto/sha1/issue15617_test.go            |     2 -
 libgo/go/crypto/sha1/sha1_test.go                  |    14 +
 libgo/go/crypto/sha1/sha1block_decl.go             |     3 +-
 libgo/go/crypto/sha1/sha1block_generic.go          |     5 +-
 libgo/go/crypto/sha256/fallback_test.go            |     3 +-
 libgo/go/crypto/sha256/sha256.go                   |     6 +-
 libgo/go/crypto/sha256/sha256_test.go              |    14 +
 libgo/go/crypto/sha256/sha256block_decl.go         |     3 +-
 libgo/go/crypto/sha256/sha256block_generic.go      |     5 +-
 libgo/go/crypto/sha512/fallback_test.go            |     3 +-
 libgo/go/crypto/sha512/sha512.go                   |    18 +-
 libgo/go/crypto/sha512/sha512_test.go              |    14 +
 libgo/go/crypto/sha512/sha512block_amd64.go        |     3 +-
 libgo/go/crypto/sha512/sha512block_decl.go         |     3 +-
 libgo/go/crypto/sha512/sha512block_generic.go      |     1 -
 libgo/go/crypto/tls/cipher_suites.go               |     8 +-
 libgo/go/crypto/tls/common.go                      |    42 +-
 libgo/go/crypto/tls/conn.go                        |    23 +-
 libgo/go/crypto/tls/generate_cert.go               |     5 +-
 libgo/go/crypto/tls/handshake_client.go            |    10 +-
 libgo/go/crypto/tls/handshake_client_test.go       |    14 +-
 libgo/go/crypto/tls/handshake_messages.go          |     5 +-
 libgo/go/crypto/tls/handshake_messages_test.go     |     2 +-
 libgo/go/crypto/tls/handshake_server.go            |     8 +-
 libgo/go/crypto/tls/handshake_server_test.go       |    26 +-
 libgo/go/crypto/tls/handshake_server_tls13.go      |     2 +-
 libgo/go/crypto/tls/handshake_test.go              |    15 +-
 libgo/go/crypto/tls/handshake_unix_test.go         |     1 -
 libgo/go/crypto/x509/cert_pool.go                  |    23 +-
 libgo/go/crypto/x509/hybrid_pool_test.go           |    95 +
 .../crypto/x509/internal/macos/corefoundation.go   |   131 -
 libgo/go/crypto/x509/internal/macos/security.go    |   118 -
 libgo/go/crypto/x509/name_constraints_test.go      |    16 +-
 libgo/go/crypto/x509/parser.go                     |     8 +-
 libgo/go/crypto/x509/pem_decrypt.go                |     5 +-
 libgo/go/crypto/x509/pkcs8.go                      |     4 +-
 libgo/go/crypto/x509/pkix/pkix.go                  |     2 +-
 libgo/go/crypto/x509/root_aix.go                   |     3 +-
 libgo/go/crypto/x509/root_bsd.go                   |     4 +-
 libgo/go/crypto/x509/root_darwin.go                |   270 +-
 libgo/go/crypto/x509/root_ios.go                   |  4873 -------
 libgo/go/crypto/x509/root_ios_gen.go               |   181 -
 libgo/go/crypto/x509/root_js.go                    |     4 +-
 libgo/go/crypto/x509/root_linux.go                 |     3 +-
 libgo/go/crypto/x509/root_omit.go                  |    27 -
 libgo/go/crypto/x509/root_omit_test.go             |    24 -
 libgo/go/crypto/x509/root_plan9.go                 |     1 -
 libgo/go/crypto/x509/root_solaris.go               |     3 +-
 libgo/go/crypto/x509/root_unix.go                  |     1 -
 libgo/go/crypto/x509/root_unix_test.go             |     1 -
 libgo/go/crypto/x509/root_windows.go               |    53 +-
 libgo/go/crypto/x509/root_windows_test.go          |   102 +
 libgo/go/crypto/x509/verify.go                     |    39 +-
 libgo/go/crypto/x509/verify_test.go                |   112 +-
 libgo/go/crypto/x509/x509.go                       |    59 +-
 libgo/go/crypto/x509/x509_test.go                  |   182 +-
 libgo/go/crypto/x509/x509_test_import.go           |     1 -
 libgo/go/database/sql/convert.go                   |    20 +-
 libgo/go/database/sql/convert_test.go              |    45 +-
 libgo/go/database/sql/driver/driver.go             |     5 +-
 libgo/go/database/sql/driver/types.go              |    22 +-
 libgo/go/database/sql/driver/types_test.go         |     4 +-
 libgo/go/database/sql/fakedb_test.go               |    59 +-
 libgo/go/database/sql/sql.go                       |   253 +-
 libgo/go/database/sql/sql_test.go                  |   279 +-
 libgo/go/debug/buildinfo/buildinfo.go              |   397 +
 libgo/go/debug/buildinfo/buildinfo_test.go         |   227 +
 libgo/go/debug/dwarf/entry.go                      |     7 +-
 libgo/go/debug/dwarf/entry_test.go                 |     2 +-
 libgo/go/debug/dwarf/testdata/bitfields.c          |    17 +
 libgo/go/debug/dwarf/testdata/bitfields.elf4       |   Bin 0 -> 2464 bytes
 libgo/go/debug/dwarf/testdata/typedef.c            |     1 +
 libgo/go/debug/dwarf/testdata/typedef.elf5         |   Bin 0 -> 6016 bytes
 libgo/go/debug/dwarf/testdata/typedef.macho4       |   Bin 0 -> 6220 bytes
 libgo/go/debug/dwarf/type.go                       |   143 +-
 libgo/go/debug/dwarf/type_test.go                  |   118 +-
 libgo/go/debug/elf/elf.go                          |     2 +
 libgo/go/debug/elf/elf_test.go                     |    24 +-
 libgo/go/debug/elf/file.go                         |    22 +-
 libgo/go/debug/gosym/pclntab.go                    |   287 +-
 libgo/go/debug/gosym/pclntab_test.go               |    98 +-
 libgo/go/debug/gosym/symtab.go                     |    55 +-
 libgo/go/debug/gosym/symtab_test.go                |    19 +
 libgo/go/debug/macho/file.go                       |    25 +-
 libgo/go/debug/macho/file_test.go                  |    19 +-
 libgo/go/debug/pe/file.go                          |    20 +-
 libgo/go/debug/pe/file_cgo_test.go                 |     1 -
 libgo/go/debug/pe/file_test.go                     |     4 +-
 libgo/go/debug/plan9obj/file.go                    |     8 +-
 libgo/go/embed/embed.go                            |    16 +-
 libgo/go/embed/example_test.go                     |    23 +
 libgo/go/embed/internal/embedtest/embed_test.go    |    17 +-
 libgo/go/encoding/ascii85/ascii85.go               |     4 +-
 libgo/go/encoding/ascii85/ascii85_test.go          |     2 +-
 libgo/go/encoding/asn1/asn1.go                     |    10 +-
 libgo/go/encoding/asn1/asn1_test.go                |    10 +-
 libgo/go/encoding/asn1/common.go                   |     9 +-
 libgo/go/encoding/asn1/marshal.go                  |     4 +-
 libgo/go/encoding/asn1/marshal_test.go             |    12 +-
 libgo/go/encoding/base32/base32.go                 |     4 +-
 libgo/go/encoding/base32/base32_test.go            |     2 +-
 libgo/go/encoding/base64/base64.go                 |     4 +-
 libgo/go/encoding/base64/base64_test.go            |     2 +-
 libgo/go/encoding/binary/binary.go                 |    10 +-
 libgo/go/encoding/binary/binary_test.go            |    16 +-
 libgo/go/encoding/csv/fuzz.go                      |     1 -
 libgo/go/encoding/gob/codec_test.go                |    34 +-
 libgo/go/encoding/gob/debug.go                     |     3 +-
 libgo/go/encoding/gob/decgen.go                    |     1 -
 libgo/go/encoding/gob/decode.go                    |    18 +-
 libgo/go/encoding/gob/decoder.go                   |    15 +-
 libgo/go/encoding/gob/dump.go                      |     1 -
 libgo/go/encoding/gob/encgen.go                    |     1 -
 libgo/go/encoding/gob/encode.go                    |    20 +-
 libgo/go/encoding/gob/encoder.go                   |     4 +-
 libgo/go/encoding/gob/encoder_test.go              |   161 +-
 libgo/go/encoding/gob/error.go                     |     2 +-
 libgo/go/encoding/gob/gobencdec_test.go            |     2 +-
 libgo/go/encoding/gob/timing_test.go               |    32 +-
 libgo/go/encoding/gob/type.go                      |    20 +-
 libgo/go/encoding/gob/type_test.go                 |     6 +-
 libgo/go/encoding/json/bench_test.go               |     2 +-
 libgo/go/encoding/json/decode.go                   |    38 +-
 libgo/go/encoding/json/decode_test.go              |   108 +-
 libgo/go/encoding/json/encode.go                   |    34 +-
 libgo/go/encoding/json/encode_test.go              |   112 +-
 libgo/go/encoding/json/fuzz.go                     |     9 +-
 libgo/go/encoding/json/fuzz_test.go                |    83 +
 libgo/go/encoding/json/scanner.go                  |     2 +-
 libgo/go/encoding/json/scanner_test.go             |    10 +-
 libgo/go/encoding/json/stream.go                   |     8 +-
 libgo/go/encoding/json/stream_test.go              |    70 +-
 libgo/go/encoding/json/tagkey_test.go              |     6 +-
 libgo/go/encoding/json/tags.go                     |    16 +-
 libgo/go/encoding/pem/pem.go                       |    10 +-
 libgo/go/encoding/xml/marshal.go                   |    22 +-
 libgo/go/encoding/xml/marshal_test.go              |    47 +-
 libgo/go/encoding/xml/read.go                      |    18 +-
 libgo/go/encoding/xml/read_test.go                 |     6 +-
 libgo/go/encoding/xml/typeinfo.go                  |    10 +-
 libgo/go/encoding/xml/xml.go                       |    51 +-
 libgo/go/errors/wrap.go                            |     9 +-
 libgo/go/errors/wrap_test.go                       |    18 +-
 libgo/go/expvar/expvar.go                          |    10 +-
 libgo/go/expvar/expvar_test.go                     |     8 +-
 libgo/go/flag/flag.go                              |    24 +-
 libgo/go/fmt/errors.go                             |     2 +-
 libgo/go/fmt/fmt_test.go                           |    50 +-
 libgo/go/fmt/print.go                              |    40 +-
 libgo/go/fmt/scan.go                               |    28 +-
 libgo/go/fmt/scan_test.go                          |    24 +-
 libgo/go/go.mod                                    |    13 +-
 libgo/go/go/ast/ast.go                             |    47 +-
 libgo/go/go/ast/ast_notypeparams.go                |    28 -
 libgo/go/go/ast/ast_typeparams.go                  |    51 -
 libgo/go/go/ast/print.go                           |    22 +-
 libgo/go/go/ast/print_test.go                      |     2 +-
 libgo/go/go/ast/resolve.go                         |     2 +-
 libgo/go/go/ast/scope.go                           |     8 +-
 libgo/go/go/ast/walk.go                            |    18 +-
 libgo/go/go/ast/walk_notypeparams.go               |    17 -
 libgo/go/go/ast/walk_typeparams.go                 |    36 -
 libgo/go/go/build/build.go                         |    28 +-
 libgo/go/go/build/build_test.go                    |     2 +-
 libgo/go/go/build/deps_test.go                     |    51 +-
 libgo/go/go/build/gc.go                            |     1 -
 libgo/go/go/build/gccgo.go                         |     1 -
 libgo/go/go/build/read.go                          |    29 +-
 libgo/go/go/build/read_test.go                     |    21 +-
 libgo/go/go/build/syslist.go                       |     2 +-
 libgo/go/go/constant/kind_string.go                |    28 +
 libgo/go/go/constant/value.go                      |     6 +-
 libgo/go/go/constant/value_test.go                 |    16 +-
 libgo/go/go/doc/comment.go                         |    16 +-
 libgo/go/go/doc/doc.go                             |     2 +-
 libgo/go/go/doc/doc_test.go                        |   235 +-
 libgo/go/go/doc/example.go                         |    16 +-
 libgo/go/go/doc/example_test.go                    |     6 +
 libgo/go/go/doc/exports.go                         |    58 +-
 libgo/go/go/doc/filter.go                          |     2 +
 libgo/go/go/doc/headscan.go                        |    18 +-
 libgo/go/go/doc/reader.go                          |    80 +-
 libgo/go/go/doc/testdata/benchmark.go              |     4 +-
 libgo/go/go/doc/testdata/generics.0.golden         |    76 +
 libgo/go/go/doc/testdata/generics.1.golden         |    66 +
 libgo/go/go/doc/testdata/generics.2.golden         |    76 +
 libgo/go/go/doc/testdata/generics.go               |    74 +
 libgo/go/go/doc/testdata/testing.0.golden          |    24 +-
 libgo/go/go/doc/testdata/testing.1.golden          |    40 +-
 libgo/go/go/doc/testdata/testing.2.golden          |    24 +-
 libgo/go/go/doc/testdata/testing.go                |    20 +-
 libgo/go/go/format/format.go                       |     2 +-
 libgo/go/go/importer/importer_test.go              |     3 +-
 libgo/go/go/internal/gccgoimporter/parser.go       |    36 +-
 .../internal/gccgoimporter/testdata/escapeinfo.gox |   Bin 824 -> 350 bytes
 .../go/go/internal/gccgoimporter/testdata/time.gox |   Bin 7977 -> 7499 bytes
 .../go/internal/gccgoimporter/testdata/unicode.gox |   Bin 7945 -> 7474 bytes
 .../internal/gccgoimporter/testdata/v1reflect.gox  |   Bin 10872 -> 10546 bytes
 libgo/go/go/internal/gcimporter/gcimporter_test.go |   169 +-
 libgo/go/go/internal/gcimporter/iimport.go         |   225 +-
 libgo/go/go/internal/gcimporter/support.go         |    56 +-
 .../go/go/internal/gcimporter/testdata/exports.go  |    25 +-
 .../go/go/internal/gcimporter/testdata/generics.go |    29 +
 libgo/go/go/internal/typeparams/common.go          |    10 +-
 libgo/go/go/internal/typeparams/notypeparams.go    |    40 -
 libgo/go/go/internal/typeparams/typeparams.go      |    83 +-
 libgo/go/go/parser/error_test.go                   |    24 +-
 libgo/go/go/parser/interface.go                    |     6 +-
 libgo/go/go/parser/parser.go                       |   343 +-
 libgo/go/go/parser/resolver.go                     |    33 +-
 libgo/go/go/parser/resolver_test.go                |     6 +-
 libgo/go/go/parser/short_test.go                   |    19 +-
 libgo/go/go/parser/testdata/linalg.go2             |    16 +-
 .../go/parser/testdata/resolution/typeparams.go2   |     4 +-
 libgo/go/go/printer/nodes.go                       |    65 +-
 libgo/go/go/printer/printer.go                     |    27 +-
 libgo/go/go/printer/printer_test.go                |     4 -
 libgo/go/go/printer/testdata/generics.golden       |    11 +-
 libgo/go/go/printer/testdata/generics.input        |     9 +-
 libgo/go/go/printer/testdata/parser.go             |     4 +-
 libgo/go/go/scanner/scanner.go                     |     4 +-
 libgo/go/go/scanner/scanner_test.go                |     3 +-
 libgo/go/go/token/position.go                      |     2 +-
 libgo/go/go/token/serialize.go                     |     4 +-
 libgo/go/go/token/serialize_test.go                |     4 +-
 libgo/go/go/token/token.go                         |    11 +-
 libgo/go/go/types/api.go                           |   152 +-
 libgo/go/go/types/api_notypeparams.go              |   104 -
 libgo/go/go/types/api_test.go                      |   718 +-
 libgo/go/go/types/api_typeparams.go                |    53 -
 libgo/go/go/types/api_typeparams_test.go           |   139 -
 libgo/go/go/types/array.go                         |    25 +
 libgo/go/go/types/assignments.go                   |   138 +-
 libgo/go/go/types/basic.go                         |    82 +
 libgo/go/go/types/builtins.go                      |   264 +-
 libgo/go/go/types/builtins_test.go                 |     7 +-
 libgo/go/go/types/call.go                          |   318 +-
 libgo/go/go/types/chan.go                          |    35 +
 libgo/go/go/types/check.go                         |   189 +-
 libgo/go/go/types/check_test.go                    |   141 +-
 libgo/go/go/types/context.go                       |   123 +
 libgo/go/go/types/context_test.go                  |    70 +
 libgo/go/go/types/conversions.go                   |   206 +-
 libgo/go/go/types/decl.go                          |   468 +-
 libgo/go/go/types/errorcodes.go                    |   115 +-
 libgo/go/go/types/errorcodes_test.go               |     6 +-
 libgo/go/go/types/errors.go                        |    60 +-
 libgo/go/go/types/errors_test.go                   |     1 -
 libgo/go/go/types/eval.go                          |    11 +-
 libgo/go/go/types/eval_test.go                     |    10 +-
 libgo/go/go/types/example_test.go                  |     1 -
 libgo/go/go/types/expr.go                          |   324 +-
 libgo/go/go/types/exprstring.go                    |    36 +-
 libgo/go/go/types/exprstring_test.go               |    27 +
 libgo/go/go/types/gotype.go                        |     3 +-
 libgo/go/go/types/hilbert_test.go                  |     2 +-
 libgo/go/go/types/index.go                         |   207 +-
 libgo/go/go/types/infer.go                         |   330 +-
 libgo/go/go/types/initorder.go                     |    66 +-
 libgo/go/go/types/instantiate.go                   |   275 +
 libgo/go/go/types/instantiate_test.go              |   253 +
 libgo/go/go/types/interface.go                     |   225 +
 libgo/go/go/types/issues_test.go                   |    33 +-
 libgo/go/go/types/labels.go                        |     3 +-
 libgo/go/go/types/lookup.go                        |   270 +-
 libgo/go/go/types/map.go                           |    24 +
 libgo/go/go/types/methodlist.go                    |    78 +
 libgo/go/go/types/methodlist_test.go               |    41 +
 libgo/go/go/types/methodset.go                     |    75 +-
 libgo/go/go/types/methodset_test.go                |    20 +-
 libgo/go/go/types/mono.go                          |   336 +
 libgo/go/go/types/mono_test.go                     |    97 +
 libgo/go/go/types/named.go                         |   391 +
 libgo/go/go/types/object.go                        |    71 +-
 libgo/go/go/types/object_test.go                   |   106 +-
 libgo/go/go/types/operand.go                       |   141 +-
 libgo/go/go/types/pointer.go                       |    19 +
 libgo/go/go/types/predicates.go                    |   372 +-
 libgo/go/go/types/resolver.go                      |    81 +-
 libgo/go/go/types/sanitize.go                      |   206 -
 libgo/go/go/types/scope.go                         |    97 +-
 libgo/go/go/types/self_test.go                     |     8 +-
 libgo/go/go/types/signature.go                     |   320 +
 libgo/go/go/types/sizeof_test.go                   |    23 +-
 libgo/go/go/types/sizes.go                         |    18 +-
 libgo/go/go/types/slice.go                         |    19 +
 libgo/go/go/types/stdlib_test.go                   |    13 +-
 libgo/go/go/types/stmt.go                          |   285 +-
 libgo/go/go/types/struct.go                        |   217 +
 libgo/go/go/types/subst.go                         |   480 +-
 libgo/go/go/types/termlist.go                      |   167 +
 libgo/go/go/types/termlist_test.go                 |   313 +
 libgo/go/go/types/testdata/check/builtins.go2      |   277 +-
 libgo/go/go/types/testdata/check/builtins.src      |     2 +-
 libgo/go/go/types/testdata/check/const0.src        |     2 +-
 libgo/go/go/types/testdata/check/cycles.src        |     1 +
 libgo/go/go/types/testdata/check/cycles4.src       |    15 +-
 libgo/go/go/types/testdata/check/cycles5.src       |     4 +-
 libgo/go/go/types/testdata/check/decls0.src        |    12 +-
 libgo/go/go/types/testdata/check/decls1.src        |     2 +-
 libgo/go/go/types/testdata/check/errors.src        |    28 +-
 libgo/go/go/types/testdata/check/expr1.src         |     4 +-
 libgo/go/go/types/testdata/check/expr2.src         |     6 +-
 libgo/go/go/types/testdata/check/expr3.src         |    40 +-
 libgo/go/go/types/testdata/check/issues.go2        |    78 +-
 libgo/go/go/types/testdata/check/issues.src        |    12 +-
 libgo/go/go/types/testdata/check/linalg.go2        |    77 +-
 libgo/go/go/types/testdata/check/main.go2          |     2 +-
 libgo/go/go/types/testdata/check/map2.go2          |     4 +-
 libgo/go/go/types/testdata/check/methodsets.src    |    12 +-
 libgo/go/go/types/testdata/check/shifts.src        |     2 +-
 libgo/go/go/types/testdata/check/stmt0.src         |    48 +-
 libgo/go/go/types/testdata/check/tinference.go2    |   108 -
 libgo/go/go/types/testdata/check/tmp.go2           |    17 -
 libgo/go/go/types/testdata/check/typeinst.go2      |    21 +-
 libgo/go/go/types/testdata/check/typeinst2.go2     |   136 +-
 libgo/go/go/types/testdata/check/typeparams.go2    |   309 +-
 libgo/go/go/types/testdata/check/vardecl.src       |     6 +-
 libgo/go/go/types/testdata/examples/functions.go2  |    30 +-
 libgo/go/go/types/testdata/examples/inference.go2  |    35 +-
 libgo/go/go/types/testdata/examples/methods.go2    |    16 +
 libgo/go/go/types/testdata/examples/types.go2      |   109 +-
 libgo/go/go/types/testdata/fixedbugs/issue25838.go |    26 +
 .../go/go/types/testdata/fixedbugs/issue28251.src  |     2 +-
 .../go/go/types/testdata/fixedbugs/issue39634.go2  |    27 +-
 .../go/go/types/testdata/fixedbugs/issue39680.go2  |     8 +-
 .../go/go/types/testdata/fixedbugs/issue39693.go2  |    17 +-
 .../go/go/types/testdata/fixedbugs/issue39699.go2  |     2 +-
 .../go/go/types/testdata/fixedbugs/issue39711.go2  |     6 +-
 .../go/go/types/testdata/fixedbugs/issue39723.go2  |     2 +-
 .../go/go/types/testdata/fixedbugs/issue39725.go2  |     4 +-
 .../go/go/types/testdata/fixedbugs/issue39754.go2  |     7 +-
 .../go/go/types/testdata/fixedbugs/issue39755.go2  |     4 +-
 .../go/go/types/testdata/fixedbugs/issue39768.go2  |    19 +-
 .../go/go/types/testdata/fixedbugs/issue39938.go2  |    36 +-
 .../go/go/types/testdata/fixedbugs/issue39948.go2  |     2 +-
 .../go/go/types/testdata/fixedbugs/issue39976.go2  |     2 +-
 .../go/go/types/testdata/fixedbugs/issue40038.go2  |     4 +-
 .../go/go/types/testdata/fixedbugs/issue40056.go2  |     2 +-
 .../go/go/types/testdata/fixedbugs/issue40301.go2  |     4 +-
 .../go/go/types/testdata/fixedbugs/issue40684.go2  |     6 +-
 .../go/go/types/testdata/fixedbugs/issue41124.go2  |    22 +-
 .../go/go/types/testdata/fixedbugs/issue42758.go2  |     4 +-
 libgo/go/go/types/testdata/fixedbugs/issue45114.go |     8 +
 .../go/go/types/testdata/fixedbugs/issue45548.go2  |     2 +-
 .../go/go/types/testdata/fixedbugs/issue45635.go2  |     7 +-
 .../go/go/types/testdata/fixedbugs/issue45985.go2  |     5 +-
 libgo/go/go/types/testdata/fixedbugs/issue49003.go |    10 +
 libgo/go/go/types/tuple.go                         |    34 +
 libgo/go/go/types/type.go                          |  1024 +-
 libgo/go/go/types/typelists.go                     |    69 +
 libgo/go/go/types/typeparam.go                     |   163 +
 libgo/go/go/types/types_test.go                    |    19 -
 libgo/go/go/types/typeset.go                       |   404 +
 libgo/go/go/types/typeset_test.go                  |    81 +
 libgo/go/go/types/typestring.go                    |   501 +-
 libgo/go/go/types/typestring_test.go               |    70 +-
 libgo/go/go/types/typeterm.go                      |   166 +
 libgo/go/go/types/typeterm_test.go                 |   240 +
 libgo/go/go/types/typexpr.go                       |   973 +-
 libgo/go/go/types/unify.go                         |   142 +-
 libgo/go/go/types/union.go                         |   189 +
 libgo/go/go/types/universe.go                      |   103 +-
 libgo/go/go/types/validtype.go                     |   147 +
 .../x/crypto/chacha20poly1305/chacha20poly1305.go  |     6 +-
 .../chacha20poly1305/chacha20poly1305_generic.go   |     2 +-
 .../x/crypto/chacha20poly1305/xchacha20poly1305.go |     2 +-
 libgo/go/golang.org/x/crypto/cryptobyte/asn1.go    |     7 +-
 .../golang.org/x/crypto/curve25519/curve25519.go   |    52 +-
 .../x/crypto/curve25519/internal/field/fe.go       |   416 +
 .../x/crypto/curve25519/internal/field/fe_amd64.go |    14 +
 .../curve25519/internal/field/fe_amd64_noasm.go    |    12 +
 .../x/crypto/curve25519/internal/field/fe_arm64.go |    16 +
 .../curve25519/internal/field/fe_arm64_noasm.go    |    12 +
 .../crypto/curve25519/internal/field/fe_generic.go |   264 +
 .../x/crypto/internal/poly1305/bits_compat.go      |    40 +
 .../x/crypto/internal/poly1305/bits_go1.13.go      |    22 +
 .../x/crypto/internal/poly1305/mac_noasm.go}       |     7 +-
 .../x/crypto/internal/poly1305/poly1305.go         |    99 +
 .../x/crypto/internal/poly1305/sum_amd64.go        |    48 +
 .../x/crypto/internal/poly1305/sum_generic.go      |   310 +
 .../x/crypto/internal/poly1305/sum_ppc64le.go      |    48 +
 .../x/crypto/internal/poly1305/sum_s390x.go        |    76 +
 libgo/go/golang.org/x/mod/modfile/rule.go          |   545 +-
 libgo/go/golang.org/x/mod/modfile/work.go          |   234 +
 libgo/go/golang.org/x/mod/module/module.go         |     9 +-
 libgo/go/golang.org/x/mod/semver/semver.go         |    10 -
 libgo/go/golang.org/x/mod/zip/zip.go               |   143 +-
 .../go/golang.org/x/net/dns/dnsmessage/message.go  |    22 +-
 libgo/go/golang.org/x/net/http/httpproxy/proxy.go  |     4 +-
 libgo/go/golang.org/x/net/http2/hpack/huffman.go   |    38 +-
 libgo/go/golang.org/x/net/idna/go118.go            |    14 +
 libgo/go/golang.org/x/net/idna/idna10.0.0.go       |     6 +-
 libgo/go/golang.org/x/net/idna/idna9.0.0.go        |     4 +-
 libgo/go/golang.org/x/net/idna/pre_go118.go        |    12 +
 libgo/go/golang.org/x/net/idna/punycode.go         |    36 +-
 libgo/go/golang.org/x/net/lif/address.go           |     1 +
 libgo/go/golang.org/x/net/lif/binary.go            |     1 +
 libgo/go/golang.org/x/net/lif/lif.go               |     1 +
 libgo/go/golang.org/x/net/lif/link.go              |     1 +
 libgo/go/golang.org/x/net/lif/sys.go               |     1 +
 libgo/go/golang.org/x/net/lif/syscall.go           |     1 +
 libgo/go/golang.org/x/net/nettest/nettest.go       |    14 +-
 libgo/go/golang.org/x/net/route/address.go         |     4 +
 libgo/go/golang.org/x/net/route/message.go         |     2 +-
 libgo/go/golang.org/x/net/route/sys_freebsd.go     |     3 -
 libgo/go/golang.org/x/net/route/syscall.go         |    26 +-
 libgo/go/golang.org/x/sync/AUTHORS                 |     3 +
 libgo/go/golang.org/x/sync/CONTRIBUTORS            |     3 +
 libgo/go/golang.org/x/sync/LICENSE                 |    27 +
 libgo/go/golang.org/x/sync/PATENTS                 |    22 +
 libgo/go/golang.org/x/sync/semaphore/semaphore.go  |   136 +
 libgo/go/golang.org/x/sys/cpu/cpu.go               |     1 +
 libgo/go/golang.org/x/sys/cpu/cpu_gc_x86.go        |     4 -
 libgo/go/golang.org/x/sys/cpu/cpu_x86.go           |     9 +-
 libgo/go/golang.org/x/text/unicode/bidi/core.go    |     6 +-
 libgo/go/golang.org/x/tools/cover/profile.go       |    11 +-
 .../x/tools/go/analysis/internal/facts/imports.go  |    33 +-
 .../x/tools/go/analysis/passes/asmdecl/asmdecl.go  |    37 +-
 .../go/analysis/passes/composite/composite.go      |    73 +-
 .../tools/go/analysis/passes/copylock/copylock.go  |    75 +-
 .../tools/go/analysis/passes/ctrlflow/ctrlflow.go  |     6 +-
 .../go/analysis/passes/ifaceassert/ifaceassert.go  |     6 +
 .../analysis/passes/ifaceassert/parameterized.go   |   112 +
 .../x/tools/go/analysis/passes/nilfunc/nilfunc.go  |     7 +
 .../x/tools/go/analysis/passes/printf/printf.go    |    76 +-
 .../x/tools/go/analysis/passes/printf/types.go     |   213 +-
 .../x/tools/go/analysis/passes/shift/shift.go      |    36 +-
 .../go/analysis/passes/stdmethods/stdmethods.go    |     6 +-
 .../go/analysis/passes/stringintconv/string.go     |   149 +-
 .../passes/testinggoroutine/testinggoroutine.go    |    42 +-
 .../x/tools/go/analysis/passes/tests/tests.go      |    70 +-
 .../go/analysis/passes/unmarshal/unmarshal.go      |     3 +-
 .../analysis/passes/unusedresult/unusedresult.go   |     6 +
 .../x/tools/go/analysis/unitchecker/unitchecker.go |     3 +
 .../golang.org/x/tools/go/ast/astutil/enclosing.go |    20 +-
 .../golang.org/x/tools/go/ast/astutil/rewrite.go   |     6 +
 .../golang.org/x/tools/go/ast/inspector/typeof.go  |     9 +-
 .../x/tools/go/types/objectpath/objectpath.go      |   153 +-
 .../golang.org/x/tools/go/types/typeutil/callee.go |    29 +-
 .../go/golang.org/x/tools/go/types/typeutil/map.go |   138 +-
 .../golang.org/x/tools/internal/lsp/fuzzy/input.go |    37 +-
 .../x/tools/internal/lsp/fuzzy/matcher.go          |    23 +-
 .../x/tools/internal/lsp/fuzzy/symbol.go           |   236 +
 .../x/tools/internal/typeparams/common.go          |    79 +
 .../x/tools/internal/typeparams/enabled_go117.go   |    12 +
 .../x/tools/internal/typeparams/enabled_go118.go   |    15 +
 .../x/tools/internal/typeparams/normalize.go       |   216 +
 .../x/tools/internal/typeparams/termlist.go        |   172 +
 .../tools/internal/typeparams/typeparams_go117.go  |   192 +
 .../tools/internal/typeparams/typeparams_go118.go  |   146 +
 .../x/tools/internal/typeparams/typeterm.go        |   170 +
 .../x/tools}/txtar/archive.go                      |     6 +-
 libgo/go/hash/crc32/crc32_otherarch.go             |     1 -
 libgo/go/hash/crc32/gen_const_ppc64le.go           |     1 -
 libgo/go/html/fuzz.go                              |     1 -
 libgo/go/html/template/attr.go                     |     6 +-
 libgo/go/html/template/content.go                  |    12 +-
 libgo/go/html/template/content_test.go             |     4 +-
 libgo/go/html/template/context.go                  |     4 +
 libgo/go/html/template/css.go                      |     4 +-
 libgo/go/html/template/error.go                    |     2 +-
 libgo/go/html/template/escape.go                   |    79 +-
 libgo/go/html/template/escape_test.go              |    36 +-
 libgo/go/html/template/example_test.go             |     2 +-
 libgo/go/html/template/exec_test.go                |    38 +-
 libgo/go/html/template/html.go                     |    12 +-
 libgo/go/html/template/js.go                       |    16 +-
 libgo/go/html/template/js_test.go                  |    14 +-
 libgo/go/html/template/template.go                 |     8 +-
 libgo/go/html/template/template_test.go            |     2 +-
 libgo/go/html/template/url.go                      |    14 +-
 libgo/go/html/template/url_test.go                 |     2 +-
 libgo/go/image/color/palette/gen.go                |     1 -
 libgo/go/image/draw/bench_test.go                  |    12 +
 libgo/go/image/draw/draw.go                        |   329 +-
 libgo/go/image/draw/draw_test.go                   |   272 +-
 libgo/go/image/gif/fuzz_test.go                    |    61 +
 libgo/go/image/internal/imageutil/gen.go           |     1 -
 libgo/go/image/jpeg/fuzz_test.go                   |    61 +
 libgo/go/image/png/fuzz.go                         |     1 -
 libgo/go/image/png/fuzz_test.go                    |    68 +
 libgo/go/image/png/reader.go                       |    10 +-
 libgo/go/index/suffixarray/gen.go                  |     1 -
 libgo/go/internal/buildcfg/cfg.go                  |    16 +
 libgo/go/internal/buildcfg/cfg_test.go             |    26 +
 libgo/go/internal/buildcfg/exp.go                  |    31 +-
 libgo/go/internal/bytealg/bytealg.go               |     1 -
 libgo/go/internal/bytealg/compare_generic.go       |     3 +-
 libgo/go/internal/bytealg/compare_native.go        |     1 -
 libgo/go/internal/bytealg/count_generic.go         |     1 -
 libgo/go/internal/bytealg/count_native.go          |     3 +-
 libgo/go/internal/bytealg/index_generic.go         |     3 +-
 libgo/go/internal/bytealg/index_native.go          |     1 -
 libgo/go/internal/bytealg/index_ppc64x.go          |     3 +-
 libgo/go/internal/bytealg/indexbyte_generic.go     |     3 +-
 libgo/go/internal/bytealg/indexbyte_native.go      |     1 -
 libgo/go/internal/cfg/cfg.go                       |     1 +
 libgo/go/internal/cpu/cpu.go                       |    10 +-
 libgo/go/internal/cpu/cpu_amd64.go                 |     7 -
 libgo/go/internal/cpu/cpu_amd64p32.go              |     7 -
 libgo/go/internal/cpu/cpu_arm64_android.go         |     1 -
 libgo/go/internal/cpu/cpu_arm64_darwin.go          |     1 -
 libgo/go/internal/cpu/cpu_arm64_freebsd.go         |     1 -
 libgo/go/internal/cpu/cpu_arm64_hwcap.go           |     1 -
 libgo/go/internal/cpu/cpu_arm64_linux.go           |     1 -
 libgo/go/internal/cpu/cpu_arm64_other.go           |     5 -
 libgo/go/internal/cpu/cpu_mips64x.go               |     1 -
 libgo/go/internal/cpu/cpu_no_name.go               |     1 -
 libgo/go/internal/cpu/cpu_ppc64x.go                |     1 -
 libgo/go/internal/cpu/cpu_ppc64x_aix.go            |     1 -
 libgo/go/internal/cpu/cpu_ppc64x_linux.go          |     1 -
 libgo/go/internal/cpu/cpu_test.go                  |    23 +-
 libgo/go/internal/cpu/cpu_x86.go                   |    21 +-
 libgo/go/internal/cpu/cpu_x86_test.go              |    23 +-
 libgo/go/internal/fmtsort/sort.go                  |     2 +-
 libgo/go/internal/fmtsort/sort_test.go             |    27 +-
 libgo/go/internal/fuzz/counters_supported.go       |    29 +
 libgo/go/internal/fuzz/counters_unsupported.go     |    24 +
 libgo/go/internal/fuzz/coverage.go                 |    96 +
 libgo/go/internal/fuzz/encoding.go                 |   240 +
 libgo/go/internal/fuzz/encoding_test.go            |   172 +
 libgo/go/internal/fuzz/fuzz.go                     |  1081 ++
 libgo/go/internal/fuzz/mem.go                      |   140 +
 libgo/go/internal/fuzz/minimize.go                 |    95 +
 libgo/go/internal/fuzz/minimize_test.go            |   182 +
 libgo/go/internal/fuzz/mutator.go                  |   303 +
 libgo/go/internal/fuzz/mutator_test.go             |   117 +
 libgo/go/internal/fuzz/mutators_byteslice.go       |   313 +
 libgo/go/internal/fuzz/mutators_byteslice_test.go  |   186 +
 libgo/go/internal/fuzz/pcg.go                      |   145 +
 libgo/go/internal/fuzz/queue.go                    |    71 +
 libgo/go/internal/fuzz/queue_test.go               |    58 +
 libgo/go/internal/fuzz/sys_posix.go                |   130 +
 libgo/go/internal/fuzz/sys_unimplemented.go        |    44 +
 libgo/go/internal/fuzz/sys_windows.go              |   152 +
 libgo/go/internal/fuzz/trace.go                    |    29 +
 libgo/go/internal/fuzz/worker.go                   |  1173 ++
 libgo/go/internal/fuzz/worker_test.go              |   206 +
 .../sys/arch.go => internal/goarch/goarch.go}      |     8 +-
 libgo/go/internal/godebug/godebug.go               |    34 +
 libgo/go/internal/godebug/godebug_test.go          |    34 +
 .../goexperiment/exp_heapminimum512kib_off.go      |     9 +
 .../goexperiment/exp_heapminimum512kib_on.go       |     9 +
 .../internal/goexperiment/exp_pacerredesign_off.go |     9 +
 .../internal/goexperiment/exp_pacerredesign_on.go  |     9 +
 libgo/go/internal/goexperiment/exp_regabi_off.go   |     9 -
 libgo/go/internal/goexperiment/exp_regabi_on.go    |     9 -
 .../internal/goexperiment/exp_regabidefer_off.go   |     9 -
 .../go/internal/goexperiment/exp_regabidefer_on.go |     9 -
 libgo/go/internal/goexperiment/exp_regabig_off.go  |     9 -
 libgo/go/internal/goexperiment/exp_regabig_on.go   |     9 -
 libgo/go/internal/goexperiment/exp_unified_off.go  |     9 +
 libgo/go/internal/goexperiment/exp_unified_on.go   |     9 +
 libgo/go/internal/goexperiment/flags.go            |    32 +-
 libgo/go/internal/goos/goos.go                     |     6 +
 libgo/go/internal/goroot/gc.go                     |     1 -
 libgo/go/internal/goroot/gccgo.go                  |     1 -
 libgo/go/internal/goversion/goversion.go           |     2 +-
 libgo/go/internal/intern/intern.go                 |   178 +
 libgo/go/internal/intern/intern_test.go            |   205 +
 libgo/go/internal/lazytemplate/lazytemplate.go     |     2 +-
 libgo/go/internal/nettrace/nettrace.go             |     2 +-
 libgo/go/internal/poll/errno_unix.go               |     1 -
 libgo/go/internal/poll/errno_windows.go            |     1 -
 libgo/go/internal/poll/error_stub_test.go          |     1 -
 libgo/go/internal/poll/export_posix_test.go        |     1 -
 libgo/go/internal/poll/fcntl_js.go                 |     1 -
 libgo/go/internal/poll/fcntl_libc.go               |     1 -
 libgo/go/internal/poll/fcntl_syscall.go            |     1 -
 libgo/go/internal/poll/fd_fsync_posix.go           |     1 -
 libgo/go/internal/poll/fd_poll_js.go               |     1 -
 libgo/go/internal/poll/fd_poll_runtime.go          |     1 -
 libgo/go/internal/poll/fd_posix.go                 |     1 -
 libgo/go/internal/poll/fd_posix_test.go            |     1 -
 libgo/go/internal/poll/fd_unix.go                  |   214 +-
 libgo/go/internal/poll/fd_windows.go               |   316 +-
 libgo/go/internal/poll/fd_writev_darwin.go         |     1 -
 libgo/go/internal/poll/fd_writev_illumos.go        |     1 -
 libgo/go/internal/poll/fd_writev_unix.go           |     1 -
 libgo/go/internal/poll/hook_cloexec.go             |     1 -
 libgo/go/internal/poll/hook_unix.go                |     1 -
 libgo/go/internal/poll/iovec_illumos.go            |     1 -
 libgo/go/internal/poll/iovec_unix.go               |     1 -
 libgo/go/internal/poll/sendfile_bsd.go             |     3 +-
 libgo/go/internal/poll/sock_cloexec.go             |     1 -
 libgo/go/internal/poll/sockopt.go                  |     1 -
 libgo/go/internal/poll/sockopt_unix.go             |     1 -
 libgo/go/internal/poll/sockoptip.go                |     1 -
 libgo/go/internal/poll/splice_linux.go             |    14 +-
 libgo/go/internal/poll/splice_linux_test.go        |    52 +-
 libgo/go/internal/poll/strconv.go                  |     1 -
 libgo/go/internal/poll/sys_cloexec.go              |     1 -
 libgo/go/internal/poll/writev.go                   |     1 -
 libgo/go/internal/profile/legacy_profile.go        |    10 +-
 libgo/go/internal/reflectlite/all_test.go          |    32 +-
 libgo/go/internal/reflectlite/export_test.go       |     2 +-
 libgo/go/internal/reflectlite/set_test.go          |    12 +-
 libgo/go/internal/reflectlite/swapper.go           |     5 +-
 libgo/go/internal/reflectlite/tostring_test.go     |     2 +-
 libgo/go/internal/reflectlite/type.go              |     6 +-
 libgo/go/internal/reflectlite/value.go             |    39 +-
 libgo/go/internal/singleflight/singleflight.go     |    10 +-
 .../go/internal/singleflight/singleflight_test.go  |     6 +-
 .../go/internal/syscall/execenv/execenv_default.go |     1 -
 .../go/internal/syscall/execenv/execenv_windows.go |     1 -
 libgo/go/internal/syscall/unix/at.go               |     1 -
 .../go/internal/syscall/unix/getentropy_darwin.go  |    33 -
 libgo/go/internal/syscall/unix/getrandom.go        |     1 -
 libgo/go/internal/syscall/unix/net.go              |    44 +
 libgo/go/internal/syscall/unix/net_js.go           |    44 +
 libgo/go/internal/syscall/unix/nonblocking.go      |     1 -
 libgo/go/internal/syscall/unix/nonblocking_js.go   |     1 -
 libgo/go/internal/syscall/unix/nonblocking_libc.go |     1 -
 .../internal/syscall/unix/sysnum_linux_generic.go  |     2 -
 .../internal/syscall/unix/sysnum_linux_mips64x.go  |     1 -
 .../go/internal/syscall/unix/sysnum_linux_mipsx.go |     1 -
 .../internal/syscall/unix/sysnum_linux_ppc64x.go   |     1 -
 .../internal/syscall/windows/exec_windows_test.go  |     2 +-
 libgo/go/internal/syscall/windows/mksyscall.go     |     2 +-
 libgo/go/internal/syscall/windows/net_windows.go   |    18 +
 .../syscall/windows/registry/export_test.go        |     2 +-
 libgo/go/internal/syscall/windows/registry/key.go  |    13 +-
 .../internal/syscall/windows/registry/mksyscall.go |     2 +-
 .../syscall/windows/registry/registry_test.go      |     4 +-
 .../internal/syscall/windows/registry/syscall.go   |     2 +-
 .../go/internal/syscall/windows/registry/value.go  |     2 +-
 libgo/go/internal/syscall/windows/sysdll/sysdll.go |     2 +-
 libgo/go/internal/testenv/testenv.go               |    58 +
 libgo/go/internal/testenv/testenv_cgo.go           |     1 -
 .../testenv/testenv_notunix.go}                    |     9 +-
 libgo/go/internal/testenv/testenv_notwin.go        |     1 -
 libgo/go/internal/testenv/testenv_unix.go          |    13 +
 libgo/go/internal/trace/gc.go                      |     8 +-
 .../go/internal/unsafeheader/unsafeheader_test.go  |     2 +-
 libgo/go/io/example_test.go                        |    29 +-
 libgo/go/io/fs/fs.go                               |     2 +-
 libgo/go/io/io.go                                  |    42 +-
 libgo/go/io/io_test.go                             |    14 +
 libgo/go/io/multi_test.go                          |     4 +-
 libgo/go/io/pipe.go                                |    50 +-
 libgo/go/log/log.go                                |    85 +-
 libgo/go/log/log_test.go                           |    14 +-
 libgo/go/log/syslog/example_test.go                |     1 -
 libgo/go/log/syslog/syslog.go                      |     1 -
 libgo/go/log/syslog/syslog_test.go                 |    95 +-
 libgo/go/log/syslog/syslog_unix.go                 |     1 -
 libgo/go/math/all_test.go                          |     2 +-
 libgo/go/math/big/float.go                         |     4 +-
 libgo/go/math/big/floatconv_test.go                |     2 +-
 libgo/go/math/big/rat.go                           |     2 +-
 libgo/go/math/big/rat_test.go                      |    18 +
 libgo/go/math/big/ratconv.go                       |     5 +
 libgo/go/math/big/ratconv_test.go                  |     1 +
 libgo/go/math/bits/example_math_test.go            |   202 +
 libgo/go/math/bits/make_examples.go                |    20 +-
 libgo/go/math/cmplx/huge_test.go                   |     1 -
 libgo/go/math/dim_noasm.go                         |     1 -
 libgo/go/math/example_test.go                      |     5 +
 libgo/go/math/exp2_noasm.go                        |     1 -
 libgo/go/math/exp_amd64.go                         |     1 -
 libgo/go/math/exp_noasm.go                         |     1 -
 libgo/go/math/floor_noasm.go                       |     1 -
 libgo/go/math/huge_test.go                         |     1 -
 libgo/go/math/modf_noasm.go                        |     1 -
 libgo/go/math/rand/gen_cooked.go                   |     1 -
 libgo/go/math/rand/regress_test.go                 |     6 +-
 libgo/go/math/stubs.go                             |     1 -
 libgo/go/mime/encodedword.go                       |    22 +-
 libgo/go/mime/mediatype.go                         |    17 +-
 libgo/go/mime/mediatype_test.go                    |    17 +-
 libgo/go/mime/quotedprintable/reader_test.go       |     4 +-
 libgo/go/mime/type.go                              |     2 +-
 libgo/go/mime/type_unix.go                         |     1 -
 libgo/go/mime/type_unix_test.go                    |     1 -
 libgo/go/net/addrselect.go                         |     1 -
 libgo/go/net/addrselect_test.go                    |     1 -
 libgo/go/net/cgo_aix.go                            |     1 -
 libgo/go/net/cgo_android.go                        |     1 -
 libgo/go/net/cgo_bsd.go                            |     3 -
 libgo/go/net/cgo_linux.go                          |     1 -
 libgo/go/net/cgo_netbsd.go                         |     1 -
 libgo/go/net/cgo_openbsd.go                        |     1 -
 libgo/go/net/cgo_resnew.go                         |     3 -
 libgo/go/net/cgo_resold.go                         |     3 -
 libgo/go/net/cgo_socknew.go                        |     3 -
 libgo/go/net/cgo_sockold.go                        |     3 -
 libgo/go/net/cgo_solaris.go                        |     1 -
 libgo/go/net/cgo_stub.go                           |     1 -
 libgo/go/net/cgo_unix.go                           |     5 +-
 libgo/go/net/cgo_unix_test.go                      |     3 -
 libgo/go/net/cgo_windows.go                        |     1 -
 libgo/go/net/conf.go                               |     4 +-
 libgo/go/net/conf_netcgo.go                        |     1 -
 libgo/go/net/conf_test.go                          |     1 -
 libgo/go/net/conn_test.go                          |     8 +-
 libgo/go/net/dial_test.go                          |    73 +-
 libgo/go/net/dial_unix_test.go                     |    13 +-
 libgo/go/net/dnsclient.go                          |    21 +-
 libgo/go/net/dnsclient_unix.go                     |     1 -
 libgo/go/net/dnsclient_unix_test.go                |    42 +-
 libgo/go/net/dnsconfig_unix.go                     |     1 -
 libgo/go/net/dnsconfig_unix_test.go                |     1 -
 libgo/go/net/dnsname_test.go                       |     1 -
 libgo/go/net/error_plan9_test.go                   |     4 +
 libgo/go/net/error_posix.go                        |     1 -
 libgo/go/net/error_posix_test.go                   |     1 -
 libgo/go/net/error_test.go                         |    16 +-
 libgo/go/net/error_unix.go                         |     1 -
 libgo/go/net/error_unix_test.go                    |     6 +-
 libgo/go/net/error_windows_test.go                 |    12 +-
 libgo/go/net/example_test.go                       |   206 +
 libgo/go/net/external_test.go                      |     1 -
 libgo/go/net/fcntl_libc_test.go                    |     1 -
 libgo/go/net/fcntl_syscall_test.go                 |     1 -
 libgo/go/net/fd_posix.go                           |    48 +-
 libgo/go/net/fd_unix.go                            |     9 +-
 libgo/go/net/file_stub.go                          |     1 -
 libgo/go/net/file_test.go                          |    36 +-
 libgo/go/net/file_unix.go                          |     1 -
 libgo/go/net/hook_unix.go                          |     1 -
 libgo/go/net/hosts.go                              |    15 +-
 libgo/go/net/hosts_test.go                         |     4 +-
 libgo/go/net/http/cgi/child.go                     |     4 +-
 libgo/go/net/http/cgi/host.go                      |     7 +-
 libgo/go/net/http/cgi/host_test.go                 |    10 +-
 libgo/go/net/http/cgi/posix_test.go                |     1 -
 libgo/go/net/http/client.go                        |     1 -
 libgo/go/net/http/client_test.go                   |   188 +-
 libgo/go/net/http/clientserver_test.go             |    44 +-
 libgo/go/net/http/cookie.go                        |    60 +-
 libgo/go/net/http/cookie_test.go                   |    27 +-
 libgo/go/net/http/export_test.go                   |     7 +-
 libgo/go/net/http/fs.go                            |    22 +-
 libgo/go/net/http/fs_test.go                       |    25 +-
 libgo/go/net/http/h2_bundle.go                     |  1832 ++-
 libgo/go/net/http/header.go                        |    11 +-
 libgo/go/net/http/header_test.go                   |    13 +
 libgo/go/net/http/httptrace/trace.go               |     2 +-
 libgo/go/net/http/httputil/dump.go                 |     2 +-
 libgo/go/net/http/httputil/dump_test.go            |     2 +-
 libgo/go/net/http/httputil/reverseproxy.go         |     5 +-
 libgo/go/net/http/httputil/reverseproxy_test.go    |    20 +
 libgo/go/net/http/internal/chunked.go              |    16 +-
 libgo/go/net/http/internal/chunked_test.go         |    28 +
 libgo/go/net/http/internal/testcert/testcert.go    |    69 +-
 libgo/go/net/http/main_test.go                     |     9 +-
 libgo/go/net/http/omithttp2.go                     |     7 +-
 libgo/go/net/http/pprof/pprof.go                   |     2 +-
 libgo/go/net/http/pprof/pprof_test.go              |     5 +
 libgo/go/net/http/request.go                       |    44 +-
 libgo/go/net/http/request_test.go                  |     8 +-
 libgo/go/net/http/requestwrite_test.go             |     2 +-
 libgo/go/net/http/response.go                      |    15 +-
 libgo/go/net/http/response_test.go                 |    16 +-
 libgo/go/net/http/roundtrip.go                     |     1 -
 libgo/go/net/http/roundtrip_js.go                  |    43 +-
 libgo/go/net/http/serve_test.go                    |   219 +-
 libgo/go/net/http/server.go                        |   101 +-
 libgo/go/net/http/server_test.go                   |    53 +
 libgo/go/net/http/transfer.go                      |    12 +-
 libgo/go/net/http/transport.go                     |    20 +-
 libgo/go/net/http/transport_default_js.go          |    17 +
 libgo/go/net/http/transport_default_other.go       |    17 +
 libgo/go/net/http/transport_test.go                |    39 +-
 libgo/go/net/http/triv.go                          |     1 -
 libgo/go/net/interface_aix.go                      |     2 +-
 libgo/go/net/interface_bsd.go                      |     1 -
 libgo/go/net/interface_bsd_test.go                 |     1 -
 libgo/go/net/interface_bsdvar.go                   |     1 -
 libgo/go/net/interface_freebsd.go                  |    11 +-
 libgo/go/net/interface_stub.go                     |     1 -
 libgo/go/net/interface_test.go                     |     1 -
 libgo/go/net/interface_unix_test.go                |     1 -
 libgo/go/net/internal/socktest/main_test.go        |     1 -
 libgo/go/net/internal/socktest/main_unix_test.go   |     1 -
 libgo/go/net/internal/socktest/switch_posix.go     |     1 -
 libgo/go/net/internal/socktest/switch_stub.go      |     1 -
 libgo/go/net/internal/socktest/switch_unix.go      |     1 -
 libgo/go/net/internal/socktest/sys_cloexec.go      |     1 -
 libgo/go/net/internal/socktest/sys_unix.go         |     1 -
 libgo/go/net/ip.go                                 |     5 +-
 libgo/go/net/ip_test.go                            |     4 +-
 libgo/go/net/iprawsock_posix.go                    |     1 -
 libgo/go/net/iprawsock_test.go                     |     1 -
 libgo/go/net/ipsock_posix.go                       |   107 +-
 libgo/go/net/listen_test.go                        |    32 +-
 libgo/go/net/lookup.go                             |    82 +-
 libgo/go/net/lookup_fake.go                        |     1 -
 libgo/go/net/lookup_plan9.go                       |    10 +-
 libgo/go/net/lookup_test.go                        |    97 +-
 libgo/go/net/lookup_unix.go                        |     1 -
 libgo/go/net/lookup_windows.go                     |    14 +-
 libgo/go/net/lookup_windows_test.go                |    12 +-
 libgo/go/net/mail/message.go                       |     4 +-
 libgo/go/net/main_cloexec_test.go                  |     1 -
 libgo/go/net/main_conf_test.go                     |     1 -
 libgo/go/net/main_noconf_test.go                   |     1 -
 libgo/go/net/main_posix_test.go                    |     5 +-
 libgo/go/net/main_test.go                          |     8 +-
 libgo/go/net/main_unix_test.go                     |     1 -
 libgo/go/net/mockserver_test.go                    |   168 +-
 libgo/go/net/net.go                                |    14 +-
 libgo/go/net/net_fake.go                           |    33 +-
 libgo/go/net/net_test.go                           |    79 +-
 libgo/go/net/netip/export_test.go                  |    30 +
 libgo/go/net/netip/fuzz_test.go                    |   353 +
 libgo/go/net/netip/inlining_test.go                |   110 +
 libgo/go/net/netip/leaf_alts.go                    |    54 +
 libgo/go/net/netip/netip.go                        |  1498 ++
 libgo/go/net/netip/netip_pkg_test.go               |   359 +
 libgo/go/net/netip/netip_test.go                   |  1974 +++
 libgo/go/net/netip/slow_test.go                    |   190 +
 libgo/go/net/netip/uint128.go                      |    92 +
 libgo/go/net/netip/uint128_test.go                 |    89 +
 libgo/go/net/nss.go                                |     1 -
 libgo/go/net/nss_test.go                           |     1 -
 libgo/go/net/packetconn_test.go                    |    41 +-
 libgo/go/net/parse.go                              |    33 +-
 libgo/go/net/parse_test.go                         |    27 -
 libgo/go/net/platform_test.go                      |    12 +-
 libgo/go/net/port_unix.go                          |     1 -
 libgo/go/net/protoconn_test.go                     |    10 +-
 libgo/go/net/rawconn_stub_test.go                  |     1 -
 libgo/go/net/rawconn_test.go                       |    16 +-
 libgo/go/net/rawconn_unix_test.go                  |     1 -
 libgo/go/net/rpc/client.go                         |    22 +-
 libgo/go/net/rpc/client_test.go                    |     8 +-
 libgo/go/net/rpc/debug.go                          |     2 +-
 libgo/go/net/rpc/jsonrpc/all_test.go               |     6 +-
 libgo/go/net/rpc/jsonrpc/client.go                 |    12 +-
 libgo/go/net/rpc/jsonrpc/server.go                 |    10 +-
 libgo/go/net/rpc/server.go                         |    52 +-
 libgo/go/net/rpc/server_test.go                    |     8 +-
 libgo/go/net/sendfile_stub.go                      |     3 +-
 libgo/go/net/sendfile_test.go                      |    26 +-
 libgo/go/net/sendfile_unix_alt.go                  |     3 +-
 libgo/go/net/server_test.go                        |    69 +-
 libgo/go/net/smtp/smtp.go                          |    10 +-
 libgo/go/net/smtp/smtp_test.go                     |     2 +-
 libgo/go/net/sock_bsd.go                           |     1 -
 libgo/go/net/sock_cloexec.go                       |     1 -
 libgo/go/net/sock_posix.go                         |     1 -
 libgo/go/net/sock_stub.go                          |     1 -
 libgo/go/net/sockaddr_posix.go                     |     1 -
 libgo/go/net/sockopt_bsd.go                        |     1 -
 libgo/go/net/sockopt_posix.go                      |     1 -
 libgo/go/net/sockopt_stub.go                       |     1 -
 libgo/go/net/sockoptip_bsdvar.go                   |     1 -
 libgo/go/net/sockoptip_posix.go                    |     1 -
 libgo/go/net/sockoptip_stub.go                     |     7 -
 libgo/go/net/splice_stub.go                        |     1 -
 libgo/go/net/splice_test.go                        |    74 +-
 libgo/go/net/sys_cloexec.go                        |     1 -
 libgo/go/net/tcpsock.go                            |    26 +
 libgo/go/net/tcpsock_posix.go                      |     1 -
 libgo/go/net/tcpsock_test.go                       |    26 +-
 libgo/go/net/tcpsock_unix_test.go                  |     6 +-
 libgo/go/net/tcpsockopt_posix.go                   |     1 -
 libgo/go/net/tcpsockopt_stub.go                    |     1 -
 libgo/go/net/tcpsockopt_unix.go                    |     1 -
 libgo/go/net/textproto/reader.go                   |    28 +-
 libgo/go/net/textproto/textproto.go                |     2 +-
 libgo/go/net/textproto/writer.go                   |     2 +-
 libgo/go/net/timeout_test.go                       |   469 +-
 libgo/go/net/udpsock.go                            |    81 +-
 libgo/go/net/udpsock_plan9.go                      |    32 +-
 libgo/go/net/udpsock_posix.go                      |   145 +-
 libgo/go/net/udpsock_test.go                       |   168 +-
 libgo/go/net/unixsock_posix.go                     |     1 -
 libgo/go/net/unixsock_readmsg_cloexec.go           |     1 -
 libgo/go/net/unixsock_readmsg_cmsg_cloexec.go      |     1 -
 libgo/go/net/unixsock_readmsg_other.go             |     1 -
 libgo/go/net/unixsock_readmsg_test.go              |     1 -
 libgo/go/net/unixsock_test.go                      |    32 +-
 libgo/go/net/unixsock_windows_test.go              |    10 +-
 libgo/go/net/url/url.go                            |    60 +-
 libgo/go/net/url/url_test.go                       |    20 +-
 libgo/go/net/write_unix_test.go                    |     1 -
 libgo/go/net/writev_test.go                        |     6 +-
 libgo/go/net/writev_unix.go                        |     1 -
 libgo/go/os/env_test.go                            |    38 +-
 libgo/go/os/env_unix_test.go                       |     1 -
 libgo/go/os/error_errno.go                         |     1 -
 libgo/go/os/error_posix.go                         |     1 -
 libgo/go/os/error_unix_test.go                     |     1 -
 libgo/go/os/error_windows_test.go                  |     1 -
 libgo/go/os/exec.go                                |     6 +-
 libgo/go/os/exec/exec.go                           |    12 +-
 libgo/go/os/exec/exec_linux_test.go                |     1 -
 libgo/go/os/exec/exec_posix_test.go                |     1 -
 libgo/go/os/exec/exec_test.go                      |   165 +-
 libgo/go/os/exec/exec_unix.go                      |     1 -
 libgo/go/os/exec/exec_windows_test.go              |    15 +-
 libgo/go/os/exec/internal/fdtest/exists_js.go      |    18 +
 libgo/go/os/exec/internal/fdtest/exists_plan9.go   |    20 +
 libgo/go/os/exec/internal/fdtest/exists_test.go    |    21 +
 libgo/go/os/exec/internal/fdtest/exists_unix.go    |    19 +
 libgo/go/os/exec/internal/fdtest/exists_windows.go |    12 +
 libgo/go/os/exec/lp_js.go                          |     1 -
 libgo/go/os/exec/lp_unix.go                        |     1 -
 libgo/go/os/exec/lp_unix_test.go                   |     1 -
 libgo/go/os/exec/read3.go                          |    93 +-
 libgo/go/os/exec_plan9.go                          |     4 +-
 libgo/go/os/exec_posix.go                          |     5 +-
 libgo/go/os/exec_unix.go                           |     1 -
 libgo/go/os/exec_unix_test.go                      |     1 -
 libgo/go/os/executable_path.go                     |     1 -
 libgo/go/os/executable_plan9.go                    |     1 -
 libgo/go/os/executable_procfs.go                   |     1 -
 libgo/go/os/executable_sysctl.go                   |     1 -
 libgo/go/os/export_unix_test.go                    |     1 -
 libgo/go/os/fifo_test.go                           |     1 -
 libgo/go/os/file.go                                |     4 +-
 libgo/go/os/file_plan9.go                          |     2 +-
 libgo/go/os/file_posix.go                          |     3 +-
 libgo/go/os/file_unix.go                           |     1 -
 libgo/go/os/os_test.go                             |   122 +-
 libgo/go/os/os_unix_test.go                        |     1 -
 libgo/go/os/path_test.go                           |     7 +-
 libgo/go/os/path_unix.go                           |     1 -
 libgo/go/os/pipe2_bsd.go                           |     1 -
 libgo/go/os/pipe2_illumos.go                       |     1 -
 libgo/go/os/pipe_bsd.go                            |     1 -
 libgo/go/os/pipe_test.go                           |     6 -
 libgo/go/os/rawconn.go                             |     1 -
 libgo/go/os/rawconn_test.go                        |     1 -
 libgo/go/os/readfrom_stub.go                       |     1 -
 libgo/go/os/removeall_at.go                        |     1 -
 libgo/go/os/removeall_noat.go                      |     1 -
 libgo/go/os/signal/example_unix_test.go            |     1 -
 libgo/go/os/signal/internal/pty/pty.go             |     4 +-
 libgo/go/os/signal/signal_cgo_test.go              |     2 -
 libgo/go/os/signal/signal_linux_test.go            |     1 -
 libgo/go/os/signal/signal_test.go                  |     4 +-
 libgo/go/os/signal/signal_unix.go                  |     1 -
 libgo/go/os/stat_js.go                             |     1 -
 libgo/go/os/stat_plan9.go                          |     2 +-
 libgo/go/os/stat_unix.go                           |     1 -
 libgo/go/os/sticky_bsd.go                          |     1 -
 libgo/go/os/sticky_notbsd.go                       |     8 -
 libgo/go/os/sys_bsd.go                             |     1 -
 libgo/go/os/sys_js.go                              |     1 -
 libgo/go/os/sys_unix.go                            |     1 -
 libgo/go/os/timeout_test.go                        |     1 -
 libgo/go/os/types_plan9.go                         |     4 +-
 libgo/go/os/types_unix.go                          |     3 +-
 libgo/go/os/types_windows.go                       |     2 +-
 libgo/go/os/user/cgo_listgroups_unix.go            |    43 +
 libgo/go/os/user/cgo_lookup_unix.go                |     7 +-
 libgo/go/os/user/cgo_unix_test.go                  |     3 -
 libgo/go/os/user/decls_solaris.go                  |     3 -
 libgo/go/os/user/getgrouplist_unix.go              |    30 +
 libgo/go/os/user/listgroups_aix.go                 |    14 -
 libgo/go/os/user/listgroups_illumos.go             |    18 -
 libgo/go/os/user/listgroups_stub.go                |    19 +
 libgo/go/os/user/listgroups_unix.go                |   129 +-
 libgo/go/os/user/listgroups_unix_test.go           |   107 +
 libgo/go/os/user/lookup_android.go                 |     1 -
 libgo/go/os/user/lookup_plan9.go                   |     2 +
 libgo/go/os/user/lookup_stubs.go                   |    13 -
 libgo/go/os/user/lookup_unix.go                    |    21 +-
 libgo/go/os/user/lookup_unix_test.go               |    32 +-
 libgo/go/os/user/user.go                           |    17 +-
 libgo/go/os/user/user_test.go                      |    24 +-
 libgo/go/os/wait_unimp.go                          |    11 +-
 libgo/go/os/wait_wait6.go                          |     3 +-
 libgo/go/os/wait_waitid.go                         |     1 -
 libgo/go/path/filepath/example_unix_test.go        |     1 -
 libgo/go/path/filepath/example_unix_walk_test.go   |     1 -
 libgo/go/path/filepath/path_test.go                |     2 +
 libgo/go/path/filepath/path_unix.go                |     1 -
 libgo/go/path/filepath/path_windows.go             |     4 +
 libgo/go/path/filepath/symlink_unix.go             |     1 -
 libgo/go/plugin/plugin.go                          |     4 +-
 libgo/go/plugin/plugin_dlopen.go                   |     7 +-
 libgo/go/plugin/plugin_stubs.go                    |     1 -
 libgo/go/plugin/plugin_test.go                     |     1 -
 libgo/go/reflect/all_test.go                       |   755 +-
 libgo/go/reflect/deepequal.go                      |    37 +-
 libgo/go/reflect/example_test.go                   |    32 +-
 libgo/go/reflect/export_test.go                    |    11 +-
 libgo/go/reflect/makefunc.go                       |    11 +
 libgo/go/reflect/makefunc_ffi.go                   |     3 +-
 libgo/go/reflect/set_test.go                       |    24 +-
 libgo/go/reflect/swapper.go                        |     5 +-
 libgo/go/reflect/tostring_test.go                  |     2 +-
 libgo/go/reflect/type.go                           |   115 +-
 libgo/go/reflect/value.go                          |   455 +-
 libgo/go/reflect/visiblefields.go                  |     2 +-
 libgo/go/reflect/visiblefields_test.go             |    23 +-
 libgo/go/regexp/all_test.go                        |     3 +
 libgo/go/regexp/exec2_test.go                      |     1 -
 libgo/go/regexp/exec_test.go                       |    14 +-
 libgo/go/regexp/find_test.go                       |     7 +
 libgo/go/regexp/onepass.go                         |     3 +-
 libgo/go/regexp/regexp.go                          |    32 +-
 libgo/go/regexp/syntax/parse.go                    |     8 +-
 libgo/go/regexp/syntax/prog.go                     |     3 +-
 libgo/go/runtime/abi_test.go                       |     3 +-
 libgo/go/runtime/alg.go                            |    16 +-
 libgo/go/runtime/asan/asan.go                      |    38 +
 libgo/go/runtime/asan0.go                          |    22 +
 libgo/go/runtime/auxv_none.go                      |     1 -
 libgo/go/runtime/cgo/handle.go                     |    39 +-
 libgo/go/runtime/cgo/handle_test.go                |     6 +-
 libgo/go/runtime/cgocall.go                        |    10 +-
 libgo/go/runtime/cgocheck.go                       |    14 +-
 libgo/go/runtime/chan.go                           |     5 +-
 libgo/go/runtime/chan_test.go                      |     6 +-
 libgo/go/runtime/checkptr_test.go                  |    50 +
 libgo/go/runtime/cpuprof.go                        |    22 +-
 libgo/go/runtime/cputicks.go                       |     1 -
 libgo/go/runtime/crash_cgo_test.go                 |   138 +-
 libgo/go/runtime/crash_test.go                     |   112 +-
 libgo/go/runtime/crash_unix_test.go                |    18 +-
 libgo/go/runtime/debug/garbage_test.go             |    73 +-
 libgo/go/runtime/debug/mod.go                      |   188 +-
 libgo/go/runtime/debug/panic_test.go               |     1 -
 libgo/go/runtime/debuglog.go                       |     2 +-
 libgo/go/runtime/debuglog_off.go                   |     1 -
 libgo/go/runtime/debuglog_on.go                    |     1 -
 libgo/go/runtime/defer_test.go                     |    80 +-
 libgo/go/runtime/env_posix.go                      |     1 -
 libgo/go/runtime/error.go                          |     4 +-
 libgo/go/runtime/export_debuglog_test.go           |    18 +-
 libgo/go/runtime/export_linux_test.go              |    11 +-
 libgo/go/runtime/export_mmap_test.go               |     1 -
 libgo/go/runtime/export_pipe2_test.go              |     1 -
 libgo/go/runtime/export_pipe_test.go               |     1 -
 libgo/go/runtime/export_test.go                    |   211 +-
 libgo/go/runtime/export_unix_test.go               |     1 -
 libgo/go/runtime/export_windows_test.go            |     2 +
 libgo/go/runtime/extern.go                         |    17 +-
 libgo/go/runtime/float_test.go                     |    25 +
 libgo/go/runtime/gc_test.go                        |    21 +-
 libgo/go/runtime/gcinfo_test.go                    |    29 +-
 libgo/go/runtime/hash32.go                         |     1 -
 libgo/go/runtime/hash64.go                         |     1 -
 libgo/go/runtime/hash_test.go                      |     2 +-
 libgo/go/runtime/heapdump.go                       |    10 +-
 libgo/go/runtime/iface.go                          |    12 +-
 libgo/go/runtime/iface_test.go                     |    16 +-
 libgo/go/runtime/internal/atomic/atomic_test.go    |     4 +-
 libgo/go/runtime/internal/atomic/bench_test.go     |     2 +-
 libgo/go/runtime/internal/atomic/doc.go            |    18 +
 libgo/go/runtime/internal/atomic/stubs.go          |     1 -
 libgo/go/runtime/internal/atomic/types.go          |   395 +
 libgo/go/runtime/internal/atomic/types_64bit.go    |    29 +
 libgo/go/runtime/internal/math/math.go             |     4 +-
 libgo/go/runtime/internal/sys/consts.go            |    34 +
 libgo/go/runtime/internal/sys/intrinsics_common.go |    15 +
 libgo/go/runtime/internal/sys/sys.go               |     8 -
 libgo/go/runtime/lfstack_64bit.go                  |     1 -
 libgo/go/runtime/lfstack_test.go                   |     2 +-
 libgo/go/runtime/libfuzzer.go                      |     1 -
 libgo/go/runtime/lock_futex.go                     |     1 -
 libgo/go/runtime/lock_js.go                        |     1 -
 libgo/go/runtime/lock_sema.go                      |     1 -
 libgo/go/runtime/lockrank.go                       |    41 +-
 libgo/go/runtime/lockrank_off.go                   |     1 -
 libgo/go/runtime/lockrank_on.go                    |     1 -
 libgo/go/runtime/malloc.go                         |   130 +-
 libgo/go/runtime/malloc_test.go                    |    19 +-
 libgo/go/runtime/map.go                            |    80 +-
 libgo/go/runtime/map_benchmark_test.go             |     6 +-
 libgo/go/runtime/map_fast32.go                     |    17 +-
 libgo/go/runtime/map_fast64.go                     |    17 +-
 libgo/go/runtime/map_faststr.go                    |    65 +-
 libgo/go/runtime/map_test.go                       |    12 +-
 libgo/go/runtime/mbarrier.go                       |    23 +-
 libgo/go/runtime/mbitmap.go                        |   138 +-
 libgo/go/runtime/mcache.go                         |    52 +-
 libgo/go/runtime/mcentral.go                       |    85 +-
 libgo/go/runtime/mcheckmark.go                     |     4 +-
 libgo/go/runtime/mfinal.go                         |    10 +-
 libgo/go/runtime/mfinal_test.go                    |    16 +-
 libgo/go/runtime/mfixalloc.go                      |    15 +-
 libgo/go/runtime/mgc.go                            |    95 +-
 libgo/go/runtime/mgc_gccgo.go                      |     6 +-
 libgo/go/runtime/mgcmark.go                        |   183 +-
 libgo/go/runtime/mgcpacer.go                       |   694 +-
 libgo/go/runtime/mgcpacer_test.go                  |   717 +
 libgo/go/runtime/mgcscavenge.go                    |   395 +-
 libgo/go/runtime/mgcscavenge_test.go               |    15 +-
 libgo/go/runtime/mgcsweep.go                       |   278 +-
 libgo/go/runtime/mgcwork.go                        |    15 +-
 libgo/go/runtime/mheap.go                          |   149 +-
 libgo/go/runtime/mkfastlog2table.go                |     1 -
 libgo/go/runtime/mkpreempt.go                      |    25 +-
 libgo/go/runtime/mksizeclasses.go                  |     1 -
 libgo/go/runtime/mpagealloc.go                     |    30 +-
 libgo/go/runtime/mpagealloc_32bit.go               |     7 -
 libgo/go/runtime/mpagealloc_64bit.go               |     5 +-
 libgo/go/runtime/mpagealloc_test.go                |     9 +-
 libgo/go/runtime/mpagecache.go                     |    12 +-
 libgo/go/runtime/mpagecache_test.go                |    73 +-
 libgo/go/runtime/mpallocbits.go                    |    18 +
 libgo/go/runtime/mprof.go                          |     2 +-
 libgo/go/runtime/mranges.go                        |     8 +-
 libgo/go/runtime/msan/msan.go                      |     3 +-
 libgo/go/runtime/msan0.go                          |     1 -
 libgo/go/runtime/mspanset.go                       |    14 +-
 libgo/go/runtime/mstats.go                         |    20 +-
 libgo/go/runtime/mwbbuf.go                         |     4 +-
 libgo/go/runtime/nbpipe_pipe.go                    |     1 -
 libgo/go/runtime/nbpipe_pipe2.go                   |     3 +-
 libgo/go/runtime/nbpipe_test.go                    |     1 -
 libgo/go/runtime/netpoll.go                        |   187 +-
 libgo/go/runtime/netpoll_aix.go                    |     5 +-
 libgo/go/runtime/netpoll_epoll.go                  |     6 +-
 libgo/go/runtime/netpoll_fake.go                   |     1 -
 libgo/go/runtime/netpoll_kqueue.go                 |     6 +-
 libgo/go/runtime/netpoll_solaris.go                |     2 +-
 libgo/go/runtime/netpoll_stub.go                   |     1 -
 libgo/go/runtime/norace_test.go                    |     1 -
 libgo/go/runtime/os3_solaris.go                    |     5 +
 libgo/go/runtime/os_aix.go                         |    23 +-
 libgo/go/runtime/os_darwin.go                      |     5 +
 libgo/go/runtime/os_dragonfly.go                   |     3 +-
 libgo/go/runtime/os_freebsd.go                     |     9 +-
 libgo/go/runtime/os_js.go                          |     1 -
 libgo/go/runtime/os_linux.go                       |   159 +-
 libgo/go/runtime/os_linux_arm64.go                 |     1 -
 libgo/go/runtime/os_linux_mips64x.go               |     2 -
 libgo/go/runtime/os_linux_mipsx.go                 |     2 -
 libgo/go/runtime/os_linux_noauxv.go                |     1 -
 libgo/go/runtime/os_linux_ppc64x.go                |     2 -
 libgo/go/runtime/os_netbsd.go                      |    13 +-
 libgo/go/runtime/os_netbsd_arm64.go                |     7 +-
 libgo/go/runtime/os_only_solaris.go                |     1 -
 libgo/go/runtime/os_openbsd.go                     |     1 +
 libgo/go/runtime/panic.go                          |    65 +-
 libgo/go/runtime/panic32.go                        |     1 -
 libgo/go/runtime/pprof/mprof_test.go               |    32 +-
 libgo/go/runtime/pprof/pprof.go                    |    11 +-
 libgo/go/runtime/pprof/pprof_norusage.go           |     1 -
 libgo/go/runtime/pprof/pprof_rusage.go             |     1 -
 libgo/go/runtime/pprof/pprof_test.go               |   478 +-
 libgo/go/runtime/pprof/proto.go                    |    76 +-
 libgo/go/runtime/pprof/proto_test.go               |    30 +-
 libgo/go/runtime/pprof/rusage_test.go              |    39 +
 libgo/go/runtime/pprof/uname_linux_test.go         |    61 +
 libgo/go/runtime/pprof/uname_other_test.go         |    15 +
 libgo/go/runtime/preempt_nonwindows.go             |     1 -
 libgo/go/runtime/print.go                          |     4 +-
 libgo/go/runtime/proc.go                           |   171 +-
 libgo/go/runtime/proc_test.go                      |    18 +-
 libgo/go/runtime/race0.go                          |     1 -
 libgo/go/runtime/relax_stub.go                     |     1 -
 libgo/go/runtime/runtime1.go                       |    10 +-
 libgo/go/runtime/runtime2.go                       |    23 +-
 libgo/go/runtime/runtime_linux_test.go             |    41 +
 libgo/go/runtime/runtime_mmap_test.go              |     1 -
 libgo/go/runtime/runtime_test.go                   |    80 +-
 libgo/go/runtime/runtime_unix_test.go              |     1 -
 libgo/go/runtime/rwmutex_test.go                   |     5 +
 libgo/go/runtime/semasleep_test.go                 |    64 +-
 libgo/go/runtime/signal_unix.go                    |    87 +-
 libgo/go/runtime/signal_windows_test.go            |     1 -
 libgo/go/runtime/sigqueue.go                       |     1 -
 libgo/go/runtime/sigqueue_note.go                  |     1 -
 libgo/go/runtime/sizeof_test.go                    |     6 +-
 libgo/go/runtime/slice.go                          |    53 +-
 libgo/go/runtime/stack_test.go                     |   114 +-
 libgo/go/runtime/string.go                         |    20 +-
 libgo/go/runtime/stubs.go                          |    27 +-
 libgo/go/runtime/stubs2.go                         |     3 +-
 libgo/go/runtime/stubs3.go                         |     1 -
 libgo/go/runtime/stubs_linux.go                    |     1 -
 libgo/go/runtime/stubs_nonlinux.go                 |     1 -
 libgo/go/runtime/symtab_test.go                    |    32 +
 libgo/go/runtime/sys_wasm.go                       |     3 +-
 libgo/go/runtime/testdata/testprog/badtraceback.go |     3 +
 libgo/go/runtime/testdata/testprog/checkptr.go     |     8 +
 libgo/go/runtime/testdata/testprog/gc.go           |   143 +-
 .../go/runtime/testdata/testprog/numcpu_freebsd.go |    11 +-
 libgo/go/runtime/testdata/testprog/preempt.go      |     4 +
 libgo/go/runtime/testdata/testprog/signal.go       |     1 +
 libgo/go/runtime/testdata/testprog/sleep.go        |     7 +-
 .../go/runtime/testdata/testprog/syscalls_none.go  |     1 +
 .../testdata/testprog/traceback_ancestors.go       |    38 +-
 libgo/go/runtime/testdata/testprogcgo/callback.go  |     3 +-
 .../go/runtime/testdata/testprogcgo/catchpanic.go  |     1 +
 libgo/go/runtime/testdata/testprogcgo/dropm.go     |     1 +
 libgo/go/runtime/testdata/testprogcgo/eintr.go     |     1 +
 libgo/go/runtime/testdata/testprogcgo/exec.go      |     1 +
 libgo/go/runtime/testdata/testprogcgo/gprof.go     |    49 +
 libgo/go/runtime/testdata/testprogcgo/gprof_c.c    |    33 +
 .../runtime/testdata/testprogcgo/lockosthread.go   |     1 +
 .../runtime/testdata/testprogcgo/needmdeadlock.go  |     1 +
 .../runtime/testdata/testprogcgo/numgoroutine.go   |     1 +
 libgo/go/runtime/testdata/testprogcgo/panic.c      |     9 +
 libgo/go/runtime/testdata/testprogcgo/panic.go     |    23 +
 libgo/go/runtime/testdata/testprogcgo/pprof.go     |    11 +-
 libgo/go/runtime/testdata/testprogcgo/raceprof.go  |     2 -
 libgo/go/runtime/testdata/testprogcgo/racesig.go   |     1 +
 libgo/go/runtime/testdata/testprogcgo/segv.go      |     1 +
 libgo/go/runtime/testdata/testprogcgo/sigstack.go  |     1 +
 libgo/go/runtime/testdata/testprogcgo/sigthrow.go  |    20 +
 .../go/runtime/testdata/testprogcgo/threadpanic.go |     1 +
 .../go/runtime/testdata/testprogcgo/threadpprof.go |    25 +-
 .../go/runtime/testdata/testprogcgo/threadprof.go  |    17 +-
 libgo/go/runtime/testdata/testprognet/signal.go    |     1 +
 .../go/runtime/testdata/testprognet/signalexec.go  |     1 +
 libgo/go/runtime/testdata/testwinlib/main.c        |     5 +-
 libgo/go/runtime/testdata/testwinlib/main.go       |     1 +
 libgo/go/runtime/time.go                           |    40 +-
 libgo/go/runtime/time_fake.go                      |     5 +-
 libgo/go/runtime/time_nofake.go                    |     6 +-
 libgo/go/runtime/timeasm.go                        |     3 -
 libgo/go/runtime/timestub.go                       |     3 -
 libgo/go/runtime/timestub2.go                      |     7 -
 libgo/go/runtime/tls_stub.go                       |     1 -
 libgo/go/runtime/trace.go                          |    20 +-
 libgo/go/runtime/trace/annotation.go               |     2 +-
 libgo/go/runtime/traceback_test.go                 |   130 +
 libgo/go/runtime/type.go                           |     4 +-
 libgo/go/runtime/write_err.go                      |     1 -
 libgo/go/sort/slice.go                             |     6 +-
 libgo/go/sort/slice_go14.go                        |     2 +-
 libgo/go/sort/sort.go                              |     5 +-
 libgo/go/strconv/fp_test.go                        |    20 +-
 libgo/go/strconv/ftoaryu.go                        |     2 +-
 libgo/go/strconv/quote.go                          |     4 +-
 libgo/go/strconv/quote_test.go                     |     3 +
 libgo/go/strings/clone.go                          |    28 +
 libgo/go/strings/clone_test.go                     |    49 +
 libgo/go/strings/compare.go                        |     2 +-
 libgo/go/strings/example_test.go                   |    58 +-
 libgo/go/strings/export_test.go                    |     2 +-
 libgo/go/strings/reader_test.go                    |     2 +-
 libgo/go/strings/replace.go                        |    11 +-
 libgo/go/strings/strings.go                        |   120 +-
 libgo/go/strings/strings_test.go                   |    34 +-
 libgo/go/sync/atomic/atomic_test.go                |     8 +-
 libgo/go/sync/atomic/value.go                      |    23 +-
 libgo/go/sync/atomic/value_test.go                 |    18 +-
 libgo/go/sync/example_pool_test.go                 |     2 +-
 libgo/go/sync/example_test.go                      |     2 +-
 libgo/go/sync/export_test.go                       |    18 +-
 libgo/go/sync/map.go                               |    45 +-
 libgo/go/sync/map_bench_test.go                    |     4 +-
 libgo/go/sync/map_reference_test.go                |    58 +-
 libgo/go/sync/map_test.go                          |    72 +-
 libgo/go/sync/mutex.go                             |    24 +
 libgo/go/sync/mutex_test.go                        |    18 +
 libgo/go/sync/pool.go                              |    18 +-
 libgo/go/sync/pool_test.go                         |    33 +-
 libgo/go/sync/poolqueue.go                         |    18 +-
 libgo/go/sync/runtime2.go                          |     1 -
 libgo/go/sync/runtime2_lockrank.go                 |     1 -
 libgo/go/sync/rwmutex.go                           |    59 +
 libgo/go/sync/rwmutex_test.go                      |    28 +
 libgo/go/sync/waitgroup.go                         |    22 +-
 libgo/go/sync/waitgroup_test.go                    |   126 -
 libgo/go/syscall/asan0.go                          |    19 +
 libgo/go/syscall/bpf_bsd.go                        |     1 -
 libgo/go/syscall/creds_test.go                     |     1 -
 libgo/go/syscall/dirent.go                         |     1 -
 libgo/go/syscall/dirent_test.go                    |    40 +-
 libgo/go/syscall/endian_big.go                     |     3 +-
 libgo/go/syscall/endian_little.go                  |     3 +-
 libgo/go/syscall/env_unix.go                       |     1 -
 libgo/go/syscall/exec_bsd.go                       |    43 +-
 libgo/go/syscall/exec_freebsd.go                   |   294 +
 libgo/go/syscall/exec_linux.go                     |    35 +-
 libgo/go/syscall/exec_linux_test.go                |    21 +-
 libgo/go/syscall/exec_pdeathsig_test.go            |   134 +
 libgo/go/syscall/exec_unix.go                      |    21 +-
 libgo/go/syscall/exec_unix_test.go                 |     2 -
 libgo/go/syscall/exec_windows.go                   |     8 +-
 libgo/go/syscall/export_unix_test.go               |     3 +-
 libgo/go/syscall/forkpipe.go                       |     1 -
 libgo/go/syscall/forkpipe2.go                      |     1 -
 libgo/go/syscall/fs_js.go                          |     5 +-
 libgo/go/syscall/getdirentries_test.go             |     1 -
 libgo/go/syscall/js/export_test.go                 |     2 +-
 libgo/go/syscall/js/func.go                        |     8 +-
 libgo/go/syscall/js/js.go                          |    37 +-
 libgo/go/syscall/js/js_test.go                     |    20 +-
 libgo/go/syscall/mkasm.go                          |     1 -
 libgo/go/syscall/mmap_unix_test.go                 |     1 -
 libgo/go/syscall/msan0.go                          |     1 -
 libgo/go/syscall/net_js.go                         |     4 +-
 libgo/go/syscall/netlink_linux.go                  |    25 +-
 libgo/go/syscall/route_bsd.go                      |     1 -
 libgo/go/syscall/route_freebsd_32bit.go            |     1 -
 libgo/go/syscall/route_freebsd_64bit.go            |     1 -
 libgo/go/syscall/setuidgid_32_linux.go             |     2 -
 libgo/go/syscall/setuidgid_linux.go                |     1 -
 libgo/go/syscall/sockcmsg_unix.go                  |     1 -
 libgo/go/syscall/sockcmsg_unix_other.go            |     1 -
 libgo/go/syscall/socket.go                         |   150 +-
 libgo/go/syscall/syscall_dragonfly.go              |     2 +
 libgo/go/syscall/syscall_freebsd_test.go           |    12 +-
 libgo/go/syscall/syscall_js.go                     |     1 -
 libgo/go/syscall/syscall_linux_mipsx.go            |     2 -
 libgo/go/syscall/syscall_linux_test.go             |   117 -
 libgo/go/syscall/syscall_ptrace_test.go            |     1 -
 libgo/go/syscall/syscall_solaris.go                |     2 +
 libgo/go/syscall/syscall_unix.go                   |     7 +-
 libgo/go/syscall/syscall_unix_test.go              |    21 +-
 libgo/go/syscall/tables_js.go                      |     1 -
 libgo/go/syscall/time_fake.go                      |     1 -
 libgo/go/syscall/time_nofake.go                    |     1 -
 libgo/go/syscall/timestruct.go                     |     1 -
 libgo/go/testing/allocs_test.go                    |     2 +-
 libgo/go/testing/benchmark.go                      |    32 +-
 libgo/go/testing/example.go                        |     2 +-
 libgo/go/testing/fstest/mapfs.go                   |     8 +-
 libgo/go/testing/fstest/mapfs_test.go              |    28 +
 libgo/go/testing/fstest/testfs.go                  |     2 +-
 libgo/go/testing/fuzz.go                           |   704 +
 libgo/go/testing/helper_test.go                    |    35 +-
 libgo/go/testing/helperfuncs_test.go               |    32 +
 libgo/go/testing/internal/testdeps/deps.go         |    71 +
 libgo/go/testing/match.go                          |   197 +-
 libgo/go/testing/match_test.go                     |   128 +-
 libgo/go/testing/quick/quick.go                    |    20 +-
 libgo/go/testing/run_example.go                    |     1 -
 libgo/go/testing/run_example_js.go                 |     1 -
 libgo/go/testing/sub_test.go                       |     9 +-
 libgo/go/testing/testing.go                        |   350 +-
 libgo/go/testing/testing_other.go                  |    13 +
 libgo/go/testing/testing_windows.go                |    18 +
 libgo/go/text/scanner/scanner.go                   |     2 +-
 libgo/go/text/template/doc.go                      |    20 +-
 libgo/go/text/template/exec.go                     |   104 +-
 libgo/go/text/template/exec_test.go                |    71 +-
 libgo/go/text/template/funcs.go                    |    40 +-
 libgo/go/text/template/multi_test.go               |    10 +
 libgo/go/text/template/option.go                   |    10 +-
 libgo/go/text/template/parse/lex.go                |    15 +-
 libgo/go/text/template/parse/lex_test.go           |     2 +
 libgo/go/text/template/parse/node.go               |    36 +
 libgo/go/text/template/parse/parse.go              |    55 +-
 libgo/go/text/template/parse/parse_test.go         |    10 +-
 libgo/go/text/template/template.go                 |     2 +-
 libgo/go/time/embed.go                             |     1 -
 libgo/go/time/example_test.go                      |    50 +
 libgo/go/time/format.go                            |   122 +-
 libgo/go/time/format_test.go                       |    61 +
 libgo/go/time/genzabbrs.go                         |     1 -
 libgo/go/time/internal_test.go                     |     4 +-
 libgo/go/time/sleep.go                             |    16 +-
 libgo/go/time/sleep_test.go                        |    72 +
 libgo/go/time/sys_plan9.go                         |     1 -
 libgo/go/time/sys_unix.go                          |     1 -
 libgo/go/time/tick.go                              |    12 +-
 libgo/go/time/tick_test.go                         |    34 +-
 libgo/go/time/time.go                              |    45 +-
 libgo/go/time/time_test.go                         |   101 +-
 libgo/go/time/tzdata/generate_zipdata.go           |     7 +-
 libgo/go/time/tzdata/zipdata.go                    | 13757 ++++++++++---------
 libgo/go/time/zoneinfo.go                          |    13 +-
 libgo/go/time/zoneinfo_ios.go                      |     1 -
 libgo/go/time/zoneinfo_js.go                       |     1 -
 libgo/go/time/zoneinfo_unix.go                     |     1 -
 libgo/go/time/zoneinfo_unix_test.go                |     1 -
 libgo/go/unicode/example_test.go                   |    60 +
 libgo/go/unicode/utf8/example_test.go              |    10 +
 libgo/go/unicode/utf8/utf8.go                      |    26 +
 libgo/go/unicode/utf8/utf8_test.go                 |    25 +
 libgo/go/vendor/modules.txt                        |    11 +-
 libgo/gotool-packages.txt                          |     6 +-
 libgo/libgo-packages.txt                           |    12 +
 libgo/match.sh                                     |   134 +-
 libgo/merge.sh                                     |     8 +-
 libgo/misc/cgo/errors/errors_test.go               |     9 +-
 libgo/misc/cgo/errors/testdata/err2.go             |    12 +-
 libgo/misc/cgo/gmp/fib.go                          |     1 +
 libgo/misc/cgo/gmp/pi.go                           |     1 +
 libgo/misc/cgo/test/cgo_test.go                    |     2 +
 libgo/misc/cgo/test/cgo_thread_lock.go             |     1 +
 libgo/misc/cgo/test/cgo_unix_test.go               |     1 +
 libgo/misc/cgo/test/issue18146.go                  |     1 +
 libgo/misc/cgo/test/issue21897.go                  |     1 +
 libgo/misc/cgo/test/issue21897b.go                 |     1 +
 libgo/misc/cgo/test/issue4029.go                   |     4 +-
 libgo/misc/cgo/test/issue4029w.go                  |     1 +
 libgo/misc/cgo/test/issue42018.go                  |    14 +
 libgo/misc/cgo/test/issue42018_windows.go          |    46 +
 libgo/misc/cgo/test/issue8517.go                   |     1 +
 libgo/misc/cgo/test/issue8694.go                   |     1 +
 libgo/misc/cgo/test/sigaltstack.go                 |     1 +
 libgo/misc/cgo/test/sigprocmask.go                 |     1 +
 libgo/misc/cgo/test/test.go                        |     5 +
 libgo/misc/cgo/test/test_unix.go                   |     1 +
 libgo/misc/cgo/test/testdata/issue43639.go         |     9 +
 libgo/misc/cgo/test/testdata/issue43639/a.go       |     8 +
 libgo/misc/cgo/test/testdata/issue9400_linux.go    |     9 +
 libgo/misc/cgo/test/testx.go                       |    24 +
 libgo/misc/cgo/test/typeparam.go                   |    21 +
 libgo/misc/cgo/testcarchive/carchive_test.go       |   330 +-
 libgo/misc/cgo/testcarchive/testdata/libgo8/a.go   |    36 +
 libgo/misc/cgo/testcarchive/testdata/main8.c       |    16 +
 libgo/misc/cgo/testcshared/cshared_test.go         |    10 +-
 libgo/misc/cgo/testcshared/testdata/libgo2/dup2.go |     1 +
 libgo/misc/cgo/testcshared/testdata/libgo2/dup3.go |     3 +-
 libgo/misc/cgo/testgodefs/testdata/issue48396.go   |    18 +
 libgo/misc/cgo/testgodefs/testdata/main.go         |     3 +
 libgo/misc/cgo/testgodefs/testgodefs_test.go       |     1 +
 libgo/misc/cgo/testplugin/plugin_test.go           |    32 +-
 .../misc/cgo/testplugin/testdata/forkexec/main.go  |    30 +
 libgo/misc/cgo/testsanitizers/asan_test.go         |    81 +
 libgo/misc/cgo/testsanitizers/cc_test.go           |    35 +-
 .../misc/cgo/testsanitizers/testdata/asan1_fail.go |    28 +
 .../misc/cgo/testsanitizers/testdata/asan2_fail.go |    34 +
 .../misc/cgo/testsanitizers/testdata/asan3_fail.go |    23 +
 .../misc/cgo/testsanitizers/testdata/asan4_fail.go |    22 +
 .../misc/cgo/testsanitizers/testdata/asan5_fail.go |    21 +
 .../testsanitizers/testdata/asan_useAfterReturn.go |    26 +
 libgo/misc/cgo/testshared/shared_test.go           |    35 +-
 .../misc/cgo/testshared/testdata/issue47837/a/a.go |    19 +
 .../testshared/testdata/issue47837/main/main.go}   |    12 +-
 libgo/misc/cgo/testso/noso_test.go                 |     1 +
 libgo/misc/cgo/testsovar/noso_test.go              |     1 +
 libgo/misc/cgo/testtls/tls_test.go                 |     1 +
 libgo/runtime/go-signal.c                          |    15 +-
 libgo/testsuite/Makefile.in                        |     1 +
 libgo/testsuite/gotest                             |   120 +-
 1980 files changed, 84229 insertions(+), 36297 deletions(-)

diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 52f4b423f02..4e6bac7b7d5 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-b0dcd2d1e5e73952408b9f2d4d86ae12d102b20c
+47380f733ca932384e59492d2f04374edd8ec95e
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
diff --git a/gotools/Makefile.am b/gotools/Makefile.am
index 9e81024ea78..46481cb5173 100644
--- a/gotools/Makefile.am
+++ b/gotools/Makefile.am
@@ -62,6 +62,7 @@ go_cmd_gofmt_files = \
 
 go_cmd_cgo_files = \
 	$(cmdsrcdir)/cgo/ast.go \
+	$(cmdsrcdir)/cgo/ast_go118.go \
 	$(cmdsrcdir)/cgo/doc.go \
 	$(cmdsrcdir)/cgo/gcc.go \
 	$(cmdsrcdir)/cgo/godefs.go \
@@ -224,6 +225,7 @@ check-go-tool: go$(EXEEXT) $(noinst_PROGRAMS) check-head check-gccgo check-gcc
 	cp -r $(libgosrcdir)/golang.org/x/mod check-go-dir/src/cmd/vendor/golang.org/x/
 	cp -r $(libgosrcdir)/golang.org/x/crypto check-go-dir/src/cmd/vendor/golang.org/x/
 	cp -r $(libgosrcdir)/golang.org/x/xerrors check-go-dir/src/cmd/vendor/golang.org/x/
+	cp -r $(libgosrcdir)/golang.org/x/tools check-go-dir/src/cmd/vendor/golang.org/x/
 	cp $(libgodir)/objabi.go check-go-dir/src/cmd/internal/objabi/
 	@abs_libgodir=`cd $(libgodir) && $(PWD_COMMAND)`; \
 	abs_checkdir=`cd check-go-dir && $(PWD_COMMAND)`; \
diff --git a/gotools/Makefile.in b/gotools/Makefile.in
index 8a19f6f3a7a..1bcf8276ca3 100644
--- a/gotools/Makefile.in
+++ b/gotools/Makefile.in
@@ -366,6 +366,7 @@ go_cmd_gofmt_files = \
 
 go_cmd_cgo_files = \
 	$(cmdsrcdir)/cgo/ast.go \
+	$(cmdsrcdir)/cgo/ast_go118.go \
 	$(cmdsrcdir)/cgo/doc.go \
 	$(cmdsrcdir)/cgo/gcc.go \
 	$(cmdsrcdir)/cgo/godefs.go \
@@ -896,6 +897,7 @@ mostlyclean-local:
 @NATIVE_TRUE@	cp -r $(libgosrcdir)/golang.org/x/mod check-go-dir/src/cmd/vendor/golang.org/x/
 @NATIVE_TRUE@	cp -r $(libgosrcdir)/golang.org/x/crypto check-go-dir/src/cmd/vendor/golang.org/x/
 @NATIVE_TRUE@	cp -r $(libgosrcdir)/golang.org/x/xerrors check-go-dir/src/cmd/vendor/golang.org/x/
+@NATIVE_TRUE@	cp -r $(libgosrcdir)/golang.org/x/tools check-go-dir/src/cmd/vendor/golang.org/x/
 @NATIVE_TRUE@	cp $(libgodir)/objabi.go check-go-dir/src/cmd/internal/objabi/
 @NATIVE_TRUE@	@abs_libgodir=`cd $(libgodir) && $(PWD_COMMAND)`; \
 @NATIVE_TRUE@	abs_checkdir=`cd check-go-dir && $(PWD_COMMAND)`; \
diff --git a/libgo/MERGE b/libgo/MERGE
index 4473f479d5f..662af9af882 100644
--- a/libgo/MERGE
+++ b/libgo/MERGE
@@ -1,4 +1,4 @@
-21a4e67ad58e3c4a7c5254f60cda5be5c3c450ff
+41f485b9a7d8fd647c415be1d11b612063dff21c
 
 The first line of this file holds the git revision number of the
 last merge done from the master library sources.
diff --git a/libgo/Makefile.am b/libgo/Makefile.am
index 5c377a30df9..be889f2a984 100644
--- a/libgo/Makefile.am
+++ b/libgo/Makefile.am
@@ -220,6 +220,7 @@ toolexeclibgodatabasesql_DATA = \
 toolexeclibgodebugdir = $(toolexeclibgodir)/debug
 
 toolexeclibgodebug_DATA = \
+	debug/buildinfo.gox \
 	debug/dwarf.gox \
 	debug/elf.gox \
 	debug/gosym.gox \
@@ -325,6 +326,7 @@ toolexeclibgonetdir = $(toolexeclibgodir)/net
 toolexeclibgonet_DATA = \
 	net/http.gox \
 	net/mail.gox \
+	net/netip.gox \
 	net/rpc.gox \
 	net/smtp.gox \
 	net/textproto.gox \
@@ -429,6 +431,7 @@ noinst_DATA = \
 	internal/testenv.gox \
 	internal/trace.gox \
 	net/internal/socktest.gox \
+	os/exec/internal/fdtest.gox \
 	os/signal/internal/pty.gox \
 	reflect/internal/example1.gox \
 	reflect/internal/example2.gox
@@ -483,53 +486,68 @@ version.go: s-version; @true
 s-version: Makefile
 	rm -f version.go.tmp
 	echo "package sys" > version.go.tmp
-	echo 'const GOARCH = "'$(GOARCH)'"' >> version.go.tmp
-	echo 'const GOOS = "'$(GOOS)'"' >> version.go.tmp
 	echo 'const GccgoToolDir = "$(libexecsubdir)"' >> version.go.tmp
 	echo 'const StackGuardMultiplierDefault = 1' >> version.go.tmp
-	echo >> version.go.tmp
-	echo "const (" >> version.go.tmp
-	echo "	UNKNOWN ArchFamilyType = iota" >> version.go.tmp
+	$(SHELL) $(srcdir)/mvifdiff.sh version.go.tmp version.go
+	$(STAMP) $@
+
+zgoarch.go: s-zgoarch; @true
+s-zgoarch: Makefile goarch.sh
+	rm -f zgoarch.go.tmp
+	echo "package goarch" > zgoarch.go.tmp
+	echo >> zgoarch.go.tmp
+	echo 'const GOARCH = "'$(GOARCH)'"' >> zgoarch.go.tmp
+	echo >> zgoarch.go.tmp
+	echo 'const (' >> zgoarch.go.tmp
+	echo "  _ArchFamily = `$(SHELL) $(srcdir)/goarch.sh $(GOARCH) family`" >> zgoarch.go.tmp
+	echo "  _BigEndian = `$(SHELL) $(srcdir)/goarch.sh $(GOARCH) bigendian`" >> zgoarch.go.tmp
+	echo "  _DefaultPhysPageSize = `$(SHELL) $(srcdir)/goarch.sh $(GOARCH) defaultphyspagesize`" >> zgoarch.go.tmp
+	echo "  _Int64Align = `$(SHELL) $(srcdir)/goarch.sh $(GOARCH) int64align`" >> zgoarch.go.tmp
+	echo "  _MinFrameSize = `$(SHELL) $(srcdir)/goarch.sh $(GOARCH) minframesize`" >> zgoarch.go.tmp
+	echo "  _PCQuantum = `$(SHELL) $(srcdir)/goarch.sh $(GOARCH) pcquantum`" >> zgoarch.go.tmp
+	echo "  _StackAlign = `$(SHELL) $(srcdir)/goarch.sh $(GOARCH) stackalign`" >> zgoarch.go.tmp
+	echo ")" >> zgoarch.go.tmp
+	echo >> zgoarch.go.tmp
+	echo "const (" >> zgoarch.go.tmp
+	echo "	UNKNOWN ArchFamilyType = iota" >> zgoarch.go.tmp
 	for a in $(ALLGOARCHFAMILY); do \
-	  echo "	$${a}" >> version.go.tmp; \
+	  echo "	$${a}" >> zgoarch.go.tmp; \
 	done
-	echo ")" >> version.go.tmp
-	echo >> version.go.tmp
+	echo ")" >> zgoarch.go.tmp
+	echo >> zgoarch.go.tmp
 	for a in $(ALLGOARCH); do \
 	  f=`echo $${a} | sed -e 's/\(.\).*/\1/' -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`; \
 	  n="$${f}`echo $${a} | sed -e 's/.//'`"; \
 	  if test "$${a}" = "$(GOARCH)"; then \
-	    echo "const Goarch$${n} = 1" >> version.go.tmp; \
+	    echo "const Is$${n} = 1" >> zgoarch.go.tmp; \
 	  else \
-	    echo "const Goarch$${n} = 0" >> version.go.tmp; \
+	    echo "const Is$${n} = 0" >> zgoarch.go.tmp; \
 	  fi; \
 	done
-	echo >> version.go.tmp
-	echo "const (" >> version.go.tmp
-	echo "  _ArchFamily = `$(SHELL) $(srcdir)/goarch.sh $(GOARCH) family`" >> version.go.tmp
-	echo "  _BigEndian = `$(SHELL) $(srcdir)/goarch.sh $(GOARCH) bigendian`" >> version.go.tmp
-	echo "  _DefaultPhysPageSize = `$(SHELL) $(srcdir)/goarch.sh $(GOARCH) defaultphyspagesize`" >> version.go.tmp
-	echo "  _Int64Align = `$(SHELL) $(srcdir)/goarch.sh $(GOARCH) int64align`" >> version.go.tmp
-	echo "  _MinFrameSize = `$(SHELL) $(srcdir)/goarch.sh $(GOARCH) minframesize`" >> version.go.tmp
-	echo "  _PCQuantum = `$(SHELL) $(srcdir)/goarch.sh $(GOARCH) pcquantum`" >> version.go.tmp
-	echo "  _StackAlign = `$(SHELL) $(srcdir)/goarch.sh $(GOARCH) stackalign`" >> version.go.tmp
-	echo ")" >> version.go.tmp
-	echo >> version.go.tmp
+	$(SHELL) $(srcdir)/mvifdiff.sh zgoarch.go.tmp zgoarch.go
+	$(STAMP) $@
+
+zgoos.go: s-zgoos; @true
+s-zgoos: Makefile
+	rm -f zgoos.go.tmp
+	echo "package goos" > zgoos.go.tmp
+	echo >> zgoos.go.tmp
+	echo 'const GOOS = "'$(GOOS)'"' >> zgoos.go.tmp
+	echo >> zgoos.go.tmp
 	for a in $(ALLGOOS); do \
 	  f=`echo $${a} | sed -e 's/\(.\).*/\1/' -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`; \
 	  n="$${f}`echo $${a} | sed -e 's/.//'`"; \
 	  if test "$${a}" = "$(GOOS)"; then \
-	    echo "const Goos$${n} = 1" >> version.go.tmp; \
+	    echo "const Is$${n} = 1" >> zgoos.go.tmp; \
 	  else \
-	    echo "const Goos$${n} = 0" >> version.go.tmp; \
+	    echo "const Is$${n} = 0" >> zgoos.go.tmp; \
 	  fi; \
 	done
-	echo >> version.go.tmp
-	$(SHELL) $(srcdir)/mvifdiff.sh version.go.tmp version.go
+	$(SHELL) $(srcdir)/mvifdiff.sh zgoos.go.tmp zgoos.go
 	$(STAMP) $@
 
 cpugen.go: s-cpu; @true
-s-cpu: Makefile
+s-cpu: Makefile goarch.sh
 	rm -f cpugen.go.tmp
 	echo "package cpu" > cpugen.go.tmp
 	echo "const CacheLinePadSize = `$(SHELL) $(srcdir)/goarch.sh $(GOARCH) cachelinesize`" >> cpugen.go.tmp
@@ -538,7 +556,7 @@ s-cpu: Makefile
 	$(STAMP) $@
 
 gcpugen.go: s-gcpu; @true
-s-gcpu: Makefile
+s-gcpu: Makefile goarch.sh
 	rm -f gcpugen.go.tmp
 	echo "package cpu" > gcpugen.go.tmp
 	echo "const cacheLineSize = `$(SHELL) $(srcdir)/goarch.sh $(GOARCH) cachelinesize`" >> gcpugen.go.tmp
@@ -560,6 +578,7 @@ s-buildcfg: Makefile
 	echo "import \"runtime\"" >> buildcfg.go.tmp
 	echo 'func defaultGOROOTValue() string { return `$(prefix)` }' >> buildcfg.go.tmp
 	echo 'const defaultGO386 = `sse2`' >> buildcfg.go.tmp
+	echo 'const defaultGOAMD64 = `v1`' >> buildcfg.go.tmp
 	echo 'const defaultGOARM = `5`' >> buildcfg.go.tmp
 	echo 'const defaultGOMIPS = `hardfloat`' >> buildcfg.go.tmp
 	echo 'const defaultGOMIPS64 = `hardfloat`' >> buildcfg.go.tmp
@@ -813,7 +832,8 @@ libgo_ldflags = \
 
 libgo_libadd = \
 	$(libgo_go_objs) ../libbacktrace/libbacktrace.la \
-	$(LIBATOMIC) $(LIBFFI) $(PTHREAD_LIBS) $(MATH_LIBS) $(NET_LIBS)
+	$(LIBATOMIC) $(LIBFFI) $(PTHREAD_LIBS) $(MATH_LIBS) \
+	$(NET_LIBS) $(RT_LIBS)
 
 libgo_la_SOURCES = $(runtime_files)
 libgo_la_LDFLAGS = $(libgo_ldflags)
@@ -904,7 +924,7 @@ GOBENCH =
 CHECK = \
 	GC="$(GOC) $(GOCFLAGS) $($(subst /,_,$@)_GOCFLAGS) -L `${PWD_COMMAND}` -L `${PWD_COMMAND}`/.libs"; \
 	export GC; \
-	GOLIBS="$(extra_check_libs_$(subst .,_,$(subst /,_,$(@D)))) $(PTHREAD_LIBS) $(MATH_LIBS) $(NET_LIBS) $(LIBS)"; \
+	GOLIBS="$(extra_check_libs_$(subst .,_,$(subst /,_,$(@D)))) $(PTHREAD_LIBS) $(MATH_LIBS) $(NET_LIBS) $(RT_LIBS) $(LIBS)"; \
 	export GOLIBS; \
 	RUNTESTFLAGS="$(RUNTESTFLAGS)"; \
 	export RUNTESTFLAGS; \
@@ -1065,6 +1085,12 @@ runtime/internal/sys.lo.dep: $(extra_go_files_runtime_internal_sys)
 extra_go_files_internal_cpu = cpugen.go
 internal/cpu.lo.dep: $(extra_go_files_internal_cpu)
 
+extra_go_files_internal_goarch = zgoarch.go
+internal/goarch.lo.dep: $(extra_go_files_internal_goarch)
+
+extra_go_files_internal_goos = zgoos.go
+internal/goos.lo.dep: $(extra_go_files_internal_goos)
+
 extra_go_files_golang_org_x_sys_cpu = gcpugen.go
 golang.org/x/sys/cpu.lo.dep: $(extra_go_files_golang_org_x_sys_cpu)
 
diff --git a/libgo/Makefile.in b/libgo/Makefile.in
index 1240b16d443..216be43f14a 100644
--- a/libgo/Makefile.in
+++ b/libgo/Makefile.in
@@ -233,7 +233,8 @@ am__DEPENDENCIES_4 =
 am__DEPENDENCIES_5 = $(am__DEPENDENCIES_3) \
 	../libbacktrace/libbacktrace.la $(am__DEPENDENCIES_4) \
 	$(am__DEPENDENCIES_4) $(am__DEPENDENCIES_4) \
-	$(am__DEPENDENCIES_4) $(am__DEPENDENCIES_4)
+	$(am__DEPENDENCIES_4) $(am__DEPENDENCIES_4) \
+	$(am__DEPENDENCIES_4)
 libgo_llgo_la_DEPENDENCIES = $(am__DEPENDENCIES_5)
 @LIBGO_IS_LINUX_TRUE@@LIBGO_IS_X86_TRUE@am__objects_1 =  \
 @LIBGO_IS_LINUX_TRUE@@LIBGO_IS_X86_TRUE@	runtime/go-context.lo
@@ -465,6 +466,7 @@ PATH_SEPARATOR = @PATH_SEPARATOR@
 PTHREAD_CFLAGS = @PTHREAD_CFLAGS@
 PTHREAD_LIBS = @PTHREAD_LIBS@
 RANLIB = @RANLIB@
+RT_LIBS = @RT_LIBS@
 SED = @SED@
 SET_MAKE = @SET_MAKE@
 SHELL = @SHELL@
@@ -712,6 +714,7 @@ toolexeclibgodatabasesql_DATA = \
 
 toolexeclibgodebugdir = $(toolexeclibgodir)/debug
 toolexeclibgodebug_DATA = \
+	debug/buildinfo.gox \
 	debug/dwarf.gox \
 	debug/elf.gox \
 	debug/gosym.gox \
@@ -804,6 +807,7 @@ toolexeclibgonetdir = $(toolexeclibgodir)/net
 toolexeclibgonet_DATA = \
 	net/http.gox \
 	net/mail.gox \
+	net/netip.gox \
 	net/rpc.gox \
 	net/smtp.gox \
 	net/textproto.gox \
@@ -892,9 +896,9 @@ toolexeclibgointernal_DATA = \
 noinst_DATA = golang.org/x/net/nettest.gox internal/cfg.gox \
 	internal/obscuretestdata.gox internal/profile.gox \
 	internal/testenv.gox internal/trace.gox \
-	net/internal/socktest.gox os/signal/internal/pty.gox \
-	reflect/internal/example1.gox reflect/internal/example2.gox \
-	zdefaultcc.go
+	net/internal/socktest.gox os/exec/internal/fdtest.gox \
+	os/signal/internal/pty.gox reflect/internal/example1.gox \
+	reflect/internal/example2.gox zdefaultcc.go
 @LIBGO_IS_RTEMS_FALSE@rtems_task_variable_add_file = 
 @LIBGO_IS_RTEMS_TRUE@rtems_task_variable_add_file = runtime/rtems-task-variable-add.c
 runtime_context_asm_file = $(am__append_3)
@@ -968,7 +972,8 @@ libgo_ldflags = \
 
 libgo_libadd = \
 	$(libgo_go_objs) ../libbacktrace/libbacktrace.la \
-	$(LIBATOMIC) $(LIBFFI) $(PTHREAD_LIBS) $(MATH_LIBS) $(NET_LIBS)
+	$(LIBATOMIC) $(LIBFFI) $(PTHREAD_LIBS) $(MATH_LIBS) \
+	$(NET_LIBS) $(RT_LIBS)
 
 libgo_la_SOURCES = $(runtime_files)
 libgo_la_LDFLAGS = $(libgo_ldflags)
@@ -1042,7 +1047,7 @@ GOBENCH =
 CHECK = \
 	GC="$(GOC) $(GOCFLAGS) $($(subst /,_,$@)_GOCFLAGS) -L `${PWD_COMMAND}` -L `${PWD_COMMAND}`/.libs"; \
 	export GC; \
-	GOLIBS="$(extra_check_libs_$(subst .,_,$(subst /,_,$(@D)))) $(PTHREAD_LIBS) $(MATH_LIBS) $(NET_LIBS) $(LIBS)"; \
+	GOLIBS="$(extra_check_libs_$(subst .,_,$(subst /,_,$(@D)))) $(PTHREAD_LIBS) $(MATH_LIBS) $(NET_LIBS) $(RT_LIBS) $(LIBS)"; \
 	export GOLIBS; \
 	RUNTESTFLAGS="$(RUNTESTFLAGS)"; \
 	export RUNTESTFLAGS; \
@@ -1138,6 +1143,8 @@ runtime_pprof_check_GOCFLAGS = -static-libgo -fno-inline
 @HAVE_STATIC_LINK_TRUE@syscall_check_GOCFLAGS = -static
 extra_go_files_runtime_internal_sys = version.go
 extra_go_files_internal_cpu = cpugen.go
+extra_go_files_internal_goarch = zgoarch.go
+extra_go_files_internal_goos = zgoos.go
 extra_go_files_golang_org_x_sys_cpu = gcpugen.go
 extra_go_files_internal_buildcfg = buildcfg.go
 extra_go_files_internal_goroot = zstdpkglist.go
@@ -2692,53 +2699,68 @@ version.go: s-version; @true
 s-version: Makefile
 	rm -f version.go.tmp
 	echo "package sys" > version.go.tmp
-	echo 'const GOARCH = "'$(GOARCH)'"' >> version.go.tmp
-	echo 'const GOOS = "'$(GOOS)'"' >> version.go.tmp
 	echo 'const GccgoToolDir = "$(libexecsubdir)"' >> version.go.tmp
 	echo 'const StackGuardMultiplierDefault = 1' >> version.go.tmp
-	echo >> version.go.tmp
-	echo "const (" >> version.go.tmp
-	echo "	UNKNOWN ArchFamilyType = iota" >> version.go.tmp
+	$(SHELL) $(srcdir)/mvifdiff.sh version.go.tmp version.go
+	$(STAMP) $@
+
+zgoarch.go: s-zgoarch; @true
+s-zgoarch: Makefile goarch.sh
+	rm -f zgoarch.go.tmp
+	echo "package goarch" > zgoarch.go.tmp
+	echo >> zgoarch.go.tmp
+	echo 'const GOARCH = "'$(GOARCH)'"' >> zgoarch.go.tmp
+	echo >> zgoarch.go.tmp
+	echo 'const (' >> zgoarch.go.tmp
+	echo "  _ArchFamily = `$(SHELL) $(srcdir)/goarch.sh $(GOARCH) family`" >> zgoarch.go.tmp
+	echo "  _BigEndian = `$(SHELL) $(srcdir)/goarch.sh $(GOARCH) bigendian`" >> zgoarch.go.tmp
+	echo "  _DefaultPhysPageSize = `$(SHELL) $(srcdir)/goarch.sh $(GOARCH) defaultphyspagesize`" >> zgoarch.go.tmp
+	echo "  _Int64Align = `$(SHELL) $(srcdir)/goarch.sh $(GOARCH) int64align`" >> zgoarch.go.tmp
+	echo "  _MinFrameSize = `$(SHELL) $(srcdir)/goarch.sh $(GOARCH) minframesize`" >> zgoarch.go.tmp
+	echo "  _PCQuantum = `$(SHELL) $(srcdir)/goarch.sh $(GOARCH) pcquantum`" >> zgoarch.go.tmp
+	echo "  _StackAlign = `$(SHELL) $(srcdir)/goarch.sh $(GOARCH) stackalign`" >> zgoarch.go.tmp
+	echo ")" >> zgoarch.go.tmp
+	echo >> zgoarch.go.tmp
+	echo "const (" >> zgoarch.go.tmp
+	echo "	UNKNOWN ArchFamilyType = iota" >> zgoarch.go.tmp
 	for a in $(ALLGOARCHFAMILY); do \
-	  echo "	$${a}" >> version.go.tmp; \
+	  echo "	$${a}" >> zgoarch.go.tmp; \
 	done
-	echo ")" >> version.go.tmp
-	echo >> version.go.tmp
+	echo ")" >> zgoarch.go.tmp
+	echo >> zgoarch.go.tmp
 	for a in $(ALLGOARCH); do \
 	  f=`echo $${a} | sed -e 's/\(.\).*/\1/' -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`; \
 	  n="$${f}`echo $${a} | sed -e 's/.//'`"; \
 	  if test "$${a}" = "$(GOARCH)"; then \
-	    echo "const Goarch$${n} = 1" >> version.go.tmp; \
+	    echo "const Is$${n} = 1" >> zgoarch.go.tmp; \
 	  else \
-	    echo "const Goarch$${n} = 0" >> version.go.tmp; \
+	    echo "const Is$${n} = 0" >> zgoarch.go.tmp; \
 	  fi; \
 	done
-	echo >> version.go.tmp
-	echo "const (" >> version.go.tmp
-	echo "  _ArchFamily = `$(SHELL) $(srcdir)/goarch.sh $(GOARCH) family`" >> version.go.tmp
-	echo "  _BigEndian = `$(SHELL) $(srcdir)/goarch.sh $(GOARCH) bigendian`" >> version.go.tmp
-	echo "  _DefaultPhysPageSize = `$(SHELL) $(srcdir)/goarch.sh $(GOARCH) defaultphyspagesize`" >> version.go.tmp
-	echo "  _Int64Align = `$(SHELL) $(srcdir)/goarch.sh $(GOARCH) int64align`" >> version.go.tmp
-	echo "  _MinFrameSize = `$(SHELL) $(srcdir)/goarch.sh $(GOARCH) minframesize`" >> version.go.tmp
-	echo "  _PCQuantum = `$(SHELL) $(srcdir)/goarch.sh $(GOARCH) pcquantum`" >> version.go.tmp
-	echo "  _StackAlign = `$(SHELL) $(srcdir)/goarch.sh $(GOARCH) stackalign`" >> version.go.tmp
-	echo ")" >> version.go.tmp
-	echo >> version.go.tmp
+	$(SHELL) $(srcdir)/mvifdiff.sh zgoarch.go.tmp zgoarch.go
+	$(STAMP) $@
+
+zgoos.go: s-zgoos; @true
+s-zgoos: Makefile
+	rm -f zgoos.go.tmp
+	echo "package goos" > zgoos.go.tmp
+	echo >> zgoos.go.tmp
+	echo 'const GOOS = "'$(GOOS)'"' >> zgoos.go.tmp
+	echo >> zgoos.go.tmp
 	for a in $(ALLGOOS); do \
 	  f=`echo $${a} | sed -e 's/\(.\).*/\1/' -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`; \
 	  n="$${f}`echo $${a} | sed -e 's/.//'`"; \
 	  if test "$${a}" = "$(GOOS)"; then \
-	    echo "const Goos$${n} = 1" >> version.go.tmp; \
+	    echo "const Is$${n} = 1" >> zgoos.go.tmp; \
 	  else \
-	    echo "const Goos$${n} = 0" >> version.go.tmp; \
+	    echo "const Is$${n} = 0" >> zgoos.go.tmp; \
 	  fi; \
 	done
-	echo >> version.go.tmp
-	$(SHELL) $(srcdir)/mvifdiff.sh version.go.tmp version.go
+	$(SHELL) $(srcdir)/mvifdiff.sh zgoos.go.tmp zgoos.go
 	$(STAMP) $@
 
 cpugen.go: s-cpu; @true
-s-cpu: Makefile
+s-cpu: Makefile goarch.sh
 	rm -f cpugen.go.tmp
 	echo "package cpu" > cpugen.go.tmp
 	echo "const CacheLinePadSize = `$(SHELL) $(srcdir)/goarch.sh $(GOARCH) cachelinesize`" >> cpugen.go.tmp
@@ -2747,7 +2769,7 @@ s-cpu: Makefile
 	$(STAMP) $@
 
 gcpugen.go: s-gcpu; @true
-s-gcpu: Makefile
+s-gcpu: Makefile goarch.sh
 	rm -f gcpugen.go.tmp
 	echo "package cpu" > gcpugen.go.tmp
 	echo "const cacheLineSize = `$(SHELL) $(srcdir)/goarch.sh $(GOARCH) cachelinesize`" >> gcpugen.go.tmp
@@ -2769,6 +2791,7 @@ s-buildcfg: Makefile
 	echo "import \"runtime\"" >> buildcfg.go.tmp
 	echo 'func defaultGOROOTValue() string { return `$(prefix)` }' >> buildcfg.go.tmp
 	echo 'const defaultGO386 = `sse2`' >> buildcfg.go.tmp
+	echo 'const defaultGOAMD64 = `v1`' >> buildcfg.go.tmp
 	echo 'const defaultGOARM = `5`' >> buildcfg.go.tmp
 	echo 'const defaultGOMIPS = `hardfloat`' >> buildcfg.go.tmp
 	echo 'const defaultGOMIPS64 = `hardfloat`' >> buildcfg.go.tmp
@@ -3019,6 +3042,8 @@ runtime.lo.dep: $(extra_go_files_runtime)
 syscall.lo.dep: $(extra_go_files_syscall)
 runtime/internal/sys.lo.dep: $(extra_go_files_runtime_internal_sys)
 internal/cpu.lo.dep: $(extra_go_files_internal_cpu)
+internal/goarch.lo.dep: $(extra_go_files_internal_goarch)
+internal/goos.lo.dep: $(extra_go_files_internal_goos)
 golang.org/x/sys/cpu.lo.dep: $(extra_go_files_golang_org_x_sys_cpu)
 cmd/internal/buildcfg.lo.dep: $(extra_go_files_internal_buildcfg)
 internal/goroot.lo.dep: $(extra_go_files_internal_goroot)
diff --git a/libgo/VERSION b/libgo/VERSION
index 844393b24b0..301234bc893 100644
--- a/libgo/VERSION
+++ b/libgo/VERSION
@@ -1 +1 @@
-go1.17.1
+go1.18beta2
diff --git a/libgo/check-packages.txt b/libgo/check-packages.txt
index dd8990f10e2..79f21689c52 100644
--- a/libgo/check-packages.txt
+++ b/libgo/check-packages.txt
@@ -19,13 +19,13 @@ cmd/go/internal/par
 cmd/go/internal/search
 cmd/go/internal/str
 cmd/go/internal/test
-cmd/go/internal/txtar
 cmd/go/internal/vcs
 cmd/go/internal/work
 cmd/internal/buildid
 cmd/internal/edit
 cmd/internal/objabi
 cmd/internal/pkgpath
+cmd/internal/quoted
 cmd/internal/test2json
 compress/bzip2
 compress/flate
@@ -46,7 +46,7 @@ crypto/ed25519
 crypto/ed25519/internal/edwards25519
 crypto/ed25519/internal/edwards25519/field
 crypto/elliptic
-crypto/elliptic/internal/fiat
+crypto/elliptic/internal/nistec
 crypto/hmac
 crypto/internal/subtle
 crypto/md5
@@ -61,6 +61,7 @@ crypto/tls
 crypto/x509
 database/sql
 database/sql/driver
+debug/buildinfo
 debug/dwarf
 debug/elf
 debug/macho
@@ -110,9 +111,13 @@ image/draw
 image/jpeg
 image/png
 index/suffixarray
+internal/buildcfg
 internal/cpu
 internal/execabs
 internal/fmtsort
+internal/fuzz
+internal/godebug
+internal/intern
 internal/itoa
 internal/poll
 internal/profile
@@ -147,6 +152,7 @@ net/http/internal/ascii
 net/http/pprof
 net/internal/socktest
 net/mail
+net/netip
 net/rpc
 net/rpc/jsonrpc
 net/smtp
diff --git a/libgo/configure b/libgo/configure
index 309e17dd91f..e2403634281 100755
--- a/libgo/configure
+++ b/libgo/configure
@@ -649,6 +649,7 @@ HAVE_SYS_MMAN_H_FALSE
 HAVE_SYS_MMAN_H_TRUE
 PTHREAD_LIBS
 PTHREAD_CFLAGS
+RT_LIBS
 NET_LIBS
 MATH_LIBS
 GOC_IS_LLGO_FALSE
@@ -2608,7 +2609,7 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu
 ac_config_headers="$ac_config_headers config.h"
 
 
-libtool_VERSION=20:0:0
+libtool_VERSION=21:0:0
 
 
 # Default to --enable-multilib
@@ -11544,7 +11545,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11547 "configure"
+#line 11548 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -11650,7 +11651,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11653 "configure"
+#line 11654 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -14747,6 +14748,12 @@ $as_echo "$libgo_cv_lib_sockets" >&6; }
 NET_LIBS="$libgo_cv_lib_sockets"
 
 
+RT_LIBS=
+case ${host} in
+  *-*-linux*) RT_LIBS=-lrt ;;
+esac
+
+
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether -pthread is supported" >&5
 $as_echo_n "checking whether -pthread is supported... " >&6; }
 if ${libgo_cv_lib_pthread+:} false; then :
diff --git a/libgo/configure.ac b/libgo/configure.ac
index 8691d5b0ac1..1b44b226f62 100644
--- a/libgo/configure.ac
+++ b/libgo/configure.ac
@@ -10,7 +10,7 @@ AC_INIT(package-unused, version-unused,, libgo)
 AC_CONFIG_SRCDIR(Makefile.am)
 AC_CONFIG_HEADER(config.h)
 
-libtool_VERSION=20:0:0
+libtool_VERSION=21:0:0
 AC_SUBST(libtool_VERSION)
 
 AM_ENABLE_MULTILIB(, ..)
@@ -549,6 +549,12 @@ AC_CACHE_CHECK([for socket libraries], libgo_cv_lib_sockets,
 NET_LIBS="$libgo_cv_lib_sockets"
 AC_SUBST(NET_LIBS)
 
+RT_LIBS=
+case ${host} in
+  *-*-linux*) RT_LIBS=-lrt ;;
+esac
+AC_SUBST(RT_LIBS)
+
 dnl Test whether the compiler supports the -pthread option.
 AC_CACHE_CHECK([whether -pthread is supported],
 [libgo_cv_lib_pthread],
diff --git a/libgo/go/archive/tar/common.go b/libgo/go/archive/tar/common.go
index c667cfc8720..c99b5c19207 100644
--- a/libgo/go/archive/tar/common.go
+++ b/libgo/go/archive/tar/common.go
@@ -316,10 +316,10 @@ func invertSparseEntries(src []sparseEntry, size int64) []sparseEntry {
 // fileState tracks the number of logical (includes sparse holes) and physical
 // (actual in tar archive) bytes remaining for the current file.
 //
-// Invariant: LogicalRemaining >= PhysicalRemaining
+// Invariant: logicalRemaining >= physicalRemaining
 type fileState interface {
-	LogicalRemaining() int64
-	PhysicalRemaining() int64
+	logicalRemaining() int64
+	physicalRemaining() int64
 }
 
 // allowedFormats determines which formats can be used.
@@ -413,22 +413,22 @@ func (h Header) allowedFormats() (format Format, paxHdrs map[string]string, err
 
 	// Check basic fields.
 	var blk block
-	v7 := blk.V7()
-	ustar := blk.USTAR()
-	gnu := blk.GNU()
-	verifyString(h.Name, len(v7.Name()), "Name", paxPath)
-	verifyString(h.Linkname, len(v7.LinkName()), "Linkname", paxLinkpath)
-	verifyString(h.Uname, len(ustar.UserName()), "Uname", paxUname)
-	verifyString(h.Gname, len(ustar.GroupName()), "Gname", paxGname)
-	verifyNumeric(h.Mode, len(v7.Mode()), "Mode", paxNone)
-	verifyNumeric(int64(h.Uid), len(v7.UID()), "Uid", paxUid)
-	verifyNumeric(int64(h.Gid), len(v7.GID()), "Gid", paxGid)
-	verifyNumeric(h.Size, len(v7.Size()), "Size", paxSize)
-	verifyNumeric(h.Devmajor, len(ustar.DevMajor()), "Devmajor", paxNone)
-	verifyNumeric(h.Devminor, len(ustar.DevMinor()), "Devminor", paxNone)
-	verifyTime(h.ModTime, len(v7.ModTime()), "ModTime", paxMtime)
-	verifyTime(h.AccessTime, len(gnu.AccessTime()), "AccessTime", paxAtime)
-	verifyTime(h.ChangeTime, len(gnu.ChangeTime()), "ChangeTime", paxCtime)
+	v7 := blk.toV7()
+	ustar := blk.toUSTAR()
+	gnu := blk.toGNU()
+	verifyString(h.Name, len(v7.name()), "Name", paxPath)
+	verifyString(h.Linkname, len(v7.linkName()), "Linkname", paxLinkpath)
+	verifyString(h.Uname, len(ustar.userName()), "Uname", paxUname)
+	verifyString(h.Gname, len(ustar.groupName()), "Gname", paxGname)
+	verifyNumeric(h.Mode, len(v7.mode()), "Mode", paxNone)
+	verifyNumeric(int64(h.Uid), len(v7.uid()), "Uid", paxUid)
+	verifyNumeric(int64(h.Gid), len(v7.gid()), "Gid", paxGid)
+	verifyNumeric(h.Size, len(v7.size()), "Size", paxSize)
+	verifyNumeric(h.Devmajor, len(ustar.devMajor()), "Devmajor", paxNone)
+	verifyNumeric(h.Devminor, len(ustar.devMinor()), "Devminor", paxNone)
+	verifyTime(h.ModTime, len(v7.modTime()), "ModTime", paxMtime)
+	verifyTime(h.AccessTime, len(gnu.accessTime()), "AccessTime", paxAtime)
+	verifyTime(h.ChangeTime, len(gnu.changeTime()), "ChangeTime", paxCtime)
 
 	// Check for header-only types.
 	var whyOnlyPAX, whyOnlyGNU string
@@ -538,7 +538,7 @@ type headerFileInfo struct {
 func (fi headerFileInfo) Size() int64        { return fi.h.Size }
 func (fi headerFileInfo) IsDir() bool        { return fi.Mode().IsDir() }
 func (fi headerFileInfo) ModTime() time.Time { return fi.h.ModTime }
-func (fi headerFileInfo) Sys() interface{}   { return fi.h }
+func (fi headerFileInfo) Sys() any           { return fi.h }
 
 // Name returns the base name of the file.
 func (fi headerFileInfo) Name() string {
diff --git a/libgo/go/archive/tar/format.go b/libgo/go/archive/tar/format.go
index cfe24a5e1d3..21b9d9d4dbc 100644
--- a/libgo/go/archive/tar/format.go
+++ b/libgo/go/archive/tar/format.go
@@ -156,28 +156,28 @@ var zeroBlock block
 type block [blockSize]byte
 
 // Convert block to any number of formats.
-func (b *block) V7() *headerV7       { return (*headerV7)(b) }
-func (b *block) GNU() *headerGNU     { return (*headerGNU)(b) }
-func (b *block) STAR() *headerSTAR   { return (*headerSTAR)(b) }
-func (b *block) USTAR() *headerUSTAR { return (*headerUSTAR)(b) }
-func (b *block) Sparse() sparseArray { return sparseArray(b[:]) }
+func (b *block) toV7() *headerV7       { return (*headerV7)(b) }
+func (b *block) toGNU() *headerGNU     { return (*headerGNU)(b) }
+func (b *block) toSTAR() *headerSTAR   { return (*headerSTAR)(b) }
+func (b *block) toUSTAR() *headerUSTAR { return (*headerUSTAR)(b) }
+func (b *block) toSparse() sparseArray { return sparseArray(b[:]) }
 
 // GetFormat checks that the block is a valid tar header based on the checksum.
 // It then attempts to guess the specific format based on magic values.
 // If the checksum fails, then FormatUnknown is returned.
-func (b *block) GetFormat() Format {
+func (b *block) getFormat() Format {
 	// Verify checksum.
 	var p parser
-	value := p.parseOctal(b.V7().Chksum())
-	chksum1, chksum2 := b.ComputeChecksum()
+	value := p.parseOctal(b.toV7().chksum())
+	chksum1, chksum2 := b.computeChecksum()
 	if p.err != nil || (value != chksum1 && value != chksum2) {
 		return FormatUnknown
 	}
 
 	// Guess the magic values.
-	magic := string(b.USTAR().Magic())
-	version := string(b.USTAR().Version())
-	trailer := string(b.STAR().Trailer())
+	magic := string(b.toUSTAR().magic())
+	version := string(b.toUSTAR().version())
+	trailer := string(b.toSTAR().trailer())
 	switch {
 	case magic == magicUSTAR && trailer == trailerSTAR:
 		return formatSTAR
@@ -190,23 +190,23 @@ func (b *block) GetFormat() Format {
 	}
 }
 
-// SetFormat writes the magic values necessary for specified format
+// setFormat writes the magic values necessary for specified format
 // and then updates the checksum accordingly.
-func (b *block) SetFormat(format Format) {
+func (b *block) setFormat(format Format) {
 	// Set the magic values.
 	switch {
 	case format.has(formatV7):
 		// Do nothing.
 	case format.has(FormatGNU):
-		copy(b.GNU().Magic(), magicGNU)
-		copy(b.GNU().Version(), versionGNU)
+		copy(b.toGNU().magic(), magicGNU)
+		copy(b.toGNU().version(), versionGNU)
 	case format.has(formatSTAR):
-		copy(b.STAR().Magic(), magicUSTAR)
-		copy(b.STAR().Version(), versionUSTAR)
-		copy(b.STAR().Trailer(), trailerSTAR)
+		copy(b.toSTAR().magic(), magicUSTAR)
+		copy(b.toSTAR().version(), versionUSTAR)
+		copy(b.toSTAR().trailer(), trailerSTAR)
 	case format.has(FormatUSTAR | FormatPAX):
-		copy(b.USTAR().Magic(), magicUSTAR)
-		copy(b.USTAR().Version(), versionUSTAR)
+		copy(b.toUSTAR().magic(), magicUSTAR)
+		copy(b.toUSTAR().version(), versionUSTAR)
 	default:
 		panic("invalid format")
 	}
@@ -214,17 +214,17 @@ func (b *block) SetFormat(format Format) {
 	// Update checksum.
 	// This field is special in that it is terminated by a NULL then space.
 	var f formatter
-	field := b.V7().Chksum()
-	chksum, _ := b.ComputeChecksum() // Possible values are 256..128776
+	field := b.toV7().chksum()
+	chksum, _ := b.computeChecksum() // Possible values are 256..128776
 	f.formatOctal(field[:7], chksum) // Never fails since 128776 < 262143
 	field[7] = ' '
 }
 
-// ComputeChecksum computes the checksum for the header block.
+// computeChecksum computes the checksum for the header block.
 // POSIX specifies a sum of the unsigned byte values, but the Sun tar used
 // signed byte values.
 // We compute and return both.
-func (b *block) ComputeChecksum() (unsigned, signed int64) {
+func (b *block) computeChecksum() (unsigned, signed int64) {
 	for i, c := range b {
 		if 148 <= i && i < 156 {
 			c = ' ' // Treat the checksum field itself as all spaces.
@@ -236,68 +236,68 @@ func (b *block) ComputeChecksum() (unsigned, signed int64) {
 }
 
 // Reset clears the block with all zeros.
-func (b *block) Reset() {
+func (b *block) reset() {
 	*b = block{}
 }
 
 type headerV7 [blockSize]byte
 
-func (h *headerV7) Name() []byte     { return h[000:][:100] }
-func (h *headerV7) Mode() []byte     { return h[100:][:8] }
-func (h *headerV7) UID() []byte      { return h[108:][:8] }
-func (h *headerV7) GID() []byte      { return h[116:][:8] }
-func (h *headerV7) Size() []byte     { return h[124:][:12] }
-func (h *headerV7) ModTime() []byte  { return h[136:][:12] }
-func (h *headerV7) Chksum() []byte   { return h[148:][:8] }
-func (h *headerV7) TypeFlag() []byte { return h[156:][:1] }
-func (h *headerV7) LinkName() []byte { return h[157:][:100] }
+func (h *headerV7) name() []byte     { return h[000:][:100] }
+func (h *headerV7) mode() []byte     { return h[100:][:8] }
+func (h *headerV7) uid() []byte      { return h[108:][:8] }
+func (h *headerV7) gid() []byte      { return h[116:][:8] }
+func (h *headerV7) size() []byte     { return h[124:][:12] }
+func (h *headerV7) modTime() []byte  { return h[136:][:12] }
+func (h *headerV7) chksum() []byte   { return h[148:][:8] }
+func (h *headerV7) typeFlag() []byte { return h[156:][:1] }
+func (h *headerV7) linkName() []byte { return h[157:][:100] }
 
 type headerGNU [blockSize]byte
 
-func (h *headerGNU) V7() *headerV7       { return (*headerV7)(h) }
-func (h *headerGNU) Magic() []byte       { return h[257:][:6] }
-func (h *headerGNU) Version() []byte     { return h[263:][:2] }
-func (h *headerGNU) UserName() []byte    { return h[265:][:32] }
-func (h *headerGNU) GroupName() []byte   { return h[297:][:32] }
-func (h *headerGNU) DevMajor() []byte    { return h[329:][:8] }
-func (h *headerGNU) DevMinor() []byte    { return h[337:][:8] }
-func (h *headerGNU) AccessTime() []byte  { return h[345:][:12] }
-func (h *headerGNU) ChangeTime() []byte  { return h[357:][:12] }
-func (h *headerGNU) Sparse() sparseArray { return sparseArray(h[386:][:24*4+1]) }
-func (h *headerGNU) RealSize() []byte    { return h[483:][:12] }
+func (h *headerGNU) v7() *headerV7       { return (*headerV7)(h) }
+func (h *headerGNU) magic() []byte       { return h[257:][:6] }
+func (h *headerGNU) version() []byte     { return h[263:][:2] }
+func (h *headerGNU) userName() []byte    { return h[265:][:32] }
+func (h *headerGNU) groupName() []byte   { return h[297:][:32] }
+func (h *headerGNU) devMajor() []byte    { return h[329:][:8] }
+func (h *headerGNU) devMinor() []byte    { return h[337:][:8] }
+func (h *headerGNU) accessTime() []byte  { return h[345:][:12] }
+func (h *headerGNU) changeTime() []byte  { return h[357:][:12] }
+func (h *headerGNU) sparse() sparseArray { return sparseArray(h[386:][:24*4+1]) }
+func (h *headerGNU) realSize() []byte    { return h[483:][:12] }
 
 type headerSTAR [blockSize]byte
 
-func (h *headerSTAR) V7() *headerV7      { return (*headerV7)(h) }
-func (h *headerSTAR) Magic() []byte      { return h[257:][:6] }
-func (h *headerSTAR) Version() []byte    { return h[263:][:2] }
-func (h *headerSTAR) UserName() []byte   { return h[265:][:32] }
-func (h *headerSTAR) GroupName() []byte  { return h[297:][:32] }
-func (h *headerSTAR) DevMajor() []byte   { return h[329:][:8] }
-func (h *headerSTAR) DevMinor() []byte   { return h[337:][:8] }
-func (h *headerSTAR) Prefix() []byte     { return h[345:][:131] }
-func (h *headerSTAR) AccessTime() []byte { return h[476:][:12] }
-func (h *headerSTAR) ChangeTime() []byte { return h[488:][:12] }
-func (h *headerSTAR) Trailer() []byte    { return h[508:][:4] }
+func (h *headerSTAR) v7() *headerV7      { return (*headerV7)(h) }
+func (h *headerSTAR) magic() []byte      { return h[257:][:6] }
+func (h *headerSTAR) version() []byte    { return h[263:][:2] }
+func (h *headerSTAR) userName() []byte   { return h[265:][:32] }
+func (h *headerSTAR) groupName() []byte  { return h[297:][:32] }
+func (h *headerSTAR) devMajor() []byte   { return h[329:][:8] }
+func (h *headerSTAR) devMinor() []byte   { return h[337:][:8] }
+func (h *headerSTAR) prefix() []byte     { return h[345:][:131] }
+func (h *headerSTAR) accessTime() []byte { return h[476:][:12] }
+func (h *headerSTAR) changeTime() []byte { return h[488:][:12] }
+func (h *headerSTAR) trailer() []byte    { return h[508:][:4] }
 
 type headerUSTAR [blockSize]byte
 
-func (h *headerUSTAR) V7() *headerV7     { return (*headerV7)(h) }
-func (h *headerUSTAR) Magic() []byte     { return h[257:][:6] }
-func (h *headerUSTAR) Version() []byte   { return h[263:][:2] }
-func (h *headerUSTAR) UserName() []byte  { return h[265:][:32] }
-func (h *headerUSTAR) GroupName() []byte { return h[297:][:32] }
-func (h *headerUSTAR) DevMajor() []byte  { return h[329:][:8] }
-func (h *headerUSTAR) DevMinor() []byte  { return h[337:][:8] }
-func (h *headerUSTAR) Prefix() []byte    { return h[345:][:155] }
+func (h *headerUSTAR) v7() *headerV7     { return (*headerV7)(h) }
+func (h *headerUSTAR) magic() []byte     { return h[257:][:6] }
+func (h *headerUSTAR) version() []byte   { return h[263:][:2] }
+func (h *headerUSTAR) userName() []byte  { return h[265:][:32] }
+func (h *headerUSTAR) groupName() []byte { return h[297:][:32] }
+func (h *headerUSTAR) devMajor() []byte  { return h[329:][:8] }
+func (h *headerUSTAR) devMinor() []byte  { return h[337:][:8] }
+func (h *headerUSTAR) prefix() []byte    { return h[345:][:155] }
 
 type sparseArray []byte
 
-func (s sparseArray) Entry(i int) sparseElem { return sparseElem(s[i*24:]) }
-func (s sparseArray) IsExtended() []byte     { return s[24*s.MaxEntries():][:1] }
-func (s sparseArray) MaxEntries() int        { return len(s) / 24 }
+func (s sparseArray) entry(i int) sparseElem { return sparseElem(s[i*24:]) }
+func (s sparseArray) isExtended() []byte     { return s[24*s.maxEntries():][:1] }
+func (s sparseArray) maxEntries() int        { return len(s) / 24 }
 
 type sparseElem []byte
 
-func (s sparseElem) Offset() []byte { return s[00:][:12] }
-func (s sparseElem) Length() []byte { return s[12:][:12] }
+func (s sparseElem) offset() []byte { return s[00:][:12] }
+func (s sparseElem) length() []byte { return s[12:][:12] }
diff --git a/libgo/go/archive/tar/fuzz_test.go b/libgo/go/archive/tar/fuzz_test.go
new file mode 100644
index 00000000000..e73e0d2609e
--- /dev/null
+++ b/libgo/go/archive/tar/fuzz_test.go
@@ -0,0 +1,80 @@
+// Copyright 2021 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 tar
+
+import (
+	"bytes"
+	"io"
+	"testing"
+)
+
+func FuzzReader(f *testing.F) {
+	b := bytes.NewBuffer(nil)
+	w := NewWriter(b)
+	inp := []byte("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.")
+	err := w.WriteHeader(&Header{
+		Name: "lorem.txt",
+		Mode: 0600,
+		Size: int64(len(inp)),
+	})
+	if err != nil {
+		f.Fatalf("failed to create writer: %s", err)
+	}
+	_, err = w.Write(inp)
+	if err != nil {
+		f.Fatalf("failed to write file to archive: %s", err)
+	}
+	if err := w.Close(); err != nil {
+		f.Fatalf("failed to write archive: %s", err)
+	}
+	f.Add(b.Bytes())
+
+	f.Fuzz(func(t *testing.T, b []byte) {
+		r := NewReader(bytes.NewReader(b))
+		type file struct {
+			header  *Header
+			content []byte
+		}
+		files := []file{}
+		for {
+			hdr, err := r.Next()
+			if err == io.EOF {
+				break
+			}
+			if err != nil {
+				return
+			}
+			buf := bytes.NewBuffer(nil)
+			if _, err := io.Copy(buf, r); err != nil {
+				continue
+			}
+			files = append(files, file{header: hdr, content: buf.Bytes()})
+		}
+
+		// If we were unable to read anything out of the archive don't
+		// bother trying to roundtrip it.
+		if len(files) == 0 {
+			return
+		}
+
+		out := bytes.NewBuffer(nil)
+		w := NewWriter(out)
+		for _, f := range files {
+			if err := w.WriteHeader(f.header); err != nil {
+				t.Fatalf("unable to write previously parsed header: %s", err)
+			}
+			if _, err := w.Write(f.content); err != nil {
+				t.Fatalf("unable to write previously parsed content: %s", err)
+			}
+		}
+		if err := w.Close(); err != nil {
+			t.Fatalf("Unable to write archive: %s", err)
+		}
+
+		// TODO: We may want to check if the archive roundtrips. This would require
+		// taking into account addition of the two zero trailer blocks that Writer.Close
+		// appends.
+	})
+}
diff --git a/libgo/go/archive/tar/reader.go b/libgo/go/archive/tar/reader.go
index 1b1d5b46891..4b11909bc95 100644
--- a/libgo/go/archive/tar/reader.go
+++ b/libgo/go/archive/tar/reader.go
@@ -65,7 +65,7 @@ func (tr *Reader) next() (*Header, error) {
 	format := FormatUSTAR | FormatPAX | FormatGNU
 	for {
 		// Discard the remainder of the file and any padding.
-		if err := discard(tr.r, tr.curr.PhysicalRemaining()); err != nil {
+		if err := discard(tr.r, tr.curr.physicalRemaining()); err != nil {
 			return nil, err
 		}
 		if _, err := tryReadFull(tr.r, tr.blk[:tr.pad]); err != nil {
@@ -355,7 +355,7 @@ func (tr *Reader) readHeader() (*Header, *block, error) {
 	}
 
 	// Verify the header matches a known format.
-	format := tr.blk.GetFormat()
+	format := tr.blk.getFormat()
 	if format == FormatUnknown {
 		return nil, nil, ErrHeader
 	}
@@ -364,30 +364,30 @@ func (tr *Reader) readHeader() (*Header, *block, error) {
 	hdr := new(Header)
 
 	// Unpack the V7 header.
-	v7 := tr.blk.V7()
-	hdr.Typeflag = v7.TypeFlag()[0]
-	hdr.Name = p.parseString(v7.Name())
-	hdr.Linkname = p.parseString(v7.LinkName())
-	hdr.Size = p.parseNumeric(v7.Size())
-	hdr.Mode = p.parseNumeric(v7.Mode())
-	hdr.Uid = int(p.parseNumeric(v7.UID()))
-	hdr.Gid = int(p.parseNumeric(v7.GID()))
-	hdr.ModTime = time.Unix(p.parseNumeric(v7.ModTime()), 0)
+	v7 := tr.blk.toV7()
+	hdr.Typeflag = v7.typeFlag()[0]
+	hdr.Name = p.parseString(v7.name())
+	hdr.Linkname = p.parseString(v7.linkName())
+	hdr.Size = p.parseNumeric(v7.size())
+	hdr.Mode = p.parseNumeric(v7.mode())
+	hdr.Uid = int(p.parseNumeric(v7.uid()))
+	hdr.Gid = int(p.parseNumeric(v7.gid()))
+	hdr.ModTime = time.Unix(p.parseNumeric(v7.modTime()), 0)
 
 	// Unpack format specific fields.
 	if format > formatV7 {
-		ustar := tr.blk.USTAR()
-		hdr.Uname = p.parseString(ustar.UserName())
-		hdr.Gname = p.parseString(ustar.GroupName())
-		hdr.Devmajor = p.parseNumeric(ustar.DevMajor())
-		hdr.Devminor = p.parseNumeric(ustar.DevMinor())
+		ustar := tr.blk.toUSTAR()
+		hdr.Uname = p.parseString(ustar.userName())
+		hdr.Gname = p.parseString(ustar.groupName())
+		hdr.Devmajor = p.parseNumeric(ustar.devMajor())
+		hdr.Devminor = p.parseNumeric(ustar.devMinor())
 
 		var prefix string
 		switch {
 		case format.has(FormatUSTAR | FormatPAX):
 			hdr.Format = format
-			ustar := tr.blk.USTAR()
-			prefix = p.parseString(ustar.Prefix())
+			ustar := tr.blk.toUSTAR()
+			prefix = p.parseString(ustar.prefix())
 
 			// For Format detection, check if block is properly formatted since
 			// the parser is more liberal than what USTAR actually permits.
@@ -396,23 +396,23 @@ func (tr *Reader) readHeader() (*Header, *block, error) {
 				hdr.Format = FormatUnknown // Non-ASCII characters in block.
 			}
 			nul := func(b []byte) bool { return int(b[len(b)-1]) == 0 }
-			if !(nul(v7.Size()) && nul(v7.Mode()) && nul(v7.UID()) && nul(v7.GID()) &&
-				nul(v7.ModTime()) && nul(ustar.DevMajor()) && nul(ustar.DevMinor())) {
+			if !(nul(v7.size()) && nul(v7.mode()) && nul(v7.uid()) && nul(v7.gid()) &&
+				nul(v7.modTime()) && nul(ustar.devMajor()) && nul(ustar.devMinor())) {
 				hdr.Format = FormatUnknown // Numeric fields must end in NUL
 			}
 		case format.has(formatSTAR):
-			star := tr.blk.STAR()
-			prefix = p.parseString(star.Prefix())
-			hdr.AccessTime = time.Unix(p.parseNumeric(star.AccessTime()), 0)
-			hdr.ChangeTime = time.Unix(p.parseNumeric(star.ChangeTime()), 0)
+			star := tr.blk.toSTAR()
+			prefix = p.parseString(star.prefix())
+			hdr.AccessTime = time.Unix(p.parseNumeric(star.accessTime()), 0)
+			hdr.ChangeTime = time.Unix(p.parseNumeric(star.changeTime()), 0)
 		case format.has(FormatGNU):
 			hdr.Format = format
 			var p2 parser
-			gnu := tr.blk.GNU()
-			if b := gnu.AccessTime(); b[0] != 0 {
+			gnu := tr.blk.toGNU()
+			if b := gnu.accessTime(); b[0] != 0 {
 				hdr.AccessTime = time.Unix(p2.parseNumeric(b), 0)
 			}
-			if b := gnu.ChangeTime(); b[0] != 0 {
+			if b := gnu.changeTime(); b[0] != 0 {
 				hdr.ChangeTime = time.Unix(p2.parseNumeric(b), 0)
 			}
 
@@ -439,8 +439,8 @@ func (tr *Reader) readHeader() (*Header, *block, error) {
 			// See https://golang.org/issues/21005
 			if p2.err != nil {
 				hdr.AccessTime, hdr.ChangeTime = time.Time{}, time.Time{}
-				ustar := tr.blk.USTAR()
-				if s := p.parseString(ustar.Prefix()); isASCII(s) {
+				ustar := tr.blk.toUSTAR()
+				if s := p.parseString(ustar.prefix()); isASCII(s) {
 					prefix = s
 				}
 				hdr.Format = FormatUnknown // Buggy file is not GNU
@@ -465,38 +465,38 @@ func (tr *Reader) readOldGNUSparseMap(hdr *Header, blk *block) (sparseDatas, err
 	// Make sure that the input format is GNU.
 	// Unfortunately, the STAR format also has a sparse header format that uses
 	// the same type flag but has a completely different layout.
-	if blk.GetFormat() != FormatGNU {
+	if blk.getFormat() != FormatGNU {
 		return nil, ErrHeader
 	}
 	hdr.Format.mayOnlyBe(FormatGNU)
 
 	var p parser
-	hdr.Size = p.parseNumeric(blk.GNU().RealSize())
+	hdr.Size = p.parseNumeric(blk.toGNU().realSize())
 	if p.err != nil {
 		return nil, p.err
 	}
-	s := blk.GNU().Sparse()
-	spd := make(sparseDatas, 0, s.MaxEntries())
+	s := blk.toGNU().sparse()
+	spd := make(sparseDatas, 0, s.maxEntries())
 	for {
-		for i := 0; i < s.MaxEntries(); i++ {
+		for i := 0; i < s.maxEntries(); i++ {
 			// This termination condition is identical to GNU and BSD tar.
-			if s.Entry(i).Offset()[0] == 0x00 {
+			if s.entry(i).offset()[0] == 0x00 {
 				break // Don't return, need to process extended headers (even if empty)
 			}
-			offset := p.parseNumeric(s.Entry(i).Offset())
-			length := p.parseNumeric(s.Entry(i).Length())
+			offset := p.parseNumeric(s.entry(i).offset())
+			length := p.parseNumeric(s.entry(i).length())
 			if p.err != nil {
 				return nil, p.err
 			}
 			spd = append(spd, sparseEntry{Offset: offset, Length: length})
 		}
 
-		if s.IsExtended()[0] > 0 {
+		if s.isExtended()[0] > 0 {
 			// There are more entries. Read an extension header and parse its entries.
 			if _, err := mustReadFull(tr.r, blk[:]); err != nil {
 				return nil, err
 			}
-			s = blk.Sparse()
+			s = blk.toSparse()
 			continue
 		}
 		return spd, nil // Done
@@ -678,11 +678,13 @@ func (fr *regFileReader) WriteTo(w io.Writer) (int64, error) {
 	return io.Copy(w, struct{ io.Reader }{fr})
 }
 
-func (fr regFileReader) LogicalRemaining() int64 {
+// logicalRemaining implements fileState.logicalRemaining.
+func (fr regFileReader) logicalRemaining() int64 {
 	return fr.nb
 }
 
-func (fr regFileReader) PhysicalRemaining() int64 {
+// logicalRemaining implements fileState.physicalRemaining.
+func (fr regFileReader) physicalRemaining() int64 {
 	return fr.nb
 }
 
@@ -694,9 +696,9 @@ type sparseFileReader struct {
 }
 
 func (sr *sparseFileReader) Read(b []byte) (n int, err error) {
-	finished := int64(len(b)) >= sr.LogicalRemaining()
+	finished := int64(len(b)) >= sr.logicalRemaining()
 	if finished {
-		b = b[:sr.LogicalRemaining()]
+		b = b[:sr.logicalRemaining()]
 	}
 
 	b0 := b
@@ -724,7 +726,7 @@ func (sr *sparseFileReader) Read(b []byte) (n int, err error) {
 		return n, errMissData // Less data in dense file than sparse file
 	case err != nil:
 		return n, err
-	case sr.LogicalRemaining() == 0 && sr.PhysicalRemaining() > 0:
+	case sr.logicalRemaining() == 0 && sr.physicalRemaining() > 0:
 		return n, errUnrefData // More data in dense file than sparse file
 	case finished:
 		return n, io.EOF
@@ -746,7 +748,7 @@ func (sr *sparseFileReader) WriteTo(w io.Writer) (n int64, err error) {
 
 	var writeLastByte bool
 	pos0 := sr.pos
-	for sr.LogicalRemaining() > 0 && !writeLastByte && err == nil {
+	for sr.logicalRemaining() > 0 && !writeLastByte && err == nil {
 		var nf int64 // Size of fragment
 		holeStart, holeEnd := sr.sp[0].Offset, sr.sp[0].endOffset()
 		if sr.pos < holeStart { // In a data fragment
@@ -754,7 +756,7 @@ func (sr *sparseFileReader) WriteTo(w io.Writer) (n int64, err error) {
 			nf, err = io.CopyN(ws, sr.fr, nf)
 		} else { // In a hole fragment
 			nf = holeEnd - sr.pos
-			if sr.PhysicalRemaining() == 0 {
+			if sr.physicalRemaining() == 0 {
 				writeLastByte = true
 				nf--
 			}
@@ -779,18 +781,18 @@ func (sr *sparseFileReader) WriteTo(w io.Writer) (n int64, err error) {
 		return n, errMissData // Less data in dense file than sparse file
 	case err != nil:
 		return n, err
-	case sr.LogicalRemaining() == 0 && sr.PhysicalRemaining() > 0:
+	case sr.logicalRemaining() == 0 && sr.physicalRemaining() > 0:
 		return n, errUnrefData // More data in dense file than sparse file
 	default:
 		return n, nil
 	}
 }
 
-func (sr sparseFileReader) LogicalRemaining() int64 {
+func (sr sparseFileReader) logicalRemaining() int64 {
 	return sr.sp[len(sr.sp)-1].endOffset() - sr.pos
 }
-func (sr sparseFileReader) PhysicalRemaining() int64 {
-	return sr.fr.PhysicalRemaining()
+func (sr sparseFileReader) physicalRemaining() int64 {
+	return sr.fr.physicalRemaining()
 }
 
 type zeroReader struct{}
diff --git a/libgo/go/archive/tar/reader_test.go b/libgo/go/archive/tar/reader_test.go
index 789ddc1bc03..f21a6065b48 100644
--- a/libgo/go/archive/tar/reader_test.go
+++ b/libgo/go/archive/tar/reader_test.go
@@ -1021,12 +1021,12 @@ func TestParsePAX(t *testing.T) {
 
 func TestReadOldGNUSparseMap(t *testing.T) {
 	populateSparseMap := func(sa sparseArray, sps []string) []string {
-		for i := 0; len(sps) > 0 && i < sa.MaxEntries(); i++ {
-			copy(sa.Entry(i), sps[0])
+		for i := 0; len(sps) > 0 && i < sa.maxEntries(); i++ {
+			copy(sa.entry(i), sps[0])
 			sps = sps[1:]
 		}
 		if len(sps) > 0 {
-			copy(sa.IsExtended(), "\x80")
+			copy(sa.isExtended(), "\x80")
 		}
 		return sps
 	}
@@ -1034,19 +1034,19 @@ func TestReadOldGNUSparseMap(t *testing.T) {
 	makeInput := func(format Format, size string, sps ...string) (out []byte) {
 		// Write the initial GNU header.
 		var blk block
-		gnu := blk.GNU()
-		sparse := gnu.Sparse()
-		copy(gnu.RealSize(), size)
+		gnu := blk.toGNU()
+		sparse := gnu.sparse()
+		copy(gnu.realSize(), size)
 		sps = populateSparseMap(sparse, sps)
 		if format != FormatUnknown {
-			blk.SetFormat(format)
+			blk.setFormat(format)
 		}
 		out = append(out, blk[:]...)
 
 		// Write extended sparse blocks.
 		for len(sps) > 0 {
 			var blk block
-			sps = populateSparseMap(blk.Sparse(), sps)
+			sps = populateSparseMap(blk.toSparse(), sps)
 			out = append(out, blk[:]...)
 		}
 		return out
@@ -1359,11 +1359,11 @@ func TestFileReader(t *testing.T) {
 			wantCnt int64
 			wantErr error
 		}
-		testRemaining struct { // LogicalRemaining() == wantLCnt, PhysicalRemaining() == wantPCnt
+		testRemaining struct { // logicalRemaining() == wantLCnt, physicalRemaining() == wantPCnt
 			wantLCnt int64
 			wantPCnt int64
 		}
-		testFnc interface{} // testRead | testWriteTo | testRemaining
+		testFnc any // testRead | testWriteTo | testRemaining
 	)
 
 	type (
@@ -1376,7 +1376,7 @@ func TestFileReader(t *testing.T) {
 			spd     sparseDatas
 			size    int64
 		}
-		fileMaker interface{} // makeReg | makeSparse
+		fileMaker any // makeReg | makeSparse
 	)
 
 	vectors := []struct {
@@ -1596,11 +1596,11 @@ func TestFileReader(t *testing.T) {
 					t.Errorf("test %d.%d, expected %d more operations", i, j, len(f.ops))
 				}
 			case testRemaining:
-				if got := fr.LogicalRemaining(); got != tf.wantLCnt {
-					t.Errorf("test %d.%d, LogicalRemaining() = %d, want %d", i, j, got, tf.wantLCnt)
+				if got := fr.logicalRemaining(); got != tf.wantLCnt {
+					t.Errorf("test %d.%d, logicalRemaining() = %d, want %d", i, j, got, tf.wantLCnt)
 				}
-				if got := fr.PhysicalRemaining(); got != tf.wantPCnt {
-					t.Errorf("test %d.%d, PhysicalRemaining() = %d, want %d", i, j, got, tf.wantPCnt)
+				if got := fr.physicalRemaining(); got != tf.wantPCnt {
+					t.Errorf("test %d.%d, physicalRemaining() = %d, want %d", i, j, got, tf.wantPCnt)
 				}
 			default:
 				t.Fatalf("test %d.%d, unknown test operation: %T", i, j, tf)
diff --git a/libgo/go/archive/tar/stat_actime1.go b/libgo/go/archive/tar/stat_actime1.go
index 71cece5793a..5e4a00dc4d2 100644
--- a/libgo/go/archive/tar/stat_actime1.go
+++ b/libgo/go/archive/tar/stat_actime1.go
@@ -3,7 +3,6 @@
 // license that can be found in the LICENSE file.
 
 //go:build aix || hurd || linux || dragonfly || openbsd || solaris
-// +build aix hurd linux dragonfly openbsd solaris
 
 package tar
 
diff --git a/libgo/go/archive/tar/stat_actime2.go b/libgo/go/archive/tar/stat_actime2.go
index 5a9a35cbb4e..f76d6be220f 100644
--- a/libgo/go/archive/tar/stat_actime2.go
+++ b/libgo/go/archive/tar/stat_actime2.go
@@ -3,7 +3,6 @@
 // license that can be found in the LICENSE file.
 
 //go:build darwin || freebsd || netbsd
-// +build darwin freebsd netbsd
 
 package tar
 
diff --git a/libgo/go/archive/tar/stat_unix.go b/libgo/go/archive/tar/stat_unix.go
index f27df67eedc..1349f3e8b7d 100644
--- a/libgo/go/archive/tar/stat_unix.go
+++ b/libgo/go/archive/tar/stat_unix.go
@@ -3,7 +3,6 @@
 // license that can be found in the LICENSE file.
 
 //go:build aix || hurd || linux || darwin || dragonfly || freebsd || openbsd || netbsd || solaris
-// +build aix hurd linux darwin dragonfly freebsd openbsd netbsd solaris
 
 package tar
 
diff --git a/libgo/go/archive/tar/strconv.go b/libgo/go/archive/tar/strconv.go
index f0b61e6dba6..275db6f0263 100644
--- a/libgo/go/archive/tar/strconv.go
+++ b/libgo/go/archive/tar/strconv.go
@@ -14,7 +14,7 @@ import (
 
 // hasNUL reports whether the NUL character exists within s.
 func hasNUL(s string) bool {
-	return strings.IndexByte(s, 0) >= 0
+	return strings.Contains(s, "\x00")
 }
 
 // isASCII reports whether the input is an ASCII C-style string.
@@ -201,10 +201,7 @@ func parsePAXTime(s string) (time.Time, error) {
 	const maxNanoSecondDigits = 9
 
 	// Split string into seconds and sub-seconds parts.
-	ss, sn := s, ""
-	if pos := strings.IndexByte(s, '.'); pos >= 0 {
-		ss, sn = s[:pos], s[pos+1:]
-	}
+	ss, sn, _ := strings.Cut(s, ".")
 
 	// Parse the seconds.
 	secs, err := strconv.ParseInt(ss, 10, 64)
@@ -254,48 +251,32 @@ func formatPAXTime(ts time.Time) (s string) {
 // return the remainder as r.
 func parsePAXRecord(s string) (k, v, r string, err error) {
 	// The size field ends at the first space.
-	sp := strings.IndexByte(s, ' ')
-	if sp == -1 {
+	nStr, rest, ok := strings.Cut(s, " ")
+	if !ok {
 		return "", "", s, ErrHeader
 	}
 
 	// Parse the first token as a decimal integer.
-	n, perr := strconv.ParseInt(s[:sp], 10, 0) // Intentionally parse as native int
-	if perr != nil || n < 5 || int64(len(s)) < n {
+	n, perr := strconv.ParseInt(nStr, 10, 0) // Intentionally parse as native int
+	if perr != nil || n < 5 || n > int64(len(s)) {
 		return "", "", s, ErrHeader
 	}
-
-	afterSpace := int64(sp + 1)
-	beforeLastNewLine := n - 1
-	// In some cases, "length" was perhaps padded/malformed, and
-	// trying to index past where the space supposedly is goes past
-	// the end of the actual record.
-	// For example:
-	//    "0000000000000000000000000000000030 mtime=1432668921.098285006\n30 ctime=2147483649.15163319"
-	//                                  ^     ^
-	//                                  |     |
-	//                                  |  afterSpace=35
-	//                                  |
-	//                          beforeLastNewLine=29
-	// yet indexOf(firstSpace) MUST BE before endOfRecord.
-	//
-	// See https://golang.org/issues/40196.
-	if afterSpace >= beforeLastNewLine {
+	n -= int64(len(nStr) + 1) // convert from index in s to index in rest
+	if n <= 0 {
 		return "", "", s, ErrHeader
 	}
 
 	// Extract everything between the space and the final newline.
-	rec, nl, rem := s[afterSpace:beforeLastNewLine], s[beforeLastNewLine:n], s[n:]
+	rec, nl, rem := rest[:n-1], rest[n-1:n], rest[n:]
 	if nl != "\n" {
 		return "", "", s, ErrHeader
 	}
 
 	// The first equals separates the key from the value.
-	eq := strings.IndexByte(rec, '=')
-	if eq == -1 {
+	k, v, ok = strings.Cut(rec, "=")
+	if !ok {
 		return "", "", s, ErrHeader
 	}
-	k, v = rec[:eq], rec[eq+1:]
 
 	if !validPAXRecord(k, v) {
 		return "", "", s, ErrHeader
@@ -333,7 +314,7 @@ func formatPAXRecord(k, v string) (string, error) {
 // for the PAX version of the USTAR string fields.
 // The key must not contain an '=' character.
 func validPAXRecord(k, v string) bool {
-	if k == "" || strings.IndexByte(k, '=') >= 0 {
+	if k == "" || strings.Contains(k, "=") {
 		return false
 	}
 	switch k {
diff --git a/libgo/go/archive/tar/tar_test.go b/libgo/go/archive/tar/tar_test.go
index e9fafc7cc70..a476f5eb010 100644
--- a/libgo/go/archive/tar/tar_test.go
+++ b/libgo/go/archive/tar/tar_test.go
@@ -23,7 +23,7 @@ import (
 
 type testError struct{ error }
 
-type fileOps []interface{} // []T where T is (string | int64)
+type fileOps []any // []T where T is (string | int64)
 
 // testFile is an io.ReadWriteSeeker where the IO operations performed
 // on it must match the list of operations in ops.
diff --git a/libgo/go/archive/tar/writer.go b/libgo/go/archive/tar/writer.go
index e80498d03e3..3729f7e82c1 100644
--- a/libgo/go/archive/tar/writer.go
+++ b/libgo/go/archive/tar/writer.go
@@ -50,7 +50,7 @@ func (tw *Writer) Flush() error {
 	if tw.err != nil {
 		return tw.err
 	}
-	if nb := tw.curr.LogicalRemaining(); nb > 0 {
+	if nb := tw.curr.logicalRemaining(); nb > 0 {
 		return fmt.Errorf("archive/tar: missed writing %d bytes", nb)
 	}
 	if _, tw.err = tw.w.Write(zeroBlock[:tw.pad]); tw.err != nil {
@@ -117,8 +117,8 @@ func (tw *Writer) writeUSTARHeader(hdr *Header) error {
 	// Pack the main header.
 	var f formatter
 	blk := tw.templateV7Plus(hdr, f.formatString, f.formatOctal)
-	f.formatString(blk.USTAR().Prefix(), namePrefix)
-	blk.SetFormat(FormatUSTAR)
+	f.formatString(blk.toUSTAR().prefix(), namePrefix)
+	blk.setFormat(FormatUSTAR)
 	if f.err != nil {
 		return f.err // Should never happen since header is validated
 	}
@@ -208,7 +208,7 @@ func (tw *Writer) writePAXHeader(hdr *Header, paxHdrs map[string]string) error {
 	var f formatter // Ignore errors since they are expected
 	fmtStr := func(b []byte, s string) { f.formatString(b, toASCII(s)) }
 	blk := tw.templateV7Plus(hdr, fmtStr, f.formatOctal)
-	blk.SetFormat(FormatPAX)
+	blk.setFormat(FormatPAX)
 	if err := tw.writeRawHeader(blk, hdr.Size, hdr.Typeflag); err != nil {
 		return err
 	}
@@ -250,10 +250,10 @@ func (tw *Writer) writeGNUHeader(hdr *Header) error {
 	var spb []byte
 	blk := tw.templateV7Plus(hdr, f.formatString, f.formatNumeric)
 	if !hdr.AccessTime.IsZero() {
-		f.formatNumeric(blk.GNU().AccessTime(), hdr.AccessTime.Unix())
+		f.formatNumeric(blk.toGNU().accessTime(), hdr.AccessTime.Unix())
 	}
 	if !hdr.ChangeTime.IsZero() {
-		f.formatNumeric(blk.GNU().ChangeTime(), hdr.ChangeTime.Unix())
+		f.formatNumeric(blk.toGNU().changeTime(), hdr.ChangeTime.Unix())
 	}
 	// TODO(dsnet): Re-enable this when adding sparse support.
 	// See https://golang.org/issue/22735
@@ -293,7 +293,7 @@ func (tw *Writer) writeGNUHeader(hdr *Header) error {
 			f.formatNumeric(blk.GNU().RealSize(), realSize)
 		}
 	*/
-	blk.SetFormat(FormatGNU)
+	blk.setFormat(FormatGNU)
 	if err := tw.writeRawHeader(blk, hdr.Size, hdr.Typeflag); err != nil {
 		return err
 	}
@@ -321,28 +321,28 @@ type (
 // The block returned is only valid until the next call to
 // templateV7Plus or writeRawFile.
 func (tw *Writer) templateV7Plus(hdr *Header, fmtStr stringFormatter, fmtNum numberFormatter) *block {
-	tw.blk.Reset()
+	tw.blk.reset()
 
 	modTime := hdr.ModTime
 	if modTime.IsZero() {
 		modTime = time.Unix(0, 0)
 	}
 
-	v7 := tw.blk.V7()
-	v7.TypeFlag()[0] = hdr.Typeflag
-	fmtStr(v7.Name(), hdr.Name)
-	fmtStr(v7.LinkName(), hdr.Linkname)
-	fmtNum(v7.Mode(), hdr.Mode)
-	fmtNum(v7.UID(), int64(hdr.Uid))
-	fmtNum(v7.GID(), int64(hdr.Gid))
-	fmtNum(v7.Size(), hdr.Size)
-	fmtNum(v7.ModTime(), modTime.Unix())
+	v7 := tw.blk.toV7()
+	v7.typeFlag()[0] = hdr.Typeflag
+	fmtStr(v7.name(), hdr.Name)
+	fmtStr(v7.linkName(), hdr.Linkname)
+	fmtNum(v7.mode(), hdr.Mode)
+	fmtNum(v7.uid(), int64(hdr.Uid))
+	fmtNum(v7.gid(), int64(hdr.Gid))
+	fmtNum(v7.size(), hdr.Size)
+	fmtNum(v7.modTime(), modTime.Unix())
 
-	ustar := tw.blk.USTAR()
-	fmtStr(ustar.UserName(), hdr.Uname)
-	fmtStr(ustar.GroupName(), hdr.Gname)
-	fmtNum(ustar.DevMajor(), hdr.Devmajor)
-	fmtNum(ustar.DevMinor(), hdr.Devminor)
+	ustar := tw.blk.toUSTAR()
+	fmtStr(ustar.userName(), hdr.Uname)
+	fmtStr(ustar.groupName(), hdr.Gname)
+	fmtNum(ustar.devMajor(), hdr.Devmajor)
+	fmtNum(ustar.devMinor(), hdr.Devminor)
 
 	return &tw.blk
 }
@@ -351,7 +351,7 @@ func (tw *Writer) templateV7Plus(hdr *Header, fmtStr stringFormatter, fmtNum num
 // It uses format to encode the header format and will write data as the body.
 // It uses default values for all of the other fields (as BSD and GNU tar does).
 func (tw *Writer) writeRawFile(name, data string, flag byte, format Format) error {
-	tw.blk.Reset()
+	tw.blk.reset()
 
 	// Best effort for the filename.
 	name = toASCII(name)
@@ -361,15 +361,15 @@ func (tw *Writer) writeRawFile(name, data string, flag byte, format Format) erro
 	name = strings.TrimRight(name, "/")
 
 	var f formatter
-	v7 := tw.blk.V7()
-	v7.TypeFlag()[0] = flag
-	f.formatString(v7.Name(), name)
-	f.formatOctal(v7.Mode(), 0)
-	f.formatOctal(v7.UID(), 0)
-	f.formatOctal(v7.GID(), 0)
-	f.formatOctal(v7.Size(), int64(len(data))) // Must be < 8GiB
-	f.formatOctal(v7.ModTime(), 0)
-	tw.blk.SetFormat(format)
+	v7 := tw.blk.toV7()
+	v7.typeFlag()[0] = flag
+	f.formatString(v7.name(), name)
+	f.formatOctal(v7.mode(), 0)
+	f.formatOctal(v7.uid(), 0)
+	f.formatOctal(v7.gid(), 0)
+	f.formatOctal(v7.size(), int64(len(data))) // Must be < 8GiB
+	f.formatOctal(v7.modTime(), 0)
+	tw.blk.setFormat(format)
 	if f.err != nil {
 		return f.err // Only occurs if size condition is violated
 	}
@@ -511,10 +511,13 @@ func (fw *regFileWriter) ReadFrom(r io.Reader) (int64, error) {
 	return io.Copy(struct{ io.Writer }{fw}, r)
 }
 
-func (fw regFileWriter) LogicalRemaining() int64 {
+// logicalRemaining implements fileState.logicalRemaining.
+func (fw regFileWriter) logicalRemaining() int64 {
 	return fw.nb
 }
-func (fw regFileWriter) PhysicalRemaining() int64 {
+
+// logicalRemaining implements fileState.physicalRemaining.
+func (fw regFileWriter) physicalRemaining() int64 {
 	return fw.nb
 }
 
@@ -526,9 +529,9 @@ type sparseFileWriter struct {
 }
 
 func (sw *sparseFileWriter) Write(b []byte) (n int, err error) {
-	overwrite := int64(len(b)) > sw.LogicalRemaining()
+	overwrite := int64(len(b)) > sw.logicalRemaining()
 	if overwrite {
-		b = b[:sw.LogicalRemaining()]
+		b = b[:sw.logicalRemaining()]
 	}
 
 	b0 := b
@@ -556,7 +559,7 @@ func (sw *sparseFileWriter) Write(b []byte) (n int, err error) {
 		return n, errMissData // Not possible; implies bug in validation logic
 	case err != nil:
 		return n, err
-	case sw.LogicalRemaining() == 0 && sw.PhysicalRemaining() > 0:
+	case sw.logicalRemaining() == 0 && sw.physicalRemaining() > 0:
 		return n, errUnrefData // Not possible; implies bug in validation logic
 	case overwrite:
 		return n, ErrWriteTooLong
@@ -578,12 +581,12 @@ func (sw *sparseFileWriter) ReadFrom(r io.Reader) (n int64, err error) {
 
 	var readLastByte bool
 	pos0 := sw.pos
-	for sw.LogicalRemaining() > 0 && !readLastByte && err == nil {
+	for sw.logicalRemaining() > 0 && !readLastByte && err == nil {
 		var nf int64 // Size of fragment
 		dataStart, dataEnd := sw.sp[0].Offset, sw.sp[0].endOffset()
 		if sw.pos < dataStart { // In a hole fragment
 			nf = dataStart - sw.pos
-			if sw.PhysicalRemaining() == 0 {
+			if sw.physicalRemaining() == 0 {
 				readLastByte = true
 				nf--
 			}
@@ -613,18 +616,18 @@ func (sw *sparseFileWriter) ReadFrom(r io.Reader) (n int64, err error) {
 		return n, errMissData // Not possible; implies bug in validation logic
 	case err != nil:
 		return n, err
-	case sw.LogicalRemaining() == 0 && sw.PhysicalRemaining() > 0:
+	case sw.logicalRemaining() == 0 && sw.physicalRemaining() > 0:
 		return n, errUnrefData // Not possible; implies bug in validation logic
 	default:
 		return n, ensureEOF(rs)
 	}
 }
 
-func (sw sparseFileWriter) LogicalRemaining() int64 {
+func (sw sparseFileWriter) logicalRemaining() int64 {
 	return sw.sp[len(sw.sp)-1].endOffset() - sw.pos
 }
-func (sw sparseFileWriter) PhysicalRemaining() int64 {
-	return sw.fw.PhysicalRemaining()
+func (sw sparseFileWriter) physicalRemaining() int64 {
+	return sw.fw.physicalRemaining()
 }
 
 // zeroWriter may only be written with NULs, otherwise it returns errWriteHole.
diff --git a/libgo/go/archive/tar/writer_test.go b/libgo/go/archive/tar/writer_test.go
index a00f02d8fab..da3fb89e65e 100644
--- a/libgo/go/archive/tar/writer_test.go
+++ b/libgo/go/archive/tar/writer_test.go
@@ -67,7 +67,7 @@ func TestWriter(t *testing.T) {
 		testClose struct { // Close() == wantErr
 			wantErr error
 		}
-		testFnc interface{} // testHeader | testWrite | testReadFrom | testClose
+		testFnc any // testHeader | testWrite | testReadFrom | testClose
 	)
 
 	vectors := []struct {
@@ -987,11 +987,9 @@ func TestIssue12594(t *testing.T) {
 		// The prefix field should never appear in the GNU format.
 		var blk block
 		copy(blk[:], b.Bytes())
-		prefix := string(blk.USTAR().Prefix())
-		if i := strings.IndexByte(prefix, 0); i >= 0 {
-			prefix = prefix[:i] // Truncate at the NUL terminator
-		}
-		if blk.GetFormat() == FormatGNU && len(prefix) > 0 && strings.HasPrefix(name, prefix) {
+		prefix := string(blk.toUSTAR().prefix())
+		prefix, _, _ = strings.Cut(prefix, "\x00") // Truncate at the NUL terminator
+		if blk.getFormat() == FormatGNU && len(prefix) > 0 && strings.HasPrefix(name, prefix) {
 			t.Errorf("test %d, found prefix in GNU format: %s", i, prefix)
 		}
 
@@ -1029,11 +1027,11 @@ func TestFileWriter(t *testing.T) {
 			wantCnt int64
 			wantErr error
 		}
-		testRemaining struct { // LogicalRemaining() == wantLCnt, PhysicalRemaining() == wantPCnt
+		testRemaining struct { // logicalRemaining() == wantLCnt, physicalRemaining() == wantPCnt
 			wantLCnt int64
 			wantPCnt int64
 		}
-		testFnc interface{} // testWrite | testReadFrom | testRemaining
+		testFnc any // testWrite | testReadFrom | testRemaining
 	)
 
 	type (
@@ -1046,7 +1044,7 @@ func TestFileWriter(t *testing.T) {
 			sph     sparseHoles
 			size    int64
 		}
-		fileMaker interface{} // makeReg | makeSparse
+		fileMaker any // makeReg | makeSparse
 	)
 
 	vectors := []struct {
@@ -1292,11 +1290,11 @@ func TestFileWriter(t *testing.T) {
 					t.Errorf("test %d.%d, expected %d more operations", i, j, len(f.ops))
 				}
 			case testRemaining:
-				if got := fw.LogicalRemaining(); got != tf.wantLCnt {
-					t.Errorf("test %d.%d, LogicalRemaining() = %d, want %d", i, j, got, tf.wantLCnt)
+				if got := fw.logicalRemaining(); got != tf.wantLCnt {
+					t.Errorf("test %d.%d, logicalRemaining() = %d, want %d", i, j, got, tf.wantLCnt)
 				}
-				if got := fw.PhysicalRemaining(); got != tf.wantPCnt {
-					t.Errorf("test %d.%d, PhysicalRemaining() = %d, want %d", i, j, got, tf.wantPCnt)
+				if got := fw.physicalRemaining(); got != tf.wantPCnt {
+					t.Errorf("test %d.%d, physicalRemaining() = %d, want %d", i, j, got, tf.wantPCnt)
 				}
 			default:
 				t.Fatalf("test %d.%d, unknown test operation: %T", i, j, tf)
diff --git a/libgo/go/archive/zip/fuzz_test.go b/libgo/go/archive/zip/fuzz_test.go
new file mode 100644
index 00000000000..7dffde69bf5
--- /dev/null
+++ b/libgo/go/archive/zip/fuzz_test.go
@@ -0,0 +1,81 @@
+// Copyright 2021 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 zip
+
+import (
+	"bytes"
+	"io"
+	"os"
+	"path/filepath"
+	"testing"
+)
+
+func FuzzReader(f *testing.F) {
+	testdata, err := os.ReadDir("testdata")
+	if err != nil {
+		f.Fatalf("failed to read testdata directory: %s", err)
+	}
+	for _, de := range testdata {
+		if de.IsDir() {
+			continue
+		}
+		b, err := os.ReadFile(filepath.Join("testdata", de.Name()))
+		if err != nil {
+			f.Fatalf("failed to read testdata: %s", err)
+		}
+		f.Add(b)
+	}
+
+	f.Fuzz(func(t *testing.T, b []byte) {
+		r, err := NewReader(bytes.NewReader(b), int64(len(b)))
+		if err != nil {
+			return
+		}
+
+		type file struct {
+			header  *FileHeader
+			content []byte
+		}
+		files := []file{}
+
+		for _, f := range r.File {
+			fr, err := f.Open()
+			if err != nil {
+				continue
+			}
+			content, err := io.ReadAll(fr)
+			if err != nil {
+				continue
+			}
+			files = append(files, file{header: &f.FileHeader, content: content})
+			if _, err := r.Open(f.Name); err != nil {
+				continue
+			}
+		}
+
+		// If we were unable to read anything out of the archive don't
+		// bother trying to roundtrip it.
+		if len(files) == 0 {
+			return
+		}
+
+		w := NewWriter(io.Discard)
+		for _, f := range files {
+			ww, err := w.CreateHeader(f.header)
+			if err != nil {
+				t.Fatalf("unable to write previously parsed header: %s", err)
+			}
+			if _, err := ww.Write(f.content); err != nil {
+				t.Fatalf("unable to write previously parsed content: %s", err)
+			}
+		}
+
+		if err := w.Close(); err != nil {
+			t.Fatalf("Unable to write archive: %s", err)
+		}
+
+		// TODO: We may want to check if the archive roundtrips.
+	})
+}
diff --git a/libgo/go/archive/zip/reader.go b/libgo/go/archive/zip/reader.go
index c91a8d00e6c..92fd6f6a925 100644
--- a/libgo/go/archive/zip/reader.go
+++ b/libgo/go/archive/zip/reader.go
@@ -125,7 +125,6 @@ func (z *Reader) init(r io.ReaderAt, size int64) error {
 		if err != nil {
 			return err
 		}
-		f.readDataDescriptor()
 		z.File = append(z.File, f)
 	}
 	if uint16(len(z.File)) != uint16(end.directoryRecords) { // only compare 16 bits here
@@ -186,10 +185,15 @@ func (f *File) Open() (io.ReadCloser, error) {
 		return nil, ErrAlgorithm
 	}
 	var rc io.ReadCloser = dcomp(r)
+	var desr io.Reader
+	if f.hasDataDescriptor() {
+		desr = io.NewSectionReader(f.zipr, f.headerOffset+bodyOffset+size, dataDescriptorLen)
+	}
 	rc = &checksumReader{
 		rc:   rc,
 		hash: crc32.NewIEEE(),
 		f:    f,
+		desr: desr,
 	}
 	return rc, nil
 }
@@ -205,49 +209,13 @@ func (f *File) OpenRaw() (io.Reader, error) {
 	return r, nil
 }
 
-func (f *File) readDataDescriptor() {
-	if !f.hasDataDescriptor() {
-		return
-	}
-
-	bodyOffset, err := f.findBodyOffset()
-	if err != nil {
-		f.descErr = err
-		return
-	}
-
-	// In section 4.3.9.2 of the spec: "However ZIP64 format MAY be used
-	// regardless of the size of a file.  When extracting, if the zip64
-	// extended information extra field is present for the file the
-	// compressed and uncompressed sizes will be 8 byte values."
-	//
-	// Historically, this package has used the compressed and uncompressed
-	// sizes from the central directory to determine if the package is
-	// zip64.
-	//
-	// For this case we allow either the extra field or sizes to determine
-	// the data descriptor length.
-	zip64 := f.zip64 || f.isZip64()
-	n := int64(dataDescriptorLen)
-	if zip64 {
-		n = dataDescriptor64Len
-	}
-	size := int64(f.CompressedSize64)
-	r := io.NewSectionReader(f.zipr, f.headerOffset+bodyOffset+size, n)
-	dd, err := readDataDescriptor(r, zip64)
-	if err != nil {
-		f.descErr = err
-		return
-	}
-	f.CRC32 = dd.crc32
-}
-
 type checksumReader struct {
 	rc    io.ReadCloser
 	hash  hash.Hash32
 	nread uint64 // number of bytes read so far
 	f     *File
-	err   error // sticky error
+	desr  io.Reader // if non-nil, where to read the data descriptor
+	err   error     // sticky error
 }
 
 func (r *checksumReader) Stat() (fs.FileInfo, error) {
@@ -268,12 +236,12 @@ func (r *checksumReader) Read(b []byte) (n int, err error) {
 		if r.nread != r.f.UncompressedSize64 {
 			return 0, io.ErrUnexpectedEOF
 		}
-		if r.f.hasDataDescriptor() {
-			if r.f.descErr != nil {
-				if r.f.descErr == io.EOF {
+		if r.desr != nil {
+			if err1 := readDataDescriptor(r.desr, r.f); err1 != nil {
+				if err1 == io.EOF {
 					err = io.ErrUnexpectedEOF
 				} else {
-					err = r.f.descErr
+					err = err1
 				}
 			} else if r.hash.Sum32() != r.f.CRC32 {
 				err = ErrChecksum
@@ -485,10 +453,8 @@ parseExtras:
 	return nil
 }
 
-func readDataDescriptor(r io.Reader, zip64 bool) (*dataDescriptor, error) {
-	// Create enough space for the largest possible size
-	var buf [dataDescriptor64Len]byte
-
+func readDataDescriptor(r io.Reader, f *File) error {
+	var buf [dataDescriptorLen]byte
 	// The spec says: "Although not originally assigned a
 	// signature, the value 0x08074b50 has commonly been adopted
 	// as a signature value for the data descriptor record.
@@ -497,9 +463,10 @@ func readDataDescriptor(r io.Reader, zip64 bool) (*dataDescriptor, error) {
 	// descriptors and should account for either case when reading
 	// ZIP files to ensure compatibility."
 	//
-	// First read just those 4 bytes to see if the signature exists.
+	// dataDescriptorLen includes the size of the signature but
+	// first read just those 4 bytes to see if it exists.
 	if _, err := io.ReadFull(r, buf[:4]); err != nil {
-		return nil, err
+		return err
 	}
 	off := 0
 	maybeSig := readBuf(buf[:4])
@@ -508,28 +475,21 @@ func readDataDescriptor(r io.Reader, zip64 bool) (*dataDescriptor, error) {
 		// bytes.
 		off += 4
 	}
-
-	end := dataDescriptorLen - 4
-	if zip64 {
-		end = dataDescriptor64Len - 4
+	if _, err := io.ReadFull(r, buf[off:12]); err != nil {
+		return err
 	}
-	if _, err := io.ReadFull(r, buf[off:end]); err != nil {
-		return nil, err
+	b := readBuf(buf[:12])
+	if b.uint32() != f.CRC32 {
+		return ErrChecksum
 	}
-	b := readBuf(buf[:end])
 
-	out := &dataDescriptor{
-		crc32: b.uint32(),
-	}
+	// The two sizes that follow here can be either 32 bits or 64 bits
+	// but the spec is not very clear on this and different
+	// interpretations has been made causing incompatibilities. We
+	// already have the sizes from the central directory so we can
+	// just ignore these.
 
-	if zip64 {
-		out.compressedSize = b.uint64()
-		out.uncompressedSize = b.uint64()
-	} else {
-		out.compressedSize = uint64(b.uint32())
-		out.uncompressedSize = uint64(b.uint32())
-	}
-	return out, nil
+	return nil
 }
 
 func readDirectoryEnd(r io.ReaderAt, size int64) (dir *directoryEnd, err error) {
@@ -710,7 +670,7 @@ func (f *fileListEntry) Size() int64       { return 0 }
 func (f *fileListEntry) Mode() fs.FileMode { return fs.ModeDir | 0555 }
 func (f *fileListEntry) Type() fs.FileMode { return fs.ModeDir }
 func (f *fileListEntry) IsDir() bool       { return true }
-func (f *fileListEntry) Sys() interface{}  { return nil }
+func (f *fileListEntry) Sys() any          { return nil }
 
 func (f *fileListEntry) ModTime() time.Time {
 	if f.file == nil {
@@ -741,6 +701,9 @@ func (r *Reader) initFileList() {
 		for _, file := range r.File {
 			isDir := len(file.Name) > 0 && file.Name[len(file.Name)-1] == '/'
 			name := toValidName(file.Name)
+			if name == "" {
+				continue
+			}
 			for dir := path.Dir(name); dir != "."; dir = path.Dir(dir) {
 				dirs[dir] = true
 			}
@@ -782,8 +745,11 @@ func fileEntryLess(x, y string) bool {
 func (r *Reader) Open(name string) (fs.File, error) {
 	r.initFileList()
 
+	if !fs.ValidPath(name) {
+		return nil, &fs.PathError{Op: "open", Path: name, Err: fs.ErrInvalid}
+	}
 	e := r.openLookup(name)
-	if e == nil || !fs.ValidPath(name) {
+	if e == nil {
 		return nil, &fs.PathError{Op: "open", Path: name, Err: fs.ErrNotExist}
 	}
 	if e.isDir {
@@ -797,7 +763,7 @@ func (r *Reader) Open(name string) (fs.File, error) {
 }
 
 func split(name string) (dir, elem string, isDir bool) {
-	if name[len(name)-1] == '/' {
+	if len(name) > 0 && name[len(name)-1] == '/' {
 		isDir = true
 		name = name[:len(name)-1]
 	}
diff --git a/libgo/go/archive/zip/reader_test.go b/libgo/go/archive/zip/reader_test.go
index afb03ace24d..d1a9bdd3346 100644
--- a/libgo/go/archive/zip/reader_test.go
+++ b/libgo/go/archive/zip/reader_test.go
@@ -13,6 +13,7 @@ import (
 	"io/fs"
 	"os"
 	"path/filepath"
+	"reflect"
 	"regexp"
 	"strings"
 	"testing"
@@ -1202,127 +1203,14 @@ func TestCVE202127919(t *testing.T) {
 	if err != nil {
 		t.Errorf("Error reading file: %v", err)
 	}
-}
-
-func TestReadDataDescriptor(t *testing.T) {
-	tests := []struct {
-		desc    string
-		in      []byte
-		zip64   bool
-		want    *dataDescriptor
-		wantErr error
-	}{{
-		desc: "valid 32 bit with signature",
-		in: []byte{
-			0x50, 0x4b, 0x07, 0x08, // signature
-			0x00, 0x01, 0x02, 0x03, // crc32
-			0x04, 0x05, 0x06, 0x07, // compressed size
-			0x08, 0x09, 0x0a, 0x0b, // uncompressed size
-		},
-		want: &dataDescriptor{
-			crc32:            0x03020100,
-			compressedSize:   0x07060504,
-			uncompressedSize: 0x0b0a0908,
-		},
-	}, {
-		desc: "valid 32 bit without signature",
-		in: []byte{
-			0x00, 0x01, 0x02, 0x03, // crc32
-			0x04, 0x05, 0x06, 0x07, // compressed size
-			0x08, 0x09, 0x0a, 0x0b, // uncompressed size
-		},
-		want: &dataDescriptor{
-			crc32:            0x03020100,
-			compressedSize:   0x07060504,
-			uncompressedSize: 0x0b0a0908,
-		},
-	}, {
-		desc: "valid 64 bit with signature",
-		in: []byte{
-			0x50, 0x4b, 0x07, 0x08, // signature
-			0x00, 0x01, 0x02, 0x03, // crc32
-			0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, // compressed size
-			0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, // uncompressed size
-		},
-		zip64: true,
-		want: &dataDescriptor{
-			crc32:            0x03020100,
-			compressedSize:   0x0b0a090807060504,
-			uncompressedSize: 0x131211100f0e0d0c,
-		},
-	}, {
-		desc: "valid 64 bit without signature",
-		in: []byte{
-			0x00, 0x01, 0x02, 0x03, // crc32
-			0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, // compressed size
-			0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, // uncompressed size
-		},
-		zip64: true,
-		want: &dataDescriptor{
-			crc32:            0x03020100,
-			compressedSize:   0x0b0a090807060504,
-			uncompressedSize: 0x131211100f0e0d0c,
-		},
-	}, {
-		desc: "invalid 32 bit with signature",
-		in: []byte{
-			0x50, 0x4b, 0x07, 0x08, // signature
-			0x00, 0x01, 0x02, 0x03, // crc32
-			0x04, 0x05, // unexpected end
-		},
-		wantErr: io.ErrUnexpectedEOF,
-	}, {
-		desc: "invalid 32 bit without signature",
-		in: []byte{
-			0x00, 0x01, 0x02, 0x03, // crc32
-			0x04, 0x05, // unexpected end
-		},
-		wantErr: io.ErrUnexpectedEOF,
-	}, {
-		desc: "invalid 64 bit with signature",
-		in: []byte{
-			0x50, 0x4b, 0x07, 0x08, // signature
-			0x00, 0x01, 0x02, 0x03, // crc32
-			0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, // compressed size
-			0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, // unexpected end
-		},
-		zip64:   true,
-		wantErr: io.ErrUnexpectedEOF,
-	}, {
-		desc: "invalid 64 bit without signature",
-		in: []byte{
-			0x00, 0x01, 0x02, 0x03, // crc32
-			0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, // compressed size
-			0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, // unexpected end
-		},
-		zip64:   true,
-		wantErr: io.ErrUnexpectedEOF,
-	}}
-
-	for _, test := range tests {
-		t.Run(test.desc, func(t *testing.T) {
-			r := bytes.NewReader(test.in)
-
-			desc, err := readDataDescriptor(r, test.zip64)
-			if err != test.wantErr {
-				t.Fatalf("got err %v; want nil", err)
-			}
-			if test.want == nil {
-				return
-			}
-			if desc == nil {
-				t.Fatalf("got nil DataDescriptor; want non-nil")
-			}
-			if desc.crc32 != test.want.crc32 {
-				t.Errorf("got CRC32 %#x; want %#x", desc.crc32, test.want.crc32)
-			}
-			if desc.compressedSize != test.want.compressedSize {
-				t.Errorf("got CompressedSize %#x; want %#x", desc.compressedSize, test.want.compressedSize)
-			}
-			if desc.uncompressedSize != test.want.uncompressedSize {
-				t.Errorf("got UncompressedSize %#x; want %#x", desc.uncompressedSize, test.want.uncompressedSize)
-			}
-		})
+	if len(r.File) != 1 {
+		t.Fatalf("No entries in the file list")
+	}
+	if r.File[0].Name != "../test.txt" {
+		t.Errorf("Unexpected entry name: %s", r.File[0].Name)
+	}
+	if _, err := r.File[0].Open(); err != nil {
+		t.Errorf("Error opening file: %v", err)
 	}
 }
 
@@ -1402,3 +1290,121 @@ func TestCVE202139293(t *testing.T) {
 		t.Fatalf("unexpected error, got: %v, want: %v", err, ErrFormat)
 	}
 }
+
+func TestCVE202141772(t *testing.T) {
+	// Archive contains a file whose name is exclusively made up of '/', '\'
+	// characters, or "../", "..\" paths, which would previously cause a panic.
+	//
+	//  Length   Method    Size  Cmpr    Date    Time   CRC-32   Name
+	// --------  ------  ------- ---- ---------- ----- --------  ----
+	//        0  Stored        0   0% 08-05-2021 18:32 00000000  /
+	//        0  Stored        0   0% 09-14-2021 12:59 00000000  //
+	//        0  Stored        0   0% 09-14-2021 12:59 00000000  \
+	//       11  Stored       11   0% 09-14-2021 13:04 0d4a1185  /test.txt
+	// --------          -------  ---                            -------
+	//       11               11   0%                            4 files
+	data := []byte{
+		0x50, 0x4b, 0x03, 0x04, 0x0a, 0x00, 0x00, 0x08,
+		0x00, 0x00, 0x06, 0x94, 0x05, 0x53, 0x00, 0x00,
+		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+		0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x2f, 0x50,
+		0x4b, 0x03, 0x04, 0x0a, 0x00, 0x00, 0x00, 0x00,
+		0x00, 0x78, 0x67, 0x2e, 0x53, 0x00, 0x00, 0x00,
+		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+		0x00, 0x02, 0x00, 0x00, 0x00, 0x2f, 0x2f, 0x50,
+		0x4b, 0x03, 0x04, 0x0a, 0x00, 0x00, 0x00, 0x00,
+		0x00, 0x78, 0x67, 0x2e, 0x53, 0x00, 0x00, 0x00,
+		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+		0x00, 0x01, 0x00, 0x00, 0x00, 0x5c, 0x50, 0x4b,
+		0x03, 0x04, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00,
+		0x91, 0x68, 0x2e, 0x53, 0x85, 0x11, 0x4a, 0x0d,
+		0x0b, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00,
+		0x09, 0x00, 0x00, 0x00, 0x2f, 0x74, 0x65, 0x73,
+		0x74, 0x2e, 0x74, 0x78, 0x74, 0x68, 0x65, 0x6c,
+		0x6c, 0x6f, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64,
+		0x50, 0x4b, 0x01, 0x02, 0x14, 0x03, 0x0a, 0x00,
+		0x00, 0x08, 0x00, 0x00, 0x06, 0x94, 0x05, 0x53,
+		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+		0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
+		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
+		0xed, 0x41, 0x00, 0x00, 0x00, 0x00, 0x2f, 0x50,
+		0x4b, 0x01, 0x02, 0x3f, 0x00, 0x0a, 0x00, 0x00,
+		0x00, 0x00, 0x00, 0x78, 0x67, 0x2e, 0x53, 0x00,
+		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+		0x00, 0x00, 0x00, 0x02, 0x00, 0x24, 0x00, 0x00,
+		0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00,
+		0x00, 0x1f, 0x00, 0x00, 0x00, 0x2f, 0x2f, 0x0a,
+		0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
+		0x00, 0x18, 0x00, 0x93, 0x98, 0x25, 0x57, 0x25,
+		0xa9, 0xd7, 0x01, 0x93, 0x98, 0x25, 0x57, 0x25,
+		0xa9, 0xd7, 0x01, 0x93, 0x98, 0x25, 0x57, 0x25,
+		0xa9, 0xd7, 0x01, 0x50, 0x4b, 0x01, 0x02, 0x3f,
+		0x00, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78,
+		0x67, 0x2e, 0x53, 0x00, 0x00, 0x00, 0x00, 0x00,
+		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
+		0x00, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+		0x00, 0x20, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00,
+		0x00, 0x5c, 0x0a, 0x00, 0x20, 0x00, 0x00, 0x00,
+		0x00, 0x00, 0x01, 0x00, 0x18, 0x00, 0x93, 0x98,
+		0x25, 0x57, 0x25, 0xa9, 0xd7, 0x01, 0x93, 0x98,
+		0x25, 0x57, 0x25, 0xa9, 0xd7, 0x01, 0x93, 0x98,
+		0x25, 0x57, 0x25, 0xa9, 0xd7, 0x01, 0x50, 0x4b,
+		0x01, 0x02, 0x3f, 0x00, 0x0a, 0x00, 0x00, 0x00,
+		0x00, 0x00, 0x91, 0x68, 0x2e, 0x53, 0x85, 0x11,
+		0x4a, 0x0d, 0x0b, 0x00, 0x00, 0x00, 0x0b, 0x00,
+		0x00, 0x00, 0x09, 0x00, 0x24, 0x00, 0x00, 0x00,
+		0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
+		0x5e, 0x00, 0x00, 0x00, 0x2f, 0x74, 0x65, 0x73,
+		0x74, 0x2e, 0x74, 0x78, 0x74, 0x0a, 0x00, 0x20,
+		0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x18,
+		0x00, 0xa9, 0x80, 0x51, 0x01, 0x26, 0xa9, 0xd7,
+		0x01, 0x31, 0xd1, 0x57, 0x01, 0x26, 0xa9, 0xd7,
+		0x01, 0xdf, 0x48, 0x85, 0xf9, 0x25, 0xa9, 0xd7,
+		0x01, 0x50, 0x4b, 0x05, 0x06, 0x00, 0x00, 0x00,
+		0x00, 0x04, 0x00, 0x04, 0x00, 0x31, 0x01, 0x00,
+		0x00, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00,
+	}
+	r, err := NewReader(bytes.NewReader([]byte(data)), int64(len(data)))
+	if err != nil {
+		t.Fatalf("Error reading the archive: %v", err)
+	}
+	entryNames := []string{`/`, `//`, `\`, `/test.txt`}
+	var names []string
+	for _, f := range r.File {
+		names = append(names, f.Name)
+		if _, err := f.Open(); err != nil {
+			t.Errorf("Error opening %q: %v", f.Name, err)
+		}
+		if _, err := r.Open(f.Name); err == nil {
+			t.Errorf("Opening %q with fs.FS API succeeded", f.Name)
+		}
+	}
+	if !reflect.DeepEqual(names, entryNames) {
+		t.Errorf("Unexpected file entries: %q", names)
+	}
+	if _, err := r.Open(""); err == nil {
+		t.Errorf("Opening %q with fs.FS API succeeded", "")
+	}
+	if _, err := r.Open("test.txt"); err != nil {
+		t.Errorf("Error opening %q with fs.FS API: %v", "test.txt", err)
+	}
+	dirEntries, err := fs.ReadDir(r, ".")
+	if err != nil {
+		t.Fatalf("Error reading the root directory: %v", err)
+	}
+	if len(dirEntries) != 1 || dirEntries[0].Name() != "test.txt" {
+		t.Errorf("Unexpected directory entries")
+		for _, dirEntry := range dirEntries {
+			_, err := r.Open(dirEntry.Name())
+			t.Logf("%q (Open error: %v)", dirEntry.Name(), err)
+		}
+		t.FailNow()
+	}
+	info, err := dirEntries[0].Info()
+	if err != nil {
+		t.Fatalf("Error reading info entry: %v", err)
+	}
+	if name := info.Name(); name != "test.txt" {
+		t.Errorf("Inconsistent name in info entry: %v", name)
+	}
+}
diff --git a/libgo/go/archive/zip/struct.go b/libgo/go/archive/zip/struct.go
index ff9f605eb69..6f73fb8376a 100644
--- a/libgo/go/archive/zip/struct.go
+++ b/libgo/go/archive/zip/struct.go
@@ -163,7 +163,7 @@ func (fi headerFileInfo) ModTime() time.Time {
 }
 func (fi headerFileInfo) Mode() fs.FileMode { return fi.fh.Mode() }
 func (fi headerFileInfo) Type() fs.FileMode { return fi.fh.Mode().Type() }
-func (fi headerFileInfo) Sys() interface{}  { return fi.fh }
+func (fi headerFileInfo) Sys() any          { return fi.fh }
 
 func (fi headerFileInfo) Info() (fs.FileInfo, error) { return fi, nil }
 
@@ -390,11 +390,3 @@ func unixModeToFileMode(m uint32) fs.FileMode {
 	}
 	return mode
 }
-
-// dataDescriptor holds the data descriptor that optionally follows the file
-// contents in the zip file.
-type dataDescriptor struct {
-	crc32            uint32
-	compressedSize   uint64
-	uncompressedSize uint64
-}
diff --git a/libgo/go/archive/zip/writer_test.go b/libgo/go/archive/zip/writer_test.go
index 97c6c529799..2b73eca814f 100644
--- a/libgo/go/archive/zip/writer_test.go
+++ b/libgo/go/archive/zip/writer_test.go
@@ -362,7 +362,7 @@ func TestWriterDirAttributes(t *testing.T) {
 	}
 
 	binary.LittleEndian.PutUint32(sig[:], uint32(dataDescriptorSignature))
-	if bytes.Index(b, sig[:]) != -1 {
+	if bytes.Contains(b, sig[:]) {
 		t.Error("there should be no data descriptor")
 	}
 }
diff --git a/libgo/go/bufio/bufio.go b/libgo/go/bufio/bufio.go
index ec928e7ad69..7483946fc0a 100644
--- a/libgo/go/bufio/bufio.go
+++ b/libgo/go/bufio/bufio.go
@@ -68,7 +68,12 @@ func (b *Reader) Size() int { return len(b.buf) }
 
 // Reset discards any buffered data, resets all state, and switches
 // the buffered reader to read from r.
+// Calling Reset on the zero value of Reader initializes the internal buffer
+// to the default size.
 func (b *Reader) Reset(r io.Reader) {
+	if b.buf == nil {
+		b.buf = make([]byte, defaultBufSize)
+	}
 	b.reset(b.buf, r)
 }
 
@@ -168,6 +173,10 @@ func (b *Reader) Discard(n int) (discarded int, err error) {
 	if n == 0 {
 		return
 	}
+
+	b.lastByte = -1
+	b.lastRuneSize = -1
+
 	remain := n
 	for {
 		skip := b.Buffered()
@@ -235,6 +244,8 @@ func (b *Reader) Read(p []byte) (n int, err error) {
 	}
 
 	// copy as much as we can
+	// Note: if the slice panics here, it is probably because
+	// the underlying reader returned a bad count. See issue 49795.
 	n = copy(p, b.buf[b.r:b.w])
 	b.r += n
 	b.lastByte = int(b.buf[b.r-1])
@@ -261,8 +272,8 @@ func (b *Reader) ReadByte() (byte, error) {
 // UnreadByte unreads the last byte. Only the most recently read byte can be unread.
 //
 // UnreadByte returns an error if the most recent method called on the
-// Reader was not a read operation. Notably, Peek is not considered a
-// read operation.
+// Reader was not a read operation. Notably, Peek, Discard, and WriteTo are not
+// considered read operations.
 func (b *Reader) UnreadByte() error {
 	if b.lastByte < 0 || b.r == 0 && b.w > 0 {
 		return ErrInvalidUnreadByte
@@ -497,6 +508,9 @@ func (b *Reader) ReadString(delim byte) (string, error) {
 // If the underlying reader supports the WriteTo method,
 // this calls the underlying WriteTo without buffering.
 func (b *Reader) WriteTo(w io.Writer) (n int64, err error) {
+	b.lastByte = -1
+	b.lastRuneSize = -1
+
 	n, err = b.writeBuf(w)
 	if err != nil {
 		return
@@ -581,6 +595,8 @@ func NewWriterSize(w io.Writer, size int) *Writer {
 }
 
 // NewWriter returns a new Writer whose buffer has the default size.
+// If the argument io.Writer is already a Writer with large enough buffer size,
+// it returns the underlying Writer.
 func NewWriter(w io.Writer) *Writer {
 	return NewWriterSize(w, defaultBufSize)
 }
@@ -590,7 +606,12 @@ func (b *Writer) Size() int { return len(b.buf) }
 
 // Reset discards any unflushed buffered data, clears any error, and
 // resets b to write its output to w.
+// Calling Reset on the zero value of Writer initializes the internal buffer
+// to the default size.
 func (b *Writer) Reset(w io.Writer) {
+	if b.buf == nil {
+		b.buf = make([]byte, defaultBufSize)
+	}
 	b.err = nil
 	b.n = 0
 	b.wr = w
@@ -623,6 +644,14 @@ func (b *Writer) Flush() error {
 // Available returns how many bytes are unused in the buffer.
 func (b *Writer) Available() int { return len(b.buf) - b.n }
 
+// AvailableBuffer returns an empty buffer with b.Available() capacity.
+// This buffer is intended to be appended to and
+// passed to an immediately succeeding Write call.
+// The buffer is only valid until the next write operation on b.
+func (b *Writer) AvailableBuffer() []byte {
+	return b.buf[b.n:][:0]
+}
+
 // Buffered returns the number of bytes that have been written into the current buffer.
 func (b *Writer) Buffered() int { return b.n }
 
@@ -720,19 +749,14 @@ func (b *Writer) WriteString(s string) (int, error) {
 }
 
 // ReadFrom implements io.ReaderFrom. If the underlying writer
-// supports the ReadFrom method, and b has no buffered data yet,
-// this calls the underlying ReadFrom without buffering.
+// supports the ReadFrom method, this calls the underlying ReadFrom.
+// If there is buffered data and an underlying ReadFrom, this fills
+// the buffer and writes it before calling ReadFrom.
 func (b *Writer) ReadFrom(r io.Reader) (n int64, err error) {
 	if b.err != nil {
 		return 0, b.err
 	}
-	if b.Buffered() == 0 {
-		if w, ok := b.wr.(io.ReaderFrom); ok {
-			n, err = w.ReadFrom(r)
-			b.err = err
-			return n, err
-		}
-	}
+	readerFrom, readerFromOK := b.wr.(io.ReaderFrom)
 	var m int
 	for {
 		if b.Available() == 0 {
@@ -740,6 +764,12 @@ func (b *Writer) ReadFrom(r io.Reader) (n int64, err error) {
 				return n, err1
 			}
 		}
+		if readerFromOK && b.Buffered() == 0 {
+			nn, err := readerFrom.ReadFrom(r)
+			b.err = err
+			n += nn
+			return n, err
+		}
 		nr := 0
 		for nr < maxConsecutiveEmptyReads {
 			m, err = r.Read(b.buf[b.n:])
diff --git a/libgo/go/bufio/bufio_test.go b/libgo/go/bufio/bufio_test.go
index ebcc711db9d..ff3396e9469 100644
--- a/libgo/go/bufio/bufio_test.go
+++ b/libgo/go/bufio/bufio_test.go
@@ -10,6 +10,8 @@ import (
 	"errors"
 	"fmt"
 	"io"
+	"math/rand"
+	"strconv"
 	"strings"
 	"testing"
 	"testing/iotest"
@@ -302,6 +304,40 @@ func TestNoUnreadByteAfterPeek(t *testing.T) {
 	}
 }
 
+func TestNoUnreadRuneAfterDiscard(t *testing.T) {
+	br := NewReader(strings.NewReader("example"))
+	br.ReadRune()
+	br.Discard(1)
+	if err := br.UnreadRune(); err == nil {
+		t.Error("UnreadRune didn't fail after Discard")
+	}
+}
+
+func TestNoUnreadByteAfterDiscard(t *testing.T) {
+	br := NewReader(strings.NewReader("example"))
+	br.ReadByte()
+	br.Discard(1)
+	if err := br.UnreadByte(); err == nil {
+		t.Error("UnreadByte didn't fail after Discard")
+	}
+}
+
+func TestNoUnreadRuneAfterWriteTo(t *testing.T) {
+	br := NewReader(strings.NewReader("example"))
+	br.WriteTo(io.Discard)
+	if err := br.UnreadRune(); err == nil {
+		t.Error("UnreadRune didn't fail after WriteTo")
+	}
+}
+
+func TestNoUnreadByteAfterWriteTo(t *testing.T) {
+	br := NewReader(strings.NewReader("example"))
+	br.WriteTo(io.Discard)
+	if err := br.UnreadByte(); err == nil {
+		t.Error("UnreadByte didn't fail after WriteTo")
+	}
+}
+
 func TestUnreadByte(t *testing.T) {
 	segments := []string{"Hello, ", "world"}
 	r := NewReader(&StringReader{data: segments})
@@ -608,6 +644,37 @@ func TestWriter(t *testing.T) {
 	}
 }
 
+func TestWriterAppend(t *testing.T) {
+	got := new(bytes.Buffer)
+	var want []byte
+	rn := rand.New(rand.NewSource(0))
+	w := NewWriterSize(got, 64)
+	for i := 0; i < 100; i++ {
+		// Obtain a buffer to append to.
+		b := w.AvailableBuffer()
+		if w.Available() != cap(b) {
+			t.Fatalf("Available() = %v, want %v", w.Available(), cap(b))
+		}
+
+		// While not recommended, it is valid to append to a shifted buffer.
+		// This forces Write to copy the input.
+		if rn.Intn(8) == 0 && cap(b) > 0 {
+			b = b[1:1:cap(b)]
+		}
+
+		// Append a random integer of varying width.
+		n := int64(rn.Intn(1 << rn.Intn(30)))
+		want = append(strconv.AppendInt(want, n, 10), ' ')
+		b = append(strconv.AppendInt(b, n, 10), ' ')
+		w.Write(b)
+	}
+	w.Flush()
+
+	if !bytes.Equal(got.Bytes(), want) {
+		t.Errorf("output mismatch:\ngot  %s\nwant %s", got.Bytes(), want)
+	}
+}
+
 // Check that write errors are returned properly.
 
 type errorWriterTest struct {
@@ -1284,6 +1351,54 @@ func TestWriterReadFromErrNoProgress(t *testing.T) {
 	}
 }
 
+type readFromWriter struct {
+	buf           []byte
+	writeBytes    int
+	readFromBytes int
+}
+
+func (w *readFromWriter) Write(p []byte) (int, error) {
+	w.buf = append(w.buf, p...)
+	w.writeBytes += len(p)
+	return len(p), nil
+}
+
+func (w *readFromWriter) ReadFrom(r io.Reader) (int64, error) {
+	b, err := io.ReadAll(r)
+	w.buf = append(w.buf, b...)
+	w.readFromBytes += len(b)
+	return int64(len(b)), err
+}
+
+// Test that calling (*Writer).ReadFrom with a partially-filled buffer
+// fills the buffer before switching over to ReadFrom.
+func TestWriterReadFromWithBufferedData(t *testing.T) {
+	const bufsize = 16
+
+	input := createTestInput(64)
+	rfw := &readFromWriter{}
+	w := NewWriterSize(rfw, bufsize)
+
+	const writeSize = 8
+	if n, err := w.Write(input[:writeSize]); n != writeSize || err != nil {
+		t.Errorf("w.Write(%v bytes) = %v, %v; want %v, nil", writeSize, n, err, writeSize)
+	}
+	n, err := w.ReadFrom(bytes.NewReader(input[writeSize:]))
+	if wantn := len(input[writeSize:]); int(n) != wantn || err != nil {
+		t.Errorf("io.Copy(w, %v bytes) = %v, %v; want %v, nil", wantn, n, err, wantn)
+	}
+	if err := w.Flush(); err != nil {
+		t.Errorf("w.Flush() = %v, want nil", err)
+	}
+
+	if got, want := rfw.writeBytes, bufsize; got != want {
+		t.Errorf("wrote %v bytes with Write, want %v", got, want)
+	}
+	if got, want := rfw.readFromBytes, len(input)-bufsize; got != want {
+		t.Errorf("wrote %v bytes with ReadFrom, want %v", got, want)
+	}
+}
+
 func TestReadZero(t *testing.T) {
 	for _, size := range []int{100, 2} {
 		t.Run(fmt.Sprintf("bufsize=%d", size), func(t *testing.T) {
@@ -1312,6 +1427,7 @@ func TestReaderReset(t *testing.T) {
 	if string(buf) != "foo" {
 		t.Errorf("buf = %q; want foo", buf)
 	}
+
 	r.Reset(strings.NewReader("bar bar"))
 	all, err := io.ReadAll(r)
 	if err != nil {
@@ -1320,12 +1436,23 @@ func TestReaderReset(t *testing.T) {
 	if string(all) != "bar bar" {
 		t.Errorf("ReadAll = %q; want bar bar", all)
 	}
+
+	*r = Reader{} // zero out the Reader
+	r.Reset(strings.NewReader("bar bar"))
+	all, err = io.ReadAll(r)
+	if err != nil {
+		t.Fatal(err)
+	}
+	if string(all) != "bar bar" {
+		t.Errorf("ReadAll = %q; want bar bar", all)
+	}
 }
 
 func TestWriterReset(t *testing.T) {
-	var buf1, buf2 bytes.Buffer
+	var buf1, buf2, buf3 bytes.Buffer
 	w := NewWriter(&buf1)
 	w.WriteString("foo")
+
 	w.Reset(&buf2) // and not flushed
 	w.WriteString("bar")
 	w.Flush()
@@ -1335,6 +1462,17 @@ func TestWriterReset(t *testing.T) {
 	if buf2.String() != "bar" {
 		t.Errorf("buf2 = %q; want bar", buf2.String())
 	}
+
+	*w = Writer{}  // zero out the Writer
+	w.Reset(&buf3) // and not flushed
+	w.WriteString("bar")
+	w.Flush()
+	if buf1.String() != "" {
+		t.Errorf("buf1 = %q; want empty", buf1.String())
+	}
+	if buf3.String() != "bar" {
+		t.Errorf("buf3 = %q; want bar", buf3.String())
+	}
 }
 
 func TestReaderDiscard(t *testing.T) {
@@ -1382,7 +1520,7 @@ func TestReaderDiscard(t *testing.T) {
 			wantBuffered: 0,
 		},
 		// Any error from filling shouldn't show up until we
-		// get past the valid bytes. Here we return we return 5 valid bytes at the same time
+		// get past the valid bytes. Here we return 5 valid bytes at the same time
 		// as an error, but test that we don't see the error from Discard.
 		{
 			name: "fill error, discard less",
diff --git a/libgo/go/bufio/example_test.go b/libgo/go/bufio/example_test.go
index 8885d40549f..a864d11012e 100644
--- a/libgo/go/bufio/example_test.go
+++ b/libgo/go/bufio/example_test.go
@@ -20,6 +20,18 @@ func ExampleWriter() {
 	// Output: Hello, world!
 }
 
+func ExampleWriter_AvailableBuffer() {
+	w := bufio.NewWriter(os.Stdout)
+	for _, i := range []int64{1, 2, 3, 4} {
+		b := w.AvailableBuffer()
+		b = strconv.AppendInt(b, i, 10)
+		b = append(b, ' ')
+		w.Write(b)
+	}
+	w.Flush()
+	// Output: 1 2 3 4
+}
+
 // The simplest use of a Scanner, to read standard input as a set of lines.
 func ExampleScanner_lines() {
 	scanner := bufio.NewScanner(os.Stdin)
diff --git a/libgo/go/builtin/builtin.go b/libgo/go/builtin/builtin.go
index 01190e99002..08ae7ed313a 100644
--- a/libgo/go/builtin/builtin.go
+++ b/libgo/go/builtin/builtin.go
@@ -91,6 +91,16 @@ type byte = uint8
 // used, by convention, to distinguish character values from integer values.
 type rune = int32
 
+// any is an alias for interface{} and is equivalent to interface{} in all ways.
+type any = interface{}
+
+// comparable is an interface that is implemented by all comparable types
+// (booleans, numbers, strings, pointers, channels, interfaces,
+// arrays of comparable types, structs whose fields are all comparable types).
+// The comparable interface may only be used as a type parameter constraint,
+// not as the type of a variable.
+type comparable comparable
+
 // iota is a predeclared identifier representing the untyped integer ordinal
 // number of the current const specification in a (usually parenthesized)
 // const declaration. It is zero-indexed.
@@ -229,7 +239,7 @@ func close(c chan<- Type)
 // that point, the program is terminated with a non-zero exit code. This
 // termination sequence is called panicking and can be controlled by the
 // built-in function recover.
-func panic(v interface{})
+func panic(v any)
 
 // The recover built-in function allows a program to manage behavior of a
 // panicking goroutine. Executing a call to recover inside a deferred
@@ -240,7 +250,7 @@ func panic(v interface{})
 // panicking, or if the argument supplied to panic was nil, recover returns
 // nil. Thus the return value from recover reports whether the goroutine is
 // panicking.
-func recover() interface{}
+func recover() any
 
 // The print built-in function formats its arguments in an
 // implementation-specific way and writes the result to standard error.
diff --git a/libgo/go/bytes/boundary_test.go b/libgo/go/bytes/boundary_test.go
index 5a47526593b..f9855fcb052 100644
--- a/libgo/go/bytes/boundary_test.go
+++ b/libgo/go/bytes/boundary_test.go
@@ -3,7 +3,6 @@
 // license that can be found in the LICENSE file.
 //
 //go:build linux
-// +build linux
 
 package bytes_test
 
@@ -66,7 +65,11 @@ func TestIndexByteNearPageBoundary(t *testing.T) {
 
 func TestIndexNearPageBoundary(t *testing.T) {
 	t.Parallel()
-	var q [64]byte
+	q := dangerousSlice(t)
+	if len(q) > 64 {
+		// Only worry about when we're near the end of a page.
+		q = q[len(q)-64:]
+	}
 	b := dangerousSlice(t)
 	if len(b) > 256 {
 		// Only worry about when we're near the end of a page.
@@ -82,4 +85,16 @@ func TestIndexNearPageBoundary(t *testing.T) {
 		}
 		q[j-1] = 0
 	}
+
+	// Test differing alignments and sizes of q which always end on a page boundary.
+	q[len(q)-1] = 1 // difference is only found on the last byte
+	for j := 0; j < len(q); j++ {
+		for i := range b {
+			idx := Index(b[i:], q[j:])
+			if idx != -1 {
+				t.Fatalf("Index(b[%d:], q[%d:])=%d, want -1\n", i, j, idx)
+			}
+		}
+	}
+	q[len(q)-1] = 0
 }
diff --git a/libgo/go/bytes/bytes.go b/libgo/go/bytes/bytes.go
index ce52649f132..6fdaa49c734 100644
--- a/libgo/go/bytes/bytes.go
+++ b/libgo/go/bytes/bytes.go
@@ -21,7 +21,7 @@ func Equal(a, b []byte) bool {
 }
 
 // Compare returns an integer comparing two byte slices lexicographically.
-// The result will be 0 if a==b, -1 if a < b, and +1 if a > b.
+// The result will be 0 if a == b, -1 if a < b, and +1 if a > b.
 // A nil argument is equivalent to an empty slice.
 func Compare(a, b []byte) int {
 	return bytealg.Compare(a, b)
@@ -699,7 +699,7 @@ func ToValidUTF8(s, replacement []byte) []byte {
 		if c < utf8.RuneSelf {
 			i++
 			invalid = false
-			b = append(b, byte(c))
+			b = append(b, c)
 			continue
 		}
 		_, wid := utf8.DecodeRune(s[i:])
@@ -746,7 +746,8 @@ func isSeparator(r rune) bool {
 // Title treats s as UTF-8-encoded bytes and returns a copy with all Unicode letters that begin
 // words mapped to their title case.
 //
-// BUG(rsc): The rule Title uses for word boundaries does not handle Unicode punctuation properly.
+// Deprecated: The rule Title uses for word boundaries does not handle Unicode
+// punctuation properly. Use golang.org/x/text/cases instead.
 func Title(s []byte) []byte {
 	// Use a closure here to remember state.
 	// Hackish but effective. Depends on Map scanning in order and calling
@@ -867,6 +868,8 @@ func lastIndexFunc(s []byte, f func(r rune) bool, truth bool) int {
 // most-significant bit of the highest word, map to the full range of all
 // 128 ASCII characters. The 128-bits of the upper 16 bytes will be zeroed,
 // ensuring that any non-ASCII character will be reported as not in the set.
+// This allocates a total of 32 bytes even though the upper half
+// is unused to avoid bounds checks in asciiSet.contains.
 type asciiSet [8]uint32
 
 // makeASCIISet creates a set of ASCII characters and reports whether all
@@ -877,53 +880,133 @@ func makeASCIISet(chars string) (as asciiSet, ok bool) {
 		if c >= utf8.RuneSelf {
 			return as, false
 		}
-		as[c>>5] |= 1 << uint(c&31)
+		as[c/32] |= 1 << (c % 32)
 	}
 	return as, true
 }
 
 // contains reports whether c is inside the set.
 func (as *asciiSet) contains(c byte) bool {
-	return (as[c>>5] & (1 << uint(c&31))) != 0
+	return (as[c/32] & (1 << (c % 32))) != 0
 }
 
-func makeCutsetFunc(cutset string) func(r rune) bool {
-	if len(cutset) == 1 && cutset[0] < utf8.RuneSelf {
-		return func(r rune) bool {
-			return r == rune(cutset[0])
-		}
-	}
-	if as, isASCII := makeASCIISet(cutset); isASCII {
-		return func(r rune) bool {
-			return r < utf8.RuneSelf && as.contains(byte(r))
-		}
-	}
-	return func(r rune) bool {
-		for _, c := range cutset {
-			if c == r {
-				return true
-			}
+// containsRune is a simplified version of strings.ContainsRune
+// to avoid importing the strings package.
+// We avoid bytes.ContainsRune to avoid allocating a temporary copy of s.
+func containsRune(s string, r rune) bool {
+	for _, c := range s {
+		if c == r {
+			return true
 		}
-		return false
 	}
+	return false
 }
 
 // Trim returns a subslice of s by slicing off all leading and
 // trailing UTF-8-encoded code points contained in cutset.
 func Trim(s []byte, cutset string) []byte {
-	return TrimFunc(s, makeCutsetFunc(cutset))
+	if len(s) == 0 || cutset == "" {
+		return s
+	}
+	if len(cutset) == 1 && cutset[0] < utf8.RuneSelf {
+		return trimLeftByte(trimRightByte(s, cutset[0]), cutset[0])
+	}
+	if as, ok := makeASCIISet(cutset); ok {
+		return trimLeftASCII(trimRightASCII(s, &as), &as)
+	}
+	return trimLeftUnicode(trimRightUnicode(s, cutset), cutset)
 }
 
 // TrimLeft returns a subslice of s by slicing off all leading
 // UTF-8-encoded code points contained in cutset.
 func TrimLeft(s []byte, cutset string) []byte {
-	return TrimLeftFunc(s, makeCutsetFunc(cutset))
+	if len(s) == 0 || cutset == "" {
+		return s
+	}
+	if len(cutset) == 1 && cutset[0] < utf8.RuneSelf {
+		return trimLeftByte(s, cutset[0])
+	}
+	if as, ok := makeASCIISet(cutset); ok {
+		return trimLeftASCII(s, &as)
+	}
+	return trimLeftUnicode(s, cutset)
+}
+
+func trimLeftByte(s []byte, c byte) []byte {
+	for len(s) > 0 && s[0] == c {
+		s = s[1:]
+	}
+	return s
+}
+
+func trimLeftASCII(s []byte, as *asciiSet) []byte {
+	for len(s) > 0 {
+		if !as.contains(s[0]) {
+			break
+		}
+		s = s[1:]
+	}
+	return s
+}
+
+func trimLeftUnicode(s []byte, cutset string) []byte {
+	for len(s) > 0 {
+		r, n := rune(s[0]), 1
+		if r >= utf8.RuneSelf {
+			r, n = utf8.DecodeRune(s)
+		}
+		if !containsRune(cutset, r) {
+			break
+		}
+		s = s[n:]
+	}
+	return s
 }
 
 // TrimRight returns a subslice of s by slicing off all trailing
 // UTF-8-encoded code points that are contained in cutset.
 func TrimRight(s []byte, cutset string) []byte {
-	return TrimRightFunc(s, makeCutsetFunc(cutset))
+	if len(s) == 0 || cutset == "" {
+		return s
+	}
+	if len(cutset) == 1 && cutset[0] < utf8.RuneSelf {
+		return trimRightByte(s, cutset[0])
+	}
+	if as, ok := makeASCIISet(cutset); ok {
+		return trimRightASCII(s, &as)
+	}
+	return trimRightUnicode(s, cutset)
+}
+
+func trimRightByte(s []byte, c byte) []byte {
+	for len(s) > 0 && s[len(s)-1] == c {
+		s = s[:len(s)-1]
+	}
+	return s
+}
+
+func trimRightASCII(s []byte, as *asciiSet) []byte {
+	for len(s) > 0 {
+		if !as.contains(s[len(s)-1]) {
+			break
+		}
+		s = s[:len(s)-1]
+	}
+	return s
+}
+
+func trimRightUnicode(s []byte, cutset string) []byte {
+	for len(s) > 0 {
+		r, n := rune(s[len(s)-1]), 1
+		if r >= utf8.RuneSelf {
+			r, n = utf8.DecodeLastRune(s)
+		}
+		if !containsRune(cutset, r) {
+			break
+		}
+		s = s[:len(s)-n]
+	}
+	return s
 }
 
 // TrimSpace returns a subslice of s by slicing off all leading and
@@ -1174,3 +1257,16 @@ func Index(s, sep []byte) int {
 	}
 	return -1
 }
+
+// Cut slices s around the first instance of sep,
+// returning the text before and after sep.
+// The found result reports whether sep appears in s.
+// If sep does not appear in s, cut returns s, nil, false.
+//
+// Cut returns slices of the original slice s, not copies.
+func Cut(s, sep []byte) (before, after []byte, found bool) {
+	if i := Index(s, sep); i >= 0 {
+		return s[:i], s[i+len(sep):], true
+	}
+	return s, nil, false
+}
diff --git a/libgo/go/bytes/bytes_test.go b/libgo/go/bytes/bytes_test.go
index 0111d31d44c..2e6d27cadba 100644
--- a/libgo/go/bytes/bytes_test.go
+++ b/libgo/go/bytes/bytes_test.go
@@ -1256,7 +1256,9 @@ var trimTests = []TrimTest{
 	{"TrimLeft", "abba", "ab", ""},
 	{"TrimRight", "abba", "ab", ""},
 	{"TrimLeft", "abba", "a", "bba"},
+	{"TrimLeft", "abba", "b", "abba"},
 	{"TrimRight", "abba", "a", "abb"},
+	{"TrimRight", "abba", "b", "abba"},
 	{"Trim", "<tag>", "<>", "tag"},
 	{"Trim", "* listitem", " *", "listitem"},
 	{"Trim", `"quote"`, `"`, "quote"},
@@ -1570,6 +1572,29 @@ func TestEqualFold(t *testing.T) {
 	}
 }
 
+var cutTests = []struct {
+	s, sep        string
+	before, after string
+	found         bool
+}{
+	{"abc", "b", "a", "c", true},
+	{"abc", "a", "", "bc", true},
+	{"abc", "c", "ab", "", true},
+	{"abc", "abc", "", "", true},
+	{"abc", "", "", "abc", true},
+	{"abc", "d", "abc", "", false},
+	{"", "d", "", "", false},
+	{"", "", "", "", true},
+}
+
+func TestCut(t *testing.T) {
+	for _, tt := range cutTests {
+		if before, after, found := Cut([]byte(tt.s), []byte(tt.sep)); string(before) != tt.before || string(after) != tt.after || found != tt.found {
+			t.Errorf("Cut(%q, %q) = %q, %q, %v, want %q, %q, %v", tt.s, tt.sep, before, after, found, tt.before, tt.after, tt.found)
+		}
+	}
+}
+
 func TestBufferGrowNegative(t *testing.T) {
 	defer func() {
 		if err := recover(); err == nil {
@@ -1968,6 +1993,13 @@ func BenchmarkTrimASCII(b *testing.B) {
 	}
 }
 
+func BenchmarkTrimByte(b *testing.B) {
+	x := []byte("  the quick brown fox   ")
+	for i := 0; i < b.N; i++ {
+		Trim(x, " ")
+	}
+}
+
 func BenchmarkIndexPeriodic(b *testing.B) {
 	key := []byte{1, 1}
 	for _, skip := range [...]int{2, 4, 8, 16, 32, 64} {
diff --git a/libgo/go/bytes/example_test.go b/libgo/go/bytes/example_test.go
index ae93202b570..54a7aa6ae6c 100644
--- a/libgo/go/bytes/example_test.go
+++ b/libgo/go/bytes/example_test.go
@@ -37,6 +37,16 @@ func ExampleBuffer_Bytes() {
 	// Output: hello world
 }
 
+func ExampleBuffer_Cap() {
+	buf1 := bytes.NewBuffer(make([]byte, 10))
+	buf2 := bytes.NewBuffer(make([]byte, 0, 10))
+	fmt.Println(buf1.Cap())
+	fmt.Println(buf2.Cap())
+	// Output:
+	// 10
+	// 10
+}
+
 func ExampleBuffer_Grow() {
 	var b bytes.Buffer
 	b.Grow(64)
@@ -54,6 +64,52 @@ func ExampleBuffer_Len() {
 	// Output: 5
 }
 
+func ExampleBuffer_Next() {
+	var b bytes.Buffer
+	b.Grow(64)
+	b.Write([]byte("abcde"))
+	fmt.Printf("%s\n", string(b.Next(2)))
+	fmt.Printf("%s\n", string(b.Next(2)))
+	fmt.Printf("%s", string(b.Next(2)))
+	// Output:
+	// ab
+	// cd
+	// e
+}
+
+func ExampleBuffer_Read() {
+	var b bytes.Buffer
+	b.Grow(64)
+	b.Write([]byte("abcde"))
+	rdbuf := make([]byte, 1)
+	n, err := b.Read(rdbuf)
+	if err != nil {
+		panic(err)
+	}
+	fmt.Println(n)
+	fmt.Println(b.String())
+	fmt.Println(string(rdbuf))
+	// Output
+	// 1
+	// bcde
+	// a
+}
+
+func ExampleBuffer_ReadByte() {
+	var b bytes.Buffer
+	b.Grow(64)
+	b.Write([]byte("abcde"))
+	c, err := b.ReadByte()
+	if err != nil {
+		panic(err)
+	}
+	fmt.Println(c)
+	fmt.Println(b.String())
+	// Output
+	// 97
+	// bcde
+}
+
 func ExampleCompare() {
 	// Interpret Compare's result by comparing it to zero.
 	var a, b []byte
@@ -92,36 +148,6 @@ func ExampleCompare_search() {
 	}
 }
 
-func ExampleTrimSuffix() {
-	var b = []byte("Hello, goodbye, etc!")
-	b = bytes.TrimSuffix(b, []byte("goodbye, etc!"))
-	b = bytes.TrimSuffix(b, []byte("gopher"))
-	b = append(b, bytes.TrimSuffix([]byte("world!"), []byte("x!"))...)
-	os.Stdout.Write(b)
-	// Output: Hello, world!
-}
-
-func ExampleTrimPrefix() {
-	var b = []byte("Goodbye,, world!")
-	b = bytes.TrimPrefix(b, []byte("Goodbye,"))
-	b = bytes.TrimPrefix(b, []byte("See ya,"))
-	fmt.Printf("Hello%s", b)
-	// Output: Hello, world!
-}
-
-func ExampleFields() {
-	fmt.Printf("Fields are: %q", bytes.Fields([]byte("  foo bar  baz   ")))
-	// Output: Fields are: ["foo" "bar" "baz"]
-}
-
-func ExampleFieldsFunc() {
-	f := func(c rune) bool {
-		return !unicode.IsLetter(c) && !unicode.IsNumber(c)
-	}
-	fmt.Printf("Fields are: %q", bytes.FieldsFunc([]byte("  foo1;bar2,baz3..."), f))
-	// Output: Fields are: ["foo1" "bar2" "baz3"]
-}
-
 func ExampleContains() {
 	fmt.Println(bytes.Contains([]byte("seafood"), []byte("foo")))
 	fmt.Println(bytes.Contains([]byte("seafood"), []byte("bar")))
@@ -168,6 +194,22 @@ func ExampleCount() {
 	// 5
 }
 
+func ExampleCut() {
+	show := func(s, sep string) {
+		before, after, found := bytes.Cut([]byte(s), []byte(sep))
+		fmt.Printf("Cut(%q, %q) = %q, %q, %v\n", s, sep, before, after, found)
+	}
+	show("Gopher", "Go")
+	show("Gopher", "ph")
+	show("Gopher", "er")
+	show("Gopher", "Badger")
+	// Output:
+	// Cut("Gopher", "Go") = "", "pher", true
+	// Cut("Gopher", "ph") = "Go", "er", true
+	// Cut("Gopher", "er") = "Goph", "", true
+	// Cut("Gopher", "Badger") = "Gopher", "", false
+}
+
 func ExampleEqual() {
 	fmt.Println(bytes.Equal([]byte("Go"), []byte("Go")))
 	fmt.Println(bytes.Equal([]byte("Go"), []byte("C++")))
@@ -181,6 +223,19 @@ func ExampleEqualFold() {
 	// Output: true
 }
 
+func ExampleFields() {
+	fmt.Printf("Fields are: %q", bytes.Fields([]byte("  foo bar  baz   ")))
+	// Output: Fields are: ["foo" "bar" "baz"]
+}
+
+func ExampleFieldsFunc() {
+	f := func(c rune) bool {
+		return !unicode.IsLetter(c) && !unicode.IsNumber(c)
+	}
+	fmt.Printf("Fields are: %q", bytes.FieldsFunc([]byte("  foo1;bar2,baz3..."), f))
+	// Output: Fields are: ["foo1" "bar2" "baz3"]
+}
+
 func ExampleHasPrefix() {
 	fmt.Println(bytes.HasPrefix([]byte("Gopher"), []byte("Go")))
 	fmt.Println(bytes.HasPrefix([]byte("Gopher"), []byte("C")))
@@ -246,6 +301,12 @@ func ExampleIndexRune() {
 	// -1
 }
 
+func ExampleJoin() {
+	s := [][]byte{[]byte("foo"), []byte("bar"), []byte("baz")}
+	fmt.Printf("%s", bytes.Join(s, []byte(", ")))
+	// Output: foo, bar, baz
+}
+
 func ExampleLastIndex() {
 	fmt.Println(bytes.Index([]byte("go gopher"), []byte("go")))
 	fmt.Println(bytes.LastIndex([]byte("go gopher"), []byte("go")))
@@ -286,10 +347,12 @@ func ExampleLastIndexFunc() {
 	// -1
 }
 
-func ExampleJoin() {
-	s := [][]byte{[]byte("foo"), []byte("bar"), []byte("baz")}
-	fmt.Printf("%s", bytes.Join(s, []byte(", ")))
-	// Output: foo, bar, baz
+func ExampleReader_Len() {
+	fmt.Println(bytes.NewReader([]byte("Hi!")).Len())
+	fmt.Println(bytes.NewReader([]byte("こんにちは!")).Len())
+	// Output:
+	// 3
+	// 16
 }
 
 func ExampleRepeat() {
@@ -399,20 +462,6 @@ func ExampleTrimFunc() {
 	// go-gopher!
 }
 
-func ExampleMap() {
-	rot13 := func(r rune) rune {
-		switch {
-		case r >= 'A' && r <= 'Z':
-			return 'A' + (r-'A'+13)%26
-		case r >= 'a' && r <= 'z':
-			return 'a' + (r-'a'+13)%26
-		}
-		return r
-	}
-	fmt.Printf("%s", bytes.Map(rot13, []byte("'Twas brillig and the slithy gopher...")))
-	// Output: 'Gjnf oevyyvt naq gur fyvgul tbcure...
-}
-
 func ExampleTrimLeft() {
 	fmt.Print(string(bytes.TrimLeft([]byte("453gopher8257"), "0123456789")))
 	// Output:
@@ -429,11 +478,28 @@ func ExampleTrimLeftFunc() {
 	// go-gopher!567
 }
 
+func ExampleTrimPrefix() {
+	var b = []byte("Goodbye,, world!")
+	b = bytes.TrimPrefix(b, []byte("Goodbye,"))
+	b = bytes.TrimPrefix(b, []byte("See ya,"))
+	fmt.Printf("Hello%s", b)
+	// Output: Hello, world!
+}
+
 func ExampleTrimSpace() {
 	fmt.Printf("%s", bytes.TrimSpace([]byte(" \t\n a lone gopher \n\t\r\n")))
 	// Output: a lone gopher
 }
 
+func ExampleTrimSuffix() {
+	var b = []byte("Hello, goodbye, etc!")
+	b = bytes.TrimSuffix(b, []byte("goodbye, etc!"))
+	b = bytes.TrimSuffix(b, []byte("gopher"))
+	b = append(b, bytes.TrimSuffix([]byte("world!"), []byte("x!"))...)
+	os.Stdout.Write(b)
+	// Output: Hello, world!
+}
+
 func ExampleTrimRight() {
 	fmt.Print(string(bytes.TrimRight([]byte("453gopher8257"), "0123456789")))
 	// Output:
@@ -450,21 +516,6 @@ func ExampleTrimRightFunc() {
 	// 1234go-gopher!
 }
 
-func ExampleToUpper() {
-	fmt.Printf("%s", bytes.ToUpper([]byte("Gopher")))
-	// Output: GOPHER
-}
-
-func ExampleToUpperSpecial() {
-	str := []byte("ahoj vývojári golang")
-	totitle := bytes.ToUpperSpecial(unicode.AzeriCase, str)
-	fmt.Println("Original : " + string(str))
-	fmt.Println("ToUpper : " + string(totitle))
-	// Output:
-	// Original : ahoj vývojári golang
-	// ToUpper : AHOJ VÝVOJÁRİ GOLANG
-}
-
 func ExampleToLower() {
 	fmt.Printf("%s", bytes.ToLower([]byte("Gopher")))
 	// Output: gopher
@@ -480,10 +531,17 @@ func ExampleToLowerSpecial() {
 	// ToLower : ahoj vývojári golang
 }
 
-func ExampleReader_Len() {
-	fmt.Println(bytes.NewReader([]byte("Hi!")).Len())
-	fmt.Println(bytes.NewReader([]byte("こんにちは!")).Len())
+func ExampleToUpper() {
+	fmt.Printf("%s", bytes.ToUpper([]byte("Gopher")))
+	// Output: GOPHER
+}
+
+func ExampleToUpperSpecial() {
+	str := []byte("ahoj vývojári golang")
+	totitle := bytes.ToUpperSpecial(unicode.AzeriCase, str)
+	fmt.Println("Original : " + string(str))
+	fmt.Println("ToUpper : " + string(totitle))
 	// Output:
-	// 3
-	// 16
+	// Original : ahoj vývojári golang
+	// ToUpper : AHOJ VÝVOJÁRİ GOLANG
 }
diff --git a/libgo/go/bytes/reader_test.go b/libgo/go/bytes/reader_test.go
index 8baac5046cb..9119c944ace 100644
--- a/libgo/go/bytes/reader_test.go
+++ b/libgo/go/bytes/reader_test.go
@@ -76,7 +76,7 @@ func TestReaderAt(t *testing.T) {
 		off     int64
 		n       int
 		want    string
-		wanterr interface{}
+		wanterr any
 	}{
 		{0, 10, "0123456789", nil},
 		{1, 10, "123456789", io.EOF},
diff --git a/libgo/go/cmd/cgo/ast.go b/libgo/go/cmd/cgo/ast.go
index a073407a961..28879e349c4 100644
--- a/libgo/go/cmd/cgo/ast.go
+++ b/libgo/go/cmd/cgo/ast.go
@@ -338,8 +338,7 @@ func (f *File) walk(x interface{}, context astContext, visit func(*File, interfa
 
 	// everything else just recurs
 	default:
-		error_(token.NoPos, "unexpected type %T in walk", x)
-		panic("unexpected type")
+		f.walkUnexpected(x, context, visit)
 
 	case nil:
 
diff --git a/libgo/go/cmd/cgo/ast_go1.go b/libgo/go/cmd/cgo/ast_go1.go
new file mode 100644
index 00000000000..f52bf00d7cb
--- /dev/null
+++ b/libgo/go/cmd/cgo/ast_go1.go
@@ -0,0 +1,17 @@
+// Copyright 2021 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.
+
+//go:build compiler_bootstrap
+// +build compiler_bootstrap
+
+package main
+
+import (
+	"go/token"
+)
+
+func (f *File) walkUnexpected(x interface{}, context astContext, visit func(*File, interface{}, astContext)) {
+	error_(token.NoPos, "unexpected type %T in walk", x)
+	panic("unexpected type")
+}
diff --git a/libgo/go/cmd/cgo/ast_go118.go b/libgo/go/cmd/cgo/ast_go118.go
new file mode 100644
index 00000000000..db0108ed726
--- /dev/null
+++ b/libgo/go/cmd/cgo/ast_go118.go
@@ -0,0 +1,25 @@
+// Copyright 2021 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.
+
+//go:build !compiler_bootstrap
+// +build !compiler_bootstrap
+
+package main
+
+import (
+	"go/ast"
+	"go/token"
+)
+
+func (f *File) walkUnexpected(x interface{}, context astContext, visit func(*File, interface{}, astContext)) {
+	switch n := x.(type) {
+	default:
+		error_(token.NoPos, "unexpected type %T in walk", x)
+		panic("unexpected type")
+
+	case *ast.IndexListExpr:
+		f.walk(&n.X, ctxExpr, visit)
+		f.walk(n.Indices, ctxExpr, visit)
+	}
+}
diff --git a/libgo/go/cmd/cgo/gcc.go b/libgo/go/cmd/cgo/gcc.go
index de64a75f710..02391495bbe 100644
--- a/libgo/go/cmd/cgo/gcc.go
+++ b/libgo/go/cmd/cgo/gcc.go
@@ -23,10 +23,13 @@ import (
 	"internal/xcoff"
 	"math"
 	"os"
+	"os/exec"
 	"strconv"
 	"strings"
 	"unicode"
 	"unicode/utf8"
+
+	"cmd/internal/quoted"
 )
 
 var debugDefine = flag.Bool("debug-define", false, "print relevant #defines")
@@ -400,7 +403,7 @@ func (p *Package) guessKinds(f *File) []*Name {
 		stderr = p.gccErrors(b.Bytes())
 	}
 	if stderr == "" {
-		fatalf("%s produced no output\non input:\n%s", p.gccBaseCmd()[0], b.Bytes())
+		fatalf("%s produced no output\non input:\n%s", gccBaseCmd[0], b.Bytes())
 	}
 
 	completed := false
@@ -475,7 +478,7 @@ func (p *Package) guessKinds(f *File) []*Name {
 	}
 
 	if !completed {
-		fatalf("%s did not produce error at completed:1\non input:\n%s\nfull error output:\n%s", p.gccBaseCmd()[0], b.Bytes(), stderr)
+		fatalf("%s did not produce error at completed:1\non input:\n%s\nfull error output:\n%s", gccBaseCmd[0], b.Bytes(), stderr)
 	}
 
 	for i, n := range names {
@@ -506,7 +509,7 @@ func (p *Package) guessKinds(f *File) []*Name {
 		// to users debugging preamble mistakes. See issue 8442.
 		preambleErrors := p.gccErrors([]byte(f.Preamble))
 		if len(preambleErrors) > 0 {
-			error_(token.NoPos, "\n%s errors for preamble:\n%s", p.gccBaseCmd()[0], preambleErrors)
+			error_(token.NoPos, "\n%s errors for preamble:\n%s", gccBaseCmd[0], preambleErrors)
 		}
 
 		fatalf("unresolved names")
@@ -1521,7 +1524,7 @@ func (p *Package) rewriteName(f *File, r *Ref, addPosition bool) ast.Expr {
 				Args: []ast.Expr{getNewIdent(name.Mangle)},
 			}
 		case "type":
-			// Okay - might be new(T)
+			// Okay - might be new(T), T(x), Generic[T], etc.
 			if r.Name.Type == nil {
 				error_(r.Pos(), "expression C.%s: undefined C type '%s'", fixGo(r.Name.Go), r.Name.C)
 			}
@@ -1563,20 +1566,37 @@ func gofmtPos(n ast.Expr, pos token.Pos) string {
 	return fmt.Sprintf("/*line :%d:%d*/%s", p.Line, p.Column, s)
 }
 
-// gccBaseCmd returns the start of the compiler command line.
+// checkGCCBaseCmd returns the start of the compiler command line.
 // It uses $CC if set, or else $GCC, or else the compiler recorded
 // during the initial build as defaultCC.
 // defaultCC is defined in zdefaultcc.go, written by cmd/dist.
-func (p *Package) gccBaseCmd() []string {
+//
+// The compiler command line is split into arguments on whitespace. Quotes
+// are understood, so arguments may contain whitespace.
+//
+// checkGCCBaseCmd confirms that the compiler exists in PATH, returning
+// an error if it does not.
+func checkGCCBaseCmd() ([]string, error) {
 	// Use $CC if set, since that's what the build uses.
-	if ret := strings.Fields(os.Getenv("CC")); len(ret) > 0 {
-		return ret
+	value := os.Getenv("CC")
+	if value == "" {
+		// Try $GCC if set, since that's what we used to use.
+		value = os.Getenv("GCC")
+	}
+	if value == "" {
+		value = defaultCC(goos, goarch)
 	}
-	// Try $GCC if set, since that's what we used to use.
-	if ret := strings.Fields(os.Getenv("GCC")); len(ret) > 0 {
-		return ret
+	args, err := quoted.Split(value)
+	if err != nil {
+		return nil, err
 	}
-	return strings.Fields(defaultCC(goos, goarch))
+	if len(args) == 0 {
+		return nil, errors.New("CC not set and no default found")
+	}
+	if _, err := exec.LookPath(args[0]); err != nil {
+		return nil, fmt.Errorf("C compiler %q not found: %v", args[0], err)
+	}
+	return args[:len(args):len(args)], nil
 }
 
 // gccMachine returns the gcc -m flag to use, either "-m32", "-m64" or "-marm".
@@ -1630,7 +1650,7 @@ func gccTmp() string {
 // gccCmd returns the gcc command line to use for compiling
 // the input.
 func (p *Package) gccCmd() []string {
-	c := append(p.gccBaseCmd(),
+	c := append(gccBaseCmd,
 		"-w",          // no warnings
 		"-Wno-error",  // warnings are not errors
 		"-o"+gccTmp(), // write object to tmp
@@ -2030,7 +2050,7 @@ func (p *Package) gccDebug(stdin []byte, nnames int) (d *dwarf.Data, ints []int6
 // #defines that gcc encountered while processing the input
 // and its included files.
 func (p *Package) gccDefines(stdin []byte) string {
-	base := append(p.gccBaseCmd(), "-E", "-dM", "-xc")
+	base := append(gccBaseCmd, "-E", "-dM", "-xc")
 	base = append(base, p.gccMachine()...)
 	stdout, _ := runGcc(stdin, append(append(base, p.GccOptions...), "-"))
 	return stdout
@@ -2111,6 +2131,9 @@ type typeConv struct {
 	// Type names X for which there exists an XGetTypeID function with type func() CFTypeID.
 	getTypeIDs map[string]bool
 
+	// badStructs contains C structs that should be marked NotInHeap.
+	notInHeapStructs map[string]bool
+
 	// Predeclared types.
 	bool                                   ast.Expr
 	byte                                   ast.Expr // denotes padding
@@ -2122,6 +2145,7 @@ type typeConv struct {
 	string                                 ast.Expr
 	goVoid                                 ast.Expr // _Ctype_void, denotes C's void
 	goVoidPtr                              ast.Expr // unsafe.Pointer or *byte
+	goVoidPtrNoHeap                        ast.Expr // *_Ctype_void_notinheap, like goVoidPtr but marked NotInHeap
 
 	ptrSize int64
 	intSize int64
@@ -2145,6 +2169,7 @@ func (c *typeConv) Init(ptrSize, intSize int64) {
 	c.m = make(map[string]*Type)
 	c.ptrs = make(map[string][]*Type)
 	c.getTypeIDs = make(map[string]bool)
+	c.notInHeapStructs = make(map[string]bool)
 	c.bool = c.Ident("bool")
 	c.byte = c.Ident("byte")
 	c.int8 = c.Ident("int8")
@@ -2163,6 +2188,7 @@ func (c *typeConv) Init(ptrSize, intSize int64) {
 	c.void = c.Ident("void")
 	c.string = c.Ident("string")
 	c.goVoid = c.Ident("_Ctype_void")
+	c.goVoidPtrNoHeap = c.Ident("*_Ctype_void_notinheap")
 
 	// Normally cgo translates void* to unsafe.Pointer,
 	// but for historical reasons -godefs uses *byte instead.
@@ -2543,6 +2569,7 @@ func (c *typeConv) loadType(dtype dwarf.Type, pos token.Pos, parent string) *Typ
 				tt.C = &TypeRepr{"struct %s", []interface{}{tag}}
 			}
 			tt.Go = g
+			tt.NotInHeap = c.notInHeapStructs[tag]
 			typedef[name.Name] = &tt
 		}
 
@@ -2586,6 +2613,30 @@ func (c *typeConv) loadType(dtype dwarf.Type, pos token.Pos, parent string) *Typ
 				oldType.BadPointer = true
 			}
 		}
+		if c.badVoidPointerTypedef(dt) {
+			// Treat this typedef as a pointer to a NotInHeap void.
+			s := *sub
+			s.Go = c.goVoidPtrNoHeap
+			sub = &s
+			// Make sure we update any previously computed type.
+			if oldType := typedef[name.Name]; oldType != nil {
+				oldType.Go = sub.Go
+			}
+		}
+		// Check for non-pointer "struct <tag>{...}; typedef struct <tag> *<name>"
+		// typedefs that should be marked NotInHeap.
+		if ptr, ok := dt.Type.(*dwarf.PtrType); ok {
+			if strct, ok := ptr.Type.(*dwarf.StructType); ok {
+				if c.badStructPointerTypedef(dt.Name, strct) {
+					c.notInHeapStructs[strct.StructName] = true
+					// Make sure we update any previously computed type.
+					name := "_Ctype_struct_" + strct.StructName
+					if oldType := typedef[name]; oldType != nil {
+						oldType.NotInHeap = true
+					}
+				}
+			}
+		}
 		t.Go = name
 		t.BadPointer = sub.BadPointer
 		t.NotInHeap = sub.NotInHeap
@@ -3035,6 +3086,31 @@ func upper(s string) string {
 // so that all fields are exported.
 func godefsFields(fld []*ast.Field) {
 	prefix := fieldPrefix(fld)
+
+	// Issue 48396: check for duplicate field names.
+	if prefix != "" {
+		names := make(map[string]bool)
+	fldLoop:
+		for _, f := range fld {
+			for _, n := range f.Names {
+				name := n.Name
+				if name == "_" {
+					continue
+				}
+				if name != prefix {
+					name = strings.TrimPrefix(n.Name, prefix)
+				}
+				name = upper(name)
+				if names[name] {
+					// Field name conflict: don't remove prefix.
+					prefix = ""
+					break fldLoop
+				}
+				names[name] = true
+			}
+		}
+	}
+
 	npad := 0
 	for _, f := range fld {
 		for _, n := range f.Names {
@@ -3112,6 +3188,48 @@ func (c *typeConv) badPointerTypedef(dt *dwarf.TypedefType) bool {
 	return false
 }
 
+// badVoidPointerTypedef is like badPointerTypeDef, but for "void *" typedefs that should be NotInHeap.
+func (c *typeConv) badVoidPointerTypedef(dt *dwarf.TypedefType) bool {
+	// Match the Windows HANDLE type (#42018).
+	if goos != "windows" || dt.Name != "HANDLE" {
+		return false
+	}
+	// Check that the typedef is "typedef void *<name>".
+	if ptr, ok := dt.Type.(*dwarf.PtrType); ok {
+		if _, ok := ptr.Type.(*dwarf.VoidType); ok {
+			return true
+		}
+	}
+	return false
+}
+
+// badStructPointerTypedef is like badVoidPointerTypedefs but for structs.
+func (c *typeConv) badStructPointerTypedef(name string, dt *dwarf.StructType) bool {
+	// Windows handle types can all potentially contain non-pointers.
+	// badVoidPointerTypedef handles the "void *" HANDLE type, but other
+	// handles are defined as
+	//
+	// struct <name>__{int unused;}; typedef struct <name>__ *name;
+	//
+	// by the DECLARE_HANDLE macro in STRICT mode. The macro is declared in
+	// the Windows ntdef.h header,
+	//
+	// https://github.com/tpn/winsdk-10/blob/master/Include/10.0.16299.0/shared/ntdef.h#L779
+	if goos != "windows" {
+		return false
+	}
+	if len(dt.Field) != 1 {
+		return false
+	}
+	if dt.StructName != name+"__" {
+		return false
+	}
+	if f := dt.Field[0]; f.Name != "unused" || f.Type.Common().Name != "int" {
+		return false
+	}
+	return true
+}
+
 // baseBadPointerTypedef reports whether the base of a chain of typedefs is a bad typedef
 // as badPointerTypedef reports.
 func (c *typeConv) baseBadPointerTypedef(dt *dwarf.TypedefType) bool {
diff --git a/libgo/go/cmd/cgo/main.go b/libgo/go/cmd/cgo/main.go
index 40dc6d2562d..58477e47045 100644
--- a/libgo/go/cmd/cgo/main.go
+++ b/libgo/go/cmd/cgo/main.go
@@ -21,7 +21,6 @@ import (
 	"io"
 	"io/ioutil"
 	"os"
-	"os/exec"
 	"path/filepath"
 	"reflect"
 	"runtime"
@@ -252,6 +251,7 @@ var importSyscall = flag.Bool("import_syscall", true, "import syscall in generat
 var trimpath = flag.String("trimpath", "", "applies supplied rewrites or trims prefixes to recorded source file paths")
 
 var goarch, goos, gomips, gomips64 string
+var gccBaseCmd []string
 
 func main() {
 	objabi.AddVersionFlag() // -V
@@ -309,10 +309,10 @@ func main() {
 	p := newPackage(args[:i])
 
 	// We need a C compiler to be available. Check this.
-	gccName := p.gccBaseCmd()[0]
-	_, err := exec.LookPath(gccName)
+	var err error
+	gccBaseCmd, err = checkGCCBaseCmd()
 	if err != nil {
-		fatalf("C compiler %q not found: %v", gccName, err)
+		fatalf("%v", err)
 		os.Exit(2)
 	}
 
diff --git a/libgo/go/cmd/cgo/out.go b/libgo/go/cmd/cgo/out.go
index 3cf16f90f98..8d1eb5b6a96 100644
--- a/libgo/go/cmd/cgo/out.go
+++ b/libgo/go/cmd/cgo/out.go
@@ -64,9 +64,9 @@ func (p *Package) writeDefs() {
 	// Write C main file for using gcc to resolve imports.
 	fmt.Fprintf(fm, "int main() { return 0; }\n")
 	if *importRuntimeCgo {
-		fmt.Fprintf(fm, "void crosscall2(void(*fn)(void*), void *a, int c, __SIZE_TYPE__ ctxt) { }\n")
+		fmt.Fprintf(fm, "void crosscall2(void(*fn)(void*) __attribute__((unused)), void *a __attribute__((unused)), int c __attribute__((unused)), __SIZE_TYPE__ ctxt __attribute__((unused))) { }\n")
 		fmt.Fprintf(fm, "__SIZE_TYPE__ _cgo_wait_runtime_init_done(void) { return 0; }\n")
-		fmt.Fprintf(fm, "void _cgo_release_context(__SIZE_TYPE__ ctxt) { }\n")
+		fmt.Fprintf(fm, "void _cgo_release_context(__SIZE_TYPE__ ctxt __attribute__((unused))) { }\n")
 		fmt.Fprintf(fm, "char* _cgo_topofstack(void) { return (char*)0; }\n")
 	} else {
 		// If we're not importing runtime/cgo, we *are* runtime/cgo,
@@ -75,8 +75,8 @@ func (p *Package) writeDefs() {
 		fmt.Fprintf(fm, "__SIZE_TYPE__ _cgo_wait_runtime_init_done(void);\n")
 		fmt.Fprintf(fm, "void _cgo_release_context(__SIZE_TYPE__);\n")
 	}
-	fmt.Fprintf(fm, "void _cgo_allocate(void *a, int c) { }\n")
-	fmt.Fprintf(fm, "void _cgo_panic(void *a, int c) { }\n")
+	fmt.Fprintf(fm, "void _cgo_allocate(void *a __attribute__((unused)), int c __attribute__((unused))) { }\n")
+	fmt.Fprintf(fm, "void _cgo_panic(void *a __attribute__((unused)), int c __attribute__((unused))) { }\n")
 	fmt.Fprintf(fm, "void _cgo_reginit(void) { }\n")
 
 	// Write second Go output: definitions of _C_xxx.
@@ -140,6 +140,7 @@ func (p *Package) writeDefs() {
 		fmt.Fprintf(fgo2, "%s", buf.Bytes())
 		fmt.Fprintf(fgo2, "\n\n")
 	}
+	fmt.Fprintf(fgo2, "//go:notinheap\ntype _Ctype_void_notinheap struct{}\n\n")
 	if *gccgo {
 		fmt.Fprintf(fgo2, "type _Ctype_void byte\n")
 	} else {
@@ -1059,9 +1060,10 @@ func (p *Package) writeExports(fgo2, fm, fgcc, fgcch io.Writer) {
 
 		fmt.Fprintf(fm, "void _cgoexp%s_%s(void* p){}\n", cPrefix, exp.ExpName)
 
+		fmt.Fprintf(fgo2, "\t")
+
 		if gccResult != "void" {
 			// Write results back to frame.
-			fmt.Fprintf(fgo2, "\t")
 			forFieldList(fntype.Results,
 				func(i int, aname string, atype ast.Expr) {
 					if i > 0 {
@@ -1463,10 +1465,10 @@ const gccProlog = `
   (have a negative array count) and an inscrutable error will come
   out of the compiler and hopefully mention "name".
 */
-#define __cgo_compile_assert_eq(x, y, name) typedef char name[(x-y)*(x-y)*-2+1];
+#define __cgo_compile_assert_eq(x, y, name) typedef char name[(x-y)*(x-y)*-2UL+1UL];
 
 /* Check at compile time that the sizes we use match our expectations. */
-#define __cgo_size_assert(t, n) __cgo_compile_assert_eq(sizeof(t), n, _cgo_sizeof_##t##_is_not_##n)
+#define __cgo_size_assert(t, n) __cgo_compile_assert_eq(sizeof(t), (size_t)n, _cgo_sizeof_##t##_is_not_##n)
 
 __cgo_size_assert(char, 1)
 __cgo_size_assert(short, 2)
diff --git a/libgo/go/cmd/go.mod b/libgo/go/cmd/go.mod
index cd03968eedc..48fc888f949 100644
--- a/libgo/go/cmd/go.mod
+++ b/libgo/go/cmd/go.mod
@@ -1,15 +1,19 @@
 module cmd
 
-go 1.17
+go 1.18
 
 require (
-	github.com/google/pprof v0.0.0-20210506205249-923b5ab0fc1a
-	github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639 // indirect
-	golang.org/x/arch v0.0.0-20210502124803-cbf565b21d1e
-	golang.org/x/crypto v0.0.0-20210503195802-e9a32991a82e // indirect
-	golang.org/x/mod v0.4.3-0.20210608190319-0f08993efd8a
-	golang.org/x/sys v0.0.0-20210511113859-b0526f3d8744 // indirect
-	golang.org/x/term v0.0.0-20210503060354-a79de5458b56
-	golang.org/x/tools v0.1.2-0.20210519160823-49064d2332f9
+	github.com/google/pprof v0.0.0-20211104044539-f987b9c94b31
+	golang.org/x/arch v0.0.0-20210923205945-b76863e36670
+	golang.org/x/mod v0.6.0-dev.0.20211102181907-3a5865c02020
+	golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
+	golang.org/x/term v0.0.0-20210927222741-03fcf44c2211
+	golang.org/x/tools v0.1.9-0.20220124164225-97de9ec46646
+)
+
+require (
+	github.com/ianlancetaylor/demangle v0.0.0-20210905161508-09a460cdf81d // indirect
+	golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3 // indirect
+	golang.org/x/sys v0.0.0-20211205182925-97ca703d548d // indirect
 	golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
 )
diff --git a/libgo/go/cmd/go/alldocs.go b/libgo/go/cmd/go/alldocs.go
index 7f88d3216cf..826b0ccf19c 100644
--- a/libgo/go/cmd/go/alldocs.go
+++ b/libgo/go/cmd/go/alldocs.go
@@ -25,6 +25,7 @@
 // 	install     compile and install packages and dependencies
 // 	list        list packages or modules
 // 	mod         module maintenance
+// 	work        workspace maintenance
 // 	run         compile and run Go program
 // 	test        test packages
 // 	tool        run specified go tool
@@ -114,13 +115,16 @@
 // 		The default is GOMAXPROCS, normally the number of CPUs available.
 // 	-race
 // 		enable data race detection.
-// 		Supported only on linux/amd64, freebsd/amd64, darwin/amd64, windows/amd64,
+// 		Supported only on linux/amd64, freebsd/amd64, darwin/amd64, darwin/arm64, windows/amd64,
 // 		linux/ppc64le and linux/arm64 (only for 48-bit VMA).
 // 	-msan
 // 		enable interoperation with memory sanitizer.
 // 		Supported only on linux/amd64, linux/arm64
 // 		and only with Clang/LLVM as the host C compiler.
 // 		On linux/arm64, pie build mode will be used.
+// 	-asan
+// 		enable interoperation with address sanitizer.
+// 		Supported only on linux/arm64, linux/amd64.
 // 	-v
 // 		print the names of packages as they are compiled.
 // 	-work
@@ -133,6 +137,12 @@
 // 		arguments to pass on each go tool asm invocation.
 // 	-buildmode mode
 // 		build mode to use. See 'go help buildmode' for more.
+// 	-buildvcs
+// 		Whether to stamp binaries with version control information. By default,
+// 		version control information is stamped into a binary if the main package
+// 		and the main module containing it are in the repository containing the
+// 		current directory (if there is a repository). Use -buildvcs=false to
+// 		omit version control information.
 // 	-compiler name
 // 		name of compiler to use, as in runtime.Compiler (gccgo or gc).
 // 	-gccgoflags '[pattern=]arg list'
@@ -144,8 +154,8 @@
 // 		in order to keep output separate from default builds.
 // 		If using the -race flag, the install suffix is automatically set to race
 // 		or, if set explicitly, has _race appended to it. Likewise for the -msan
-// 		flag. Using a -buildmode option that requires non-default compile flags
-// 		has a similar effect.
+// 		and -asan flags. Using a -buildmode option that requires non-default compile
+// 		flags has a similar effect.
 // 	-ldflags '[pattern=]arg list'
 // 		arguments to pass on each go tool link invocation.
 // 	-linkshared
@@ -167,6 +177,14 @@
 // 		directory, but it is not accessed. When -modfile is specified, an
 // 		alternate go.sum file is also used: its path is derived from the
 // 		-modfile flag by trimming the ".mod" extension and appending ".sum".
+// 	-workfile file
+// 		in module aware mode, use the given go.work file as a workspace file.
+// 		By default or when -workfile is "auto", the go command searches for a
+// 		file named go.work in the current directory and then containing directories
+// 		until one is found. If a valid go.work file is found, the modules
+// 		specified will collectively be used as the main modules. If -workfile
+// 		is "off", or a go.work file is not found in "auto" mode, workspace
+// 		mode is disabled.
 // 	-overlay file
 // 		read a JSON config file that provides an overlay for build operations.
 // 		The file is a JSON struct with a single field, named 'Replace', that
@@ -191,9 +209,8 @@
 // 	-trimpath
 // 		remove all file system paths from the resulting executable.
 // 		Instead of absolute file system paths, the recorded file names
-// 		will begin with either "go" (for the standard library),
-// 		or a module path@version (when using modules),
-// 		or a plain import path (when using GOPATH).
+// 		will begin either a module path@version (when using modules),
+// 		or a plain import path (when using the standard library, or GOPATH).
 // 	-toolexec 'cmd args'
 // 		a program to use to invoke toolchain programs like vet and asm.
 // 		For example, instead of running asm, the go command will run
@@ -284,6 +301,13 @@
 // download cache, including unpacked source code of versioned
 // dependencies.
 //
+// The -fuzzcache flag causes clean to remove files stored in the Go build
+// cache for fuzz testing. The fuzzing engine caches files that expand
+// code coverage, so removing them may make fuzzing less effective until
+// new inputs are found that provide the same coverage. These files are
+// distinct from those stored in testdata directory; clean does not remove
+// those files.
+//
 // For more about build flags, see 'go help build'.
 //
 // For more about specifying packages, see 'go help packages'.
@@ -338,9 +362,8 @@
 // path. The go tool's usual package mechanism does not apply: package path
 // elements like . and ... are not implemented by go doc.
 //
-// When run with two arguments, the first must be a full package path (not just a
-// suffix), and the second is a symbol, or symbol with method or struct field.
-// This is similar to the syntax accepted by godoc:
+// When run with two arguments, the first is a package path (full path or suffix),
+// and the second is a symbol, or symbol with method or struct field:
 //
 // 	go doc <pkg> <sym>[.<methodOrField>]
 //
@@ -438,14 +461,18 @@
 //
 // Usage:
 //
-// 	go fix [packages]
+// 	go fix [-fix list] [packages]
 //
 // Fix runs the Go fix command on the packages named by the import paths.
 //
+// The -fix flag sets a comma-separated list of fixes to run.
+// The default is all known fixes.
+// (Its value is passed to 'go tool fix -r'.)
+//
 // For more about fix, see 'go doc cmd/fix'.
 // For more about specifying packages, see 'go help packages'.
 //
-// To run fix with specific options, run 'go tool fix'.
+// To run fix with other options, run 'go tool fix'.
 //
 // See also: go fmt, go vet.
 //
@@ -483,7 +510,7 @@
 // files. Those commands can run any process but the intent is to
 // create or update Go source files.
 //
-// Go generate is never run automatically by go build, go get, go test,
+// Go generate is never run automatically by go build, go test,
 // and so on. It must be run explicitly.
 //
 // Go generate scans the file for directives, which are lines of
@@ -598,11 +625,11 @@
 //
 // Usage:
 //
-// 	go get [-d] [-t] [-u] [-v] [build flags] [packages]
+// 	go get [-t] [-u] [-v] [build flags] [packages]
 //
 // Get resolves its command-line arguments to packages at specific module versions,
-// updates go.mod to require those versions, downloads source code into the
-// module cache, then builds and installs the named packages.
+// updates go.mod to require those versions, and downloads source code into the
+// module cache.
 //
 // To add a dependency for a package or upgrade it to its latest version:
 //
@@ -618,17 +645,18 @@
 //
 // See https://golang.org/ref/mod#go-get for details.
 //
-// The 'go install' command may be used to build and install packages. When a
-// version is specified, 'go install' runs in module-aware mode and ignores
-// the go.mod file in the current directory. For example:
+// In earlier versions of Go, 'go get' was used to build and install packages.
+// Now, 'go get' is dedicated to adjusting dependencies in go.mod. 'go install'
+// may be used to build and install commands instead. When a version is specified,
+// 'go install' runs in module-aware mode and ignores the go.mod file in the
+// current directory. For example:
 //
 // 	go install example.com/pkg@v1.2.3
 // 	go install example.com/pkg@latest
 //
 // See 'go help install' or https://golang.org/ref/mod#go-install for details.
 //
-// In addition to build flags (listed in 'go help build') 'go get' accepts the
-// following flags.
+// 'go get' accepts the following flags.
 //
 // The -t flag instructs get to consider modules needed to build tests of
 // packages specified on the command line.
@@ -643,15 +671,9 @@
 // When the -t and -u flags are used together, get will update
 // test dependencies as well.
 //
-// The -d flag instructs get not to build or install packages. get will only
-// update go.mod and download source code needed to build packages.
-//
-// Building and installing packages with get is deprecated. In a future release,
-// the -d flag will be enabled by default, and 'go get' will be only be used to
-// adjust dependencies of the current module. To install a package using
-// dependencies from the current module, use 'go install'. To install a package
-// ignoring the current module, use 'go install' with an @version suffix like
-// "@latest" after each argument.
+// The -x flag prints commands as they are executed. This is useful for
+// debugging version control commands when a module is downloaded directly
+// from a repository.
 //
 // For more about modules, see https://golang.org/ref/mod.
 //
@@ -694,14 +716,17 @@
 //
 // - All arguments must refer to packages in the same module at the same version.
 //
+// - Package path arguments must refer to main packages. Pattern arguments
+// will only match main packages.
+//
 // - No module is considered the "main" module. If the module containing
 // packages named on the command line has a go.mod file, it must not contain
 // directives (replace and exclude) that would cause it to be interpreted
 // differently than if it were the main module. The module must not require
 // a higher version of itself.
 //
-// - Package path arguments must refer to main packages. Pattern arguments
-// will only match main packages.
+// - Vendor directories are not used in any module. (Vendor directories are not
+// included in the module zip files downloaded by 'go install'.)
 //
 // If the arguments don't have version suffixes, "go install" may run in
 // module-aware mode or GOPATH mode, depending on the GO111MODULE environment
@@ -1041,8 +1066,11 @@
 //
 // Download downloads the named modules, which can be module patterns selecting
 // dependencies of the main module or module queries of the form path@version.
-// With no arguments, download applies to all dependencies of the main module
-// (equivalent to 'go mod download all').
+//
+// With no arguments, download applies to the modules needed to build and test
+// the packages in the main module: the modules explicitly required by the main
+// module if it is at 'go 1.17' or higher, or all transitively-required modules
+// if at 'go 1.16' or lower.
 //
 // The go command will automatically download modules as needed during ordinary
 // execution. The "go mod download" command is useful mainly for pre-filling
@@ -1260,7 +1288,7 @@
 //
 // Usage:
 //
-// 	go mod vendor [-e] [-v]
+// 	go mod vendor [-e] [-v] [-o outdir]
 //
 // Vendor resets the main module's vendor directory to include all packages
 // needed to build and test all the main module's packages.
@@ -1272,6 +1300,11 @@
 // The -e flag causes vendor to attempt to proceed despite errors
 // encountered while loading packages.
 //
+// The -o flag causes vendor to create the vendor directory at the given
+// path instead of "vendor". The go command can only use a vendor directory
+// named "vendor" within the module root directory, so this flag is
+// primarily useful for other tools.
+//
 // See https://golang.org/ref/mod#go-mod-vendor for more about 'go mod vendor'.
 //
 //
@@ -1329,6 +1362,202 @@
 // See https://golang.org/ref/mod#go-mod-why for more about 'go mod why'.
 //
 //
+// Workspace maintenance
+//
+// Go workspace provides access to operations on workspaces.
+//
+// Note that support for workspaces is built into many other commands, not
+// just 'go work'.
+//
+// See 'go help modules' for information about Go's module system of which
+// workspaces are a part.
+//
+// A workspace is specified by a go.work file that specifies a set of
+// module directories with the "use" directive. These modules are used as
+// root modules by the go command for builds and related operations.  A
+// workspace that does not specify modules to be used cannot be used to do
+// builds from local modules.
+//
+// go.work files are line-oriented. Each line holds a single directive,
+// made up of a keyword followed by aruments. For example:
+//
+// 	go 1.18
+//
+// 	use ../foo/bar
+// 	use ./baz
+//
+// 	replace example.com/foo v1.2.3 => example.com/bar v1.4.5
+//
+// The leading keyword can be factored out of adjacent lines to create a block,
+// like in Go imports.
+//
+// 	use (
+// 	  ../foo/bar
+// 	  ./baz
+// 	)
+//
+// The use directive specifies a module to be included in the workspace's
+// set of main modules. The argument to the use directive is the directory
+// containing the module's go.mod file.
+//
+// The go directive specifies the version of Go the file was written at. It
+// is possible there may be future changes in the semantics of workspaces
+// that could be controlled by this version, but for now the version
+// specified has no effect.
+//
+// The replace directive has the same syntax as the replace directive in a
+// go.mod file and takes precedence over replaces in go.mod files.  It is
+// primarily intended to override conflicting replaces in different workspace
+// modules.
+//
+// To determine whether the go command is operating in workspace mode, use
+// the "go env GOWORK" command. This will specify the workspace file being
+// used.
+//
+// Usage:
+//
+// 	go work <command> [arguments]
+//
+// The commands are:
+//
+// 	edit        edit go.work from tools or scripts
+// 	init        initialize workspace file
+// 	sync        sync workspace build list to modules
+// 	use         add modules to workspace file
+//
+// Use "go help work <command>" for more information about a command.
+//
+// Edit go.work from tools or scripts
+//
+// Usage:
+//
+// 	go work edit [editing flags] [go.work]
+//
+// Edit provides a command-line interface for editing go.work,
+// for use primarily by tools or scripts. It only reads go.work;
+// it does not look up information about the modules involved.
+// If no file is specified, Edit looks for a go.work file in the current
+// directory and its parent directories
+//
+// The editing flags specify a sequence of editing operations.
+//
+// The -fmt flag reformats the go.work file without making other changes.
+// This reformatting is also implied by any other modifications that use or
+// rewrite the go.mod file. The only time this flag is needed is if no other
+// flags are specified, as in 'go work edit -fmt'.
+//
+// The -use=path and -dropuse=path flags
+// add and drop a use directive from the go.work file's set of module directories.
+//
+// The -replace=old[@v]=new[@v] flag adds a replacement of the given
+// module path and version pair. If the @v in old@v is omitted, a
+// replacement without a version on the left side is added, which applies
+// to all versions of the old module path. If the @v in new@v is omitted,
+// the new path should be a local module root directory, not a module
+// path. Note that -replace overrides any redundant replacements for old[@v],
+// so omitting @v will drop existing replacements for specific versions.
+//
+// The -dropreplace=old[@v] flag drops a replacement of the given
+// module path and version pair. If the @v is omitted, a replacement without
+// a version on the left side is dropped.
+//
+// The -use, -dropuse, -replace, and -dropreplace,
+// editing flags may be repeated, and the changes are applied in the order given.
+//
+// The -go=version flag sets the expected Go language version.
+//
+// The -print flag prints the final go.work in its text format instead of
+// writing it back to go.mod.
+//
+// The -json flag prints the final go.work file in JSON format instead of
+// writing it back to go.mod. The JSON output corresponds to these Go types:
+//
+// 	type Module struct {
+// 		Path    string
+// 		Version string
+// 	}
+//
+// 	type GoWork struct {
+// 		Go        string
+// 		Directory []Directory
+// 		Replace   []Replace
+// 	}
+//
+// 	type Use struct {
+// 		Path       string
+// 		ModulePath string
+// 	}
+//
+// 	type Replace struct {
+// 		Old Module
+// 		New Module
+// 	}
+//
+// See the workspaces design proposal at
+// https://go.googlesource.com/proposal/+/master/design/45713-workspace.md for
+// more information.
+//
+//
+// Initialize workspace file
+//
+// Usage:
+//
+// 	go work init [moddirs]
+//
+// Init initializes and writes a new go.work file in the
+// current directory, in effect creating a new workspace at the current
+// directory.
+//
+// go work init optionally accepts paths to the workspace modules as
+// arguments. If the argument is omitted, an empty workspace with no
+// modules will be created.
+//
+// Each argument path is added to a use directive in the go.work file. The
+// current go version will also be listed in the go.work file.
+//
+//
+// Sync workspace build list to modules
+//
+// Usage:
+//
+// 	go work sync
+//
+// Sync syncs the workspace's build list back to the
+// workspace's modules
+//
+// The workspace's build list is the set of versions of all the
+// (transitive) dependency modules used to do builds in the workspace. go
+// work sync generates that build list using the Minimal Version Selection
+// algorithm, and then syncs those versions back to each of modules
+// specified in the workspace (with use directives).
+//
+// The syncing is done by sequentially upgrading each of the dependency
+// modules specified in a workspace module to the version in the build list
+// if the dependency module's version is not already the same as the build
+// list's version. Note that Minimal Version Selection guarantees that the
+// build list's version of each module is always the same or higher than
+// that in each workspace module.
+//
+//
+// Add modules to workspace file
+//
+// Usage:
+//
+// 	go work use [-r] [moddirs]
+//
+// Use provides a command-line interface for adding
+// directories, optionally recursively, to a go.work file.
+//
+// A use directive will be added to the go.work file for each argument
+// directory listed on the command line go.work file, if it exists on disk,
+// or removed from the go.work file if it does not exist on disk.
+//
+// The -r flag searches recursively for modules in the argument
+// directories, and the use command operates as if each of the directories
+// were specified as arguments: namely, use directives will be added for
+// directories that exist, and removed for directories that do not exist.
+//
+//
 // Compile and run Go program
 //
 // Usage:
@@ -1387,8 +1616,8 @@
 //
 // 'Go test' recompiles each package along with any files with names matching
 // the file pattern "*_test.go".
-// These additional files can contain test functions, benchmark functions, and
-// example functions. See 'go help testfunc' for more.
+// These additional files can contain test functions, benchmark functions, fuzz
+// tests and example functions. See 'go help testfunc' for more.
 // Each listed package causes the execution of a separate test binary.
 // Files whose names begin with "_" (including "_test.go") or "." are ignored.
 //
@@ -1405,7 +1634,8 @@
 // used. That subset is: 'atomic', 'bool', 'buildtags', 'errorsas',
 // 'ifaceassert', 'nilfunc', 'printf', and 'stringintconv'. You can see
 // the documentation for these and other vet tests via "go doc cmd/vet".
-// To disable the running of go vet, use the -vet=off flag.
+// To disable the running of go vet, use the -vet=off flag. To run all
+// checks, use the -vet=all flag.
 //
 // All test output and summary lines are printed to the go command's
 // standard output, even if the test printed them to its own standard
@@ -1446,16 +1676,16 @@
 // The rule for a match in the cache is that the run involves the same
 // test binary and the flags on the command line come entirely from a
 // restricted set of 'cacheable' test flags, defined as -benchtime, -cpu,
-// -list, -parallel, -run, -short, and -v. If a run of go test has any test
-// or non-test flags outside this set, the result is not cached. To
-// disable test caching, use any test flag or argument other than the
-// cacheable flags. The idiomatic way to disable test caching explicitly
-// is to use -count=1. Tests that open files within the package's source
-// root (usually $GOPATH) or that consult environment variables only
-// match future runs in which the files and environment variables are unchanged.
-// A cached test result is treated as executing in no time at all,
-// so a successful package test result will be cached and reused
-// regardless of -timeout setting.
+// -list, -parallel, -run, -short, -timeout, -failfast, and -v.
+// If a run of go test has any test or non-test flags outside this set,
+// the result is not cached. To disable test caching, use any test flag
+// or argument other than the cacheable flags. The idiomatic way to disable
+// test caching explicitly is to use -count=1. Tests that open files within
+// the package's source root (usually $GOPATH) or that consult environment
+// variables only match future runs in which the files and environment
+// variables are unchanged. A cached test result is treated as executing
+// in no time at all,so a successful package test result will be cached and
+// reused regardless of -timeout setting.
 //
 // In addition to the build flags, the flags handled by 'go test' itself are:
 //
@@ -1746,6 +1976,13 @@
 // See 'go help test' for details. Running 'go clean -testcache' removes
 // all cached test results (but not cached build results).
 //
+// The go command also caches values used in fuzzing with 'go test -fuzz',
+// specifically, values that expanded code coverage when passed to a
+// fuzz function. These values are not used for regular building and
+// testing, but they're stored in a subdirectory of the build cache.
+// Running 'go clean -fuzzcache' removes all cached fuzzing values.
+// This may make fuzzing less effective, temporarily.
+//
 // The GODEBUG environment variable can enable printing of debugging
 // information about the state of the cache:
 //
@@ -1885,6 +2122,10 @@
 // 	GO386
 // 		For GOARCH=386, how to implement floating point instructions.
 // 		Valid values are sse2 (default), softfloat.
+// 	GOAMD64
+// 		For GOARCH=amd64, the microarchitecture level for which to compile.
+// 		Valid values are v1 (default), v2, v3, v4.
+// 		See https://golang.org/wiki/MinimumRequirements#amd64
 // 	GOMIPS
 // 		For GOARCH=mips{,le}, whether to use floating point instructions.
 // 		Valid values are hardfloat (default), softfloat.
@@ -2622,9 +2863,10 @@
 // 	    (for example, -benchtime 100x).
 //
 // 	-count n
-// 	    Run each test and benchmark n times (default 1).
+// 	    Run each test, benchmark, and fuzz seed n times (default 1).
 // 	    If -cpu is set, run n times for each GOMAXPROCS value.
-// 	    Examples are always run once.
+// 	    Examples are always run once. -count does not apply to
+// 	    fuzz tests matched by -fuzz.
 //
 // 	-cover
 // 	    Enable coverage analysis.
@@ -2651,32 +2893,67 @@
 // 	    Sets -cover.
 //
 // 	-cpu 1,2,4
-// 	    Specify a list of GOMAXPROCS values for which the tests or
-// 	    benchmarks should be executed. The default is the current value
-// 	    of GOMAXPROCS.
+// 	    Specify a list of GOMAXPROCS values for which the tests, benchmarks or
+// 	    fuzz tests should be executed. The default is the current value
+// 	    of GOMAXPROCS. -cpu does not apply to fuzz tests matched by -fuzz.
 //
 // 	-failfast
 // 	    Do not start new tests after the first test failure.
 //
+// 	-fuzz regexp
+// 	    Run the fuzz test matching the regular expression. When specified,
+// 	    the command line argument must match exactly one package within the
+// 	    main module, and regexp must match exactly one fuzz test within
+// 	    that package. Fuzzing will occur after tests, benchmarks, seed corpora
+// 	    of other fuzz tests, and examples have completed. See the Fuzzing
+// 	    section of the testing package documentation for details.
+//
+// 	-fuzztime t
+// 	    Run enough iterations of the fuzz target during fuzzing to take t,
+// 	    specified as a time.Duration (for example, -fuzztime 1h30s).
+// 		The default is to run forever.
+// 	    The special syntax Nx means to run the fuzz target N times
+// 	    (for example, -fuzztime 1000x).
+//
+// 	-fuzzminimizetime t
+// 	    Run enough iterations of the fuzz target during each minimization
+// 	    attempt to take t, as specified as a time.Duration (for example,
+// 	    -fuzzminimizetime 30s).
+// 		The default is 60s.
+// 	    The special syntax Nx means to run the fuzz target N times
+// 	    (for example, -fuzzminimizetime 100x).
+//
+// 	-json
+// 	    Log verbose output and test results in JSON. This presents the
+// 	    same information as the -v flag in a machine-readable format.
+//
 // 	-list regexp
-// 	    List tests, benchmarks, or examples matching the regular expression.
-// 	    No tests, benchmarks or examples will be run. This will only
-// 	    list top-level tests. No subtest or subbenchmarks will be shown.
+// 	    List tests, benchmarks, fuzz tests, or examples matching the regular
+// 	    expression. No tests, benchmarks, fuzz tests, or examples will be run.
+// 	    This will only list top-level tests. No subtest or subbenchmarks will be
+// 	    shown.
 //
 // 	-parallel n
-// 	    Allow parallel execution of test functions that call t.Parallel.
+// 	    Allow parallel execution of test functions that call t.Parallel, and
+// 	    fuzz targets that call t.Parallel when running the seed corpus.
 // 	    The value of this flag is the maximum number of tests to run
-// 	    simultaneously; by default, it is set to the value of GOMAXPROCS.
+// 	    simultaneously.
+// 	    While fuzzing, the value of this flag is the maximum number of
+// 	    subprocesses that may call the fuzz function simultaneously, regardless of
+// 	    whether T.Parallel is called.
+// 	    By default, -parallel is set to the value of GOMAXPROCS.
+// 	    Setting -parallel to values higher than GOMAXPROCS may cause degraded
+// 	    performance due to CPU contention, especially when fuzzing.
 // 	    Note that -parallel only applies within a single test binary.
 // 	    The 'go test' command may run tests for different packages
 // 	    in parallel as well, according to the setting of the -p flag
 // 	    (see 'go help build').
 //
 // 	-run regexp
-// 	    Run only those tests and examples matching the regular expression.
-// 	    For tests, the regular expression is split by unbracketed slash (/)
-// 	    characters into a sequence of regular expressions, and each part
-// 	    of a test's identifier must match the corresponding element in
+// 	    Run only those tests, examples, and fuzz tests matching the regular
+// 	    expression. For tests, the regular expression is split by unbracketed
+// 	    slash (/) characters into a sequence of regular expressions, and each
+// 	    part of a test's identifier must match the corresponding element in
 // 	    the sequence, if any. Note that possible parents of matches are
 // 	    run too, so that -run=X/Y matches and runs and reports the result
 // 	    of all tests matching X, even those without sub-tests matching Y,
@@ -2689,11 +2966,11 @@
 // 	    exhaustive tests.
 //
 // 	-shuffle off,on,N
-// 		Randomize the execution order of tests and benchmarks.
-// 		It is off by default. If -shuffle is set to on, then it will seed
-// 		the randomizer using the system clock. If -shuffle is set to an
-// 		integer N, then N will be used as the seed value. In both cases,
-// 		the seed will be reported for reproducibility.
+// 	    Randomize the execution order of tests and benchmarks.
+// 	    It is off by default. If -shuffle is set to on, then it will seed
+// 	    the randomizer using the system clock. If -shuffle is set to an
+// 	    integer N, then N will be used as the seed value. In both cases,
+// 	    the seed will be reported for reproducibility.
 //
 // 	-timeout d
 // 	    If a test binary runs longer than duration d, panic.
@@ -2789,7 +3066,11 @@
 // When 'go test' runs a test binary, it does so from within the
 // corresponding package's source code directory. Depending on the test,
 // it may be necessary to do the same when invoking a generated test
-// binary directly.
+// binary directly. Because that directory may be located within the
+// module cache, which may be read-only and is verified by checksums, the
+// test must not write to it or any other directory within the module
+// unless explicitly requested by the user (such as with the -fuzz flag,
+// which writes failures to testdata/fuzz).
 //
 // The command-line package list, if present, must appear before any
 // flag not known to the go test command. Continuing the example above,
@@ -2843,6 +3124,10 @@
 //
 // 	func BenchmarkXxx(b *testing.B) { ... }
 //
+// A fuzz test is one named FuzzXxx and should have the signature,
+//
+// 	func FuzzXxx(f *testing.F) { ... }
+//
 // An example function is similar to a test function but, instead of using
 // *testing.T to report success or failure, prints output to os.Stdout.
 // If the last comment in the function starts with "Output:" then the output
@@ -2882,7 +3167,7 @@
 //
 // The entire test file is presented as the example when it contains a single
 // example function, at least one other function, type, variable, or constant
-// declaration, and no test or benchmark functions.
+// declaration, and no tests, benchmarks, or fuzz tests.
 //
 // See the documentation of the testing package for more information.
 //
diff --git a/libgo/go/cmd/go/go11.go b/libgo/go/cmd/go/go11.go
index a1f2727825e..9faa7cba42e 100644
--- a/libgo/go/cmd/go/go11.go
+++ b/libgo/go/cmd/go/go11.go
@@ -3,7 +3,6 @@
 // license that can be found in the LICENSE file.
 
 //go:build go1.1
-// +build go1.1
 
 package main
 
diff --git a/libgo/go/cmd/go/go_test.go b/libgo/go/cmd/go/go_test.go
index 6ce276537ba..7aaec4eb986 100644
--- a/libgo/go/cmd/go/go_test.go
+++ b/libgo/go/cmd/go/go_test.go
@@ -13,6 +13,7 @@ import (
 	"flag"
 	"fmt"
 	"go/format"
+	"internal/godebug"
 	"internal/race"
 	"internal/testenv"
 	"io"
@@ -31,7 +32,6 @@ import (
 	"cmd/go/internal/cache"
 	"cmd/go/internal/cfg"
 	"cmd/go/internal/robustio"
-	"cmd/go/internal/work"
 	"cmd/internal/sys"
 )
 
@@ -44,9 +44,12 @@ func init() {
 }
 
 var (
-	canRace = false // whether we can run the race detector
-	canCgo  = false // whether we can use cgo
-	canMSan = false // whether we can run the memory sanitizer
+	canRace          = false // whether we can run the race detector
+	canCgo           = false // whether we can use cgo
+	canMSan          = false // whether we can run the memory sanitizer
+	canASan          = false // whether we can run the address sanitizer
+	canFuzz          = false // whether we can search for new fuzz failures
+	fuzzInstrumented = false // whether fuzzing uses instrumentation
 )
 
 var exeSuffix string = func() string {
@@ -198,6 +201,7 @@ func TestMain(m *testing.M) {
 		testGOCACHE = strings.TrimSpace(string(out))
 
 		canMSan = canCgo && sys.MSanSupported(runtime.GOOS, runtime.GOARCH)
+		canASan = canCgo && sys.ASanSupported(runtime.GOOS, runtime.GOARCH)
 		canRace = canCgo && sys.RaceDetectorSupported(runtime.GOOS, runtime.GOARCH)
 		// The race detector doesn't work on Alpine Linux:
 		// golang.org/issue/14481
@@ -205,6 +209,8 @@ func TestMain(m *testing.M) {
 		if isAlpineLinux() || runtime.Compiler == "gccgo" {
 			canRace = false
 		}
+		canFuzz = sys.FuzzSupported(runtime.GOOS, runtime.GOARCH)
+		fuzzInstrumented = sys.FuzzInstrumented(runtime.GOOS, runtime.GOARCH)
 	}
 	// Don't let these environment variables confuse the test.
 	os.Setenv("GOENV", "off")
@@ -806,7 +812,9 @@ func TestNewReleaseRebuildsStalePackagesInGOPATH(t *testing.T) {
 		"src/internal/abi",
 		"src/internal/bytealg",
 		"src/internal/cpu",
+		"src/internal/goarch",
 		"src/internal/goexperiment",
+		"src/internal/goos",
 		"src/math/bits",
 		"src/unsafe",
 		filepath.Join("pkg", runtime.GOOS+"_"+runtime.GOARCH),
@@ -1120,11 +1128,11 @@ func TestGoListTest(t *testing.T) {
 	tg.grepStdoutNot(`^testing \[sort.test\]$`, "unexpected test copy of testing")
 	tg.grepStdoutNot(`^testing$`, "unexpected real copy of testing")
 
-	tg.run("list", "-test", "cmd/dist", "cmd/doc")
-	tg.grepStdout(`^cmd/dist$`, "missing cmd/dist")
+	tg.run("list", "-test", "cmd/buildid", "cmd/doc")
+	tg.grepStdout(`^cmd/buildid$`, "missing cmd/buildid")
 	tg.grepStdout(`^cmd/doc$`, "missing cmd/doc")
 	tg.grepStdout(`^cmd/doc\.test$`, "missing cmd/doc test")
-	tg.grepStdoutNot(`^cmd/dist\.test$`, "unexpected cmd/dist test")
+	tg.grepStdoutNot(`^cmd/buildid\.test$`, "unexpected cmd/buildid test")
 	tg.grepStdoutNot(`^testing`, "unexpected testing")
 
 	tg.run("list", "-test", "runtime/cgo")
@@ -1376,7 +1384,7 @@ func TestLdFlagsLongArgumentsIssue42295(t *testing.T) {
 		}`)
 	testStr := "test test test test test \n\\ "
 	var buf bytes.Buffer
-	for buf.Len() < work.ArgLengthForResponseFile+1 {
+	for buf.Len() < sys.ExecArgLengthLimit+1 {
 		buf.WriteString(testStr)
 	}
 	tg.run("run", "-ldflags", fmt.Sprintf(`-X "main.extern=%s"`, buf.String()), tg.path("main.go"))
@@ -2274,7 +2282,7 @@ func TestUpxCompression(t *testing.T) {
 
 func TestCacheListStale(t *testing.T) {
 	tooSlow(t)
-	if strings.Contains(os.Getenv("GODEBUG"), "gocacheverify") {
+	if godebug.Get("gocacheverify") == "1" {
 		t.Skip("GODEBUG gocacheverify")
 	}
 	tg := testgo(t)
@@ -2297,7 +2305,7 @@ func TestCacheListStale(t *testing.T) {
 func TestCacheCoverage(t *testing.T) {
 	tooSlow(t)
 
-	if strings.Contains(os.Getenv("GODEBUG"), "gocacheverify") {
+	if godebug.Get("gocacheverify") == "1" {
 		t.Skip("GODEBUG gocacheverify")
 	}
 
@@ -2329,7 +2337,7 @@ func TestIssue22588(t *testing.T) {
 
 func TestIssue22531(t *testing.T) {
 	tooSlow(t)
-	if strings.Contains(os.Getenv("GODEBUG"), "gocacheverify") {
+	if godebug.Get("gocacheverify") == "1" {
 		t.Skip("GODEBUG gocacheverify")
 	}
 	tg := testgo(t)
@@ -2358,7 +2366,7 @@ func TestIssue22531(t *testing.T) {
 
 func TestIssue22596(t *testing.T) {
 	tooSlow(t)
-	if strings.Contains(os.Getenv("GODEBUG"), "gocacheverify") {
+	if godebug.Get("gocacheverify") == "1" {
 		t.Skip("GODEBUG gocacheverify")
 	}
 	tg := testgo(t)
@@ -2388,7 +2396,7 @@ func TestIssue22596(t *testing.T) {
 func TestTestCache(t *testing.T) {
 	tooSlow(t)
 
-	if strings.Contains(os.Getenv("GODEBUG"), "gocacheverify") {
+	if godebug.Get("gocacheverify") == "1" {
 		t.Skip("GODEBUG gocacheverify")
 	}
 	tg := testgo(t)
diff --git a/libgo/go/cmd/go/go_unix_test.go b/libgo/go/cmd/go/go_unix_test.go
index db992b78914..29fa343d931 100644
--- a/libgo/go/cmd/go/go_unix_test.go
+++ b/libgo/go/cmd/go/go_unix_test.go
@@ -3,7 +3,6 @@
 // license that can be found in the LICENSE file.
 
 //go:build darwin || dragonfly || freebsd || hurd || linux || netbsd || openbsd || solaris
-// +build darwin dragonfly freebsd hurd linux netbsd openbsd solaris
 
 package main_test
 
diff --git a/libgo/go/cmd/go/internal/base/base.go b/libgo/go/cmd/go/internal/base/base.go
index 954ce47a989..c2d4e6b2588 100644
--- a/libgo/go/cmd/go/internal/base/base.go
+++ b/libgo/go/cmd/go/internal/base/base.go
@@ -117,12 +117,12 @@ func Exit() {
 	os.Exit(exitStatus)
 }
 
-func Fatalf(format string, args ...interface{}) {
+func Fatalf(format string, args ...any) {
 	Errorf(format, args...)
 	Exit()
 }
 
-func Errorf(format string, args ...interface{}) {
+func Errorf(format string, args ...any) {
 	log.Printf(format, args...)
 	SetExitStatus(1)
 }
@@ -151,7 +151,7 @@ func GetExitStatus() int {
 // Run runs the command, with stdout and stderr
 // connected to the go command's own stdout and stderr.
 // If the command fails, Run reports the error using Errorf.
-func Run(cmdargs ...interface{}) {
+func Run(cmdargs ...any) {
 	cmdline := str.StringList(cmdargs...)
 	if cfg.BuildN || cfg.BuildX {
 		fmt.Printf("%s\n", strings.Join(cmdline, " "))
diff --git a/libgo/go/cmd/go/internal/base/flag.go b/libgo/go/cmd/go/internal/base/flag.go
index 677f8196827..2c72c7e562b 100644
--- a/libgo/go/cmd/go/internal/base/flag.go
+++ b/libgo/go/cmd/go/internal/base/flag.go
@@ -9,7 +9,7 @@ import (
 
 	"cmd/go/internal/cfg"
 	"cmd/go/internal/fsys"
-	"cmd/go/internal/str"
+	"cmd/internal/quoted"
 )
 
 // A StringsFlag is a command-line flag that interprets its argument
@@ -18,7 +18,7 @@ type StringsFlag []string
 
 func (v *StringsFlag) Set(s string) error {
 	var err error
-	*v, err = str.SplitQuotedFields(s)
+	*v, err = quoted.Split(s)
 	if *v == nil {
 		*v = []string{}
 	}
@@ -62,6 +62,13 @@ func AddModFlag(flags *flag.FlagSet) {
 	flags.Var(explicitStringFlag{value: &cfg.BuildMod, explicit: &cfg.BuildModExplicit}, "mod", "")
 }
 
+// AddWorkfileFlag adds the workfile flag to the flag set. It enables workspace
+// mode for commands that support it by resetting the cfg.WorkFile variable
+// to "" (equivalent to auto) rather than off.
+func AddWorkfileFlag(flags *flag.FlagSet) {
+	flags.Var(explicitStringFlag{value: &cfg.WorkFile, explicit: &cfg.WorkFileExplicit}, "workfile", "")
+}
+
 // AddModCommonFlags adds the module-related flags common to build commands
 // and 'go mod' subcommands.
 func AddModCommonFlags(flags *flag.FlagSet) {
diff --git a/libgo/go/cmd/go/internal/base/signal_notunix.go b/libgo/go/cmd/go/internal/base/signal_notunix.go
index 5cc0b0f1011..682705f9b2c 100644
--- a/libgo/go/cmd/go/internal/base/signal_notunix.go
+++ b/libgo/go/cmd/go/internal/base/signal_notunix.go
@@ -3,7 +3,6 @@
 // license that can be found in the LICENSE file.
 
 //go:build plan9 || windows
-// +build plan9 windows
 
 package base
 
diff --git a/libgo/go/cmd/go/internal/base/signal_unix.go b/libgo/go/cmd/go/internal/base/signal_unix.go
index cdb25934c2d..0cf58eb9299 100644
--- a/libgo/go/cmd/go/internal/base/signal_unix.go
+++ b/libgo/go/cmd/go/internal/base/signal_unix.go
@@ -3,7 +3,6 @@
 // license that can be found in the LICENSE file.
 
 //go:build aix || darwin || dragonfly || freebsd || hurd || js || linux || netbsd || openbsd || solaris
-// +build aix darwin dragonfly freebsd hurd js linux netbsd openbsd solaris
 
 package base
 
diff --git a/libgo/go/cmd/go/internal/base/tool.go b/libgo/go/cmd/go/internal/base/tool.go
index d0da65e03ce..f9270169650 100644
--- a/libgo/go/cmd/go/internal/base/tool.go
+++ b/libgo/go/cmd/go/internal/base/tool.go
@@ -36,7 +36,7 @@ func Tool(toolName string) string {
 	}
 	// Give a nice message if there is no tool with that name.
 	if _, err := os.Stat(toolPath); err != nil {
-		fmt.Fprintf(os.Stderr, "go tool: no such tool %q\n", toolName)
+		fmt.Fprintf(os.Stderr, "go: no such tool %q\n", toolName)
 		SetExitStatus(2)
 		Exit()
 	}
diff --git a/libgo/go/cmd/go/internal/bug/bug.go b/libgo/go/cmd/go/internal/bug/bug.go
index 307527c695c..702dc2a14ac 100644
--- a/libgo/go/cmd/go/internal/bug/bug.go
+++ b/libgo/go/cmd/go/internal/bug/bug.go
@@ -40,7 +40,7 @@ func init() {
 
 func runBug(ctx context.Context, cmd *base.Command, args []string) {
 	if len(args) > 0 {
-		base.Fatalf("go bug: bug takes no arguments")
+		base.Fatalf("go: bug takes no arguments")
 	}
 	var buf bytes.Buffer
 	buf.WriteString(bugHeader)
@@ -106,8 +106,9 @@ func printGoEnv(w io.Writer) {
 }
 
 func printGoDetails(w io.Writer) {
-	printCmdOut(w, "GOROOT/bin/go version: ", filepath.Join(runtime.GOROOT(), "bin/go"), "version")
-	printCmdOut(w, "GOROOT/bin/go tool compile -V: ", filepath.Join(runtime.GOROOT(), "bin/go"), "tool", "compile", "-V")
+	gocmd := filepath.Join(runtime.GOROOT(), "bin/go")
+	printCmdOut(w, "GOROOT/bin/go version: ", gocmd, "version")
+	printCmdOut(w, "GOROOT/bin/go tool compile -V: ", gocmd, "tool", "compile", "-V")
 }
 
 func printOSDetails(w io.Writer) {
diff --git a/libgo/go/cmd/go/internal/cache/cache.go b/libgo/go/cmd/go/internal/cache/cache.go
index d592d704978..93d7c25658f 100644
--- a/libgo/go/cmd/go/internal/cache/cache.go
+++ b/libgo/go/cmd/go/internal/cache/cache.go
@@ -533,3 +533,15 @@ func (c *Cache) copyFile(file io.ReadSeeker, out OutputID, size int64) error {
 
 	return nil
 }
+
+// FuzzDir returns a subdirectory within the cache for storing fuzzing data.
+// The subdirectory may not exist.
+//
+// This directory is managed by the internal/fuzz package. Files in this
+// directory aren't removed by the 'go clean -cache' command or by Trim.
+// They may be removed with 'go clean -fuzzcache'.
+//
+// TODO(#48526): make Trim remove unused files from this directory.
+func (c *Cache) FuzzDir() string {
+	return filepath.Join(c.dir, "fuzz")
+}
diff --git a/libgo/go/cmd/go/internal/cache/default.go b/libgo/go/cmd/go/internal/cache/default.go
index 0b1c1e0c203..426dddfb978 100644
--- a/libgo/go/cmd/go/internal/cache/default.go
+++ b/libgo/go/cmd/go/internal/cache/default.go
@@ -30,6 +30,7 @@ var (
 // README as a courtesy to explain where it came from.
 const cacheREADME = `This directory holds cached build artifacts from the Go build system.
 Run "go clean -cache" if the directory is getting too large.
+Run "go clean -fuzzcache" to delete the fuzz cache.
 See golang.org to learn more about Go.
 `
 
diff --git a/libgo/go/cmd/go/internal/cfg/cfg.go b/libgo/go/cmd/go/internal/cfg/cfg.go
index 57a3c1ff6fb..7f68d7bb628 100644
--- a/libgo/go/cmd/go/internal/cfg/cfg.go
+++ b/libgo/go/cmd/go/internal/cfg/cfg.go
@@ -26,6 +26,7 @@ import (
 var (
 	BuildA                 bool   // -a flag
 	BuildBuildmode         string // -buildmode flag
+	BuildBuildvcs          bool   // -buildvcs flag
 	BuildContext           = defaultContext()
 	BuildMod               string                  // -mod flag
 	BuildModExplicit       bool                    // whether -mod was set explicitly
@@ -33,6 +34,7 @@ var (
 	BuildI                 bool                    // -i flag
 	BuildLinkshared        bool                    // -linkshared flag
 	BuildMSan              bool                    // -msan flag
+	BuildASan              bool                    // -asan flag
 	BuildN                 bool                    // -n flag
 	BuildO                 string                  // -o flag
 	BuildP                 = runtime.GOMAXPROCS(0) // -p flag
@@ -47,17 +49,26 @@ var (
 	BuildWork              bool // -work flag
 	BuildX                 bool // -x flag
 
-	ModCacheRW bool   // -modcacherw flag
-	ModFile    string // -modfile flag
+	ModCacheRW       bool   // -modcacherw flag
+	ModFile          string // -modfile flag
+	WorkFile         string // -workfile flag
+	WorkFileExplicit bool   // whether -workfile was set explicitly
 
 	CmdName string // "build", "install", "list", "mod tidy", etc.
 
 	DebugActiongraph string // -debug-actiongraph flag (undocumented, unstable)
 	DebugTrace       string // -debug-trace flag
+
+	// GoPathError is set when GOPATH is not set. it contains an
+	// explanation why GOPATH is unset.
+	GoPathError string
+
+	GOEXPERIMENT = envOr("GOEXPERIMENT", buildcfg.DefaultGOEXPERIMENT)
 )
 
 func defaultContext() build.Context {
 	ctxt := build.Default
+
 	ctxt.JoinPath = filepath.Join // back door to say "do not use go command"
 
 	ctxt.GOROOT = findGOROOT()
@@ -70,7 +81,7 @@ func defaultContext() build.Context {
 		build.ToolDir = filepath.Join(ctxt.GOROOT, "pkg/tool/"+runtime.GOOS+"_"+runtime.GOARCH)
 	}
 
-	ctxt.GOPATH = envOr("GOPATH", ctxt.GOPATH)
+	ctxt.GOPATH = envOr("GOPATH", gopath(ctxt))
 
 	// Override defaults computed in go/build with defaults
 	// from go environment configuration file, if known.
@@ -79,7 +90,7 @@ func defaultContext() build.Context {
 
 	// The experiments flags are based on GOARCH, so they may
 	// need to change.  TODO: This should be cleaned up.
-	buildcfg.UpdateExperiments(ctxt.GOOS, ctxt.GOARCH, envOr("GOEXPERIMENT", buildcfg.DefaultGOEXPERIMENT))
+	buildcfg.UpdateExperiments(ctxt.GOOS, ctxt.GOARCH, GOEXPERIMENT)
 	ctxt.ToolTags = nil
 	for _, exp := range buildcfg.EnabledExperiments() {
 		ctxt.ToolTags = append(ctxt.ToolTags, "goexperiment."+exp)
@@ -261,6 +272,7 @@ var (
 	// Used in envcmd.MkEnv and build ID computations.
 	GOARM    = envOr("GOARM", fmt.Sprint(buildcfg.GOARM))
 	GO386    = envOr("GO386", buildcfg.GO386)
+	GOAMD64  = envOr("GOAMD64", fmt.Sprintf("%s%d", "v", buildcfg.GOAMD64))
 	GOMIPS   = envOr("GOMIPS", buildcfg.GOMIPS)
 	GOMIPS64 = envOr("GOMIPS64", buildcfg.GOMIPS64)
 	GOPPC64  = envOr("GOPPC64", fmt.Sprintf("%s%d", "power", buildcfg.GOPPC64))
@@ -287,6 +299,8 @@ func GetArchEnv() (key, val string) {
 		return "GOARM", GOARM
 	case "386":
 		return "GO386", GO386
+	case "amd64":
+		return "GOAMD64", GOAMD64
 	case "mips", "mipsle":
 		return "GOMIPS", GOMIPS
 	case "mips64", "mips64le":
@@ -396,3 +410,24 @@ func gopathDir(rel string) string {
 	}
 	return filepath.Join(list[0], rel)
 }
+
+func gopath(ctxt build.Context) string {
+	if len(ctxt.GOPATH) > 0 {
+		return ctxt.GOPATH
+	}
+	env := "HOME"
+	if runtime.GOOS == "windows" {
+		env = "USERPROFILE"
+	} else if runtime.GOOS == "plan9" {
+		env = "home"
+	}
+	if home := os.Getenv(env); home != "" {
+		def := filepath.Join(home, "go")
+		if filepath.Clean(def) == filepath.Clean(runtime.GOROOT()) {
+			GoPathError = "cannot set GOROOT as GOPATH"
+		}
+		return ""
+	}
+	GoPathError = fmt.Sprintf("%s is not set", env)
+	return ""
+}
diff --git a/libgo/go/cmd/go/internal/clean/clean.go b/libgo/go/cmd/go/internal/clean/clean.go
index fd4cb205591..dc93cdf5983 100644
--- a/libgo/go/cmd/go/internal/clean/clean.go
+++ b/libgo/go/cmd/go/internal/clean/clean.go
@@ -75,6 +75,13 @@ The -modcache flag causes clean to remove the entire module
 download cache, including unpacked source code of versioned
 dependencies.
 
+The -fuzzcache flag causes clean to remove files stored in the Go build
+cache for fuzz testing. The fuzzing engine caches files that expand
+code coverage, so removing them may make fuzzing less effective until
+new inputs are found that provide the same coverage. These files are
+distinct from those stored in testdata directory; clean does not remove
+those files.
+
 For more about build flags, see 'go help build'.
 
 For more about specifying packages, see 'go help packages'.
@@ -85,6 +92,7 @@ var (
 	cleanI         bool // clean -i flag
 	cleanR         bool // clean -r flag
 	cleanCache     bool // clean -cache flag
+	cleanFuzzcache bool // clean -fuzzcache flag
 	cleanModcache  bool // clean -modcache flag
 	cleanTestcache bool // clean -testcache flag
 )
@@ -96,6 +104,7 @@ func init() {
 	CmdClean.Flag.BoolVar(&cleanI, "i", false, "")
 	CmdClean.Flag.BoolVar(&cleanR, "r", false, "")
 	CmdClean.Flag.BoolVar(&cleanCache, "cache", false, "")
+	CmdClean.Flag.BoolVar(&cleanFuzzcache, "fuzzcache", false, "")
 	CmdClean.Flag.BoolVar(&cleanModcache, "modcache", false, "")
 	CmdClean.Flag.BoolVar(&cleanTestcache, "testcache", false, "")
 
@@ -112,7 +121,7 @@ func runClean(ctx context.Context, cmd *base.Command, args []string) {
 	// or no other target (such as a cache) was requested to be cleaned.
 	cleanPkg := len(args) > 0 || cleanI || cleanR
 	if (!modload.Enabled() || modload.HasModRoot()) &&
-		!cleanCache && !cleanModcache && !cleanTestcache {
+		!cleanCache && !cleanModcache && !cleanTestcache && !cleanFuzzcache {
 		cleanPkg = true
 	}
 
@@ -144,7 +153,7 @@ func runClean(ctx context.Context, cmd *base.Command, args []string) {
 						// This also mimics what os.RemoveAll(dir) would do.
 						if err := os.RemoveAll(d); err != nil && !printedErrors {
 							printedErrors = true
-							base.Errorf("go clean -cache: %v", err)
+							base.Errorf("go: %v", err)
 						}
 					}
 				}
@@ -157,7 +166,7 @@ func runClean(ctx context.Context, cmd *base.Command, args []string) {
 			if !cfg.BuildN {
 				if err := os.RemoveAll(logFile); err != nil && !printedErrors {
 					printedErrors = true
-					base.Errorf("go clean -cache: %v", err)
+					base.Errorf("go: %v", err)
 				}
 			}
 		}
@@ -187,7 +196,7 @@ func runClean(ctx context.Context, cmd *base.Command, args []string) {
 			}
 			if err != nil {
 				if _, statErr := os.Stat(dir); !os.IsNotExist(statErr) {
-					base.Errorf("go clean -testcache: %v", err)
+					base.Errorf("go: %v", err)
 				}
 			}
 		}
@@ -195,14 +204,26 @@ func runClean(ctx context.Context, cmd *base.Command, args []string) {
 
 	if cleanModcache {
 		if cfg.GOMODCACHE == "" {
-			base.Fatalf("go clean -modcache: no module cache")
+			base.Fatalf("go: cannot clean -modcache without a module cache")
 		}
 		if cfg.BuildN || cfg.BuildX {
 			b.Showcmd("", "rm -rf %s", cfg.GOMODCACHE)
 		}
 		if !cfg.BuildN {
 			if err := modfetch.RemoveAll(cfg.GOMODCACHE); err != nil {
-				base.Errorf("go clean -modcache: %v", err)
+				base.Errorf("go: %v", err)
+			}
+		}
+	}
+
+	if cleanFuzzcache {
+		fuzzDir := cache.Default().FuzzDir()
+		if cfg.BuildN || cfg.BuildX {
+			b.Showcmd("", "rm -rf %s", fuzzDir)
+		}
+		if !cfg.BuildN {
+			if err := os.RemoveAll(fuzzDir); err != nil {
+				base.Errorf("go: %v", err)
 			}
 		}
 	}
@@ -245,7 +266,7 @@ func clean(p *load.Package) {
 	}
 	dirs, err := os.ReadDir(p.Dir)
 	if err != nil {
-		base.Errorf("go clean %s: %v", p.Dir, err)
+		base.Errorf("go: %s: %v", p.Dir, err)
 		return
 	}
 
@@ -334,7 +355,7 @@ func clean(p *load.Package) {
 					}
 				}
 				if err := os.RemoveAll(filepath.Join(p.Dir, name)); err != nil {
-					base.Errorf("go clean: %v", err)
+					base.Errorf("go: %v", err)
 				}
 			}
 			continue
@@ -386,5 +407,5 @@ func removeFile(f string) {
 			return
 		}
 	}
-	base.Errorf("go clean: %v", err)
+	base.Errorf("go: %v", err)
 }
diff --git a/libgo/go/cmd/go/internal/cmdflag/flag.go b/libgo/go/cmd/go/internal/cmdflag/flag.go
index 8abb7e559f5..a634bc1ab8d 100644
--- a/libgo/go/cmd/go/internal/cmdflag/flag.go
+++ b/libgo/go/cmd/go/internal/cmdflag/flag.go
@@ -92,7 +92,7 @@ func ParseOne(fs *flag.FlagSet, args []string) (f *flag.Flag, remainingArgs []st
 	// Use fs.Set instead of f.Value.Set below so that any subsequent call to
 	// fs.Visit will correctly visit the flags that have been set.
 
-	failf := func(format string, a ...interface{}) (*flag.Flag, []string, error) {
+	failf := func(format string, a ...any) (*flag.Flag, []string, error) {
 		return f, args, fmt.Errorf(format, a...)
 	}
 
diff --git a/libgo/go/cmd/go/internal/doc/doc.go b/libgo/go/cmd/go/internal/doc/doc.go
index 8580a5dc4d2..7741a9022c9 100644
--- a/libgo/go/cmd/go/internal/doc/doc.go
+++ b/libgo/go/cmd/go/internal/doc/doc.go
@@ -60,9 +60,8 @@ The package path must be either a qualified path or a proper suffix of a
 path. The go tool's usual package mechanism does not apply: package path
 elements like . and ... are not implemented by go doc.
 
-When run with two arguments, the first must be a full package path (not just a
-suffix), and the second is a symbol, or symbol with method or struct field.
-This is similar to the syntax accepted by godoc:
+When run with two arguments, the first is a package path (full path or suffix),
+and the second is a symbol, or symbol with method or struct field:
 
 	go doc <pkg> <sym>[.<methodOrField>]
 
diff --git a/libgo/go/cmd/go/internal/envcmd/env.go b/libgo/go/cmd/go/internal/envcmd/env.go
index 1553d263914..e56dd8223f0 100644
--- a/libgo/go/cmd/go/internal/envcmd/env.go
+++ b/libgo/go/cmd/go/internal/envcmd/env.go
@@ -26,6 +26,7 @@ import (
 	"cmd/go/internal/load"
 	"cmd/go/internal/modload"
 	"cmd/go/internal/work"
+	"cmd/internal/quoted"
 )
 
 var CmdEnv = &base.Command{
@@ -104,13 +105,13 @@ func MkEnv() []cfg.EnvVar {
 		env = append(env, cfg.EnvVar{Name: key, Value: val})
 	}
 
-	cc := cfg.DefaultCC(cfg.Goos, cfg.Goarch)
-	if env := strings.Fields(cfg.Getenv("CC")); len(env) > 0 {
-		cc = env[0]
+	cc := cfg.Getenv("CC")
+	if cc == "" {
+		cc = cfg.DefaultCC(cfg.Goos, cfg.Goarch)
 	}
-	cxx := cfg.DefaultCXX(cfg.Goos, cfg.Goarch)
-	if env := strings.Fields(cfg.Getenv("CXX")); len(env) > 0 {
-		cxx = env[0]
+	cxx := cfg.Getenv("CXX")
+	if cxx == "" {
+		cxx = cfg.DefaultCXX(cfg.Goos, cfg.Goarch)
 	}
 	env = append(env, cfg.EnvVar{Name: "AR", Value: envOr("AR", "ar")})
 	env = append(env, cfg.EnvVar{Name: "CC", Value: cc})
@@ -145,13 +146,17 @@ func findEnv(env []cfg.EnvVar, name string) string {
 // ExtraEnvVars returns environment variables that should not leak into child processes.
 func ExtraEnvVars() []cfg.EnvVar {
 	gomod := ""
+	modload.Init()
 	if modload.HasModRoot() {
-		gomod = filepath.Join(modload.ModRoot(), "go.mod")
+		gomod = modload.ModFilePath()
 	} else if modload.Enabled() {
 		gomod = os.DevNull
 	}
+	modload.InitWorkfile()
+	gowork := modload.WorkFilePath()
 	return []cfg.EnvVar{
 		{Name: "GOMOD", Value: gomod},
+		{Name: "GOWORK", Value: gowork},
 	}
 }
 
@@ -191,13 +196,13 @@ func argKey(arg string) string {
 
 func runEnv(ctx context.Context, cmd *base.Command, args []string) {
 	if *envJson && *envU {
-		base.Fatalf("go env: cannot use -json with -u")
+		base.Fatalf("go: cannot use -json with -u")
 	}
 	if *envJson && *envW {
-		base.Fatalf("go env: cannot use -json with -w")
+		base.Fatalf("go: cannot use -json with -w")
 	}
 	if *envU && *envW {
-		base.Fatalf("go env: cannot use -u with -w")
+		base.Fatalf("go: cannot use -u with -w")
 	}
 
 	// Handle 'go env -w' and 'go env -u' before calling buildcfg.Check,
@@ -275,7 +280,7 @@ func runEnv(ctx context.Context, cmd *base.Command, args []string) {
 func runEnvW(args []string) {
 	// Process and sanity-check command line.
 	if len(args) == 0 {
-		base.Fatalf("go env -w: no KEY=VALUE arguments given")
+		base.Fatalf("go: no KEY=VALUE arguments given")
 	}
 	osEnv := make(map[string]string)
 	for _, e := range cfg.OrigEnv {
@@ -287,14 +292,14 @@ func runEnvW(args []string) {
 	for _, arg := range args {
 		i := strings.Index(arg, "=")
 		if i < 0 {
-			base.Fatalf("go env -w: arguments must be KEY=VALUE: invalid argument: %s", arg)
+			base.Fatalf("go: arguments must be KEY=VALUE: invalid argument: %s", arg)
 		}
 		key, val := arg[:i], arg[i+1:]
 		if err := checkEnvWrite(key, val); err != nil {
-			base.Fatalf("go env -w: %v", err)
+			base.Fatalf("go: %v", err)
 		}
 		if _, ok := add[key]; ok {
-			base.Fatalf("go env -w: multiple values for key: %s", key)
+			base.Fatalf("go: multiple values for key: %s", key)
 		}
 		add[key] = val
 		if osVal := osEnv[key]; osVal != "" && osVal != val {
@@ -303,13 +308,13 @@ func runEnvW(args []string) {
 	}
 
 	if err := checkBuildConfig(add, nil); err != nil {
-		base.Fatalf("go env -w: %v", err)
+		base.Fatalf("go: %v", err)
 	}
 
 	gotmp, okGOTMP := add["GOTMPDIR"]
 	if okGOTMP {
 		if !filepath.IsAbs(gotmp) && gotmp != "" {
-			base.Fatalf("go env -w: GOTMPDIR must be an absolute path")
+			base.Fatalf("go: GOTMPDIR must be an absolute path")
 		}
 	}
 
@@ -319,18 +324,18 @@ func runEnvW(args []string) {
 func runEnvU(args []string) {
 	// Process and sanity-check command line.
 	if len(args) == 0 {
-		base.Fatalf("go env -u: no arguments given")
+		base.Fatalf("go: 'go env -u' requires an argument")
 	}
 	del := make(map[string]bool)
 	for _, arg := range args {
 		if err := checkEnvWrite(arg, ""); err != nil {
-			base.Fatalf("go env -u: %v", err)
+			base.Fatalf("go: %v", err)
 		}
 		del[arg] = true
 	}
 
 	if err := checkBuildConfig(nil, del); err != nil {
-		base.Fatalf("go env -u: %v", err)
+		base.Fatalf("go: %v", err)
 	}
 
 	updateEnvFile(nil, del)
@@ -414,7 +419,7 @@ func printEnvAsJSON(env []cfg.EnvVar) {
 	enc := json.NewEncoder(os.Stdout)
 	enc.SetIndent("", "\t")
 	if err := enc.Encode(m); err != nil {
-		base.Fatalf("go env -json: %s", err)
+		base.Fatalf("go: %s", err)
 	}
 }
 
@@ -429,7 +434,7 @@ func getOrigEnv(key string) string {
 
 func checkEnvWrite(key, val string) error {
 	switch key {
-	case "GOEXE", "GOGCCFLAGS", "GOHOSTARCH", "GOHOSTOS", "GOMOD", "GOTOOLDIR", "GOVERSION":
+	case "GOEXE", "GOGCCFLAGS", "GOHOSTARCH", "GOHOSTOS", "GOMOD", "GOWORK", "GOTOOLDIR", "GOVERSION":
 		return fmt.Errorf("%s cannot be modified", key)
 	case "GOENV":
 		return fmt.Errorf("%s can only be set using the OS environment", key)
@@ -457,10 +462,23 @@ func checkEnvWrite(key, val string) error {
 		if !filepath.IsAbs(val) && val != "" {
 			return fmt.Errorf("GOPATH entry is relative; must be absolute path: %q", val)
 		}
-	// Make sure CC and CXX are absolute paths
-	case "CC", "CXX", "GOMODCACHE":
-		if !filepath.IsAbs(val) && val != "" && val != filepath.Base(val) {
-			return fmt.Errorf("%s entry is relative; must be absolute path: %q", key, val)
+	case "GOMODCACHE":
+		if !filepath.IsAbs(val) && val != "" {
+			return fmt.Errorf("GOMODCACHE entry is relative; must be absolute path: %q", val)
+		}
+	case "CC", "CXX":
+		if val == "" {
+			break
+		}
+		args, err := quoted.Split(val)
+		if err != nil {
+			return fmt.Errorf("invalid %s: %v", key, err)
+		}
+		if len(args) == 0 {
+			return fmt.Errorf("%s entry cannot contain only space", key)
+		}
+		if !filepath.IsAbs(args[0]) && args[0] != filepath.Base(args[0]) {
+			return fmt.Errorf("%s entry is relative; must be absolute path: %q", key, args[0])
 		}
 	}
 
@@ -479,11 +497,11 @@ func checkEnvWrite(key, val string) error {
 func updateEnvFile(add map[string]string, del map[string]bool) {
 	file, err := cfg.EnvFile()
 	if file == "" {
-		base.Fatalf("go env: cannot find go env config: %v", err)
+		base.Fatalf("go: cannot find go env config: %v", err)
 	}
 	data, err := os.ReadFile(file)
 	if err != nil && (!os.IsNotExist(err) || len(add) == 0) {
-		base.Fatalf("go env: reading go env config: %v", err)
+		base.Fatalf("go: reading go env config: %v", err)
 	}
 
 	lines := strings.SplitAfter(string(data), "\n")
@@ -541,7 +559,7 @@ func updateEnvFile(add map[string]string, del map[string]bool) {
 		os.MkdirAll(filepath.Dir(file), 0777)
 		err = os.WriteFile(file, data, 0666)
 		if err != nil {
-			base.Fatalf("go env: writing go env config: %v", err)
+			base.Fatalf("go: writing go env config: %v", err)
 		}
 	}
 }
diff --git a/libgo/go/cmd/go/internal/fix/fix.go b/libgo/go/cmd/go/internal/fix/fix.go
index 988d45e71cc..d8ba353de65 100644
--- a/libgo/go/cmd/go/internal/fix/fix.go
+++ b/libgo/go/cmd/go/internal/fix/fix.go
@@ -11,27 +11,39 @@ import (
 	"cmd/go/internal/load"
 	"cmd/go/internal/modload"
 	"cmd/go/internal/str"
+	"cmd/go/internal/work"
 	"context"
 	"fmt"
+	"go/build"
 	"os"
 )
 
 var CmdFix = &base.Command{
-	Run:       runFix,
-	UsageLine: "go fix [packages]",
+	UsageLine: "go fix [-fix list] [packages]",
 	Short:     "update packages to use new APIs",
 	Long: `
 Fix runs the Go fix command on the packages named by the import paths.
 
+The -fix flag sets a comma-separated list of fixes to run.
+The default is all known fixes.
+(Its value is passed to 'go tool fix -r'.)
+
 For more about fix, see 'go doc cmd/fix'.
 For more about specifying packages, see 'go help packages'.
 
-To run fix with specific options, run 'go tool fix'.
+To run fix with other options, run 'go tool fix'.
 
 See also: go fmt, go vet.
 	`,
 }
 
+var fixes = CmdFix.Flag.String("fix", "", "comma-separated list of fixes to apply")
+
+func init() {
+	work.AddBuildFlags(CmdFix, work.DefaultBuildFlags)
+	CmdFix.Run = runFix // fix cycle
+}
+
 func runFix(ctx context.Context, cmd *base.Command, args []string) {
 	pkgs := load.PackagesAndErrors(ctx, load.PackageOpts{}, args)
 	w := 0
@@ -58,6 +70,16 @@ func runFix(ctx context.Context, cmd *base.Command, args []string) {
 		// the command only applies to this package,
 		// not to packages in subdirectories.
 		files := base.RelPaths(pkg.InternalAllGoFiles())
-		base.Run(str.StringList(cfg.BuildToolexec, base.Tool("fix"), files))
+		goVersion := ""
+		if pkg.Module != nil {
+			goVersion = "go" + pkg.Module.GoVersion
+		} else if pkg.Standard {
+			goVersion = build.Default.ReleaseTags[len(build.Default.ReleaseTags)-1]
+		}
+		var fixArg []string
+		if *fixes != "" {
+			fixArg = []string{"-r=" + *fixes}
+		}
+		base.Run(str.StringList(cfg.BuildToolexec, base.Tool("fix"), "-go="+goVersion, fixArg, files))
 	}
 }
diff --git a/libgo/go/cmd/go/internal/fmtcmd/fmt.go b/libgo/go/cmd/go/internal/fmtcmd/fmt.go
index 8a040087539..19656eab7fc 100644
--- a/libgo/go/cmd/go/internal/fmtcmd/fmt.go
+++ b/libgo/go/cmd/go/internal/fmtcmd/fmt.go
@@ -11,14 +11,12 @@ import (
 	"fmt"
 	"os"
 	"path/filepath"
-	"runtime"
-	"sync"
 
 	"cmd/go/internal/base"
 	"cmd/go/internal/cfg"
 	"cmd/go/internal/load"
 	"cmd/go/internal/modload"
-	"cmd/go/internal/str"
+	"cmd/internal/sys"
 )
 
 func init() {
@@ -53,18 +51,13 @@ See also: go fix, go vet.
 func runFmt(ctx context.Context, cmd *base.Command, args []string) {
 	printed := false
 	gofmt := gofmtPath()
-	procs := runtime.GOMAXPROCS(0)
-	var wg sync.WaitGroup
-	wg.Add(procs)
-	fileC := make(chan string, 2*procs)
-	for i := 0; i < procs; i++ {
-		go func() {
-			defer wg.Done()
-			for file := range fileC {
-				base.Run(str.StringList(gofmt, "-l", "-w", file))
-			}
-		}()
-	}
+
+	gofmtArgs := []string{gofmt, "-l", "-w"}
+	gofmtArgLen := len(gofmt) + len(" -l -w")
+
+	baseGofmtArgs := len(gofmtArgs)
+	baseGofmtArgLen := gofmtArgLen
+
 	for _, pkg := range load.PackagesAndErrors(ctx, load.PackageOpts{}, args) {
 		if modload.Enabled() && pkg.Module != nil && !pkg.Module.Main {
 			if !printed {
@@ -89,11 +82,18 @@ func runFmt(ctx context.Context, cmd *base.Command, args []string) {
 		// not to packages in subdirectories.
 		files := base.RelPaths(pkg.InternalAllGoFiles())
 		for _, file := range files {
-			fileC <- file
+			gofmtArgs = append(gofmtArgs, file)
+			gofmtArgLen += 1 + len(file) // plus separator
+			if gofmtArgLen >= sys.ExecArgLengthLimit {
+				base.Run(gofmtArgs)
+				gofmtArgs = gofmtArgs[:baseGofmtArgs]
+				gofmtArgLen = baseGofmtArgLen
+			}
 		}
 	}
-	close(fileC)
-	wg.Wait()
+	if len(gofmtArgs) > baseGofmtArgs {
+		base.Run(gofmtArgs)
+	}
 }
 
 func gofmtPath() string {
diff --git a/libgo/go/cmd/go/internal/fsys/fsys.go b/libgo/go/cmd/go/internal/fsys/fsys.go
index 0b806027e64..9a1bbf890e1 100644
--- a/libgo/go/cmd/go/internal/fsys/fsys.go
+++ b/libgo/go/cmd/go/internal/fsys/fsys.go
@@ -499,7 +499,7 @@ func (f fakeFile) Size() int64        { return f.real.Size() }
 func (f fakeFile) Mode() fs.FileMode  { return f.real.Mode() }
 func (f fakeFile) ModTime() time.Time { return f.real.ModTime() }
 func (f fakeFile) IsDir() bool        { return f.real.IsDir() }
-func (f fakeFile) Sys() interface{}   { return f.real.Sys() }
+func (f fakeFile) Sys() any           { return f.real.Sys() }
 
 // missingFile provides an fs.FileInfo for an overlaid file where the
 // destination file in the overlay doesn't exist. It returns zero values
@@ -512,7 +512,7 @@ func (f missingFile) Size() int64        { return 0 }
 func (f missingFile) Mode() fs.FileMode  { return fs.ModeIrregular }
 func (f missingFile) ModTime() time.Time { return time.Unix(0, 0) }
 func (f missingFile) IsDir() bool        { return false }
-func (f missingFile) Sys() interface{}   { return nil }
+func (f missingFile) Sys() any           { return nil }
 
 // fakeDir provides an fs.FileInfo implementation for directories that are
 // implicitly created by overlaid files. Each directory in the
@@ -524,7 +524,7 @@ func (f fakeDir) Size() int64        { return 0 }
 func (f fakeDir) Mode() fs.FileMode  { return fs.ModeDir | 0500 }
 func (f fakeDir) ModTime() time.Time { return time.Unix(0, 0) }
 func (f fakeDir) IsDir() bool        { return true }
-func (f fakeDir) Sys() interface{}   { return nil }
+func (f fakeDir) Sys() any           { return nil }
 
 // Glob is like filepath.Glob but uses the overlay file system.
 func Glob(pattern string) (matches []string, err error) {
diff --git a/libgo/go/cmd/go/internal/fsys/fsys_test.go b/libgo/go/cmd/go/internal/fsys/fsys_test.go
index 7f175c70311..c080c14987c 100644
--- a/libgo/go/cmd/go/internal/fsys/fsys_test.go
+++ b/libgo/go/cmd/go/internal/fsys/fsys_test.go
@@ -1,7 +1,6 @@
 package fsys
 
 import (
-	"cmd/go/internal/txtar"
 	"encoding/json"
 	"errors"
 	"fmt"
@@ -12,6 +11,8 @@ import (
 	"path/filepath"
 	"reflect"
 	"testing"
+
+	"golang.org/x/tools/txtar"
 )
 
 // initOverlay resets the overlay state to reflect the config.
diff --git a/libgo/go/cmd/go/internal/generate/generate.go b/libgo/go/cmd/go/internal/generate/generate.go
index 80ea32b4284..54ccfe78f24 100644
--- a/libgo/go/cmd/go/internal/generate/generate.go
+++ b/libgo/go/cmd/go/internal/generate/generate.go
@@ -38,7 +38,7 @@ Generate runs commands described by directives within existing
 files. Those commands can run any process but the intent is to
 create or update Go source files.
 
-Go generate is never run automatically by go build, go get, go test,
+Go generate is never run automatically by go build, go test,
 and so on. It must be run explicitly.
 
 Go generate scans the file for directives, which are lines of
@@ -408,7 +408,7 @@ var stop = fmt.Errorf("error in generation")
 // errorf logs an error message prefixed with the file and line number.
 // It then exits the program (with exit status 1) because generation stops
 // at the first error.
-func (g *Generator) errorf(format string, args ...interface{}) {
+func (g *Generator) errorf(format string, args ...any) {
 	fmt.Fprintf(os.Stderr, "%s:%d: %s\n", base.ShortPath(g.path), g.lineNum,
 		fmt.Sprintf(format, args...))
 	panic(stop)
diff --git a/libgo/go/cmd/go/internal/get/get.go b/libgo/go/cmd/go/internal/get/get.go
index 3c16dc3040f..8cf8fe6645f 100644
--- a/libgo/go/cmd/go/internal/get/get.go
+++ b/libgo/go/cmd/go/internal/get/get.go
@@ -114,16 +114,16 @@ func init() {
 func runGet(ctx context.Context, cmd *base.Command, args []string) {
 	if cfg.ModulesEnabled {
 		// Should not happen: main.go should install the separate module-enabled get code.
-		base.Fatalf("go get: modules not implemented")
+		base.Fatalf("go: modules not implemented")
 	}
 
 	work.BuildInit()
 
 	if *getF && !*getU {
-		base.Fatalf("go get: cannot use -f flag without -u")
+		base.Fatalf("go: cannot use -f flag without -u")
 	}
 	if *getInsecure {
-		base.Fatalf("go get: -insecure flag is no longer supported; use GOINSECURE instead")
+		base.Fatalf("go: -insecure flag is no longer supported; use GOINSECURE instead")
 	}
 
 	// Disable any prompting for passwords by Git itself.
@@ -214,18 +214,19 @@ func downloadPaths(patterns []string) []string {
 		// if the argument has no slash or refers to an existing file.
 		if strings.HasSuffix(arg, ".go") {
 			if !strings.Contains(arg, "/") {
-				base.Errorf("go get %s: arguments must be package or module paths", arg)
+				base.Errorf("go: %s: arguments must be package or module paths", arg)
 				continue
 			}
 			if fi, err := os.Stat(arg); err == nil && !fi.IsDir() {
-				base.Errorf("go get: %s exists as a file, but 'go get' requires package arguments", arg)
+				base.Errorf("go: %s exists as a file, but 'go get' requires package arguments", arg)
 			}
 		}
 	}
 	base.ExitIfErrors()
 
 	var pkgs []string
-	for _, m := range search.ImportPathsQuiet(patterns) {
+	noModRoots := []string{}
+	for _, m := range search.ImportPathsQuiet(patterns, noModRoots) {
 		if len(m.Pkgs) == 0 && strings.Contains(m.Pattern(), "...") {
 			pkgs = append(pkgs, m.Pattern())
 		} else {
@@ -315,7 +316,8 @@ func download(arg string, parent *load.Package, stk *load.ImportStack, mode int)
 		if wildcardOkay && strings.Contains(arg, "...") {
 			match := search.NewMatch(arg)
 			if match.IsLocal() {
-				match.MatchDirs()
+				noModRoots := []string{} // We're in gopath mode, so there are no modroots.
+				match.MatchDirs(noModRoots)
 				args = match.Dirs
 			} else {
 				match.MatchPackages()
@@ -415,10 +417,10 @@ func download(arg string, parent *load.Package, stk *load.ImportStack, mode int)
 // to make the first copy of or update a copy of the given package.
 func downloadPackage(p *load.Package) error {
 	var (
-		vcsCmd         *vcs.Cmd
-		repo, rootPath string
-		err            error
-		blindRepo      bool // set if the repo has unusual configuration
+		vcsCmd                  *vcs.Cmd
+		repo, rootPath, repoDir string
+		err                     error
+		blindRepo               bool // set if the repo has unusual configuration
 	)
 
 	// p can be either a real package, or a pseudo-package whose “import path” is
@@ -444,10 +446,19 @@ func downloadPackage(p *load.Package) error {
 
 	if p.Internal.Build.SrcRoot != "" {
 		// Directory exists. Look for checkout along path to src.
-		vcsCmd, rootPath, err = vcs.FromDir(p.Dir, p.Internal.Build.SrcRoot)
+		const allowNesting = false
+		repoDir, vcsCmd, err = vcs.FromDir(p.Dir, p.Internal.Build.SrcRoot, allowNesting)
 		if err != nil {
 			return err
 		}
+		if !str.HasFilePathPrefix(repoDir, p.Internal.Build.SrcRoot) {
+			panic(fmt.Sprintf("repository %q not in source root %q", repo, p.Internal.Build.SrcRoot))
+		}
+		rootPath = str.TrimFilePathPrefix(repoDir, p.Internal.Build.SrcRoot)
+		if err := vcs.CheckGOVCS(vcsCmd, rootPath); err != nil {
+			return err
+		}
+
 		repo = "<local>" // should be unused; make distinctive
 
 		// Double-check where it came from.
diff --git a/libgo/go/cmd/go/internal/help/help.go b/libgo/go/cmd/go/internal/help/help.go
index 7a730fc8eb8..2a07d2423bd 100644
--- a/libgo/go/cmd/go/internal/help/help.go
+++ b/libgo/go/cmd/go/internal/help/help.go
@@ -162,7 +162,7 @@ func (w *errWriter) Write(b []byte) (int, error) {
 }
 
 // tmpl executes the given template text on data, writing the result to w.
-func tmpl(w io.Writer, text string, data interface{}) {
+func tmpl(w io.Writer, text string, data any) {
 	t := template.New("top")
 	t.Funcs(template.FuncMap{"trim": strings.TrimSpace, "capitalize": capitalize})
 	template.Must(t.Parse(text))
diff --git a/libgo/go/cmd/go/internal/help/helpdoc.go b/libgo/go/cmd/go/internal/help/helpdoc.go
index 490ff1fb7cf..7dc066cfbad 100644
--- a/libgo/go/cmd/go/internal/help/helpdoc.go
+++ b/libgo/go/cmd/go/internal/help/helpdoc.go
@@ -592,6 +592,10 @@ Architecture-specific environment variables:
 	GO386
 		For GOARCH=386, how to implement floating point instructions.
 		Valid values are sse2 (default), softfloat.
+	GOAMD64
+		For GOARCH=amd64, the microarchitecture level for which to compile.
+		Valid values are v1 (default), v2, v3, v4.
+		See https://golang.org/wiki/MinimumRequirements#amd64
 	GOMIPS
 		For GOARCH=mips{,le}, whether to use floating point instructions.
 		Valid values are hardfloat (default), softfloat.
@@ -771,6 +775,13 @@ The go command also caches successful package test results.
 See 'go help test' for details. Running 'go clean -testcache' removes
 all cached test results (but not cached build results).
 
+The go command also caches values used in fuzzing with 'go test -fuzz',
+specifically, values that expanded code coverage when passed to a
+fuzz function. These values are not used for regular building and
+testing, but they're stored in a subdirectory of the build cache.
+Running 'go clean -fuzzcache' removes all cached fuzzing values.
+This may make fuzzing less effective, temporarily.
+
 The GODEBUG environment variable can enable printing of debugging
 information about the state of the cache:
 
diff --git a/libgo/go/cmd/go/internal/imports/build.go b/libgo/go/cmd/go/internal/imports/build.go
index 50aeabc578c..ff6bea6777d 100644
--- a/libgo/go/cmd/go/internal/imports/build.go
+++ b/libgo/go/cmd/go/internal/imports/build.go
@@ -2,17 +2,51 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// Copied from Go distribution src/go/build/build.go, syslist.go
+// Copied from Go distribution src/go/build/build.go, syslist.go.
+// That package does not export the ability to process raw file data,
+// although we could fake it with an appropriate build.Context
+// and a lot of unwrapping.
+// More importantly, that package does not implement the tags["*"]
+// special case, in which both tag and !tag are considered to be true
+// for essentially all tags (except "ignore").
+//
+// If we added this API to go/build directly, we wouldn't need this
+// file anymore, but this API is not terribly general-purpose and we
+// don't really want to commit to any public form of it, nor do we
+// want to move the core parts of go/build into a top-level internal package.
+// These details change very infrequently, so the copy is fine.
 
 package imports
 
 import (
 	"bytes"
+	"errors"
+	"fmt"
+	"go/build/constraint"
 	"strings"
 	"unicode"
 )
 
-var slashslash = []byte("//")
+var (
+	bSlashSlash = []byte("//")
+	bStarSlash  = []byte("*/")
+	bSlashStar  = []byte("/*")
+	bPlusBuild  = []byte("+build")
+
+	goBuildComment = []byte("//go:build")
+
+	errGoBuildWithoutBuild = errors.New("//go:build comment without // +build comment")
+	errMultipleGoBuild     = errors.New("multiple //go:build comments")
+)
+
+func isGoBuildComment(line []byte) bool {
+	if !bytes.HasPrefix(line, goBuildComment) {
+		return false
+	}
+	line = bytes.TrimSpace(line)
+	rest := line[len(goBuildComment):]
+	return len(rest) == 0 || len(bytes.TrimSpace(rest)) < len(rest)
+}
 
 // ShouldBuild reports whether it is okay to use this file,
 // The rule is that in the file's leading run of // comments
@@ -34,10 +68,61 @@ var slashslash = []byte("//")
 // in any build.
 //
 func ShouldBuild(content []byte, tags map[string]bool) bool {
-	// Pass 1. Identify leading run of // comments and blank lines,
+	// Identify leading run of // comments and blank lines,
 	// which must be followed by a blank line.
+	// Also identify any //go:build comments.
+	content, goBuild, _, err := parseFileHeader(content)
+	if err != nil {
+		return false
+	}
+
+	// If //go:build line is present, it controls.
+	// Otherwise fall back to +build processing.
+	var shouldBuild bool
+	switch {
+	case goBuild != nil:
+		x, err := constraint.Parse(string(goBuild))
+		if err != nil {
+			return false
+		}
+		shouldBuild = eval(x, tags, true)
+
+	default:
+		shouldBuild = true
+		p := content
+		for len(p) > 0 {
+			line := p
+			if i := bytes.IndexByte(line, '\n'); i >= 0 {
+				line, p = line[:i], p[i+1:]
+			} else {
+				p = p[len(p):]
+			}
+			line = bytes.TrimSpace(line)
+			if !bytes.HasPrefix(line, bSlashSlash) || !bytes.Contains(line, bPlusBuild) {
+				continue
+			}
+			text := string(line)
+			if !constraint.IsPlusBuild(text) {
+				continue
+			}
+			if x, err := constraint.Parse(text); err == nil {
+				if !eval(x, tags, true) {
+					shouldBuild = false
+				}
+			}
+		}
+	}
+
+	return shouldBuild
+}
+
+func parseFileHeader(content []byte) (trimmed, goBuild []byte, sawBinaryOnly bool, err error) {
 	end := 0
 	p := content
+	ended := false       // found non-blank, non-// line, so stopped accepting // +build lines
+	inSlashStar := false // in /* */ comment
+
+Lines:
 	for len(p) > 0 {
 		line := p
 		if i := bytes.IndexByte(line, '\n'); i >= 0 {
@@ -46,78 +131,61 @@ func ShouldBuild(content []byte, tags map[string]bool) bool {
 			p = p[len(p):]
 		}
 		line = bytes.TrimSpace(line)
-		if len(line) == 0 { // Blank line
+		if len(line) == 0 && !ended { // Blank line
+			// Remember position of most recent blank line.
+			// When we find the first non-blank, non-// line,
+			// this "end" position marks the latest file position
+			// where a // +build line can appear.
+			// (It must appear _before_ a blank line before the non-blank, non-// line.
+			// Yes, that's confusing, which is part of why we moved to //go:build lines.)
+			// Note that ended==false here means that inSlashStar==false,
+			// since seeing a /* would have set ended==true.
 			end = len(content) - len(p)
-			continue
+			continue Lines
 		}
-		if !bytes.HasPrefix(line, slashslash) { // Not comment line
-			break
+		if !bytes.HasPrefix(line, bSlashSlash) { // Not comment line
+			ended = true
 		}
-	}
-	content = content[:end]
 
-	// Pass 2.  Process each line in the run.
-	p = content
-	allok := true
-	for len(p) > 0 {
-		line := p
-		if i := bytes.IndexByte(line, '\n'); i >= 0 {
-			line, p = line[:i], p[i+1:]
-		} else {
-			p = p[len(p):]
-		}
-		line = bytes.TrimSpace(line)
-		if !bytes.HasPrefix(line, slashslash) {
-			continue
+		if !inSlashStar && isGoBuildComment(line) {
+			if goBuild != nil {
+				return nil, nil, false, errMultipleGoBuild
+			}
+			goBuild = line
 		}
-		line = bytes.TrimSpace(line[len(slashslash):])
-		if len(line) > 0 && line[0] == '+' {
-			// Looks like a comment +line.
-			f := strings.Fields(string(line))
-			if f[0] == "+build" {
-				ok := false
-				for _, tok := range f[1:] {
-					if matchTags(tok, tags) {
-						ok = true
-					}
-				}
-				if !ok {
-					allok = false
+
+	Comments:
+		for len(line) > 0 {
+			if inSlashStar {
+				if i := bytes.Index(line, bStarSlash); i >= 0 {
+					inSlashStar = false
+					line = bytes.TrimSpace(line[i+len(bStarSlash):])
+					continue Comments
 				}
+				continue Lines
 			}
+			if bytes.HasPrefix(line, bSlashSlash) {
+				continue Lines
+			}
+			if bytes.HasPrefix(line, bSlashStar) {
+				inSlashStar = true
+				line = bytes.TrimSpace(line[len(bSlashStar):])
+				continue Comments
+			}
+			// Found non-comment text.
+			break Lines
 		}
 	}
 
-	return allok
-}
-
-// matchTags reports whether the name is one of:
-//
-//	tag (if tags[tag] is true)
-//	!tag (if tags[tag] is false)
-//	a comma-separated list of any of these
-//
-func matchTags(name string, tags map[string]bool) bool {
-	if name == "" {
-		return false
-	}
-	if i := strings.Index(name, ","); i >= 0 {
-		// comma-separated list
-		ok1 := matchTags(name[:i], tags)
-		ok2 := matchTags(name[i+1:], tags)
-		return ok1 && ok2
-	}
-	if strings.HasPrefix(name, "!!") { // bad syntax, reject always
-		return false
-	}
-	if strings.HasPrefix(name, "!") { // negation
-		return len(name) > 1 && matchTag(name[1:], tags, false)
-	}
-	return matchTag(name, tags, true)
+	return content[:end], goBuild, sawBinaryOnly, nil
 }
 
-// matchTag reports whether the tag name is valid and satisfied by tags[name]==want.
-func matchTag(name string, tags map[string]bool, want bool) bool {
+// matchTag reports whether the tag name is valid and tags[name] is true.
+// As a special case, if tags["*"] is true and name is not empty or ignore,
+// then matchTag will return prefer instead of the actual answer,
+// which allows the caller to pretend in that case that most tags are
+// both true and false.
+func matchTag(name string, tags map[string]bool, prefer bool) bool {
 	// Tags must be letters, digits, underscores or dots.
 	// Unlike in Go identifiers, all digits are fine (e.g., "386").
 	for _, c := range name {
@@ -131,7 +199,7 @@ func matchTag(name string, tags map[string]bool, want bool) bool {
 		// if we put * in the tags map then all tags
 		// except "ignore" are considered both present and not
 		// (so we return true no matter how 'want' is set).
-		return true
+		return prefer
 	}
 
 	have := tags[name]
@@ -144,7 +212,25 @@ func matchTag(name string, tags map[string]bool, want bool) bool {
 	if name == "darwin" {
 		have = have || tags["ios"]
 	}
-	return have == want
+	return have
+}
+
+// eval is like
+//	x.Eval(func(tag string) bool { return matchTag(tag, tags) })
+// except that it implements the special case for tags["*"] meaning
+// all tags are both true and false at the same time.
+func eval(x constraint.Expr, tags map[string]bool, prefer bool) bool {
+	switch x := x.(type) {
+	case *constraint.TagExpr:
+		return matchTag(x.Tag, tags, prefer)
+	case *constraint.NotExpr:
+		return !eval(x.X, tags, !prefer)
+	case *constraint.AndExpr:
+		return eval(x.X, tags, prefer) && eval(x.Y, tags, prefer)
+	case *constraint.OrExpr:
+		return eval(x.X, tags, prefer) || eval(x.Y, tags, prefer)
+	}
+	panic(fmt.Sprintf("unexpected constraint expression %T", x))
 }
 
 // MatchFile returns false if the name contains a $GOOS or $GOARCH
diff --git a/libgo/go/cmd/go/internal/imports/scan_test.go b/libgo/go/cmd/go/internal/imports/scan_test.go
index 2d245ee7872..7e69c56513a 100644
--- a/libgo/go/cmd/go/internal/imports/scan_test.go
+++ b/libgo/go/cmd/go/internal/imports/scan_test.go
@@ -33,7 +33,7 @@ func TestScan(t *testing.T) {
 		}
 		if p == "net/http" {
 			// A test import but not an import
-			t.Errorf("json reported as importing encoding/binary but does not")
+			t.Errorf("json reported as importing net/http but does not")
 		}
 	}
 	if !foundBase64 {
diff --git a/libgo/go/cmd/go/internal/imports/testdata/android/e.go b/libgo/go/cmd/go/internal/imports/testdata/android/e.go
index d9b2db769b5..f1b9c888c2c 100644
--- a/libgo/go/cmd/go/internal/imports/testdata/android/e.go
+++ b/libgo/go/cmd/go/internal/imports/testdata/android/e.go
@@ -1,3 +1,4 @@
+//go:build android
 // +build android
 
 package android
diff --git a/libgo/go/cmd/go/internal/imports/testdata/android/f.go b/libgo/go/cmd/go/internal/imports/testdata/android/f.go
index 281e4dd6b98..bb0ff7b73f6 100644
--- a/libgo/go/cmd/go/internal/imports/testdata/android/f.go
+++ b/libgo/go/cmd/go/internal/imports/testdata/android/f.go
@@ -1,3 +1,4 @@
+//go:build linux
 // +build linux
 
 package android
diff --git a/libgo/go/cmd/go/internal/imports/testdata/android/g.go b/libgo/go/cmd/go/internal/imports/testdata/android/g.go
index 66a789c0ada..ee19424890a 100644
--- a/libgo/go/cmd/go/internal/imports/testdata/android/g.go
+++ b/libgo/go/cmd/go/internal/imports/testdata/android/g.go
@@ -1,3 +1,4 @@
+//go:build !android
 // +build !android
 
 package android
diff --git a/libgo/go/cmd/go/internal/imports/testdata/illumos/e.go b/libgo/go/cmd/go/internal/imports/testdata/illumos/e.go
index 5e1ed3cb9de..fddf2c42990 100644
--- a/libgo/go/cmd/go/internal/imports/testdata/illumos/e.go
+++ b/libgo/go/cmd/go/internal/imports/testdata/illumos/e.go
@@ -1,3 +1,4 @@
+//go:build illumos
 // +build illumos
 
 package illumos
diff --git a/libgo/go/cmd/go/internal/imports/testdata/illumos/f.go b/libgo/go/cmd/go/internal/imports/testdata/illumos/f.go
index f3e3f728bce..4b6d528e4c2 100644
--- a/libgo/go/cmd/go/internal/imports/testdata/illumos/f.go
+++ b/libgo/go/cmd/go/internal/imports/testdata/illumos/f.go
@@ -1,3 +1,4 @@
+//go:build solaris
 // +build solaris
 
 package illumos
diff --git a/libgo/go/cmd/go/internal/imports/testdata/illumos/g.go b/libgo/go/cmd/go/internal/imports/testdata/illumos/g.go
index b30f1eb4037..1bf826b8151 100644
--- a/libgo/go/cmd/go/internal/imports/testdata/illumos/g.go
+++ b/libgo/go/cmd/go/internal/imports/testdata/illumos/g.go
@@ -1,3 +1,4 @@
+//go:build !illumos
 // +build !illumos
 
 package illumos
diff --git a/libgo/go/cmd/go/internal/imports/testdata/star/x1.go b/libgo/go/cmd/go/internal/imports/testdata/star/x1.go
index 6a9594aed03..eaaea979e9d 100644
--- a/libgo/go/cmd/go/internal/imports/testdata/star/x1.go
+++ b/libgo/go/cmd/go/internal/imports/testdata/star/x1.go
@@ -1,8 +1,5 @@
-// +build blahblh
-// +build linux
-// +build !linux
-// +build windows
-// +build darwin
+//go:build blahblh && linux && !linux && windows && darwin
+// +build blahblh,linux,!linux,windows,darwin
 
 package x
 
diff --git a/libgo/go/cmd/go/internal/list/list.go b/libgo/go/cmd/go/internal/list/list.go
index 7cb9ec6d949..d9a7078ccf2 100644
--- a/libgo/go/cmd/go/internal/list/list.go
+++ b/libgo/go/cmd/go/internal/list/list.go
@@ -316,6 +316,7 @@ For more about modules, see https://golang.org/ref/mod.
 func init() {
 	CmdList.Run = runList // break init cycle
 	work.AddBuildFlags(CmdList, work.DefaultBuildFlags)
+	base.AddWorkfileFlag(&CmdList.Flag)
 }
 
 var (
@@ -336,6 +337,8 @@ var (
 var nl = []byte{'\n'}
 
 func runList(ctx context.Context, cmd *base.Command, args []string) {
+	modload.InitWorkfile()
+
 	if *listFmt != "" && *listJson == true {
 		base.Fatalf("go list -f cannot be used with -json")
 	}
@@ -355,9 +358,9 @@ func runList(ctx context.Context, cmd *base.Command, args []string) {
 		}
 	}
 
-	var do func(interface{})
+	var do func(any)
 	if *listJson {
-		do = func(x interface{}) {
+		do = func(x any) {
 			b, err := json.MarshalIndent(x, "", "\t")
 			if err != nil {
 				out.Flush()
@@ -383,7 +386,7 @@ func runList(ctx context.Context, cmd *base.Command, args []string) {
 		if err != nil {
 			base.Fatalf("%s", err)
 		}
-		do = func(x interface{}) {
+		do = func(x any) {
 			if err := tmpl.Execute(out, x); err != nil {
 				out.Flush()
 				base.Fatalf("%s", err)
@@ -424,12 +427,12 @@ func runList(ctx context.Context, cmd *base.Command, args []string) {
 		}
 
 		if modload.Init(); !modload.Enabled() {
-			base.Fatalf("go list -m: not using modules")
+			base.Fatalf("go: list -m cannot be used with GO111MODULE=off")
 		}
 
 		modload.LoadModFile(ctx) // Sets cfg.BuildMod as a side-effect.
 		if cfg.BuildMod == "vendor" {
-			const actionDisabledFormat = "go list -m: can't %s using the vendor directory\n\t(Use -mod=mod or -mod=readonly to bypass.)"
+			const actionDisabledFormat = "go: can't %s using the vendor directory\n\t(Use -mod=mod or -mod=readonly to bypass.)"
 
 			if *listVersions {
 				base.Fatalf(actionDisabledFormat, "determine available versions")
@@ -468,11 +471,11 @@ func runList(ctx context.Context, cmd *base.Command, args []string) {
 		if !*listE {
 			for _, m := range mods {
 				if m.Error != nil {
-					base.Errorf("go list -m: %v", m.Error.Err)
+					base.Errorf("go: %v", m.Error.Err)
 				}
 			}
 			if err != nil {
-				base.Errorf("go list -m: %v", err)
+				base.Errorf("go: %v", err)
 			}
 			base.ExitIfErrors()
 		}
@@ -708,7 +711,7 @@ func runList(ctx context.Context, cmd *base.Command, args []string) {
 			}
 			rmods, err := modload.ListModules(ctx, args, mode)
 			if err != nil && !*listE {
-				base.Errorf("go list -retracted: %v", err)
+				base.Errorf("go: %v", err)
 			}
 			for i, arg := range args {
 				rmod := rmods[i]
diff --git a/libgo/go/cmd/go/internal/load/flag.go b/libgo/go/cmd/go/internal/load/flag.go
index 440cb861344..de079decdf2 100644
--- a/libgo/go/cmd/go/internal/load/flag.go
+++ b/libgo/go/cmd/go/internal/load/flag.go
@@ -6,7 +6,7 @@ package load
 
 import (
 	"cmd/go/internal/base"
-	"cmd/go/internal/str"
+	"cmd/internal/quoted"
 	"fmt"
 	"strings"
 )
@@ -22,6 +22,7 @@ var (
 // that allows specifying different effective flags for different packages.
 // See 'go help build' for more details about per-package flags.
 type PerPackageFlag struct {
+	raw     string
 	present bool
 	values  []ppfValue
 }
@@ -39,6 +40,7 @@ func (f *PerPackageFlag) Set(v string) error {
 
 // set is the implementation of Set, taking a cwd (current working directory) for easier testing.
 func (f *PerPackageFlag) set(v, cwd string) error {
+	f.raw = v
 	f.present = true
 	match := func(p *Package) bool { return p.Internal.CmdlinePkg || p.Internal.CmdlineFiles } // default predicate with no pattern
 	// For backwards compatibility with earlier flag splitting, ignore spaces around flags.
@@ -61,7 +63,7 @@ func (f *PerPackageFlag) set(v, cwd string) error {
 		match = MatchPackage(pattern, cwd)
 		v = v[i+1:]
 	}
-	flags, err := str.SplitQuotedFields(v)
+	flags, err := quoted.Split(v)
 	if err != nil {
 		return err
 	}
@@ -72,9 +74,7 @@ func (f *PerPackageFlag) set(v, cwd string) error {
 	return nil
 }
 
-// String is required to implement flag.Value.
-// It is not used, because cmd/go never calls flag.PrintDefaults.
-func (f *PerPackageFlag) String() string { return "<PerPackageFlag>" }
+func (f *PerPackageFlag) String() string { return f.raw }
 
 // Present reports whether the flag appeared on the command line.
 func (f *PerPackageFlag) Present() bool {
diff --git a/libgo/go/cmd/go/internal/load/pkg.go b/libgo/go/cmd/go/internal/load/pkg.go
index c085fcbbf80..67b359d19d2 100644
--- a/libgo/go/cmd/go/internal/load/pkg.go
+++ b/libgo/go/cmd/go/internal/load/pkg.go
@@ -21,9 +21,11 @@ import (
 	pathpkg "path"
 	"path/filepath"
 	"runtime"
+	"runtime/debug"
 	"sort"
 	"strconv"
 	"strings"
+	"time"
 	"unicode"
 	"unicode/utf8"
 
@@ -38,6 +40,7 @@ import (
 	"cmd/go/internal/search"
 	"cmd/go/internal/str"
 	"cmd/go/internal/trace"
+	"cmd/go/internal/vcs"
 	"cmd/internal/sys"
 
 	"golang.org/x/mod/modfile"
@@ -203,6 +206,7 @@ type PackageInternal struct {
 	Local             bool                 // imported via local path (./ or ../)
 	LocalPrefix       string               // interpret ./ and ../ imports relative to this prefix
 	ExeName           string               // desired name for temporary executable
+	FuzzInstrument    bool                 // package should be instrumented for fuzzing
 	CoverMode         string               // preprocess Go source files with the coverage tool in this mode
 	CoverVars         map[string]*CoverVar // variables created by coverage analysis
 	OmitDebug         bool                 // tell linker not to write debug information
@@ -494,7 +498,7 @@ type importError struct {
 	err        error // created with fmt.Errorf
 }
 
-func ImportErrorf(path, format string, args ...interface{}) ImportPathError {
+func ImportErrorf(path, format string, args ...any) ImportPathError {
 	err := &importError{importPath: path, err: fmt.Errorf(format, args...)}
 	if errStr := err.Error(); !strings.Contains(errStr, path) {
 		panic(fmt.Sprintf("path %q not in error %q", path, errStr))
@@ -585,10 +589,10 @@ func ClearPackageCachePartial(args []string) {
 			delete(packageCache, arg)
 		}
 	}
-	resolvedImportCache.DeleteIf(func(key interface{}) bool {
+	resolvedImportCache.DeleteIf(func(key any) bool {
 		return shouldDelete[key.(importSpec).path]
 	})
-	packageDataCache.DeleteIf(func(key interface{}) bool {
+	packageDataCache.DeleteIf(func(key any) bool {
 		return shouldDelete[key.(string)]
 	})
 }
@@ -601,7 +605,7 @@ func ReloadPackageNoFlags(arg string, stk *ImportStack) *Package {
 	p := packageCache[arg]
 	if p != nil {
 		delete(packageCache, arg)
-		resolvedImportCache.DeleteIf(func(key interface{}) bool {
+		resolvedImportCache.DeleteIf(func(key any) bool {
 			return key.(importSpec).path == p.ImportPath
 		})
 		packageDataCache.Delete(p.ImportPath)
@@ -813,7 +817,7 @@ func loadPackageData(ctx context.Context, path, parentPath, parentDir, parentRoo
 		parentIsStd: parentIsStd,
 		mode:        mode,
 	}
-	r := resolvedImportCache.Do(importKey, func() interface{} {
+	r := resolvedImportCache.Do(importKey, func() any {
 		var r resolvedImport
 		if build.IsLocalImport(path) {
 			r.dir = filepath.Join(parentDir, path)
@@ -840,7 +844,7 @@ func loadPackageData(ctx context.Context, path, parentPath, parentDir, parentRoo
 
 	// Load the package from its directory. If we already found the package's
 	// directory when resolving its import path, use that.
-	data := packageDataCache.Do(r.path, func() interface{} {
+	data := packageDataCache.Do(r.path, func() any {
 		loaded = true
 		var data packageData
 		if r.dir != "" {
@@ -1059,7 +1063,7 @@ func cleanImport(path string) string {
 var isDirCache par.Cache
 
 func isDir(path string) bool {
-	return isDirCache.Do(path, func() interface{} {
+	return isDirCache.Do(path, func() any {
 		fi, err := fsys.Stat(path)
 		return err == nil && fi.IsDir()
 	}).(bool)
@@ -1187,7 +1191,7 @@ var (
 
 // goModPath returns the module path in the go.mod in dir, if any.
 func goModPath(dir string) (path string) {
-	return goModPathCache.Do(dir, func() interface{} {
+	return goModPathCache.Do(dir, func() any {
 		data, err := os.ReadFile(filepath.Join(dir, "go.mod"))
 		if err != nil {
 			return ""
@@ -1456,9 +1460,9 @@ func disallowInternal(ctx context.Context, srcDir string, importer *Package, imp
 			// The importer is a list of command-line files.
 			// Pretend that the import path is the import path of the
 			// directory containing them.
-			// If the directory is outside the main module, this will resolve to ".",
+			// If the directory is outside the main modules, this will resolve to ".",
 			// which is not a prefix of any valid module.
-			importerPath = modload.DirImportPath(ctx, importer.Dir)
+			importerPath, _ = modload.MainModules.DirImportPath(ctx, importer.Dir)
 		}
 		parentOfInternal := p.ImportPath[:i]
 		if str.HasPathPrefix(importerPath, parentOfInternal) {
@@ -1628,6 +1632,7 @@ var cgoSyscallExclude = map[string]bool{
 	"runtime/cgo":  true,
 	"runtime/race": true,
 	"runtime/msan": true,
+	"runtime/asan": true,
 }
 
 var foldPath = make(map[string]string)
@@ -1683,9 +1688,10 @@ func (p *Package) DefaultExecName() string {
 func (p *Package) load(ctx context.Context, opts PackageOpts, path string, stk *ImportStack, importPos []token.Position, bp *build.Package, err error) {
 	p.copyBuild(opts, bp)
 
-	// The localPrefix is the path we interpret ./ imports relative to.
+	// The localPrefix is the path we interpret ./ imports relative to,
+	// if we support them at all (not in module mode!).
 	// Synthesized main packages sometimes override this.
-	if p.Internal.Local {
+	if p.Internal.Local && !cfg.ModulesEnabled {
 		p.Internal.LocalPrefix = dirToImportPath(p.Dir)
 	}
 
@@ -1925,9 +1931,8 @@ func (p *Package) load(ctx context.Context, opts PackageOpts, path string, stk *
 	}
 	p.Internal.Imports = imports
 	p.collectDeps()
-
-	if cfg.ModulesEnabled && p.Error == nil && p.Name == "main" && len(p.DepsErrors) == 0 {
-		p.Internal.BuildInfo = modload.PackageBuildInfo(pkgPath, p.Deps)
+	if p.Error == nil && p.Name == "main" && len(p.DepsErrors) == 0 {
+		p.setBuildInfo()
 	}
 
 	// unsafe is a fake package.
@@ -2018,13 +2023,18 @@ func resolveEmbed(pkgdir string, patterns []string) (files []string, pmap map[st
 	for _, pattern = range patterns {
 		pid++
 
+		glob := pattern
+		all := strings.HasPrefix(pattern, "all:")
+		if all {
+			glob = pattern[len("all:"):]
+		}
 		// Check pattern is valid for //go:embed.
-		if _, err := path.Match(pattern, ""); err != nil || !validEmbedPattern(pattern) {
+		if _, err := path.Match(glob, ""); err != nil || !validEmbedPattern(glob) {
 			return nil, nil, fmt.Errorf("invalid pattern syntax")
 		}
 
 		// Glob to find matches.
-		match, err := fsys.Glob(pkgdir + string(filepath.Separator) + filepath.FromSlash(pattern))
+		match, err := fsys.Glob(pkgdir + string(filepath.Separator) + filepath.FromSlash(glob))
 		if err != nil {
 			return nil, nil, err
 		}
@@ -2087,7 +2097,7 @@ func resolveEmbed(pkgdir string, patterns []string) (files []string, pmap map[st
 					}
 					rel := filepath.ToSlash(path[len(pkgdir)+1:])
 					name := info.Name()
-					if path != file && (isBadEmbedName(name) || name[0] == '.' || name[0] == '_') {
+					if path != file && (isBadEmbedName(name) || ((name[0] == '.' || name[0] == '_') && !all)) {
 						// Ignore bad names, assuming they won't go into modules.
 						// Also avoid hidden files that user may not know about.
 						// See golang.org/issue/42328.
@@ -2199,6 +2209,229 @@ func (p *Package) collectDeps() {
 	}
 }
 
+// vcsStatusCache maps repository directories (string)
+// to their VCS information (vcsStatusError).
+var vcsStatusCache par.Cache
+
+// setBuildInfo gathers build information, formats it as a string to be
+// embedded in the binary, then sets p.Internal.BuildInfo to that string.
+// setBuildInfo should only be called on a main package with no errors.
+//
+// This information can be retrieved using debug.ReadBuildInfo.
+//
+// Note that the GoVersion field is not set here to avoid encoding it twice.
+// It is stored separately in the binary, mostly for historical reasons.
+func (p *Package) setBuildInfo() {
+	// TODO: build and vcs information is not embedded for executables in GOROOT.
+	// cmd/dist uses -gcflags=all= -ldflags=all= by default, which means these
+	// executables always appear stale unless the user sets the same flags.
+	// Perhaps it's safe to omit those flags when GO_GCFLAGS and GO_LDFLAGS
+	// are not set?
+	setPkgErrorf := func(format string, args ...any) {
+		if p.Error == nil {
+			p.Error = &PackageError{Err: fmt.Errorf(format, args...)}
+		}
+	}
+
+	var debugModFromModinfo func(*modinfo.ModulePublic) *debug.Module
+	debugModFromModinfo = func(mi *modinfo.ModulePublic) *debug.Module {
+		dm := &debug.Module{
+			Path:    mi.Path,
+			Version: mi.Version,
+		}
+		if mi.Replace != nil {
+			dm.Replace = debugModFromModinfo(mi.Replace)
+		} else {
+			dm.Sum = modfetch.Sum(module.Version{Path: mi.Path, Version: mi.Version})
+		}
+		return dm
+	}
+
+	var main debug.Module
+	if p.Module != nil {
+		main = *debugModFromModinfo(p.Module)
+	}
+
+	visited := make(map[*Package]bool)
+	mdeps := make(map[module.Version]*debug.Module)
+	var q []*Package
+	q = append(q, p.Internal.Imports...)
+	for len(q) > 0 {
+		p1 := q[0]
+		q = q[1:]
+		if visited[p1] {
+			continue
+		}
+		visited[p1] = true
+		if p1.Module != nil {
+			m := module.Version{Path: p1.Module.Path, Version: p1.Module.Version}
+			if p1.Module.Path != main.Path && mdeps[m] == nil {
+				mdeps[m] = debugModFromModinfo(p1.Module)
+			}
+		}
+		q = append(q, p1.Internal.Imports...)
+	}
+	sortedMods := make([]module.Version, 0, len(mdeps))
+	for mod := range mdeps {
+		sortedMods = append(sortedMods, mod)
+	}
+	module.Sort(sortedMods)
+	deps := make([]*debug.Module, len(sortedMods))
+	for i, mod := range sortedMods {
+		deps[i] = mdeps[mod]
+	}
+
+	pkgPath := p.ImportPath
+	if p.Internal.CmdlineFiles {
+		pkgPath = "command-line-arguments"
+	}
+	info := &debug.BuildInfo{
+		Path: pkgPath,
+		Main: main,
+		Deps: deps,
+	}
+	appendSetting := func(key, value string) {
+		value = strings.ReplaceAll(value, "\n", " ") // make value safe
+		info.Settings = append(info.Settings, debug.BuildSetting{Key: key, Value: value})
+	}
+
+	// Add command-line flags relevant to the build.
+	// This is informational, not an exhaustive list.
+	// Please keep the list sorted.
+	if !p.Standard {
+		if cfg.BuildASan {
+			appendSetting("-asan", "true")
+		}
+		if BuildAsmflags.present {
+			appendSetting("-asmflags", BuildAsmflags.String())
+		}
+		appendSetting("-compiler", cfg.BuildContext.Compiler)
+		if BuildGccgoflags.present && cfg.BuildContext.Compiler == "gccgo" {
+			appendSetting("-gccgoflags", BuildGccgoflags.String())
+		}
+		if BuildGcflags.present && cfg.BuildContext.Compiler == "gc" {
+			appendSetting("-gcflags", BuildGcflags.String())
+		}
+		if BuildLdflags.present {
+			appendSetting("-ldflags", BuildLdflags.String())
+		}
+		if cfg.BuildMSan {
+			appendSetting("-msan", "true")
+		}
+		if cfg.BuildRace {
+			appendSetting("-race", "true")
+		}
+		if tags := cfg.BuildContext.BuildTags; len(tags) > 0 {
+			appendSetting("-tags", strings.Join(tags, ","))
+		}
+		cgo := "0"
+		if cfg.BuildContext.CgoEnabled {
+			cgo = "1"
+		}
+		appendSetting("CGO_ENABLED", cgo)
+		if cfg.BuildContext.CgoEnabled {
+			for _, name := range []string{"CGO_CFLAGS", "CGO_CPPFLAGS", "CGO_CXXFLAGS", "CGO_LDFLAGS"} {
+				appendSetting(name, cfg.Getenv(name))
+			}
+		}
+		appendSetting("GOARCH", cfg.BuildContext.GOARCH)
+		if cfg.GOEXPERIMENT != "" {
+			appendSetting("GOEXPERIMENT", cfg.GOEXPERIMENT)
+		}
+		appendSetting("GOOS", cfg.BuildContext.GOOS)
+		if key, val := cfg.GetArchEnv(); key != "" && val != "" {
+			appendSetting(key, val)
+		}
+	}
+
+	// Add VCS status if all conditions are true:
+	//
+	// - -buildvcs is enabled.
+	// - p is contained within a main module (there may be multiple main modules
+	//   in a workspace, but local replacements don't count).
+	// - Both the current directory and p's module's root directory are contained
+	//   in the same local repository.
+	// - We know the VCS commands needed to get the status.
+	setVCSError := func(err error) {
+		setPkgErrorf("error obtaining VCS status: %v\n\tUse -buildvcs=false to disable VCS stamping.", err)
+	}
+
+	var repoDir string
+	var vcsCmd *vcs.Cmd
+	var err error
+	const allowNesting = true
+	if cfg.BuildBuildvcs && p.Module != nil && p.Module.Version == "" && !p.Standard {
+		repoDir, vcsCmd, err = vcs.FromDir(base.Cwd(), "", allowNesting)
+		if err != nil && !errors.Is(err, os.ErrNotExist) {
+			setVCSError(err)
+			return
+		}
+		if !str.HasFilePathPrefix(p.Module.Dir, repoDir) &&
+			!str.HasFilePathPrefix(repoDir, p.Module.Dir) {
+			// The module containing the main package does not overlap with the
+			// repository containing the working directory. Don't include VCS info.
+			// If the repo contains the module or vice versa, but they are not
+			// the same directory, it's likely an error (see below).
+			repoDir, vcsCmd = "", nil
+		}
+	}
+	if repoDir != "" && vcsCmd.Status != nil {
+		// Check that the current directory, package, and module are in the same
+		// repository. vcs.FromDir allows nested Git repositories, but nesting
+		// is not allowed for other VCS tools. The current directory may be outside
+		// p.Module.Dir when a workspace is used.
+		pkgRepoDir, _, err := vcs.FromDir(p.Dir, "", allowNesting)
+		if err != nil {
+			setVCSError(err)
+			return
+		}
+		if pkgRepoDir != repoDir {
+			setVCSError(fmt.Errorf("main package is in repository %q but current directory is in repository %q", pkgRepoDir, repoDir))
+			return
+		}
+		modRepoDir, _, err := vcs.FromDir(p.Module.Dir, "", allowNesting)
+		if err != nil {
+			setVCSError(err)
+			return
+		}
+		if modRepoDir != repoDir {
+			setVCSError(fmt.Errorf("main module is in repository %q but current directory is in repository %q", modRepoDir, repoDir))
+			return
+		}
+
+		type vcsStatusError struct {
+			Status vcs.Status
+			Err    error
+		}
+		cached := vcsStatusCache.Do(repoDir, func() any {
+			st, err := vcsCmd.Status(vcsCmd, repoDir)
+			return vcsStatusError{st, err}
+		}).(vcsStatusError)
+		if err := cached.Err; err != nil {
+			setVCSError(err)
+			return
+		}
+		st := cached.Status
+
+		appendSetting("vcs", vcsCmd.Cmd)
+		if st.Revision != "" {
+			appendSetting("vcs.revision", st.Revision)
+		}
+		if !st.CommitTime.IsZero() {
+			stamp := st.CommitTime.UTC().Format(time.RFC3339Nano)
+			appendSetting("vcs.time", stamp)
+		}
+		appendSetting("vcs.modified", strconv.FormatBool(st.Uncommitted))
+	}
+
+	text, err := info.MarshalText()
+	if err != nil {
+		setPkgErrorf("error formatting build info: %v", err)
+		return
+	}
+	p.Internal.BuildInfo = string(text)
+}
+
 // SafeArg reports whether arg is a "safe" command-line argument,
 // meaning that when it appears in a command-line, it probably
 // doesn't have some special meaning other than its own name.
@@ -2237,6 +2470,10 @@ func LinkerDeps(p *Package) []string {
 	if cfg.BuildMSan {
 		deps = append(deps, "runtime/msan")
 	}
+	// Using address sanitizer forces an import of runtime/asan.
+	if cfg.BuildASan {
+		deps = append(deps, "runtime/asan")
+	}
 
 	return deps
 }
@@ -2453,7 +2690,8 @@ func PackagesAndErrors(ctx context.Context, opts PackageOpts, patterns []string)
 		}
 		matches, _ = modload.LoadPackages(ctx, modOpts, patterns...)
 	} else {
-		matches = search.ImportPaths(patterns)
+		noModRoots := []string{}
+		matches = search.ImportPaths(patterns, noModRoots)
 	}
 
 	var (
@@ -2679,10 +2917,7 @@ func GoFilesPackage(ctx context.Context, opts PackageOpts, gofiles []string) *Pa
 		if fi.IsDir() {
 			base.Fatalf("%s is a directory, should be a Go file", file)
 		}
-		dir1, _ := filepath.Split(file)
-		if dir1 == "" {
-			dir1 = "./"
-		}
+		dir1 := filepath.Dir(file)
 		if dir == "" {
 			dir = dir1
 		} else if dir != dir1 {
@@ -2710,7 +2945,9 @@ func GoFilesPackage(ctx context.Context, opts PackageOpts, gofiles []string) *Pa
 	pkg.Internal.Local = true
 	pkg.Internal.CmdlineFiles = true
 	pkg.load(ctx, opts, "command-line-arguments", &stk, nil, bp, err)
-	pkg.Internal.LocalPrefix = dirToImportPath(dir)
+	if !cfg.ModulesEnabled {
+		pkg.Internal.LocalPrefix = dirToImportPath(dir)
+	}
 	pkg.ImportPath = "command-line-arguments"
 	pkg.Target = ""
 	pkg.Match = gofiles
diff --git a/libgo/go/cmd/go/internal/load/test.go b/libgo/go/cmd/go/internal/load/test.go
index c8282965669..6122428c9cf 100644
--- a/libgo/go/cmd/go/internal/load/test.go
+++ b/libgo/go/cmd/go/internal/load/test.go
@@ -555,6 +555,7 @@ func formatTestmain(t *testFuncs) ([]byte, error) {
 type testFuncs struct {
 	Tests       []testFunc
 	Benchmarks  []testFunc
+	FuzzTargets []testFunc
 	Examples    []testFunc
 	TestMain    *testFunc
 	Package     *Package
@@ -653,6 +654,13 @@ func (t *testFuncs) load(filename, pkg string, doImport, seen *bool) error {
 			}
 			t.Benchmarks = append(t.Benchmarks, testFunc{pkg, name, "", false})
 			*doImport, *seen = true, true
+		case isTest(name, "Fuzz"):
+			err := checkTestFunc(n, "F")
+			if err != nil {
+				return err
+			}
+			t.FuzzTargets = append(t.FuzzTargets, testFunc{pkg, name, "", false})
+			*doImport, *seen = true, true
 		}
 	}
 	ex := doc.Examples(f)
@@ -670,10 +678,16 @@ func (t *testFuncs) load(filename, pkg string, doImport, seen *bool) error {
 }
 
 func checkTestFunc(fn *ast.FuncDecl, arg string) error {
+	var why string
 	if !isTestFunc(fn, arg) {
-		name := fn.Name.String()
+		why = fmt.Sprintf("must be: func %s(%s *testing.%s)", fn.Name.String(), strings.ToLower(arg), arg)
+	}
+	if fn.Type.TypeParams.NumFields() > 0 {
+		why = "test functions cannot have type parameters"
+	}
+	if why != "" {
 		pos := testFileSet.Position(fn.Pos())
-		return fmt.Errorf("%s: wrong signature for %s, must be: func %s(%s *testing.%s)", pos, name, name, strings.ToLower(arg), arg)
+		return fmt.Errorf("%s: wrong signature for %s, %s", pos, fn.Name.String(), why)
 	}
 	return nil
 }
@@ -716,6 +730,12 @@ var benchmarks = []testing.InternalBenchmark{
 {{end}}
 }
 
+var fuzzTargets = []testing.InternalFuzzTarget{
+{{range .FuzzTargets}}
+	{"{{.Name}}", {{.Package}}.{{.Name}}},
+{{end}}
+}
+
 var examples = []testing.InternalExample{
 {{range .Examples}}
 	{"{{.Name}}", {{.Package}}.{{.Name}}, {{.Output | printf "%q"}}, {{.Unordered}}},
@@ -774,7 +794,7 @@ func main() {
 		CoveredPackages: {{printf "%q" .Covered}},
 	})
 {{end}}
-	m := testing.MainStart(testdeps.TestDeps{}, tests, benchmarks, examples)
+	m := testing.MainStart(testdeps.TestDeps{}, tests, benchmarks, fuzzTargets, examples)
 {{with .TestMain}}
 	{{.Package}}.{{.Name}}(m)
 	os.Exit(int(reflect.ValueOf(m).Elem().FieldByName("exitCode").Int()))
diff --git a/libgo/go/cmd/go/internal/lockedfile/internal/filelock/filelock_fcntl.go b/libgo/go/cmd/go/internal/lockedfile/internal/filelock/filelock_fcntl.go
index e302fe7fccf..31ab5ea4002 100644
--- a/libgo/go/cmd/go/internal/lockedfile/internal/filelock/filelock_fcntl.go
+++ b/libgo/go/cmd/go/internal/lockedfile/internal/filelock/filelock_fcntl.go
@@ -3,7 +3,6 @@
 // license that can be found in the LICENSE file.
 
 //go:build aix || (solaris && !illumos)
-// +build aix solaris,!illumos
 
 // This code implements the filelock API using POSIX 'fcntl' locks, which attach
 // to an (inode, process) pair rather than a file descriptor. To avoid unlocking
diff --git a/libgo/go/cmd/go/internal/lockedfile/internal/filelock/filelock_other.go b/libgo/go/cmd/go/internal/lockedfile/internal/filelock/filelock_other.go
index c6eac302c57..4aef110bb1a 100644
--- a/libgo/go/cmd/go/internal/lockedfile/internal/filelock/filelock_other.go
+++ b/libgo/go/cmd/go/internal/lockedfile/internal/filelock/filelock_other.go
@@ -3,7 +3,6 @@
 // license that can be found in the LICENSE file.
 
 //go:build !aix && !darwin && !dragonfly && !freebsd && !hurd && !linux && !netbsd && !openbsd && !plan9 && !solaris && !windows
-// +build !aix,!darwin,!dragonfly,!freebsd,!hurd,!linux,!netbsd,!openbsd,!plan9,!solaris,!windows
 
 package filelock
 
diff --git a/libgo/go/cmd/go/internal/lockedfile/internal/filelock/filelock_plan9.go b/libgo/go/cmd/go/internal/lockedfile/internal/filelock/filelock_plan9.go
index 908afb6c8cb..54b2c946e0d 100644
--- a/libgo/go/cmd/go/internal/lockedfile/internal/filelock/filelock_plan9.go
+++ b/libgo/go/cmd/go/internal/lockedfile/internal/filelock/filelock_plan9.go
@@ -3,7 +3,6 @@
 // license that can be found in the LICENSE file.
 
 //go:build plan9
-// +build plan9
 
 package filelock
 
diff --git a/libgo/go/cmd/go/internal/lockedfile/internal/filelock/filelock_test.go b/libgo/go/cmd/go/internal/lockedfile/internal/filelock/filelock_test.go
index 640d4406f42..7bd7bd28f55 100644
--- a/libgo/go/cmd/go/internal/lockedfile/internal/filelock/filelock_test.go
+++ b/libgo/go/cmd/go/internal/lockedfile/internal/filelock/filelock_test.go
@@ -3,7 +3,6 @@
 // license that can be found in the LICENSE file.
 
 //go:build !js && !plan9
-// +build !js,!plan9
 
 package filelock_test
 
diff --git a/libgo/go/cmd/go/internal/lockedfile/internal/filelock/filelock_unix.go b/libgo/go/cmd/go/internal/lockedfile/internal/filelock/filelock_unix.go
index b22c0bb9918..61427c7c031 100644
--- a/libgo/go/cmd/go/internal/lockedfile/internal/filelock/filelock_unix.go
+++ b/libgo/go/cmd/go/internal/lockedfile/internal/filelock/filelock_unix.go
@@ -3,7 +3,6 @@
 // license that can be found in the LICENSE file.
 
 //go:build darwin || dragonfly || freebsd || hurd || illumos || linux || netbsd || openbsd
-// +build darwin dragonfly freebsd hurd illumos linux netbsd openbsd
 
 package filelock
 
diff --git a/libgo/go/cmd/go/internal/lockedfile/internal/filelock/filelock_windows.go b/libgo/go/cmd/go/internal/lockedfile/internal/filelock/filelock_windows.go
index dd27ce92bd8..e2ca5383046 100644
--- a/libgo/go/cmd/go/internal/lockedfile/internal/filelock/filelock_windows.go
+++ b/libgo/go/cmd/go/internal/lockedfile/internal/filelock/filelock_windows.go
@@ -3,7 +3,6 @@
 // license that can be found in the LICENSE file.
 
 //go:build windows
-// +build windows
 
 package filelock
 
diff --git a/libgo/go/cmd/go/internal/lockedfile/lockedfile_filelock.go b/libgo/go/cmd/go/internal/lockedfile/lockedfile_filelock.go
index e4923f68764..1a677a7fe4a 100644
--- a/libgo/go/cmd/go/internal/lockedfile/lockedfile_filelock.go
+++ b/libgo/go/cmd/go/internal/lockedfile/lockedfile_filelock.go
@@ -3,7 +3,6 @@
 // license that can be found in the LICENSE file.
 
 //go:build !plan9
-// +build !plan9
 
 package lockedfile
 
diff --git a/libgo/go/cmd/go/internal/lockedfile/lockedfile_plan9.go b/libgo/go/cmd/go/internal/lockedfile/lockedfile_plan9.go
index 979118b10ae..35669388e05 100644
--- a/libgo/go/cmd/go/internal/lockedfile/lockedfile_plan9.go
+++ b/libgo/go/cmd/go/internal/lockedfile/lockedfile_plan9.go
@@ -3,7 +3,6 @@
 // license that can be found in the LICENSE file.
 
 //go:build plan9
-// +build plan9
 
 package lockedfile
 
diff --git a/libgo/go/cmd/go/internal/lockedfile/lockedfile_test.go b/libgo/go/cmd/go/internal/lockedfile/lockedfile_test.go
index 3acc6695a74..c9907db46ce 100644
--- a/libgo/go/cmd/go/internal/lockedfile/lockedfile_test.go
+++ b/libgo/go/cmd/go/internal/lockedfile/lockedfile_test.go
@@ -4,7 +4,6 @@
 
 // js does not support inter-process file locking.
 //go:build !js
-// +build !js
 
 package lockedfile_test
 
diff --git a/libgo/go/cmd/go/internal/lockedfile/transform_test.go b/libgo/go/cmd/go/internal/lockedfile/transform_test.go
index b753346e7da..3c1caa334eb 100644
--- a/libgo/go/cmd/go/internal/lockedfile/transform_test.go
+++ b/libgo/go/cmd/go/internal/lockedfile/transform_test.go
@@ -4,7 +4,6 @@
 
 // js does not support inter-process file locking.
 //go:build !js
-// +build !js
 
 package lockedfile_test
 
diff --git a/libgo/go/cmd/go/internal/modcmd/download.go b/libgo/go/cmd/go/internal/modcmd/download.go
index 0e5af852376..6b8a010fd9d 100644
--- a/libgo/go/cmd/go/internal/modcmd/download.go
+++ b/libgo/go/cmd/go/internal/modcmd/download.go
@@ -16,6 +16,7 @@ import (
 	"cmd/go/internal/modload"
 
 	"golang.org/x/mod/module"
+	"golang.org/x/mod/semver"
 )
 
 var cmdDownload = &base.Command{
@@ -24,8 +25,11 @@ var cmdDownload = &base.Command{
 	Long: `
 Download downloads the named modules, which can be module patterns selecting
 dependencies of the main module or module queries of the form path@version.
-With no arguments, download applies to all dependencies of the main module
-(equivalent to 'go mod download all').
+
+With no arguments, download applies to the modules needed to build and test
+the packages in the main module: the modules explicitly required by the main
+module if it is at 'go 1.17' or higher, or all transitively-required modules
+if at 'go 1.16' or lower.
 
 The go command will automatically download modules as needed during ordinary
 execution. The "go mod download" command is useful mainly for pre-filling
@@ -66,6 +70,7 @@ func init() {
 	// TODO(jayconrod): https://golang.org/issue/35849 Apply -x to other 'go mod' commands.
 	cmdDownload.Flag.BoolVar(&cfg.BuildX, "x", false, "")
 	base.AddModCommonFlags(&cmdDownload.Flag)
+	base.AddWorkfileFlag(&cmdDownload.Flag)
 }
 
 type moduleJSON struct {
@@ -81,27 +86,68 @@ type moduleJSON struct {
 }
 
 func runDownload(ctx context.Context, cmd *base.Command, args []string) {
+	modload.InitWorkfile()
+
 	// Check whether modules are enabled and whether we're in a module.
 	modload.ForceUseModules = true
-	if !modload.HasModRoot() && len(args) == 0 {
-		base.Fatalf("go mod download: no modules specified (see 'go help mod download')")
-	}
+	modload.ExplicitWriteGoMod = true
 	haveExplicitArgs := len(args) > 0
-	if !haveExplicitArgs {
-		args = []string{"all"}
-	}
-	if modload.HasModRoot() {
-		modload.LoadModFile(ctx) // to fill Target
-		targetAtUpgrade := modload.Target.Path + "@upgrade"
-		targetAtPatch := modload.Target.Path + "@patch"
-		for _, arg := range args {
-			switch arg {
-			case modload.Target.Path, targetAtUpgrade, targetAtPatch:
-				os.Stderr.WriteString("go mod download: skipping argument " + arg + " that resolves to the main module\n")
+
+	if modload.HasModRoot() || modload.WorkFilePath() != "" {
+		modload.LoadModFile(ctx) // to fill MainModules
+
+		if haveExplicitArgs {
+			for _, mainModule := range modload.MainModules.Versions() {
+				targetAtUpgrade := mainModule.Path + "@upgrade"
+				targetAtPatch := mainModule.Path + "@patch"
+				for _, arg := range args {
+					switch arg {
+					case mainModule.Path, targetAtUpgrade, targetAtPatch:
+						os.Stderr.WriteString("go: skipping download of " + arg + " that resolves to the main module\n")
+					}
+				}
+			}
+		} else if modload.WorkFilePath() != "" {
+			// TODO(#44435): Think about what the correct query is to download the
+			// right set of modules. Also see code review comment at
+			// https://go-review.googlesource.com/c/go/+/359794/comments/ce946a80_6cf53992.
+			args = []string{"all"}
+		} else {
+			mainModule := modload.MainModules.Versions()[0]
+			modFile := modload.MainModules.ModFile(mainModule)
+			if modFile.Go == nil || semver.Compare("v"+modFile.Go.Version, modload.ExplicitIndirectVersionV) < 0 {
+				if len(modFile.Require) > 0 {
+					args = []string{"all"}
+				}
+			} else {
+				// As of Go 1.17, the go.mod file explicitly requires every module
+				// that provides any package imported by the main module.
+				// 'go mod download' is typically run before testing packages in the
+				// main module, so by default we shouldn't download the others
+				// (which are presumed irrelevant to the packages in the main module).
+				// See https://golang.org/issue/44435.
+				//
+				// However, we also need to load the full module graph, to ensure that
+				// we have downloaded enough of the module graph to run 'go list all',
+				// 'go mod graph', and similar commands.
+				_ = modload.LoadModGraph(ctx, "")
+
+				for _, m := range modFile.Require {
+					args = append(args, m.Mod.Path)
+				}
 			}
 		}
 	}
 
+	if len(args) == 0 {
+		if modload.HasModRoot() {
+			os.Stderr.WriteString("go: no module dependencies to download\n")
+		} else {
+			base.Errorf("go: no modules specified (see 'go help mod download')")
+		}
+		base.Exit()
+	}
+
 	downloadModule := func(m *moduleJSON) {
 		var err error
 		m.Info, err = modfetch.InfoFile(m.Path, m.Version)
@@ -140,13 +186,16 @@ func runDownload(ctx context.Context, cmd *base.Command, args []string) {
 	if !haveExplicitArgs {
 		// 'go mod download' is sometimes run without arguments to pre-populate the
 		// module cache. It may fetch modules that aren't needed to build packages
-		// in the main mdoule. This is usually not intended, so don't save sums for
-		// downloaded modules (golang.org/issue/45332).
-		// TODO(golang.org/issue/45551): For now, in ListModules, save sums needed
-		// to load the build list (same as 1.15 behavior). In the future, report an
-		// error if go.mod or go.sum need to be updated after loading the build
-		// list.
-		modload.DisallowWriteGoMod()
+		// in the main module. This is usually not intended, so don't save sums for
+		// downloaded modules (golang.org/issue/45332). We do still fix
+		// inconsistencies in go.mod though.
+		//
+		// TODO(#45551): In the future, report an error if go.mod or go.sum need to
+		// be updated after loading the build list. This may require setting
+		// the mode to "mod" or "readonly" depending on haveExplicitArgs.
+		if err := modload.WriteGoMod(ctx); err != nil {
+			base.Fatalf("go: %v", err)
+		}
 	}
 
 	for _, info := range infos {
@@ -183,7 +232,7 @@ func runDownload(ctx context.Context, cmd *base.Command, args []string) {
 		for _, m := range mods {
 			b, err := json.MarshalIndent(m, "", "\t")
 			if err != nil {
-				base.Fatalf("go mod download: %v", err)
+				base.Fatalf("go: %v", err)
 			}
 			os.Stdout.Write(append(b, '\n'))
 			if m.Error != "" {
@@ -193,7 +242,7 @@ func runDownload(ctx context.Context, cmd *base.Command, args []string) {
 	} else {
 		for _, m := range mods {
 			if m.Error != "" {
-				base.Errorf("go mod download: %v", m.Error)
+				base.Errorf("go: %v", m.Error)
 			}
 		}
 		base.ExitIfErrors()
@@ -206,13 +255,15 @@ func runDownload(ctx context.Context, cmd *base.Command, args []string) {
 	//
 	// Don't save sums for 'go mod download' without arguments; see comment above.
 	if haveExplicitArgs {
-		modload.WriteGoMod(ctx)
+		if err := modload.WriteGoMod(ctx); err != nil {
+			base.Errorf("go: %v", err)
+		}
 	}
 
 	// If there was an error matching some of the requested packages, emit it now
 	// (after we've written the checksums for the modules that were downloaded
 	// successfully).
 	if infosErr != nil {
-		base.Errorf("go mod download: %v", infosErr)
+		base.Errorf("go: %v", infosErr)
 	}
 }
diff --git a/libgo/go/cmd/go/internal/modcmd/edit.go b/libgo/go/cmd/go/internal/modcmd/edit.go
index bb3d5210926..e5182a9590a 100644
--- a/libgo/go/cmd/go/internal/modcmd/edit.go
+++ b/libgo/go/cmd/go/internal/modcmd/edit.go
@@ -171,15 +171,15 @@ func runEdit(ctx context.Context, cmd *base.Command, args []string) {
 			len(edits) > 0
 
 	if !anyFlags {
-		base.Fatalf("go mod edit: no flags specified (see 'go help mod edit').")
+		base.Fatalf("go: no flags specified (see 'go help mod edit').")
 	}
 
 	if *editJSON && *editPrint {
-		base.Fatalf("go mod edit: cannot use both -json and -print")
+		base.Fatalf("go: cannot use both -json and -print")
 	}
 
 	if len(args) > 1 {
-		base.Fatalf("go mod edit: too many arguments")
+		base.Fatalf("go: too many arguments")
 	}
 	var gomod string
 	if len(args) == 1 {
@@ -190,7 +190,7 @@ func runEdit(ctx context.Context, cmd *base.Command, args []string) {
 
 	if *editModule != "" {
 		if err := module.CheckImportPath(*editModule); err != nil {
-			base.Fatalf("go mod: invalid -module: %v", err)
+			base.Fatalf("go: invalid -module: %v", err)
 		}
 	}
 
@@ -264,15 +264,15 @@ func runEdit(ctx context.Context, cmd *base.Command, args []string) {
 func parsePathVersion(flag, arg string) (path, version string) {
 	i := strings.Index(arg, "@")
 	if i < 0 {
-		base.Fatalf("go mod: -%s=%s: need path@version", flag, arg)
+		base.Fatalf("go: -%s=%s: need path@version", flag, arg)
 	}
 	path, version = strings.TrimSpace(arg[:i]), strings.TrimSpace(arg[i+1:])
 	if err := module.CheckImportPath(path); err != nil {
-		base.Fatalf("go mod: -%s=%s: invalid path: %v", flag, arg, err)
+		base.Fatalf("go: -%s=%s: invalid path: %v", flag, arg, err)
 	}
 
 	if !allowedVersionArg(version) {
-		base.Fatalf("go mod: -%s=%s: invalid version %q", flag, arg, version)
+		base.Fatalf("go: -%s=%s: invalid version %q", flag, arg, version)
 	}
 
 	return path, version
@@ -281,11 +281,11 @@ func parsePathVersion(flag, arg string) (path, version string) {
 // parsePath parses -flag=arg expecting arg to be path (not path@version).
 func parsePath(flag, arg string) (path string) {
 	if strings.Contains(arg, "@") {
-		base.Fatalf("go mod: -%s=%s: need just path, not path@version", flag, arg)
+		base.Fatalf("go: -%s=%s: need just path, not path@version", flag, arg)
 	}
 	path = arg
 	if err := module.CheckImportPath(path); err != nil {
-		base.Fatalf("go mod: -%s=%s: invalid path: %v", flag, arg, err)
+		base.Fatalf("go: -%s=%s: invalid path: %v", flag, arg, err)
 	}
 	return path
 }
@@ -350,7 +350,7 @@ func flagRequire(arg string) {
 	path, version := parsePathVersion("require", arg)
 	edits = append(edits, func(f *modfile.File) {
 		if err := f.AddRequire(path, version); err != nil {
-			base.Fatalf("go mod: -require=%s: %v", arg, err)
+			base.Fatalf("go: -require=%s: %v", arg, err)
 		}
 	})
 }
@@ -360,7 +360,7 @@ func flagDropRequire(arg string) {
 	path := parsePath("droprequire", arg)
 	edits = append(edits, func(f *modfile.File) {
 		if err := f.DropRequire(path); err != nil {
-			base.Fatalf("go mod: -droprequire=%s: %v", arg, err)
+			base.Fatalf("go: -droprequire=%s: %v", arg, err)
 		}
 	})
 }
@@ -370,7 +370,7 @@ func flagExclude(arg string) {
 	path, version := parsePathVersion("exclude", arg)
 	edits = append(edits, func(f *modfile.File) {
 		if err := f.AddExclude(path, version); err != nil {
-			base.Fatalf("go mod: -exclude=%s: %v", arg, err)
+			base.Fatalf("go: -exclude=%s: %v", arg, err)
 		}
 	})
 }
@@ -380,7 +380,7 @@ func flagDropExclude(arg string) {
 	path, version := parsePathVersion("dropexclude", arg)
 	edits = append(edits, func(f *modfile.File) {
 		if err := f.DropExclude(path, version); err != nil {
-			base.Fatalf("go mod: -dropexclude=%s: %v", arg, err)
+			base.Fatalf("go: -dropexclude=%s: %v", arg, err)
 		}
 	})
 }
@@ -389,27 +389,27 @@ func flagDropExclude(arg string) {
 func flagReplace(arg string) {
 	var i int
 	if i = strings.Index(arg, "="); i < 0 {
-		base.Fatalf("go mod: -replace=%s: need old[@v]=new[@w] (missing =)", arg)
+		base.Fatalf("go: -replace=%s: need old[@v]=new[@w] (missing =)", arg)
 	}
 	old, new := strings.TrimSpace(arg[:i]), strings.TrimSpace(arg[i+1:])
 	if strings.HasPrefix(new, ">") {
-		base.Fatalf("go mod: -replace=%s: separator between old and new is =, not =>", arg)
+		base.Fatalf("go: -replace=%s: separator between old and new is =, not =>", arg)
 	}
 	oldPath, oldVersion, err := parsePathVersionOptional("old", old, false)
 	if err != nil {
-		base.Fatalf("go mod: -replace=%s: %v", arg, err)
+		base.Fatalf("go: -replace=%s: %v", arg, err)
 	}
 	newPath, newVersion, err := parsePathVersionOptional("new", new, true)
 	if err != nil {
-		base.Fatalf("go mod: -replace=%s: %v", arg, err)
+		base.Fatalf("go: -replace=%s: %v", arg, err)
 	}
 	if newPath == new && !modfile.IsDirectoryPath(new) {
-		base.Fatalf("go mod: -replace=%s: unversioned new path must be local directory", arg)
+		base.Fatalf("go: -replace=%s: unversioned new path must be local directory", arg)
 	}
 
 	edits = append(edits, func(f *modfile.File) {
 		if err := f.AddReplace(oldPath, oldVersion, newPath, newVersion); err != nil {
-			base.Fatalf("go mod: -replace=%s: %v", arg, err)
+			base.Fatalf("go: -replace=%s: %v", arg, err)
 		}
 	})
 }
@@ -418,11 +418,11 @@ func flagReplace(arg string) {
 func flagDropReplace(arg string) {
 	path, version, err := parsePathVersionOptional("old", arg, true)
 	if err != nil {
-		base.Fatalf("go mod: -dropreplace=%s: %v", arg, err)
+		base.Fatalf("go: -dropreplace=%s: %v", arg, err)
 	}
 	edits = append(edits, func(f *modfile.File) {
 		if err := f.DropReplace(path, version); err != nil {
-			base.Fatalf("go mod: -dropreplace=%s: %v", arg, err)
+			base.Fatalf("go: -dropreplace=%s: %v", arg, err)
 		}
 	})
 }
@@ -431,11 +431,11 @@ func flagDropReplace(arg string) {
 func flagRetract(arg string) {
 	vi, err := parseVersionInterval(arg)
 	if err != nil {
-		base.Fatalf("go mod: -retract=%s: %v", arg, err)
+		base.Fatalf("go: -retract=%s: %v", arg, err)
 	}
 	edits = append(edits, func(f *modfile.File) {
 		if err := f.AddRetract(vi, ""); err != nil {
-			base.Fatalf("go mod: -retract=%s: %v", arg, err)
+			base.Fatalf("go: -retract=%s: %v", arg, err)
 		}
 	})
 }
@@ -444,11 +444,11 @@ func flagRetract(arg string) {
 func flagDropRetract(arg string) {
 	vi, err := parseVersionInterval(arg)
 	if err != nil {
-		base.Fatalf("go mod: -dropretract=%s: %v", arg, err)
+		base.Fatalf("go: -dropretract=%s: %v", arg, err)
 	}
 	edits = append(edits, func(f *modfile.File) {
 		if err := f.DropRetract(vi); err != nil {
-			base.Fatalf("go mod: -dropretract=%s: %v", arg, err)
+			base.Fatalf("go: -dropretract=%s: %v", arg, err)
 		}
 	})
 }
diff --git a/libgo/go/cmd/go/internal/modcmd/graph.go b/libgo/go/cmd/go/internal/modcmd/graph.go
index ac81f26dade..9b6aa1fb14d 100644
--- a/libgo/go/cmd/go/internal/modcmd/graph.go
+++ b/libgo/go/cmd/go/internal/modcmd/graph.go
@@ -42,11 +42,14 @@ var (
 func init() {
 	cmdGraph.Flag.Var(&graphGo, "go", "")
 	base.AddModCommonFlags(&cmdGraph.Flag)
+	base.AddWorkfileFlag(&cmdGraph.Flag)
 }
 
 func runGraph(ctx context.Context, cmd *base.Command, args []string) {
+	modload.InitWorkfile()
+
 	if len(args) > 0 {
-		base.Fatalf("go mod graph: graph takes no arguments")
+		base.Fatalf("go: 'go mod graph' accepts no arguments")
 	}
 	modload.ForceUseModules = true
 	modload.RootMode = modload.NeedRoot
diff --git a/libgo/go/cmd/go/internal/modcmd/init.go b/libgo/go/cmd/go/internal/modcmd/init.go
index 958c3066ac1..bc4620a2a8d 100644
--- a/libgo/go/cmd/go/internal/modcmd/init.go
+++ b/libgo/go/cmd/go/internal/modcmd/init.go
@@ -39,7 +39,7 @@ func init() {
 
 func runInit(ctx context.Context, cmd *base.Command, args []string) {
 	if len(args) > 1 {
-		base.Fatalf("go mod init: too many arguments")
+		base.Fatalf("go: 'go mod init' accepts at most one argument")
 	}
 	var modPath string
 	if len(args) == 1 {
diff --git a/libgo/go/cmd/go/internal/modcmd/tidy.go b/libgo/go/cmd/go/internal/modcmd/tidy.go
index fe25507e94f..d35476eb539 100644
--- a/libgo/go/cmd/go/internal/modcmd/tidy.go
+++ b/libgo/go/cmd/go/internal/modcmd/tidy.go
@@ -75,8 +75,8 @@ type goVersionFlag struct {
 	v string
 }
 
-func (f *goVersionFlag) String() string   { return f.v }
-func (f *goVersionFlag) Get() interface{} { return f.v }
+func (f *goVersionFlag) String() string { return f.v }
+func (f *goVersionFlag) Get() any       { return f.v }
 
 func (f *goVersionFlag) Set(s string) error {
 	if s != "" {
@@ -95,7 +95,7 @@ func (f *goVersionFlag) Set(s string) error {
 
 func runTidy(ctx context.Context, cmd *base.Command, args []string) {
 	if len(args) > 0 {
-		base.Fatalf("go mod tidy: no arguments allowed")
+		base.Fatalf("go: 'go mod tidy' accepts no arguments")
 	}
 
 	// Tidy aims to make 'go test' reproducible for any package in 'all', so we
diff --git a/libgo/go/cmd/go/internal/modcmd/vendor.go b/libgo/go/cmd/go/internal/modcmd/vendor.go
index 713d5f9f3fa..ef123700aa3 100644
--- a/libgo/go/cmd/go/internal/modcmd/vendor.go
+++ b/libgo/go/cmd/go/internal/modcmd/vendor.go
@@ -31,7 +31,7 @@ import (
 )
 
 var cmdVendor = &base.Command{
-	UsageLine: "go mod vendor [-e] [-v]",
+	UsageLine: "go mod vendor [-e] [-v] [-o outdir]",
 	Short:     "make vendored copy of dependencies",
 	Long: `
 Vendor resets the main module's vendor directory to include all packages
@@ -44,22 +44,29 @@ modules and packages to standard error.
 The -e flag causes vendor to attempt to proceed despite errors
 encountered while loading packages.
 
+The -o flag causes vendor to create the vendor directory at the given
+path instead of "vendor". The go command can only use a vendor directory
+named "vendor" within the module root directory, so this flag is
+primarily useful for other tools.
+
 See https://golang.org/ref/mod#go-mod-vendor for more about 'go mod vendor'.
 	`,
 	Run: runVendor,
 }
 
-var vendorE bool // if true, report errors but proceed anyway
+var vendorE bool   // if true, report errors but proceed anyway
+var vendorO string // if set, overrides the default output directory
 
 func init() {
 	cmdVendor.Flag.BoolVar(&cfg.BuildV, "v", false, "")
 	cmdVendor.Flag.BoolVar(&vendorE, "e", false, "")
+	cmdVendor.Flag.StringVar(&vendorO, "o", "", "")
 	base.AddModCommonFlags(&cmdVendor.Flag)
 }
 
 func runVendor(ctx context.Context, cmd *base.Command, args []string) {
 	if len(args) != 0 {
-		base.Fatalf("go mod vendor: vendor takes no arguments")
+		base.Fatalf("go: 'go mod vendor' accepts no arguments")
 	}
 	modload.ForceUseModules = true
 	modload.RootMode = modload.NeedRoot
@@ -74,15 +81,23 @@ func runVendor(ctx context.Context, cmd *base.Command, args []string) {
 	}
 	_, pkgs := modload.LoadPackages(ctx, loadOpts, "all")
 
-	vdir := filepath.Join(modload.ModRoot(), "vendor")
+	var vdir string
+	switch {
+	case filepath.IsAbs(vendorO):
+		vdir = vendorO
+	case vendorO != "":
+		vdir = filepath.Join(base.Cwd(), vendorO)
+	default:
+		vdir = filepath.Join(modload.VendorDir())
+	}
 	if err := os.RemoveAll(vdir); err != nil {
-		base.Fatalf("go mod vendor: %v", err)
+		base.Fatalf("go: %v", err)
 	}
 
 	modpkgs := make(map[module.Version][]string)
 	for _, pkg := range pkgs {
 		m := modload.PackageModule(pkg)
-		if m.Path == "" || m == modload.Target {
+		if m.Path == "" || m.Version == "" && modload.MainModules.Contains(m.Path) {
 			continue
 		}
 		modpkgs[m] = append(modpkgs[m], pkg)
@@ -128,7 +143,8 @@ func runVendor(ctx context.Context, cmd *base.Command, args []string) {
 	}
 
 	for _, m := range vendorMods {
-		line := moduleLine(m, modload.Replacement(m))
+		replacement := modload.Replacement(m)
+		line := moduleLine(m, replacement)
 		io.WriteString(w, line)
 
 		goVersion := ""
@@ -177,11 +193,11 @@ func runVendor(ctx context.Context, cmd *base.Command, args []string) {
 	}
 
 	if err := os.MkdirAll(vdir, 0777); err != nil {
-		base.Fatalf("go mod vendor: %v", err)
+		base.Fatalf("go: %v", err)
 	}
 
 	if err := os.WriteFile(filepath.Join(vdir, "modules.txt"), buf.Bytes(), 0666); err != nil {
-		base.Fatalf("go mod vendor: %v", err)
+		base.Fatalf("go: %v", err)
 	}
 }
 
@@ -242,14 +258,14 @@ func vendorPkg(vdir, pkg string) {
 	if err != nil {
 		if errors.As(err, &noGoError) {
 			return // No source files in this package are built. Skip embeds in ignored files.
-		} else if !errors.As(err, &multiplePackageError) { // multiplePackgeErrors are okay, but others are not.
+		} else if !errors.As(err, &multiplePackageError) { // multiplePackageErrors are OK, but others are not.
 			base.Fatalf("internal error: failed to find embedded files of %s: %v\n", pkg, err)
 		}
 	}
 	embedPatterns := str.StringList(bp.EmbedPatterns, bp.TestEmbedPatterns, bp.XTestEmbedPatterns)
 	embeds, err := load.ResolveEmbed(bp.Dir, embedPatterns)
 	if err != nil {
-		base.Fatalf("go mod vendor: %v", err)
+		base.Fatalf("go: %v", err)
 	}
 	for _, embed := range embeds {
 		embedDst := filepath.Join(dst, embed)
@@ -260,21 +276,21 @@ func vendorPkg(vdir, pkg string) {
 		// Copy the file as is done by copyDir below.
 		r, err := os.Open(filepath.Join(src, embed))
 		if err != nil {
-			base.Fatalf("go mod vendor: %v", err)
+			base.Fatalf("go: %v", err)
 		}
 		if err := os.MkdirAll(filepath.Dir(embedDst), 0777); err != nil {
-			base.Fatalf("go mod vendor: %v", err)
+			base.Fatalf("go: %v", err)
 		}
 		w, err := os.Create(embedDst)
 		if err != nil {
-			base.Fatalf("go mod vendor: %v", err)
+			base.Fatalf("go: %v", err)
 		}
 		if _, err := io.Copy(w, r); err != nil {
-			base.Fatalf("go mod vendor: %v", err)
+			base.Fatalf("go: %v", err)
 		}
 		r.Close()
 		if err := w.Close(); err != nil {
-			base.Fatalf("go mod vendor: %v", err)
+			base.Fatalf("go: %v", err)
 		}
 	}
 }
@@ -353,7 +369,7 @@ func matchPotentialSourceFile(dir string, info fs.DirEntry) bool {
 	if strings.HasSuffix(info.Name(), ".go") {
 		f, err := fsys.Open(filepath.Join(dir, info.Name()))
 		if err != nil {
-			base.Fatalf("go mod vendor: %v", err)
+			base.Fatalf("go: %v", err)
 		}
 		defer f.Close()
 
@@ -375,10 +391,10 @@ func matchPotentialSourceFile(dir string, info fs.DirEntry) bool {
 func copyDir(dst, src string, match func(dir string, info fs.DirEntry) bool, copiedFiles map[string]bool) {
 	files, err := os.ReadDir(src)
 	if err != nil {
-		base.Fatalf("go mod vendor: %v", err)
+		base.Fatalf("go: %v", err)
 	}
 	if err := os.MkdirAll(dst, 0777); err != nil {
-		base.Fatalf("go mod vendor: %v", err)
+		base.Fatalf("go: %v", err)
 	}
 	for _, file := range files {
 		if file.IsDir() || !file.Type().IsRegular() || !match(src, file) {
@@ -387,20 +403,20 @@ func copyDir(dst, src string, match func(dir string, info fs.DirEntry) bool, cop
 		copiedFiles[file.Name()] = true
 		r, err := os.Open(filepath.Join(src, file.Name()))
 		if err != nil {
-			base.Fatalf("go mod vendor: %v", err)
+			base.Fatalf("go: %v", err)
 		}
 		dstPath := filepath.Join(dst, file.Name())
 		copiedFiles[dstPath] = true
 		w, err := os.Create(dstPath)
 		if err != nil {
-			base.Fatalf("go mod vendor: %v", err)
+			base.Fatalf("go: %v", err)
 		}
 		if _, err := io.Copy(w, r); err != nil {
-			base.Fatalf("go mod vendor: %v", err)
+			base.Fatalf("go: %v", err)
 		}
 		r.Close()
 		if err := w.Close(); err != nil {
-			base.Fatalf("go mod vendor: %v", err)
+			base.Fatalf("go: %v", err)
 		}
 	}
 }
diff --git a/libgo/go/cmd/go/internal/modcmd/verify.go b/libgo/go/cmd/go/internal/modcmd/verify.go
index 5a6eca32cfb..3f0c005d5d9 100644
--- a/libgo/go/cmd/go/internal/modcmd/verify.go
+++ b/libgo/go/cmd/go/internal/modcmd/verify.go
@@ -39,12 +39,15 @@ See https://golang.org/ref/mod#go-mod-verify for more about 'go mod verify'.
 
 func init() {
 	base.AddModCommonFlags(&cmdVerify.Flag)
+	base.AddWorkfileFlag(&cmdVerify.Flag)
 }
 
 func runVerify(ctx context.Context, cmd *base.Command, args []string) {
+	modload.InitWorkfile()
+
 	if len(args) != 0 {
 		// NOTE(rsc): Could take a module pattern.
-		base.Fatalf("go mod verify: verify takes no arguments")
+		base.Fatalf("go: verify takes no arguments")
 	}
 	modload.ForceUseModules = true
 	modload.RootMode = modload.NeedRoot
diff --git a/libgo/go/cmd/go/internal/modcmd/why.go b/libgo/go/cmd/go/internal/modcmd/why.go
index 3b14b27c8c7..d8355cca957 100644
--- a/libgo/go/cmd/go/internal/modcmd/why.go
+++ b/libgo/go/cmd/go/internal/modcmd/why.go
@@ -12,8 +12,6 @@ import (
 	"cmd/go/internal/base"
 	"cmd/go/internal/imports"
 	"cmd/go/internal/modload"
-
-	"golang.org/x/mod/module"
 )
 
 var cmdWhy = &base.Command{
@@ -61,11 +59,14 @@ var (
 func init() {
 	cmdWhy.Run = runWhy // break init cycle
 	base.AddModCommonFlags(&cmdWhy.Flag)
+	base.AddWorkfileFlag(&cmdWhy.Flag)
 }
 
 func runWhy(ctx context.Context, cmd *base.Command, args []string) {
+	modload.InitWorkfile()
 	modload.ForceUseModules = true
 	modload.RootMode = modload.NeedRoot
+	modload.ExplicitWriteGoMod = true // don't write go.mod in ListModules
 
 	loadOpts := modload.PackageOpts{
 		Tags:                     imports.AnyTags(),
@@ -78,28 +79,28 @@ func runWhy(ctx context.Context, cmd *base.Command, args []string) {
 	if *whyM {
 		for _, arg := range args {
 			if strings.Contains(arg, "@") {
-				base.Fatalf("go mod why: module query not allowed")
+				base.Fatalf("go: %s: 'go mod why' requires a module path, not a version query", arg)
 			}
 		}
 
 		mods, err := modload.ListModules(ctx, args, 0)
 		if err != nil {
-			base.Fatalf("go mod why: %v", err)
+			base.Fatalf("go: %v", err)
 		}
 
-		byModule := make(map[module.Version][]string)
+		byModule := make(map[string][]string)
 		_, pkgs := modload.LoadPackages(ctx, loadOpts, "all")
 		for _, path := range pkgs {
 			m := modload.PackageModule(path)
 			if m.Path != "" {
-				byModule[m] = append(byModule[m], path)
+				byModule[m.Path] = append(byModule[m.Path], path)
 			}
 		}
 		sep := ""
 		for _, m := range mods {
 			best := ""
 			bestDepth := 1000000000
-			for _, path := range byModule[module.Version{Path: m.Path, Version: m.Version}] {
+			for _, path := range byModule[m.Path] {
 				d := modload.WhyDepth(path)
 				if d > 0 && d < bestDepth {
 					best = path
diff --git a/libgo/go/cmd/go/internal/modfetch/bootstrap.go b/libgo/go/cmd/go/internal/modfetch/bootstrap.go
index ed694581a7c..e23669fb00c 100644
--- a/libgo/go/cmd/go/internal/modfetch/bootstrap.go
+++ b/libgo/go/cmd/go/internal/modfetch/bootstrap.go
@@ -3,7 +3,6 @@
 // license that can be found in the LICENSE file.
 
 //go:build cmd_go_bootstrap
-// +build cmd_go_bootstrap
 
 package modfetch
 
diff --git a/libgo/go/cmd/go/internal/modfetch/cache.go b/libgo/go/cmd/go/internal/modfetch/cache.go
index b01b4674131..b0dae1cb3d3 100644
--- a/libgo/go/cmd/go/internal/modfetch/cache.go
+++ b/libgo/go/cmd/go/internal/modfetch/cache.go
@@ -204,7 +204,7 @@ func (r *cachingRepo) Versions(prefix string) ([]string, error) {
 		list []string
 		err  error
 	}
-	c := r.cache.Do("versions:"+prefix, func() interface{} {
+	c := r.cache.Do("versions:"+prefix, func() any {
 		list, err := r.repo().Versions(prefix)
 		return cached{list, err}
 	}).(cached)
@@ -221,7 +221,7 @@ type cachedInfo struct {
 }
 
 func (r *cachingRepo) Stat(rev string) (*RevInfo, error) {
-	c := r.cache.Do("stat:"+rev, func() interface{} {
+	c := r.cache.Do("stat:"+rev, func() any {
 		file, info, err := readDiskStat(r.path, rev)
 		if err == nil {
 			return cachedInfo{info, nil}
@@ -233,7 +233,7 @@ func (r *cachingRepo) Stat(rev string) (*RevInfo, error) {
 			// then save the information under the proper version, for future use.
 			if info.Version != rev {
 				file, _ = CachePath(module.Version{Path: r.path, Version: info.Version}, "info")
-				r.cache.Do("stat:"+info.Version, func() interface{} {
+				r.cache.Do("stat:"+info.Version, func() any {
 					return cachedInfo{info, err}
 				})
 			}
@@ -253,12 +253,12 @@ func (r *cachingRepo) Stat(rev string) (*RevInfo, error) {
 }
 
 func (r *cachingRepo) Latest() (*RevInfo, error) {
-	c := r.cache.Do("latest:", func() interface{} {
+	c := r.cache.Do("latest:", func() any {
 		info, err := r.repo().Latest()
 
 		// Save info for likely future Stat call.
 		if err == nil {
-			r.cache.Do("stat:"+info.Version, func() interface{} {
+			r.cache.Do("stat:"+info.Version, func() any {
 				return cachedInfo{info, err}
 			})
 			if file, _, err := readDiskStat(r.path, info.Version); err != nil {
@@ -281,7 +281,7 @@ func (r *cachingRepo) GoMod(version string) ([]byte, error) {
 		text []byte
 		err  error
 	}
-	c := r.cache.Do("gomod:"+version, func() interface{} {
+	c := r.cache.Do("gomod:"+version, func() any {
 		file, text, err := readDiskGoMod(r.path, version)
 		if err == nil {
 			// Note: readDiskGoMod already called checkGoMod.
@@ -642,7 +642,7 @@ func rewriteVersionList(dir string) (err error) {
 	// Lock listfile when writing to it to try to avoid corruption to the file.
 	// Under rare circumstances, for instance, if the system loses power in the
 	// middle of a write it is possible for corrupt data to be written. This is
-	// not a problem for the go command itself, but may be an issue if the the
+	// not a problem for the go command itself, but may be an issue if the
 	// cache is being served by a GOPROXY HTTP server. This will be corrected
 	// the next time a new version of the module is fetched and the file is rewritten.
 	// TODO(matloob): golang.org/issue/43313 covers adding a go mod verify
@@ -720,7 +720,7 @@ func checkCacheDir() error {
 	if cfg.GOMODCACHE == "" {
 		// modload.Init exits if GOPATH[0] is empty, and cfg.GOMODCACHE
 		// is set to GOPATH[0]/pkg/mod if GOMODCACHE is empty, so this should never happen.
-		return fmt.Errorf("internal error: cfg.GOMODCACHE not set")
+		return fmt.Errorf("module cache not found: neither GOMODCACHE nor GOPATH is set")
 	}
 	if !filepath.IsAbs(cfg.GOMODCACHE) {
 		return fmt.Errorf("GOMODCACHE entry is relative; must be absolute path: %q.\n", cfg.GOMODCACHE)
diff --git a/libgo/go/cmd/go/internal/modfetch/codehost/codehost.go b/libgo/go/cmd/go/internal/modfetch/codehost/codehost.go
index 378fbae34f9..4a0e2241e50 100644
--- a/libgo/go/cmd/go/internal/modfetch/codehost/codehost.go
+++ b/libgo/go/cmd/go/internal/modfetch/codehost/codehost.go
@@ -55,21 +55,6 @@ type Repo interface {
 	// os.IsNotExist(err) returns true.
 	ReadFile(rev, file string, maxSize int64) (data []byte, err error)
 
-	// ReadFileRevs reads a single file at multiple versions.
-	// It should refuse to read more than maxSize bytes.
-	// The result is a map from each requested rev strings
-	// to the associated FileRev. The map must have a non-nil
-	// entry for every requested rev (unless ReadFileRevs returned an error).
-	// A file simply being missing or even corrupted in revs[i]
-	// should be reported only in files[revs[i]].Err, not in the error result
-	// from ReadFileRevs.
-	// The overall call should return an error (and no map) only
-	// in the case of a problem with obtaining the data, such as
-	// a network failure.
-	// Implementations may assume that revs only contain tags,
-	// not direct commit hashes.
-	ReadFileRevs(revs []string, file string, maxSize int64) (files map[string]*FileRev, err error)
-
 	// ReadZip downloads a zip file for the subdir subdirectory
 	// of the given revision to a new file in a given temporary directory.
 	// It should refuse to read more than maxSize bytes.
@@ -243,7 +228,7 @@ var dirLock sync.Map
 // It returns the standard output and, for a non-zero exit,
 // a *RunError indicating the command, exit status, and standard error.
 // Standard error is unavailable for commands that exit successfully.
-func Run(dir string, cmdline ...interface{}) ([]byte, error) {
+func Run(dir string, cmdline ...any) ([]byte, error) {
 	return RunWithStdin(dir, nil, cmdline...)
 }
 
@@ -251,7 +236,7 @@ func Run(dir string, cmdline ...interface{}) ([]byte, error) {
 // See https://www.gnu.org/software/bash/manual/html_node/Double-Quotes.html.
 var bashQuoter = strings.NewReplacer(`"`, `\"`, `$`, `\$`, "`", "\\`", `\`, `\\`)
 
-func RunWithStdin(dir string, stdin io.Reader, cmdline ...interface{}) ([]byte, error) {
+func RunWithStdin(dir string, stdin io.Reader, cmdline ...any) ([]byte, error) {
 	if dir != "" {
 		muIface, ok := dirLock.Load(dir)
 		if !ok {
diff --git a/libgo/go/cmd/go/internal/modfetch/codehost/git.go b/libgo/go/cmd/go/internal/modfetch/codehost/git.go
index 4d4964edf44..34f453c855e 100644
--- a/libgo/go/cmd/go/internal/modfetch/codehost/git.go
+++ b/libgo/go/cmd/go/internal/modfetch/codehost/git.go
@@ -56,7 +56,7 @@ func newGitRepoCached(remote string, localOK bool) (Repo, error) {
 		err  error
 	}
 
-	c := gitRepoCache.Do(key{remote, localOK}, func() interface{} {
+	c := gitRepoCache.Do(key{remote, localOK}, func() any {
 		repo, err := newGitRepo(remote, localOK)
 		return cached{repo, err}
 	}).(cached)
@@ -170,59 +170,63 @@ func (r *gitRepo) loadLocalTags() {
 }
 
 // loadRefs loads heads and tags references from the remote into the map r.refs.
-// Should only be called as r.refsOnce.Do(r.loadRefs).
-func (r *gitRepo) loadRefs() {
-	// The git protocol sends all known refs and ls-remote filters them on the client side,
-	// so we might as well record both heads and tags in one shot.
-	// Most of the time we only care about tags but sometimes we care about heads too.
-	out, gitErr := Run(r.dir, "git", "ls-remote", "-q", r.remote)
-	if gitErr != nil {
-		if rerr, ok := gitErr.(*RunError); ok {
-			if bytes.Contains(rerr.Stderr, []byte("fatal: could not read Username")) {
-				rerr.HelpText = "Confirm the import path was entered correctly.\nIf this is a private repository, see https://golang.org/doc/faq#git_https for additional information."
+// The result is cached in memory.
+func (r *gitRepo) loadRefs() (map[string]string, error) {
+	r.refsOnce.Do(func() {
+		// The git protocol sends all known refs and ls-remote filters them on the client side,
+		// so we might as well record both heads and tags in one shot.
+		// Most of the time we only care about tags but sometimes we care about heads too.
+		out, gitErr := Run(r.dir, "git", "ls-remote", "-q", r.remote)
+		if gitErr != nil {
+			if rerr, ok := gitErr.(*RunError); ok {
+				if bytes.Contains(rerr.Stderr, []byte("fatal: could not read Username")) {
+					rerr.HelpText = "Confirm the import path was entered correctly.\nIf this is a private repository, see https://golang.org/doc/faq#git_https for additional information."
+				}
 			}
-		}
 
-		// If the remote URL doesn't exist at all, ideally we should treat the whole
-		// repository as nonexistent by wrapping the error in a notExistError.
-		// For HTTP and HTTPS, that's easy to detect: we'll try to fetch the URL
-		// ourselves and see what code it serves.
-		if u, err := url.Parse(r.remoteURL); err == nil && (u.Scheme == "http" || u.Scheme == "https") {
-			if _, err := web.GetBytes(u); errors.Is(err, fs.ErrNotExist) {
-				gitErr = notExistError{gitErr}
+			// If the remote URL doesn't exist at all, ideally we should treat the whole
+			// repository as nonexistent by wrapping the error in a notExistError.
+			// For HTTP and HTTPS, that's easy to detect: we'll try to fetch the URL
+			// ourselves and see what code it serves.
+			if u, err := url.Parse(r.remoteURL); err == nil && (u.Scheme == "http" || u.Scheme == "https") {
+				if _, err := web.GetBytes(u); errors.Is(err, fs.ErrNotExist) {
+					gitErr = notExistError{gitErr}
+				}
 			}
-		}
 
-		r.refsErr = gitErr
-		return
-	}
-
-	r.refs = make(map[string]string)
-	for _, line := range strings.Split(string(out), "\n") {
-		f := strings.Fields(line)
-		if len(f) != 2 {
-			continue
+			r.refsErr = gitErr
+			return
 		}
-		if f[1] == "HEAD" || strings.HasPrefix(f[1], "refs/heads/") || strings.HasPrefix(f[1], "refs/tags/") {
-			r.refs[f[1]] = f[0]
+
+		refs := make(map[string]string)
+		for _, line := range strings.Split(string(out), "\n") {
+			f := strings.Fields(line)
+			if len(f) != 2 {
+				continue
+			}
+			if f[1] == "HEAD" || strings.HasPrefix(f[1], "refs/heads/") || strings.HasPrefix(f[1], "refs/tags/") {
+				refs[f[1]] = f[0]
+			}
 		}
-	}
-	for ref, hash := range r.refs {
-		if strings.HasSuffix(ref, "^{}") { // record unwrapped annotated tag as value of tag
-			r.refs[strings.TrimSuffix(ref, "^{}")] = hash
-			delete(r.refs, ref)
+		for ref, hash := range refs {
+			if strings.HasSuffix(ref, "^{}") { // record unwrapped annotated tag as value of tag
+				refs[strings.TrimSuffix(ref, "^{}")] = hash
+				delete(refs, ref)
+			}
 		}
-	}
+		r.refs = refs
+	})
+	return r.refs, r.refsErr
 }
 
 func (r *gitRepo) Tags(prefix string) ([]string, error) {
-	r.refsOnce.Do(r.loadRefs)
-	if r.refsErr != nil {
-		return nil, r.refsErr
+	refs, err := r.loadRefs()
+	if err != nil {
+		return nil, err
 	}
 
 	tags := []string{}
-	for ref := range r.refs {
+	for ref := range refs {
 		if !strings.HasPrefix(ref, "refs/tags/") {
 			continue
 		}
@@ -237,14 +241,14 @@ func (r *gitRepo) Tags(prefix string) ([]string, error) {
 }
 
 func (r *gitRepo) Latest() (*RevInfo, error) {
-	r.refsOnce.Do(r.loadRefs)
-	if r.refsErr != nil {
-		return nil, r.refsErr
+	refs, err := r.loadRefs()
+	if err != nil {
+		return nil, err
 	}
-	if r.refs["HEAD"] == "" {
+	if refs["HEAD"] == "" {
 		return nil, ErrNoCommits
 	}
-	return r.Stat(r.refs["HEAD"])
+	return r.Stat(refs["HEAD"])
 }
 
 // findRef finds some ref name for the given hash,
@@ -252,8 +256,11 @@ func (r *gitRepo) Latest() (*RevInfo, error) {
 // There may be multiple ref names for a given hash,
 // in which case this returns some name - it doesn't matter which.
 func (r *gitRepo) findRef(hash string) (ref string, ok bool) {
-	r.refsOnce.Do(r.loadRefs)
-	for ref, h := range r.refs {
+	refs, err := r.loadRefs()
+	if err != nil {
+		return "", false
+	}
+	for ref, h := range refs {
 		if h == hash {
 			return ref, true
 		}
@@ -295,29 +302,32 @@ func (r *gitRepo) stat(rev string) (*RevInfo, error) {
 	// Maybe rev is the name of a tag or branch on the remote server.
 	// Or maybe it's the prefix of a hash of a named ref.
 	// Try to resolve to both a ref (git name) and full (40-hex-digit) commit hash.
-	r.refsOnce.Do(r.loadRefs)
+	refs, err := r.loadRefs()
+	if err != nil {
+		return nil, err
+	}
 	// loadRefs may return an error if git fails, for example segfaults, or
 	// could not load a private repo, but defer checking to the else block
 	// below, in case we already have the rev in question in the local cache.
 	var ref, hash string
-	if r.refs["refs/tags/"+rev] != "" {
+	if refs["refs/tags/"+rev] != "" {
 		ref = "refs/tags/" + rev
-		hash = r.refs[ref]
+		hash = refs[ref]
 		// Keep rev as is: tags are assumed not to change meaning.
-	} else if r.refs["refs/heads/"+rev] != "" {
+	} else if refs["refs/heads/"+rev] != "" {
 		ref = "refs/heads/" + rev
-		hash = r.refs[ref]
+		hash = refs[ref]
 		rev = hash // Replace rev, because meaning of refs/heads/foo can change.
-	} else if rev == "HEAD" && r.refs["HEAD"] != "" {
+	} else if rev == "HEAD" && refs["HEAD"] != "" {
 		ref = "HEAD"
-		hash = r.refs[ref]
+		hash = refs[ref]
 		rev = hash // Replace rev, because meaning of HEAD can change.
 	} else if len(rev) >= minHashDigits && len(rev) <= 40 && AllHex(rev) {
 		// At the least, we have a hash prefix we can look up after the fetch below.
 		// Maybe we can map it to a full hash using the known refs.
 		prefix := rev
 		// Check whether rev is prefix of known ref hash.
-		for k, h := range r.refs {
+		for k, h := range refs {
 			if strings.HasPrefix(h, prefix) {
 				if hash != "" && hash != h {
 					// Hash is an ambiguous hash prefix.
@@ -335,9 +345,6 @@ func (r *gitRepo) stat(rev string) (*RevInfo, error) {
 			hash = rev
 		}
 	} else {
-		if r.refsErr != nil {
-			return nil, r.refsErr
-		}
 		return nil, &UnknownRevisionError{Rev: rev}
 	}
 
@@ -496,7 +503,7 @@ func (r *gitRepo) Stat(rev string) (*RevInfo, error) {
 		info *RevInfo
 		err  error
 	}
-	c := r.statCache.Do(rev, func() interface{} {
+	c := r.statCache.Do(rev, func() any {
 		info, err := r.stat(rev)
 		return cached{info, err}
 	}).(cached)
@@ -516,140 +523,6 @@ func (r *gitRepo) ReadFile(rev, file string, maxSize int64) ([]byte, error) {
 	return out, nil
 }
 
-func (r *gitRepo) ReadFileRevs(revs []string, file string, maxSize int64) (map[string]*FileRev, error) {
-	// Create space to hold results.
-	files := make(map[string]*FileRev)
-	for _, rev := range revs {
-		f := &FileRev{Rev: rev}
-		files[rev] = f
-	}
-
-	// Collect locally-known revs.
-	need, err := r.readFileRevs(revs, file, files)
-	if err != nil {
-		return nil, err
-	}
-	if len(need) == 0 {
-		return files, nil
-	}
-
-	// Build list of known remote refs that might help.
-	var redo []string
-	r.refsOnce.Do(r.loadRefs)
-	if r.refsErr != nil {
-		return nil, r.refsErr
-	}
-	for _, tag := range need {
-		if r.refs["refs/tags/"+tag] != "" {
-			redo = append(redo, tag)
-		}
-	}
-	if len(redo) == 0 {
-		return files, nil
-	}
-
-	// Protect r.fetchLevel and the "fetch more and more" sequence.
-	// See stat method above.
-	unlock, err := r.mu.Lock()
-	if err != nil {
-		return nil, err
-	}
-	defer unlock()
-
-	if err := r.fetchRefsLocked(); err != nil {
-		return nil, err
-	}
-
-	if _, err := r.readFileRevs(redo, file, files); err != nil {
-		return nil, err
-	}
-
-	return files, nil
-}
-
-func (r *gitRepo) readFileRevs(tags []string, file string, fileMap map[string]*FileRev) (missing []string, err error) {
-	var stdin bytes.Buffer
-	for _, tag := range tags {
-		fmt.Fprintf(&stdin, "refs/tags/%s\n", tag)
-		fmt.Fprintf(&stdin, "refs/tags/%s:%s\n", tag, file)
-	}
-
-	data, err := RunWithStdin(r.dir, &stdin, "git", "cat-file", "--batch")
-	if err != nil {
-		return nil, err
-	}
-
-	next := func() (typ string, body []byte, ok bool) {
-		var line string
-		i := bytes.IndexByte(data, '\n')
-		if i < 0 {
-			return "", nil, false
-		}
-		line, data = string(bytes.TrimSpace(data[:i])), data[i+1:]
-		if strings.HasSuffix(line, " missing") {
-			return "missing", nil, true
-		}
-		f := strings.Fields(line)
-		if len(f) != 3 {
-			return "", nil, false
-		}
-		n, err := strconv.Atoi(f[2])
-		if err != nil || n > len(data) {
-			return "", nil, false
-		}
-		body, data = data[:n], data[n:]
-		if len(data) > 0 && data[0] == '\r' {
-			data = data[1:]
-		}
-		if len(data) > 0 && data[0] == '\n' {
-			data = data[1:]
-		}
-		return f[1], body, true
-	}
-
-	badGit := func() ([]string, error) {
-		return nil, fmt.Errorf("malformed output from git cat-file --batch")
-	}
-
-	for _, tag := range tags {
-		commitType, _, ok := next()
-		if !ok {
-			return badGit()
-		}
-		fileType, fileData, ok := next()
-		if !ok {
-			return badGit()
-		}
-		f := fileMap[tag]
-		f.Data = nil
-		f.Err = nil
-		switch commitType {
-		default:
-			f.Err = fmt.Errorf("unexpected non-commit type %q for rev %s", commitType, tag)
-
-		case "missing":
-			// Note: f.Err must not satisfy os.IsNotExist. That's reserved for the file not existing in a valid commit.
-			f.Err = fmt.Errorf("no such rev %s", tag)
-			missing = append(missing, tag)
-
-		case "tag", "commit":
-			switch fileType {
-			default:
-				f.Err = &fs.PathError{Path: tag + ":" + file, Op: "read", Err: fmt.Errorf("unexpected non-blob type %q", fileType)}
-			case "missing":
-				f.Err = &fs.PathError{Path: tag + ":" + file, Op: "read", Err: fs.ErrNotExist}
-			case "blob":
-				f.Data = fileData
-			}
-		}
-	}
-	if len(bytes.TrimSpace(data)) != 0 {
-		return badGit()
-	}
-
-	return missing, nil
-}
-
 func (r *gitRepo) RecentTag(rev, prefix string, allowed func(string) bool) (tag string, err error) {
 	info, err := r.Stat(rev)
 	if err != nil {
diff --git a/libgo/go/cmd/go/internal/modfetch/codehost/shell.go b/libgo/go/cmd/go/internal/modfetch/codehost/shell.go
index 0e9f3819667..eaa01950b95 100644
--- a/libgo/go/cmd/go/internal/modfetch/codehost/shell.go
+++ b/libgo/go/cmd/go/internal/modfetch/codehost/shell.go
@@ -3,7 +3,6 @@
 // license that can be found in the LICENSE file.
 
 //go:build ignore
-// +build ignore
 
 // Interactive debugging shell for codehost.Repo implementations.
 
diff --git a/libgo/go/cmd/go/internal/modfetch/codehost/vcs.go b/libgo/go/cmd/go/internal/modfetch/codehost/vcs.go
index c2cca084e30..de62265efc5 100644
--- a/libgo/go/cmd/go/internal/modfetch/codehost/vcs.go
+++ b/libgo/go/cmd/go/internal/modfetch/codehost/vcs.go
@@ -38,7 +38,7 @@ type VCSError struct {
 
 func (e *VCSError) Error() string { return e.Err.Error() }
 
-func vcsErrorf(format string, a ...interface{}) error {
+func vcsErrorf(format string, a ...any) error {
 	return &VCSError{Err: fmt.Errorf(format, a...)}
 }
 
@@ -51,7 +51,7 @@ func NewRepo(vcs, remote string) (Repo, error) {
 		repo Repo
 		err  error
 	}
-	c := vcsRepoCache.Do(key{vcs, remote}, func() interface{} {
+	c := vcsRepoCache.Do(key{vcs, remote}, func() any {
 		repo, err := newVCSRepo(vcs, remote)
 		if err != nil {
 			err = &VCSError{err}
@@ -382,19 +382,6 @@ func (r *vcsRepo) ReadFile(rev, file string, maxSize int64) ([]byte, error) {
 	return out, nil
 }
 
-func (r *vcsRepo) ReadFileRevs(revs []string, file string, maxSize int64) (map[string]*FileRev, error) {
-	// We don't technically need to lock here since we're returning an error
-	// uncondititonally, but doing so anyway will help to avoid baking in
-	// lock-inversion bugs.
-	unlock, err := r.mu.Lock()
-	if err != nil {
-		return nil, err
-	}
-	defer unlock()
-
-	return nil, vcsErrorf("ReadFileRevs not implemented")
-}
-
 func (r *vcsRepo) RecentTag(rev, prefix string, allowed func(string) bool) (tag string, err error) {
 	// We don't technically need to lock here since we're returning an error
 	// uncondititonally, but doing so anyway will help to avoid baking in
diff --git a/libgo/go/cmd/go/internal/modfetch/coderepo.go b/libgo/go/cmd/go/internal/modfetch/coderepo.go
index dfef9f73c27..79da010809b 100644
--- a/libgo/go/cmd/go/internal/modfetch/coderepo.go
+++ b/libgo/go/cmd/go/internal/modfetch/coderepo.go
@@ -321,7 +321,7 @@ func (r *codeRepo) convert(info *codehost.RevInfo, statVers string) (*RevInfo, e
 		return ok
 	}
 
-	invalidf := func(format string, args ...interface{}) error {
+	invalidf := func(format string, args ...any) error {
 		return &module.ModuleError{
 			Path: r.modPath,
 			Err: &module.InvalidVersionError{
@@ -567,11 +567,11 @@ func (r *codeRepo) validatePseudoVersion(info *codehost.RevInfo, version string)
 	if rev != info.Short {
 		switch {
 		case strings.HasPrefix(rev, info.Short):
-			return fmt.Errorf("revision is longer than canonical (%s)", info.Short)
+			return fmt.Errorf("revision is longer than canonical (expected %s)", info.Short)
 		case strings.HasPrefix(info.Short, rev):
-			return fmt.Errorf("revision is shorter than canonical (%s)", info.Short)
+			return fmt.Errorf("revision is shorter than canonical (expected %s)", info.Short)
 		default:
-			return fmt.Errorf("does not match short name of revision (%s)", info.Short)
+			return fmt.Errorf("does not match short name of revision (expected %s)", info.Short)
 		}
 	}
 
@@ -1066,7 +1066,7 @@ func (fi dataFileInfo) Size() int64        { return int64(len(fi.f.data)) }
 func (fi dataFileInfo) Mode() fs.FileMode  { return 0644 }
 func (fi dataFileInfo) ModTime() time.Time { return time.Time{} }
 func (fi dataFileInfo) IsDir() bool        { return false }
-func (fi dataFileInfo) Sys() interface{}   { return nil }
+func (fi dataFileInfo) Sys() any           { return nil }
 
 // hasPathPrefix reports whether the path s begins with the
 // elements in prefix.
diff --git a/libgo/go/cmd/go/internal/modfetch/fetch.go b/libgo/go/cmd/go/internal/modfetch/fetch.go
index d3d30d970b3..f5423b48ad3 100644
--- a/libgo/go/cmd/go/internal/modfetch/fetch.go
+++ b/libgo/go/cmd/go/internal/modfetch/fetch.go
@@ -48,7 +48,7 @@ func Download(ctx context.Context, mod module.Version) (dir string, err error) {
 		dir string
 		err error
 	}
-	c := downloadCache.Do(mod, func() interface{} {
+	c := downloadCache.Do(mod, func() any {
 		dir, err := download(ctx, mod)
 		if err != nil {
 			return cached{"", err}
@@ -165,7 +165,7 @@ func DownloadZip(ctx context.Context, mod module.Version) (zipfile string, err e
 		zipfile string
 		err     error
 	}
-	c := downloadZipCache.Do(mod, func() interface{} {
+	c := downloadZipCache.Do(mod, func() any {
 		zipfile, err := CachePath(mod, "zip")
 		if err != nil {
 			return cached{"", err}
@@ -384,7 +384,8 @@ func RemoveAll(dir string) error {
 	return robustio.RemoveAll(dir)
 }
 
-var GoSumFile string // path to go.sum; set by package modload
+var GoSumFile string             // path to go.sum; set by package modload
+var WorkspaceGoSumFiles []string // path to module go.sums in workspace; set by package modload
 
 type modSum struct {
 	mod module.Version
@@ -393,16 +394,39 @@ type modSum struct {
 
 var goSum struct {
 	mu        sync.Mutex
-	m         map[module.Version][]string // content of go.sum file
-	status    map[modSum]modSumStatus     // state of sums in m
-	overwrite bool                        // if true, overwrite go.sum without incorporating its contents
-	enabled   bool                        // whether to use go.sum at all
+	m         map[module.Version][]string            // content of go.sum file
+	w         map[string]map[module.Version][]string // sum file in workspace -> content of that sum file
+	status    map[modSum]modSumStatus                // state of sums in m
+	overwrite bool                                   // if true, overwrite go.sum without incorporating its contents
+	enabled   bool                                   // whether to use go.sum at all
 }
 
 type modSumStatus struct {
 	used, dirty bool
 }
 
+// Reset resets globals in the modfetch package, so previous loads don't affect
+// contents of go.sum files
+func Reset() {
+	GoSumFile = ""
+	WorkspaceGoSumFiles = nil
+
+	// Uses of lookupCache and downloadCache both can call checkModSum,
+	// which in turn sets the used bit on goSum.status for modules.
+	// Reset them so used can be computed properly.
+	lookupCache = par.Cache{}
+	downloadCache = par.Cache{}
+
+	// Clear all fields on goSum. It will be initialized later
+	goSum.mu.Lock()
+	goSum.m = nil
+	goSum.w = nil
+	goSum.status = nil
+	goSum.overwrite = false
+	goSum.enabled = false
+	goSum.mu.Unlock()
+}
+
 // initGoSum initializes the go.sum data.
 // The boolean it returns reports whether the
 // use of go.sum is now enabled.
@@ -417,23 +441,38 @@ func initGoSum() (bool, error) {
 
 	goSum.m = make(map[module.Version][]string)
 	goSum.status = make(map[modSum]modSumStatus)
+	goSum.w = make(map[string]map[module.Version][]string)
+
+	for _, f := range WorkspaceGoSumFiles {
+		goSum.w[f] = make(map[module.Version][]string)
+		_, err := readGoSumFile(goSum.w[f], f)
+		if err != nil {
+			return false, err
+		}
+	}
+
+	enabled, err := readGoSumFile(goSum.m, GoSumFile)
+	goSum.enabled = enabled
+	return enabled, err
+}
+
+func readGoSumFile(dst map[module.Version][]string, file string) (bool, error) {
 	var (
 		data []byte
 		err  error
 	)
-	if actualSumFile, ok := fsys.OverlayPath(GoSumFile); ok {
+	if actualSumFile, ok := fsys.OverlayPath(file); ok {
 		// Don't lock go.sum if it's part of the overlay.
 		// On Plan 9, locking requires chmod, and we don't want to modify any file
 		// in the overlay. See #44700.
 		data, err = os.ReadFile(actualSumFile)
 	} else {
-		data, err = lockedfile.Read(GoSumFile)
+		data, err = lockedfile.Read(file)
 	}
 	if err != nil && !os.IsNotExist(err) {
 		return false, err
 	}
-	goSum.enabled = true
-	readGoSum(goSum.m, GoSumFile, data)
+	readGoSum(dst, file, data)
 
 	return true, nil
 }
@@ -485,6 +524,16 @@ func HaveSum(mod module.Version) bool {
 	if err != nil || !inited {
 		return false
 	}
+	for _, goSums := range goSum.w {
+		for _, h := range goSums[mod] {
+			if !strings.HasPrefix(h, "h1:") {
+				continue
+			}
+			if !goSum.status[modSum{mod, h}].dirty {
+				return true
+			}
+		}
+	}
 	for _, h := range goSum.m[mod] {
 		if !strings.HasPrefix(h, "h1:") {
 			continue
@@ -602,15 +651,32 @@ func checkModSum(mod module.Version, h string) error {
 // If it finds a conflicting pair instead, it calls base.Fatalf.
 // goSum.mu must be locked.
 func haveModSumLocked(mod module.Version, h string) bool {
+	sumFileName := "go.sum"
+	if strings.HasSuffix(GoSumFile, "go.work.sum") {
+		sumFileName = "go.work.sum"
+	}
 	for _, vh := range goSum.m[mod] {
 		if h == vh {
 			return true
 		}
 		if strings.HasPrefix(vh, "h1:") {
-			base.Fatalf("verifying %s@%s: checksum mismatch\n\tdownloaded: %v\n\tgo.sum:     %v"+goSumMismatch, mod.Path, mod.Version, h, vh)
+			base.Fatalf("verifying %s@%s: checksum mismatch\n\tdownloaded: %v\n\t%s:     %v"+goSumMismatch, mod.Path, mod.Version, h, sumFileName, vh)
+		}
+	}
+	// Also check workspace sums.
+	foundMatch := false
+	// Check sums from all files in case there are conflicts between
+	// the files.
+	for goSumFile, goSums := range goSum.w {
+		for _, vh := range goSums[mod] {
+			if h == vh {
+				foundMatch = true
+			} else if strings.HasPrefix(vh, "h1:") {
+				base.Fatalf("verifying %s@%s: checksum mismatch\n\tdownloaded: %v\n\t%s:     %v"+goSumMismatch, mod.Path, mod.Version, h, goSumFile, vh)
+			}
 		}
 	}
-	return false
+	return foundMatch
 }
 
 // addModSumLocked adds the pair mod,h to go.sum.
@@ -693,19 +759,21 @@ func isValidSum(data []byte) bool {
 	return true
 }
 
+var ErrGoSumDirty = errors.New("updates to go.sum needed, disabled by -mod=readonly")
+
 // WriteGoSum writes the go.sum file if it needs to be updated.
 //
 // keep is used to check whether a newly added sum should be saved in go.sum.
 // It should have entries for both module content sums and go.mod sums
 // (version ends with "/go.mod"). Existing sums will be preserved unless they
 // have been marked for deletion with TrimGoSum.
-func WriteGoSum(keep map[module.Version]bool) {
+func WriteGoSum(keep map[module.Version]bool, readonly bool) error {
 	goSum.mu.Lock()
 	defer goSum.mu.Unlock()
 
 	// If we haven't read the go.sum file yet, don't bother writing it.
 	if !goSum.enabled {
-		return
+		return nil
 	}
 
 	// Check whether we need to add sums for which keep[m] is true or remove
@@ -723,10 +791,10 @@ Outer:
 		}
 	}
 	if !dirty {
-		return
+		return nil
 	}
-	if cfg.BuildMod == "readonly" {
-		base.Fatalf("go: updates to go.sum needed, disabled by -mod=readonly")
+	if readonly {
+		return ErrGoSumDirty
 	}
 	if _, ok := fsys.OverlayPath(GoSumFile); ok {
 		base.Fatalf("go: updates to go.sum needed, but go.sum is part of the overlay specified with -overlay")
@@ -747,7 +815,7 @@ Outer:
 			goSum.m = make(map[module.Version][]string, len(goSum.m))
 			readGoSum(goSum.m, GoSumFile, data)
 			for ms, st := range goSum.status {
-				if st.used {
+				if st.used && !sumInWorkspaceModulesLocked(ms.mod) {
 					addModSumLocked(ms.mod, ms.sum)
 				}
 			}
@@ -765,7 +833,7 @@ Outer:
 			sort.Strings(list)
 			for _, h := range list {
 				st := goSum.status[modSum{m, h}]
-				if !st.dirty || (st.used && keep[m]) {
+				if (!st.dirty || (st.used && keep[m])) && !sumInWorkspaceModulesLocked(m) {
 					fmt.Fprintf(&buf, "%s %s %s\n", m.Path, m.Version, h)
 				}
 			}
@@ -774,11 +842,21 @@ Outer:
 	})
 
 	if err != nil {
-		base.Fatalf("go: updating go.sum: %v", err)
+		return fmt.Errorf("updating go.sum: %w", err)
 	}
 
 	goSum.status = make(map[modSum]modSumStatus)
 	goSum.overwrite = false
+	return nil
+}
+
+func sumInWorkspaceModulesLocked(m module.Version) bool {
+	for _, goSums := range goSum.w {
+		if _, ok := goSums[m]; ok {
+			return true
+		}
+	}
+	return false
 }
 
 // TrimGoSum trims go.sum to contain only the modules needed for reproducible
diff --git a/libgo/go/cmd/go/internal/modfetch/repo.go b/libgo/go/cmd/go/internal/modfetch/repo.go
index 0bffa55af6f..1b42ecb6edb 100644
--- a/libgo/go/cmd/go/internal/modfetch/repo.go
+++ b/libgo/go/cmd/go/internal/modfetch/repo.go
@@ -196,7 +196,7 @@ func Lookup(proxy, path string) Repo {
 	type cached struct {
 		r Repo
 	}
-	c := lookupCache.Do(lookupCacheKey{proxy, path}, func() interface{} {
+	c := lookupCache.Do(lookupCacheKey{proxy, path}, func() any {
 		r := newCachingRepo(path, func() (Repo, error) {
 			r, err := lookup(proxy, path)
 			if err == nil && traceRepo {
@@ -308,7 +308,7 @@ func newLoggingRepo(r Repo) *loggingRepo {
 //	defer logCall("hello %s", arg)()
 //
 // Note the final ().
-func logCall(format string, args ...interface{}) func() {
+func logCall(format string, args ...any) func() {
 	start := time.Now()
 	fmt.Fprintf(os.Stderr, "+++ %s\n", fmt.Sprintf(format, args...))
 	return func() {
@@ -371,7 +371,7 @@ type notExistError struct {
 	err error
 }
 
-func notExistErrorf(format string, args ...interface{}) error {
+func notExistErrorf(format string, args ...any) error {
 	return notExistError{fmt.Errorf(format, args...)}
 }
 
diff --git a/libgo/go/cmd/go/internal/modfetch/sumdb.go b/libgo/go/cmd/go/internal/modfetch/sumdb.go
index f233cba6df1..492b03bd84a 100644
--- a/libgo/go/cmd/go/internal/modfetch/sumdb.go
+++ b/libgo/go/cmd/go/internal/modfetch/sumdb.go
@@ -5,7 +5,6 @@
 // Go checksum database lookup
 
 //go:build !cmd_go_bootstrap
-// +build !cmd_go_bootstrap
 
 package modfetch
 
@@ -201,7 +200,8 @@ func (c *dbClient) ReadConfig(file string) (data []byte, err error) {
 	}
 
 	if cfg.SumdbDir == "" {
-		return nil, errors.New("could not locate sumdb file: missing $GOPATH")
+		return nil, fmt.Errorf("could not locate sumdb file: missing $GOPATH: %s",
+			cfg.GoPathError)
 	}
 	targ := filepath.Join(cfg.SumdbDir, file)
 	data, err = lockedfile.Read(targ)
@@ -220,7 +220,8 @@ func (*dbClient) WriteConfig(file string, old, new []byte) error {
 		return fmt.Errorf("cannot write key")
 	}
 	if cfg.SumdbDir == "" {
-		return errors.New("could not locate sumdb file: missing $GOPATH")
+		return fmt.Errorf("could not locate sumdb file: missing $GOPATH: %s",
+			cfg.GoPathError)
 	}
 	targ := filepath.Join(cfg.SumdbDir, file)
 	os.MkdirAll(filepath.Dir(targ), 0777)
diff --git a/libgo/go/cmd/go/internal/modget/get.go b/libgo/go/cmd/go/internal/modget/get.go
index 9672e5598e0..3d8463e892c 100644
--- a/libgo/go/cmd/go/internal/modget/get.go
+++ b/libgo/go/cmd/go/internal/modget/get.go
@@ -37,7 +37,6 @@ import (
 
 	"cmd/go/internal/base"
 	"cmd/go/internal/imports"
-	"cmd/go/internal/load"
 	"cmd/go/internal/modfetch"
 	"cmd/go/internal/modload"
 	"cmd/go/internal/par"
@@ -50,14 +49,14 @@ import (
 )
 
 var CmdGet = &base.Command{
-	// Note: -d -u are listed explicitly because they are the most common get flags.
+	// Note: flags below are listed explicitly because they're the most common.
 	// Do not send CLs removing them because they're covered by [get flags].
-	UsageLine: "go get [-d] [-t] [-u] [-v] [build flags] [packages]",
+	UsageLine: "go get [-t] [-u] [-v] [build flags] [packages]",
 	Short:     "add dependencies to current module and install them",
 	Long: `
 Get resolves its command-line arguments to packages at specific module versions,
-updates go.mod to require those versions, downloads source code into the
-module cache, then builds and installs the named packages.
+updates go.mod to require those versions, and downloads source code into the
+module cache.
 
 To add a dependency for a package or upgrade it to its latest version:
 
@@ -73,17 +72,18 @@ To remove a dependency on a module and downgrade modules that require it:
 
 See https://golang.org/ref/mod#go-get for details.
 
-The 'go install' command may be used to build and install packages. When a
-version is specified, 'go install' runs in module-aware mode and ignores
-the go.mod file in the current directory. For example:
+In earlier versions of Go, 'go get' was used to build and install packages.
+Now, 'go get' is dedicated to adjusting dependencies in go.mod. 'go install'
+may be used to build and install commands instead. When a version is specified,
+'go install' runs in module-aware mode and ignores the go.mod file in the
+current directory. For example:
 
 	go install example.com/pkg@v1.2.3
 	go install example.com/pkg@latest
 
 See 'go help install' or https://golang.org/ref/mod#go-install for details.
 
-In addition to build flags (listed in 'go help build') 'go get' accepts the
-following flags.
+'go get' accepts the following flags.
 
 The -t flag instructs get to consider modules needed to build tests of
 packages specified on the command line.
@@ -98,15 +98,9 @@ but changes the default to select patch releases.
 When the -t and -u flags are used together, get will update
 test dependencies as well.
 
-The -d flag instructs get not to build or install packages. get will only
-update go.mod and download source code needed to build packages.
-
-Building and installing packages with get is deprecated. In a future release,
-the -d flag will be enabled by default, and 'go get' will be only be used to
-adjust dependencies of the current module. To install a package using
-dependencies from the current module, use 'go install'. To install a package
-ignoring the current module, use 'go install' with an @version suffix like
-"@latest" after each argument.
+The -x flag prints commands as they are executed. This is useful for
+debugging version control commands when a module is downloaded directly
+from a repository.
 
 For more about modules, see https://golang.org/ref/mod.
 
@@ -218,7 +212,7 @@ variable for future go command invocations.
 }
 
 var (
-	getD        = CmdGet.Flag.Bool("d", false, "")
+	getD        = CmdGet.Flag.Bool("d", true, "")
 	getF        = CmdGet.Flag.Bool("f", false, "")
 	getFix      = CmdGet.Flag.Bool("fix", false, "")
 	getM        = CmdGet.Flag.Bool("m", false, "")
@@ -263,30 +257,50 @@ func runGet(ctx context.Context, cmd *base.Command, args []string) {
 	case "", "upgrade", "patch":
 		// ok
 	default:
-		base.Fatalf("go get: unknown upgrade flag -u=%s", getU.rawVersion)
+		base.Fatalf("go: unknown upgrade flag -u=%s", getU.rawVersion)
+	}
+	// TODO(#43684): in the future (Go 1.20), warn that -d is a no-op.
+	if !*getD {
+		base.Fatalf("go: -d flag may not be disabled")
 	}
 	if *getF {
-		fmt.Fprintf(os.Stderr, "go get: -f flag is a no-op when using modules\n")
+		fmt.Fprintf(os.Stderr, "go: -f flag is a no-op when using modules\n")
 	}
 	if *getFix {
-		fmt.Fprintf(os.Stderr, "go get: -fix flag is a no-op when using modules\n")
+		fmt.Fprintf(os.Stderr, "go: -fix flag is a no-op when using modules\n")
 	}
 	if *getM {
-		base.Fatalf("go get: -m flag is no longer supported; consider -d to skip building packages")
+		base.Fatalf("go: -m flag is no longer supported")
 	}
 	if *getInsecure {
-		base.Fatalf("go get: -insecure flag is no longer supported; use GOINSECURE instead")
+		base.Fatalf("go: -insecure flag is no longer supported; use GOINSECURE instead")
 	}
 
+	modload.ForceUseModules = true
+
 	// Do not allow any updating of go.mod until we've applied
 	// all the requested changes and checked that the result matches
 	// what was requested.
-	modload.DisallowWriteGoMod()
+	modload.ExplicitWriteGoMod = true
 
 	// Allow looking up modules for import paths when outside of a module.
 	// 'go get' is expected to do this, unlike other commands.
 	modload.AllowMissingModuleImports()
 
+	// 'go get' no longer builds or installs packages, so there's nothing to do
+	// if there's no go.mod file.
+	// TODO(#40775): make modload.Init return ErrNoModRoot instead of exiting.
+	// We could handle that here by printing a different message.
+	modload.Init()
+	if !modload.HasModRoot() {
+		base.Fatalf("go: go.mod file not found in current directory or any parent directory.\n" +
+			"\t'go get' is no longer supported outside a module.\n" +
+			"\tTo build and install a command, use 'go install' with a version,\n" +
+			"\tlike 'go install example.com/cmd@latest'\n" +
+			"\tFor more information, see https://golang.org/doc/go-get-install-deprecation\n" +
+			"\tor run 'go help get' or 'go help install'.")
+	}
+
 	queries := parseArgs(ctx, args)
 
 	r := newResolver(ctx, queries)
@@ -356,74 +370,12 @@ func runGet(ctx context.Context, cmd *base.Command, args []string) {
 	}
 	r.checkPackageProblems(ctx, pkgPatterns)
 
-	// We've already downloaded modules (and identified direct and indirect
-	// dependencies) by loading packages in findAndUpgradeImports.
-	// So if -d is set, we're done after the module work.
-	//
-	// Otherwise, we need to build and install the packages matched by
-	// command line arguments.
-	// Note that 'go get -u' without arguments is equivalent to
-	// 'go get -u .', so we'll typically build the package in the current
-	// directory.
-	if !*getD && len(pkgPatterns) > 0 {
-		work.BuildInit()
-
-		pkgOpts := load.PackageOpts{ModResolveTests: *getT}
-		var pkgs []*load.Package
-		for _, pkg := range load.PackagesAndErrors(ctx, pkgOpts, pkgPatterns) {
-			if pkg.Error != nil {
-				var noGo *load.NoGoError
-				if errors.As(pkg.Error.Err, &noGo) {
-					if m := modload.PackageModule(pkg.ImportPath); m.Path == pkg.ImportPath {
-						// pkg is at the root of a module, and doesn't exist with the current
-						// build tags. Probably the user just wanted to change the version of
-						// that module — not also build the package — so suppress the error.
-						// (See https://golang.org/issue/33526.)
-						continue
-					}
-				}
-			}
-			pkgs = append(pkgs, pkg)
-		}
-		load.CheckPackageErrors(pkgs)
-
-		haveExternalExe := false
-		for _, pkg := range pkgs {
-			if pkg.Name == "main" && pkg.Module != nil && pkg.Module.Path != modload.Target.Path {
-				haveExternalExe = true
-				break
-			}
-		}
-		if haveExternalExe {
-			fmt.Fprint(os.Stderr, "go get: installing executables with 'go get' in module mode is deprecated.")
-			var altMsg string
-			if modload.HasModRoot() {
-				altMsg = `
-	To adjust and download dependencies of the current module, use 'go get -d'.
-	To install using requirements of the current module, use 'go install'.
-	To install ignoring the current module, use 'go install' with a version,
-	like 'go install example.com/cmd@latest'.
-`
-			} else {
-				altMsg = "\n\tUse 'go install pkg@version' instead.\n"
-			}
-			fmt.Fprint(os.Stderr, altMsg)
-			fmt.Fprintf(os.Stderr, "\tFor more information, see https://golang.org/doc/go-get-install-deprecation\n\tor run 'go help get' or 'go help install'.\n")
-		}
-
-		work.InstallPackages(ctx, pkgPatterns, pkgs)
-	}
-
-	if !modload.HasModRoot() {
-		return
-	}
-
 	// Everything succeeded. Update go.mod.
 	oldReqs := reqsFromGoMod(modload.ModFile())
 
-	modload.AllowWriteGoMod()
-	modload.WriteGoMod(ctx)
-	modload.DisallowWriteGoMod()
+	if err := modload.WriteGoMod(ctx); err != nil {
+		base.Fatalf("go: %v", err)
+	}
 
 	newReqs := reqsFromGoMod(modload.ModFile())
 	r.reportChanges(oldReqs, newReqs)
@@ -440,7 +392,7 @@ func parseArgs(ctx context.Context, rawArgs []string) []*query {
 	for _, arg := range search.CleanPatterns(rawArgs) {
 		q, err := newQuery(arg)
 		if err != nil {
-			base.Errorf("go get: %v", err)
+			base.Errorf("go: %v", err)
 			continue
 		}
 
@@ -455,11 +407,11 @@ func parseArgs(ctx context.Context, rawArgs []string) []*query {
 		// if the argument has no version and either has no slash or refers to an existing file.
 		if strings.HasSuffix(q.raw, ".go") && q.rawVersion == "" {
 			if !strings.Contains(q.raw, "/") {
-				base.Errorf("go get %s: arguments must be package or module paths", q.raw)
+				base.Errorf("go: %s: arguments must be package or module paths", q.raw)
 				continue
 			}
 			if fi, err := os.Stat(q.raw); err == nil && !fi.IsDir() {
-				base.Errorf("go get: %s exists as a file, but 'go get' requires package arguments", q.raw)
+				base.Errorf("go: %s exists as a file, but 'go get' requires package arguments", q.raw)
 				continue
 			}
 		}
@@ -649,7 +601,7 @@ func (r *resolver) matchInModule(ctx context.Context, pattern string, m module.V
 		err      error
 	}
 
-	e := r.matchInModuleCache.Do(key{pattern, m}, func() interface{} {
+	e := r.matchInModuleCache.Do(key{pattern, m}, func() any {
 		match := modload.MatchInModule(ctx, pattern, m, imports.AnyTags())
 		if len(match.Errs) > 0 {
 			return entry{match.Pkgs, match.Errs[0]}
@@ -675,7 +627,9 @@ func (r *resolver) queryNone(ctx context.Context, q *query) {
 
 	if !q.isWildcard() {
 		q.pathOnce(q.pattern, func() pathSet {
-			if modload.HasModRoot() && q.pattern == modload.Target.Path {
+			hasModRoot := modload.HasModRoot()
+			if hasModRoot && modload.MainModules.Contains(q.pattern) {
+				v := module.Version{Path: q.pattern}
 				// The user has explicitly requested to downgrade their own module to
 				// version "none". This is not an entirely unreasonable request: it
 				// could plausibly mean “downgrade away everything that depends on any
@@ -686,7 +640,7 @@ func (r *resolver) queryNone(ctx context.Context, q *query) {
 				// However, neither of those behaviors would be consistent with the
 				// plain meaning of the query. To try to reduce confusion, reject the
 				// query explicitly.
-				return errSet(&modload.QueryMatchesMainModuleError{Pattern: q.pattern, Query: q.version})
+				return errSet(&modload.QueryMatchesMainModulesError{MainModules: []module.Version{v}, Pattern: q.pattern, Query: q.version})
 			}
 
 			return pathSet{mod: module.Version{Path: q.pattern, Version: "none"}}
@@ -698,8 +652,8 @@ func (r *resolver) queryNone(ctx context.Context, q *query) {
 			continue
 		}
 		q.pathOnce(curM.Path, func() pathSet {
-			if modload.HasModRoot() && curM == modload.Target {
-				return errSet(&modload.QueryMatchesMainModuleError{Pattern: q.pattern, Query: q.version})
+			if modload.HasModRoot() && curM.Version == "" && modload.MainModules.Contains(curM.Path) {
+				return errSet(&modload.QueryMatchesMainModulesError{MainModules: []module.Version{curM}, Pattern: q.pattern, Query: q.version})
 			}
 			return pathSet{mod: module.Version{Path: curM.Path, Version: "none"}}
 		})
@@ -718,28 +672,38 @@ func (r *resolver) performLocalQueries(ctx context.Context) {
 
 			// Absolute paths like C:\foo and relative paths like ../foo... are
 			// restricted to matching packages in the main module.
-			pkgPattern := modload.DirImportPath(ctx, q.pattern)
+			pkgPattern, mainModule := modload.MainModules.DirImportPath(ctx, q.pattern)
 			if pkgPattern == "." {
-				return errSet(fmt.Errorf("%s%s is not within module rooted at %s", q.pattern, absDetail, modload.ModRoot()))
+				modload.MustHaveModRoot()
+				var modRoots []string
+				for _, m := range modload.MainModules.Versions() {
+					modRoots = append(modRoots, modload.MainModules.ModRoot(m))
+				}
+				var plural string
+				if len(modRoots) != 1 {
+					plural = "s"
+				}
+				return errSet(fmt.Errorf("%s%s is not within module%s rooted at %s", q.pattern, absDetail, plural, strings.Join(modRoots, ", ")))
 			}
 
-			match := modload.MatchInModule(ctx, pkgPattern, modload.Target, imports.AnyTags())
+			match := modload.MatchInModule(ctx, pkgPattern, mainModule, imports.AnyTags())
 			if len(match.Errs) > 0 {
 				return pathSet{err: match.Errs[0]}
 			}
 
 			if len(match.Pkgs) == 0 {
 				if q.raw == "" || q.raw == "." {
-					return errSet(fmt.Errorf("no package in current directory"))
+					return errSet(fmt.Errorf("no package to get in current directory"))
 				}
 				if !q.isWildcard() {
-					return errSet(fmt.Errorf("%s%s is not a package in module rooted at %s", q.pattern, absDetail, modload.ModRoot()))
+					modload.MustHaveModRoot()
+					return errSet(fmt.Errorf("%s%s is not a package in module rooted at %s", q.pattern, absDetail, modload.MainModules.ModRoot(mainModule)))
 				}
 				search.WarnUnmatched([]*search.Match{match})
 				return pathSet{}
 			}
 
-			return pathSet{pkgMods: []module.Version{modload.Target}}
+			return pathSet{pkgMods: []module.Version{mainModule}}
 		})
 	}
 }
@@ -789,11 +753,12 @@ func (r *resolver) queryWildcard(ctx context.Context, q *query) {
 				return pathSet{}
 			}
 
-			if curM.Path == modload.Target.Path && !versionOkForMainModule(q.version) {
+			if modload.MainModules.Contains(curM.Path) && !versionOkForMainModule(q.version) {
 				if q.matchesPath(curM.Path) {
-					return errSet(&modload.QueryMatchesMainModuleError{
-						Pattern: q.pattern,
-						Query:   q.version,
+					return errSet(&modload.QueryMatchesMainModulesError{
+						MainModules: []module.Version{curM},
+						Pattern:     q.pattern,
+						Query:       q.version,
 					})
 				}
 
@@ -928,7 +893,7 @@ func (r *resolver) checkWildcardVersions(ctx context.Context) {
 					// curM at its original version contains a path matching q.pattern,
 					// but at rev.Version it does not, so (somewhat paradoxically) if
 					// we changed the version of curM it would no longer match the query.
-					var version interface{} = m
+					var version any = m
 					if rev.Version != q.version {
 						version = fmt.Sprintf("%s@%s (%s)", m.Path, q.version, m.Version)
 					}
@@ -1159,8 +1124,8 @@ func (r *resolver) loadPackages(ctx context.Context, patterns []string, findPack
 	}
 
 	opts.AllowPackage = func(ctx context.Context, path string, m module.Version) error {
-		if m.Path == "" || m == modload.Target {
-			// Packages in the standard library and main module are already at their
+		if m.Path == "" || m.Version == "" {
+			// Packages in the standard library and main modules are already at their
 			// latest (and only) available versions.
 			return nil
 		}
@@ -1327,7 +1292,7 @@ func (r *resolver) applyUpgrades(ctx context.Context, upgrades []pathSet) (chang
 	var tentative []module.Version
 	for _, cs := range upgrades {
 		if cs.err != nil {
-			base.Errorf("go get: %v", cs.err)
+			base.Errorf("go: %v", cs.err)
 			continue
 		}
 
@@ -1370,11 +1335,11 @@ func (r *resolver) disambiguate(cs pathSet) (filtered pathSet, isPackage bool, m
 			continue
 		}
 
-		if m.Path == modload.Target.Path {
-			if m.Version == modload.Target.Version {
+		if modload.MainModules.Contains(m.Path) {
+			if m.Version == "" {
 				return pathSet{}, true, m, true
 			}
-			// The main module can only be set to its own version.
+			// A main module can only be set to its own version.
 			continue
 		}
 
@@ -1720,13 +1685,13 @@ func (r *resolver) reportChanges(oldReqs, newReqs []module.Version) {
 	})
 	for _, c := range sortedChanges {
 		if c.old == "" {
-			fmt.Fprintf(os.Stderr, "go get: added %s %s\n", c.path, c.new)
+			fmt.Fprintf(os.Stderr, "go: added %s %s\n", c.path, c.new)
 		} else if c.new == "none" || c.new == "" {
-			fmt.Fprintf(os.Stderr, "go get: removed %s %s\n", c.path, c.old)
+			fmt.Fprintf(os.Stderr, "go: removed %s %s\n", c.path, c.old)
 		} else if semver.Compare(c.new, c.old) > 0 {
-			fmt.Fprintf(os.Stderr, "go get: upgraded %s %s => %s\n", c.path, c.old, c.new)
+			fmt.Fprintf(os.Stderr, "go: upgraded %s %s => %s\n", c.path, c.old, c.new)
 		} else {
-			fmt.Fprintf(os.Stderr, "go get: downgraded %s %s => %s\n", c.path, c.old, c.new)
+			fmt.Fprintf(os.Stderr, "go: downgraded %s %s => %s\n", c.path, c.old, c.new)
 		}
 	}
 
@@ -1744,10 +1709,11 @@ func (r *resolver) resolve(q *query, m module.Version) {
 		panic("internal error: resolving a module.Version with an empty path")
 	}
 
-	if m.Path == modload.Target.Path && m.Version != modload.Target.Version {
-		reportError(q, &modload.QueryMatchesMainModuleError{
-			Pattern: q.pattern,
-			Query:   q.version,
+	if modload.MainModules.Contains(m.Path) && m.Version != "" {
+		reportError(q, &modload.QueryMatchesMainModulesError{
+			MainModules: []module.Version{{Path: m.Path}},
+			Pattern:     q.pattern,
+			Query:       q.version,
 		})
 		return
 	}
@@ -1775,7 +1741,7 @@ func (r *resolver) updateBuildList(ctx context.Context, additions []module.Versi
 
 	resolved := make([]module.Version, 0, len(r.resolvedVersion))
 	for mPath, rv := range r.resolvedVersion {
-		if mPath != modload.Target.Path {
+		if !modload.MainModules.Contains(mPath) {
 			resolved = append(resolved, module.Version{Path: mPath, Version: rv.version})
 		}
 	}
@@ -1784,7 +1750,7 @@ func (r *resolver) updateBuildList(ctx context.Context, additions []module.Versi
 	if err != nil {
 		var constraint *modload.ConstraintError
 		if !errors.As(err, &constraint) {
-			base.Errorf("go get: %v", err)
+			base.Errorf("go: %v", err)
 			return false
 		}
 
@@ -1796,7 +1762,7 @@ func (r *resolver) updateBuildList(ctx context.Context, additions []module.Versi
 			return rv.reason.ResolvedString(module.Version{Path: m.Path, Version: rv.version})
 		}
 		for _, c := range constraint.Conflicts {
-			base.Errorf("go get: %v requires %v, not %v", reason(c.Source), c.Dep, reason(c.Constraint))
+			base.Errorf("go: %v requires %v, not %v", reason(c.Source), c.Dep, reason(c.Constraint))
 		}
 		return false
 	}
diff --git a/libgo/go/cmd/go/internal/modget/query.go b/libgo/go/cmd/go/internal/modget/query.go
index 1a5a60f7eb9..887cb51b317 100644
--- a/libgo/go/cmd/go/internal/modget/query.go
+++ b/libgo/go/cmd/go/internal/modget/query.go
@@ -192,9 +192,9 @@ func (q *query) validate() error {
 			// TODO(bcmills): "all@none" seems like a totally reasonable way to
 			// request that we remove all module requirements, leaving only the main
 			// module and standard library. Perhaps we should implement that someday.
-			return &modload.QueryMatchesMainModuleError{
-				Pattern: q.pattern,
-				Query:   q.version,
+			return &modload.QueryUpgradesAllError{
+				MainModules: modload.MainModules.Versions(),
+				Query:       q.version,
 			}
 		}
 	}
@@ -284,21 +284,21 @@ func reportError(q *query, err error) {
 	patternRE := regexp.MustCompile("(?m)(?:[ \t(\"`]|^)" + regexp.QuoteMeta(q.pattern) + "(?:[ @:;)\"`]|$)")
 	if patternRE.MatchString(errStr) {
 		if q.rawVersion == "" {
-			base.Errorf("go get: %s", errStr)
+			base.Errorf("go: %s", errStr)
 			return
 		}
 
 		versionRE := regexp.MustCompile("(?m)(?:[ @(\"`]|^)" + regexp.QuoteMeta(q.version) + "(?:[ :;)\"`]|$)")
 		if versionRE.MatchString(errStr) {
-			base.Errorf("go get: %s", errStr)
+			base.Errorf("go: %s", errStr)
 			return
 		}
 	}
 
 	if qs := q.String(); qs != "" {
-		base.Errorf("go get %s: %s", qs, errStr)
+		base.Errorf("go: %s: %s", qs, errStr)
 	} else {
-		base.Errorf("go get: %s", errStr)
+		base.Errorf("go: %s", errStr)
 	}
 }
 
diff --git a/libgo/go/cmd/go/internal/modload/build.go b/libgo/go/cmd/go/internal/modload/build.go
index becf6b87f80..bfc73cc2f9a 100644
--- a/libgo/go/cmd/go/internal/modload/build.go
+++ b/libgo/go/cmd/go/internal/modload/build.go
@@ -5,7 +5,6 @@
 package modload
 
 import (
-	"bytes"
 	"context"
 	"encoding/hex"
 	"errors"
@@ -80,7 +79,7 @@ func ModuleInfo(ctx context.Context, path string) *modinfo.ModulePublic {
 		v  string
 		ok bool
 	)
-	if rs.depth == lazy {
+	if rs.pruning == pruned {
 		v, ok = rs.rootSelected(path)
 	}
 	if !ok {
@@ -212,20 +211,20 @@ func addDeprecation(ctx context.Context, m *modinfo.ModulePublic) {
 // in rs (which may be nil to indicate that m was not loaded from a requirement
 // graph).
 func moduleInfo(ctx context.Context, rs *Requirements, m module.Version, mode ListMode) *modinfo.ModulePublic {
-	if m == Target {
+	if m.Version == "" && MainModules.Contains(m.Path) {
 		info := &modinfo.ModulePublic{
 			Path:    m.Path,
 			Version: m.Version,
 			Main:    true,
 		}
-		if v, ok := rawGoVersion.Load(Target); ok {
+		if v, ok := rawGoVersion.Load(m); ok {
 			info.GoVersion = v.(string)
 		} else {
 			panic("internal error: GoVersion not set for main module")
 		}
-		if HasModRoot() {
-			info.Dir = ModRoot()
-			info.GoMod = ModFilePath()
+		if modRoot := MainModules.ModRoot(m); modRoot != "" {
+			info.Dir = modRoot
+			info.GoMod = modFilePath(modRoot)
 		}
 		return info
 	}
@@ -322,7 +321,7 @@ func moduleInfo(ctx context.Context, rs *Requirements, m module.Version, mode Li
 		if filepath.IsAbs(r.Path) {
 			info.Replace.Dir = r.Path
 		} else {
-			info.Replace.Dir = filepath.Join(ModRoot(), r.Path)
+			info.Replace.Dir = filepath.Join(replaceRelativeTo(), r.Path)
 		}
 		info.Replace.GoMod = filepath.Join(info.Replace.Dir, "go.mod")
 	}
@@ -336,116 +335,33 @@ func moduleInfo(ctx context.Context, rs *Requirements, m module.Version, mode Li
 	return info
 }
 
-// PackageBuildInfo returns a string containing module version information
-// for modules providing packages named by path and deps. path and deps must
-// name packages that were resolved successfully with LoadPackages.
-func PackageBuildInfo(path string, deps []string) string {
-	if isStandardImportPath(path) || !Enabled() {
-		return ""
-	}
-
-	target := mustFindModule(loaded, path, path)
-	mdeps := make(map[module.Version]bool)
-	for _, dep := range deps {
-		if !isStandardImportPath(dep) {
-			mdeps[mustFindModule(loaded, path, dep)] = true
-		}
-	}
-	var mods []module.Version
-	delete(mdeps, target)
-	for mod := range mdeps {
-		mods = append(mods, mod)
-	}
-	module.Sort(mods)
-
-	var buf bytes.Buffer
-	fmt.Fprintf(&buf, "path\t%s\n", path)
-
-	writeEntry := func(token string, m module.Version) {
-		mv := m.Version
-		if mv == "" {
-			mv = "(devel)"
-		}
-		fmt.Fprintf(&buf, "%s\t%s\t%s", token, m.Path, mv)
-		if r := Replacement(m); r.Path == "" {
-			fmt.Fprintf(&buf, "\t%s\n", modfetch.Sum(m))
-		} else {
-			fmt.Fprintf(&buf, "\n=>\t%s\t%s\t%s\n", r.Path, r.Version, modfetch.Sum(r))
-		}
-	}
-
-	writeEntry("mod", target)
-	for _, mod := range mods {
-		writeEntry("dep", mod)
-	}
-
-	return buf.String()
-}
-
-// mustFindModule is like findModule, but it calls base.Fatalf if the
-// module can't be found.
-//
-// TODO(jayconrod): remove this. Callers should use findModule and return
-// errors instead of relying on base.Fatalf.
-func mustFindModule(ld *loader, target, path string) module.Version {
-	pkg, ok := ld.pkgCache.Get(path).(*loadPkg)
-	if ok {
-		if pkg.err != nil {
-			base.Fatalf("build %v: cannot load %v: %v", target, path, pkg.err)
-		}
-		return pkg.mod
-	}
-
-	if path == "command-line-arguments" {
-		return Target
-	}
-
-	base.Fatalf("build %v: cannot find module for path %v", target, path)
-	panic("unreachable")
-}
-
 // findModule searches for the module that contains the package at path.
 // If the package was loaded, its containing module and true are returned.
-// Otherwise, module.Version{} and false are returend.
+// Otherwise, module.Version{} and false are returned.
 func findModule(ld *loader, path string) (module.Version, bool) {
 	if pkg, ok := ld.pkgCache.Get(path).(*loadPkg); ok {
 		return pkg.mod, pkg.mod != module.Version{}
 	}
-	if path == "command-line-arguments" {
-		return Target, true
-	}
 	return module.Version{}, false
 }
 
 func ModInfoProg(info string, isgccgo bool) []byte {
-	// Inject a variable with the debug information as runtime.modinfo,
-	// but compile it in package main so that it is specific to the binary.
-	// The variable must be a literal so that it will have the correct value
-	// before the initializer for package main runs.
-	//
-	// The runtime startup code refers to the variable, which keeps it live
-	// in all binaries.
-	//
-	// Note: we use an alternate recipe below for gccgo (based on an
-	// init function) due to the fact that gccgo does not support
-	// applying a "//go:linkname" directive to a variable. This has
-	// drawbacks in that other packages may want to look at the module
-	// info in their init functions (see issue 29628), which won't
-	// work for gccgo. See also issue 30344.
-
-	if !isgccgo {
-		return []byte(fmt.Sprintf(`package main
-import _ "unsafe"
-//go:linkname __set_modinfo__ runtime.setmodinfo
-func __set_modinfo__(string)
-func init() { __set_modinfo__(%q) }
-	`, string(infoStart)+info+string(infoEnd)))
-	} else {
+	// Inject an init function to set runtime.modinfo.
+	// This is only used for gccgo - with gc we hand the info directly to the linker.
+	// The init function has the drawback that packages may want to
+	// look at the module info in their init functions (see issue 29628),
+	// which won't work. See also issue 30344.
+	if isgccgo {
 		return []byte(fmt.Sprintf(`package main
 import _ "unsafe"
 //go:linkname __set_debug_modinfo__ runtime.setmodinfo
 func __set_debug_modinfo__(string)
 func init() { __set_debug_modinfo__(%q) }
-`, string(infoStart)+info+string(infoEnd)))
+`, ModInfoData(info)))
 	}
+	return nil
+}
+
+func ModInfoData(info string) []byte {
+	return []byte(string(infoStart) + info + string(infoEnd))
 }
diff --git a/libgo/go/cmd/go/internal/modload/buildlist.go b/libgo/go/cmd/go/internal/modload/buildlist.go
index bf695673167..6f9072c8c48 100644
--- a/libgo/go/cmd/go/internal/modload/buildlist.go
+++ b/libgo/go/cmd/go/internal/modload/buildlist.go
@@ -30,18 +30,25 @@ func capVersionSlice(s []module.Version) []module.Version {
 
 // A Requirements represents a logically-immutable set of root module requirements.
 type Requirements struct {
-	// depth is the depth at which the requirement graph is computed.
+	// pruning is the pruning at which the requirement graph is computed.
 	//
-	// If eager, the graph includes all transitive requirements regardless of depth.
+	// If unpruned, the graph includes all transitive requirements regardless
+	// of whether the requiring module supports pruning.
 	//
-	// If lazy, the graph includes only the root modules, the explicit
+	// If pruned, the graph includes only the root modules, the explicit
 	// requirements of those root modules, and the transitive requirements of only
-	// the *non-lazy* root modules.
-	depth modDepth
-
-	// rootModules is the set of module versions explicitly required by the main
-	// module, sorted and capped to length. It may contain duplicates, and may
-	// contain multiple versions for a given module path.
+	// the root modules that do not support pruning.
+	//
+	// If workspace, the graph includes only the workspace modules, the explicit
+	// requirements of the workspace modules, and the transitive requirements of
+	// the workspace modules that do not support pruning.
+	pruning modPruning
+
+	// rootModules is the set of root modules of the graph, sorted and capped to
+	// length. It may contain duplicates, and may contain multiple versions for a
+	// given module path. The root modules of the groph are the set of main
+	// modules in workspace mode, and the main module's direct requirements
+	// outside workspace mode.
 	rootModules    []module.Version
 	maxRootVersion map[string]string
 
@@ -97,10 +104,23 @@ var requirements *Requirements
 //
 // If vendoring is in effect, the caller must invoke initVendor on the returned
 // *Requirements before any other method.
-func newRequirements(depth modDepth, rootModules []module.Version, direct map[string]bool) *Requirements {
+func newRequirements(pruning modPruning, rootModules []module.Version, direct map[string]bool) *Requirements {
+	if pruning == workspace {
+		return &Requirements{
+			pruning:        pruning,
+			rootModules:    capVersionSlice(rootModules),
+			maxRootVersion: nil,
+			direct:         direct,
+		}
+	}
+
+	if workFilePath != "" && pruning != workspace {
+		panic("in workspace mode, but pruning is not workspace in newRequirements")
+	}
+
 	for i, m := range rootModules {
-		if m == Target {
-			panic(fmt.Sprintf("newRequirements called with untrimmed build list: rootModules[%v] is Target", i))
+		if m.Version == "" && MainModules.Contains(m.Path) {
+			panic(fmt.Sprintf("newRequirements called with untrimmed build list: rootModules[%v] is a main module", i))
 		}
 		if m.Path == "" || m.Version == "" {
 			panic(fmt.Sprintf("bad requirement: rootModules[%v] = %v", i, m))
@@ -114,7 +134,7 @@ func newRequirements(depth modDepth, rootModules []module.Version, direct map[st
 	}
 
 	rs := &Requirements{
-		depth:          depth,
+		pruning:        pruning,
 		rootModules:    capVersionSlice(rootModules),
 		maxRootVersion: make(map[string]string, len(rootModules)),
 		direct:         direct,
@@ -135,13 +155,18 @@ func newRequirements(depth modDepth, rootModules []module.Version, direct map[st
 func (rs *Requirements) initVendor(vendorList []module.Version) {
 	rs.graphOnce.Do(func() {
 		mg := &ModuleGraph{
-			g: mvs.NewGraph(cmpVersion, []module.Version{Target}),
+			g: mvs.NewGraph(cmpVersion, MainModules.Versions()),
 		}
 
-		if rs.depth == lazy {
-			// The roots of a lazy module should already include every module in the
-			// vendor list, because the vendored modules are the same as those
-			// maintained as roots by the lazy loading “import invariant”.
+		if MainModules.Len() != 1 {
+			panic("There should be exactly one main module in Vendor mode.")
+		}
+		mainModule := MainModules.Versions()[0]
+
+		if rs.pruning == pruned {
+			// The roots of a pruned module should already include every module in the
+			// vendor list, because the vendored modules are the same as those needed
+			// for graph pruning.
 			//
 			// Just to be sure, we'll double-check that here.
 			inconsistent := false
@@ -156,9 +181,9 @@ func (rs *Requirements) initVendor(vendorList []module.Version) {
 			}
 
 			// Now we can treat the rest of the module graph as effectively “pruned
-			// out”, like a more aggressive version of lazy loading: in vendor mode,
-			// the root requirements *are* the complete module graph.
-			mg.g.Require(Target, rs.rootModules)
+			// out”, as though we are viewing the main module from outside: in vendor
+			// mode, the root requirements *are* the complete module graph.
+			mg.g.Require(mainModule, rs.rootModules)
 		} else {
 			// The transitive requirements of the main module are not in general available
 			// from the vendor directory, and we don't actually know how we got from
@@ -170,7 +195,7 @@ func (rs *Requirements) initVendor(vendorList []module.Version) {
 			// graph, but still distinguishes between direct and indirect
 			// dependencies.
 			vendorMod := module.Version{Path: "vendor/modules.txt", Version: ""}
-			mg.g.Require(Target, append(rs.rootModules, vendorMod))
+			mg.g.Require(mainModule, append(rs.rootModules, vendorMod))
 			mg.g.Require(vendorMod, vendorList)
 		}
 
@@ -182,8 +207,8 @@ func (rs *Requirements) initVendor(vendorList []module.Version) {
 // path, or the zero module.Version and ok=false if the module is not a root
 // dependency.
 func (rs *Requirements) rootSelected(path string) (version string, ok bool) {
-	if path == Target.Path {
-		return Target.Version, true
+	if MainModules.Contains(path) {
+		return "", true
 	}
 	if v, ok := rs.maxRootVersion[path]; ok {
 		return v, true
@@ -197,7 +222,7 @@ func (rs *Requirements) rootSelected(path string) (version string, ok bool) {
 // selection.
 func (rs *Requirements) hasRedundantRoot() bool {
 	for i, m := range rs.rootModules {
-		if m.Path == Target.Path || (i > 0 && m.Path == rs.rootModules[i-1].Path) {
+		if MainModules.Contains(m.Path) || (i > 0 && m.Path == rs.rootModules[i-1].Path) {
 			return true
 		}
 	}
@@ -214,7 +239,7 @@ func (rs *Requirements) hasRedundantRoot() bool {
 // returns a non-nil error of type *mvs.BuildListError.
 func (rs *Requirements) Graph(ctx context.Context) (*ModuleGraph, error) {
 	rs.graphOnce.Do(func() {
-		mg, mgErr := readModGraph(ctx, rs.depth, rs.rootModules)
+		mg, mgErr := readModGraph(ctx, rs.pruning, rs.rootModules)
 		rs.graph.Store(cachedGraph{mg, mgErr})
 	})
 	cached := rs.graph.Load().(cachedGraph)
@@ -230,7 +255,7 @@ func (rs *Requirements) IsDirect(path string) bool {
 // A ModuleGraph represents the complete graph of module dependencies
 // of a main module.
 //
-// If the main module is lazily loaded, the graph does not include
+// If the main module supports module graph pruning, the graph does not include
 // transitive dependencies of non-root (implicit) dependencies.
 type ModuleGraph struct {
 	g         *mvs.Graph
@@ -254,8 +279,16 @@ var readModGraphDebugOnce sync.Once
 //
 // Unlike LoadModGraph, readModGraph does not attempt to diagnose or update
 // inconsistent roots.
-func readModGraph(ctx context.Context, depth modDepth, roots []module.Version) (*ModuleGraph, error) {
-	if depth == lazy {
+func readModGraph(ctx context.Context, pruning modPruning, roots []module.Version) (*ModuleGraph, error) {
+	if pruning == pruned {
+		// Enable diagnostics for lazy module loading
+		// (https://golang.org/ref/mod#lazy-loading) only if the module graph is
+		// pruned.
+		//
+		// In unpruned modules,we load the module graph much more aggressively (in
+		// order to detect inconsistencies that wouldn't be feasible to spot-check),
+		// so it wouldn't be useful to log when that occurs (because it happens in
+		// normal operation all the time).
 		readModGraphDebugOnce.Do(func() {
 			for _, f := range strings.Split(os.Getenv("GODEBUG"), ",") {
 				switch f {
@@ -274,21 +307,26 @@ func readModGraph(ctx context.Context, depth modDepth, roots []module.Version) (
 		mu       sync.Mutex // guards mg.g and hasError during loading
 		hasError bool
 		mg       = &ModuleGraph{
-			g: mvs.NewGraph(cmpVersion, []module.Version{Target}),
+			g: mvs.NewGraph(cmpVersion, MainModules.Versions()),
 		}
 	)
-	mg.g.Require(Target, roots)
+	if pruning != workspace {
+		if inWorkspaceMode() {
+			panic("pruning is not workspace in workspace mode")
+		}
+		mg.g.Require(MainModules.mustGetSingleMainModule(), roots)
+	}
 
 	var (
-		loadQueue    = par.NewQueue(runtime.GOMAXPROCS(0))
-		loadingEager sync.Map // module.Version → nil; the set of modules that have been or are being loaded via eager roots
+		loadQueue       = par.NewQueue(runtime.GOMAXPROCS(0))
+		loadingUnpruned sync.Map // module.Version → nil; the set of modules that have been or are being loaded via roots that do not support pruning
 	)
 
 	// loadOne synchronously loads the explicit requirements for module m.
 	// It does not load the transitive requirements of m even if the go version in
-	// m's go.mod file indicates eager loading.
+	// m's go.mod file indicates that it supports graph pruning.
 	loadOne := func(m module.Version) (*modFileSummary, error) {
-		cached := mg.loadCache.Do(m, func() interface{} {
+		cached := mg.loadCache.Do(m, func() any {
 			summary, err := goModSummary(m)
 
 			mu.Lock()
@@ -305,16 +343,16 @@ func readModGraph(ctx context.Context, depth modDepth, roots []module.Version) (
 		return cached.summary, cached.err
 	}
 
-	var enqueue func(m module.Version, depth modDepth)
-	enqueue = func(m module.Version, depth modDepth) {
+	var enqueue func(m module.Version, pruning modPruning)
+	enqueue = func(m module.Version, pruning modPruning) {
 		if m.Version == "none" {
 			return
 		}
 
-		if depth == eager {
-			if _, dup := loadingEager.LoadOrStore(m, nil); dup {
-				// m has already been enqueued for loading. Since eager loading may
-				// follow cycles in the the requirement graph, we need to return early
+		if pruning == unpruned {
+			if _, dup := loadingUnpruned.LoadOrStore(m, nil); dup {
+				// m has already been enqueued for loading. Since unpruned loading may
+				// follow cycles in the requirement graph, we need to return early
 				// to avoid making the load queue infinitely long.
 				return
 			}
@@ -326,24 +364,74 @@ func readModGraph(ctx context.Context, depth modDepth, roots []module.Version) (
 				return // findError will report the error later.
 			}
 
-			// If the version in m's go.mod file implies eager loading, then we cannot
-			// assume that the explicit requirements of m (added by loadOne) are
-			// sufficient to build the packages it contains. We must load its full
+			// If the version in m's go.mod file does not support pruning, then we
+			// cannot assume that the explicit requirements of m (added by loadOne)
+			// are sufficient to build the packages it contains. We must load its full
 			// transitive dependency graph to be sure that we see all relevant
 			// dependencies.
-			if depth == eager || summary.depth == eager {
+			if pruning != pruned || summary.pruning == unpruned {
+				nextPruning := summary.pruning
+				if pruning == unpruned {
+					nextPruning = unpruned
+				}
 				for _, r := range summary.require {
-					enqueue(r, eager)
+					enqueue(r, nextPruning)
 				}
 			}
 		})
 	}
 
 	for _, m := range roots {
-		enqueue(m, depth)
+		enqueue(m, pruning)
 	}
 	<-loadQueue.Idle()
 
+	// Reload any dependencies of the main modules which are not
+	// at their selected versions at workspace mode, because the
+	// requirements don't accurately reflect the transitive imports.
+	if pruning == workspace {
+		// hasDepsInAll contains the set of modules that need to be loaded
+		// at workspace pruning because any of their dependencies may
+		// provide packages in all.
+		hasDepsInAll := make(map[string]bool)
+		seen := map[module.Version]bool{}
+		for _, m := range roots {
+			hasDepsInAll[m.Path] = true
+			seen[m] = true
+		}
+		// This loop will terminate because it will call enqueue on each version of
+		// each dependency of the modules in hasDepsInAll at most once (and only
+		// calls enqueue on successively increasing versions of each dependency).
+		for {
+			needsEnqueueing := map[module.Version]bool{}
+			for p := range hasDepsInAll {
+				m := module.Version{Path: p, Version: mg.g.Selected(p)}
+				reqs, ok := mg.g.RequiredBy(m)
+				if !ok {
+					needsEnqueueing[m] = true
+					continue
+				}
+				for _, r := range reqs {
+					s := module.Version{Path: r.Path, Version: mg.g.Selected(r.Path)}
+					if cmpVersion(s.Version, r.Version) > 0 && !seen[s] {
+						needsEnqueueing[s] = true
+					}
+				}
+			}
+			// add all needs enqueueing to paths we care about
+			if len(needsEnqueueing) == 0 {
+				break
+			}
+
+			for p := range needsEnqueueing {
+				enqueue(p, workspace)
+				seen[p] = true
+				hasDepsInAll[p.Path] = true
+			}
+			<-loadQueue.Idle()
+		}
+	}
+
 	if hasError {
 		return mg, mg.findError()
 	}
@@ -351,8 +439,7 @@ func readModGraph(ctx context.Context, depth modDepth, roots []module.Version) (
 }
 
 // RequiredBy returns the dependencies required by module m in the graph,
-// or ok=false if module m's dependencies are not relevant (such as if they
-// are pruned out by lazy loading).
+// or ok=false if module m's dependencies are pruned out.
 //
 // The caller must not modify the returned slice, but may safely append to it
 // and may rely on it not to be modified.
@@ -404,7 +491,12 @@ func (mg *ModuleGraph) findError() error {
 }
 
 func (mg *ModuleGraph) allRootsSelected() bool {
-	roots, _ := mg.g.RequiredBy(Target)
+	var roots []module.Version
+	if inWorkspaceMode() {
+		roots = MainModules.Versions()
+	} else {
+		roots, _ = mg.g.RequiredBy(MainModules.mustGetSingleMainModule())
+	}
 	for _, m := range roots {
 		if mg.Selected(m.Path) != m.Version {
 			return false
@@ -427,12 +519,12 @@ func LoadModGraph(ctx context.Context, goVersion string) *ModuleGraph {
 	rs := LoadModFile(ctx)
 
 	if goVersion != "" {
-		depth := modDepthFromGoVersion(goVersion)
-		if depth == eager && rs.depth != eager {
+		pruning := pruningForGoVersion(goVersion)
+		if pruning == unpruned && rs.pruning != unpruned {
 			// Use newRequirements instead of convertDepth because convertDepth
 			// also updates roots; here, we want to report the unmodified roots
 			// even though they may seem inconsistent.
-			rs = newRequirements(eager, rs.rootModules, rs.direct)
+			rs = newRequirements(unpruned, rs.rootModules, rs.direct)
 		}
 
 		mg, err := rs.Graph(ctx)
@@ -447,7 +539,8 @@ func LoadModGraph(ctx context.Context, goVersion string) *ModuleGraph {
 		base.Fatalf("go: %v", err)
 	}
 
-	commitRequirements(ctx, modFileGoVersion(), rs)
+	requirements = rs
+
 	return mg
 }
 
@@ -455,9 +548,8 @@ func LoadModGraph(ctx context.Context, goVersion string) *ModuleGraph {
 //
 // If the complete graph reveals that some root of rs is not actually the
 // selected version of its path, expandGraph computes a new set of roots that
-// are consistent. (When lazy loading is implemented, this may result in
-// upgrades to other modules due to requirements that were previously pruned
-// out.)
+// are consistent. (With a pruned module graph, this may result in upgrades to
+// other modules due to requirements that were previously pruned out.)
 //
 // expandGraph returns the updated roots, along with the module graph loaded
 // from those roots and any error encountered while loading that graph.
@@ -473,9 +565,9 @@ func expandGraph(ctx context.Context, rs *Requirements) (*Requirements, *ModuleG
 
 	if !mg.allRootsSelected() {
 		// The roots of rs are not consistent with the rest of the graph. Update
-		// them. In an eager module this is a no-op for the build list as a whole —
+		// them. In an unpruned module this is a no-op for the build list as a whole —
 		// it just promotes what were previously transitive requirements to be
-		// roots — but in a lazy module it may pull in previously-irrelevant
+		// roots — but in a pruned module it may pull in previously-irrelevant
 		// transitive dependencies.
 
 		newRS, rsErr := updateRoots(ctx, rs.direct, rs, nil, nil, false)
@@ -513,7 +605,7 @@ func EditBuildList(ctx context.Context, add, mustSelect []module.Version) (chang
 	if err != nil {
 		return false, err
 	}
-	commitRequirements(ctx, modFileGoVersion(), rs)
+	requirements = rs
 	return changed, err
 }
 
@@ -544,23 +636,45 @@ type Conflict struct {
 
 // tidyRoots trims the root dependencies to the minimal requirements needed to
 // both retain the same versions of all packages in pkgs and satisfy the
-// lazy loading invariants (if applicable).
+// graph-pruning invariants (if applicable).
 func tidyRoots(ctx context.Context, rs *Requirements, pkgs []*loadPkg) (*Requirements, error) {
-	if rs.depth == eager {
-		return tidyEagerRoots(ctx, rs.direct, pkgs)
+	mainModule := MainModules.mustGetSingleMainModule()
+	if rs.pruning == unpruned {
+		return tidyUnprunedRoots(ctx, mainModule, rs.direct, pkgs)
 	}
-	return tidyLazyRoots(ctx, rs.direct, pkgs)
+	return tidyPrunedRoots(ctx, mainModule, rs.direct, pkgs)
 }
 
 func updateRoots(ctx context.Context, direct map[string]bool, rs *Requirements, pkgs []*loadPkg, add []module.Version, rootsImported bool) (*Requirements, error) {
-	if rs.depth == eager {
-		return updateEagerRoots(ctx, direct, rs, add)
+	switch rs.pruning {
+	case unpruned:
+		return updateUnprunedRoots(ctx, direct, rs, add)
+	case pruned:
+		return updatePrunedRoots(ctx, direct, rs, pkgs, add, rootsImported)
+	case workspace:
+		return updateWorkspaceRoots(ctx, rs, add)
+	default:
+		panic(fmt.Sprintf("unsupported pruning mode: %v", rs.pruning))
+	}
+}
+
+func updateWorkspaceRoots(ctx context.Context, rs *Requirements, add []module.Version) (*Requirements, error) {
+	if len(add) != 0 {
+		// add should be empty in workspace mode because workspace mode implies
+		// -mod=readonly, which in turn implies no new requirements. The code path
+		// that would result in add being non-empty returns an error before it
+		// reaches this point: The set of modules to add comes from
+		// resolveMissingImports, which in turn resolves each package by calling
+		// queryImport. But queryImport explicitly checks for -mod=readonly, and
+		// return an error.
+		panic("add is not empty")
 	}
-	return updateLazyRoots(ctx, direct, rs, pkgs, add, rootsImported)
+	return rs, nil
 }
 
-// tidyLazyRoots returns a minimal set of root requirements that maintains the
-// "lazy loading" invariants of the go.mod file for the given packages:
+// tidyPrunedRoots returns a minimal set of root requirements that maintains the
+// invariants of the go.mod file needed to support graph pruning for the given
+// packages:
 //
 // 	1. For each package marked with pkgInAll, the module path that provided that
 // 	   package is included as a root.
@@ -568,16 +682,16 @@ func updateRoots(ctx context.Context, direct map[string]bool, rs *Requirements,
 // 	   selected at the same version or is upgraded by the dependencies of a
 // 	   root.
 //
-// If any module that provided a package has been upgraded above its previous,
+// If any module that provided a package has been upgraded above its previous
 // version, the caller may need to reload and recompute the package graph.
 //
 // To ensure that the loading process eventually converges, the caller should
 // add any needed roots from the tidy root set (without removing existing untidy
 // roots) until the set of roots has converged.
-func tidyLazyRoots(ctx context.Context, direct map[string]bool, pkgs []*loadPkg) (*Requirements, error) {
+func tidyPrunedRoots(ctx context.Context, mainModule module.Version, direct map[string]bool, pkgs []*loadPkg) (*Requirements, error) {
 	var (
 		roots        []module.Version
-		pathIncluded = map[string]bool{Target.Path: true}
+		pathIncluded = map[string]bool{mainModule.Path: true}
 	)
 	// We start by adding roots for every package in "all".
 	//
@@ -605,7 +719,7 @@ func tidyLazyRoots(ctx context.Context, direct map[string]bool, pkgs []*loadPkg)
 		queued[pkg] = true
 	}
 	module.Sort(roots)
-	tidy := newRequirements(lazy, roots, direct)
+	tidy := newRequirements(pruned, roots, direct)
 
 	for len(queue) > 0 {
 		roots = tidy.rootModules
@@ -641,7 +755,7 @@ func tidyLazyRoots(ctx context.Context, direct map[string]bool, pkgs []*loadPkg)
 
 		if len(roots) > len(tidy.rootModules) {
 			module.Sort(roots)
-			tidy = newRequirements(lazy, roots, tidy.direct)
+			tidy = newRequirements(pruned, roots, tidy.direct)
 		}
 	}
 
@@ -652,8 +766,8 @@ func tidyLazyRoots(ctx context.Context, direct map[string]bool, pkgs []*loadPkg)
 	return tidy, nil
 }
 
-// updateLazyRoots returns a set of root requirements that maintains the “lazy
-// loading” invariants of the go.mod file:
+// updatePrunedRoots returns a set of root requirements that maintains the
+// invariants of the go.mod file needed to support graph pruning:
 //
 // 	1. The selected version of the module providing each package marked with
 // 	   either pkgInAll or pkgIsRoot is included as a root.
@@ -670,7 +784,7 @@ func tidyLazyRoots(ctx context.Context, direct map[string]bool, pkgs []*loadPkg)
 // The packages in pkgs are assumed to have been loaded from either the roots of
 // rs or the modules selected in the graph of rs.
 //
-// The above invariants together imply the “lazy loading” invariants for the
+// The above invariants together imply the graph-pruning invariants for the
 // go.mod file:
 //
 // 	1. (The import invariant.) Every module that provides a package transitively
@@ -690,13 +804,13 @@ func tidyLazyRoots(ctx context.Context, direct map[string]bool, pkgs []*loadPkg)
 // 	   it requires explicitly. This invariant is left up to the caller, who must
 // 	   not load packages from outside the module graph but may add roots to the
 // 	   graph, but is facilited by (3). If the caller adds roots to the graph in
-// 	   order to resolve missing packages, then updateLazyRoots will retain them,
+// 	   order to resolve missing packages, then updatePrunedRoots will retain them,
 // 	   the selected versions of those roots cannot regress, and they will
 // 	   eventually be written back to the main module's go.mod file.
 //
 // (See https://golang.org/design/36460-lazy-module-loading#invariants for more
 // detail.)
-func updateLazyRoots(ctx context.Context, direct map[string]bool, rs *Requirements, pkgs []*loadPkg, add []module.Version, rootsImported bool) (*Requirements, error) {
+func updatePrunedRoots(ctx context.Context, direct map[string]bool, rs *Requirements, pkgs []*loadPkg, add []module.Version, rootsImported bool) (*Requirements, error) {
 	roots := rs.rootModules
 	rootsUpgraded := false
 
@@ -717,11 +831,11 @@ func updateLazyRoots(ctx context.Context, direct map[string]bool, rs *Requiremen
 			// pkg is transitively imported by a package or test in the main module.
 			// We need to promote the module that maintains it to a root: if some
 			// other module depends on the main module, and that other module also
-			// uses lazy loading, it will expect to find all of our transitive
-			// dependencies by reading just our go.mod file, not the go.mod files of
-			// everything we depend on.
+			// uses a pruned module graph, it will expect to find all of our
+			// transitive dependencies by reading just our go.mod file, not the go.mod
+			// files of everything we depend on.
 			//
-			// (This is the “import invariant” that makes lazy loading possible.)
+			// (This is the “import invariant” that makes graph pruning possible.)
 
 		case rootsImported && pkg.flags.has(pkgFromRoot):
 			// pkg is a transitive dependency of some root, and we are treating the
@@ -732,17 +846,18 @@ func updateLazyRoots(ctx context.Context, direct map[string]bool, rs *Requiremen
 			// it matches a command-line argument.) We want future invocations of the
 			// 'go' command — such as 'go test' on the same package — to continue to
 			// use the same versions of its dependencies that we are using right now.
-			// So we need to bring this package's dependencies inside the lazy-loading
-			// horizon.
+			// So we need to bring this package's dependencies inside the pruned
+			// module graph.
 			//
 			// Making the module containing this package a root of the module graph
-			// does exactly that: if the module containing the package is lazy it
-			// should satisfy the import invariant itself, so all of its dependencies
-			// should be in its go.mod file, and if the module containing the package
-			// is eager then if we make it a root we will load all of its transitive
-			// dependencies into the module graph.
+			// does exactly that: if the module containing the package supports graph
+			// pruning then it should satisfy the import invariant itself, so all of
+			// its dependencies should be in its go.mod file, and if the module
+			// containing the package does not support pruning then if we make it a
+			// root we will load all of its (unpruned) transitive dependencies into
+			// the module graph.
 			//
-			// (This is the “argument invariant” of lazy loading, and is important for
+			// (This is the “argument invariant”, and is important for
 			// reproducibility.)
 
 		default:
@@ -807,16 +922,15 @@ func updateLazyRoots(ctx context.Context, direct map[string]bool, rs *Requiremen
 			// We've added or upgraded one or more roots, so load the full module
 			// graph so that we can update those roots to be consistent with other
 			// requirements.
-			if cfg.BuildMod != "mod" {
+			if mustHaveCompleteRequirements() {
 				// Our changes to the roots may have moved dependencies into or out of
-				// the lazy-loading horizon, which could in turn change the selected
-				// versions of other modules. (Unlike for eager modules, for lazy
-				// modules adding or removing an explicit root is a semantic change, not
-				// just a cosmetic one.)
+				// the graph-pruning horizon, which could in turn change the selected
+				// versions of other modules. (For pruned modules adding or removing an
+				// explicit root is a semantic change, not just a cosmetic one.)
 				return rs, errGoModDirty
 			}
 
-			rs = newRequirements(lazy, roots, direct)
+			rs = newRequirements(pruned, roots, direct)
 			var err error
 			mg, err = rs.Graph(ctx)
 			if err != nil {
@@ -831,7 +945,7 @@ func updateLazyRoots(ctx context.Context, direct map[string]bool, rs *Requiremen
 			if rs.graph.Load() != nil {
 				// We've already loaded the full module graph, which includes the
 				// requirements of all of the root modules — even the transitive
-				// requirements, if they are eager!
+				// requirements, if they are unpruned!
 				mg, _ = rs.Graph(ctx)
 			} else if cfg.BuildMod == "vendor" {
 				// We can't spot-check the requirements of other modules because we
@@ -855,7 +969,9 @@ func updateLazyRoots(ctx context.Context, direct map[string]bool, rs *Requiremen
 		roots = make([]module.Version, 0, len(rs.rootModules))
 		rootsUpgraded = false
 		inRootPaths := make(map[string]bool, len(rs.rootModules)+1)
-		inRootPaths[Target.Path] = true
+		for _, mm := range MainModules.Versions() {
+			inRootPaths[mm.Path] = true
+		}
 		for _, m := range rs.rootModules {
 			if inRootPaths[m.Path] {
 				// This root specifies a redundant path. We already retained the
@@ -908,12 +1024,12 @@ func updateLazyRoots(ctx context.Context, direct map[string]bool, rs *Requiremen
 		}
 	}
 
-	if rs.depth == lazy && reflect.DeepEqual(roots, rs.rootModules) && reflect.DeepEqual(direct, rs.direct) {
-		// The root set is unchanged and rs was already lazy, so keep rs to
+	if rs.pruning == pruned && reflect.DeepEqual(roots, rs.rootModules) && reflect.DeepEqual(direct, rs.direct) {
+		// The root set is unchanged and rs was already pruned, so keep rs to
 		// preserve its cached ModuleGraph (if any).
 		return rs, nil
 	}
-	return newRequirements(lazy, roots, direct), nil
+	return newRequirements(pruned, roots, direct), nil
 }
 
 // spotCheckRoots reports whether the versions of the roots in rs satisfy the
@@ -955,17 +1071,37 @@ func spotCheckRoots(ctx context.Context, rs *Requirements, mods map[module.Versi
 	return true
 }
 
-// tidyEagerRoots returns a minimal set of root requirements that maintains the
-// selected version of every module that provided a package in pkgs, and
-// includes the selected version of every such module in direct as a root.
-func tidyEagerRoots(ctx context.Context, direct map[string]bool, pkgs []*loadPkg) (*Requirements, error) {
+// tidyUnprunedRoots returns a minimal set of root requirements that maintains
+// the selected version of every module that provided or lexically could have
+// provided a package in pkgs, and includes the selected version of every such
+// module in direct as a root.
+func tidyUnprunedRoots(ctx context.Context, mainModule module.Version, direct map[string]bool, pkgs []*loadPkg) (*Requirements, error) {
 	var (
+		// keep is a set of of modules that provide packages or are needed to
+		// disambiguate imports.
 		keep     []module.Version
 		keptPath = map[string]bool{}
-	)
-	var (
-		rootPaths   []string // module paths that should be included as roots
+
+		// rootPaths is a list of module paths that provide packages directly
+		// imported from the main module. They should be included as roots.
+		rootPaths   []string
 		inRootPaths = map[string]bool{}
+
+		// altMods is a set of paths of modules that lexically could have provided
+		// imported packages. It may be okay to remove these from the list of
+		// explicit requirements if that removes them from the module graph. If they
+		// are present in the module graph reachable from rootPaths, they must not
+		// be at a lower version. That could cause a missing sum error or a new
+		// import ambiguity.
+		//
+		// For example, suppose a developer rewrites imports from example.com/m to
+		// example.com/m/v2, then runs 'go mod tidy'. Tidy may delete the
+		// requirement on example.com/m if there is no other transitive requirement
+		// on it. However, if example.com/m were downgraded to a version not in
+		// go.sum, when package example.com/m/v2/p is loaded, we'd get an error
+		// trying to disambiguate the import, since we can't check example.com/m
+		// without its sum. See #47738.
+		altMods = map[string]string{}
 	)
 	for _, pkg := range pkgs {
 		if !pkg.fromExternalModule() {
@@ -979,16 +1115,48 @@ func tidyEagerRoots(ctx context.Context, direct map[string]bool, pkgs []*loadPkg
 				inRootPaths[m.Path] = true
 			}
 		}
+		for _, m := range pkg.altMods {
+			altMods[m.Path] = m.Version
+		}
 	}
 
-	min, err := mvs.Req(Target, rootPaths, &mvsReqs{roots: keep})
+	// Construct a build list with a minimal set of roots.
+	// This may remove or downgrade modules in altMods.
+	reqs := &mvsReqs{roots: keep}
+	min, err := mvs.Req(mainModule, rootPaths, reqs)
 	if err != nil {
 		return nil, err
 	}
-	return newRequirements(eager, min, direct), nil
+	buildList, err := mvs.BuildList([]module.Version{mainModule}, reqs)
+	if err != nil {
+		return nil, err
+	}
+
+	// Check if modules in altMods were downgraded but not removed.
+	// If so, add them to roots, which will retain an "// indirect" requirement
+	// in go.mod. See comment on altMods above.
+	keptAltMod := false
+	for _, m := range buildList {
+		if v, ok := altMods[m.Path]; ok && semver.Compare(m.Version, v) < 0 {
+			keep = append(keep, module.Version{Path: m.Path, Version: v})
+			keptAltMod = true
+		}
+	}
+	if keptAltMod {
+		// We must run mvs.Req again instead of simply adding altMods to min.
+		// It's possible that a requirement in altMods makes some other
+		// explicit indirect requirement unnecessary.
+		reqs.roots = keep
+		min, err = mvs.Req(mainModule, rootPaths, reqs)
+		if err != nil {
+			return nil, err
+		}
+	}
+
+	return newRequirements(unpruned, min, direct), nil
 }
 
-// updateEagerRoots returns a set of root requirements that includes the selected
+// updateUnprunedRoots returns a set of root requirements that includes the selected
 // version of every module path in direct as a root, and maintains the selected
 // version of every module selected in the graph of rs.
 //
@@ -1002,7 +1170,7 @@ func tidyEagerRoots(ctx context.Context, direct map[string]bool, pkgs []*loadPkg
 // 	   by a dependency in add.
 // 	4. Every version in add is selected at its given version unless upgraded by
 // 	   (the dependencies of) an existing root or another module in add.
-func updateEagerRoots(ctx context.Context, direct map[string]bool, rs *Requirements, add []module.Version) (*Requirements, error) {
+func updateUnprunedRoots(ctx context.Context, direct map[string]bool, rs *Requirements, add []module.Version) (*Requirements, error) {
 	mg, err := rs.Graph(ctx)
 	if err != nil {
 		// We can't ignore errors in the module graph even if the user passed the -e
@@ -1011,7 +1179,7 @@ func updateEagerRoots(ctx context.Context, direct map[string]bool, rs *Requireme
 		return rs, err
 	}
 
-	if cfg.BuildMod != "mod" {
+	if mustHaveCompleteRequirements() {
 		// Instead of actually updating the requirements, just check that no updates
 		// are needed.
 		if rs == nil {
@@ -1067,10 +1235,10 @@ func updateEagerRoots(ctx context.Context, direct map[string]bool, rs *Requireme
 
 	// “The selected version of every module path in direct is included as a root.”
 	//
-	// This is only for convenience and clarity for end users: in an eager module,
+	// This is only for convenience and clarity for end users: in an unpruned module,
 	// the choice of explicit vs. implicit dependency has no impact on MVS
 	// selection (for itself or any other module).
-	keep := append(mg.BuildList()[1:], add...)
+	keep := append(mg.BuildList()[MainModules.Len():], add...)
 	for _, m := range keep {
 		if direct[m.Path] && !inRootPaths[m.Path] {
 			rootPaths = append(rootPaths, m.Path)
@@ -1078,44 +1246,53 @@ func updateEagerRoots(ctx context.Context, direct map[string]bool, rs *Requireme
 		}
 	}
 
-	min, err := mvs.Req(Target, rootPaths, &mvsReqs{roots: keep})
-	if err != nil {
-		return rs, err
+	var roots []module.Version
+	for _, mainModule := range MainModules.Versions() {
+		min, err := mvs.Req(mainModule, rootPaths, &mvsReqs{roots: keep})
+		if err != nil {
+			return rs, err
+		}
+		roots = append(roots, min...)
 	}
-	if rs.depth == eager && reflect.DeepEqual(min, rs.rootModules) && reflect.DeepEqual(direct, rs.direct) {
-		// The root set is unchanged and rs was already eager, so keep rs to
+	if MainModules.Len() > 1 {
+		module.Sort(roots)
+	}
+	if rs.pruning == unpruned && reflect.DeepEqual(roots, rs.rootModules) && reflect.DeepEqual(direct, rs.direct) {
+		// The root set is unchanged and rs was already unpruned, so keep rs to
 		// preserve its cached ModuleGraph (if any).
 		return rs, nil
 	}
-	return newRequirements(eager, min, direct), nil
+
+	return newRequirements(unpruned, roots, direct), nil
 }
 
-// convertDepth returns a version of rs with the given depth.
-// If rs already has the given depth, convertDepth returns rs unmodified.
-func convertDepth(ctx context.Context, rs *Requirements, depth modDepth) (*Requirements, error) {
-	if rs.depth == depth {
+// convertPruning returns a version of rs with the given pruning behavior.
+// If rs already has the given pruning, convertPruning returns rs unmodified.
+func convertPruning(ctx context.Context, rs *Requirements, pruning modPruning) (*Requirements, error) {
+	if rs.pruning == pruning {
 		return rs, nil
+	} else if rs.pruning == workspace || pruning == workspace {
+		panic("attempthing to convert to/from workspace pruning and another pruning type")
 	}
 
-	if depth == eager {
-		// We are converting a lazy module to an eager one. The roots of an eager
-		// module graph are a superset of the roots of a lazy graph, so we don't
-		// need to add any new roots — we just need to prune away the ones that are
-		// redundant given eager loading, which is exactly what updateEagerRoots
-		// does.
-		return updateEagerRoots(ctx, rs.direct, rs, nil)
+	if pruning == unpruned {
+		// We are converting a pruned module to an unpruned one. The roots of a
+		// ppruned module graph are a superset of the roots of an unpruned one, so
+		// we don't need to add any new roots — we just need to drop the ones that
+		// are redundant, which is exactly what updateUnprunedRoots does.
+		return updateUnprunedRoots(ctx, rs.direct, rs, nil)
 	}
 
-	// We are converting an eager module to a lazy one. The module graph of an
-	// eager module includes the transitive dependencies of every module in the
-	// build list.
+	// We are converting an unpruned module to a pruned one.
 	//
-	// Hey, we can express that as a lazy root set! “Include the transitive
-	// dependencies of every module in the build list” is exactly what happens in
-	// a lazy module if we promote every module in the build list to a root!
+	// An unpruned module graph includes the transitive dependencies of every
+	// module in the build list. As it turns out, we can express that as a pruned
+	// root set! “Include the transitive dependencies of every module in the build
+	// list” is exactly what happens in a pruned module if we promote every module
+	// in the build list to a root.
 	mg, err := rs.Graph(ctx)
 	if err != nil {
 		return rs, err
 	}
-	return newRequirements(lazy, mg.BuildList()[1:], rs.direct), nil
+	return newRequirements(pruned, mg.BuildList()[MainModules.Len():], rs.direct), nil
 }
diff --git a/libgo/go/cmd/go/internal/modload/edit.go b/libgo/go/cmd/go/internal/modload/edit.go
index 47f236ce168..0f37e3b2e94 100644
--- a/libgo/go/cmd/go/internal/modload/edit.go
+++ b/libgo/go/cmd/go/internal/modload/edit.go
@@ -21,7 +21,7 @@ import (
 // 	2. Each module version in tryUpgrade is upgraded toward the indicated
 // 	   version as far as can be done without violating (1).
 //
-// 	3. Each module version in rs.rootModules (or rs.graph, if rs.depth is eager)
+// 	3. Each module version in rs.rootModules (or rs.graph, if rs is unpruned)
 // 	   is downgraded from its original version only to the extent needed to
 // 	   satisfy (1), or upgraded only to the extent needed to satisfy (1) and
 // 	   (2).
@@ -69,13 +69,14 @@ func editRequirements(ctx context.Context, rs *Requirements, tryUpgrade, mustSel
 	}
 
 	var roots []module.Version
-	if rs.depth == eager {
-		// In an eager module, modules that provide packages imported by the main
-		// module may either be explicit roots or implicit transitive dependencies.
-		// We promote the modules in mustSelect to be explicit requirements.
+	if rs.pruning == unpruned {
+		// In a module without graph pruning, modules that provide packages imported
+		// by the main module may either be explicit roots or implicit transitive
+		// dependencies. We promote the modules in mustSelect to be explicit
+		// requirements.
 		var rootPaths []string
 		for _, m := range mustSelect {
-			if m.Version != "none" && m.Path != Target.Path {
+			if m.Version != "none" && !MainModules.Contains(m.Path) {
 				rootPaths = append(rootPaths, m.Path)
 			}
 		}
@@ -97,13 +98,13 @@ func editRequirements(ctx context.Context, rs *Requirements, tryUpgrade, mustSel
 			}
 		}
 
-		roots, err = mvs.Req(Target, rootPaths, &mvsReqs{roots: mods})
+		roots, err = mvs.Req(MainModules.mustGetSingleMainModule(), rootPaths, &mvsReqs{roots: mods})
 		if err != nil {
 			return nil, false, err
 		}
 	} else {
-		// In a lazy module, every module that provides a package imported by the
-		// main module must be retained as a root.
+		// In a module with a pruned graph, every module that provides a package
+		// imported by the main module must be retained as a root.
 		roots = mods
 		if !changed {
 			// Because the roots we just computed are unchanged, the entire graph must
@@ -126,7 +127,7 @@ func editRequirements(ctx context.Context, rs *Requirements, tryUpgrade, mustSel
 			direct[m.Path] = true
 		}
 	}
-	return newRequirements(rs.depth, roots, direct), changed, nil
+	return newRequirements(rs.pruning, roots, direct), changed, nil
 }
 
 // limiterForEdit returns a versionLimiter with its max versions set such that
@@ -149,11 +150,12 @@ func limiterForEdit(ctx context.Context, rs *Requirements, tryUpgrade, mustSelec
 		}
 	}
 
-	if rs.depth == eager {
-		// Eager go.mod files don't indicate which transitive dependencies are
-		// actually relevant to the main module, so we have to assume that any module
-		// that could have provided any package — that is, any module whose selected
-		// version was not "none" — may be relevant.
+	if rs.pruning == unpruned {
+		// go.mod files that do not support graph pruning don't indicate which
+		// transitive dependencies are actually relevant to the main module, so we
+		// have to assume that any module that could have provided any package —
+		// that is, any module whose selected version was not "none" — may be
+		// relevant.
 		for _, m := range mg.BuildList() {
 			restrictTo(m)
 		}
@@ -175,7 +177,7 @@ func limiterForEdit(ctx context.Context, rs *Requirements, tryUpgrade, mustSelec
 		}
 	}
 
-	if err := raiseLimitsForUpgrades(ctx, maxVersion, rs.depth, tryUpgrade, mustSelect); err != nil {
+	if err := raiseLimitsForUpgrades(ctx, maxVersion, rs.pruning, tryUpgrade, mustSelect); err != nil {
 		return nil, err
 	}
 
@@ -185,7 +187,7 @@ func limiterForEdit(ctx context.Context, rs *Requirements, tryUpgrade, mustSelec
 		restrictTo(m)
 	}
 
-	return newVersionLimiter(rs.depth, maxVersion), nil
+	return newVersionLimiter(rs.pruning, maxVersion), nil
 }
 
 // raiseLimitsForUpgrades increases the module versions in maxVersions to the
@@ -195,12 +197,12 @@ func limiterForEdit(ctx context.Context, rs *Requirements, tryUpgrade, mustSelec
 //
 // Versions not present in maxVersion are unrestricted, and it is assumed that
 // they will not be promoted to root requirements (and thus will not contribute
-// their own dependencies if the main module is lazy).
+// their own dependencies if the main module supports graph pruning).
 //
 // These limits provide an upper bound on how far a module may be upgraded as
 // part of an incidental downgrade, if downgrades are needed in order to select
 // the versions in mustSelect.
-func raiseLimitsForUpgrades(ctx context.Context, maxVersion map[string]string, depth modDepth, tryUpgrade []module.Version, mustSelect []module.Version) error {
+func raiseLimitsForUpgrades(ctx context.Context, maxVersion map[string]string, pruning modPruning, tryUpgrade []module.Version, mustSelect []module.Version) error {
 	// allow raises the limit for m.Path to at least m.Version.
 	// If m.Path was already unrestricted, it remains unrestricted.
 	allow := func(m module.Version) {
@@ -214,21 +216,21 @@ func raiseLimitsForUpgrades(ctx context.Context, maxVersion map[string]string, d
 	}
 
 	var (
-		eagerUpgrades  []module.Version
-		isLazyRootPath map[string]bool
+		unprunedUpgrades []module.Version
+		isPrunedRootPath map[string]bool
 	)
-	if depth == eager {
-		eagerUpgrades = tryUpgrade
+	if pruning == unpruned {
+		unprunedUpgrades = tryUpgrade
 	} else {
-		isLazyRootPath = make(map[string]bool, len(maxVersion))
+		isPrunedRootPath = make(map[string]bool, len(maxVersion))
 		for p := range maxVersion {
-			isLazyRootPath[p] = true
+			isPrunedRootPath[p] = true
 		}
 		for _, m := range tryUpgrade {
-			isLazyRootPath[m.Path] = true
+			isPrunedRootPath[m.Path] = true
 		}
 		for _, m := range mustSelect {
-			isLazyRootPath[m.Path] = true
+			isPrunedRootPath[m.Path] = true
 		}
 
 		allowedRoot := map[module.Version]bool{}
@@ -240,10 +242,10 @@ func raiseLimitsForUpgrades(ctx context.Context, maxVersion map[string]string, d
 			}
 			allowedRoot[m] = true
 
-			if m.Path == Target.Path {
-				// Target is already considered to be higher than any possible m, so we
-				// won't be upgrading to it anyway and there is no point scanning its
-				// dependencies.
+			if MainModules.Contains(m.Path) {
+				// The main module versions are already considered to be higher than any
+				// possible m, so m cannot be selected as a root and there is no point
+				// scanning its dependencies.
 				return nil
 			}
 
@@ -253,15 +255,15 @@ func raiseLimitsForUpgrades(ctx context.Context, maxVersion map[string]string, d
 			if err != nil {
 				return err
 			}
-			if summary.depth == eager {
-				// For efficiency, we'll load all of the eager upgrades as one big
+			if summary.pruning == unpruned {
+				// For efficiency, we'll load all of the unpruned upgrades as one big
 				// graph, rather than loading the (potentially-overlapping) subgraph for
 				// each upgrade individually.
-				eagerUpgrades = append(eagerUpgrades, m)
+				unprunedUpgrades = append(unprunedUpgrades, m)
 				return nil
 			}
 			for _, r := range summary.require {
-				if isLazyRootPath[r.Path] {
+				if isPrunedRootPath[r.Path] {
 					// r could become a root as the result of an upgrade or downgrade,
 					// in which case its dependencies will not be pruned out.
 					// We need to allow those dependencies to be upgraded too.
@@ -282,21 +284,19 @@ func raiseLimitsForUpgrades(ctx context.Context, maxVersion map[string]string, d
 		}
 	}
 
-	if len(eagerUpgrades) > 0 {
-		// Compute the max versions for eager upgrades all together.
-		// Since these modules are eager, we'll end up scanning all of their
+	if len(unprunedUpgrades) > 0 {
+		// Compute the max versions for unpruned upgrades all together.
+		// Since these modules are unpruned, we'll end up scanning all of their
 		// transitive dependencies no matter which versions end up selected,
 		// and since we have a large dependency graph to scan we might get
 		// a significant benefit from not revisiting dependencies that are at
 		// common versions among multiple upgrades.
-		upgradeGraph, err := readModGraph(ctx, eager, eagerUpgrades)
+		upgradeGraph, err := readModGraph(ctx, unpruned, unprunedUpgrades)
 		if err != nil {
-			if go117LazyTODO {
-				// Compute the requirement path from a module path in tryUpgrade to the
-				// error, and the requirement path (if any) from rs.rootModules to the
-				// tryUpgrade module path. Return a *mvs.BuildListError showing the
-				// concatenation of the paths (with an upgrade in the middle).
-			}
+			// Compute the requirement path from a module path in tryUpgrade to the
+			// error, and the requirement path (if any) from rs.rootModules to the
+			// tryUpgrade module path. Return a *mvs.BuildListError showing the
+			// concatenation of the paths (with an upgrade in the middle).
 			return err
 		}
 
@@ -311,7 +311,7 @@ func raiseLimitsForUpgrades(ctx context.Context, maxVersion map[string]string, d
 	nextRoots := append([]module.Version(nil), mustSelect...)
 	for nextRoots != nil {
 		module.Sort(nextRoots)
-		rs := newRequirements(depth, nextRoots, nil)
+		rs := newRequirements(pruning, nextRoots, nil)
 		nextRoots = nil
 
 		rs, mustGraph, err := expandGraph(ctx, rs)
@@ -325,7 +325,7 @@ func raiseLimitsForUpgrades(ctx context.Context, maxVersion map[string]string, d
 			// which case we will error out either way).
 			allow(r)
 
-			if isLazyRootPath[r.Path] {
+			if isPrunedRootPath[r.Path] {
 				if v, ok := rs.rootSelected(r.Path); ok && r.Version == v {
 					// r is already a root, so its requirements are already included in
 					// the build list.
@@ -365,12 +365,12 @@ func selectPotentiallyImportedModules(ctx context.Context, limiter *versionLimit
 	}
 
 	var initial []module.Version
-	if rs.depth == eager {
+	if rs.pruning == unpruned {
 		mg, err := rs.Graph(ctx)
 		if err != nil {
 			return nil, false, err
 		}
-		initial = mg.BuildList()[1:]
+		initial = mg.BuildList()[MainModules.Len():]
 	} else {
 		initial = rs.rootModules
 	}
@@ -382,7 +382,7 @@ func selectPotentiallyImportedModules(ctx context.Context, limiter *versionLimit
 
 	mods = make([]module.Version, 0, len(limiter.selected))
 	for path, v := range limiter.selected {
-		if v != "none" && path != Target.Path {
+		if v != "none" && !MainModules.Contains(path) {
 			mods = append(mods, module.Version{Path: path, Version: v})
 		}
 	}
@@ -392,13 +392,13 @@ func selectPotentiallyImportedModules(ctx context.Context, limiter *versionLimit
 	// downgraded module may require a higher (but still allowed) version of
 	// another. The lower version may require extraneous dependencies that aren't
 	// actually relevant, so we need to compute the actual selected versions.
-	mg, err := readModGraph(ctx, rs.depth, mods)
+	mg, err := readModGraph(ctx, rs.pruning, mods)
 	if err != nil {
 		return nil, false, err
 	}
 	mods = make([]module.Version, 0, len(limiter.selected))
 	for path, _ := range limiter.selected {
-		if path != Target.Path {
+		if !MainModules.Contains(path) {
 			if v := mg.Selected(path); v != "none" {
 				mods = append(mods, module.Version{Path: path, Version: v})
 			}
@@ -414,16 +414,16 @@ func selectPotentiallyImportedModules(ctx context.Context, limiter *versionLimit
 // A versionLimiter tracks the versions that may be selected for each module
 // subject to constraints on the maximum versions of transitive dependencies.
 type versionLimiter struct {
-	// depth is the depth at which the dependencies of the modules passed to
+	// pruning is the pruning at which the dependencies of the modules passed to
 	// Select and UpgradeToward are loaded.
-	depth modDepth
+	pruning modPruning
 
 	// max maps each module path to the maximum version that may be selected for
 	// that path.
 	//
 	// Paths with no entry are unrestricted, and we assume that they will not be
 	// promoted to root dependencies (so will not contribute dependencies if the
-	// main module is lazy).
+	// main module supports graph pruning).
 	max map[string]string
 
 	// selected maps each module path to a version of that path (if known) whose
@@ -475,14 +475,18 @@ func (dq dqState) isDisqualified() bool {
 // in the map are unrestricted. The limiter assumes that unrestricted paths will
 // not be promoted to root dependencies.
 //
-// If depth is lazy, then if a module passed to UpgradeToward or Select is
-// itself lazy, its unrestricted dependencies are skipped when scanning
-// requirements.
-func newVersionLimiter(depth modDepth, max map[string]string) *versionLimiter {
+// If module graph pruning is in effect, then if a module passed to
+// UpgradeToward or Select supports pruning, its unrestricted dependencies are
+// skipped when scanning requirements.
+func newVersionLimiter(pruning modPruning, max map[string]string) *versionLimiter {
+	selected := make(map[string]string)
+	for _, m := range MainModules.Versions() {
+		selected[m.Path] = m.Version
+	}
 	return &versionLimiter{
-		depth:     depth,
+		pruning:   pruning,
 		max:       max,
-		selected:  map[string]string{Target.Path: Target.Version},
+		selected:  selected,
 		dqReason:  map[module.Version]dqState{},
 		requiring: map[module.Version][]module.Version{},
 	}
@@ -491,8 +495,8 @@ func newVersionLimiter(depth modDepth, max map[string]string) *versionLimiter {
 // UpgradeToward attempts to upgrade the selected version of m.Path as close as
 // possible to m.Version without violating l's maximum version limits.
 //
-// If depth is lazy and m itself is lazy, the the dependencies of unrestricted
-// dependencies of m will not be followed.
+// If module graph pruning is in effect and m itself supports pruning, the
+// dependencies of unrestricted dependencies of m will not be followed.
 func (l *versionLimiter) UpgradeToward(ctx context.Context, m module.Version) error {
 	selected, ok := l.selected[m.Path]
 	if ok {
@@ -504,7 +508,7 @@ func (l *versionLimiter) UpgradeToward(ctx context.Context, m module.Version) er
 		selected = "none"
 	}
 
-	if l.check(m, l.depth).isDisqualified() {
+	if l.check(m, l.pruning).isDisqualified() {
 		candidates, err := versions(ctx, m.Path, CheckAllowed)
 		if err != nil {
 			// This is likely a transient error reaching the repository,
@@ -521,7 +525,7 @@ func (l *versionLimiter) UpgradeToward(ctx context.Context, m module.Version) er
 		})
 		candidates = candidates[:i]
 
-		for l.check(m, l.depth).isDisqualified() {
+		for l.check(m, l.pruning).isDisqualified() {
 			n := len(candidates)
 			if n == 0 || cmpVersion(selected, candidates[n-1]) >= 0 {
 				// We couldn't find a suitable candidate above the already-selected version.
@@ -538,7 +542,7 @@ func (l *versionLimiter) UpgradeToward(ctx context.Context, m module.Version) er
 
 // Select attempts to set the selected version of m.Path to exactly m.Version.
 func (l *versionLimiter) Select(m module.Version) (conflict module.Version, err error) {
-	dq := l.check(m, l.depth)
+	dq := l.check(m, l.pruning)
 	if !dq.isDisqualified() {
 		l.selected[m.Path] = m.Version
 	}
@@ -548,15 +552,15 @@ func (l *versionLimiter) Select(m module.Version) (conflict module.Version, err
 // check determines whether m (or its transitive dependencies) would violate l's
 // maximum version limits if added to the module requirement graph.
 //
-// If depth is lazy and m itself is lazy, then the dependencies of unrestricted
-// dependencies of m will not be followed. If the lazy loading invariants hold
-// for the main module up to this point, the packages in those modules are at
-// best only imported by tests of dependencies that are themselves loaded from
-// outside modules. Although we would like to keep 'go test all' as reproducible
-// as is feasible, we don't want to retain test dependencies that are only
-// marginally relevant at best.
-func (l *versionLimiter) check(m module.Version, depth modDepth) dqState {
-	if m.Version == "none" || m == Target {
+// If pruning is in effect and m itself supports graph pruning, the dependencies
+// of unrestricted dependencies of m will not be followed. If the graph-pruning
+// invariants hold for the main module up to this point, the packages in those
+// modules are at best only imported by tests of dependencies that are
+// themselves loaded from outside modules. Although we would like to keep
+// 'go test all' as reproducible as is feasible, we don't want to retain test
+// dependencies that are only marginally relevant at best.
+func (l *versionLimiter) check(m module.Version, pruning modPruning) dqState {
+	if m.Version == "none" || m == MainModules.mustGetSingleMainModule() {
 		// version "none" has no requirements, and the dependencies of Target are
 		// tautological.
 		return dqState{}
@@ -586,20 +590,20 @@ func (l *versionLimiter) check(m module.Version, depth modDepth) dqState {
 		return l.disqualify(m, dqState{err: err})
 	}
 
-	if summary.depth == eager {
-		depth = eager
+	if summary.pruning == unpruned {
+		pruning = unpruned
 	}
 	for _, r := range summary.require {
-		if depth == lazy {
+		if pruning == pruned {
 			if _, restricted := l.max[r.Path]; !restricted {
 				// r.Path is unrestricted, so we don't care at what version it is
 				// selected. We assume that r.Path will not become a root dependency, so
-				// since m is lazy, r's dependencies won't be followed.
+				// since m supports pruning, r's dependencies won't be followed.
 				continue
 			}
 		}
 
-		if dq := l.check(r, depth); dq.isDisqualified() {
+		if dq := l.check(r, pruning); dq.isDisqualified() {
 			return l.disqualify(m, dq)
 		}
 
diff --git a/libgo/go/cmd/go/internal/modload/import.go b/libgo/go/cmd/go/internal/modload/import.go
index d2bbe5cbe0b..812e48a1568 100644
--- a/libgo/go/cmd/go/internal/modload/import.go
+++ b/libgo/go/cmd/go/internal/modload/import.go
@@ -32,6 +32,8 @@ type ImportMissingError struct {
 	Module   module.Version
 	QueryErr error
 
+	ImportingMainModule module.Version
+
 	// isStd indicates whether we would expect to find the package in the standard
 	// library. This is normally true for all dotless import paths, but replace
 	// directives can cause us to treat the replaced paths as also being in
@@ -71,6 +73,9 @@ func (e *ImportMissingError) Error() string {
 		if e.QueryErr != nil {
 			return fmt.Sprintf("%s: %v", message, e.QueryErr)
 		}
+		if e.ImportingMainModule.Path != "" && e.ImportingMainModule != MainModules.ModContainingCWD() {
+			return fmt.Sprintf("%s; to add it:\n\tcd %s\n\tgo get %s", message, MainModules.ModRoot(e.ImportingMainModule), e.Path)
+		}
 		return fmt.Sprintf("%s; to add it:\n\tgo get %s", message, e.Path)
 	}
 
@@ -238,55 +243,63 @@ func (e *invalidImportError) Unwrap() error {
 //
 // If the package is not present in any module selected from the requirement
 // graph, importFromModules returns an *ImportMissingError.
-func importFromModules(ctx context.Context, path string, rs *Requirements, mg *ModuleGraph) (m module.Version, dir string, err error) {
+//
+// If the package is present in exactly one module, importFromModules will
+// return the module, its root directory, and a list of other modules that
+// lexically could have provided the package but did not.
+func importFromModules(ctx context.Context, path string, rs *Requirements, mg *ModuleGraph) (m module.Version, dir string, altMods []module.Version, err error) {
 	if strings.Contains(path, "@") {
-		return module.Version{}, "", fmt.Errorf("import path should not have @version")
+		return module.Version{}, "", nil, fmt.Errorf("import path should not have @version")
 	}
 	if build.IsLocalImport(path) {
-		return module.Version{}, "", fmt.Errorf("relative import not supported")
+		return module.Version{}, "", nil, fmt.Errorf("relative import not supported")
 	}
 	if path == "C" {
 		// There's no directory for import "C".
-		return module.Version{}, "", nil
+		return module.Version{}, "", nil, nil
 	}
 	// Before any further lookup, check that the path is valid.
 	if err := module.CheckImportPath(path); err != nil {
-		return module.Version{}, "", &invalidImportError{importPath: path, err: err}
+		return module.Version{}, "", nil, &invalidImportError{importPath: path, err: err}
 	}
 
 	// Is the package in the standard library?
 	pathIsStd := search.IsStandardImportPath(path)
 	if pathIsStd && goroot.IsStandardPackage(cfg.GOROOT, cfg.BuildContext.Compiler, path) {
-		if targetInGorootSrc {
-			if dir, ok, err := dirInModule(path, targetPrefix, ModRoot(), true); err != nil {
-				return module.Version{}, dir, err
-			} else if ok {
-				return Target, dir, nil
+		for _, mainModule := range MainModules.Versions() {
+			if MainModules.InGorootSrc(mainModule) {
+				if dir, ok, err := dirInModule(path, MainModules.PathPrefix(mainModule), MainModules.ModRoot(mainModule), true); err != nil {
+					return module.Version{}, dir, nil, err
+				} else if ok {
+					return mainModule, dir, nil, nil
+				}
 			}
 		}
 		dir := filepath.Join(cfg.GOROOT, "src", path)
-		return module.Version{}, dir, nil
+		return module.Version{}, dir, nil, nil
 	}
 
 	// -mod=vendor is special.
 	// Everything must be in the main module or the main module's vendor directory.
 	if cfg.BuildMod == "vendor" {
-		mainDir, mainOK, mainErr := dirInModule(path, targetPrefix, ModRoot(), true)
-		vendorDir, vendorOK, _ := dirInModule(path, "", filepath.Join(ModRoot(), "vendor"), false)
+		mainModule := MainModules.mustGetSingleMainModule()
+		modRoot := MainModules.ModRoot(mainModule)
+		mainDir, mainOK, mainErr := dirInModule(path, MainModules.PathPrefix(mainModule), modRoot, true)
+		vendorDir, vendorOK, _ := dirInModule(path, "", filepath.Join(modRoot, "vendor"), false)
 		if mainOK && vendorOK {
-			return module.Version{}, "", &AmbiguousImportError{importPath: path, Dirs: []string{mainDir, vendorDir}}
+			return module.Version{}, "", nil, &AmbiguousImportError{importPath: path, Dirs: []string{mainDir, vendorDir}}
 		}
 		// Prefer to return main directory if there is one,
 		// Note that we're not checking that the package exists.
 		// We'll leave that for load.
 		if !vendorOK && mainDir != "" {
-			return Target, mainDir, nil
+			return mainModule, mainDir, nil, nil
 		}
 		if mainErr != nil {
-			return module.Version{}, "", mainErr
+			return module.Version{}, "", nil, mainErr
 		}
-		readVendorList()
-		return vendorPkgModule[path], vendorDir, nil
+		readVendorList(mainModule)
+		return vendorPkgModule[path], vendorDir, nil, nil
 	}
 
 	// Check each module on the build list.
@@ -307,7 +320,7 @@ func importFromModules(ctx context.Context, path string, rs *Requirements, mg *M
 	// already non-nil, then we attempt to load the package using the full
 	// requirements in mg.
 	for {
-		var sumErrMods []module.Version
+		var sumErrMods, altMods []module.Version
 		for prefix := path; prefix != "."; prefix = pathpkg.Dir(prefix) {
 			var (
 				v  string
@@ -341,13 +354,15 @@ func importFromModules(ctx context.Context, path string, rs *Requirements, mg *M
 				// continue the loop and find the package in some other module,
 				// we need to look at this module to make sure the import is
 				// not ambiguous.
-				return module.Version{}, "", err
+				return module.Version{}, "", nil, err
 			}
 			if dir, ok, err := dirInModule(path, m.Path, root, isLocal); err != nil {
-				return module.Version{}, "", err
+				return module.Version{}, "", nil, err
 			} else if ok {
 				mods = append(mods, m)
 				dirs = append(dirs, dir)
+			} else {
+				altMods = append(altMods, m)
 			}
 		}
 
@@ -360,7 +375,7 @@ func importFromModules(ctx context.Context, path string, rs *Requirements, mg *M
 				mods[i], mods[j] = mods[j], mods[i]
 				dirs[i], dirs[j] = dirs[j], dirs[i]
 			}
-			return module.Version{}, "", &AmbiguousImportError{importPath: path, Dirs: dirs, Modules: mods}
+			return module.Version{}, "", nil, &AmbiguousImportError{importPath: path, Dirs: dirs, Modules: mods}
 		}
 
 		if len(sumErrMods) > 0 {
@@ -368,7 +383,7 @@ func importFromModules(ctx context.Context, path string, rs *Requirements, mg *M
 				j := len(sumErrMods) - 1 - i
 				sumErrMods[i], sumErrMods[j] = sumErrMods[j], sumErrMods[i]
 			}
-			return module.Version{}, "", &ImportMissingSumError{
+			return module.Version{}, "", nil, &ImportMissingSumError{
 				importPath: path,
 				mods:       sumErrMods,
 				found:      len(mods) > 0,
@@ -376,7 +391,7 @@ func importFromModules(ctx context.Context, path string, rs *Requirements, mg *M
 		}
 
 		if len(mods) == 1 {
-			return mods[0], dirs[0], nil
+			return mods[0], dirs[0], altMods, nil
 		}
 
 		if mg != nil {
@@ -386,7 +401,7 @@ func importFromModules(ctx context.Context, path string, rs *Requirements, mg *M
 			if !HasModRoot() {
 				queryErr = ErrNoModRoot
 			}
-			return module.Version{}, "", &ImportMissingError{Path: path, QueryErr: queryErr, isStd: pathIsStd}
+			return module.Version{}, "", nil, &ImportMissingError{Path: path, QueryErr: queryErr, isStd: pathIsStd}
 		}
 
 		// So far we've checked the root dependencies.
@@ -397,7 +412,7 @@ func importFromModules(ctx context.Context, path string, rs *Requirements, mg *M
 			// the module graph, so we can't return an ImportMissingError here — one
 			// of the missing modules might actually contain the package in question,
 			// in which case we shouldn't go looking for it in some new dependency.
-			return module.Version{}, "", err
+			return module.Version{}, "", nil, err
 		}
 	}
 }
@@ -410,9 +425,9 @@ func importFromModules(ctx context.Context, path string, rs *Requirements, mg *M
 func queryImport(ctx context.Context, path string, rs *Requirements) (module.Version, error) {
 	// To avoid spurious remote fetches, try the latest replacement for each
 	// module (golang.org/issue/26241).
-	if index != nil {
-		var mods []module.Version
-		for mp, mv := range index.highestReplaced {
+	var mods []module.Version
+	if MainModules != nil { // TODO(#48912): Ensure MainModules exists at this point, and remove the check.
+		for mp, mv := range MainModules.HighestReplaced() {
 			if !maybeInModule(path, mp) {
 				continue
 			}
@@ -439,40 +454,41 @@ func queryImport(ctx context.Context, path string, rs *Requirements) (module.Ver
 			}
 			mods = append(mods, module.Version{Path: mp, Version: mv})
 		}
+	}
 
-		// Every module path in mods is a prefix of the import path.
-		// As in QueryPattern, prefer the longest prefix that satisfies the import.
-		sort.Slice(mods, func(i, j int) bool {
-			return len(mods[i].Path) > len(mods[j].Path)
-		})
-		for _, m := range mods {
-			needSum := true
-			root, isLocal, err := fetch(ctx, m, needSum)
-			if err != nil {
-				if sumErr := (*sumMissingError)(nil); errors.As(err, &sumErr) {
-					return module.Version{}, &ImportMissingSumError{importPath: path}
-				}
-				return module.Version{}, err
-			}
-			if _, ok, err := dirInModule(path, m.Path, root, isLocal); err != nil {
-				return m, err
-			} else if ok {
-				if cfg.BuildMod == "readonly" {
-					return module.Version{}, &ImportMissingError{Path: path, replaced: m}
-				}
-				return m, nil
+	// Every module path in mods is a prefix of the import path.
+	// As in QueryPattern, prefer the longest prefix that satisfies the import.
+	sort.Slice(mods, func(i, j int) bool {
+		return len(mods[i].Path) > len(mods[j].Path)
+	})
+	for _, m := range mods {
+		needSum := true
+		root, isLocal, err := fetch(ctx, m, needSum)
+		if err != nil {
+			if sumErr := (*sumMissingError)(nil); errors.As(err, &sumErr) {
+				return module.Version{}, &ImportMissingSumError{importPath: path}
 			}
+			return module.Version{}, err
 		}
-		if len(mods) > 0 && module.CheckPath(path) != nil {
-			// The package path is not valid to fetch remotely,
-			// so it can only exist in a replaced module,
-			// and we know from the above loop that it is not.
-			return module.Version{}, &PackageNotInModuleError{
-				Mod:         mods[0],
-				Query:       "latest",
-				Pattern:     path,
-				Replacement: Replacement(mods[0]),
+		if _, ok, err := dirInModule(path, m.Path, root, isLocal); err != nil {
+			return m, err
+		} else if ok {
+			if cfg.BuildMod == "readonly" {
+				return module.Version{}, &ImportMissingError{Path: path, replaced: m}
 			}
+			return m, nil
+		}
+	}
+	if len(mods) > 0 && module.CheckPath(path) != nil {
+		// The package path is not valid to fetch remotely,
+		// so it can only exist in a replaced module,
+		// and we know from the above loop that it is not.
+		replacement := Replacement(mods[0])
+		return module.Version{}, &PackageNotInModuleError{
+			Mod:         mods[0],
+			Query:       "latest",
+			Pattern:     path,
+			Replacement: replacement,
 		}
 	}
 
@@ -596,7 +612,7 @@ func dirInModule(path, mpath, mdir string, isLocal bool) (dir string, haveGoFile
 	// (the main module, and any directory trees pointed at by replace directives).
 	if isLocal {
 		for d := dir; d != mdir && len(d) > len(mdir); {
-			haveGoMod := haveGoModCache.Do(d, func() interface{} {
+			haveGoMod := haveGoModCache.Do(d, func() any {
 				fi, err := fsys.Stat(filepath.Join(d, "go.mod"))
 				return err == nil && !fi.IsDir()
 			}).(bool)
@@ -619,7 +635,7 @@ func dirInModule(path, mpath, mdir string, isLocal bool) (dir string, haveGoFile
 	// Are there Go source files in the directory?
 	// We don't care about build tags, not even "+build ignore".
 	// We're just looking for a plausible directory.
-	res := haveGoFilesCache.Do(dir, func() interface{} {
+	res := haveGoFilesCache.Do(dir, func() any {
 		ok, err := fsys.IsDirWithGoFiles(dir)
 		return goFilesEntry{haveGoFiles: ok, err: err}
 	}).(goFilesEntry)
@@ -638,14 +654,14 @@ func dirInModule(path, mpath, mdir string, isLocal bool) (dir string, haveGoFile
 // The isLocal return value reports whether the replacement,
 // if any, is local to the filesystem.
 func fetch(ctx context.Context, mod module.Version, needSum bool) (dir string, isLocal bool, err error) {
-	if mod == Target {
-		return ModRoot(), true, nil
+	if modRoot := MainModules.ModRoot(mod); modRoot != "" {
+		return modRoot, true, nil
 	}
 	if r := Replacement(mod); r.Path != "" {
 		if r.Version == "" {
 			dir = r.Path
 			if !filepath.IsAbs(dir) {
-				dir = filepath.Join(ModRoot(), dir)
+				dir = filepath.Join(replaceRelativeTo(), dir)
 			}
 			// Ensure that the replacement directory actually exists:
 			// dirInModule does not report errors for missing modules,
@@ -667,7 +683,7 @@ func fetch(ctx context.Context, mod module.Version, needSum bool) (dir string, i
 		mod = r
 	}
 
-	if HasModRoot() && cfg.BuildMod == "readonly" && needSum && !modfetch.HaveSum(mod) {
+	if HasModRoot() && cfg.BuildMod == "readonly" && !inWorkspaceMode() && needSum && !modfetch.HaveSum(mod) {
 		return "", false, module.VersionError(mod, &sumMissingError{})
 	}
 
diff --git a/libgo/go/cmd/go/internal/modload/import_test.go b/libgo/go/cmd/go/internal/modload/import_test.go
index 98145887e9d..65a889ec52f 100644
--- a/libgo/go/cmd/go/internal/modload/import_test.go
+++ b/libgo/go/cmd/go/internal/modload/import_test.go
@@ -69,7 +69,7 @@ func TestQueryImport(t *testing.T) {
 	RootMode = NoRoot
 
 	ctx := context.Background()
-	rs := newRequirements(eager, nil, nil)
+	rs := LoadModFile(ctx)
 
 	for _, tt := range importTests {
 		t.Run(strings.ReplaceAll(tt.path, "/", "_"), func(t *testing.T) {
diff --git a/libgo/go/cmd/go/internal/modload/init.go b/libgo/go/cmd/go/internal/modload/init.go
index 45f724d5e36..cdcfbeb8ded 100644
--- a/libgo/go/cmd/go/internal/modload/init.go
+++ b/libgo/go/cmd/go/internal/modload/init.go
@@ -12,11 +12,13 @@ import (
 	"fmt"
 	"go/build"
 	"internal/lazyregexp"
+	"io/ioutil"
 	"os"
 	"path"
 	"path/filepath"
 	"strconv"
 	"strings"
+	"sync"
 
 	"cmd/go/internal/base"
 	"cmd/go/internal/cfg"
@@ -43,28 +45,198 @@ var (
 	ForceUseModules bool
 
 	allowMissingModuleImports bool
+
+	// ExplicitWriteGoMod prevents LoadPackages, ListModules, and other functions
+	// from updating go.mod and go.sum or reporting errors when updates are
+	// needed. A package should set this if it would cause go.mod to be written
+	// multiple times (for example, 'go get' calls LoadPackages multiple times) or
+	// if it needs some other operation to be successful before go.mod and go.sum
+	// can be written (for example, 'go mod download' must download modules before
+	// adding sums to go.sum). Packages that set this are responsible for calling
+	// WriteGoMod explicitly.
+	ExplicitWriteGoMod bool
 )
 
 // Variables set in Init.
 var (
 	initialized bool
-	modRoot     string
-	gopath      string
+
+	// These are primarily used to initialize the MainModules, and should be
+	// eventually superceded by them but are still used in cases where the module
+	// roots are required but MainModules hasn't been initialized yet. Set to
+	// the modRoots of the main modules.
+	// modRoots != nil implies len(modRoots) > 0
+	modRoots []string
+	gopath   string
 )
 
-// Variables set in initTarget (during {Load,Create}ModFile).
+// EnterModule resets MainModules and requirements to refer to just this one module.
+func EnterModule(ctx context.Context, enterModroot string) {
+	MainModules = nil // reset MainModules
+	requirements = nil
+	workFilePath = "" // Force module mode
+	modfetch.Reset()
+
+	modRoots = []string{enterModroot}
+	LoadModFile(ctx)
+}
+
+// Variable set in InitWorkfile
 var (
-	Target module.Version
+	// Set to the path to the go.work file, or "" if workspace mode is disabled.
+	workFilePath string
+)
+
+type MainModuleSet struct {
+	// versions are the module.Version values of each of the main modules.
+	// For each of them, the Path fields are ordinary module paths and the Version
+	// fields are empty strings.
+	versions []module.Version
+
+	// modRoot maps each module in versions to its absolute filesystem path.
+	modRoot map[module.Version]string
 
-	// targetPrefix is the path prefix for packages in Target, without a trailing
-	// slash. For most modules, targetPrefix is just Target.Path, but the
+	// pathPrefix is the path prefix for packages in the module, without a trailing
+	// slash. For most modules, pathPrefix is just version.Path, but the
 	// standard-library module "std" has an empty prefix.
-	targetPrefix string
+	pathPrefix map[module.Version]string
 
-	// targetInGorootSrc caches whether modRoot is within GOROOT/src.
+	// inGorootSrc caches whether modRoot is within GOROOT/src.
 	// The "std" module is special within GOROOT/src, but not otherwise.
-	targetInGorootSrc bool
-)
+	inGorootSrc map[module.Version]bool
+
+	modFiles map[module.Version]*modfile.File
+
+	modContainingCWD module.Version
+
+	workFileGoVersion string
+
+	workFileReplaceMap map[module.Version]module.Version
+	// highest replaced version of each module path; empty string for wildcard-only replacements
+	highestReplaced map[string]string
+
+	indexMu sync.Mutex
+	indices map[module.Version]*modFileIndex
+}
+
+func (mms *MainModuleSet) PathPrefix(m module.Version) string {
+	return mms.pathPrefix[m]
+}
+
+// Versions returns the module.Version values of each of the main modules.
+// For each of them, the Path fields are ordinary module paths and the Version
+// fields are empty strings.
+// Callers should not modify the returned slice.
+func (mms *MainModuleSet) Versions() []module.Version {
+	if mms == nil {
+		return nil
+	}
+	return mms.versions
+}
+
+func (mms *MainModuleSet) Contains(path string) bool {
+	if mms == nil {
+		return false
+	}
+	for _, v := range mms.versions {
+		if v.Path == path {
+			return true
+		}
+	}
+	return false
+}
+
+func (mms *MainModuleSet) ModRoot(m module.Version) string {
+	if mms == nil {
+		return ""
+	}
+	return mms.modRoot[m]
+}
+
+func (mms *MainModuleSet) InGorootSrc(m module.Version) bool {
+	if mms == nil {
+		return false
+	}
+	return mms.inGorootSrc[m]
+}
+
+func (mms *MainModuleSet) mustGetSingleMainModule() module.Version {
+	if mms == nil || len(mms.versions) == 0 {
+		panic("internal error: mustGetSingleMainModule called i[...]

[diff truncated at 524288 bytes]


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-02-11 23:01 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-11 23:01 [gcc r12-7205] libgo: update to Go1.18beta2 Ian Lance Taylor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).