1
0
mirror of https://github.com/golang/go synced 2024-11-08 08:56:16 -07:00
Commit Graph

54570 Commits

Author SHA1 Message Date
cui fliter
2e054128bf cmd/go/internal: use strings.Cut
Change-Id: Icbe2af4f2abf22b6a8c9cec33f0f88018f3bd1c7
GitHub-Last-Rev: 81392a6e88
GitHub-Pull-Request: golang/go#55908
Reviewed-on: https://go-review.googlesource.com/c/go/+/435737
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
2022-10-06 02:38:04 +00:00
Damien Neil
0bf7ee9977 archive/tar: limit size of headers
Set a 1MiB limit on special file blocks (PAX headers, GNU long names,
GNU link names), to avoid reading arbitrarily large amounts of data
into memory.

Thanks to Adam Korczynski (ADA Logics) and OSS-Fuzz for reporting
this issue.

Fixes CVE-2022-2879
For #54853

Change-Id: I85136d6ff1e0af101a112190e027987ab4335680
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go-private/+/1565555
Reviewed-by: Tatiana Bradley <tatianabradley@google.com>
Run-TryBot: Roland Shoemaker <bracewell@google.com>
Reviewed-by: Roland Shoemaker <bracewell@google.com>
Reviewed-on: https://go-review.googlesource.com/c/go/+/439355
Reviewed-by: Damien Neil <dneil@google.com>
Run-TryBot: Roland Shoemaker <roland@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Roland Shoemaker <roland@golang.org>
2022-10-05 20:40:43 +00:00
Russ Cox
c3c4aea55b regexp: limit size of parsed regexps
Set a 128 MB limit on the amount of space used by []syntax.Inst
in the compiled form corresponding to a given regexp.

Also set a 128 MB limit on the rune storage in the *syntax.Regexp
tree itself.

Thanks to Adam Korczynski (ADA Logics) and OSS-Fuzz for reporting this issue.

Fixes CVE-2022-41715.
Fixes #55949.

Change-Id: Ia656baed81564436368cf950e1c5409752f28e1b
Reviewed-on: https://go-review.googlesource.com/c/go/+/439356
Auto-Submit: Roland Shoemaker <roland@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Roland Shoemaker <roland@golang.org>
Reviewed-by: Damien Neil <dneil@google.com>
2022-10-05 20:39:49 +00:00
Michael Matloob
881a16542e cmd/go/internal/modindex: ignore non-source files for index
We were saving non-go file information in the module index files,
leading in an unnecessary increase in memory usage in modules
containing many non-go files. This was a bug because this information
is never used. Don't save that information.

For #54226

Change-Id: I0644064f83f96e3a9f43b7e66ca94d69d9603376
Reviewed-on: https://go-review.googlesource.com/c/go/+/439118
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
Run-TryBot: Michael Matloob <matloob@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
2022-10-05 18:59:21 +00:00
hopehook
3a37b11281 cmd/go: add @latest suffix for go install
Fixes #56014.

Change-Id: I75a3960e092459531de43868750f1684ed2ccb70
Reviewed-on: https://go-review.googlesource.com/c/go/+/437998
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
Reviewed-by: Tim King <taking@google.com>
Run-TryBot: hopehook <hopehook@golangcn.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Bryan Mills <bcmills@google.com>
2022-10-05 17:44:59 +00:00
Wang Deyu
f63b268b9a runtime: avoid initializing MemProfileRate in init function
Fixes #55100

Change-Id: Ibbff921e74c3a416fd8bb019d20410273961c015
Reviewed-on: https://go-review.googlesource.com/c/go/+/431315
Auto-Submit: Michael Pratt <mpratt@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Michael Pratt <mpratt@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
2022-10-05 17:31:56 +00:00
Robert Griesemer
97d38f3002 go/types, types2: use consistent error messages for invalid struct literals
Fixes #51879.

Change-Id: Ic7ac892b82a0fe4ad6f95ff8ae84e6d30c52c111
Reviewed-on: https://go-review.googlesource.com/c/go/+/438855
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
Run-TryBot: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-10-05 16:52:44 +00:00
Than McIntosh
47a538842b runtime/coverage: revise/shorten function names
Use shorter more Go-like names for the new APIs being added in the
runtime/coverage package for writing coverage data under user control
from server programs. Old names were a bit too clunky/verbose.

Updates #51430.

Change-Id: Ifdd5b882a88613c7c4342b40ed93b58547483c77
Reviewed-on: https://go-review.googlesource.com/c/go/+/438503
Reviewed-by: Russ Cox <rsc@golang.org>
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-10-05 14:59:05 +00:00
shaoliming
9f78c3cb04 cmd/internal/obj/arm64: add missing operand register in GNU assembly
Fixes #55832

Change-Id: Ib20279d47c1ca9a383a3c85bb41ca4f550bb0a33
GitHub-Last-Rev: 10af77a2f2
GitHub-Pull-Request: golang/go#55838
Reviewed-on: https://go-review.googlesource.com/c/go/+/433575
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: hopehook <hopehook@golangcn.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
2022-10-05 14:57:54 +00:00
Cherry Mui
500bc6b805 runtime: don't jump stack if at entry of systemstack
The traceback code has special "jump stack" logic, to trace back
stack switches through systemstack. If we're at the entry of
systemstack, the stack switch hasn't happened, so don't jump to
user stack.

The jump stack logic is only used if we're on the g0 stack. It can
happen that we're at the entry of a recursive systemstack call on
the g0 stack. In we jump stack here, there will be two problems:
1. There are frames between entering the g0 stack and this
   recursive systemstack call. Those frames will be lost.
2. Worse, we switched frame.sp but frame.fp calculation will use
   the entry SP delta (0), which will be wrong, which in turn
   leads wrong frame.lr and things will go off.

For now, don't jump stack if we're at entry of systemstack (SP
delta is 0).

Using a per-PC SPWRITE marker may be a better fix. If we haven't
written the SP, we haven't switched the stack so we can just
unwind like a normal function.

May fix #55851.

Change-Id: I2b624c8c086b235b34d9c7d3cebd4a37264f00f8
Reviewed-on: https://go-review.googlesource.com/c/go/+/437299
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Cherry Mui <cherryyz@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
2022-10-05 14:52:31 +00:00
Youlin Feng
7d3a5a501c runtime/cgo: let darwin pthread stacksize follow rlimit
On Mac OS X, the default stack size for non-main threads created by cgo is
fixed at 512KB and cannot be altered by setrlimit. This stack size is too
small for some recursive scenarios. We can solve this problem by explicitly
copying the stack size of the main thread when creating a new thread.

Change-Id: I400d5b2e929a1ee261502914a991e208759f64a8
GitHub-Last-Rev: b29c74599e
GitHub-Pull-Request: golang/go#53667
Reviewed-on: https://go-review.googlesource.com/c/go/+/415915
Run-TryBot: Cherry Mui <cherryyz@google.com>
Reviewed-by: hopehook <hopehook@golangcn.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
2022-10-05 14:48:48 +00:00
Paul E. Murphy
c318f191e4 cmd/link: optimize PPC64 inline plt sequences if local
Indirect branches are much more expensive than direct. If the call is
known to be local, we can replace most of the operations with a nop,
and call directly.

Updates #53345

Change-Id: Icfff9ec1f6c7f8e4181f0f28976033308d2f53eb
Reviewed-on: https://go-review.googlesource.com/c/go/+/412715
Reviewed-by: Cherry Mui <cherryyz@google.com>
Run-TryBot: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-10-05 14:12:24 +00:00
eric fang
ddc7d2a80c cmd/compile: add late lower pass for last rules to run
Usually optimization rules have corresponding priorities, some need to
be run first, some run next, and some run last, which produces the best
code. But currently our optimization rules have no priority, this CL
adds a late lower pass that runs those rules that need to be run at last,
such as split unreasonable constant folding. This pass can be seen as
the second round of the lower pass.

For example:
func foo(a, b uint64) uint64 {
        d := a+0x1234568
        d1 := b+0x1234568
        return d&d1
}
The code generated by the master branch:
	0x0004 00004        ADD     $19088744, R0, R2 // movz+movk+add
	0x0010 00016        ADD     $19088744, R1, R1 // movz+movk+add
	0x001c 00028        AND     R1, R2, R0

This is because the current constant folding optimization rules do not
take into account the range of constants, causing the constant to be
loaded repeatedly. This CL splits these unreasonable constants folding
in the late lower pass. With this CL the generated code:
	0x0004 00004        MOVD    $19088744, R2 // movz+movk
	0x000c 00012        ADD     R0, R2, R3
	0x0010 00016        ADD     R1, R2, R1
	0x0014 00020        AND     R1, R3, R0

This CL also adds constant folding optimization for ADDS instruction.

In addition, in order not to introduce the codegen regression, an
optimization rule is added to change the addition of a negative number
into a subtraction of a positive number.

go1 benchmarks:
name                     old time/op    new time/op    delta
BinaryTree17-8              1.22s ± 1%     1.24s ± 0%  +1.56%  (p=0.008 n=5+5)
Fannkuch11-8                1.54s ± 0%     1.53s ± 0%  -0.69%  (p=0.016 n=4+5)
FmtFprintfEmpty-8          14.1ns ± 0%    14.1ns ± 0%    ~     (p=0.079 n=4+5)
FmtFprintfString-8         26.0ns ± 0%    26.1ns ± 0%  +0.23%  (p=0.008 n=5+5)
FmtFprintfInt-8            32.3ns ± 0%    32.9ns ± 1%  +1.72%  (p=0.008 n=5+5)
FmtFprintfIntInt-8         54.5ns ± 0%    55.5ns ± 0%  +1.83%  (p=0.008 n=5+5)
FmtFprintfPrefixedInt-8    61.5ns ± 0%    62.0ns ± 0%  +0.93%  (p=0.008 n=5+5)
FmtFprintfFloat-8          72.0ns ± 0%    73.6ns ± 0%  +2.24%  (p=0.008 n=5+5)
FmtManyArgs-8               221ns ± 0%     224ns ± 0%  +1.22%  (p=0.008 n=5+5)
GobDecode-8                1.91ms ± 0%    1.93ms ± 0%  +0.98%  (p=0.008 n=5+5)
GobEncode-8                1.40ms ± 1%    1.39ms ± 0%  -0.79%  (p=0.032 n=5+5)
Gzip-8                      115ms ± 0%     117ms ± 1%  +1.17%  (p=0.008 n=5+5)
Gunzip-8                   19.4ms ± 1%    19.3ms ± 0%  -0.71%  (p=0.016 n=5+4)
HTTPClientServer-8         27.0µs ± 0%    27.3µs ± 0%  +0.80%  (p=0.008 n=5+5)
JSONEncode-8               3.36ms ± 1%    3.33ms ± 0%    ~     (p=0.056 n=5+5)
JSONDecode-8               17.5ms ± 2%    17.8ms ± 0%  +1.71%  (p=0.016 n=5+4)
Mandelbrot200-8            2.29ms ± 0%    2.29ms ± 0%    ~     (p=0.151 n=5+5)
GoParse-8                  1.35ms ± 1%    1.36ms ± 1%    ~     (p=0.056 n=5+5)
RegexpMatchEasy0_32-8      24.5ns ± 0%    24.5ns ± 0%    ~     (p=0.444 n=4+5)
RegexpMatchEasy0_1K-8       131ns ±11%     118ns ± 6%    ~     (p=0.056 n=5+5)
RegexpMatchEasy1_32-8      22.9ns ± 0%    22.9ns ± 0%    ~     (p=0.905 n=4+5)
RegexpMatchEasy1_1K-8       126ns ± 0%     127ns ± 0%    ~     (p=0.063 n=4+5)
RegexpMatchMedium_32-8      486ns ± 5%     483ns ± 0%    ~     (p=0.381 n=5+4)
RegexpMatchMedium_1K-8     15.4µs ± 1%    15.5µs ± 0%    ~     (p=0.151 n=5+5)
RegexpMatchHard_32-8        687ns ± 0%     686ns ± 0%    ~     (p=0.103 n=5+5)
RegexpMatchHard_1K-8       20.7µs ± 0%    20.7µs ± 1%    ~     (p=0.151 n=5+5)
Revcomp-8                   175ms ± 2%     176ms ± 3%    ~     (p=1.000 n=5+5)
Template-8                 20.4ms ± 6%    20.1ms ± 2%    ~     (p=0.151 n=5+5)
TimeParse-8                 112ns ± 0%     113ns ± 0%  +0.97%  (p=0.016 n=5+4)
TimeFormat-8                156ns ± 0%     145ns ± 0%  -7.14%  (p=0.029 n=4+4)

Change-Id: I3ced26e89041f873ac989586514ccc5ee09f13da
Reviewed-on: https://go-review.googlesource.com/c/go/+/425134
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
Run-TryBot: Eric Fang <eric.fang@arm.com>
2022-10-05 02:40:56 +00:00
Robert Griesemer
c591d82ea9 cmd/compile/internal/syntax: better error message for erroneous method declaration
Also make error recovery slightly more robust in this case.

Fixes #56022.

Change-Id: I1c01c1465adb48c71367d037b6f0e3fe56f68ec9
Reviewed-on: https://go-review.googlesource.com/c/go/+/438540
Run-TryBot: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-10-05 01:05:29 +00:00
Robert Griesemer
d118743869 cmd/compile/internal/types2: remove "unimplemented" function (cleanup)
Change-Id: I72fed206df1a4e36d5e519378599e8d952423d53
Reviewed-on: https://go-review.googlesource.com/c/go/+/438346
Auto-Submit: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
Run-TryBot: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-10-05 00:48:21 +00:00
Tomasz Jezierski
9c2fd81ee1 encoding/asn1: remove allocation from init
asn1 allocates due to reflect.TypeOf(new(big.Int)) in init time.
We could replace it with (*big.Int)(nil).

Before:
init encoding/asn1 @1.0 ms, 0.009 ms clock, 224 bytes, 7 allocs

After:
init encoding/asn1 @0.70 ms, 0.002 ms clock, 192 bytes, 6 allocs

Fixes #55973

Change-Id: I7c3cc0f48631af73cf34ad3c731c380f46c72359
Reviewed-on: https://go-review.googlesource.com/c/go/+/435257
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: hopehook <hopehook@golangcn.org>
Auto-Submit: Ian Lance Taylor <iant@google.com>
2022-10-04 23:29:48 +00:00
Bryan C. Mills
0fec65d281 os/exec: add a GODEBUG setting to diagnose leaked processes
Updates #52580.
For #50436.

Change-Id: I669f13863f1f85d576c3c94500b118e6989000eb
Reviewed-on: https://go-review.googlesource.com/c/go/+/436655
Auto-Submit: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
2022-10-04 23:19:13 +00:00
Zeke Lu
e7d203f494 reflect: avoid unnecessary copy of funcTypes
Imagine that initFuncTypes is called with n=3, funcTypes will be
[nil, nil, nil, **reflect.rtype] afterward, then it's called with n=2.
The current implementation will copy funcTypes because funcTypes[2] is
nil. This is unnecessary. It should make a new slice and copy funcTypes
into it only when n >= len(funcTypes).

Updates #56011.

Change-Id: Ia093d2f550d6924a4c58bcd21325093e32b40baa
GitHub-Last-Rev: a599eae7c2
GitHub-Pull-Request: golang/go#56024
Reviewed-on: https://go-review.googlesource.com/c/go/+/438395
Auto-Submit: Ian Lance Taylor <iant@google.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Keith Randall <khr@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Auto-Submit: Keith Randall <khr@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
2022-10-04 23:15:54 +00:00
cui fliter
58158e990f all: use fmt.Appendf
Change-Id: I45f941ba3db26a12b3f56d93bdcd7f9e1d490346
GitHub-Last-Rev: 22b51167b0
GitHub-Pull-Request: golang/go#56030
Reviewed-on: https://go-review.googlesource.com/c/go/+/438539
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
2022-10-04 22:43:12 +00:00
Bryan Mills
3380ee2520 Revert "os/exec: make StdoutPipe and StderrPipe safe to Close concurrently"
This reverts CL 437176.

Reason for revert: broke programs that plumb StdoutPipe from one command to Stdin on another and then call Wait on the former.

os/exec itself uses a type-assertion to *os.File to determine whether to copy stdin using a goroutine or just pass a file descriptor. An early Wait using a *os.File is benign (because closing the pipe doesn't close the child's inherited file descriptor), but an early Wait using a non-*os.File is not.

Updates #50436.

Change-Id: I4a2993e290982834f91696d890dfe77364c0cc50
Reviewed-on: https://go-review.googlesource.com/c/go/+/438695
Auto-Submit: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Bryan Mills <bcmills@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
2022-10-04 21:17:23 +00:00
Russ Cox
058f019e45 cmd/cgo, cmd/compile, cmd/link: remove old style build tags
[Roll-forward of CL 436915 by Tobias Klauser, with builtin and gen
directories dropped now that they've been handled separately.]

The minimum bootstrap version for Go ≥ 1.20 is Go 1.17. That version
supports the new style //go:build lines. Thus the old style //+build
lines can be dropped in this part of the tree as well. Leave the
//+build lines in cmd/dist which will ensure the minimum Go version
during bootstrap.

As suggested by Cherry during review of CL 430496

For #44505

Change-Id: Ifa686656c3e50bf7f92f70747b44d74a7d51bad8
Reviewed-on: https://go-review.googlesource.com/c/go/+/435473
Reviewed-by: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
2022-10-04 19:36:17 +00:00
Russ Cox
164406ad93 cmd/compile: rename gen and builtin to _gen and _builtin
These two directories are full of //go:build ignore files.
We can ignore them more easily by putting an underscore
at the start of the name. That also works around a bug
in Go 1.17 that was not fixed until Go 1.17.3.

Change-Id: Ia5389b65c79b1e6d08e4fef374d335d776d44ead
Reviewed-on: https://go-review.googlesource.com/c/go/+/435472
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
2022-10-04 19:35:46 +00:00
Than McIntosh
841873f27c runtime: change exit hooks test to use RaceDetectorSupported
Use internal/syssup.RaceDetectorSupported in the exit hooks tests as a
better way to tell if the race detector is available.

Change-Id: I8f43f93319f68b9910f2eea88fc375f7ef3bb2e4
Reviewed-on: https://go-review.googlesource.com/c/go/+/438476
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-10-04 18:52:38 +00:00
Than McIntosh
cddf792428 runtime/coverage: use atomic access for counter reads
Read counters using atomic ops so as to avoid problems with the race
detector if a goroutine happens to still be executing at the end of a
test run when we're writing out counter data. In theory we could guard
the atomic use on the counter mode, but it's better just to do it in
all cases, leaves us with a simpler implementation.

Fixes #56006.

Change-Id: I81c2234b5a1c3b00cff6c77daf2c2315451b7f6c
Reviewed-on: https://go-review.googlesource.com/c/go/+/438256
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: David Chase <drchase@google.com>
Run-TryBot: Than McIntosh <thanm@google.com>
2022-10-04 18:49:20 +00:00
Than McIntosh
8bd803fd4e cmd/internal/sys: migrate support.go functions to new internal pkg
Separate out the functions from cmd/internal/sys/support.go and
migrate them to a new package internal/platform, so that functions such as
"RaceDetectorSupported" can be called from tests in std as well as in
cmd. This isn't a complete move of everything in cmd/internal/sys;
there are still many functions left.

The original version of this CL (patch set 1) called the new package
"internal/sys", but for packages that needed both "internal/sys" and
"cmd/internal/sys" the import of the former had to be done with a
different name, which was confusing and also required a hack in
cmd/dist.

Updates #56006.

Change-Id: I866d62e75adbf3a640a06e2c7386a6e9e2a18d91
Reviewed-on: https://go-review.googlesource.com/c/go/+/438475
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Run-TryBot: Than McIntosh <thanm@google.com>
2022-10-04 18:08:15 +00:00
Andrew Pogrebnoy
dfd8aa461b cmd/compile: add "runtime/internal/syscall" back to runtimePackages
It was accidentally removed in CL 355451.

Change-Id: I818ea01b83e437c25829bf7e88c7180963e696f8
Reviewed-on: https://go-review.googlesource.com/c/go/+/438615
Auto-Submit: Michael Pratt <mpratt@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Pratt <mpratt@google.com>
Run-TryBot: Michael Pratt <mpratt@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
2022-10-04 17:42:01 +00:00
Archana R
feed072b6e cmd/go: update gcc version check for asan support on ppc64le
Update the minimum version required for asan to be gcc9.
This will ensure that go build -asan is supported only on
systems with the required version of gcc. Update the asan
error message to include the name of the compiler (the
error message is updated to include the name of the compiler
instead of C compiler for other platforms as well).

Related to CL 425355

Change-Id: Ib864d43b2b3028f39ffcf792890a678361f507f6
Reviewed-on: https://go-review.googlesource.com/c/go/+/436740
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Archana Ravindar <aravind5@in.ibm.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
2022-10-04 17:19:12 +00:00
Roland Shoemaker
fa463cc96d crypto/x509/internal/macos: handle unexpected null returns
SecCreatePolicySSL returns null when called from a binary that has a
strange path. This seems to be a weirdo macos bug, but we should be
properly handling those null returns anyway. Also add handling for
SecTrustGetCertificateAtIndex.

Fixes #54590

Change-Id: I251e74f3b0bf65890a80b094b3e88718e13fd3db
Reviewed-on: https://go-review.googlesource.com/c/go/+/438135
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Roland Shoemaker <roland@golang.org>
Reviewed-by: Damien Neil <dneil@google.com>
Auto-Submit: Roland Shoemaker <roland@golang.org>
2022-10-04 16:03:32 +00:00
Florian Zenker
6a9aaf1f02 runtime/race: use internal linking mode for amd64 subarch packages
CL 424034 introduced two new packages that trigger external
linking mode where internal linking mode is sufficient.

Change-Id: I81583210331fe4151d631b5efd7fc5d3c8f11f39
Reviewed-on: https://go-review.googlesource.com/c/go/+/435256
Run-TryBot: Than McIntosh <thanm@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-10-04 15:03:23 +00:00
Daniel Martí
cbd931c9c2 encoding/gob: prevent a decoder state overflow
When decoding a struct, if a positive delta is large enough to overflow
when added to fieldnum, we would panic due to the resulting negative index.

Instead, catch this problem and produce an error like we do with
negative delta integers. If fieldnum ends up being negative or smaller
than state.fieldnum, the addition overflowed.

While here, remove an unnecessary break after an error call,
since those error functions cause a panic.

Fixes #55337.

Change-Id: I7a0e4f43e5c81a703e79c1597e3bb3714cc832c8
Reviewed-on: https://go-review.googlesource.com/c/go/+/432715
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-10-04 13:27:35 +00:00
Cuong Manh Le
6d8ec89303 reflect: fix race condition on funcTypes
CL 425314 made creating funcTypes using StructOf, and using a mutex to
protect read+write to funcTypes. However, after initializing funcTypes,
it is accessed in FuncOf without holding lock, causing a race.

Fixing it by returning the n-th Type directly from initFuncTypes, so the
accessing funcTypes will always be guarded by a mutex.

Fixes #56011

Change-Id: I1b50d1ae342943f16f368b8606f2614076dc90fb
Reviewed-on: https://go-review.googlesource.com/c/go/+/437997
Reviewed-by: Keith Randall <khr@google.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
2022-10-03 20:06:58 +00:00
hopehook
12daabb915 go/build: replace +build with go:build in documentation
Fixes #54181.

Change-Id: I47f5102ff2095a794b6fc6bcf75617ba5f85c24d
Reviewed-on: https://go-review.googlesource.com/c/go/+/437995
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-10-03 18:24:24 +00:00
cui fliter
78f7d0f001 cmd/compile/internal: fix a few function names on comments
Change-Id: If78c6d3c6183494f71f2857e496e172a789da39f
GitHub-Last-Rev: 58e0b75052
GitHub-Pull-Request: golang/go#55992
Reviewed-on: https://go-review.googlesource.com/c/go/+/437517
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Keith Randall <khr@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Keith Randall <khr@golang.org>
Auto-Submit: Keith Randall <khr@golang.org>
2022-10-03 17:47:02 +00:00
cuiweixie
a8d180409d cmd/trace: replace loop with append(slice, slice2...)
Change-Id: I4686f36a8f718fea1a08d816bc14e24e3528bb07
Reviewed-on: https://go-review.googlesource.com/c/go/+/436706
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: hopehook <hopehook@golangcn.org>
Run-TryBot: xie cui <523516579@qq.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Ian Lance Taylor <iant@google.com>
2022-10-03 15:30:36 +00:00
miller
17622b891a runtime/coverage: recognise Plan 9 error message in emitToNonexistentDir
In TestCoverageApis/emitToNonexistentDir there is a list of error
messages to match when a nonexistent directory is opened. The list
has message text only for Unix and Windows. Add the corresponding
text for Plan 9.

Fixes #55983

Change-Id: Id32130300cb02394b319e1aeb1229ee147b4afb2
Reviewed-on: https://go-review.googlesource.com/c/go/+/437557
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: David du Colombier <0intro@gmail.com>
Run-TryBot: David du Colombier <0intro@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
2022-10-03 15:17:12 +00:00
chanxuehong
5451ba3ac4 go/token: fix File.AddLineColumnInfo logic
The offset of the line info should be smaller than the file size.
Otherwise, it should be ignored.
Before the change, such an invalid line info won't be ignored when it's
the first one to add.

Change-Id: Id17492a8de97f277a49a59fae0070efeec40b2f9
GitHub-Last-Rev: 4d61d73c3a
GitHub-Pull-Request: golang/go#48456
Reviewed-on: https://go-review.googlesource.com/c/go/+/350741
Reviewed-by: Robert Griesemer <gri@golang.org>
Reviewed-by: Zeke Lu <lvzecai@gmail.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Benny Siegert <bsiegert@gmail.com>
Run-TryBot: hopehook <hopehook@golangcn.org>
2022-10-03 13:05:50 +00:00
Félix Dorn
e7e554e546 log/syslog: return nil directly
Reduce return complexity.

Change-Id: I280a0fe1a49371e231e93e0d3e177730b6f28769
GitHub-Last-Rev: 2ebc10641d
GitHub-Pull-Request: golang/go#55989
Reviewed-on: https://go-review.googlesource.com/c/go/+/437516
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: Benny Siegert <bsiegert@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Run-TryBot: Rob Pike <r@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-10-03 08:59:45 +00:00
cui fliter
1888875182 regexp: fix a few function names on comments
Change-Id: I192dd34c677e52e16f0ef78e1dae58a78f6d1aac
GitHub-Last-Rev: 1638a74689
GitHub-Pull-Request: golang/go#55967
Reviewed-on: https://go-review.googlesource.com/c/go/+/436885
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
2022-10-02 02:31:23 +00:00
Ian Lance Taylor
82e357d6d5 os: use backslashes for DirFS on Windows
Otherwise DirFS of a UNC path does not work.

Fixes #54694

Change-Id: I82c1c436f7c26b3935c2cc4fd238daf094fc4d86
Reviewed-on: https://go-review.googlesource.com/c/go/+/426094
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
Reviewed-by: hopehook <hopehook@golangcn.org>
Auto-Submit: Ian Lance Taylor <iant@google.com>
2022-10-02 02:31:18 +00:00
hopehook
4585bf96b4 all: use time.Since instead of time.Now().Sub
Change-Id: Ifaa73b64e5b6a1d37c753e2440b642478d7dfbce
Reviewed-on: https://go-review.googlesource.com/c/go/+/436957
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Run-TryBot: hopehook <hopehook@golangcn.org>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
2022-10-02 02:28:27 +00:00
cui fliter
51297dd6df syscall: remove redundant type conversion
Change-Id: Iae290216687fd1ce8be720600157fb78cc2446d0
GitHub-Last-Rev: 4fba64ecb1
GitHub-Pull-Request: golang/go#55959
Reviewed-on: https://go-review.googlesource.com/c/go/+/436881
Auto-Submit: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
2022-10-02 02:27:38 +00:00
cui fliter
5f566d35bf crypto/rand: convert r.used to atomic type
For #53821

Change-Id: I1b5c62288eca20ff50f6d8d979cf82df24d4545b
GitHub-Last-Rev: 266148570a
GitHub-Pull-Request: golang/go#54884
Reviewed-on: https://go-review.googlesource.com/c/go/+/428477
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-10-01 08:32:46 +00:00
Daniel Martí
ef1c70fbde cmd/go: remove the -i build flag
The flag is now removed from `go build` and `go test`.
It has been deprecated since Go 1.16, printing a warning message.
The idea was to fully delete it in Go 1.17, but that didn't happen.

First, delete the BuildI variable and its flag declarations,
as well as all the bits of docs that mentioned the flag.

Second, delete or simplify the code paths that used BuildI.

Third, adapt the tests to the removed flag.
Some of them are removed, like test_relative_import_dash_i.txt and
TestGoTestDashIDashOWritesBinary, as they centered around the flag.
The rest are modified to not cover or use the flag.

Finally, change cmd/dist to no longer use `go install -i`.
The purpose of the flag was that, when bootstrapping the toolchain,
all of its dependencies would also be installed as object files.

When removing the use of the -i flags, the checkNotStale call right
after building toolchain3 would fail as expected,
because runtime/internal/sys is now only up to date in the build cache.

Luckily, that's not a problem: we run `go install std cmd` right after,
so all standard library packages will be installed as object files.
Move the checkNotStale call after that install command.

Fixes #41696.

Change-Id: I5d8139f18aaee07da886d483e663f3f2f00d5f3a
Reviewed-on: https://go-review.googlesource.com/c/go/+/416094
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-10-01 08:31:45 +00:00
Mikael Urankar
738a2caf08 cmd/dist: add support for freebsd/riscv64
Updates #53466

Change-Id: I6643b4254dc707351d397018cee485bb508dde94
Reviewed-on: https://go-review.googlesource.com/c/go/+/431659
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Joel Sing <joel@sing.id.au>
Reviewed-by: Joel Sing <joel@sing.id.au>
Reviewed-by: Dmitri Goutnik <dgoutnik@gmail.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2022-10-01 06:43:40 +00:00
David Chase
2b1c414fa8 cmd/internal/obj: hoist constant slice out of function called in loop
It's all local to a single file and responsible for 1.7% of total
space allocated summed over compilation of the bent benchmarks.

Showing nodes accounting for 27.16GB, 27.04% of 100.44GB total
Dropped 1622 nodes (cum <= 0.50GB)
Showing top 10 nodes out of 321
      flat  flat%   sum%        cum   cum%
    4.87GB  4.85%  4.85%     4.87GB  4.85%  cmd/compile/internal/objw.init
    4.79GB  4.77%  9.62%     4.81GB  4.79%  runtime.allocm
    4.72GB  4.70% 14.32%     4.72GB  4.70%  cmd/compile/internal/types.newType
    3.10GB  3.09% 17.41%     3.17GB  3.15%  cmd/compile/internal/ssagen.InitConfig
    1.86GB  1.85% 19.26%     2.61GB  2.60%  cmd/compile/internal/ssa.cse

    1.72GB  1.71% 20.97%     2.25GB  2.24%  cmd/internal/obj.(*Link).traverseFuncAux

    1.66GB  1.65% 22.62%     1.66GB  1.65%  runtime.malg
    1.61GB  1.61% 24.23%     1.64GB  1.63%  cmd/compile/internal/ssa.schedule
    1.42GB  1.41% 25.64%     1.42GB  1.41%  cmd/compile/internal/ir.NewNameAt

Change-Id: Id18ee3b83cb23a7042d59714a0c1ca074e7bc7a8
Reviewed-on: https://go-review.googlesource.com/c/go/+/437297
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: David Chase <drchase@google.com>
2022-10-01 02:15:39 +00:00
Cuong Manh Le
1baea0ddb3 test: skip inlining check in escape4.go
This is the last failed test in Unified IR, since it can inline f5 and
f6 but the old frontend can not. So marking them as //go:noinline, with
a TODO for re-enable once GOEXPERIMENT=nounified is gone.

Fixes #53058

Change-Id: Ifbbc49c87997a53e1b323048f0067f0257655fad
Reviewed-on: https://go-review.googlesource.com/c/go/+/437217
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
2022-10-01 01:52:17 +00:00
Cuong Manh Le
0cbe30467a test: relax closure name matching in closure3.go
The mismatch between Unified IR and the old frontend is not about how
they number the closures, but how they name them. For nested closure,
the old frontend use the immediate function which contains the closure
as the outer function, while Unified IR uses the outer most function as
the outer for all closures.

That said, what important is matching the number of closures, not their
name prefix. So this CL relax the test to match both "main.func1.func2"
and "main.func1.2" to satisfy both Unified IR and the old frontend.

Updates #53058

Change-Id: I66ed816d1968aa68dd3089a4ea5850ba30afd75b
Reviewed-on: https://go-review.googlesource.com/c/go/+/437216
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-10-01 01:52:16 +00:00
eric fang
dd7ce26abf math: optimize Hypot function
This CL optimizes the Hypot function by putting the Abs function in
front of the IsInf check. This simplifies the judgment of IsInf.

Benchmarks:
On linux/arm64,
name         old time/op  new time/op  delta
Hypot-160    5.26ns ± 0%  4.53ns ± 0%  -13.84%  (p=0.000 n=4+5)
HypotGo-160  5.19ns ± 0%  4.85ns ± 0%   -6.53%  (p=0.008 n=5+5)

On linux/amd64,
name        old time/op  new time/op  delta
Hypot-44    5.99ns ± 0%  5.99ns ± 0%     ~     (p=0.667 n=5+5)
HypotGo-44  7.46ns ± 0%  6.61ns ± 0%  -11.37%  (p=0.008 n=5+5)

On darwin/arm64,
name       old time/op  new time/op  delta
Hypot-8    3.58ns ± 0%  2.79ns ± 0%  -22.01%  (p=0.008 n=5+5)
HypotGo-8  3.58ns ± 0%  2.79ns ± 0%  -22.15%  (p=0.008 n=5+5)

Change-Id: Id79236e01d9494b6e00bbda3ec08c72caf5ef3c1
Reviewed-on: https://go-review.googlesource.com/c/go/+/414974
Reviewed-by: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Eric Fang <eric.fang@arm.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2022-10-01 01:51:35 +00:00
Bryan C. Mills
9a029a6915 os/exec: make StdoutPipe and StderrPipe safe to Close concurrently
For #50436, I want to be able to close the pipes returned by
StdoutPipe and StderrPipe after the Context has been canceled
and the WaitDelay has subsequently expired.

However, the fact that the exec.onceCloser wrapper for StdinPipe
(added in CL 13329043) was retained in CL 65490 suggests to me that
(*os.File).Close is still not safe to call concurrently.

This may cause type assertions of these ReadClosers to *os.File that
once succeeded to no longer do so. However, the StdoutPipe and
StderrPipe methods return interfaces, not concrete *os.Files, so
callers already should not have been relying on that implementation
detail — and as far as I can tell the closeOnce wrapper does not mask
any (*os.File) methods, so assertions to any interface type that
previously succeeded will continue to do so.

This change is logically part of CL 401835, but since it may expose
fragile type-assertions in callers I want to keep it separate for
clearer bisection of any new test failures.

For #50436.

Change-Id: I58de1d48fb6fd788502f13657d8d4484516271cf
Reviewed-on: https://go-review.googlesource.com/c/go/+/437176
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-10-01 00:21:25 +00:00
Bryan C. Mills
c9a62b7e71 os/exec: recombine goroutinePipes and userPipes
This change undoes CL 401894, because on further consideration
it turns out not to be needed.

This also makes (*Cmd).closeDescriptors a free function, since it does
not actually use the receiver in any way and is not needed to satisfy
any interfaces.

For #50436.

Change-Id: I7915265b0e6398ed5a34fae0c12873ab08a14194
Reviewed-on: https://go-review.googlesource.com/c/go/+/437175
Run-TryBot: Bryan Mills <bcmills@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Bryan Mills <bcmills@google.com>
2022-10-01 00:12:32 +00:00