Skip to content

Commit 92f02c9

Browse files
committed
Merge remote-tracking branch 'upstream/master' into 41884-fix
2 parents 4ddb2d7 + ff9e836 commit 92f02c9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+9176
-7501
lines changed

doc/asm.html

Lines changed: 58 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,57 @@ <h3 id="directives">Directives</h3>
464464
</li>
465465
</ul>
466466

467+
<h3 id="data-offsets">Interacting with Go types and constants</h3>
468+
469+
<p>
470+
If a package has any .s files, then <code>go build</code> will direct
471+
the compiler to emit a special header called <code>go_asm.h</code>,
472+
which the .s files can then <code>#include</code>.
473+
The file contains symbolic <code>#define</code> constants for the
474+
offsets of Go struct fields, the sizes of Go struct types, and most
475+
Go <code>const</code> declarations defined in the current package.
476+
Go assembly should avoid making assumptions about the layout of Go
477+
types and instead use these constants.
478+
This improves the readability of assembly code, and keeps it robust to
479+
changes in data layout either in the Go type definitions or in the
480+
layout rules used by the Go compiler.
481+
</p>
482+
483+
<p>
484+
Constants are of the form <code>const_<i>name</i></code>.
485+
For example, given the Go declaration <code>const bufSize =
486+
1024</code>, assembly code can refer to the value of this constant
487+
as <code>const_bufSize</code>.
488+
</p>
489+
490+
<p>
491+
Field offsets are of the form <code><i>type</i>_<i>field</i></code>.
492+
Struct sizes are of the form <code><i>type</i>__size</code>.
493+
For example, consider the following Go definition:
494+
</p>
495+
496+
<pre>
497+
type reader struct {
498+
buf [bufSize]byte
499+
r int
500+
}
501+
</pre>
502+
503+
<p>
504+
Assembly can refer to the size of this struct
505+
as <code>reader__size</code> and the offsets of the two fields
506+
as <code>reader_buf</code> and <code>reader_r</code>.
507+
Hence, if register <code>R1</code> contains a pointer to
508+
a <code>reader</code>, assembly can reference the <code>r</code> field
509+
as <code>reader_r(R1)</code>.
510+
</p>
511+
512+
<p>
513+
If any of these <code>#define</code> names are ambiguous (for example,
514+
a struct with a <code>_size</code> field), <code>#include
515+
"go_asm.h"</code> will fail with a "redefinition of macro" error.
516+
</p>
517+
467518
<h3 id="runtime">Runtime Coordination</h3>
468519

469520
<p>
@@ -615,21 +666,15 @@ <h3 id="x86">32-bit Intel 386</h3>
615666
<p>
616667
The runtime pointer to the <code>g</code> structure is maintained
617668
through the value of an otherwise unused (as far as Go is concerned) register in the MMU.
618-
An OS-dependent macro <code>get_tls</code> is defined for the assembler if the source is
619-
in the <code>runtime</code> package and includes a special header, <code>go_tls.h</code>:
669+
In the runtime package, assembly code can include <code>go_tls.h</code>, which defines
670+
an OS- and architecture-dependent macro <code>get_tls</code> for accessing this register.
671+
The <code>get_tls</code> macro takes one argument, which is the register to load the
672+
<code>g</code> pointer into.
620673
</p>
621674

622-
<pre>
623-
#include "go_tls.h"
624-
</pre>
625-
626675
<p>
627-
Within the runtime, the <code>get_tls</code> macro loads its argument register
628-
with a pointer to the <code>g</code> pointer, and the <code>g</code> struct
629-
contains the <code>m</code> pointer.
630-
There's another special header containing the offsets for each
631-
element of <code>g</code>, called <code>go_asm.h</code>.
632-
The sequence to load <code>g</code> and <code>m</code> using <code>CX</code> looks like this:
676+
For example, the sequence to load <code>g</code> and <code>m</code>
677+
using <code>CX</code> looks like this:
633678
</p>
634679

635680
<pre>
@@ -642,8 +687,7 @@ <h3 id="x86">32-bit Intel 386</h3>
642687
</pre>
643688

644689
<p>
645-
Note: The code above works only in the <code>runtime</code> package, while <code>go_tls.h</code> also
646-
applies to <a href="#arm">arm</a>, <a href="#amd64">amd64</a> and amd64p32, and <code>go_asm.h</code> applies to all architectures.
690+
The <code>get_tls</code> macro is also defined on <a href="#amd64">amd64</a>.
647691
</p>
648692

649693
<p>

doc/go1.16.html

Lines changed: 158 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ <h4 id="list-buildid">The <code>list</code> command</h4>
275275
When the <code>-export</code> flag is specified, the <code>BuildID</code>
276276
field is now set to the build ID of the compiled package. This is equivalent
277277
to running <code>go</code> <code>tool</code> <code>buildid</code> on
278-
<code>go</code> <code>list</code> <code>-exported</code> <code>-f</code> <code>{{.Export}</code>,
278+
<code>go</code> <code>list</code> <code>-exported</code> <code>-f</code> <code>{{.Export}}</code>,
279279
but without the extra step.
280280
</p>
281281

@@ -461,10 +461,10 @@ <h3 id="fs">File Systems</h3>
461461

462462
<p>
463463
The new <a href="/pkg/io/fs/"><code>io/fs</code></a> package
464-
defines an abstraction for read-only trees of files,
465-
the <a href="/pkg/io/fs/#FS"><code>fs.FS</code></a> interface,
466-
and the standard library packages have
467-
been adapted to make use of the interface as appropriate.
464+
defines the <a href="/pkg/io/fs/#FS"><code>fs.FS</code></a> interface,
465+
an abstraction for read-only trees of files.
466+
The standard library packages have been adapted to make use
467+
of the interface as appropriate.
468468
</p>
469469

470470
<p>
@@ -499,6 +499,44 @@ <h3 id="fs">File Systems</h3>
499499
implementations.
500500
</p>
501501

502+
<h3 id="ioutil">Deprecation of io/ioutil</h3>
503+
504+
<p>
505+
The <a href="/pkg/io/ioutil/"><code>io/ioutil</code></a> package has
506+
turned out to be a poorly defined and hard to understand collection
507+
of things. All functionality provided by the package has been moved
508+
to other packages. The <code>io/ioutil</code> package remains and
509+
will continue to work as before, but we encourage new code to use
510+
the new definitions in the <a href="/pkg/io/"><code>io</code></a> and
511+
<a href="/pkg/os/"><code>os</code></a> packages.
512+
513+
Here is a list of the new locations of the names exported
514+
by <code>io/ioutil</code>:
515+
<ul>
516+
<li><a href="/pkg/io/ioutil/#Discard"><code>Discard</code></a>
517+
=> <a href="/pkg/io/#Discard"><code>io.Discard</code></a></li>
518+
<li><a href="/pkg/io/ioutil/#NopCloser"><code>NopCloser</code></a>
519+
=> <a href="/pkg/io/#NopCloser"><code>io.NopCloser</code></a></li>
520+
<li><a href="/pkg/io/ioutil/#ReadAll"><code>ReadAll</code></a>
521+
=> <a href="/pkg/io/#ReadAll"><code>io.ReadAll</code></a></li>
522+
<li><a href="/pkg/io/ioutil/#ReadDir"><code>ReadDir</code></a>
523+
=> <a href="/pkg/os/#ReadDir"><code>os.ReadDir</code></a>
524+
(note: returns a slice of
525+
<a href="/pkg/os/#DirEntry"><code>os.DirEntry</code></a>
526+
rather than a slice of
527+
<a href="/pkg/fs/#FileInfo"><code>fs.FileInfo</code></a>)
528+
</li>
529+
<li><a href="/pkg/io/ioutil/#ReadFile"><code>ReadFile</code></a>
530+
=> <a href="/pkg/os/#ReadFile"><code>os.ReadFile</code></a></li>
531+
<li><a href="/pkg/io/ioutil/#TempDir"><code>TempDir</code></a>
532+
=> <a href="/pkg/os/#MkdirTemp"><code>os.MkdirTemp</code></a></li>
533+
<li><a href="/pkg/io/ioutil/#TempFile"><code>TempFile</code></a>
534+
=> <a href="/pkg/os/#CreateTemp"><code>os.CreateTemp</code></a></li>
535+
<li><a href="/pkg/io/ioutil/#WriteFile"><code>WriteFile</code></a>
536+
=> <a href="/pkg/os/#WriteFile"><code>os.WriteFile</code></a></li>
537+
</ul>
538+
</p>
539+
502540
<!-- okay-after-beta1
503541
TODO: decide if any additional changes are worth factoring out from
504542
"Minor changes to the library" and highlighting in "Core library"
@@ -623,6 +661,14 @@ <h3 id="minor_library_changes">Minor changes to the library</h3>
623661
method allows accessing the <a href="/pkg/crypto/x509/#SystemRootsError.Err"><code>Err</code></a>
624662
field through the <a href="/pkg/errors"><code>errors</code></a> package functions.
625663
</p>
664+
665+
<p><!-- CL 230025 -->
666+
On Unix systems, the <code>crypto/x509</code> package is now more
667+
efficient in how it stores its copy of the system cert pool.
668+
Programs that use only a small number of roots will use around a
669+
half megabyte less memory.
670+
</p>
671+
626672
</dd>
627673
</dl><!-- crypto/x509 -->
628674

@@ -685,6 +731,37 @@ <h3 id="minor_library_changes">Minor changes to the library</h3>
685731
</dd>
686732
</dl><!-- flag -->
687733

734+
<dl id="go/build"><dt><a href="/pkg/go/build/">go/build</a></dt>
735+
<dd>
736+
<p><!-- CL 243941, CL 283636 -->
737+
The <a href="/pkg/go/build/#Package"><code>Package</code></a>
738+
struct has new fields that report information
739+
about <code>//go:embed</code> directives in the package:
740+
<a href="/pkg/go/build/#Package.EmbedPatterns"><code>EmbedPatterns</code></a>,
741+
<a href="/pkg/go/build/#Package.EmbedPatternPos"><code>EmbedPatternPos</code></a>,
742+
<a href="/pkg/go/build/#Package.TestEmbedPatterns"><code>TestEmbedPatterns</code></a>,
743+
<a href="/pkg/go/build/#Package.TestEmbedPatternPos"><code>TestEmbedPatternPos</code></a>,
744+
<a href="/pkg/go/build/#Package.XTestEmbedPatterns"><code>XTestEmbedPatterns</code></a>,
745+
<a href="/pkg/go/build/#Package.XTestEmbedPatternPos"><code>XTestEmbedPatternPos</code></a>.
746+
</p>
747+
748+
<p><!-- CL 240551 -->
749+
The <a href="/pkg/go/build/#Package"><code>Package</code></a> field
750+
<a href="/pkg/go/build/#Package.IgnoredGoFiles"><code>IgnoredGoFiles</code></a>
751+
will no longer include files that start with "_" or ".",
752+
as those files are always ignored.
753+
<code>IgnoredGoFiles</code> is for files ignored because of
754+
build constraints.
755+
</p>
756+
757+
<p><!-- CL 240551 -->
758+
The new <a href="/pkg/go/build/#Package"><code>Package</code></a>
759+
field <a href="/pkg/go/build/#Package.IgnoredOtherFiles"><code>IgnoredOtherFiles</code></a>
760+
has a list of non-Go files ignored because of build constraints.
761+
</p>
762+
</dd>
763+
</dl><!-- go/build -->
764+
688765
<dl id="html/template"><dt><a href="/pkg/html/template/">html/template</a></dt>
689766
<dd>
690767
<p><!-- CL 243938 -->
@@ -703,6 +780,15 @@ <h3 id="minor_library_changes">Minor changes to the library</h3>
703780
The package now defines a
704781
<a href="/pkg/io/#ReadSeekCloser"><code>ReadSeekCloser</code></a> interface.
705782
</p>
783+
784+
<p><!-- CL 263141 -->
785+
The package now defines
786+
<a href="/pkg/io/#Discard"><code>Discard</code></a>,
787+
<a href="/pkg/io/#NopCloser"><code>NopCloser</code></a>, and
788+
<a href="/pkg/io/#ReadAll"><code>ReadAll</code></a>,
789+
to be used instead of the same names in the
790+
<a href="/pkg/io/ioutil/"><code>io/ioutil</code></a> package.
791+
</p>
706792
</dd>
707793
</dl><!-- io -->
708794

@@ -857,6 +943,52 @@ <h3 id="minor_library_changes">Minor changes to the library</h3>
857943
instead of the unexported <code>errFinished</code> when the process has
858944
already finished.
859945
</p>
946+
947+
<p><!-- CL 261540 -->
948+
The package defines a new type
949+
<a href="/pkg/os/#DirEntry"><code>DirEntry</code></a>
950+
as an alias for <a href="/pkg/io/fs/#DirEntry"><code>fs.DirEntry</code></a>.
951+
The new <a href="/pkg/os/#ReadDir"><code>ReadDir</code></a>
952+
function and the new
953+
<a href="/pkg/os/#File.ReadDir"><code>File.ReadDir</code></a>
954+
method can be used to read the contents of a directory into a
955+
slice of <a href="/pkg/os/#DirEntry"><code>DirEntry</code></a>.
956+
The <a href="/pkg/os/#File.Readdir"><code>File.Readdir</code></a>
957+
method (note the lower case <code>d</code> in <code>dir</code>)
958+
still exists, returning a slice of
959+
<a href="/pkg/os/#FileInfo"><code>FileInfo</code></a>, but for
960+
most programs it will be more efficient to switch to
961+
<a href="/pkg/os/#File.ReadDir"><code>File.ReadDir</code></a>.
962+
</p>
963+
964+
<p><!-- CL 263141 -->
965+
The package now defines
966+
<a href="/pkg/os/#CreateTemp"><code>CreateTemp</code></a>,
967+
<a href="/pkg/os/#MkdirTemp"><code>MkdirTemp</code></a>,
968+
<a href="/pkg/os/#ReadFile"><code>ReadFile</code></a>, and
969+
<a href="/pkg/os/#WriteFile"><code>WriteFile</code></a>,
970+
to be used instead of functions defined in the
971+
<a href="/pkg/io/ioutil/"><code>io/ioutil</code></a> package.
972+
</p>
973+
974+
<p><!-- CL 243906 -->
975+
The types <a href="/pkg/os/#FileInfo"><code>FileInfo</code></a>,
976+
<a href="/pkg/os/#FileMode"><code>FileMode</code></a>, and
977+
<a href="/pkg/os/#PathError"><code>PathError</code></a>
978+
are now aliases for types of the same name in the
979+
<a href="/pkg/io/fs/"><code>io/fs</code></a> package.
980+
Function signatures in the <a href="/pkg/os/"><code>os</code></a>
981+
package have been updated to refer to the names in the
982+
<a href="/pkg/io/fs/"><code>io/fs</code></a> package.
983+
This should not affect any existing code.
984+
</p>
985+
986+
<p><!-- CL 243911 -->
987+
The new <a href="/pkg/os/#DirFS"><code>DirFS</code></a> function
988+
provides an implementation of
989+
<a href="/pkg/io/fs/#FS"><code>fs.FS</code></a> backed by a tree
990+
of operating system files.
991+
</p>
860992
</dd>
861993
</dl><!-- os -->
862994

@@ -887,9 +1019,9 @@ <h3 id="minor_library_changes">Minor changes to the library</h3>
8871019
<dd>
8881020
<p><!-- CL 267887 -->
8891021
The new function
890-
<a href="/pkg/path/filepath/WalkDir"><code>WalkDir</code></a>
1022+
<a href="/pkg/path/filepath/#WalkDir"><code>WalkDir</code></a>
8911023
is similar to
892-
<a href="/pkg/path/filepath/Walk"><code>Walk</code></a>,
1024+
<a href="/pkg/path/filepath/#Walk"><code>Walk</code></a>,
8931025
but is typically more efficient.
8941026
The function passed to <code>WalkDir</code> receives a
8951027
<a href="/pkg/io/fs/#DirEntry"><code>fs.DirEntry</code></a>
@@ -975,6 +1107,25 @@ <h3 id="minor_library_changes">Minor changes to the library</h3>
9751107
</dd>
9761108
</dl><!-- syscall -->
9771109

1110+
<dl id="testing/iotest"><dt><a href="/pkg/testing/iotest/">testing/iotest</a></dt>
1111+
<dd>
1112+
<p><!-- CL 199501 -->
1113+
The new
1114+
<a href="/pkg/testing/iotest/#ErrReader"><code>ErrReader</code></a>
1115+
function returns an
1116+
<a href="/pkg/io/#Reader"><code>io.Reader</code></a> that always
1117+
returns an error.
1118+
</p>
1119+
1120+
<p><!-- CL 243909 -->
1121+
The new
1122+
<a href="/pkg/testing/iotest/#TestReader"><code>TestReader</code></a>
1123+
function tests that an <a href="/pkg/io/#Reader"><code>io.Reader</code></a>
1124+
behaves correctly.
1125+
</p>
1126+
</dd>
1127+
</dl><!-- testing/iotest -->
1128+
9781129
<dl id="text/template"><dt><a href="/pkg/text/template/">text/template</a></dt>
9791130
<dd>
9801131
<p><!-- CL 254257, golang.org/issue/29770 -->

lib/time/update.bash

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
# Consult https://www.iana.org/time-zones for the latest versions.
99

1010
# Versions to use.
11-
CODE=2020f
12-
DATA=2020f
11+
CODE=2021a
12+
DATA=2021a
1313

1414
set -e
1515
rm -rf work

lib/time/zoneinfo.zip

9 Bytes
Binary file not shown.

src/cmd/compile/internal/gc/walk.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ func walkstmt(n *Node) *Node {
267267
if n.List.Len() == 0 {
268268
break
269269
}
270-
if (Curfn.Type.FuncType().Outnamed && n.List.Len() > 1) || paramoutheap(Curfn) {
270+
if (Curfn.Type.FuncType().Outnamed && n.List.Len() > 1) || paramoutheap(Curfn) || Curfn.Func.HasDefer() {
271271
// assign to the function out parameters,
272272
// so that reorder3 can fix up conflicts
273273
var rl []*Node
@@ -2233,7 +2233,15 @@ func aliased(r *Node, all []*Node) bool {
22332233
memwrite = true
22342234
continue
22352235

2236-
case PAUTO, PPARAM, PPARAMOUT:
2236+
case PPARAMOUT:
2237+
// Assignments to a result parameter in a function with defers
2238+
// becomes visible early if evaluation of any later expression
2239+
// panics (#43835).
2240+
if Curfn.Func.HasDefer() {
2241+
return true
2242+
}
2243+
fallthrough
2244+
case PAUTO, PPARAM:
22372245
if l.Name.Addrtaken() {
22382246
memwrite = true
22392247
continue

src/cmd/go/testdata/script/cgo_path.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
[!cgo] skip
22

3+
# Set CC explicitly to something that requires a PATH lookup.
4+
# Normally, the default is gcc or clang, but if CC was set during make.bash,
5+
# that becomes the default.
6+
[exec:clang] env CC=clang
7+
[exec:gcc] env CC=gcc
8+
[!exec:clang] [!exec:gcc] skip 'Unknown C compiler'
9+
310
env GOCACHE=$WORK/gocache # Looking for compile flags, so need a clean cache.
411
[!windows] env PATH=.:$PATH
512
[!windows] chmod 0755 p/gcc p/clang

0 commit comments

Comments
 (0)