]> Cypherpunks.ru repositories - gostls13.git/log
gostls13.git
13 months agomisc/cgo: gofmt
Ian Lance Taylor [Tue, 4 Apr 2023 20:59:06 +0000 (13:59 -0700)]
misc/cgo: gofmt

Change-Id: I5d02279d0593a8368b2f249a6b53650b89aed7b7
Reviewed-on: https://go-review.googlesource.com/c/go/+/482275
Reviewed-by: David Chase <drchase@google.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Auto-Submit: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>

13 months agocmd/compile: don't inline hot calls into big functions
Michael Pratt [Tue, 28 Mar 2023 16:45:17 +0000 (12:45 -0400)]
cmd/compile: don't inline hot calls into big functions

Standard inlining has a reduced maximum cost of callees (20 instead of
80) when inlining into a "big" function, to limit how much bigger we
will make an already big function.

When adding PGO hot call budget increases, we inadvertently bypassed
this "big" function restriction, allowing hot calls of up to
inlineHotMaxBudget, even into big functions.

Add the restriction back, even for hot calls. If a function is already
very large, we probably shouldn't inline even more.

A very important note here is that function "big"-ness is computed prior
to any inlining. One potential problem with PGO is that many hot calls
inline into an initially-small function and ultimately make it very
large. This CL does nothing to address that case, which would require
recomputing size after inlining.

This CL has no impact on sweet PGO benchmarks. I specifically dug into
tile38, which contained 0 hot big functions. Other benchmarks are
probably similar.

Change-Id: I3b6304eaf7738a219359d4b8bb121d68babfea8b
Reviewed-on: https://go-review.googlesource.com/c/go/+/482157
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Michael Pratt <mpratt@google.com>

13 months agocmd/go: return and handle errors from loadImport for bad imports
Michael Matloob [Mon, 3 Apr 2023 20:07:41 +0000 (16:07 -0400)]
cmd/go: return and handle errors from loadImport for bad imports

And assign the error to the importing package. Before this change, for
some errors for bad imports, such as importing a vendored package with
the wrong path, we would make a dummy package for the imported package
with the error on it. Instead report the error on the importing
package where it belongs. Do so by returning an error from loadImport
and handling it on the importing package.

For #59157

Change-Id: I952e1a82af3857efc5da4fd3f8bc6be473a60cf5
Reviewed-on: https://go-review.googlesource.com/c/go/+/482877
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Michael Matloob <matloob@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>

13 months agoreflect: remove typedmemmovepartial as it is unused
Daniel Martí [Fri, 7 Apr 2023 17:41:10 +0000 (18:41 +0100)]
reflect: remove typedmemmovepartial as it is unused

It appears to have been unused since https://go.dev/cl/298670
in April 2021, as that change removed its only use.
It is always in the git history if it is needed again.

Change-Id: Ie55d059c102dfaa75bd253e09d48a4b30f45e941
Reviewed-on: https://go-review.googlesource.com/c/go/+/483136
Reviewed-by: Michael Pratt <mpratt@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Auto-Submit: Michael Pratt <mpratt@google.com>

13 months agoruntime: support GOTRACEBACK=wer on Windows
qmuntal [Thu, 9 Mar 2023 13:55:31 +0000 (14:55 +0100)]
runtime: support GOTRACEBACK=wer on Windows

GOTRACEBACK=wer is a new traceback level that acts as "crash" and
also enables WER. The same effect can be achieved using
debug.SetTraceback("wer").

The Go runtime currently crashes using exit(2), which bypasses WER
even if it is enabled. To best way to trigger WER is calling
RaiseFailFastException [1] instead, which internally launches the
WER machinery.

This CL also changes how GOTRACEBACK=crash crashes, so both "wer" and
"crash" crash using RaiseFailFastException, which simplifies the
implementation and resolves a longstanding TODO.

Fixes #57441
Fixes #20498

[1] https://learn.microsoft.com/en-us/windows/win32/api/errhandlingapi/nf-errhandlingapi-raisefailfastexception

Change-Id: I45669d619fbbd2f6413ce5e5f08425ed1d9aeb64
Reviewed-on: https://go-review.googlesource.com/c/go/+/474915
Reviewed-by: Davis Goodin <dagood@microsoft.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
Run-TryBot: Quim Muntal <quimmuntal@gmail.com>

14 months agonet: re-enable unixpacket tests on netbsd/386
Tobias Klauser [Sun, 9 Apr 2023 08:31:41 +0000 (10:31 +0200)]
net: re-enable unixpacket tests on netbsd/386

The tests seem to work fine on netbsd/386 (NetBSD 9.3). This reverts CL
80756.

Updates #22927

Change-Id: I2235d69129aa81b43513a171834d058f47cd9933
Reviewed-on: https://go-review.googlesource.com/c/go/+/483395
Reviewed-by: Benny Siegert <bsiegert@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>

14 months agocmd/compile: teach prove about bitwise OR operation
Cuong Manh Le [Mon, 10 Apr 2023 04:08:25 +0000 (11:08 +0700)]
cmd/compile: teach prove about bitwise OR operation

For now, only apply the rule if either of arguments are constants. That
would catch a lot of real user code, without slowing down the compiler
with code generated for string comparison (experience in CL 410336).

Updates #57959
Fixes #45928

Change-Id: Ie2e830d6d0d71cda3947818b22c2775bd94f7971
Reviewed-on: https://go-review.googlesource.com/c/go/+/483359
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Keith Randall <khr@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
14 months agocmd/compile: replace isSigned(t) with t.IsSigned()
Keith Randall [Sun, 9 Apr 2023 15:36:12 +0000 (08:36 -0700)]
cmd/compile: replace isSigned(t) with t.IsSigned()

No change in semantics, just removing an unneeded helper.

Also align rules a bit.

Change-Id: Ie4dabb99392315a7700c645b3d0931eb8766a5fa
Reviewed-on: https://go-review.googlesource.com/c/go/+/483439
Reviewed-by: David Chase <drchase@google.com>
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
14 months agocmd/compile: clean up store rules to use store type, not argument type
Keith Randall [Sun, 9 Apr 2023 15:11:06 +0000 (08:11 -0700)]
cmd/compile: clean up store rules to use store type, not argument type

Argument type is dangerous because it may be thinner than the actual
store being issued.

Change-Id: Id19fbd8e6c41390a453994f897dd5048473136aa
Reviewed-on: https://go-review.googlesource.com/c/go/+/483438
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: David Chase <drchase@google.com>
14 months agocrypto/x509: skip broken darwin root tests
Michael Pratt [Mon, 10 Apr 2023 15:25:06 +0000 (11:25 -0400)]
crypto/x509: skip broken darwin root tests

For #57428.
For #35678.

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

14 months agoruntime: add support for --buildmode=c-shared on loong64
limeidan [Thu, 25 Aug 2022 03:07:25 +0000 (11:07 +0800)]
runtime: add support for --buildmode=c-shared on loong64

These c-shared related CLs are follow up of CLs 455016, 455017, 455018. Here we
follow the LoongArch ELF psABI v2 standard, which requires the support of the
PCALAU12I instruction.

Updates #53301
Updates #58784

Change-Id: I7f1ddbf3b2470d610f12069d147aa9b3a6a96f32
Reviewed-on: https://go-review.googlesource.com/c/go/+/425474
Reviewed-by: abner chenc <chenguoqi@loongson.cn>
Reviewed-by: WANG Xuerui <git@xen0n.name>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

14 months agocmd/internal/obj/loong64, cmd/link/internal: switch to LoongArch ELF psABI v2 relocs
WANG Xuerui [Sat, 3 Dec 2022 13:16:49 +0000 (21:16 +0800)]
cmd/internal/obj/loong64, cmd/link/internal: switch to LoongArch ELF psABI v2 relocs

The LoongArch ELF psABI v2 [1] relocs are vastly simplified from the v1
which involved a stack machine for computing the reloc values, but the
details of PC-relative addressing are changed as well. Specifically, the
`pcaddu12i` instruction is substituted with the `pcalau12i`, which is
like arm64's `adrp` -- meaning the lower bits of a symbol's address now
have to be absolute and not PC-relative.

However, apart from the little bit of added complexity, the obvious
advantage is that only 1 reloc needs to be emitted for every kind of
external reloc we care about. This can mean substantial space savings
(each RELA reloc occupies 24 bytes), and no open-coded stack ops has to
remain any more.

While at it, update the preset value for the output ELF's flags to
indicate the psABI update.

Fixes #58784

[1]: https://loongson.github.io/LoongArch-Documentation/LoongArch-ELF-ABI-EN.html

Change-Id: I5c13bc710eaf58293a32e930dd33feff2ef14c28
Reviewed-on: https://go-review.googlesource.com/c/go/+/455017
Run-TryBot: Ben Shi <powerman1st@163.com>
Reviewed-by: xiaodong liu <teaofmoli@gmail.com>
Reviewed-by: abner chenc <chenguoqi@loongson.cn>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: Meidan Li <limeidan@loongson.cn>
Auto-Submit: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
14 months agocmd/compile, cmd/dist, internal: enable buildmode=pie for linux/loong64
WANG Xuerui [Sun, 4 Dec 2022 07:06:45 +0000 (15:06 +0800)]
cmd/compile, cmd/dist, internal: enable buildmode=pie for linux/loong64

This is actually not tied to the ELF psABI v2 upgrade, and can be
enabled "for free".

Change-Id: I6906d9eb4bd8655c685b059283e200cb7e210369
Reviewed-on: https://go-review.googlesource.com/c/go/+/455075
Reviewed-by: abner chenc <chenguoqi@loongson.cn>
Run-TryBot: Ben Shi <powerman1st@163.com>
Reviewed-by: Meidan Li <limeidan@loongson.cn>
Run-TryBot: WANG Xuerui <git@xen0n.name>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: David Chase <drchase@google.com>
14 months agocmd/compile/internal/amd64: improve fix up code for signed division
Joel Sing [Wed, 5 Apr 2023 20:11:14 +0000 (06:11 +1000)]
cmd/compile/internal/amd64: improve fix up code for signed division

In order to avoid a CPU exception resulting from signed overflow, the signed
division code tests if the divisor is -1 and if it is, runs fix up code to
manually compute the quotient and remainder (thus avoiding IDIV and potential
signed overflow).

However, the way that this is currently structured means that the normal code
path for the case where the divisor is not -1 results in five instructions
and two branches (CMP, JEQ, followed by sign extension, IDIV and another JMP
to skip over the fix up code).

Rework the fix up code such that the final JMP is incurred by the less likely
divisor is -1 code path, rather than more likely code path (which is already
more expensive due to IDIV). This result in a four instruction sequence
(CMP, JNE, sign extension, IDIV), with only a single branch.

Updates #59089

Change-Id: Ie8d065750a178518d7397e194920b201afeb0530
Reviewed-on: https://go-review.googlesource.com/c/go/+/482658
Run-TryBot: Joel Sing <joel@sing.id.au>
Reviewed-by: Keith Randall <khr@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
14 months agocmd/compile/internal/amd64: simplify code generation for signed division
Joel Sing [Wed, 5 Apr 2023 20:11:10 +0000 (06:11 +1000)]
cmd/compile/internal/amd64: simplify code generation for signed division

The same switch statement handles code generation for signed division of
words, double words and quad words. Rather than using multiple switch
statements to select the appropriate instructions, determine all of the
correctly sized operands up front, then use them as needed.

Updates #59089

Change-Id: I2b7567c8e0ecb9904c37607332538c95b0521dca
Reviewed-on: https://go-review.googlesource.com/c/go/+/482657
Run-TryBot: Joel Sing <joel@sing.id.au>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>

14 months agoruntime: mark map bucket slots as empty during map clear
Cuong Manh Le [Tue, 4 Apr 2023 05:49:39 +0000 (12:49 +0700)]
runtime: mark map bucket slots as empty during map clear

So iterators that are in progress can know entries have been deleted and
terminate the iterator properly.

Update #55002
Update #56351
Fixes #59411

Change-Id: I924f16a00fe4ed6564f730a677348a6011d3fb67
Reviewed-on: https://go-review.googlesource.com/c/go/+/481935
Reviewed-by: Keith Randall <khr@golang.org>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Keith Randall <khr@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

14 months agoos: add wasip1 support
Johan Brandhorst-Satzkorn [Sat, 25 Mar 2023 17:18:26 +0000 (10:18 -0700)]
os: add wasip1 support

For #58141

Co-authored-by: Richard Musiol <neelance@gmail.com>
Co-authored-by: Achille Roussel <achille.roussel@gmail.com>
Co-authored-by: Julien Fabre <ju.pryz@gmail.com>
Co-authored-by: Evan Phoenix <evan@phx.io>
Change-Id: I52e3e161f81dcbe8605570e47d732992979c4d34
Reviewed-on: https://go-review.googlesource.com/c/go/+/479623
Run-TryBot: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>

14 months agointernal: add wasip1 support
Johan Brandhorst-Satzkorn [Sat, 25 Mar 2023 16:03:15 +0000 (09:03 -0700)]
internal: add wasip1 support

For #58141

Co-authored-by: Richard Musiol <neelance@gmail.com>
Co-authored-by: Achille Roussel <achille.roussel@gmail.com>
Co-authored-by: Julien Fabre <ju.pryz@gmail.com>
Co-authored-by: Evan Phoenix <evan@phx.io>
Change-Id: I1488726e5b43cd21c5f83900476afd2fb63d70c9
Reviewed-on: https://go-review.googlesource.com/c/go/+/479622
Auto-Submit: Ian Lance Taylor <iant@google.com>
Run-TryBot: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Ian Lance Taylor <iant@google.com>

14 months agoslices: add DeleteFunc
Ian Lance Taylor [Fri, 7 Apr 2023 21:03:55 +0000 (14:03 -0700)]
slices: add DeleteFunc

Fixes #54768

Change-Id: I588ae33c13e0bbd9d324c11771667b22a864047d
Reviewed-on: https://go-review.googlesource.com/c/go/+/483175
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Eli Bendersky <eliben@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>

14 months agocmd/compile: use correct type for byteswaps on multi-byte stores
Keith Randall [Sat, 1 Apr 2023 17:33:26 +0000 (10:33 -0700)]
cmd/compile: use correct type for byteswaps on multi-byte stores

Use the type of the store for the byteswap, not the type of the
store's value argument.

Normally when we're storing a 16-bit value, the value being stored is
also typed as 16 bits. But sometimes it is typed as something smaller,
usually because it is the result of an upcast from a smaller value,
and that upcast needs no instructions.

If the type of the store's arg is thinner than the type being stored,
and the byteswap'd value uses that thinner type, and the byteswap'd
value needs to be spilled & restored, that spill/restore happens using
the thinner type, which causes us to lose some of the top bits of the
value.

Fixes #59367

Change-Id: If6ce1e8a76f18bf8e9d79871b6caa438bc3cce4d
Reviewed-on: https://go-review.googlesource.com/c/go/+/481395
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>

14 months agocmd/compile: minor cleanup to HashDebugPos
David Chase [Thu, 6 Apr 2023 14:09:51 +0000 (10:09 -0400)]
cmd/compile: minor cleanup to HashDebugPos

HashDebugPos function/method included a parameter that was always
the same, and a variable in the same package as the hashdebug code.
So remove it.

(I wrote that code, there was no reason for it to be that way).

Also corrects a stale comment in the loopvar code.

Change-Id: Id3da69cfe6dadeb31d5de62fb76d15103a5d6152
Reviewed-on: https://go-review.googlesource.com/c/go/+/482816
Run-TryBot: David Chase <drchase@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
14 months agocmd/internal/objfile: align the load address of ELF binary
Cherry Mui [Fri, 7 Apr 2023 00:26:55 +0000 (20:26 -0400)]
cmd/internal/objfile: align the load address of ELF binary

The ELF ABI just requires that the address and the offset of a
segment are congruent modulo the alignment, but does not require
the start address to be aligned. While usually the segment's
start address is aligned, apparently the zig linker generates
binary with unaligned address.

At the run time, the memory mapping that contains the segment
starts at an aligned address (rounding down). Use the aligned
address for the load address, which matches the mapping.
Apparently this is what the pprof library expects.

Fixes #59466.

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

14 months agocmd/link: bump loong64 function alignment to 16 bytes
WANG Xuerui [Tue, 4 Apr 2023 08:35:06 +0000 (16:35 +0800)]
cmd/link: bump loong64 function alignment to 16 bytes

The loong64 PCALIGN directive works with PCs relative to beginning of
functions. So if the function alignment is less than that requested by
PCALIGN, the following code may in fact not be aligned as such, leading
to unexpected performance.

The current function alignment on loong64 is 8 bytes, which seems to
stem from mips64 or riscv64. In order to make performance more
predictable on loong64, it is raised to 16 bytes to ensure that at
least `PCALIGN $16` works.

As alignment of loops written in Go is yet to be tackled, and the
codegen is not otherwise touched, benchmark numbers for this change are
not going to be meaningful, and not included.

Change-Id: I2120ef3746ce067e274920c82091810073bfa3be
Reviewed-on: https://go-review.googlesource.com/c/go/+/481936
Auto-Submit: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Run-TryBot: WANG Xuerui <git@xen0n.name>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
14 months agointernal/bytealg, runtime: align some loong64 asm loops to 16-byte boundaries
WANG Xuerui [Tue, 28 Mar 2023 11:58:17 +0000 (19:58 +0800)]
internal/bytealg, runtime: align some loong64 asm loops to 16-byte boundaries

The LA464 micro-architecture is very sensitive to alignment of loops,
so the final performance of linked binaries can vary wildly due to
uncontrolled alignment of certain performance-critical loops. Now that
PCALIGN is available on loong64, let's make use of it and manually align
some assembly loops. The functions are identified based on perf records
of some easily regressed go1 benchmark cases (e.g. FmtFprintfPrefixedInt,
RegexpMatchEasy0_1K and Revcomp are particularly sensitive; even those
optimizations purely reducing dynamic instruction counts can regress
those cases by 6~12%, making the numbers almost useless).

Benchmark results on Loongson 3A5000 (which is an LA464 implementation):

goos: linux
goarch: loong64
pkg: test/bench/go1
                      │  CL 416154  │               this CL               │
                      │   sec/op    │   sec/op     vs base                │
BinaryTree17             14.10 ± 1%    14.10 ± 1%        ~ (p=1.000 n=10)
Fannkuch11               3.672 ± 0%    3.579 ± 0%   -2.53% (p=0.000 n=10)
FmtFprintfEmpty         94.72n ± 0%   94.73n ± 0%   +0.01% (p=0.000 n=10)
FmtFprintfString        149.9n ± 0%   151.9n ± 0%   +1.33% (p=0.000 n=10)
FmtFprintfInt           154.1n ± 0%   158.3n ± 0%   +2.73% (p=0.000 n=10)
FmtFprintfIntInt        236.2n ± 0%   241.4n ± 0%   +2.20% (p=0.000 n=10)
FmtFprintfPrefixedInt   314.2n ± 0%   320.2n ± 0%   +1.91% (p=0.000 n=10)
FmtFprintfFloat         405.0n ± 0%   414.3n ± 0%   +2.30% (p=0.000 n=10)
FmtManyArgs             933.6n ± 0%   949.9n ± 0%   +1.75% (p=0.000 n=10)
GobDecode               15.51m ± 1%   15.24m ± 0%   -1.77% (p=0.000 n=10)
GobEncode               18.42m ± 4%   18.10m ± 2%        ~ (p=0.631 n=10)
Gzip                    423.6m ± 0%   429.9m ± 0%   +1.49% (p=0.000 n=10)
Gunzip                  88.75m ± 0%   88.31m ± 0%   -0.50% (p=0.000 n=10)
HTTPClientServer        85.44µ ± 0%   85.71µ ± 0%   +0.31% (p=0.035 n=10)
JSONEncode              18.65m ± 0%   19.74m ± 0%   +5.81% (p=0.000 n=10)
JSONDecode              77.75m ± 0%   78.60m ± 1%   +1.09% (p=0.000 n=10)
Mandelbrot200           7.214m ± 0%   7.208m ± 0%        ~ (p=0.481 n=10)
GoParse                 7.616m ± 2%   7.616m ± 1%        ~ (p=0.739 n=10)
RegexpMatchEasy0_32     142.9n ± 0%   133.0n ± 0%   -6.93% (p=0.000 n=10)
RegexpMatchEasy0_1K     1.535µ ± 0%   1.362µ ± 0%  -11.27% (p=0.000 n=10)
RegexpMatchEasy1_32     161.8n ± 0%   161.8n ± 0%        ~ (p=0.628 n=10)
RegexpMatchEasy1_1K     1.635µ ± 0%   1.497µ ± 0%   -8.41% (p=0.000 n=10)
RegexpMatchMedium_32    1.429µ ± 0%   1.420µ ± 0%   -0.63% (p=0.000 n=10)
RegexpMatchMedium_1K    41.86µ ± 0%   42.25µ ± 0%   +0.93% (p=0.000 n=10)
RegexpMatchHard_32      2.144µ ± 0%   2.108µ ± 0%   -1.68% (p=0.000 n=10)
RegexpMatchHard_1K      63.83µ ± 0%   62.65µ ± 0%   -1.86% (p=0.000 n=10)
Revcomp                  1.337 ± 0%    1.192 ± 0%  -10.89% (p=0.000 n=10)
Template                116.4m ± 1%   115.6m ± 2%        ~ (p=0.579 n=10)
TimeParse               421.4n ± 2%   418.1n ± 1%   -0.78% (p=0.001 n=10)
TimeFormat              515.1n ± 0%   517.9n ± 0%   +0.54% (p=0.001 n=10)
geomean                 104.5µ        103.5µ        -0.99%

                     │  CL 416154   │               this CL                │
                     │     B/s      │     B/s       vs base                │
GobDecode              47.19Mi ± 1%   48.04Mi ± 0%   +1.80% (p=0.000 n=10)
GobEncode              39.73Mi ± 4%   40.44Mi ± 2%        ~ (p=0.631 n=10)
Gzip                   43.68Mi ± 0%   43.04Mi ± 0%   -1.47% (p=0.000 n=10)
Gunzip                 208.5Mi ± 0%   209.6Mi ± 0%   +0.50% (p=0.000 n=10)
JSONEncode             99.21Mi ± 0%   93.76Mi ± 0%   -5.49% (p=0.000 n=10)
JSONDecode             23.80Mi ± 0%   23.55Mi ± 1%   -1.08% (p=0.000 n=10)
GoParse                7.253Mi ± 2%   7.253Mi ± 1%        ~ (p=0.810 n=10)
RegexpMatchEasy0_32    213.6Mi ± 0%   229.4Mi ± 0%   +7.41% (p=0.000 n=10)
RegexpMatchEasy0_1K    636.3Mi ± 0%   717.3Mi ± 0%  +12.73% (p=0.000 n=10)
RegexpMatchEasy1_32    188.6Mi ± 0%   188.6Mi ± 0%        ~ (p=0.810 n=10)
RegexpMatchEasy1_1K    597.4Mi ± 0%   652.2Mi ± 0%   +9.17% (p=0.000 n=10)
RegexpMatchMedium_32   21.35Mi ± 0%   21.49Mi ± 0%   +0.63% (p=0.000 n=10)
RegexpMatchMedium_1K   23.33Mi ± 0%   23.11Mi ± 0%   -0.94% (p=0.000 n=10)
RegexpMatchHard_32     14.24Mi ± 0%   14.48Mi ± 0%   +1.67% (p=0.000 n=10)
RegexpMatchHard_1K     15.30Mi ± 0%   15.59Mi ± 0%   +1.93% (p=0.000 n=10)
Revcomp                181.3Mi ± 0%   203.4Mi ± 0%  +12.21% (p=0.000 n=10)
Template               15.89Mi ± 1%   16.00Mi ± 2%        ~ (p=0.542 n=10)
geomean                59.33Mi        60.72Mi        +2.33%

Change-Id: I9ac28d936e03d21c46bb19fa100018f61ace6b42
Reviewed-on: https://go-review.googlesource.com/c/go/+/479816
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: WANG Xuerui <git@xen0n.name>
Reviewed-by: Keith Randall <khr@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
14 months agocmd/link, cmd/internal/obj/loong64: support the PCALIGN directive
WANG Xuerui [Tue, 28 Mar 2023 11:30:04 +0000 (19:30 +0800)]
cmd/link, cmd/internal/obj/loong64: support the PCALIGN directive

Allow writing `PCALIGN $imm` where imm is a power-of-2 between 8 and
2048 (inclusive), for ensuring that the following instruction is
placed at an imm-byte boundary relative to the beginning of the
function. If the PC is not sufficiently aligned, NOOPs will be
inserted to make it so, otherwise the directive will do nothing.

This could be useful for both asm performance hand-tuning, and future
scenarios where a certain bigger alignment might be required.

Change-Id: Iad6244669a3d5adea88eceb0dc7be1af4f0d4fc9
Reviewed-on: https://go-review.googlesource.com/c/go/+/479815
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
Run-TryBot: WANG Xuerui <git@xen0n.name>
Auto-Submit: Ian Lance Taylor <iant@golang.org>
Reviewed-by: abner chenc <chenguoqi@loongson.cn>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
14 months agoencoding/xml: use reflect.Value.Grow
Daniel Martí [Fri, 7 Apr 2023 17:21:00 +0000 (18:21 +0100)]
encoding/xml: use reflect.Value.Grow

Like https://go.dev/cl/481376 did for encoding/gob,
but now for encoding/xml, which had very similar code.

One minor difference is that encoding/xml now needs a SetLen before the
call to Index, as otherwise we index just past the length.
Still, calling Grow and SetLen is easier to understand,
and avoids needing to make a new zero value.

goos: linux
goarch: amd64
pkg: encoding/xml
cpu: AMD Ryzen 7 PRO 5850U with Radeon Graphics
│     old     │                new                │
│   sec/op    │   sec/op     vs base              │
Unmarshal-8   6.904µ ± 1%   6.980µ ± 1%  +1.10% (p=0.009 n=6)

│     old      │                new                 │
│     B/op     │     B/op      vs base              │
Unmarshal-8   7.656Ki ± 0%   7.586Ki ± 0%  -0.92% (p=0.002 n=6)

│    old     │               new                │
│ allocs/op  │ allocs/op   vs base              │
Unmarshal-8   188.0 ± 0%   185.0 ± 0%  -1.60% (p=0.002 n=6)

Change-Id: Id83feb467a9c59c80c7936aa892780aae7e8b809
Reviewed-on: https://go-review.googlesource.com/c/go/+/483135
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Ian Lance Taylor <iant@google.com>
14 months agonet/http: expose "http: server gave HTTP response to HTTPS client" error
Akihiro Suda [Fri, 7 Apr 2023 01:19:21 +0000 (01:19 +0000)]
net/http: expose "http: server gave HTTP response to HTTPS client" error

Expose "http: server gave HTTP response to HTTPS client" error as `ErrSchemeMismatch`, so that it can be compared with `errors.Is` .

Fixes #44855

Change-Id: If96e0d000fdef641fea407310faf9e1c4f7ad0f0
GitHub-Last-Rev: 22879fc88367d77817d7d96c9164f22e55f3a192
GitHub-Pull-Request: golang/go#50939
Reviewed-on: https://go-review.googlesource.com/c/go/+/382117
Run-TryBot: Damien Neil <dneil@google.com>
Auto-Submit: Damien Neil <dneil@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
14 months agocmd/compile: remove broken LEA "optimization"
David Chase [Thu, 6 Apr 2023 18:42:53 +0000 (14:42 -0400)]
cmd/compile: remove broken LEA "optimization"

CL 440035 added rewrite rules to simplify "costly" LEA
instructions, but the types in the rewrites were wrong and
the code would go bad if the wrong-typed register was spilled.

CL 482536 attempted to fix this by correcting the type in the
rewrite, but that "fix" broke something on windows-amd64-race.

Instead / for-now, remove the offending rewrite rules.

Updates #21735.
Fixes #59432.

Change-Id: I0497c42db414f2055e1378e0a53e2bceee9cd5d9
Reviewed-on: https://go-review.googlesource.com/c/go/+/482820
Run-TryBot: David Chase <drchase@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

14 months agonet/http: wait forever for write results in tests
Damien Neil [Fri, 7 Apr 2023 17:04:42 +0000 (10:04 -0700)]
net/http: wait forever for write results in tests

After performing a round trip on a connection, the connection is
usually returned to the idle connection pool. If the write of the
request did not complete successfully, the connection is not
returned.

It is possible for the response to be read before the write
goroutine has finished signalling that its write has completed.
To allow for this, the check to see if the write completed successfully
waits for 50ms for the write goroutine to report the result of the
write.

See comments in persistConn.wroteRequest for more details.

On a slow builder, it is possible for the write goroutine to take
longer than 50ms to report the status of its write, leading to test
flakiness when successive requests unexpectedly use different connections.

Set the timeout for waiting for the writer to an effectively
infinite duration in tests.

Fixes #51147
Fixes #56275
Fixes #56419
Fixes #56577
Fixes #57375
Fixes #57417
Fixes #57476
Fixes #57604
Fixes #57605

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

14 months agonet/http: fix a race in TestResponseControllerSetPastReadDeadline
Bryan C. Mills [Fri, 7 Apr 2023 15:37:18 +0000 (15:37 +0000)]
net/http: fix a race in TestResponseControllerSetPastReadDeadline

If the Write goroutine is delayed for long enough after its first
Write, the handler may have closed both the readc and donec channels
by the time it selects over them, and the donec case may be randomly
chosen. Handle that case by explicitly checking readc as well.

This fixes a race accidentally introduced in CL 482935 and observed in
https://build.golang.org/log/fa684750994d1fda409722f144b90c65b4c52cf9.

For #59447.

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

14 months agocmd/compile: allow more inlining of functions that construct closures
Than McIntosh [Tue, 4 Apr 2023 22:31:46 +0000 (18:31 -0400)]
cmd/compile: allow more inlining of functions that construct closures

[This is a roll-forward of CL 479095, which was reverted due to a bad
interaction between inlining and escape analysis since fixed in CL 482355.]

Currently, when the inliner is determining if a function is
inlineable, it descends into the bodies of closures constructed by
that function. This has several unfortunate consequences:

- If the closure contains a disallowed operation (e.g., a defer), then
  the outer function can't be inlined. It makes sense that the
  *closure* can't be inlined in this case, but it doesn't make sense
  to punish the function that constructs the closure.

- The hairiness of the closure counts against the inlining budget of
  the outer function. Since we currently copy the closure body when
  inlining the outer function, this makes sense from the perspective
  of export data size and binary size, but ultimately doesn't make
  much sense from the perspective of what should be inlineable.

- Since the inliner walks into every closure created by an outer
  function in addition to starting a walk at every closure, this adds
  an n^2 factor to inlinability analysis.

This CL simply drops this behavior.

In std, this makes 57 more functions inlinable, and disallows inlining
for 10 (due to the basic instability of our bottom-up inlining
approach), for an net increase of 47 inlinable functions (+0.6%).

This will help significantly with the performance of the functions to
be added for #56102, which have a somewhat complicated nesting of
closures with a performance-critical fast path.

The downside of this seems to be a potential increase in export data
and text size, but the practical impact of this seems to be
negligible:

       │    before    │           after            │
       │    bytes     │    bytes      vs base      │
Go/binary        15.12Mi ± 0%   15.14Mi ± 0%  +0.16% (n=1)
Go/text          5.220Mi ± 0%   5.237Mi ± 0%  +0.32% (n=1)
Compile/binary   22.92Mi ± 0%   22.94Mi ± 0%  +0.07% (n=1)
Compile/text     8.428Mi ± 0%   8.435Mi ± 0%  +0.08% (n=1)

Updates #56102.

Change-Id: I1f4fc96c71609c8feb59fecdb92b69ba7e3b5b41
Reviewed-on: https://go-review.googlesource.com/c/go/+/482356
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Than McIntosh <thanm@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

14 months agocmd/compile: deadcode unreferenced hidden closures during inlining
Than McIntosh [Tue, 4 Apr 2023 22:56:21 +0000 (18:56 -0400)]
cmd/compile: deadcode unreferenced hidden closures during inlining

When a closure is inlined, it may contain other hidden closures, which
the inliner will duplicate, rendering the original nested closures as
unreachable. Because they are unreachable, they don't get processed in
escape analysis, meaning that go/defer statements don't get rewritten,
which can then in turn trigger errors in walk. This patch looks for
nested hidden closures and marks them as dead, so that they can be
skipped later on in the compilation flow.  NB: if during escape
analysis we rediscover a hidden closure (due to an explicit reference)
that was previously marked dead, revive it at that point.

Fixes #59404.

Change-Id: I76db1e9cf1ee38bd1147aeae823f916dbbbf081b
Reviewed-on: https://go-review.googlesource.com/c/go/+/482355
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Than McIntosh <thanm@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
14 months agoruntime: permit core dumps in darwin-amd64
Ian Lance Taylor [Thu, 6 Apr 2023 23:38:47 +0000 (16:38 -0700)]
runtime: permit core dumps in darwin-amd64

Previously we did not permit them as Go programs generated enormous
core dumps on macOS. However, according to an investigation in #59446,
they are OK now.

For #59446

Change-Id: I1d7a3f500a6bc525aa6de8dfa8a1d8dbb15feadc
Reviewed-on: https://go-review.googlesource.com/c/go/+/483015
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
14 months agocmd/link/internal/ppc64: generate PCrel trampolines on P10
Paul E. Murphy [Tue, 10 Jan 2023 21:14:46 +0000 (15:14 -0600)]
cmd/link/internal/ppc64: generate PCrel trampolines on P10

PCrelative trampolines have no dependence on the TOC pointer or build
mode, thus they are preferable to use when supported.

This is a step towards eliminating the need to use and maintain the
TOC pointer in R2 when PCrel is supported.

Change-Id: I1b1a7e16831cfd6732b31f7fad8df2a7c88c8f84
Reviewed-on: https://go-review.googlesource.com/c/go/+/461599
Reviewed-by: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Run-TryBot: Paul Murphy <murp@ibm.com>

14 months agocmd/link/internal/ld: don't set IMAGE_FILE_DEBUG_STRIPPED on PE binaries
qmuntal [Mon, 3 Apr 2023 08:01:43 +0000 (10:01 +0200)]
cmd/link/internal/ld: don't set IMAGE_FILE_DEBUG_STRIPPED on PE binaries

The IMAGE_FILE_DEBUG_STRIPPED characteristic is used to inform that
the debugging information have been removed from the PE files and moved
into a DBG file, but the Go linker doesn't generate DBG files.

Having this characteristic can confuse debugging tools, so better
don't set it.

While here, remove also IMAGE_FILE_LINE_NUMS_STRIPPED, which is
deprecated and should be zero [1].

Fixes #59391

[1] https://learn.microsoft.com/en-us/windows/win32/debug/pe-format#characteristics

Change-Id: Ia6b1dc3353bfa292a17c4bef17c9bac8dc95189a
Reviewed-on: https://go-review.googlesource.com/c/go/+/481615
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
Run-TryBot: Quim Muntal <quimmuntal@gmail.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
14 months agocmd/compile: get more bounds info from logic operators in prove pass
ruinan [Tue, 12 Jul 2022 04:05:41 +0000 (04:05 +0000)]
cmd/compile: get more bounds info from logic operators in prove pass

Currently, the prove pass can get knowledge from some specific logic
operators only before the CFG is explored, which means that the bounds
information of the branch will be ignored.

This CL updates the facts table by the logic operators in every
branch. Combined with the branch information, this will be helpful for
BCE in some circumstances.

Fixes #57243

Change-Id: I0bd164f1b47804ccfc37879abe9788740b016fd5
Reviewed-on: https://go-review.googlesource.com/c/go/+/419555
Reviewed-by: Keith Randall <khr@golang.org>
Run-TryBot: Eric Fang <eric.fang@arm.com>
Reviewed-by: Keith Randall <khr@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
14 months agoruntime: correct GoCheckBindM's C declaration in EnsureBindM test
Cherry Mui [Thu, 6 Apr 2023 21:36:05 +0000 (17:36 -0400)]
runtime: correct GoCheckBindM's C declaration in EnsureBindM test

The test file has a C declaration which doesn't match the actual
definition. Remove it and include "_cgo_export.h" to have the
right declaration.

Change-Id: Iddf6d8883ee0e439147c7027029dd3e352ef090d
Reviewed-on: https://go-review.googlesource.com/c/go/+/482975
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Cherry Mui <cherryyz@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
14 months agocmd: add wasip1 support
Johan Brandhorst-Satzkorn [Sat, 25 Mar 2023 15:50:19 +0000 (08:50 -0700)]
cmd: add wasip1 support

For #58141

Co-authored-by: Richard Musiol <neelance@gmail.com>
Co-authored-by: Achille Roussel <achille.roussel@gmail.com>
Co-authored-by: Julien Fabre <ju.pryz@gmail.com>
Co-authored-by: Evan Phoenix <evan@phx.io>
Change-Id: I530ea78a3cd142f3a745f650b21c30e7f10ce981
Reviewed-on: https://go-review.googlesource.com/c/go/+/479621
Reviewed-by: Bryan Mills <bcmills@google.com>
Auto-Submit: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
14 months agocmd/go: improve packages help description
Oleksandr Redko [Wed, 5 Apr 2023 10:07:14 +0000 (13:07 +0300)]
cmd/go: improve packages help description

Clarify that 'action' is not the valid 'go' command.

Change-Id: I0a77722c46a3dc56f81c5e6e177e0c73bc60adc2
Reviewed-on: https://go-review.googlesource.com/c/go/+/482455
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
14 months agonet/http: improve failure mode for TestResponseControllerSetPastReadDeadline
Damien Neil [Thu, 6 Apr 2023 19:09:04 +0000 (12:09 -0700)]
net/http: improve failure mode for TestResponseControllerSetPastReadDeadline

A test flake in #59447 seems to indicate that this test got stuck
waiting for the test handler to close the readc channel.
If the handler returns early due to an unexpected error, it might
fail to close this channel. Add a second channel to act as a
signal that the handler has given up and the test should stop.
This won't fix whatever happened in the flake, but might help
us debug it if it happens again.

For #59447

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

14 months agomisc/wasm: add wasip1/wasm exec script
Johan Brandhorst-Satzkorn [Sat, 25 Mar 2023 15:48:03 +0000 (08:48 -0700)]
misc/wasm: add wasip1/wasm exec script

This script uses Wazero, the open source, zero dependencies
pure Go Wasm and WASI runtime. This is the runtime that allows
the greatest number of standard library tests to pass.

For #58141

Co-authored-by: Richard Musiol <neelance@gmail.com>
Co-authored-by: Achille Roussel <achille.roussel@gmail.com>
Co-authored-by: Julien Fabre <ju.pryz@gmail.com>
Co-authored-by: Evan Phoenix <evan@phx.io>
Change-Id: I789465ae4daf2b380f3c05a9365b8d449c6af56c
Reviewed-on: https://go-review.googlesource.com/c/go/+/479620
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
14 months agosyscall: add remaining wasip1 files
Johan Brandhorst-Satzkorn [Sat, 25 Mar 2023 06:16:43 +0000 (23:16 -0700)]
syscall: add remaining wasip1 files

Implements filesystem, networking and os interactions.

For #58141

Co-authored-by: Richard Musiol <neelance@gmail.com>
Co-authored-by: Achille Roussel <achille.roussel@gmail.com>
Co-authored-by: Julien Fabre <ju.pryz@gmail.com>
Co-authored-by: Evan Phoenix <evan@phx.io>
Change-Id: If5c43ad5bd2955e6d2d4e2822fd68bce89ca786c
Reviewed-on: https://go-review.googlesource.com/c/go/+/479619
Reviewed-by: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>

14 months agocmd/go/internal/modfetch/codehost: set core.longpaths in Git repos on Windows
Bryan C. Mills [Thu, 6 Apr 2023 18:40:51 +0000 (18:40 +0000)]
cmd/go/internal/modfetch/codehost: set core.longpaths in Git repos on Windows

This setting appears to be needed to avoid “Filename too long” errors
when downloading modules from repos with long branch names,
particularly if the path to the module cache is already fairly long
(as may be the case in CI systems and in tests of cmd/go itself).

Change-Id: I3aa89ea872b29eb0460c8a8afc94f182a68982fd
Reviewed-on: https://go-review.googlesource.com/c/go/+/482819
Reviewed-by: Russ Cox <rsc@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

14 months agogo/scanner: align line and column limit with the compiler's limit
Damien Neil [Wed, 5 Apr 2023 16:28:00 +0000 (09:28 -0700)]
go/scanner: align line and column limit with the compiler's limit

The compiler disallows line and column numbers > (1<<30)
(cmd/compiler/internal/syntax.PosMax).

Set the go/scanner limit to the same rather than off by one.

For #59180

Change-Id: Ibf9e0e6826d6f6230b0d492543b7e906298a0524
Reviewed-on: https://go-review.googlesource.com/c/go/+/482595
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Damien Neil <dneil@google.com>

14 months agonet/http: add tests covering non-GET methods for file serving
Damien Neil [Thu, 6 Apr 2023 18:01:05 +0000 (11:01 -0700)]
net/http: add tests covering non-GET methods for file serving

ServeFile and FileServer will respond to methods such as DELETE by
serving the file contents. This is surprising, but we don't want to
change it without some consideration.

Add tests covering the current behavior.

For #59470

Change-Id: Ib6a2594c5b2b7f380149fc1628f7204b308161e1
Reviewed-on: https://go-review.googlesource.com/c/go/+/482876
Run-TryBot: Damien Neil <dneil@google.com>
Reviewed-by: Tatiana Bradley <tatianabradley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

14 months agoRevert "cmd/compile: use correct type in amd64 late-lower rules"
David Chase [Thu, 6 Apr 2023 17:03:24 +0000 (17:03 +0000)]
Revert "cmd/compile: use correct type in amd64 late-lower rules"

This reverts CL 482536.

Reason for revert: breaks windows-amd64-race

Change-Id: I033c52fe0d6bbbc879ed2a33d91fb1357f4874bc
Reviewed-on: https://go-review.googlesource.com/c/go/+/482817
Reviewed-by: Cherry Mui <cherryyz@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
14 months agocmd/go: fix tests for new builder environment
Heschi Kreinick [Wed, 29 Mar 2023 17:13:19 +0000 (13:13 -0400)]
cmd/go: fix tests for new builder environment

Fix two long tests that fail in the builders we're trying out:

- TestQueryImport was failing with:
  open /nonexist-gopath/pkg/sumdb/sum.golang.org/latest: no such file or directory
  which eventually turns out to be because it couldn't create
  /nonexist-gopath because it wasn't running as root. The test already
  uses a temporary GOPATH, but missed overriding a configuration
  variable set at init time.
- test_flags fails if the working directory has /x/ in it, which it now
  happens to.

Change-Id: Ideef0f318157b42987539e3a20f9fba6a3d3bdd0
Reviewed-on: https://go-review.googlesource.com/c/go/+/480255
Run-TryBot: Heschi Kreinick <heschi@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

14 months agoruntime: add remaining wasip1 files
Johan Brandhorst-Satzkorn [Sat, 25 Mar 2023 06:11:55 +0000 (23:11 -0700)]
runtime: add remaining wasip1 files

Implements OS interactions and memory management.

For #58141

Co-authored-by: Richard Musiol <neelance@gmail.com>
Co-authored-by: Achille Roussel <achille.roussel@gmail.com>
Co-authored-by: Julien Fabre <ju.pryz@gmail.com>
Co-authored-by: Evan Phoenix <evan@phx.io>
Change-Id: I876e7b033090c2fe2d76d2535bb63d52efa36185
Reviewed-on: https://go-review.googlesource.com/c/go/+/479618
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
Auto-Submit: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>

14 months agoRevert "net/http: FileServer method check + minimal OPTIONS implementation"
Damien Neil [Wed, 5 Apr 2023 17:19:44 +0000 (10:19 -0700)]
Revert "net/http: FileServer method check + minimal OPTIONS implementation"

This reverts https://go.dev/cl/413554

Reason for revert: Backwards-incompatible change in behavior.

For #53501
For #59375

Change-Id: Ic3f63b378f9c819599b32e5e6e410f6163849317
Reviewed-on: https://go-review.googlesource.com/c/go/+/482635
Reviewed-by: Tatiana Bradley <tatianabradley@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

14 months agoruntime: fix typo in traceback.go
Kaiya [Thu, 6 Apr 2023 07:01:34 +0000 (15:01 +0800)]
runtime: fix typo in traceback.go

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

14 months agocmd/compile: modify debug-hash to support match exclusion
David Chase [Fri, 31 Mar 2023 21:26:04 +0000 (17:26 -0400)]
cmd/compile: modify debug-hash to support match exclusion

The goal here is to enable a search that will locate all the instances
of a failure, not just the first one.  This helps with searches for
loopvar-change breakage, FP differences from fused-multiply-add, and
allows certain semantics queries that can be implemented as compiler
changes (for example, where does integer overflow routinely occur?)

Change-Id: Ic28f1695d47e421c2089d1f3f7c4b40c56db970f
Reviewed-on: https://go-review.googlesource.com/c/go/+/481195
Run-TryBot: David Chase <drchase@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

14 months agocmd/compile: use correct type in amd64 late-lower rules
David Chase [Wed, 5 Apr 2023 19:49:07 +0000 (15:49 -0400)]
cmd/compile: use correct type in amd64 late-lower rules

The wrong type causes the wrong width spill, which corrupts
the value.  I tried to write a test for this and did not
succeed, but was able (using gossahash and ssa.html) to
isolate to exact change and spill.

Fixes #59432.

Change-Id: I85ad82c9f8fed7674c69d6a2b0a62e111f690454
Reviewed-on: https://go-review.googlesource.com/c/go/+/482536
Reviewed-by: Cherry Mui <cherryyz@google.com>
Run-TryBot: David Chase <drchase@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

14 months agoruntime: flush each idle P's page cache at the end of each GC cycle
Michael Anthony Knyszek [Mon, 28 Nov 2022 19:53:20 +0000 (19:53 +0000)]
runtime: flush each idle P's page cache at the end of each GC cycle

Currently pages may linger in an idle P's page cache, hiding the memory
from the scavenger precisely when it's useful to return memory to the OS
and reduce the application's footprint.

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

14 months agoruntime: initialize the memory limit in mallocinit
Michael Anthony Knyszek [Fri, 11 Nov 2022 22:16:20 +0000 (22:16 +0000)]
runtime: initialize the memory limit in mallocinit

Currently the memory limit is left uninitialized before gcinit, and
allocations may happen. The result is that the span allocation path
might try to scavenge memory unnecessarily. Prevent this by setting the
memory limit up early to its default value.

Change-Id: I886d9a8fa645861e4f88e0d54af793418426f520
Reviewed-on: https://go-review.googlesource.com/c/go/+/450736
Run-TryBot: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
14 months agoruntime: add sysNoHugePage
Michael Anthony Knyszek [Wed, 2 Nov 2022 16:47:09 +0000 (16:47 +0000)]
runtime: add sysNoHugePage

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

14 months agocmd/internal/obj: generate SEH aux symbols for windows/amd64
qmuntal [Mon, 16 Jan 2023 15:21:48 +0000 (16:21 +0100)]
cmd/internal/obj: generate SEH aux symbols for windows/amd64

This CL updates the Go compiler so it generate SEH unwind info [1] as a
function auxiliary symbol when building for windows/amd64.

A follow up CL will teach the Go linker how to assemble these codes
into the PE .xdata section.

Updates #57302

[1] https://learn.microsoft.com/en-us/cpp/build/exception-handling-x64#struct-unwind_info

Change-Id: I40ae0437bfee326c1a67c2b5e1496f0bf3ecea17
Reviewed-on: https://go-review.googlesource.com/c/go/+/461749
Reviewed-by: Davis Goodin <dagood@microsoft.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
Run-TryBot: Quim Muntal <quimmuntal@gmail.com>

14 months agocmd/internal/obj/arm64: use more appropriate types for olsr9s/olsr12u
Joel Sing [Mon, 27 Feb 2023 07:39:09 +0000 (18:39 +1100)]
cmd/internal/obj/arm64: use more appropriate types for olsr9s/olsr12u

This allows for a large number of casts to be removed at call sites.
While here, use consistent register naming.

Change-Id: I78a2a928b78c9f09f91fb6ed6ad440aa4e63923d
Reviewed-on: https://go-review.googlesource.com/c/go/+/471517
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Run-TryBot: Joel Sing <joel@sing.id.au>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
14 months agocmd/internal/obj/arm64: use more appropriate types for opldpstp
Joel Sing [Sun, 26 Feb 2023 19:03:31 +0000 (06:03 +1100)]
cmd/internal/obj/arm64: use more appropriate types for opldpstp

This allows for a large number of casts to be removed at call sites.
While here, use consistent register naming.

Change-Id: I68cee985f6500ed9523f7fb3efbc11bb849681dc
Reviewed-on: https://go-review.googlesource.com/c/go/+/471516
Reviewed-by: Cherry Mui <cherryyz@google.com>
Run-TryBot: Joel Sing <joel@sing.id.au>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
14 months agocmd/internal/obj/arm64: use more appropriate types for opbfm and opextr
Joel Sing [Sun, 26 Feb 2023 18:52:04 +0000 (05:52 +1100)]
cmd/internal/obj/arm64: use more appropriate types for opbfm and opextr

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

Change-Id: I44a162040cc5b4de02e106d3a6de10f8e0870cb9
Reviewed-on: https://go-review.googlesource.com/c/go/+/471515
Run-TryBot: Joel Sing <joel@sing.id.au>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
14 months agoall: add wasip1 asm and link logic
Johan Brandhorst-Satzkorn [Sat, 25 Mar 2023 06:07:58 +0000 (23:07 -0700)]
all: add wasip1 asm and link logic

Add wasip1 asm and symbols to cmd/internal/obj, cmd/link and
runtime.

For #58141

Co-authored-by: Richard Musiol <neelance@gmail.com>
Co-authored-by: Achille Roussel <achille.roussel@gmail.com>
Co-authored-by: Julien Fabre <ju.pryz@gmail.com>
Co-authored-by: Evan Phoenix <evan@phx.io>
Change-Id: Ie088d9b65ea13e231694af6341465f95be33093f
Reviewed-on: https://go-review.googlesource.com/c/go/+/479617
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Bypass: Ian Lance Taylor <iant@golang.org>
Auto-Submit: Ian Lance Taylor <iant@golang.org>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>

14 months agoruntime: save frame pointer to the stack in signal handlers for arm64
Nick Ripley [Mon, 3 Apr 2023 13:54:53 +0000 (09:54 -0400)]
runtime: save frame pointer to the stack in signal handlers for arm64

When taking over the goroutine stack in the panic or preemption signal
handlers on arm64, the frame pointer should be saved on the stack (like
the link register) so that frame-pointer unwinding from a panic stack
works properly. Otherwise, tests like TestStackWrapperStackPanic will
fail with the frame pointer check in adjustframe (enabled with
debugCheckBP) when checking the sigpanic frame.

Updates #39524, #58432

Change-Id: I8b89e6fc4877af29b1b81e55e591e6398159855c
Reviewed-on: https://go-review.googlesource.com/c/go/+/481635
Reviewed-by: Felix Geisendörfer <felix.geisendoerfer@datadoghq.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Nick Ripley <nick.ripley@datadoghq.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
14 months agoruntime: remove unused dynamically imported Sleep
qmuntal [Wed, 5 Apr 2023 07:28:49 +0000 (09:28 +0200)]
runtime: remove unused dynamically imported Sleep

Sleep is not used, it can be removed.

Change-Id: I237c966eb9b4e91127091d78f0b86725139c77a7
Reviewed-on: https://go-review.googlesource.com/c/go/+/482435
Run-TryBot: Quim Muntal <quimmuntal@gmail.com>
Auto-Submit: Quim Muntal <quimmuntal@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
14 months agocmd/compile: don't set range expr key/value type if already set
Cuong Manh Le [Mon, 3 Apr 2023 04:18:45 +0000 (11:18 +0700)]
cmd/compile: don't set range expr key/value type if already set

Unified IR already records the correct type for them.

Fixes #59378

Change-Id: I275c45b48f67bde55c8e2079d60b5868d0acde7f
Reviewed-on: https://go-review.googlesource.com/c/go/+/481555
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
14 months agocontext: clean up test files
Sameer Ajmani [Wed, 29 Mar 2023 21:47:50 +0000 (17:47 -0400)]
context: clean up test files

Tests in package context cannot depend directly on package testing due to an import cycle.
We resolved this by having test functions in package context_test (x_test.go) forward to
test functions in package context (context_test.go). This is fragile, since it's easy
to add a test to context_test.go and forget to add the forwarding function, and tests
written in this way cannot easily use testing package features like t.Run for subtests.

It turns out that only four test functions actually use unexported members of package
context. This CL moves all except those four to x_test.go and makes them regular tests.
It also updates TestCause to use t.Run and t.Parallel to parallelize its test cases.
It also adds documentation indicating when tests should be added to each file.

Change-Id: Ic60bae32a7a44e07831b5388c9af219d53ba9af3
Reviewed-on: https://go-review.googlesource.com/c/go/+/480375
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Sameer Ajmani <sameer@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Damien Neil <dneil@google.com>
14 months agohtml/template,mime/multipart: document new GODEBUG settings
Michael Anthony Knyszek [Tue, 4 Apr 2023 22:07:09 +0000 (22:07 +0000)]
html/template,mime/multipart: document new GODEBUG settings

This change documents the new GODEBUG settings introduced for
html/template and mime/multipart, released with Go 1.19.8 and Go 1.20.3
as part of a security fix.

Updates #59153.
Updates #59234.

Change-Id: I25f4d8245da3301dccccfb44da8ff1a5985392a4
Reviewed-on: https://go-review.googlesource.com/c/go/+/482238
Auto-Submit: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

14 months agoarchive/zip: return ErrInsecurePath for unsafe paths by OpenReader
Imre Rad [Tue, 7 Mar 2023 16:31:13 +0000 (16:31 +0000)]
archive/zip: return ErrInsecurePath for unsafe paths by OpenReader

zip.NewReader was recently improved to return ErrInsecurePath when
insecure entries are encountered.
This change adopts the same logic for the OpenReader interface as well.

Fixes #58641

Change-Id: I0d8be94d073cc14cf93a914dc250f85b19cec4ab
GitHub-Last-Rev: 68391dc51562aebc893ec70fdfbdfb181955983a
GitHub-Pull-Request: golang/go#58658
Reviewed-on: https://go-review.googlesource.com/c/go/+/470735
Run-TryBot: Damien Neil <dneil@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Auto-Submit: Damien Neil <dneil@google.com>

14 months agointernal/syscall/unix: fix PosixFallocate error check on freebsd
Tobias Klauser [Wed, 5 Apr 2023 11:16:58 +0000 (13:16 +0200)]
internal/syscall/unix: fix PosixFallocate error check on freebsd

The posix_fallocate syscall returns the result in r1 rather than in
errno:

> If successful, posix_fallocate() returns zero. It returns an error on failure, without
> setting errno.

Source: https://man.freebsd.org/cgi/man.cgi?query=posix_fallocate&sektion=2&n=1

Adjust the PosixFallocate wrappers on freebsd to account for that.

Also, CL 479715 used the same syscall wrapper for 386 and arm. However,
on arm the syscall argument order is different. The wrapper was
generated using mksyscall.go from the golang.org/x/sys/unix package,
adjusting the r1 check correspondingly.

Fixes #59352

Change-Id: I9a4e8e4546237010bc5e730c4988a2a476264cf4
Reviewed-on: https://go-review.googlesource.com/c/go/+/481621
Reviewed-by: Cherry Mui <cherryyz@google.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Yuval Pavel Zholkover <paulzhol@gmail.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

14 months agocmd/dist: skip static linking tests for linux boringcrypto
Ian Lance Taylor [Tue, 4 Apr 2023 21:43:46 +0000 (14:43 -0700)]
cmd/dist: skip static linking tests for linux boringcrypto

Otherwise we get warnings from the C linker.

Fixes #59422

Change-Id: I61843dbe5245da0185b0f23dc4b774767fffed40
Reviewed-on: https://go-review.googlesource.com/c/go/+/482315
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Auto-Submit: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
14 months agonet/http: drop client address comparison in TestTransportRemovesDeadIdleConnections
Bryan C. Mills [Tue, 4 Apr 2023 18:49:23 +0000 (14:49 -0400)]
net/http: drop client address comparison in TestTransportRemovesDeadIdleConnections

Since the first client connection is explicitly closed before making
the second request, we cannot in general assume that the second
request uses a different port (it is equally valid to open the new
connection on the same port as the old one that was closed).

Fixes #59438.

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

14 months agocmd/go: suppress calls to collectDeps for test packages
Bryan C. Mills [Mon, 3 Apr 2023 21:02:49 +0000 (17:02 -0400)]
cmd/go: suppress calls to collectDeps for test packages

Instead, do the cycle checking in recompileForTest once the test
variant packages have been poked in the right places in the dependency
tree(graph?).

(Pair programming with bcmills@.)

For #59157.

Change-Id: I0c644cb9f2c0dac3a5b0189e2aa0eef083c669f6
Reviewed-on: https://go-review.googlesource.com/c/go/+/482237
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
Run-TryBot: Michael Matloob <matloob@golang.org>

14 months agogo/internal/gcimporter: use saferio.ReadData instead of io.ReadAll when possible
Lasse Folger [Mon, 3 Apr 2023 11:52:56 +0000 (13:52 +0200)]
go/internal/gcimporter: use saferio.ReadData instead of io.ReadAll when possible

saferio.ReadData avoids unnecessary allocations because the buffer can be
preallocated with the right size (up to a limit) instead of having to resize
and copy it step by step.

Change-Id: Id70f6908971d4f126c601a9571ac3c67ea0accdc
Reviewed-on: https://go-review.googlesource.com/c/go/+/481616
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Auto-Submit: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
14 months agoencoding/binary: add word size to the error message of the failed constraint
Constantin Konstantinidis [Mon, 14 May 2018 11:50:56 +0000 (13:50 +0200)]
encoding/binary: add word size to the error message of the failed constraint

Test added.

Fixes #22860

Change-Id: I08304834a2b7b10b4ac729bf36761692eb4731da
Reviewed-on: https://go-review.googlesource.com/c/go/+/113075
Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Auto-Submit: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>

14 months agoos/exec: skip remount in TestFindExecutableVsNoexec on EROFS
Tobias Klauser [Tue, 4 Apr 2023 12:57:14 +0000 (14:57 +0200)]
os/exec: skip remount in TestFindExecutableVsNoexec on EROFS

To allow using testenv.SyscallIsNotSupported, rewrite the test to use
the exported API only. Given that path is an absolute path,
exec.LookPath is equivalent to exec.findExecutable on linux.

Fixes #59087

Change-Id: Ia01b84d4e9d5a65a88dd995f9e3c8a81c4ccd19f
Reviewed-on: https://go-review.googlesource.com/c/go/+/481620
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Bypass: Bryan Mills <bcmills@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
14 months agoruntime/trace: Fix TestTraceSymbolize on solaris and illumos
Felix Geisendörfer [Sun, 2 Apr 2023 00:19:37 +0000 (20:19 -0400)]
runtime/trace: Fix TestTraceSymbolize on solaris and illumos

Fix a regression caused by CL 463835. Unlike most platforms, solaris and
illumos don't use a libc_read_trampoline, so we need to skip one frame
less when using frame pointer unwinding in traceGoSysCall.

The solution is a bit hacky, so it might make sense to implement
gp.syscallbp if this causes more test failures in the future.

Fixes #59350

Change-Id: I0f0b08f36efe8a492eb4a535e752c03636857057
Reviewed-on: https://go-review.googlesource.com/c/go/+/481336
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Run-TryBot: Felix Geisendörfer <felix.geisendoerfer@datadoghq.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
14 months agomath/rand: clarify Seed deprecation note
Ian Lance Taylor [Tue, 4 Apr 2023 01:41:54 +0000 (18:41 -0700)]
math/rand: clarify Seed deprecation note

Fixes #59331

Change-Id: I62156be2f2758c59349c3b02db6cf9140429c9e3
Reviewed-on: https://go-review.googlesource.com/c/go/+/481915
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Bypass: Ian Lance Taylor <iant@google.com>
Reviewed-by: Russ Cox <rsc@golang.org>
14 months agocmd/dist: mark openbsd-mips64 and openbsd-ppc64 broken
Heschi Kreinick [Tue, 4 Apr 2023 17:02:02 +0000 (13:02 -0400)]
cmd/dist: mark openbsd-mips64 and openbsd-ppc64 broken

The former was broken deliberately; see #58110. The latter is just an
in-progress port.

Updates #58110, #56001.

Change-Id: I7f1c5e2ac016fb7c65c081174d19239fc9b1ea32
Reviewed-on: https://go-review.googlesource.com/c/go/+/482115
Auto-Submit: Heschi Kreinick <heschi@google.com>
TryBot-Bypass: Heschi Kreinick <heschi@google.com>
Run-TryBot: Heschi Kreinick <heschi@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
14 months agohtml/template: disallow actions in JS template literals
Roland Shoemaker [Mon, 20 Mar 2023 18:01:13 +0000 (11:01 -0700)]
html/template: disallow actions in JS template literals

ECMAScript 6 introduced template literals[0][1] which are delimited with
backticks. These need to be escaped in a similar fashion to the
delimiters for other string literals. Additionally template literals can
contain special syntax for string interpolation.

There is no clear way to allow safe insertion of actions within JS
template literals, as handling (JS) string interpolation inside of these
literals is rather complex. As such we've chosen to simply disallow
template actions within these template literals.

A new error code is added for this parsing failure case, errJsTmplLit,
but it is unexported as it is not backwards compatible with other minor
release versions to introduce an API change in a minor release. We will
export this code in the next major release.

The previous behavior (with the cavet that backticks are now escaped
properly) can be re-enabled with GODEBUG=jstmpllitinterp=1.

This change subsumes CL471455.

Thanks to Sohom Datta, Manipal Institute of Technology, for reporting
this issue.

Fixes CVE-2023-24538
Fixes #59234

[0] https://tc39.es/ecma262/multipage/ecmascript-language-expressions.html#sec-template-literals
[1] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals

Reviewed-on: https://team-review.git.corp.google.com/c/golang/go-private/+/1802457
Reviewed-by: Damien Neil <dneil@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
Reviewed-by: Julie Qiu <julieqiu@google.com>
Reviewed-by: Roland Shoemaker <bracewell@google.com>
Change-Id: Ia221fefdb273bd0f066dffc2abcf2a616801d2f2
Reviewed-on: https://go-review.googlesource.com/c/go/+/482079
TryBot-Bypass: Michael Knyszek <mknyszek@google.com>
Run-TryBot: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Auto-Submit: Michael Knyszek <mknyszek@google.com>

14 months agogo/scanner: reject large line and column numbers in //line directives
Damien Neil [Wed, 22 Mar 2023 16:33:22 +0000 (09:33 -0700)]
go/scanner: reject large line and column numbers in //line directives

Setting a large line or column number using a //line directive can cause
integer overflow even in small source files.

Limit line and column numbers in //line directives to 2^30-1, which
is small enough to avoid int32 overflow on all reasonbly-sized files.

For #59180
Fixes CVE-2023-24537

Reviewed-on: https://team-review.git.corp.google.com/c/golang/go-private/+/1802456
Reviewed-by: Julie Qiu <julieqiu@google.com>
Reviewed-by: Roland Shoemaker <bracewell@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
Change-Id: I149bf34deca532af7994203fa1e6aca3c890ea14
Reviewed-on: https://go-review.googlesource.com/c/go/+/482078
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
TryBot-Bypass: Michael Knyszek <mknyszek@google.com>
Run-TryBot: Michael Knyszek <mknyszek@google.com>
Auto-Submit: Michael Knyszek <mknyszek@google.com>

14 months agomime/multipart: limit parsed mime message sizes
Damien Neil [Mon, 20 Mar 2023 17:43:19 +0000 (10:43 -0700)]
mime/multipart: limit parsed mime message sizes

The parsed forms of MIME headers and multipart forms can consume
substantially more memory than the size of the input data.
A malicious input containing a very large number of headers or
form parts can cause excessively large memory allocations.

Set limits on the size of MIME data:

Reader.NextPart and Reader.NextRawPart limit the the number
of headers in a part to 10000.

Reader.ReadForm limits the total number of headers in all
FileHeaders to 10000.

Both of these limits may be set with with
GODEBUG=multipartmaxheaders=<values>.

Reader.ReadForm limits the number of parts in a form to 1000.
This limit may be set with GODEBUG=multipartmaxparts=<value>.

Thanks for Jakob Ackermann (@das7pad) for reporting this issue.

For CVE-2023-24536
For #59153

Reviewed-on: https://team-review.git.corp.google.com/c/golang/go-private/+/1802455
Run-TryBot: Damien Neil <dneil@google.com>
Reviewed-by: Roland Shoemaker <bracewell@google.com>
Reviewed-by: Julie Qiu <julieqiu@google.com>
Change-Id: I08dd297bd75724aade4b0bd6a7d19aeca5bbf99f
Reviewed-on: https://go-review.googlesource.com/c/go/+/482077
Run-TryBot: Michael Knyszek <mknyszek@google.com>
Auto-Submit: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
14 months agonet/textproto, mime/multipart: improve accounting of non-file data
Damien Neil [Thu, 16 Mar 2023 23:56:12 +0000 (16:56 -0700)]
net/textproto, mime/multipart: improve accounting of non-file data

For requests containing large numbers of small parts,
memory consumption of a parsed form could be about 250%
over the estimated size.

When considering the size of parsed forms, account for the size of
FileHeader structs and increase the estimate of memory consumed by
map entries.

Thanks to Jakob Ackermann (@das7pad) for reporting this issue.

For CVE-2023-24536
For #59153

Reviewed-on: https://team-review.git.corp.google.com/c/golang/go-private/+/1802454
Run-TryBot: Damien Neil <dneil@google.com>
Reviewed-by: Roland Shoemaker <bracewell@google.com>
Reviewed-by: Julie Qiu <julieqiu@google.com>
Change-Id: I9620758495ed77c09ca6dc5db4b723c29f3baad8
Reviewed-on: https://go-review.googlesource.com/c/go/+/482076
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Michael Knyszek <mknyszek@google.com>
Run-TryBot: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
14 months agomime/multipart: avoid excessive copy buffer allocations in ReadForm
Damien Neil [Thu, 16 Mar 2023 21:18:04 +0000 (14:18 -0700)]
mime/multipart: avoid excessive copy buffer allocations in ReadForm

When copying form data to disk with io.Copy,
allocate only one copy buffer and reuse it rather than
creating two buffers per file (one from io.multiReader.WriteTo,
and a second one from os.File.ReadFrom).

Thanks to Jakob Ackermann (@das7pad) for reporting this issue.

For CVE-2023-24536
For #59153

Reviewed-on: https://team-review.git.corp.google.com/c/golang/go-private/+/1802453
Run-TryBot: Damien Neil <dneil@google.com>
Reviewed-by: Julie Qiu <julieqiu@google.com>
Reviewed-by: Roland Shoemaker <bracewell@google.com>
Change-Id: I732bd2e1e7467918cac8ab9d65d089272ba4656f
Reviewed-on: https://go-review.googlesource.com/c/go/+/482075
Auto-Submit: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
TryBot-Bypass: Michael Knyszek <mknyszek@google.com>
Run-TryBot: Michael Knyszek <mknyszek@google.com>

14 months agonet/textproto: avoid overpredicting the number of MIME header keys
Damien Neil [Fri, 10 Mar 2023 22:21:05 +0000 (14:21 -0800)]
net/textproto: avoid overpredicting the number of MIME header keys

A parsed MIME header is a map[string][]string. In the common case,
a header contains many one-element []string slices. To avoid
allocating a separate slice for each key, ReadMIMEHeader looks
ahead in the input to predict the number of keys that will be
parsed, and allocates a single []string of that length.
The individual slices are then allocated out of the larger one.

The prediction of the number of header keys was done by counting
newlines in the input buffer, which does not take into account
header continuation lines (where a header key/value spans multiple
lines) or the end of the header block and the start of the body.
This could lead to a substantial amount of overallocation, for
example when the body consists of nothing but a large block of
newlines.

Fix header key count prediction to take into account the end of
the headers (indicated by a blank line) and continuation lines
(starting with whitespace).

Thanks to Jakob Ackermann (@das7pad) for reporting this issue.

For #58975
Fixes CVE-2023-24534

Reviewed-on: https://team-review.git.corp.google.com/c/golang/go-private/+/1802452
Run-TryBot: Damien Neil <dneil@google.com>
Reviewed-by: Roland Shoemaker <bracewell@google.com>
Reviewed-by: Julie Qiu <julieqiu@google.com>
Change-Id: Iacc1c2b5ea6509529845a972414199f988ede1e5
Reviewed-on: https://go-review.googlesource.com/c/go/+/481994
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Michael Knyszek <mknyszek@google.com>
Auto-Submit: Michael Knyszek <mknyszek@google.com>

14 months agonet: treat EAI_NODATA as errNoSuchHost
Mateusz Poliwczak [Thu, 30 Mar 2023 07:22:35 +0000 (07:22 +0000)]
net: treat EAI_NODATA as errNoSuchHost

man getaddrinfo:
EAI_NODATA
              The specified network host exists, but does not have any
              network addresses defined.

In the go resolver we treat this kind of error as nosuchhost.

Change-Id: I69fab6f8da8e3a86907e65104bca9f055968633a
GitHub-Last-Rev: b4891e2addaeccecb242d0485daa168bb55cf54e
GitHub-Pull-Request: golang/go#57507
Reviewed-on: https://go-review.googlesource.com/c/go/+/459955
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Run-TryBot: Mateusz Poliwczak <mpoliwczak34@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

14 months agoall: fix misuses of "a" vs "an"
cui fliter [Thu, 30 Mar 2023 16:00:19 +0000 (00:00 +0800)]
all: fix misuses of "a" vs "an"

Fixes the misuse of "a" vs "an", according to English grammatical
expectations and using https://www.a-or-an.com/

Change-Id: I53ac724070e3ff3d33c304483fe72c023c7cda47
Reviewed-on: https://go-review.googlesource.com/c/go/+/480536
Run-TryBot: shuang cui <imcusg@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
14 months agoencoding/gob: use reflect.Value.Grow
Daniel Martí [Sat, 1 Apr 2023 17:55:06 +0000 (18:55 +0100)]
encoding/gob: use reflect.Value.Grow

Growing by one is a simpler, and often cheaper,
operation compared to appending one (newly created) zero value.
The method was introduced in Go 1.20.

growSlice in dec_helpers.go is left alone,
as it grows using the builtin append instead of reflect.Append.

No noticeable performance difference on any of our benchmarks,
as this code only runs for slices large enough to not fit in
saferio.SliceCap, and none of our benchmarks use data that large.

goos: linux
goarch: amd64
pkg: encoding/gob
cpu: AMD Ryzen 7 PRO 5850U with Radeon Graphics
   │     old     │                new                 │
   │   sec/op    │   sec/op     vs base               │
DecodeBytesSlice-8       11.37µ ± 1%   11.46µ ± 4%       ~ (p=0.315 n=10)
DecodeInterfaceSlice-8   96.49µ ± 1%   95.75µ ± 1%       ~ (p=0.436 n=10)
geomean                  33.12µ        33.12µ       +0.01%

   │     old      │                 new                 │
   │     B/op     │     B/op      vs base               │
DecodeBytesSlice-8       22.39Ki ± 0%   22.39Ki ± 0%       ~ (p=1.000 n=10)
DecodeInterfaceSlice-8   80.25Ki ± 0%   80.25Ki ± 0%       ~ (p=0.650 n=10)
geomean                  42.39Ki        42.39Ki       +0.00%

   │     old     │                 new                  │
   │  allocs/op  │  allocs/op   vs base                 │
DecodeBytesSlice-8        169.0 ± 0%    169.0 ± 0%       ~ (p=1.000 n=10) ¹
DecodeInterfaceSlice-8   3.178k ± 0%   3.178k ± 0%       ~ (p=1.000 n=10) ¹
geomean                   732.9         732.9       +0.00%

Change-Id: I468aebf4ae6f197a1fd35f6fee809ca591c1788f
Reviewed-on: https://go-review.googlesource.com/c/go/+/481376
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
14 months agoencoding/gob: report allocs in benchmarks
Daniel Martí [Sat, 1 Apr 2023 17:44:20 +0000 (18:44 +0100)]
encoding/gob: report allocs in benchmarks

I almost exclusively use these benchmarks with -benchtime already.

Change-Id: I6539cbba6abbdb6b275502e122f4e16856d8b9e4
Reviewed-on: https://go-review.googlesource.com/c/go/+/481375
Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Rob Pike <r@golang.org>
14 months agodatabase/sql,testing/quick: use reflect.Value.SetZero
Daniel Martí [Sat, 1 Apr 2023 15:19:52 +0000 (16:19 +0100)]
database/sql,testing/quick: use reflect.Value.SetZero

Change-Id: I2893a6aa8c2715f69745f424262c20c21370b05f
Reviewed-on: https://go-review.googlesource.com/c/go/+/481355
Reviewed-by: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>

14 months agoruntime/cgo: use pthread_attr_get_np on Illumos
Cherry Mui [Mon, 3 Apr 2023 19:17:40 +0000 (15:17 -0400)]
runtime/cgo: use pthread_attr_get_np on Illumos

While Solaris supports pthread_getattr_np, Illumos doesn't...
Instead, Illumos supports pthread_attr_get_np.

Updates #59294.

Change-Id: I2c66dad79b8bf3d510352875bf21d04415f23eeb
Reviewed-on: https://go-review.googlesource.com/c/go/+/481795
TryBot-Bypass: Cherry Mui <cherryyz@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
14 months agocmd/go: add wasip1 to modindex syslist
Johan Brandhorst-Satzkorn [Thu, 30 Mar 2023 19:14:55 +0000 (12:14 -0700)]
cmd/go: add wasip1 to modindex syslist

This was intended to be merged together with changes in CL 479616.

For #58141

Change-Id: I76c38d3d4dfee93a1a170e28af28f0c9d6382830
Reviewed-on: https://go-review.googlesource.com/c/go/+/480656
Run-TryBot: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
14 months agoruntime: cleanup PPC64/linux runtime.sigtramp
Paul E. Murphy [Mon, 13 Mar 2023 20:58:15 +0000 (15:58 -0500)]
runtime: cleanup PPC64/linux runtime.sigtramp

Add new helper macros to further simplify the transition from
the host's ABI to Go. Fortunately the same one should work for
all PPC64 targets.

Update the other site which uses these wrappers to further
consolidate. Also, update the call to runtime.sigtrampgo to
call the ABIInternal version directly.

Also, update the SAVE/RESTORE_VR macros to accept R0.

Change-Id: I0046176029e1e1b25838688e4b7bf57805b01bd4
Reviewed-on: https://go-review.googlesource.com/c/go/+/476297
Reviewed-by: Archana Ravindar <aravind5@in.ibm.com>
Run-TryBot: Paul Murphy <murp@ibm.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Lynn Boger <laboger@linux.vnet.ibm.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

14 months agoRevert "Revert "runtime: consolidate function descriptor definitions on PPC64""
Cherry Mui [Fri, 31 Mar 2023 19:56:26 +0000 (19:56 +0000)]
Revert "Revert "runtime: consolidate function descriptor definitions on PPC64""

This reverts CL 481059, which in turn reverts CL 478917.

Reason for revert: reapply the original CL.

Change-Id: Icf6bb6a620313b44fadcc7f69a62fdbb943e34fd
Reviewed-on: https://go-review.googlesource.com/c/go/+/481075
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
Reviewed-by: Paul Murphy <murp@ibm.com>
14 months agocmd/compile/internal/test: skip testpoint due to revert of CL 479095
Than McIntosh [Mon, 3 Apr 2023 18:09:03 +0000 (14:09 -0400)]
cmd/compile/internal/test: skip testpoint due to revert of CL 479095

Skip one of the testpoints that verifies inlining, since it
no longer passes as a result of reverting CL 479095. Once we
roll forward with a new version of CL 479095 we can re-enable
this testpoint.

Change-Id: I41f6fb3fce78f31e60c5f0ed2856be0e66865149
Reviewed-on: https://go-review.googlesource.com/c/go/+/481755
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Than McIntosh <thanm@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
14 months agoruntime/cgo: store M for C-created thread in pthread key
doujiang24 [Fri, 31 Mar 2023 19:45:39 +0000 (15:45 -0400)]
runtime/cgo: store M for C-created thread in pthread key

This reapplies CL 392854, with the followup fixes in CL 479255,
CL 479915, and CL 481057 incorporated.

CL 392854, by doujiang24 <doujiang24@gmail.com>, speed up C to Go
calls by binding the M to the C thread. See below for its
description.
CL 479255 is a followup fix for a small bug in ARM assembly code.
CL 479915 is another followup fix to address C to Go calls after
the C code uses some stack, but that CL is also buggy.
CL 481057, by Michael Knyszek, is a followup fix for a memory leak
bug of CL 479915.

[Original CL 392854 description]

In a C thread, it's necessary to acquire an extra M by using needm while invoking a Go function from C. But, needm and dropm are heavy costs due to the signal-related syscalls.
So, we change to not dropm while returning back to C, which means binding the extra M to the C thread until it exits, to avoid needm and dropm on each C to Go call.
Instead, we only dropm while the C thread exits, so the extra M won't leak.

When invoking a Go function from C:
Allocate a pthread variable using pthread_key_create, only once per shared object, and register a thread-exit-time destructor.
And store the g0 of the current m into the thread-specified value of the pthread key,  only once per C thread, so that the destructor will put the extra M back onto the extra M list while the C thread exits.

When returning back to C:
Skip dropm in cgocallback, when the pthread variable has been created, so that the extra M will be reused the next time invoke a Go function from C.

This is purely a performance optimization. The old version, in which needm & dropm happen on each cgo call, is still correct too, and we have to keep the old version on systems with cgo but without pthreads, like Windows.

This optimization is significant, and the specific value depends on the OS system and CPU, but in general, it can be considered as 10x faster, for a simple Go function call from a C thread.

For the newly added BenchmarkCGoInCThread, some benchmark results:
1. it's 28x faster, from 3395 ns/op to 121 ns/op, in darwin OS & Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
2. it's 6.5x faster, from 1495 ns/op to 230 ns/op, in Linux OS & Intel(R) Xeon(R) CPU E5-2630 0 @ 2.30GHz

[CL 479915 description]

Currently, when C calls into Go the first time, we grab an M
using needm, which sets m.g0's stack bounds using the SP. We don't
know how big the stack is, so we simply assume 32K. Previously,
when the Go function returns to C, we drop the M, and the next
time C calls into Go, we put a new stack bound on the g0 based on
the current SP. After CL 392854, we don't drop the M, and the next
time C calls into Go, we reuse the same g0, without recomputing
the stack bounds. If the C code uses quite a bit of stack space
before calling into Go, the SP may be well below the 32K stack
bound we assumed, so the runtime thinks the g0 stack overflows.

This CL makes needm get a more accurate stack bound from
pthread. (In some platforms this may still be a guess as we don't
know exactly where we are in the C stack), but it is probably
better than simply assuming 32K.

Fixes #51676.
Fixes #59294.

Change-Id: I9bf1400106d5c08ce621d2ed1df3a2d9e3f55494
Reviewed-on: https://go-review.googlesource.com/c/go/+/481061
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
Reviewed-by: DeJiang Zhu (doujiang) <doujiang24@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

14 months agoreflect: deprecate SliceHeader and StringHeader
Russ Cox [Tue, 22 Nov 2022 15:24:11 +0000 (10:24 -0500)]
reflect: deprecate SliceHeader and StringHeader

These are replaced by unsafe.String etc, which were added in Go 1.20.
Per https://go.dev/wiki/Deprecated, we must wait until Go 1.21
to mark them deprecated.

Fixes #56906.

Change-Id: I4198c3f3456e9e2031f6c7232842e187e6448892
Reviewed-on: https://go-review.googlesource.com/c/go/+/452762
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Russ Cox <rsc@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
Run-TryBot: Russ Cox <rsc@golang.org>

14 months agodoc: fix template mistake in godebug.md
Russ Cox [Fri, 31 Mar 2023 16:47:47 +0000 (12:47 -0400)]
doc: fix template mistake in godebug.md

This file is itself template input, so have to hide the template
in the go command example.

Change-Id: Ifc4eaff35ca8dc2fb479f8e28d64c06b2a9c9d3b
Reviewed-on: https://go-review.googlesource.com/c/go/+/480995
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
14 months agoRevert "cmd/compile: allow more inlining of functions that construct closures"
Than McIntosh [Mon, 3 Apr 2023 14:25:58 +0000 (14:25 +0000)]
Revert "cmd/compile: allow more inlining of functions that construct closures"

This reverts commit http://go.dev/cl//479095

Reason for revert: causes failures in google-internal testing

Change-Id: If1018b35be0b8627e2959f116179ada24d44d67c
Reviewed-on: https://go-review.googlesource.com/c/go/+/481637
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Pratt <mpratt@google.com>
Run-TryBot: Than McIntosh <thanm@google.com>

14 months agocrypto/subtle: don't cast to *uintptr when word size is 0
Keith Randall [Thu, 30 Mar 2023 16:52:39 +0000 (09:52 -0700)]
crypto/subtle: don't cast to *uintptr when word size is 0

Casting to a *uintptr is not ok if there isn't at least 8 bytes of
data backing that pointer (on 64-bit archs).
So although we end up making a slice of 0 length with that pointer,
the cast itself doesn't know that.
Instead, bail early if the result is going to be 0 length.

Fixes #59334

Change-Id: Id3c0e09d341d838835c0382cccfb0f71dc3dc7e6
Reviewed-on: https://go-review.googlesource.com/c/go/+/480575
Run-TryBot: Keith Randall <khr@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
14 months agocmd/gofmt: set backup file permissions on Windows
qmuntal [Thu, 30 Mar 2023 08:28:32 +0000 (10:28 +0200)]
cmd/gofmt: set backup file permissions on Windows

File.Chmod is supported on Windows since CL 250077, there is no need
to skip the call anymore.

Updates #18026

Change-Id: Ie03cf016e651b93241f73067614fc4cb341504ef
Reviewed-on: https://go-review.googlesource.com/c/go/+/480416
Run-TryBot: Quim Muntal <quimmuntal@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
14 months agogo/internal/gcimport: unskip Windows tests
qmuntal [Thu, 30 Mar 2023 08:08:15 +0000 (10:08 +0200)]
go/internal/gcimport: unskip Windows tests

There are many tests in internal/gcimporter that are skipped on
Windows because they build a test program that needs the -D flag
when invoking the Go compiler.

This flag is already passed since CL 442303, so there is no need to
skip those tests.

Change-Id: I877e670194048bda9a52ad2568650cf33eacfb5a
Reviewed-on: https://go-review.googlesource.com/c/go/+/480415
Run-TryBot: Quim Muntal <quimmuntal@gmail.com>
Auto-Submit: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
14 months agonet: unskip TestConcurrentPreferGoResolversDial on Windows
qmuntal [Thu, 30 Mar 2023 09:04:48 +0000 (11:04 +0200)]
net: unskip TestConcurrentPreferGoResolversDial on Windows

Windows resolver uses the Dial function since CL 409234.

Change-Id: Id631a84d2b85fc4f8897e413a0a454cf54c00de4
Reviewed-on: https://go-review.googlesource.com/c/go/+/480418
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Quim Muntal <quimmuntal@gmail.com>