]> Cypherpunks repositories - gostls13.git/log
gostls13.git
2 years agocmd/asm: remove the incorrect check of LDADDx-like instructions
fanzha02 [Fri, 13 Jan 2023 06:22:34 +0000 (06:22 +0000)]
cmd/asm: remove the incorrect check of LDADDx-like instructions

According to the ARM Architecture Reference Manual, LDADDx-like
instructions can take rt as zr when the encode A bit is 0. They
are used by the alias STADDx-like instructions. The current
assembler adds incorrect constraints for them, which is rt can't
be zr when field.enc A is 0. This patch removes it.

Add test cases.

Reported by Matt Horsnell <matt.horsnell@arm.com>

The reference:
https://developer.arm.com/documentation/ddi0602/2022-12/Base-Instructions

Change-Id: Ia2487a5e3900e32994fc14edaf03deeb245e70c6
Reviewed-on: https://go-review.googlesource.com/c/go/+/462295
Reviewed-by: Matt Horsnell <matthew.horsnell@gmail.com>
Run-TryBot: Joel Sing <joel@sing.id.au>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

2 years agonet,os: set the theoretical unlimited remaining bytes to max int64
Andy Pan [Mon, 27 Feb 2023 04:07:57 +0000 (12:07 +0800)]
net,os: set the theoretical unlimited remaining bytes to max int64

Based on https://go-review.googlesource.com/c/go/+/466015/comment/073a63fa_7a9e485f

Change-Id: I3e1b035de6b8217c5fa5695e436f164b3058e33c
Reviewed-on: https://go-review.googlesource.com/c/go/+/471439
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Run-TryBot: Andy Pan <panjf2000@gmail.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
2 years agoall: fix typos
pgxiaolianzi [Mon, 27 Feb 2023 06:51:55 +0000 (06:51 +0000)]
all: fix typos

Change-Id: Ica8d5e5799a4de532764ae86cdb623508d3a8e18
GitHub-Last-Rev: 3e97cca9de3885f2fe0d7deb776e59cc1c73146d
GitHub-Pull-Request: golang/go#58689
Reviewed-on: https://go-review.googlesource.com/c/go/+/471021
Auto-Submit: 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>
Run-TryBot: Ian Lance Taylor <iant@google.com>

2 years agocmd/compile: omit redundant sign/unsign extension on arm64
ruinan [Thu, 18 Aug 2022 01:31:57 +0000 (01:31 +0000)]
cmd/compile: omit redundant sign/unsign extension on arm64

On Arm64, all 32-bit instructions will ignore the upper 32 bits and
clear them to zero for the result. No need to do an unsign extend before
a 32 bit op.

This CL removes the redundant unsign extension only for the existing
32-bit opcodes, and also omits the sign extension when the upper bit of
the result can be predicted.

Fixes #42162

Change-Id: I61e6670bfb8982572430e67a4fa61134a3ea240a
CustomizedGitHooks: yes
Reviewed-on: https://go-review.googlesource.com/c/go/+/427454
Reviewed-by: Keith Randall <khr@google.com>
Auto-Submit: Eric Fang <eric.fang@arm.com>
Reviewed-by: Keith Randall <khr@golang.org>
Run-TryBot: Eric Fang <eric.fang@arm.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

2 years agointernal/testdir: simplify and clean up
Dmitri Shuralyov [Mon, 6 Feb 2023 22:10:22 +0000 (17:10 -0500)]
internal/testdir: simplify and clean up

Now that the bare minimum change to make the run.go test runner into
a normal go test is done, there remain many opportunities to simplify,
modernize and generally clean up the test code.

Of all the opportunities available, this change tries to fit somewhere
between doing "not enough" and "way too much". This ends up including:

• replace verbose flag with testing.Verbose()
• replace custom temporary directory creation, removal, -keep flag
  with testing.T.TempDir
• replace custom code to find the go command with testenv.GoToolPath
• replace many instances of "t.err = err; return" with "return err",
  or with t.Fatal when it's clearly a test infrastructure error
• replace reliance on changing working directory to GOROOT/test to
  computing and using absolute paths
• replace uses of log.Fatal with t.Fatal
• replace uses of deprecated ioutil package with their replacements
• add some missing error checks, use more idiomatic identifier names

For #56844.

Change-Id: I5b301bb83a8e5b64cf211d7f2f4b14d38d48fea0
Reviewed-on: https://go-review.googlesource.com/c/go/+/466155
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>

2 years agocmd/dist, test: convert test/run.go runner to a cmd/go test
Dmitri Shuralyov [Wed, 8 Feb 2023 16:40:06 +0000 (11:40 -0500)]
cmd/dist, test: convert test/run.go runner to a cmd/go test

As motivated on the issue, we want to move the functionality of the
run.go program to happen via a normal go test. Each .go test case in
the GOROOT/test directory gets a subtest, and cmd/go's support for
parallel test execution replaces run.go's own implementation thereof.

The goal of this change is to have fairly minimal and readable diff
while making an atomic changeover. The working directory is modified
during the test execution to be GOROOT/test as it was with run.go,
and most of the test struct and its run method are kept unchanged.
The next CL in the stack applies further simplifications and cleanups
that become viable.

There's no noticeable difference in test execution time: it takes around
60-80 seconds both before and after on my machine. Test caching, which
the previous runner lacked, can shorten the time significantly.

For #37486.
Fixes #56844.

Change-Id: I209619dc9d90e7529624e49c01efeadfbeb5c9ae
Reviewed-on: https://go-review.googlesource.com/c/go/+/463276
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

2 years agomisc/cgo/{life,stdio}: remove reliance on test/run.go
Dmitri Shuralyov [Mon, 6 Feb 2023 18:44:32 +0000 (13:44 -0500)]
misc/cgo/{life,stdio}: remove reliance on test/run.go

The misc/cgo/life and misc/cgo/stdio tests started out as fairly simple
test cases when they were added, but the machinery to execute them has
grown in complexity over the years.

They currently reuse the test/run.go runner and its "run" action without
needing much of the additional flexibility that said runner implements.
Given that runner isn't well documented, it makes it harder to see that
ultimately these tests just do 'go run' on a few test programs and check
that the output matches a golden file.

Maybe these test cases should move out of misc to be near similar tests,
or the machinery to execute them can made available in a package that is
easier and safer to reuse. I'd rather not block the refactor of the test
directory runner on that, so for now rewrite these to be self-contained.

Also delete misc/cgo/stdio/testdata/run.out which has no effect on the
test. It was seemingly accidentally kept behind during the refactor in
CL 6220049.

For #56844.

Change-Id: I5e2f542824925092cdddb03b44b6295a4136ccb4
Reviewed-on: https://go-review.googlesource.com/c/go/+/465755
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Austin Clements <austin@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>

2 years agocmd/compile/internal/noder: correct positions for synthetic closures
Matthew Dempsky [Tue, 14 Feb 2023 23:13:50 +0000 (15:13 -0800)]
cmd/compile/internal/noder: correct positions for synthetic closures

When inlining functions that contain function literals, we need to be
careful about position information. The OCLOSURE node should use the
inline-adjusted position, but the ODCLFUNC and its body should use the
original positions.

However, the same problem can arise with certain generic constructs,
which require the compiler to synthesize function literals to insert
dictionary arguments.

go.dev/cl/425395 fixed the issue with user-written function literals
in a somewhat kludgy way; this CL extends the same solution to
synthetic function literals.

This is all quite subtle and the solutions aren't terribly robust, so
longer term it's probably desirable to revisit how we track inlining
context for positions. But for now, this seems to be the least bad
solution, esp. for backporting to 1.20.

Updates #54625.
Fixes #58513.

Change-Id: Icc43a70dbb11a0e665cbc9e6a64ef274ad8253d1
Reviewed-on: https://go-review.googlesource.com/c/go/+/468415
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Than McIntosh <thanm@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>

2 years agoos: don't try to put directory into non-blocking mode
Ian Lance Taylor [Fri, 18 Nov 2022 23:20:06 +0000 (15:20 -0800)]
os: don't try to put directory into non-blocking mode

Fixes #56843

Change-Id: I3cb3e8397499cd8c57a3edddd45f38c510519b36
Reviewed-on: https://go-review.googlesource.com/c/go/+/451997
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Nicolas Hillegeer <aktau@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Rob Pike <r@golang.org>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>

2 years agonet/http: reduce calls to append in hexEscapeNonASCII to gain a slight performance...
Andy Pan [Wed, 24 Aug 2022 15:02:16 +0000 (23:02 +0800)]
net/http: reduce calls to append in hexEscapeNonASCII to gain a slight performance boost

goos: linux
goarch: amd64
pkg: net/http
cpu: DO-Premium-Intel
                    │     old      │                 new                 │
                    │    sec/op    │   sec/op     vs base                │
HexEscapeNonASCII-4   469.6n ± 20%   371.1n ± 9%  -20.98% (p=0.000 n=10)

                    │    old     │              new               │
                    │    B/op    │    B/op     vs base            │
HexEscapeNonASCII-4   192.0 ± 0%   192.0 ± 0%  ~ (p=1.000 n=10) ¹
¹ all samples are equal

                    │    old     │              new               │
                    │ allocs/op  │ allocs/op   vs base            │
HexEscapeNonASCII-4   2.000 ± 0%   2.000 ± 0%  ~ (p=1.000 n=10) ¹
¹ all samples are equal

Change-Id: Ic8d2b3ddcf2cf724dec3f51a2aba205f2c6e4fe6
Reviewed-on: https://go-review.googlesource.com/c/go/+/425786
Reviewed-by: Than McIntosh <thanm@google.com>
Auto-Submit: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Andy Pan <panjf2000@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2 years agoos: skip zero-copy attempts with copy_file_range(2)/splice(2) for target files with...
Andy Pan [Mon, 27 Feb 2023 04:47:39 +0000 (12:47 +0800)]
os: skip zero-copy attempts with copy_file_range(2)/splice(2) for target files with O_APPEND flag

Change-Id: I6cccac9295ab4a9bf7f7a33382a34f31b1c4a000
Reviewed-on: https://go-review.googlesource.com/c/go/+/471496
Auto-Submit: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Andy Pan <panjf2000@gmail.com>

2 years agocmd/go: convert mkalldocs.sh to a Go program
Bryan C. Mills [Wed, 15 Feb 2023 21:45:14 +0000 (16:45 -0500)]
cmd/go: convert mkalldocs.sh to a Go program

mkalldocs.sh required a Unix shell, making it less accessible for
contributors on Windows. It also used a substantially different
codepath to regenerate the file than the one used to check the file
for staleness, making failures in TestDocsUpToDate more complex to
diagnose.

We can solve both of those problems by using the same technique as in
checkScriptReadme: use the test itself as the generator to update the
file. The test is already written in Go, the test binary already knows
how to mimic the 'go' command, and this approach brings the difference
between the test and the generator down to a single flag check.

Updates #26735.

Change-Id: I7c6f65cb0e0c29e334e38a45412e0a73c4d31d42
Reviewed-on: https://go-review.googlesource.com/c/go/+/468636
Reviewed-by: Alan Donovan <adonovan@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Bryan Mills <bcmills@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>

2 years agocmd/compile: use zero constants in comparisons where possible
Michael Munday [Mon, 20 Sep 2021 20:39:39 +0000 (21:39 +0100)]
cmd/compile: use zero constants in comparisons where possible

Some integer comparisons with 1 and -1 can be rewritten as comparisons
with 0. For example, x < 1 is equivalent to x <= 0. This is an
advantageous transformation on riscv64 because comparisons with zero
do not require a constant to be loaded into a register. Other
architectures will likely benefit too and the transformation is
relatively benign on architectures that do not benefit.

Change-Id: I2ce9821dd7605a660eb71d76e83a61f9bae1bf25
Reviewed-on: https://go-review.googlesource.com/c/go/+/350831
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Run-TryBot: Michael Munday <mike.munday@lowrisc.org>
TryBot-Result: Gopher Robot <gobot@golang.org>

2 years agocmd/go: reject list when -find and -export are used together
RenKanai [Sun, 27 Mar 2022 13:06:22 +0000 (22:06 +0900)]
cmd/go: reject list when -find and -export are used together

Fixes #51952.

Change-Id: If2cfc41d65373ca38cfb7b0396be8988d444eb5e
Reviewed-on: https://go-review.googlesource.com/c/go/+/396074
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
2 years agocmd/compile: improve logical shift with MASKEQZ on loong64
Wayne Zuo [Thu, 1 Sep 2022 04:26:43 +0000 (12:26 +0800)]
cmd/compile: improve logical shift with MASKEQZ on loong64

Using MASKEQZ instruction can save one instruction in calculation of
shift operations.

Reference: https://loongson.github.io/LoongArch-Documentation/LoongArch-Vol1-EN.html

Change-Id: Ic5349c6f5ebd7af608c7d75a9b3a862305758275
Reviewed-on: https://go-review.googlesource.com/c/go/+/427396
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: abner chenc <chenguoqi@loongson.cn>
Reviewed-by: David Chase <drchase@google.com>
Run-TryBot: Wayne Zuo <wdvxdr@golangcn.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Dmitri Shuralyov <dmitshur@google.com>

2 years agocmd/asm: preserve 3rd arg when GOT-rewriting assembly instructions
Keith Randall [Mon, 27 Feb 2023 16:53:34 +0000 (08:53 -0800)]
cmd/asm: preserve 3rd arg when GOT-rewriting assembly instructions

Fixes #58735

Change-Id: I7cc1c34ed8454553328d44b2ea72e4c0255b6ec1
Reviewed-on: https://go-review.googlesource.com/c/go/+/471675
Run-TryBot: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Auto-Submit: Keith Randall <khr@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>

2 years agoruntime: set procid on Windows
qmuntal [Thu, 23 Feb 2023 13:15:28 +0000 (14:15 +0100)]
runtime: set procid on Windows

The runtime-gdb.py script needs procid to be set in order to
map a goroutine ID with an OS thread. The Go runtime is not currently
setting that variable on Windows, so TestGdbPython (and friends) can't
succeed.

This CL initializes procid and unskips gdb tests on Windows.

Fixes #22687
Updates #21380
Updates #22021

Change-Id: Icd1d9fc1764669ed1bf04f53d17fadfd24ac3f30
Reviewed-on: https://go-review.googlesource.com/c/go/+/470596
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Quim Muntal <quimmuntal@gmail.com>

2 years agocmd/go: make go test build multiple executables
Maksadbek Akhmedov [Wed, 8 Feb 2023 13:58:04 +0000 (14:58 +0100)]
cmd/go: make go test build multiple executables

If -c is set while testing multiple packages, then allow
to build testing binary executables to the current directory
or to the directory that -o refers to.

$ go test -c -o /tmp ./pkg1 ./pkg2 ./pkg2
$ ls /tmp
pkg1.test pkg2.test pkg3.test

Fixes #15513.

Change-Id: I3aba01bebfa90e61e59276f2832d99c0d323b82e
Reviewed-on: https://go-review.googlesource.com/c/go/+/466397
Run-TryBot: Bryan Mills <bcmills@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2 years agoruntime: use explicit NOFRAME on solaris/amd64
qmuntal [Wed, 8 Feb 2023 15:42:45 +0000 (16:42 +0100)]
runtime: use explicit NOFRAME on solaris/amd64

This CL marks some solaris assembly functions as NOFRAME to avoid
relying on the implicit amd64 NOFRAME heuristic, where NOSPLIT functions
without stack were also marked as NOFRAME.

While here, I've reduced the stack usage of runtime·sigtramp by
16 bytes to compensate the additional 8 bytes from the stack-allocated
frame pointer. There were two unused 8-byte slots on the stack, one
at 24(SP) and the other at 80(SP).

Updates #58378

Change-Id: If9230e71a8b3c72681ffc82030ade6ceccf824db
Reviewed-on: https://go-review.googlesource.com/c/go/+/466456
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Quim Muntal <quimmuntal@gmail.com>

2 years agointernal/syscall/execenv: refactor handling env variables
Cuong Manh Le [Sun, 26 Feb 2023 02:39:07 +0000 (09:39 +0700)]
internal/syscall/execenv: refactor handling env variables

Discover while working on CL 471335.

Change-Id: I006077a5aa93cafb7be47813ab0c4714bb00d774
Reviewed-on: https://go-review.googlesource.com/c/go/+/471435
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
2 years agosyscall: fix invalid unsafe.Pointer conversion on Windows
Cuong Manh Le [Sat, 25 Feb 2023 09:32:15 +0000 (16:32 +0700)]
syscall: fix invalid unsafe.Pointer conversion on Windows

Fixes #58714

Change-Id: Ifa5c059ed5e358ed98aee7e83b95dd1806b535f7
Reviewed-on: https://go-review.googlesource.com/c/go/+/471335
Reviewed-by: Than McIntosh <thanm@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
2 years agoruntime: use explicit NOFRAME on openbsd/amd64
qmuntal [Wed, 8 Feb 2023 15:31:15 +0000 (16:31 +0100)]
runtime: use explicit NOFRAME on openbsd/amd64

This CL marks some openbsd assembly functions as NOFRAME to avoid
relying on the implicit amd64 NOFRAME heuristic, where NOSPLIT functions
without stack were also marked as NOFRAME.

Updates #58378

Change-Id: I993549df41a93255fb714357443f8b24c3dfb0a4
Reviewed-on: https://go-review.googlesource.com/c/go/+/466455
Reviewed-by: Keith Randall <khr@google.com>
Run-TryBot: Quim Muntal <quimmuntal@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Joel Sing <joel@sing.id.au>
Reviewed-by: Cherry Mui <cherryyz@google.com>
2 years agobytes, strings: avoid unnecessary zero initialization
Joe Tsai [Thu, 8 Dec 2022 11:51:04 +0000 (03:51 -0800)]
bytes, strings: avoid unnecessary zero initialization

Add bytealg.MakeNoZero that specially allocates a []byte
without zeroing it. It assumes the caller will populate every byte.
From within the bytes and strings packages, we can use
bytealg.MakeNoZero in a way where our logic ensures that
the entire slice is overwritten such that uninitialized bytes
are never leaked to the end user.

We use bytealg.MakeNoZero from within the following functions:

* bytes.Join
* bytes.Repeat
* bytes.ToUpper
* bytes.ToLower
* strings.Builder.Grow

The optimization in strings.Builder transitively benefits the following:

* strings.Join
* strings.Map
* strings.Repeat
* strings.ToUpper
* strings.ToLower
* strings.ToValidUTF8
* strings.Replace
* any user logic that depends on strings.Builder

This optimization is especially notable on large buffers that
do not fit in the CPU cache, such that the cost of
runtime.memclr and runtime.memmove are non-trivial since they are
both limited by the relatively slow speed of physical RAM.

Performance:

RepeatLarge/256/1             66.0ns ± 3%    64.5ns ± 1%      ~     (p=0.095 n=5+5)
RepeatLarge/256/16            55.4ns ± 5%    53.1ns ± 3%    -4.17%  (p=0.016 n=5+5)
RepeatLarge/512/1             95.5ns ± 7%    87.1ns ± 2%    -8.78%  (p=0.008 n=5+5)
RepeatLarge/512/16            84.4ns ± 9%    76.2ns ± 5%    -9.73%  (p=0.016 n=5+5)
RepeatLarge/1024/1             161ns ± 4%     144ns ± 7%   -10.45%  (p=0.016 n=5+5)
RepeatLarge/1024/16            148ns ± 3%     141ns ± 5%      ~     (p=0.095 n=5+5)
RepeatLarge/2048/1             296ns ± 7%     288ns ± 5%      ~     (p=0.841 n=5+5)
RepeatLarge/2048/16            298ns ± 8%     281ns ± 5%      ~     (p=0.151 n=5+5)
RepeatLarge/4096/1             593ns ± 8%     539ns ± 8%    -8.99%  (p=0.032 n=5+5)
RepeatLarge/4096/16            568ns ±12%     526ns ± 7%      ~     (p=0.056 n=5+5)
RepeatLarge/8192/1            1.15µs ± 8%    1.08µs ±12%      ~     (p=0.095 n=5+5)
RepeatLarge/8192/16           1.12µs ± 4%    1.07µs ± 7%      ~     (p=0.310 n=5+5)
RepeatLarge/8192/4097         1.77ns ± 1%    1.76ns ± 2%      ~     (p=0.310 n=5+5)
RepeatLarge/16384/1           2.06µs ± 7%    1.94µs ± 5%      ~     (p=0.222 n=5+5)
RepeatLarge/16384/16          2.02µs ± 4%    1.92µs ± 6%      ~     (p=0.095 n=5+5)
RepeatLarge/16384/4097        1.50µs ±15%    1.44µs ±11%      ~     (p=0.802 n=5+5)
RepeatLarge/32768/1           3.90µs ± 8%    3.65µs ±11%      ~     (p=0.151 n=5+5)
RepeatLarge/32768/16          3.92µs ±14%    3.68µs ±12%      ~     (p=0.222 n=5+5)
RepeatLarge/32768/4097        3.71µs ± 5%    3.43µs ± 4%    -7.54%  (p=0.032 n=5+5)
RepeatLarge/65536/1           7.47µs ± 8%    6.88µs ± 9%      ~     (p=0.056 n=5+5)
RepeatLarge/65536/16          7.29µs ± 4%    6.74µs ± 6%    -7.60%  (p=0.016 n=5+5)
RepeatLarge/65536/4097        7.90µs ±11%    6.34µs ± 5%   -19.81%  (p=0.008 n=5+5)
RepeatLarge/131072/1          17.0µs ±18%    14.1µs ± 6%   -17.32%  (p=0.008 n=5+5)
RepeatLarge/131072/16         15.2µs ± 2%    16.2µs ±17%      ~     (p=0.151 n=5+5)
RepeatLarge/131072/4097       15.7µs ± 6%    14.8µs ±11%      ~     (p=0.095 n=5+5)
RepeatLarge/262144/1          30.4µs ± 5%    31.4µs ±13%      ~     (p=0.548 n=5+5)
RepeatLarge/262144/16         30.1µs ± 4%    30.7µs ±11%      ~     (p=1.000 n=5+5)
RepeatLarge/262144/4097       31.2µs ± 7%    32.7µs ±13%      ~     (p=0.310 n=5+5)
RepeatLarge/524288/1          67.5µs ± 9%    63.7µs ± 3%      ~     (p=0.095 n=5+5)
RepeatLarge/524288/16         67.2µs ± 5%    62.9µs ± 6%      ~     (p=0.151 n=5+5)
RepeatLarge/524288/4097       65.5µs ± 4%    65.2µs ±18%      ~     (p=0.548 n=5+5)
RepeatLarge/1048576/1          141µs ± 6%     137µs ±14%      ~     (p=0.421 n=5+5)
RepeatLarge/1048576/16         140µs ± 2%     134µs ±11%      ~     (p=0.222 n=5+5)
RepeatLarge/1048576/4097       141µs ± 3%     134µs ±10%      ~     (p=0.151 n=5+5)
RepeatLarge/2097152/1          258µs ± 2%     271µs ±10%      ~     (p=0.222 n=5+5)
RepeatLarge/2097152/16         263µs ± 6%     273µs ± 9%      ~     (p=0.151 n=5+5)
RepeatLarge/2097152/4097       270µs ± 2%     277µs ± 6%      ~     (p=0.690 n=5+5)
RepeatLarge/4194304/1          684µs ± 3%     467µs ± 6%   -31.69%  (p=0.008 n=5+5)
RepeatLarge/4194304/16         682µs ± 1%     471µs ± 7%   -30.91%  (p=0.008 n=5+5)
RepeatLarge/4194304/4097       685µs ± 2%     465µs ±20%   -32.12%  (p=0.008 n=5+5)
RepeatLarge/8388608/1         1.50ms ± 1%    1.16ms ± 8%   -22.63%  (p=0.008 n=5+5)
RepeatLarge/8388608/16        1.50ms ± 2%    1.22ms ±17%   -18.49%  (p=0.008 n=5+5)
RepeatLarge/8388608/4097      1.51ms ± 7%    1.33ms ±11%   -11.56%  (p=0.008 n=5+5)
RepeatLarge/16777216/1        3.48ms ± 4%    2.66ms ±13%   -23.76%  (p=0.008 n=5+5)
RepeatLarge/16777216/16       3.37ms ± 3%    2.57ms ±13%   -23.72%  (p=0.008 n=5+5)
RepeatLarge/16777216/4097     3.38ms ± 9%    2.50ms ±11%   -26.16%  (p=0.008 n=5+5)
RepeatLarge/33554432/1        7.74ms ± 1%    4.70ms ±19%   -39.31%  (p=0.016 n=4+5)
RepeatLarge/33554432/16       7.90ms ± 4%    4.78ms ± 9%   -39.50%  (p=0.008 n=5+5)
RepeatLarge/33554432/4097     7.80ms ± 2%    4.86ms ±11%   -37.60%  (p=0.008 n=5+5)
RepeatLarge/67108864/1        16.4ms ± 3%     9.7ms ±15%   -41.29%  (p=0.008 n=5+5)
RepeatLarge/67108864/16       16.5ms ± 1%     9.9ms ±15%   -39.83%  (p=0.008 n=5+5)
RepeatLarge/67108864/4097     16.5ms ± 1%    11.0ms ±18%   -32.95%  (p=0.008 n=5+5)
RepeatLarge/134217728/1       35.2ms ±12%    19.2ms ±10%   -45.58%  (p=0.008 n=5+5)
RepeatLarge/134217728/16      34.6ms ± 6%    19.3ms ± 7%   -44.07%  (p=0.008 n=5+5)
RepeatLarge/134217728/4097    33.2ms ± 2%    19.3ms ±14%   -41.79%  (p=0.008 n=5+5)
RepeatLarge/268435456/1       70.9ms ± 2%    36.2ms ± 5%   -48.87%  (p=0.008 n=5+5)
RepeatLarge/268435456/16      77.4ms ± 7%    36.1ms ± 8%   -53.33%  (p=0.008 n=5+5)
RepeatLarge/268435456/4097    75.8ms ± 4%    37.0ms ± 4%   -51.15%  (p=0.008 n=5+5)
RepeatLarge/536870912/1        163ms ±14%      77ms ± 9%   -52.94%  (p=0.008 n=5+5)
RepeatLarge/536870912/16       156ms ± 4%      76ms ± 6%   -51.42%  (p=0.008 n=5+5)
RepeatLarge/536870912/4097     151ms ± 2%      76ms ± 6%   -49.64%  (p=0.008 n=5+5)
RepeatLarge/1073741824/1       293ms ± 5%     149ms ± 8%   -49.18%  (p=0.008 n=5+5)
RepeatLarge/1073741824/16      308ms ± 9%     150ms ± 8%   -51.19%  (p=0.008 n=5+5)
RepeatLarge/1073741824/4097    299ms ± 5%     151ms ± 6%   -49.51%  (p=0.008 n=5+5)

Updates #57153

Change-Id: I024553b7e676d6da6408278109ac1fa8def0a802
Reviewed-on: https://go-review.googlesource.com/c/go/+/456336
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Joseph Tsai <joetsai@digital-static.net>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
2 years agocompress/zlib: use binary.BigEndian consistently
Joe Tsai [Wed, 14 Sep 2022 05:20:06 +0000 (22:20 -0700)]
compress/zlib: use binary.BigEndian consistently

One major reason to avoid binary.BigEndian is because
the binary package includes a transitive dependency on reflect.
See #54097.

Given that writer.go already depends on the binary package,
embrace use of it consistently where sensible.
We should either embrace use of binary or fully avoid it.

Change-Id: I5f2d27d0ed8cab5ac54be02362c7d33276dd4b9a
Reviewed-on: https://go-review.googlesource.com/c/go/+/452176
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Run-TryBot: Joseph Tsai <joetsai@digital-static.net>
Auto-Submit: Joseph Tsai <joetsai@digital-static.net>
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

2 years agointernal/poll: avoid race between SetDeadline and timer expiry in Plan 9
miller [Wed, 22 Feb 2023 14:15:08 +0000 (14:15 +0000)]
internal/poll: avoid race between SetDeadline and timer expiry in Plan 9

The mutexes added by CL 235820 aren't sufficient to prevent a race when
an i/o deadline timer fires just as the deadline is being reset to zero.

Consider this possible sequence when goroutine S is clearing the
deadline and goroutine T has been started by the timer:

1. S locks the mutex
2. T blocks on the mutex
3. S sets the timedout flag to false
4. S calls Stop on the timer (and fails, because the timer has fired)
5. S unlocks the mutex
6. T locks the mutex
7. T sets the timedout flag to true

Now all subsequent I/O will timeout, although the deadline has been
cleared.

The fix is for the timeout goroutine to skip setting the timedout
flag if the timer pointer has been cleared, or reassigned by
another SetDeadline operation.

Fixes #57114

Change-Id: I4a45d19c3b4b66cdf151dcc3f70536deaa8216a7
Reviewed-on: https://go-review.googlesource.com/c/go/+/470215
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: David du Colombier <0intro@gmail.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
2 years agocmd/link: revert CL 467715 in favor of better fix
Than McIntosh [Mon, 27 Feb 2023 15:29:24 +0000 (10:29 -0500)]
cmd/link: revert CL 467715 in favor of better fix

This patch backs out CL 467715 (written to fix 58425), now that we
have a better fix for the "relocation doesn't fit" problem in the
trampoline generation phase (send in a previous CL).

Updates #58428.
Updates #58425.

Change-Id: Ib0d966fed00bd04db7ed85aa4e9132382b979a44
Reviewed-on: https://go-review.googlesource.com/c/go/+/471596
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
2 years agoencoding/json: simplify folded name logic
Joe Tsai [Mon, 20 Feb 2023 19:26:10 +0000 (11:26 -0800)]
encoding/json: simplify folded name logic

The folded name logic (despite all attempts to optimize it)
was fundamentally an O(n) operation where every field in a struct
needed to be linearly scanned in order to find a match.
This made unmashaling of unknown fields always O(n).
Instead of optimizing the comparison for each field,
make it such that we can look up a name in O(1).

We accomplish this by maintaining a map keyed by pre-folded names,
which we can pre-calculate when processing the struct type.
Using a stack-allocated buffer, we can fold the input name and
look up its presence in the map.

Also, instead of mapping from names to indexes,
map directly to a pointer to the field information.
The memory cost of this is the same and avoids an extra slice index.

The new logic is both simpler and faster.

Performance:

name                   old time/op    new time/op    delta
CodeDecoder           2.47ms ± 4%    2.42ms ± 2%  -1.83%  (p=0.022 n=10+9)
UnicodeDecoder         259ns ± 2%     248ns ± 1%  -4.32%  (p=0.000 n=10+10)
DecoderStream          150ns ± 1%     149ns ± 1%    ~     (p=0.516 n=10+10)
CodeUnmarshal         3.13ms ± 2%    3.09ms ± 2%  -1.37%  (p=0.022 n=10+9)
CodeUnmarshalReuse    2.50ms ± 1%    2.45ms ± 1%  -1.96%  (p=0.001 n=8+9)
UnmarshalString       67.1ns ± 5%    64.5ns ± 5%  -3.90%  (p=0.005 n=10+10)
UnmarshalFloat64      60.1ns ± 4%    58.4ns ± 2%  -2.89%  (p=0.002 n=10+8)
UnmarshalInt64        51.0ns ± 4%    49.2ns ± 1%  -3.53%  (p=0.001 n=10+8)
Issue10335            80.7ns ± 2%    79.2ns ± 1%  -1.82%  (p=0.016 n=10+8)
Issue34127            28.6ns ± 3%    28.8ns ± 3%    ~     (p=0.388 n=9+10)
Unmapped               177ns ± 2%     177ns ± 2%    ~     (p=0.956 n=10+10)

Change-Id: I478b2b958f5a63a69c9a991a39cd5ffb43244a2a
Reviewed-on: https://go-review.googlesource.com/c/go/+/471196
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Run-TryBot: Joseph Tsai <joetsai@digital-static.net>
Auto-Submit: Joseph Tsai <joetsai@digital-static.net>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
2 years agoencoding/json: use append for HTMLEscape
Joe Tsai [Mon, 20 Feb 2023 08:42:27 +0000 (00:42 -0800)]
encoding/json: use append for HTMLEscape

Use append for HTMLEscape similar to Indent and Compact.
Move it to indent.go alongside Compact, as it shares similar logic.
In a future CL, we will modify appendCompact to be written in terms
of appendHTMLEscape, but we need to first move the JSON decoder logic
out of the main loop of appendCompact.

Change-Id: I131c64cd53d5d2b4ca798b37349aeefe17b418c7
Reviewed-on: https://go-review.googlesource.com/c/go/+/471198
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Run-TryBot: Joseph Tsai <joetsai@digital-static.net>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>
Auto-Submit: Joseph Tsai <joetsai@digital-static.net>

2 years agocmd/link: better fix for arm32 trampgen problem with duff routines
Than McIntosh [Fri, 17 Feb 2023 19:51:05 +0000 (14:51 -0500)]
cmd/link: better fix for arm32 trampgen problem with duff routines

This patch provides a fix for a problem linking large arm32 binaries
with external linking, specifically R_CALLARM relocations against
runtime.duff* routines being flagged by the external linker as not
reaching.

What appears to be happening in the bug in question is that the Go
linker and the external linker are using slightly different recipes to
decide whether a given R_CALLARM relocation will "fit" (e.g. will not
require a trampoline). The Go linker is taking into account the addend
on the call reloc (which for calls to runtime.duffcopy or
runtime.duffzero is nonzero), whereas the external linker appears to
be ignoring the addend.

Example to illustrate:

   Addr      Size   Func
   -----     -----  -----
   ...
   XYZ       1024   runtime.duffcopy
   ...
   ABC       ...    mypackge.MyFunc
     + R0: R_CALLARM  o=8 a=848 tgt=runtime.duffcopy<0>

Let's say that the distance between ABC (start address of
runtime.duffcopy) and XYZ (start of MyFunc) is just over the
architected 24-bit maximum displacement for an R_CALLARM (let's say
that ABC-XYZ is just over the architected limit by some small value,
say 36). Because we're calling into runtime.duffcopy at offset 848,
however, the relocation does in fact fit, but if the external linker
isn't taking into account the addend (assuming that all calls target
the first instruction of the called routine), then we'll get a
"doesn't fit" error from the linker.

To work around this problem, revise the ARM trampoline generation code
in the Go linker that computes the trampoline threshold to ignore the
addend on R_CALLARM relocations, so as to harmonize the two linkers.

Updates #58428.
Updates #58425.

Change-Id: I56e580c05b7b47bbe8edf5532a1770bbd700fbe5
Reviewed-on: https://go-review.googlesource.com/c/go/+/469275
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Run-TryBot: Than McIntosh <thanm@google.com>

2 years agoencoding/json: rely on reflect.Value.SetZero
Joe Tsai [Thu, 23 Feb 2023 21:28:48 +0000 (13:28 -0800)]
encoding/json: rely on reflect.Value.SetZero

v.SetZero() is faster than v.Set(reflect.Zero(v.Type()))
and was recently added in Go 1.20.

Benchmark numbers are largely unchanged since this mainly
affects the unmarshaling of large numbers of JSON nulls,
which our benchmarks do not heavily exercise.

Change-Id: I464f60f63c9027e63a99fd5da92e7ab782018329
Reviewed-on: https://go-review.googlesource.com/c/go/+/471195
Reviewed-by: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
Run-TryBot: Joseph Tsai <joetsai@digital-static.net>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Auto-Submit: Joseph Tsai <joetsai@digital-static.net>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
2 years agoencoding/json: remove legacy fuzz.go file
Joe Tsai [Fri, 24 Feb 2023 09:46:09 +0000 (01:46 -0800)]
encoding/json: remove legacy fuzz.go file

With native support for fuzzing in the Go toolchain,
rely instead on the fuzz tests declared in fuzz_test.go.

Change-Id: I601842cd0bc7e64ea3bfdafbbbc3534df11acf59
Reviewed-on: https://go-review.googlesource.com/c/go/+/471197
Reviewed-by: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Run-TryBot: Joseph Tsai <joetsai@digital-static.net>
Auto-Submit: Joseph Tsai <joetsai@digital-static.net>
TryBot-Result: Gopher Robot <gobot@golang.org>

2 years agoencoding/gob: use reflect.Value.SetZero
Daniel Martí [Sat, 25 Feb 2023 17:04:30 +0000 (17:04 +0000)]
encoding/gob: use reflect.Value.SetZero

Particularly helps when decoding map maps.

goos: linux
goarch: amd64
pkg: encoding/gob
cpu: AMD Ryzen 7 PRO 5850U with Radeon Graphics
│     old     │                new                 │
│   sec/op    │   sec/op     vs base               │
DecodeStringSlice-16      30.78µ ± 2%   30.68µ ± 1%        ~ (p=0.699 n=6)
DecodeStringsSlice-16     61.36µ ± 6%   60.85µ ± 4%        ~ (p=0.589 n=6)
DecodeBytesSlice-16       16.57µ ± 2%   16.51µ ± 4%        ~ (p=0.937 n=6)
DecodeInterfaceSlice-16   124.3µ ± 0%   125.4µ ± 1%        ~ (p=0.065 n=6)
DecodeMap-16              251.0µ ± 3%   216.2µ ± 2%  -13.86% (p=0.002 n=6)
geomean                   62.80µ        60.87µ        -3.07%

│     old      │                new                 │
│     B/op     │     B/op      vs base              │
DecodeStringSlice-16      37.98Ki ± 0%   37.98Ki ± 0%       ~ (p=1.000 n=6)
DecodeStringsSlice-16     63.79Ki ± 0%   63.79Ki ± 0%       ~ (p=0.675 n=6)
DecodeBytesSlice-16       22.40Ki ± 0%   22.40Ki ± 0%       ~ (p=0.364 n=6)
DecodeInterfaceSlice-16   80.27Ki ± 0%   80.27Ki ± 0%       ~ (p=0.924 n=6)
DecodeMap-16              52.67Ki ± 0%   52.67Ki ± 0%       ~ (p=0.145 n=6)
geomean                   47.01Ki        47.01Ki       +0.00%

│     old     │                 new                 │
│  allocs/op  │  allocs/op   vs base                │
DecodeStringSlice-16      1.169k ± 0%   1.169k ± 0%       ~ (p=1.000 n=6) ¹
DecodeStringsSlice-16     2.178k ± 0%   2.178k ± 0%       ~ (p=1.000 n=6) ¹
DecodeBytesSlice-16        169.0 ± 0%    169.0 ± 0%       ~ (p=1.000 n=6) ¹
DecodeInterfaceSlice-16   3.178k ± 0%   3.178k ± 0%       ~ (p=1.000 n=6) ¹
DecodeMap-16               181.0 ± 0%    181.0 ± 0%       ~ (p=1.000 n=6) ¹
geomean                    756.3         756.3       +0.00%
¹ all samples are equal

Change-Id: I5ae9268b1a86296494d8569f5158ef0e78128eb1
Reviewed-on: https://go-review.googlesource.com/c/go/+/471257
Reviewed-by: Joseph Tsai <joetsai@digital-static.net>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
2 years agocmd/go: simplify code thanks to reflect.Value.SetZero
Daniel Martí [Sat, 25 Feb 2023 17:24:42 +0000 (17:24 +0000)]
cmd/go: simplify code thanks to reflect.Value.SetZero

Change-Id: Ie9c05210390dae43faf566907839bce953925735
Reviewed-on: https://go-review.googlesource.com/c/go/+/471258
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Joseph Tsai <joetsai@digital-static.net>
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>

2 years agocmd/link: check for power10 support on external linker for PPC64
Paul E. Murphy [Mon, 20 Feb 2023 15:21:32 +0000 (09:21 -0600)]
cmd/link: check for power10 support on external linker for PPC64

The external linker will need to support the new PC relative relocations
when they are generated by Go in a future patch. If it does not, many
unhelpful relocation errors will be generated by the external linker.

Use the -mcpu=power10 option as a surrogate for -mpcrel. It most cases,
it should indicate whether the underlying linker has support for
resolving PC relative relocations.

Change-Id: I84b151ce04512ccaeb17835aaf44105a5f6b515b
Reviewed-on: https://go-review.googlesource.com/c/go/+/469576
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Paul Murphy <murp@ibm.com>
Reviewed-by: Archana Ravindar <aravind5@in.ibm.com>
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
2 years agocmd/compile/internal/pgo: fix RedirectEdges
Xiangdong Ji [Thu, 9 Feb 2023 09:31:14 +0000 (17:31 +0800)]
cmd/compile/internal/pgo: fix RedirectEdges

'RedirectEdges' may range over an out-edge slice under modification, leading to out-of-index
panic, and reuse an IREdge object by mistake if there are multiple inlining call-sites.

Fix by rewriting part of the redirecting operation.

Remove 'redirectEdges' as it's not used now and not working as expected in case of multiple
inlining call-sites.

Fixes #58437.

Change-Id: Ic344d4c262df548529acdc9380636cb50835ca51
Reviewed-on: https://go-review.googlesource.com/c/go/+/466915
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>
2 years agosyscall: use unsafe.Slice in anyToSockaddr
Cuong Manh Le [Sun, 26 Feb 2023 12:34:24 +0000 (19:34 +0700)]
syscall: use unsafe.Slice in anyToSockaddr

The function was added since go1.17, which is the minimum version for
bootstraping now.

Change-Id: I08b55c3639bb9ff042aabfcdcfbdf2993032ba6b
Reviewed-on: https://go-review.googlesource.com/c/go/+/471436
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

2 years agoencoding/json: rely on reflect.Value.Grow
Joe Tsai [Thu, 23 Feb 2023 21:32:10 +0000 (13:32 -0800)]
encoding/json: rely on reflect.Value.Grow

The Grow method is generally a more efficient way to grow a slice.
The older approach of using reflect.MakeSlice has to
waste effort zeroing the elements overwritten by the older slice
and has to allocate the slice header on the heap.

Performance:

name                old time/op    new time/op    delta
CodeDecoder         2.41ms ± 2%    2.42ms ± 2%    ~
CodeUnmarshal       3.12ms ± 3%    3.13ms ± 3%    ~
CodeUnmarshalReuse  2.49ms ± 3%    2.52ms ± 3%    ~

name                 old alloc/op  new alloc/op   delta
CodeDecoder         2.00MB ± 1%    1.99MB ± 1%    ~
CodeUnmarshal       3.05MB ± 0%    2.92MB ± 0%    -4.23%
CodeUnmarshalReuse  1.68MB ± 0%    1.68MB ± 0%    -0.32%

name                old allocs/op  new allocs/op  delta
CodeDecoder         77.1k ± 0%     77.0k ± 0%     -0.09%
CodeUnmarshal       92.7k ± 0%     91.3k ± 0%     -1.47%
CodeUnmarshalReuse  77.1k ± 0%     77.0k ± 0%     -0.07%

The Code benchmarks (which are the only ones that uses slices)
are largely unaffected. There is a slight reduction in allocations.

A histogram of slice lengths from the Code testdata is as follows:

   ≤1: 392
   ≤2: 256
   ≤4: 252
   ≤8: 152
  ≤16: 126
  ≤32: 78
  ≤64: 62
 ≤128: 46
 ≤256: 18
 ≤512: 10
≤1024: 8

A bulk majority of slice lengths are 8 elements or under.
Use of reflect.Value.Grow performs better for larger slices since
it can avoid the zeroing of memory and has a faster growth rate.
However, Grow grows starting from 1 element,
with a 2x growth rate until some threshold (currently 512),
Starting from 1 ensures better utilization of the heap,
but at the cost of more frequent regrowth early on.

In comparison, the previous logic always started
with a minimum of 4 elements, which leads to a wasted capacity
of 75% for the highly frequent case of a single element slice.
The older code always had a growth rate of 1.5x,
and so wastes less memory for number of elements below 512.

All in all, there are too many factors that hurt or help performance.
Rergardless, the simplicity of favoring reflect.Value.Grow
over manually managing growth rates is a welcome simplification.

Change-Id: I62868a7f112ece3c2da3b4f6bdf74d397110243c
Reviewed-on: https://go-review.googlesource.com/c/go/+/471175
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>
Auto-Submit: Joseph Tsai <joetsai@digital-static.net>
Run-TryBot: Joseph Tsai <joetsai@digital-static.net>

2 years agoos: checking for testable network before creating local listener
Cuong Manh Le [Mon, 27 Feb 2023 04:23:03 +0000 (11:23 +0700)]
os: checking for testable network before creating local listener

Fixes #58745

Change-Id: Id6666477b2c25f081d6f86047cea12bf8b3cb679
Reviewed-on: https://go-review.googlesource.com/c/go/+/471495
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Andy Pan <panjf2000@gmail.com>
2 years agonet: skip test affected by local network config on non-builder
Cuong Manh Le [Sun, 26 Feb 2023 12:41:32 +0000 (19:41 +0700)]
net: skip test affected by local network config on non-builder

CL 461275 uses testing.Short to skip this kind of tests. But it may lead
to false positive, because testing.Short may not always set. For
example, the normal workflow when testing changes in net package is
running:

go test -v net

in local machine, that will cause the test failed.

Using testenv.Builder is better, since when it's the standard way to
check whether the test is running on builder or local machine.

Change-Id: Ia5347eb76b4f0415dde8fa3d6c89bd0105f15aa7
Reviewed-on: https://go-review.googlesource.com/c/go/+/471437
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Than McIntosh <thanm@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>

2 years agoos: ensure File.ReadFrom returns ErrClosed instead of the internal poll.ErrFileClosing
Andy Pan [Tue, 21 Feb 2023 15:45:13 +0000 (23:45 +0800)]
os: ensure File.ReadFrom returns ErrClosed instead of the internal poll.ErrFileClosing

Fixes #58622

Change-Id: Ibb80296c39614478c75cb6bb04b6d0695cb990d3
Reviewed-on: https://go-review.googlesource.com/c/go/+/469795
Run-TryBot: Andy Pan <panjf2000@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
2 years agoos: support zero-copy from TCP/Unix socket to file
Andy Pan [Sat, 3 Sep 2022 02:41:03 +0000 (10:41 +0800)]
os: support zero-copy from TCP/Unix socket to file

Go currently supports the cases of zero-copy: from TCP/Unix socket to TCP socket, from file to TCP socket, from file to file.

Now implementing the new support of zero-copy: from TCP/Unix socket to file.

goos: linux
goarch: amd64
pkg: net
cpu: DO-Premium-Intel
                                  │      old      │                 new                  │
                                  │    sec/op     │    sec/op     vs base                │
SpliceFile/tcp-to-file/1024-4        5.910µ ±  9%   4.116µ ± 13%  -30.35% (p=0.000 n=10)
SpliceFile/tcp-to-file/2048-4        6.150µ ± 10%   4.077µ ± 13%  -33.72% (p=0.002 n=10)
SpliceFile/tcp-to-file/4096-4        4.837µ ± 28%   4.447µ ± 23%        ~ (p=0.353 n=10)
SpliceFile/tcp-to-file/8192-4        9.309µ ±  7%   6.293µ ±  9%  -32.40% (p=0.000 n=10)
SpliceFile/tcp-to-file/16384-4       19.43µ ± 12%   12.48µ ±  9%  -35.76% (p=0.000 n=10)
SpliceFile/tcp-to-file/32768-4       42.73µ ± 10%   25.32µ ±  8%  -40.76% (p=0.000 n=10)
SpliceFile/tcp-to-file/65536-4       70.37µ ± 11%   48.60µ ±  4%  -30.93% (p=0.000 n=10)
SpliceFile/tcp-to-file/131072-4     141.91µ ±  6%   96.24µ ±  4%  -32.18% (p=0.000 n=10)
SpliceFile/tcp-to-file/262144-4      329.7µ ±  8%   246.7µ ± 13%  -25.19% (p=0.000 n=10)
SpliceFile/tcp-to-file/524288-4      653.5µ ±  7%   441.6µ ±  7%  -32.43% (p=0.000 n=10)
SpliceFile/tcp-to-file/1048576-4    1184.4µ ±  9%   851.8µ ± 14%  -28.09% (p=0.000 n=10)
SpliceFile/unix-to-file/1024-4       1.734µ ± 10%   1.524µ ± 25%  -12.06% (p=0.035 n=10)
SpliceFile/unix-to-file/2048-4       2.614µ ±  7%   2.231µ ±  8%  -14.65% (p=0.000 n=10)
SpliceFile/unix-to-file/4096-4       5.081µ ±  7%   3.947µ ± 11%  -22.33% (p=0.000 n=10)
SpliceFile/unix-to-file/8192-4       8.560µ ±  5%   8.531µ ± 17%        ~ (p=0.796 n=10)
SpliceFile/unix-to-file/16384-4      18.09µ ± 12%   12.92µ ± 25%  -28.59% (p=0.000 n=10)
SpliceFile/unix-to-file/32768-4      35.50µ ±  5%   24.50µ ±  6%  -31.00% (p=0.000 n=10)
SpliceFile/unix-to-file/65536-4      69.99µ ±  7%   51.22µ ± 23%  -26.82% (p=0.000 n=10)
SpliceFile/unix-to-file/131072-4     133.7µ ± 17%   119.7µ ±  6%  -10.43% (p=0.000 n=10)
SpliceFile/unix-to-file/262144-4     246.5µ ±  5%   207.3µ ± 19%  -15.90% (p=0.007 n=10)
SpliceFile/unix-to-file/524288-4     484.8µ ± 20%   382.9µ ± 10%  -21.02% (p=0.000 n=10)
SpliceFile/unix-to-file/1048576-4   1188.4µ ± 27%   781.8µ ± 11%  -34.21% (p=0.000 n=10)
geomean                              42.24µ         31.45µ        -25.53%

                                  │      old       │                  new                   │
                                  │      B/s       │      B/s        vs base                │
SpliceFile/tcp-to-file/1024-4        165.4Mi ± 10%    237.3Mi ± 11%  +43.47% (p=0.000 n=10)
SpliceFile/tcp-to-file/2048-4        317.6Mi ± 12%    479.7Mi ± 14%  +51.02% (p=0.002 n=10)
SpliceFile/tcp-to-file/4096-4        808.2Mi ± 22%    886.8Mi ± 19%        ~ (p=0.353 n=10)
SpliceFile/tcp-to-file/8192-4        839.3Mi ±  6%   1241.5Mi ±  8%  +47.91% (p=0.000 n=10)
SpliceFile/tcp-to-file/16384-4       804.7Mi ± 13%   1252.2Mi ± 10%  +55.61% (p=0.000 n=10)
SpliceFile/tcp-to-file/32768-4       731.3Mi ± 11%   1234.3Mi ±  7%  +68.78% (p=0.000 n=10)
SpliceFile/tcp-to-file/65536-4       888.7Mi ± 10%   1286.2Mi ±  4%  +44.73% (p=0.000 n=10)
SpliceFile/tcp-to-file/131072-4      880.9Mi ±  6%   1299.0Mi ±  4%  +47.47% (p=0.000 n=10)
SpliceFile/tcp-to-file/262144-4      758.2Mi ±  7%   1014.4Mi ± 15%  +33.78% (p=0.000 n=10)
SpliceFile/tcp-to-file/524288-4      765.3Mi ±  7%   1132.5Mi ±  7%  +47.99% (p=0.000 n=10)
SpliceFile/tcp-to-file/1048576-4     845.0Mi ±  8%   1174.0Mi ± 16%  +38.94% (p=0.000 n=10)
SpliceFile/unix-to-file/1024-4       564.2Mi ± 11%    640.5Mi ± 20%  +13.53% (p=0.035 n=10)
SpliceFile/unix-to-file/2048-4       747.4Mi ±  7%    875.7Mi ±  8%  +17.17% (p=0.000 n=10)
SpliceFile/unix-to-file/4096-4       768.8Mi ±  6%    989.8Mi ± 10%  +28.74% (p=0.000 n=10)
SpliceFile/unix-to-file/8192-4       912.9Mi ±  5%    915.8Mi ± 15%        ~ (p=0.796 n=10)
SpliceFile/unix-to-file/16384-4      863.6Mi ± 10%   1209.7Mi ± 20%  +40.06% (p=0.000 n=10)
SpliceFile/unix-to-file/32768-4      880.2Mi ±  6%   1275.7Mi ±  6%  +44.93% (p=0.000 n=10)
SpliceFile/unix-to-file/65536-4      893.0Mi ±  7%   1220.3Mi ± 19%  +36.66% (p=0.000 n=10)
SpliceFile/unix-to-file/131072-4     935.1Mi ± 14%   1043.9Mi ±  7%  +11.64% (p=0.000 n=10)
SpliceFile/unix-to-file/262144-4    1014.2Mi ±  6%   1205.9Mi ± 16%  +18.91% (p=0.007 n=10)
SpliceFile/unix-to-file/524288-4     1.007Gi ± 17%    1.275Gi ±  9%  +26.61% (p=0.000 n=10)
SpliceFile/unix-to-file/1048576-4    841.8Mi ± 21%   1279.0Mi ± 10%  +51.94% (p=0.000 n=10)
geomean                              740.1Mi          994.2Mi        +34.33%

                                  │      old       │                   new                   │
                                  │      B/op      │    B/op     vs base                     │
SpliceFile/tcp-to-file/1024-4       0.000 ±   0%     0.000 ± 0%         ~ (p=1.000 n=10) ¹
SpliceFile/tcp-to-file/2048-4       0.000 ±   0%     0.000 ± 0%         ~ (p=1.000 n=10) ¹
SpliceFile/tcp-to-file/4096-4       0.000 ±   0%     0.000 ± 0%         ~ (p=1.000 n=10) ¹
SpliceFile/tcp-to-file/8192-4       0.000 ±   0%     0.000 ± 0%         ~ (p=1.000 n=10) ¹
SpliceFile/tcp-to-file/16384-4      0.000 ±   0%     0.000 ± 0%         ~ (p=1.000 n=10) ¹
SpliceFile/tcp-to-file/32768-4      1.000 ±   0%     0.000 ± 0%  -100.00% (p=0.000 n=10)
SpliceFile/tcp-to-file/65536-4      1.000 ± 100%     0.000 ± 0%  -100.00% (p=0.000 n=10)
SpliceFile/tcp-to-file/131072-4     3.000 ±  33%     0.000 ± 0%  -100.00% (p=0.000 n=10)
SpliceFile/tcp-to-file/262144-4     8.500 ±  18%     0.000 ± 0%  -100.00% (p=0.000 n=10)
SpliceFile/tcp-to-file/524288-4     16.50 ±  21%      0.00 ± 0%  -100.00% (p=0.000 n=10)
SpliceFile/tcp-to-file/1048576-4    30.50 ±  15%      0.00 ± 0%  -100.00% (p=0.000 n=10)
SpliceFile/unix-to-file/1024-4      0.000 ±   0%     0.000 ± 0%         ~ (p=1.000 n=10) ¹
SpliceFile/unix-to-file/2048-4      0.000 ±   0%     0.000 ± 0%         ~ (p=1.000 n=10) ¹
SpliceFile/unix-to-file/4096-4      0.000 ±   0%     0.000 ± 0%         ~ (p=1.000 n=10) ¹
SpliceFile/unix-to-file/8192-4      0.000 ±   0%     0.000 ± 0%         ~ (p=1.000 n=10) ¹
SpliceFile/unix-to-file/16384-4     0.000 ±   0%     0.000 ± 0%         ~ (p=1.000 n=10) ¹
SpliceFile/unix-to-file/32768-4     0.000 ±   0%     0.000 ± 0%         ~ (p=1.000 n=10) ¹
SpliceFile/unix-to-file/65536-4     1.000 ± 100%     0.000 ± 0%  -100.00% (p=0.000 n=10)
SpliceFile/unix-to-file/131072-4    3.000 ±  33%     0.000 ± 0%  -100.00% (p=0.000 n=10)
SpliceFile/unix-to-file/262144-4    6.000 ±  17%     0.000 ± 0%  -100.00% (p=0.000 n=10)
SpliceFile/unix-to-file/524288-4    12.00 ±   8%      0.00 ± 0%  -100.00% (p=0.000 n=10)
SpliceFile/unix-to-file/1048576-4   33.50 ±  10%      0.00 ± 0%  -100.00% (p=0.000 n=10)
geomean                                          ²               ?                       ² ³
¹ all samples are equal
² summaries must be >0 to compute geomean
³ ratios must be >0 to compute geomean

                                  │     old      │                 new                 │
                                  │  allocs/op   │ allocs/op   vs base                 │
SpliceFile/tcp-to-file/1024-4       0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=10) ¹
SpliceFile/tcp-to-file/2048-4       0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=10) ¹
SpliceFile/tcp-to-file/4096-4       0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=10) ¹
SpliceFile/tcp-to-file/8192-4       0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=10) ¹
SpliceFile/tcp-to-file/16384-4      0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=10) ¹
SpliceFile/tcp-to-file/32768-4      0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=10) ¹
SpliceFile/tcp-to-file/65536-4      0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=10) ¹
SpliceFile/tcp-to-file/131072-4     0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=10) ¹
SpliceFile/tcp-to-file/262144-4     0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=10) ¹
SpliceFile/tcp-to-file/524288-4     0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=10) ¹
SpliceFile/tcp-to-file/1048576-4    0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=10) ¹
SpliceFile/unix-to-file/1024-4      0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=10) ¹
SpliceFile/unix-to-file/2048-4      0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=10) ¹
SpliceFile/unix-to-file/4096-4      0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=10) ¹
SpliceFile/unix-to-file/8192-4      0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=10) ¹
SpliceFile/unix-to-file/16384-4     0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=10) ¹
SpliceFile/unix-to-file/32768-4     0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=10) ¹
SpliceFile/unix-to-file/65536-4     0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=10) ¹
SpliceFile/unix-to-file/131072-4    0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=10) ¹
SpliceFile/unix-to-file/262144-4    0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=10) ¹
SpliceFile/unix-to-file/524288-4    0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=10) ¹
SpliceFile/unix-to-file/1048576-4   0.000 ± 0%     0.000 ± 0%       ~ (p=1.000 n=10) ¹
geomean                                        ²               +0.00%                ²
¹ all samples are equal
² summaries must be >0 to compute geomean

Change-Id: Ie7f7d4d7b6b373d9ee7ce6da8f6a4cd157632486
Reviewed-on: https://go-review.googlesource.com/c/go/+/466015
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Run-TryBot: Andy Pan <panjf2000@gmail.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>

2 years agogo/types, types2: add isTypeLit predicate
Robert Griesemer [Thu, 23 Feb 2023 23:47:44 +0000 (15:47 -0800)]
go/types, types2: add isTypeLit predicate

Preparation for next CL.

Change-Id: I5ef170a04577d8aea10255e304357bdbea4935a7
Reviewed-on: https://go-review.googlesource.com/c/go/+/470919
TryBot-Result: Gopher Robot <gobot@golang.org>
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>

2 years agogo/types, types2: fix comment in Checker.renameTParams
Robert Griesemer [Thu, 23 Feb 2023 23:42:57 +0000 (15:42 -0800)]
go/types, types2: fix comment in Checker.renameTParams

The original comment examples didn't pass the correct number
of function arguments. Rather than fixing that, use a simpler
example and adjust prose a bit.

Change-Id: I2806737a2b8f9c4b876911b214f3d9e28213fc27
Reviewed-on: https://go-review.googlesource.com/c/go/+/470918
Reviewed-by: Robert Griesemer <gri@google.com>
Run-TryBot: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>

2 years agocmd/link: don't emit PAX_FLAGS segment on Linux
Ian Lance Taylor [Fri, 24 Feb 2023 23:52:58 +0000 (15:52 -0800)]
cmd/link: don't emit PAX_FLAGS segment on Linux

We started emitting this segment in 2012 in CL 6326054 for #47.
It disabled three kinds of protection: mprotect, randexec, and emutramp.
The randexec protection was deprecated some time ago, replaced by PIE.
The emutramp and mprotect protection was because we used to rely on being
able to create writable executable memory to implement function closures,
but that is not true since https://go.dev/s/go11func was implemented.

Change-Id: I5e3a5279d76d642b0423d26195b891479a235763
Reviewed-on: https://go-review.googlesource.com/c/go/+/471199
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
2 years agocrypto/internal/nistec: reduce P-256 scalar
Filippo Valsorda [Mon, 13 Feb 2023 14:16:27 +0000 (15:16 +0100)]
crypto/internal/nistec: reduce P-256 scalar

Unlike the rest of nistec, the P-256 assembly doesn't use complete
addition formulas, meaning that p256PointAdd[Affine]Asm won't return the
correct value if the two inputs are equal.

This was (undocumentedly) ignored in the scalar multiplication loops
because as long as the input point is not the identity and the scalar is
lower than the order of the group, the addition inputs can't be the same.

As part of the math/big rewrite, we went however from always reducing
the scalar to only checking its length, under the incorrect assumption
that the scalar multiplication loop didn't require reduction.

Added a reduction, and while at it added it in P256OrdInverse, too, to
enforce a universal reduction invariant on p256OrdElement values.

Note that if the input point is the infinity, the code currently still
relies on undefined behavior, but that's easily tested to behave
acceptably, and will be addressed in a future CL.

Fixes #58647
Fixes CVE-2023-24532

(Filed with the "safe APIs like complete addition formulas are good" dept.)

Change-Id: I7b2c75238440e6852be2710fad66ff1fdc4e2b24
Reviewed-on: https://go-review.googlesource.com/c/go/+/471255
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Roland Shoemaker <roland@golang.org>
Run-TryBot: Filippo Valsorda <filippo@golang.org>
Auto-Submit: Filippo Valsorda <filippo@golang.org>
Reviewed-by: Damien Neil <dneil@google.com>
2 years agonet: inline ios check in tests
Tobias Klauser [Thu, 23 Feb 2023 23:07:19 +0000 (00:07 +0100)]
net: inline ios check in tests

Change-Id: I0d796d5eb05d823a18c609b2e76cc4d35da9d2b5
Reviewed-on: https://go-review.googlesource.com/c/go/+/470955
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>

2 years agonet: document that on macOS c-archive requires -lresolv
Ian Lance Taylor [Thu, 23 Feb 2023 23:13:06 +0000 (15:13 -0800)]
net: document that on macOS c-archive requires -lresolv

For #58159

Change-Id: Iff8e017c568be111c494992cb6fe62d469e0f981
Reviewed-on: https://go-review.googlesource.com/c/go/+/470917
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

2 years agoencoding/json: use append-like operations for encoding
Joe Tsai [Mon, 20 Feb 2023 03:05:12 +0000 (19:05 -0800)]
encoding/json: use append-like operations for encoding

As part of the effort to rely less on bytes.Buffer,
switch most operations to use more natural append-like operations.
This makes it easier to swap bytes.Buffer out with a buffer type
that only needs to support a minimal subset of operations.

As a simplification, we can remove the use of the scratch buffer
and use the available capacity of the buffer itself as the scratch.
Also, declare an inlineable mayAppendQuote function to conditionally
append a double-quote if necessary.

Performance:

    name              old time/op    new time/op    delta
    CodeEncoder          405µs ± 2%     397µs ± 2%  -1.94%  (p=0.000 n=20+20)
    CodeEncoderError     453µs ± 1%     444µs ± 4%  -1.83%  (p=0.000 n=19+19)
    CodeMarshal          559µs ± 4%     548µs ± 2%  -2.02%  (p=0.001 n=19+17)
    CodeMarshalError     724µs ± 3%     716µs ± 2%  -1.13%  (p=0.030 n=19+20)
    EncodeMarshaler     24.9ns ±15%    22.9ns ± 5%    ~     (p=0.086 n=20+17)
    EncoderEncode       14.0ns ±27%    15.0ns ±20%    ~     (p=0.365 n=20+20)

There is a slight performance gain across the board due to
the elimination of the scratch buffer. Appends are done directly
into the unused capacity of the underlying buffer,
avoiding an additional copy. See #53685

Updates #27735

Change-Id: Icf6d612a7f7a51ecd10097af092762dd1225d49e
Reviewed-on: https://go-review.googlesource.com/c/go/+/469558
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Auto-Submit: Joseph Tsai <joetsai@digital-static.net>
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Joseph Tsai <joetsai@digital-static.net>

2 years agoencoding/json: unify encodeState.string and encodeState.stringBytes
Joe Tsai [Mon, 20 Feb 2023 01:37:02 +0000 (17:37 -0800)]
encoding/json: unify encodeState.string and encodeState.stringBytes

This is part of the effort to reduce direct reliance on bytes.Buffer
so that we can use a buffer with better pooling characteristics.

Unify these two methods as a single version that uses generics
to reduce duplicated logic. Unfortunately, we lack a generic
version of utf8.DecodeRune (see #56948), so we cast []byte to string.
The []byte variant is slightly slower for multi-byte unicode since
casting results in a stack-allocated copy operation.
Fortunately, this code path is used only for TextMarshalers.
We can also delete TestStringBytes, which exists to ensure
that the two duplicate implementations remain in sync.

Performance:

    name              old time/op    new time/op    delta
    CodeEncoder          399µs ± 2%     409µs ± 2%   +2.59%  (p=0.000 n=9+9)
    CodeEncoderError     450µs ± 1%     451µs ± 2%     ~     (p=0.684 n=10+10)
    CodeMarshal          553µs ± 2%     562µs ± 3%     ~     (p=0.075 n=10+10)
    CodeMarshalError     733µs ± 3%     737µs ± 2%     ~     (p=0.400 n=9+10)
    EncodeMarshaler     24.9ns ±12%    24.1ns ±13%     ~     (p=0.190 n=10+10)
    EncoderEncode       12.3ns ± 3%    14.7ns ±20%     ~     (p=0.315 n=8+10)

    name              old speed      new speed      delta
    CodeEncoder       4.87GB/s ± 2%  4.74GB/s ± 2%   -2.53%  (p=0.000 n=9+9)
    CodeEncoderError  4.31GB/s ± 1%  4.30GB/s ± 2%     ~     (p=0.684 n=10+10)
    CodeMarshal       3.51GB/s ± 2%  3.46GB/s ± 3%     ~     (p=0.075 n=10+10)
    CodeMarshalError  2.65GB/s ± 3%  2.63GB/s ± 2%     ~     (p=0.400 n=9+10)

    name              old alloc/op   new alloc/op   delta
    CodeEncoder          327B ±347%     447B ±232%  +36.93%  (p=0.034 n=9+10)
    CodeEncoderError      142B ± 1%      143B ± 0%     ~     (p=1.000 n=8+7)
    CodeMarshal         1.96MB ± 2%    1.96MB ± 2%     ~     (p=0.468 n=10+10)
    CodeMarshalError    2.04MB ± 3%    2.03MB ± 1%     ~     (p=0.971 n=10+10)
    EncodeMarshaler      4.00B ± 0%     4.00B ± 0%     ~     (all equal)
    EncoderEncode        0.00B          0.00B          ~     (all equal)

    name              old allocs/op  new allocs/op  delta
    CodeEncoder           0.00           0.00          ~     (all equal)
    CodeEncoderError      4.00 ± 0%      4.00 ± 0%     ~     (all equal)
    CodeMarshal           1.00 ± 0%      1.00 ± 0%     ~     (all equal)
    CodeMarshalError      6.00 ± 0%      6.00 ± 0%     ~     (all equal)
    EncodeMarshaler       1.00 ± 0%      1.00 ± 0%     ~     (all equal)
    EncoderEncode         0.00           0.00          ~     (all equal)

There is a very slight performance degradation for CodeEncoder
due to an increase in allocation sizes. However, the number of allocations
did not change. This is likely due to remote effects of the growth rate
differences between bytes.Buffer and the builtin append function.
We shouldn't overly rely on the growth rate of bytes.Buffer anyways
since that is subject to possibly change in #51462.
As the benchtime increases, the alloc/op goes down indicating
that the amortized memory cost is fixed.

Updates #27735

Change-Id: Ie35e480e292fe082d7986e0a4d81212c1d4202b3
Reviewed-on: https://go-review.googlesource.com/c/go/+/469556
Run-TryBot: Joseph Tsai <joetsai@digital-static.net>
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Auto-Submit: Joseph Tsai <joetsai@digital-static.net>

2 years agoencoding/json: use append for Compact and Indent
Joe Tsai [Mon, 20 Feb 2023 01:11:46 +0000 (17:11 -0800)]
encoding/json: use append for Compact and Indent

This is part of the effort to reduce direct reliance on bytes.Buffer
so that we can use a buffer with better pooling characteristics.

Avoid direct use of bytes.Buffer in Compact and Indent and
instead modify the logic to rely only on append.
This avoids reliance on the bytes.Buffer.Truncate method,
which makes switching to a custom buffer implementation easier.

Performance:

name                old time/op    new time/op    delta
EncodeMarshaler    25.5ns ± 8%    25.7ns ± 9%   ~     (p=0.724 n=10+10)

name                old alloc/op   new alloc/op   delta
EncodeMarshaler     4.00B ± 0%     4.00B ± 0%   ~     (all equal)

name                old allocs/op  new allocs/op  delta
EncodeMarshaler      1.00 ± 0%      1.00 ± 0%   ~     (all equal)

Updates #27735

Change-Id: I8cded03fab7651d43b5a238ee721f3472530868e
Reviewed-on: https://go-review.googlesource.com/c/go/+/469555
Run-TryBot: Joseph Tsai <joetsai@digital-static.net>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Joseph Tsai <joetsai@digital-static.net>
Reviewed-by: Bryan Mills <bcmills@google.com>
2 years agocmd/internal/obj/arm64: factor out code generation for addition of 12 bit immediates
Joel Sing [Sun, 8 Jan 2023 17:21:37 +0000 (04:21 +1100)]
cmd/internal/obj/arm64: factor out code generation for addition of 12 bit immediates

Factor out and simplify code that generates the addition of a 12 bit immediate
(the addition of a negative value is still handled via subtraction). This also
fixes the mishandling of the case where v is 0.

Change-Id: I6040f33d2fec87b772272531b3bf02390ae7f200
Reviewed-on: https://go-review.googlesource.com/c/go/+/461141
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Eric Fang <eric.fang@arm.com>
Reviewed-by: Than McIntosh <thanm@google.com>
Run-TryBot: Joel Sing <joel@sing.id.au>
Reviewed-by: Cherry Mui <cherryyz@google.com>
2 years agoruntime: use explicit NOFRAME on netbsd/amd64
qmuntal [Wed, 8 Feb 2023 13:28:18 +0000 (14:28 +0100)]
runtime: use explicit NOFRAME on netbsd/amd64

This CL marks some netbsd assembly functions as NOFRAME to avoid
relying on the implicit amd64 NOFRAME heuristic, where NOSPLIT functions
without stack were also marked as NOFRAME.

While here, and thanks to CL 466355, `asm_netbsd_amd64.s` can
be deleted in favor of `asm9_unix2_amd64.s`, which makes better
use of the frame pointer.

Updates #58378

Change-Id: Iff554b664ec25f2bb6ec198c0f684590b359c383
Reviewed-on: https://go-review.googlesource.com/c/go/+/466396
Reviewed-by: Than McIntosh <thanm@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Run-TryBot: Quim Muntal <quimmuntal@gmail.com>

2 years agonet/url: simplify values Get
Mateusz Poliwczak [Thu, 23 Feb 2023 19:03:00 +0000 (19:03 +0000)]
net/url: simplify values Get

Checking if v == nil is unnecessary, nil map always return the zero value of the value type.

Change-Id: I9c5499bc7db72c4c62e02013ba7f9a6ee4795c09
GitHub-Last-Rev: 03fc2330e2ae568eafeb4d2e25e3f3535491062a
GitHub-Pull-Request: golang/go#58662
Reviewed-on: https://go-review.googlesource.com/c/go/+/470736
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>

2 years agoruntime: use explicit NOFRAME on freebsd/amd64
qmuntal [Wed, 8 Feb 2023 13:08:20 +0000 (14:08 +0100)]
runtime: use explicit NOFRAME on freebsd/amd64

This CL marks some freebsd assembly functions as NOFRAME to avoid
relying on the implicit amd64 NOFRAME heuristic, where NOSPLIT functions
without stack were also marked as NOFRAME.

Updates #58378

Change-Id: Ibd00748946f1137e165293df7da73278cb673bbd
Reviewed-on: https://go-review.googlesource.com/c/go/+/466395
Reviewed-by: Than McIntosh <thanm@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Run-TryBot: Quim Muntal <quimmuntal@gmail.com>

2 years agocmd/compile: batch write barrier calls
Keith Randall [Tue, 1 Nov 2022 23:46:43 +0000 (16:46 -0700)]
cmd/compile: batch write barrier calls

Have the write barrier call return a pointer to a buffer into which
the generated code records pointers that need write barrier treatment.

Change-Id: I7871764298e0aa1513de417010c8d46b296b199e
Reviewed-on: https://go-review.googlesource.com/c/go/+/447781
Reviewed-by: Keith Randall <khr@google.com>
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Bypass: Keith Randall <khr@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
2 years agoimage/jpeg: return io.ErrUnexpectedEOF on truncated data
Alexander Yastrebov [Sat, 4 Feb 2023 14:52:55 +0000 (14:52 +0000)]
image/jpeg: return io.ErrUnexpectedEOF on truncated data

Decoder calls fill from readFull, ignore and readByte and
readByte did not check returned io.EOF.

This change moves io.EOF translation inside fill.

name                 old speed      new speed      delta
DecodeBaseline-8     67.4MB/s ± 0%  67.3MB/s ± 0%  -0.20%  (p=0.000 n=16+19)
DecodeProgressive-8  43.7MB/s ± 0%  43.6MB/s ± 0%  -0.06%  (p=0.013 n=17+19)

Fixes #56724

Change-Id: Ia0d5cc561f3c2050e25ec3f2b5e6866c3b4941c7
GitHub-Last-Rev: 470154373bc1452dffc5293d9a840e972749a76d
GitHub-Pull-Request: golang/go#56863
Reviewed-on: https://go-review.googlesource.com/c/go/+/452335
Run-TryBot: Rob Pike <r@golang.org>
Reviewed-by: Nigel Tao <nigeltao@golang.org>
Reviewed-by: Nigel Tao (INACTIVE; USE @golang.org INSTEAD) <nigeltao@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

2 years agoruntime: fix linkname signature for godebug
Adin Scannell [Thu, 23 Feb 2023 22:22:29 +0000 (22:22 +0000)]
runtime: fix linkname signature for godebug

This signature uses the wrong type for the passed function, which
will be saved in the internal runtime map. Since the functions are
likely compatible (uint64 return versus int64), this may work but
should generally be fixed.

This is other instance of #58440.

Change-Id: Ied82e554745ef72eefeb5be540605809ffa06533
Reviewed-on: https://go-review.googlesource.com/c/go/+/470915
Reviewed-by: Michael Pratt <mpratt@google.com>
Run-TryBot: Michael Pratt <mpratt@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Michael Pratt <mpratt@google.com>

2 years agocmd/compile: rework unbounded shift lowering on PPC64
Paul E. Murphy [Tue, 27 Sep 2022 18:13:10 +0000 (13:13 -0500)]
cmd/compile: rework unbounded shift lowering on PPC64

This reduces unbounded shift latency by one cycle, and may
generate less instructions in some cases.

When there is a choice whether to use doubleword or word shifts, use
doubleword shifts. Doubleword shifts have fewer hardware scheduling
restrictions across P8/P9/P10.

Likewise, rework the shift sequence to allow the compare/shift/overshift
values to compute in parallel, then choose the correct value.

Some ANDCCconst rules also need reworked to ensure they simplify when
used for their flag value. This commonly occurs when prove fails to
identify a bounded shift (e.g foo32<<uint(x&31)).

Change-Id: Ifc6ff4a865d68675e57745056db414b0eb6f2d34
Reviewed-on: https://go-review.googlesource.com/c/go/+/442597
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Lynn Boger <laboger@linux.vnet.ibm.com>
Reviewed-by: Than McIntosh <thanm@google.com>
Run-TryBot: Paul Murphy <murp@ibm.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
2 years agocmd/compile: adjust inlined DW_AT_call_line by //line
Michael Pratt [Wed, 22 Feb 2023 22:50:20 +0000 (17:50 -0500)]
cmd/compile: adjust inlined DW_AT_call_line by //line

insertInlCall mistakenly uses the absolute line number of the call
rather than the relative line number (adjusted by //line). Switch to the
correct line number.

The call filename was already correct.

Fixes #58648

Change-Id: Id8d1848895233e972d8cfe9c5789a88e62d06556
Reviewed-on: https://go-review.googlesource.com/c/go/+/470876
Reviewed-by: Than McIntosh <thanm@google.com>
Run-TryBot: Michael Pratt <mpratt@google.com>
Auto-Submit: Michael Pratt <mpratt@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
2 years agocmd/link/internal/ld: split TestInlinedRoutineRecords
Michael Pratt [Wed, 22 Feb 2023 22:11:28 +0000 (17:11 -0500)]
cmd/link/internal/ld: split TestInlinedRoutineRecords

A later CL will add additional test cases for CallFile and CallLine with
a //line directive. The parameter/variable checks have nothing to do
with line numbers and will only serve to make the test more difficult to
follow, so split this single mega-test into two: one for testing
file/line and the other for testing parameters/variables.

There are a few additional minor changes:

1. A missing AttrName is now an error.
2. Check added for AttrCallLine, which was previously untested.

For #58648.

Change-Id: I35e75ead766bcf910c58eb20541769349841f2b5
Reviewed-on: https://go-review.googlesource.com/c/go/+/470875
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Than McIntosh <thanm@google.com>
Auto-Submit: Michael Pratt <mpratt@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
2 years agoRevert "cmd/link: default to external linking with cgo std packages"
Than McIntosh [Thu, 23 Feb 2023 20:17:09 +0000 (20:17 +0000)]
Revert "cmd/link: default to external linking with cgo std packages"

This reverts CL 470298.

Reason for revert: causes issues with Google internal testing.

Updates #58619.
Updates #58620.

Change-Id: Ic6601820ba8758ef96b71e32d9ffc549c36d5c98
Reviewed-on: https://go-review.googlesource.com/c/go/+/470835
Reviewed-by: Russ Cox <rsc@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Than McIntosh <thanm@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
2 years agocmd/compile: inline constant sized memclrNoHeapPointers calls on PPC64
Lynn Boger [Tue, 31 Jan 2023 20:27:30 +0000 (14:27 -0600)]
cmd/compile: inline constant sized memclrNoHeapPointers calls on PPC64

Update the function isInlinableMemclr for ppc64 and ppc64le
to enable inlining for the constant sized cases < 512.

Larger cases can use dcbz which performs better but requires
alignment checking so it is best to continue using memclrNoHeapPointers
for those cases.

Results on p10:

MemclrKnownSize1         2.07ns ± 0%     0.57ns ± 0%   -72.59%
MemclrKnownSize2         2.56ns ± 5%     0.57ns ± 0%   -77.82%
MemclrKnownSize4         5.15ns ± 0%     0.57ns ± 0%   -89.00%
MemclrKnownSize8         2.23ns ± 0%     0.57ns ± 0%   -74.57%
MemclrKnownSize16        2.23ns ± 0%     0.50ns ± 0%   -77.74%
MemclrKnownSize32        2.28ns ± 0%     0.56ns ± 0%   -75.28%
MemclrKnownSize64        2.49ns ± 0%     0.72ns ± 0%   -70.95%
MemclrKnownSize112       2.97ns ± 2%     1.14ns ± 0%   -61.72%
MemclrKnownSize128       4.64ns ± 6%     2.45ns ± 1%   -47.17%
MemclrKnownSize192       5.45ns ± 5%     2.79ns ± 0%   -48.87%
MemclrKnownSize248       4.51ns ± 0%     2.83ns ± 0%   -37.12%
MemclrKnownSize256       6.34ns ± 1%     3.58ns ± 0%   -43.53%
MemclrKnownSize512       3.64ns ± 0%     3.64ns ± 0%    -0.03%
MemclrKnownSize1024      4.73ns ± 0%     4.73ns ± 0%    +0.01%
MemclrKnownSize4096      17.1ns ± 0%     17.1ns ± 0%    +0.07%
MemclrKnownSize512KiB    2.12µs ± 0%     2.12µs ± 0%      ~     (all equal)

Change-Id: If1abf5749f4802c64523a41fe0058bd144d0ea46
Reviewed-on: https://go-review.googlesource.com/c/go/+/464340
Run-TryBot: Lynn Boger <laboger@linux.vnet.ibm.com>
Reviewed-by: Jakub Ciolek <jakub@ciolek.dev>
Reviewed-by: Archana Ravindar <aravind5@in.ibm.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Carlos Eduardo Seo <carlos.seo@linaro.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
2 years agocmd/dist: default to GOARM=7 on all non-arm systems
Russ Cox [Thu, 23 Feb 2023 13:37:08 +0000 (08:37 -0500)]
cmd/dist: default to GOARM=7 on all non-arm systems

If you run make.bash on an arm system without GOARM set,
we sniff the local system to find the maximum default GOARM
that will actually work on that system. That's fine, and we can
keep doing that.

But the story for cross-compiling is weirder.
If we build a windows/amd64 toolchain and then use it to
cross-compile linux/arm binaries, we get GOARM=7 binaries.
Do the same on a linux/amd64 system and you get GOARM=5 binaries.
This clearly makes no sense, and worse it makes the builds
non-reproducible in a subtle way.

This CL simplifies the logic and improves reproducibility by
defaulting to GOARM=7 any time we wouldn't sniff the local system.

On go.dev/dl we serve a linux-armv6l distribution with a default GOARM=6.
That is built by setting GOARM=6 during make.bash, so it is unaffected
by this CL and will continue to be GOARM=6.

For #24904.

Change-Id: I4331709876d5948fd33ec6e4a7b18b3cef12f240
Reviewed-on: https://go-review.googlesource.com/c/go/+/470695
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

2 years agoruntime: use explicit NOFRAME on dragonfly/amd64
qmuntal [Wed, 8 Feb 2023 09:27:20 +0000 (10:27 +0100)]
runtime: use explicit NOFRAME on dragonfly/amd64

This CL marks some dragonfly assembly functions as NOFRAME to avoid
relying on the implicit amd64 NOFRAME heuristic, where NOSPLIT functions
without stack were also marked as NOFRAME.

Updates #58378

Change-Id: I832a1a78d68a49f11df3b03fa9d50d4796bcac03
Reviewed-on: https://go-review.googlesource.com/c/go/+/466355
Run-TryBot: Quim Muntal <quimmuntal@gmail.com>
Reviewed-by: Than McIntosh <thanm@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
2 years agocmd/go: don't compute Embed fields if they're not needed
Frank Viernau [Mon, 20 Feb 2023 09:08:00 +0000 (09:08 +0000)]
cmd/go: don't compute Embed fields if they're not needed

If the user provides the -json flag to explicitly specify fields, but doesn't specify any *Embed* field, skip computing the embed fields.

This enhances the initial implementation of #29666.

Change-Id: I60e86fb25a445689aecbcc7f3f3f88e0f37a0fc5
GitHub-Last-Rev: 2795c195bf995f798a45e928becebc253c89b9d6
GitHub-Pull-Request: golang/go#58522
Reviewed-on: https://go-review.googlesource.com/c/go/+/468075
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Bryan Mills <bcmills@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>

2 years agosyscall: add ptracePtr that accepts pointer arg as unsafe.Pointer
Dmitri Goutnik [Wed, 22 Feb 2023 15:58:14 +0000 (10:58 -0500)]
syscall: add ptracePtr that accepts pointer arg as unsafe.Pointer

The existing ptrace wrapper accepts pointer argument as an uintptr which
often points to the memory allocated in Go. This violates unsafe.Pointer safety
rules.

Fixes #58387

Change-Id: Iab12122c495953f94ea00c2a61654a818a464205
Reviewed-on: https://go-review.googlesource.com/c/go/+/470299
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Dmitri Goutnik <dgoutnik@gmail.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Dmitri Goutnik <dgoutnik@gmail.com>

2 years agocmd/go: enable vet directive analyzer during 'go test'
Russ Cox [Mon, 30 Jan 2023 19:23:48 +0000 (14:23 -0500)]
cmd/go: enable vet directive analyzer during 'go test'

For #56986, run the new directive analyzer during 'go test',
to diagnose problems that would otherwise be missed,
like //go:debug appearing in the wrong place in a file
or in the wrong files.

Change-Id: I1ac230c3c67e58b5e584128e0ec6ff482cb225f9
Reviewed-on: https://go-review.googlesource.com/c/go/+/464135
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
2 years agocmd/go: set default GODEBUG for main packages
Russ Cox [Tue, 29 Nov 2022 20:43:08 +0000 (15:43 -0500)]
cmd/go: set default GODEBUG for main packages

For #56986, change the go command to compute and set the
default GODEBUG settings for each main package, based on
the work module's go version and the //go:debug lines in the
main package.

Change-Id: I2118cf0ae6d981138138661e02120c05af648872
Reviewed-on: https://go-review.googlesource.com/c/go/+/453605
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

2 years agocmd/go, go/build: parse directives in file headers
Russ Cox [Tue, 29 Nov 2022 18:30:50 +0000 (13:30 -0500)]
cmd/go, go/build: parse directives in file headers

For #56986, go/build needs to report up to cmd/go
about //go:debug lines found in the source code.
Rather than make a special case for //go:debug,
this change gathers all top-level directives above the
package line and includes them in the result.

The go command's module index must match go/build,
so this CL contains the code to update the index as well.

A future CL will use the //go:debug lines to prepare the default
GODEBUG settings, as well as rejecting such lines in non-main
packages.

Change-Id: I66ab8dc72f9cd65c503b10b744367caca233f8a6
Reviewed-on: https://go-review.googlesource.com/c/go/+/453603
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>

2 years agocmd/internal/obj/arm64: use more appropriate types for olsr12u
Joel Sing [Sun, 8 Jan 2023 18:22:20 +0000 (05:22 +1100)]
cmd/internal/obj/arm64: use more appropriate types for olsr12u

This allows for a large number of casts to be removed at call sites.

Change-Id: Id929f6c7155b0b59a2bcdf43144de95a007b8a48
Reviewed-on: https://go-review.googlesource.com/c/go/+/461139
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Run-TryBot: Joel Sing <joel@sing.id.au>
Reviewed-by: Eric Fang <eric.fang@arm.com>
2 years agocmd/internal/obj/arm64: invert SP check
Joel Sing [Sat, 7 Jan 2023 15:03:30 +0000 (02:03 +1100)]
cmd/internal/obj/arm64: invert SP check

Check for REGSP use before checking for invalid instructions. This simplifies
the code and avoids duplicated op generation.

Change-Id: I302e3b54a29742f2c48024b25162200f5966cfaa
Reviewed-on: https://go-review.googlesource.com/c/go/+/461138
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Eric Fang <eric.fang@arm.com>
Reviewed-by: Than McIntosh <thanm@google.com>
Run-TryBot: Joel Sing <joel@sing.id.au>
Reviewed-by: Cherry Mui <cherryyz@google.com>
2 years agocmd/internal/obj/arm64: use obj.REG_NONE where appropriate
Joel Sing [Sat, 7 Jan 2023 07:40:56 +0000 (18:40 +1100)]
cmd/internal/obj/arm64: use obj.REG_NONE where appropriate

When referring to an unspecified register, use obj.REG_NONE rather than 0.
This has the same result but is more readable.

Change-Id: I56b541a3abc3c2c0e3ce1de21a624da0b21c485a
Reviewed-on: https://go-review.googlesource.com/c/go/+/461137
Reviewed-by: Eric Fang <eric.fang@arm.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
Run-TryBot: Joel Sing <joel@sing.id.au>
Reviewed-by: Cherry Mui <cherryyz@google.com>
2 years agocmd/internal/obj/arm64: remove bogus omovlit return value check
Joel Sing [Sat, 7 Jan 2023 07:36:38 +0000 (18:36 +1100)]
cmd/internal/obj/arm64: remove bogus omovlit return value check

omovlit never returns zero, so it does not make any sense to check for that.
Additionally, no other call site does this.

Change-Id: I5769dcdb557bed4ec4d727abe0869a1549fcf04c
Reviewed-on: https://go-review.googlesource.com/c/go/+/461136
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Eric Fang <eric.fang@arm.com>
Run-TryBot: Joel Sing <joel@sing.id.au>
TryBot-Result: Gopher Robot <gobot@golang.org>

2 years agocmd/internal/obj/arm64: remove spurious assignments with OR
Joel Sing [Sun, 8 Jan 2023 17:31:47 +0000 (04:31 +1100)]
cmd/internal/obj/arm64: remove spurious assignments with OR

Use = rather than |= when assigning to an op variable.

Change-Id: I142c9fb3aa6f4b48875710100c05ab640e21933a
Reviewed-on: https://go-review.googlesource.com/c/go/+/461135
Reviewed-by: Eric Fang <eric.fang@arm.com>
Reviewed-by: Than McIntosh <thanm@google.com>
Run-TryBot: Joel Sing <joel@sing.id.au>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
2 years agodebug/macho: don't crash if dynamic symtab with no symtab
Ian Lance Taylor [Wed, 22 Feb 2023 21:00:14 +0000 (13:00 -0800)]
debug/macho: don't crash if dynamic symtab with no symtab

No test case because the problem can only happen for invalid data. Let
the fuzzer find cases like this.

For #47653
Fixes #58642

Change-Id: I19fee0dc9bd6239b520c15182b8f1e57bb0049bb
Reviewed-on: https://go-review.googlesource.com/c/go/+/470397
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
2 years agocmd/link: default to external linking with cgo std packages
Cherry Mui [Tue, 21 Feb 2023 22:34:41 +0000 (17:34 -0500)]
cmd/link: default to external linking with cgo std packages

Previously, when a program depends on cgo packages in the standard
library (e.g. net, os/user) but not otherwise use cgo, we default
to internal linking mode. As we shipped pre-built cgo-using packages
in Go distributions, we don't require a C compiler to build those
packages. Then, by using internal linking we can link programs
using those packages without requiring a C toolchain.

As of Go 1.20, we stopped shipping those pre-built packages. If a
user doesn't have a C toolchain, they will use the non-cgo version
of the package. If they have a C toolchain, they can get cgo-using
packages but they can link with the external linker as well. So
there is no strong need to be able to link the cgo version of the
packages without a C toolchain. This CL makes it default to
external linking mode.

Fixes #58619.
Fixes #58620.

Change-Id: I62d3744c2b82ce734813c0e303e417d85dd29868
Reviewed-on: https://go-review.googlesource.com/c/go/+/470298
Run-TryBot: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
2 years agoruntime: use explicit NOFRAME on linux/amd64
qmuntal [Wed, 8 Feb 2023 08:40:44 +0000 (09:40 +0100)]
runtime: use explicit NOFRAME on linux/amd64

This CL marks some linux assembly functions as NOFRAME to avoid relying
on the implicit amd64 NOFRAME heuristic, where NOSPLIT functions
without stack were also marked as NOFRAME.

Updates #58378

Change-Id: I7792cff4f6e539bfa56c02868f2965088ca1975a
Reviewed-on: https://go-review.googlesource.com/c/go/+/466316
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Run-TryBot: Quim Muntal <quimmuntal@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

2 years agonet/http: remove warning when parsing a query containing a semicolon
Damien Neil [Wed, 22 Feb 2023 16:42:37 +0000 (08:42 -0800)]
net/http: remove warning when parsing a query containing a semicolon

It's been years since the behavior here was changed, and there's
little point in continuing to warn users of it.

Fixes #49399

Change-Id: I95f64ca14cacb64ebe78296593b1cc3d837e6b77
Reviewed-on: https://go-review.googlesource.com/c/go/+/470315
Run-TryBot: Damien Neil <dneil@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Filippo Valsorda <filippo@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
2 years agocmd/link: make Exitf panic under -h
Cherry Mui [Wed, 22 Feb 2023 17:09:56 +0000 (12:09 -0500)]
cmd/link: make Exitf panic under -h

If the -h flag is specified, currently it makes Errorf panic, but
not Exitf. Do so for Exitf as well.

Change-Id: I3e8d8899fd439f7299be3f9e9a63993b04852a93
Reviewed-on: https://go-review.googlesource.com/c/go/+/470297
Run-TryBot: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
2 years agosyscall: add jail support to ForkExec on FreeBSD
Harald Böhm [Sun, 27 Nov 2022 14:34:28 +0000 (15:34 +0100)]
syscall: add jail support to ForkExec on FreeBSD

Introduce a new SysProcAttr member called Jail on FreeBSD. This allows
supplying an existing jail's ID to which the child process is attached
before calling the exec system call.

Fixes #46259

Change-Id: Ie282e5b83429131f9a9e1e27cfcb3bcc995d1d4d
Reviewed-on: https://go-review.googlesource.com/c/go/+/458335
Run-TryBot: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Dmitri Goutnik <dgoutnik@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Samuel Karp <samuelkarp@google.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>

2 years agoruntime: improve memclr on ppc64x/power10
Archana R [Mon, 13 Feb 2023 12:18:59 +0000 (06:18 -0600)]
runtime: improve memclr on ppc64x/power10

Rewrite memclr asm function to use the new power10 instruction stxvl
or the store vector with length which can specify the number of bytes
to be stored in a register, thereby avoiding loops to store the tail
end bytes.
On power9 and power8 the code remains unchanged.
The performance for all sizes<16 improve on power10 with this change.

name          old time/op    new time/op     delta
Memclr/1        2.59ns ± 1%     2.80ns ± 9%      ~
Memclr/2        2.77ns ± 0%     2.90ns ± 8%      ~
Memclr/3        3.70ns ± 1%     3.00ns ± 1%   -19.02%
Memclr/4        4.56ns ± 5%     2.98ns ± 1%   -34.56%
Memclr/5        10.1ns ± 8%      2.9ns ± 4%   -70.82%
Memclr/6        6.99ns ± 4%     2.84ns ± 9%   -59.40%
Memclr/7        8.66ns ± 5%     2.92ns ± 4%   -66.27%
Memclr/8        2.75ns ± 1%     2.75ns ± 0%      ~
Memclr/9        3.43ns ± 1%     2.75ns ± 0%   -19.78%
Memclr/10       3.30ns ± 0%     2.77ns ± 0%   -15.81%
Memclr/12       5.09ns ± 0%     2.78ns ± 0%   -45.49%
Memclr/15       9.79ns ± 0%     2.78ns ± 0%   -71.64%
Memclr/16       2.65ns ± 1%     2.77ns ± 0%    +4.77%
GoMemclr/1      2.46ns ± 3%     2.46ns ± 3%      ~
GoMemclr/2      2.91ns ± 0%     2.46ns ± 1%   -15.38%
GoMemclr/3      4.85ns ± 6%     2.45ns ± 1%   -49.50%
GoMemclr/4      5.44ns ± 5%     2.47ns ± 1%   -54.63%
GoMemclr/5      6.48ns ± 0%     2.45ns ± 1%   -62.20%
GoMemclr/6      9.33ns ±20%     2.45ns ± 1%   -73.76%
GoMemclr/7      8.79ns ± 2%     2.46ns ± 1%   -72.03%
GoMemclr/8      2.91ns ± 0%     2.84ns ± 0%    -2.35%
GoMemclr/9      5.04ns ± 0%     2.84ns ± 0%   -43.67%
GoMemclr/10     5.17ns ± 1%     2.84ns ± 0%   -44.99%
GoMemclr/12     6.22ns ± 0%     2.84ns ± 0%   -54.41%
GoMemclr/15     10.1ns ± 0%      2.8ns ± 0%   -72.04%
GoMemclr/16     2.90ns ± 0%     2.92ns ± 0%    +0.83%

Change-Id: I2b7e1a9ceafba11c57c04a2e8cbd12b5ac87ec9b
Reviewed-on: https://go-review.googlesource.com/c/go/+/467635
Reviewed-by: Lynn Boger <laboger@linux.vnet.ibm.com>
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Archana Ravindar <aravind5@in.ibm.com>

2 years agodoc: start draft Go 1.21 release notes
Than McIntosh [Wed, 22 Feb 2023 18:17:30 +0000 (13:17 -0500)]
doc: start draft Go 1.21 release notes

This initial release notes template is based on previous releases.

For #58645.

Change-Id: I8bae25d6dd9778a69963b8b4903a6dc1c180e15f
Reviewed-on: https://go-review.googlesource.com/c/go/+/470296
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2 years agoRevert "internal/poll: drop redundant ENOSYS in CopyFileRange"
Ian Lance Taylor [Tue, 21 Feb 2023 23:00:01 +0000 (23:00 +0000)]
Revert "internal/poll: drop redundant ENOSYS in CopyFileRange"

This reverts CL 428555.

Reason for revert: It appears that even a newer kernel can get
ENOSYS from copy_file_range.

Fixes #58592

Change-Id: Ib8dd1be61544f54bf652a99dc0b449109f8f50ed
Reviewed-on: https://go-review.googlesource.com/c/go/+/470016
Reviewed-by: Andy Pan <panjf2000@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
2 years agotesting: add -fullpath to go test
Hossein Zolfi [Fri, 27 Jan 2023 14:50:09 +0000 (18:20 +0330)]
testing: add -fullpath to go test

When -test.fullpath flag is provided to go test,
go test displays the full file names in error messages.

Fixes #37708

Change-Id: I6096e75ed816fd42205810f20624e495047a73a2
Reviewed-on: https://go-review.googlesource.com/c/go/+/463837
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Bryan Mills <bcmills@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>

2 years agocmd/go: return an early error from queryImport when in vendor mode
rohnnyjoy [Sat, 18 Feb 2023 04:37:17 +0000 (04:37 +0000)]
cmd/go: return an early error from queryImport when in vendor mode

The current behavior for -mod=vendor is to let QueryPackages run and
fail from queryImport: "cannot query module due to -mod=vendor".
This has the side effect of allowing "go: finding module for package"
to be printed to stderr. Instead of this, return an error before
running QueryPackages.

Fixes #58417

Change-Id: Idc0ed33d1dd1bd185348da3a18ba8eb2dd225909
GitHub-Last-Rev: dd09deec0afecabd1bffc34cfe66db0a8c124fd9
GitHub-Pull-Request: golang/go#58471
Reviewed-on: https://go-review.googlesource.com/c/go/+/467517
Run-TryBot: Bryan Mills <bcmills@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
2 years agocmd/link: add internal linking support for calling SDYNIMPORT on mips64
Joel Sing [Mon, 6 Jun 2022 20:08:51 +0000 (06:08 +1000)]
cmd/link: add internal linking support for calling SDYNIMPORT on mips64

Add internal linking support for calling SDYNIMPORT symbols on mips64. This adds
code to generate appropriate PLT and GOT entries, along with the various dynamic
entries needed for the dynamic loader.

Updates #36435, #46178

Change-Id: I783e0d028510ca2bca82bcbc745f2375770813fe
Reviewed-on: https://go-review.googlesource.com/c/go/+/415815
Reviewed-by: Rong Zhang <rongrong@oss.cipunited.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Run-TryBot: Joel Sing <joel@sing.id.au>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Ian Lance Taylor <iant@google.com>

2 years agogo/types, types2: point out type parameters with predeclared names in errors
Robert Griesemer [Tue, 21 Feb 2023 22:42:18 +0000 (14:42 -0800)]
go/types, types2: point out type parameters with predeclared names in errors

If a type parameter has the same name as a predeclared type, error
messages can be very confusing. In these rare cases, explicitly
point out where the type parameter is declared (types2) or that it
is a type parameter (go/types).

(We can't point out where the type parameter is declared in go/types
because we don't have access to the file set in the type writer at
the moment.)

Fixes #58611.

Change-Id: I5c150c2b0afae5fad320821e7e5935090dc2ef4c
Reviewed-on: https://go-review.googlesource.com/c/go/+/470075
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>

2 years agogo/types, types2: avoid unused variable error in invalid x.(type) expression
Robert Griesemer [Tue, 21 Feb 2023 20:51:34 +0000 (12:51 -0800)]
go/types, types2: avoid unused variable error in invalid x.(type) expression

This change removes one of the two follow-on errors in the issue below.

For #58612.

Change-Id: If1eec5031e524bad33caa4a914f52e6a1e273b60
Reviewed-on: https://go-review.googlesource.com/c/go/+/470015
Reviewed-by: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>

2 years agosyscall: introduce IoctlPtr for exec_unix tests
Dmitri Goutnik [Mon, 20 Feb 2023 11:55:42 +0000 (06:55 -0500)]
syscall: introduce IoctlPtr for exec_unix tests

Avoid passing Go pointers as uintptr in exec_unix_test.go by introducing
syscall.IoctlPtr() which accepts arg as unsafe.Pointer.

For #44834
Fixes #58609

Change-Id: I6d0ded023e5f3c9989783aee7075bb88100d9ec2
Reviewed-on: https://go-review.googlesource.com/c/go/+/469675
Run-TryBot: Dmitri Goutnik <dgoutnik@gmail.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>

2 years agodebug/macho: use saferio to read symbol table strings
Ian Lance Taylor [Tue, 21 Feb 2023 18:14:20 +0000 (10:14 -0800)]
debug/macho: use saferio to read symbol table strings

No test case because the problem can only happen for invalid data. Let
the fuzzer find cases like this.

For #47653
Fixes #58603

Change-Id: I67fc45365c1a5b0b4b381f541bf2fee8ce8ddc3a
Reviewed-on: https://go-review.googlesource.com/c/go/+/469895
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>

2 years agoos: use testenv.Command instead of exec.Command in tests
cui fliter [Fri, 18 Nov 2022 06:06:56 +0000 (14:06 +0800)]
os: use testenv.Command instead of exec.Command in tests

testenv.Command sets a default timeout based on the test's deadline
and sends SIGQUIT (where supported) in case of a hang.

Change-Id: I84d469d12ca1f39175b713ca41e7cd2202d11d96
Reviewed-on: https://go-review.googlesource.com/c/go/+/451895
Auto-Submit: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Bryan Mills <bcmills@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
2 years agopath/filepath: document that Clean does not change Windows volume names
Damien Neil [Tue, 21 Feb 2023 19:46:39 +0000 (11:46 -0800)]
path/filepath: document that Clean does not change Windows volume names

Fixes #58348

Change-Id: I4aac0285f11618a45aca6b13c2da2a10a803a9b5
Reviewed-on: https://go-review.googlesource.com/c/go/+/469955
Reviewed-by: Bryan Mills <bcmills@google.com>
Auto-Submit: Damien Neil <dneil@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Damien Neil <dneil@google.com>

2 years agocmd/internal/obj/riscv: optimize loading large immediate with trailing zeros
Wayne Zuo [Tue, 8 Nov 2022 07:39:27 +0000 (15:39 +0800)]
cmd/internal/obj/riscv: optimize loading large immediate with trailing zeros

This CL can avoid a memory load for some immediate.
Reduce binary size slightly.

compilecmp HEAD~1 -> HEAD
HEAD~1 (9860faa512): math/big: remove underscores from Binomial docs
HEAD (ac85312f10): cmd/internal/obj/riscv: optimize loading large immediate with many trailing zeros
platform: linux/riscv64

file      before    after     Δ       %
addr2line 3892904   3889844   -3060   -0.079%
api       5558527   5555073   -3454   -0.062%
asm       5191725   5187853   -3872   -0.075%
buildid   2631958   2629356   -2602   -0.099%
cgo       4722642   4718516   -4126   -0.087%
compile   25579930  25564496  -15434  -0.060%
cover     4989560   4985580   -3980   -0.080%
dist      3538991   3536299   -2692   -0.076%
doc       3990845   3987605   -3240   -0.081%
fix       3410945   3407097   -3848   -0.113%
link      6701702   6697926   -3776   -0.056%
nm        3802030   3798664   -3366   -0.089%
objdump   4211373   4207651   -3722   -0.088%
pack      2423248   2421048   -2200   -0.091%
pprof     14302052  14296714  -5338   -0.037%
test2json 2724359   2721881   -2478   -0.091%
trace     13598607  13590879  -7728   -0.057%
vet       7612108   7607722   -4386   -0.058%
go        15092773  15087323  -5450   -0.036%
total     133976279 133891527 -84752  -0.063%

Change-Id: I8615c7830ebfee0386f95d0c0fc4d29dc0b4c7fb
Reviewed-on: https://go-review.googlesource.com/c/go/+/448635
Reviewed-by: Cherry Mui <cherryyz@google.com>
Run-TryBot: Wayne Zuo <wdvxdr@golangcn.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Pratt <mpratt@google.com>
Reviewed-by: Joel Sing <joel@sing.id.au>
2 years agoruntime: record parent goroutine ID, and print it in stack traces
Nick Ripley [Wed, 28 Sep 2022 18:44:56 +0000 (14:44 -0400)]
runtime: record parent goroutine ID, and print it in stack traces

Fixes #38651

Change-Id: Id46d684ee80e208c018791a06c26f304670ed159
Reviewed-on: https://go-review.googlesource.com/c/go/+/435337
Run-TryBot: Nick Ripley <nick.ripley@datadoghq.com>
Reviewed-by: Ethan Reesor <ethan.reesor@gmail.com>
Auto-Submit: Michael Pratt <mpratt@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

2 years agoRevert "hex: fix panic in Decode when len(src) > 2*len(dst)"
Joe Tsai [Wed, 8 Feb 2023 09:57:25 +0000 (01:57 -0800)]
Revert "hex: fix panic in Decode when len(src) > 2*len(dst)"

This reverts CL 461958 and CL 465855.

Reason for revert: This introduced an irreconcilable inconsistency with Encode

Fixes #58391.

Change-Id: Ifd01a04d433b24c092b73e627b8149a5851c2bca
Reviewed-on: https://go-review.googlesource.com/c/go/+/469615
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Joseph Tsai <joetsai@digital-static.net>
Auto-Submit: Joseph Tsai <joetsai@digital-static.net>
Reviewed-by: Ian Lance Taylor <iant@google.com>
2 years agostrconv: add Atoi test cases with characters less than '0'
Anuraag Agrawal [Mon, 20 Feb 2023 00:38:44 +0000 (00:38 +0000)]
strconv: add Atoi test cases with characters less than '0'

Change-Id: I35c0fe4e7e11b694ef07687d5e0532a2ab9ba213
GitHub-Last-Rev: e0a28f42367c2685d80bcc5c45294c0d2eae77fe
GitHub-Pull-Request: golang/go#58575
Reviewed-on: https://go-review.googlesource.com/c/go/+/469035
Auto-Submit: Robert Griesemer <gri@google.com>
Run-TryBot: Robert Griesemer <gri@google.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
2 years agodoc: add clear builtin to spec
Cuong Manh Le [Mon, 13 Feb 2023 17:10:10 +0000 (00:10 +0700)]
doc: add clear builtin to spec

Fixes #56351

Change-Id: Ia87bf594553b7d0464b591106840f849571c5f39
Reviewed-on: https://go-review.googlesource.com/c/go/+/467755
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Robert Griesemer <gri@google.com>
TryBot-Bypass: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

2 years agodoc: do not use "==" in slice examples
Cuong Manh Le [Fri, 17 Feb 2023 02:20:30 +0000 (09:20 +0700)]
doc: do not use "==" in slice examples

There's no slice comparison in Go.

Change-Id: I5de1766c2adeb56ed12a577a4c46c12b2582b1c8
Reviewed-on: https://go-review.googlesource.com/c/go/+/469015
Reviewed-by: Robert Griesemer <gri@google.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2 years agoruntime/cgo: restore correct build tags for linux/mips*
Joel Sing [Fri, 17 Feb 2023 18:45:34 +0000 (05:45 +1100)]
runtime/cgo: restore correct build tags for linux/mips*

The linux build tags were incorrectly removed from these files by CL 460538.
Restore the correct build tags so that they are only included in builds
for linux/mips* platforms.

Change-Id: I21d8802b0252688d8e2228cf904b47d90b253485
Reviewed-on: https://go-review.googlesource.com/c/go/+/469175
Reviewed-by: Cherry Mui <cherryyz@google.com>
Run-TryBot: Joel Sing <joel@sing.id.au>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
2 years agonet/http: remove five second timeout from TestTransportClosesBodyOnError
Damien Neil [Thu, 26 Jan 2023 21:16:26 +0000 (13:16 -0800)]
net/http: remove five second timeout from TestTransportClosesBodyOnError

Wait forever and let the test time out with a stack trace if the
expected response doesn't happen.

Fixes #57990

Change-Id: I835def63db113752cdd06e03e258cb10d63a6a25
Reviewed-on: https://go-review.googlesource.com/c/go/+/463222
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Damien Neil <dneil@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>