Commit graph

64134 commits

Author SHA1 Message Date
Roland Shoemaker
0983090171 encoding/pem: properly decode strange PEM data
When the passed byte slice has leading garbage, properly handle ignoring
it and continuing to parse the slice until we find a valid block (or
nothing).

Change-Id: I07e937d9c754fd71b028b99450b48f57b4464457
Reviewed-on: https://go-review.googlesource.com/c/go/+/712140
Reviewed-by: Damien Neil <dneil@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-10-17 08:44:33 -07:00
qmuntal
36863d6194 runtime: unify riscv64 library entry point
Cq-Include-Trybots: luci.golang.try:gotip-linux-riscv64
Change-Id: I6470dfc5c9e03dfe5fc535605fdd7d861b9ba2f3
Reviewed-on: https://go-review.googlesource.com/c/go/+/706415
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Joel Sing <joel@sing.id.au>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-10-17 01:07:59 -07:00
Mark Freeman
0c14000f87 go/types, types2: remove under(Type) in favor of Type.Underlying()
As of CL 695977, under(Type) simply delegates to Type.Underlying().
This is just a cleanup.

Change-Id: I48d5fddc38560dfe485184faa6a5ff713bea74a0
Reviewed-on: https://go-review.googlesource.com/c/go/+/712400
Commit-Queue: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-10-16 15:30:18 -07:00
Mark Freeman
1099436f1b go/types, types2: change and enforce lifecycle of Named.fromRHS and Named.underlying fields
A type definition or alias declaration consists of a type name (LHS)
which is bound to a type expression (RHS) by the declaration.

This CL consistently uses the fromRHS fields of Named and Alias types
to represent that RHS type expression, and sets Named.underlying and
Alias.actual only once those types have been computed.

Currently, Named types use Named.underlying for some of this
functionality, which makes the code difficult to understand. Operations
which used Named.underlying now use Named.fromRHS.

For example, in:

  type A = B
  type B = int

A.fromRHS is B (Alias) and B.fromRHS is int (Basic).

Meanwhile, in:

  type A B
  type B int

A.underlying is B (Named) and B.underlying is int (Basic) initially.

Note that despite A.underlying pointing to B, B is not the underlying
type of A (it is int). At some point during type checking, A walks
through the chain A.underlying -> B.underlying -> int and sets
A.underlying to int.

While this approach works, it introduces some problems:

  1. Whether A.underlying refers to the underlying type (int) or not
     (B) depends on when the field is accessed.
  2. There is no convenient mechanism to check if the underlying type
     of B has been deduced. One can check if B.underlying is a named
     type, but since B.underlying is already B's underlying type (int),
     it's still ambiguous.

Operations derived from Named.underlying share similar problems. For
example, Named.expandUnderlying() (which substitutes type arguments)
returns an instantiated named type whose Named.underlying also may or
may not refer to its underlying type.

With this change, Named.underlying is nil as long as it is unknown, and
non-nil and not a named type once it is known. Additional assertions are
added to enforce that:

  1. Named.underlying is not set until Named has been resolved.
  2. Named is not resolved until Named.fromRHS is populated, unless it
     is given explicit permission. This permission is briefly given
     while type-checking declarations of named types to account for
     cycles of alias types represented as TypeNames. It is also given to
     named types created through NewNamed for backward compatibility.
     This permission is revoked when SetUnderlying is called.

Accessors of Named.underlying are responsible for first resolving
the named type, unless they are in a context where they know the
type to already be resolved.

This change also exposed a bug in validType wherein the underlying
type for struct types containing invalid types did not have their
underlying type set to invalid (see #75194). This bug was exploited by a
test in x/tools, which has been disabled for Go 1.26 (via CL 700395).

Other minor adjustments are made for instantiated and loaded types.
Instantiated types have no RHS as they are not declared, and loaded
types set their RHS to the underlying from export data directly.

Minor simplifications are also made throughout.

Fixes #75194

Change-Id: I72644d7329c996eb1e67514063fe51c3ae06c38d
Reviewed-on: https://go-review.googlesource.com/c/go/+/695977
Auto-Submit: Mark Freeman <markfreeman@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Griesemer <gri@google.com>
2025-10-16 11:21:47 -07:00
Robert Griesemer
41f5659347 go/types, types2: remove superfluous unalias call (minor cleanup)
Change-Id: Ifc0d6e999777513498f070c5bc2fb4640d38c671
Reviewed-on: https://go-review.googlesource.com/c/go/+/712460
Reviewed-by: Robert Griesemer <gri@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Robert Griesemer <gri@google.com>
Reviewed-by: Mark Freeman <markfreeman@google.com>
2025-10-16 11:03:04 -07:00
Vasily Leonenko
e7351c03c8 runtime: use DC ZVA instead of its encoding in WORD in arm64 memclr
Change-Id: I900a96b985f4d9378d25b9256c4274610fc2f70e
Reviewed-on: https://go-review.googlesource.com/c/go/+/698417
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Carlos Amedee <carlos@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-10-16 06:46:30 -07:00
Alan Donovan
6cbe0920c4 cmd: update to x/tools@7d9453cc
go get golang.org/x/tools@master
 go mod tidy
 go mod vendor

in both cmd and src, for (enforced) consistency.

Also: GOWORK=off go generate -run=bundle std

This will enable use of modernize and inline.

Change-Id: I6348dd97ec2c41437b3ca899ed91f10815f2fe26
Reviewed-on: https://go-review.googlesource.com/c/go/+/707135
Reviewed-by: Michael Matloob <matloob@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
2025-10-16 04:23:16 -07:00
Vasily Leonenko
45eee553e2 cmd/internal/obj: move ARM64RegisterExtension from cmd/asm/internal/arch
Change-Id: Iab41674953655efa7be3d306dfb3f5be486be501
Reviewed-on: https://go-review.googlesource.com/c/go/+/701455
Reviewed-by: Cherry Mui <cherryyz@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@google.com>
2025-10-15 17:35:29 -07:00
Keith Randall
27f9a6705c runtime: increase repeat count for alloc test
To make sure a single spurious alloc doesn't flake the test.

Fixes #75858

Change-Id: I055b37ad5668459bfa7ab1dac97025c997c68f1a
Reviewed-on: https://go-review.googlesource.com/c/go/+/712201
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Keith Randall <khr@google.com>
2025-10-15 15:23:22 -07:00
Damien Neil
b68cebd809 net/http/httptest: record failed ResponseWriter writes
CL 709335 changed ResponseWriter.Write to return an error
when trying to write to a response with a status code which
doesn't permit a body, such as 304.

Continue to return an error, but still record the write in
ResponseWriter.Body. This maintains the documented property that
"the data in buf is written to rw.Body".

For #75471

Change-Id: I69139797559fe09d6580c5d25b4458f04263c60e
Reviewed-on: https://go-review.googlesource.com/c/go/+/711940
Reviewed-by: Sean Liao <sean@liao.dev>
TryBot-Bypass: Damien Neil <dneil@google.com>
Auto-Submit: Damien Neil <dneil@google.com>
Reviewed-by: Nicholas Husin <nsh@golang.org>
Reviewed-by: Nicholas Husin <husin@google.com>
2025-10-15 14:41:11 -07:00
Alan Donovan
f1fed742eb cmd: fix three printf problems reported by newest vet
Change-Id: Id70985d217c940eb022dbc95bfaa20373672512c
Reviewed-on: https://go-review.googlesource.com/c/go/+/712220
Auto-Submit: Alan Donovan <adonovan@google.com>
TryBot-Bypass: Alan Donovan <adonovan@google.com>
Commit-Queue: Alan Donovan <adonovan@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
2025-10-15 13:54:06 -07:00
mohanson
0984dcd757 cmd/compile: fix an error in comments
Remove the redundant only.

Change-Id: I9cf2d84ae080a567ad45a2d0ef002c7c89395479
Reviewed-on: https://go-review.googlesource.com/c/go/+/711960
Auto-Submit: Robert Findley <rfindley@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Bypass: Robert Griesemer <gri@google.com>
2025-10-15 13:48:28 -07:00
Robert Griesemer
31f82877e8 go/types, types2: fix misleading internal comment
See also the discussion in #75885.

Change-Id: Ieb964ea6ee51600c0c08ecba0af50a1deb209a4d
Reviewed-on: https://go-review.googlesource.com/c/go/+/712141
Reviewed-by: Mark Freeman <markfreeman@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
TryBot-Bypass: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
2025-10-15 13:46:26 -07:00
Will Faught
6346349f56 cmd/compile: replace angle brackets with square
Caused Markdown rendering error on https://go.dev/src/cmd/compile/README in macOS (15.6.1) Safari (18.6).

Change-Id: Id71436d9a7bc7e461e522500d66df5dda7cd9f7f
GitHub-Last-Rev: 4e4447e163
GitHub-Pull-Request: golang/go#75549
Reviewed-on: https://go-review.googlesource.com/c/go/+/704716
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@golang.org>
Auto-Submit: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Keith Randall <khr@google.com>
2025-10-15 12:58:21 -07:00
Alexander Musman
284379cdfc cmd/compile: remove rematerializable values from live set across calls
Remove rematerializable values in the live set across call operations,
preventing dead constant rematerialization.

When computing live values across function calls, rematerializable
values were being kept in the live set unnecessarily. This caused
the shuffling to rematerialize dead constants.

This change leads to code size reduction on arm64 linux:
    Executable            Old .text  New .text     Change
    -------------------------------------------------------
    asm                     1969236    1964356     -0.25%
    cgo                     1739588    1734884     -0.27%
    compile                 8950788    8932500     -0.20%
    cover                   1877268    1872916     -0.23%
    link                    2572660    2565076     -0.29%
    preprofile               866772     863828     -0.34%
    vet                     2888628    2881028     -0.26%

There seems also some compile time effect:

                        orig.results             uexp.results
                           sec/op       sec/op     vs base
BleveIndexBatch100-4       7.414 ± 2%    7.352 ± 1%       ~ (p=0.218 n=10)
ESBuildThreeJS-4          777.3m ± 1%   778.1m ± 1%       ~ (p=0.529 n=10)
ESBuildRomeTS-4           197.3m ± 1%   199.0m ± 1%       ~ (p=0.143 n=10)
EtcdPut-4                 64.92m ± 2%   64.95m ± 2%       ~ (p=0.912 n=10)
EtcdSTM-4                 323.9m ± 1%   323.0m ± 1%       ~ (p=0.393 n=10)
GoBuildKubelet-4           160.1 ± 0%    159.4 ± 0%  -0.42% (p=0.001 n=10)
GoBuildKubeletLink-4       12.40 ± 1%    12.27 ± 1%       ~ (p=0.529 n=10)
GoBuildIstioctl-4          125.8 ± 0%    125.2 ± 0%  -0.42% (p=0.000 n=10)
GoBuildIstioctlLink-4      8.679 ± 0%    8.686 ± 1%       ~ (p=0.912 n=10)
GoBuildFrontend-4          49.18 ± 0%    48.73 ± 0%  -0.92% (p=0.000 n=10)
GoBuildFrontendLink-4      2.300 ± 1%    2.292 ± 1%  -0.35% (p=0.043 n=10)
GopherLuaKNucleotide-4     37.77 ± 6%    38.07 ± 2%       ~ (p=0.218 n=10)
MarkdownRenderXHTML-4     274.3m ± 0%   275.2m ± 0%  +0.34% (p=0.003 n=10)
Tile38QueryLoad-4         650.7µ ± 0%   650.2µ ± 0%       ~ (p=0.971 n=10)
geomean                    2.130         2.127       -0.15%

Change-Id: I7a766195ee17bfd9e47d7a940864619f553416ff
Reviewed-on: https://go-review.googlesource.com/c/go/+/707415
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
Auto-Submit: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-10-15 12:53:02 -07:00
Youlin Feng
519ae514ab cmd/compile: eliminate bound check for slices of the same length
If two slices start out with the same length and decrease in length by
the same amount on each round of the loop (or in the if block), then
we think their length are always equal.

For example:

if len(a) != len(b) {
	return
}
for len(a) >= 4 {
	a = a[4:]
	b = b[4:] // proved here, omit boundary check
}
if len(a) == len(b) { // proved here
	//...
}

Or, change 'for' to 'if':

if len(a) != len(b) {
	return
}
if len(a) >= 4 {
	a = a[4:]
	b = b[4:]
}
if len(a) == len(b) { // proved here
	//...
}

Fixes #75144

Change-Id: I4e5902a02b5cf8fdc122715a7dbd2fb5e9a8f5dc
Reviewed-on: https://go-review.googlesource.com/c/go/+/699155
Reviewed-by: Michael Pratt <mpratt@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Keith Randall <khr@golang.org>
2025-10-15 12:34:48 -07:00
Alan Donovan
b5a29cca48 cmd/distpack: add fix tool to inventory
(To be consistent with change to build.go in CL 700795.)

For #71859

Change-Id: I8caad28b7e5a2657f21b60a72899daecf0b2c324
Reviewed-on: https://go-review.googlesource.com/c/go/+/712180
Auto-Submit: Alan Donovan <adonovan@google.com>
Reviewed-by: Michael Matloob <matloob@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
TryBot-Bypass: Alan Donovan <adonovan@google.com>
2025-10-15 12:29:26 -07:00
matloob
bb5eb51715 runtime/pprof: fix errors in pprof_test
I think the original depth-1 argument to allocDeep was correct.
Reverted that, and also the change to maxSkip in mprof.go, which was
also incorrect. I think before we were usually passing accidentally in
the loop over matched stacks when we really should usually have been
passing in the previous loop.

Change-Id: I6a6a696463e2baf045b66f418d7afbfcb49258e4
Reviewed-on: https://go-review.googlesource.com/c/go/+/712100
Reviewed-by: Michael Matloob <matloob@google.com>
TryBot-Bypass: Michael Matloob <matloob@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
2025-10-15 11:15:17 -07:00
Vasily Leonenko
5c9a26c7f8 cmd/compile: use arm64 neon in LoweredMemmove/LoweredMemmoveLoop
Raspberry Pi 5 (Cortex-A76)

                     │   base.log   │               opt.log               │
                     │    sec/op    │   sec/op     vs base                │
MemmoveKnownSize112     3.549n ± 0%   3.652n ± 0%   +2.92% (p=0.000 n=10)
MemmoveKnownSize128     3.979n ± 0%   3.617n ± 0%   -9.09% (p=0.000 n=10)
MemmoveKnownSize192     7.566n ± 0%   5.074n ± 0%  -32.94% (p=0.000 n=10)
MemmoveKnownSize248     8.549n ± 0%   7.184n ± 1%  -15.97% (p=0.000 n=10)
MemmoveKnownSize256    10.010n ± 0%   6.827n ± 0%  -31.80% (p=0.000 n=10)
MemmoveKnownSize512     19.81n ± 0%   13.59n ± 0%  -31.40% (p=0.000 n=10)
MemmoveKnownSize1024    39.66n ± 0%   27.00n ± 0%  -31.93% (p=0.000 n=10)
geomean                 9.538n        7.392n       -22.50%

Change-Id: I7b17408cd0a500ceaa80bc93ffe2f19ddeea9c0d
Reviewed-on: https://go-review.googlesource.com/c/go/+/692315
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: David Chase <drchase@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-10-15 09:38:03 -07:00
Keith Randall
61d1ff61ad cmd/compile: use block starting position for phi line number
Fixes #75615

Change-Id: I2c7f0ea1203e8a97749c9f780c29a66050f0159d
Reviewed-on: https://go-review.googlesource.com/c/go/+/710355
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: David Chase <drchase@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-10-15 09:13:12 -07:00
Ian Alexander
5b29875c8e cmd/go: inject State parameter into run.runRun
This command modifies the call tree starting at `run.runRun` to inject
a `State` parameter to every function that is currently using the
global `modload.LoaderState` variable.  By explicilty passing a
`State` parameter, we can begin to eliminate the usage of the global
`modload.LoaderState`.

This commit is part of the overall effort to eliminate global
modloader state.

[git-generate]
cd src/cmd/go/internal/run
rf 'inject modload.LoaderState runRun'
cd ..
./rf-cleanup.zsh

Change-Id: I337323c087ed4e43af28973fad27152791eefbc2
Reviewed-on: https://go-review.googlesource.com/c/go/+/698063
TryBot-Bypass: Ian Alexander <jitsu@google.com>
Reviewed-by: Michael Matloob <matloob@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
2025-10-15 08:59:02 -07:00
matloob
5113496805 runtime/pprof: skip flaky test TestProfilerStackDepth/heap for now
The test has been causing a lot of flakes on the builders. Skip it while
I'm debugging it.

For #74029

Change-Id: I6a6a696450c23f65bc310a2d0ab61b22dba88f00
Reviewed-on: https://go-review.googlesource.com/c/go/+/712060
TryBot-Bypass: Michael Matloob <matloob@google.com>
Reviewed-by: Michael Matloob <matloob@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
2025-10-15 08:32:21 -07:00
Ian Alexander
36086e85f8 cmd/go: create temporary cleanup script
This is a large series of sed commands to cleanup after successful use
of the `rf inject` command.  This script will be used to refactor the
codebase to eliminate global state within the module loader.  Once
that effort is complete, this script will be removed.

This commit is part of the overall effort to eliminate global
modloader state.

Change-Id: If04926b5ca5b7230f91ac98fe4a82c20ef5f73ee
Reviewed-on: https://go-review.googlesource.com/c/go/+/709978
Reviewed-by: Michael Matloob <matloob@golang.org>
TryBot-Bypass: Ian Alexander <jitsu@google.com>
Commit-Queue: Ian Alexander <jitsu@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
2025-10-15 07:30:13 -07:00
David Chase
7056c71d32 cmd/compile: disable use of new saturating float-to-int conversions
The new conversions can be activated (or bisected) with
  -gcflags=all=-d=converthash=PATTERN

where PATTERN is either a hash string or n, qn, y, qy for
no, quietly no, yes, quietly yes.

This CL makes the default pattern be "qn" instead of the
default-default which is an efficient encoding of "qy".

Updates #75834

Change-Id: I88a9fd7880bc999132420c8d0a22a8fdc1e95a2a
Reviewed-on: https://go-review.googlesource.com/c/go/+/711845
Reviewed-by: Cherry Mui <cherryyz@google.com>
TryBot-Bypass: David Chase <drchase@google.com>
2025-10-14 15:09:35 -07:00
David Chase
6d5b13793f Revert "cmd/compile: make 386 float-to-int conversions match amd64"
This reverts commit 78d75b3799.

Reason for revert: we need to do this more carefully, at minimum gated by a module version

(This should follow the softfloat FP conversion revert)

Change-Id: I736bec6cd860285dcc3b11fac85b377a149435c3
Reviewed-on: https://go-review.googlesource.com/c/go/+/711842
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
2025-10-14 12:46:22 -07:00
David Chase
bb2a14252b Revert "runtime: adjust softfloat corner cases to match amd64/arm64"
This reverts commit b9f3accdcf.

Reason for revert: we need to do this more carefully, at minimum gated by a module version

(This should follow the WASM FP conversion revert)

Change-Id: Ib98ce7d243348f69c9944db8537397b225c2cc33
Reviewed-on: https://go-review.googlesource.com/c/go/+/711841
Reviewed-by: Keith Randall <khr@golang.org>
TryBot-Bypass: David Chase <drchase@google.com>
Reviewed-by: Keith Randall <khr@google.com>
2025-10-14 12:45:58 -07:00
David Chase
3bc9d9fa83 Revert "cmd/compile: make wasm match other platforms for FP->int32/64 conversions"
This reverts commit 8d810286b3.

Reason for revert: we need to do this more carefully, at minimum gated by a module version

Change-Id: Ia951e2e5ecdd455ea0f17567963c6fab0f4540dc
Reviewed-on: https://go-review.googlesource.com/c/go/+/711840
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
2025-10-14 12:44:32 -07:00
Joe Tsai
ee5af46172 encoding/json: avoid misleading errors under goexperiment.jsonv2
The jsontext package represents the location of JSON errors
using a JSON Pointer (RFC 6901). This uses the JSON type system.

Unfortunately the v1 json.UnmarshalTypeError assumes a Go struct-based
mechanism for reporting the location of errors
(and has historically never been implemented correctly since
it was a weird mix of both JSON and Go namespaces; see #43126).
Trying to map a JSON Pointer into UnmarshalTypeError.{Struct,Field}
is difficult to get right without teaching jsontext
about the Go type system.

To reduce the probability of misleading errors,
check whether the last token looks like a JSON array index
and if so, elide the phrase "into Go struct field".

Fixes #74801

Change-Id: Id2088ffb9c339a9238ed38c90223d86a89422842
Reviewed-on: https://go-review.googlesource.com/c/go/+/710676
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
2025-10-14 12:20:23 -07:00
Bill Roberts
11d3d2f77d cmd/internal/obj/arm64: add support for PAC instructions
Add support for the Pointer Authentication Code instructions
required for the ELF ABI when enabling PAC aware binaries.

This allows for assembly writers to add PAC instructions where needed to
support this ABI. Follow up work is to enable the compiler to emit these
instructions in the appropriate places.

The TL;DR for the Linux ABI is that the prologue of a function that
pushes the link register (LR) to the stack, signs the LR with a key
managed by the operating system and hardware using a PAC instruction,
like "paciasp". The function epilog, when restoring the LR from the
stack will verify the signature, using an instruction like "autiasp".

This helps prevents attackers from modifying the return address on the
stack, a common technique for ROP attacks.

Details on PAC can be found here:
  - https://community.arm.com/arm-community-blogs/b/architectures-and-processors-blog/posts/enabling-pac-and-bti-on-aarch64
  - https://developer.arm.com/documentation/109576/0100/Pointer-Authentication-Code

The ABI details can be found here:
  - https://github.com/ARM-software/abi-aa/blob/main/aaelf64/aaelf64.rst

Change-Id: I4516ed1294d19f9ff9d278833d542821b6642aa9
Reviewed-on: https://go-review.googlesource.com/c/go/+/676675
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Joel Sing <joel@sing.id.au>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2025-10-14 12:00:00 -07:00
Mateusz Poliwczak
4dbf1a5a4c cmd/compile/internal/devirtualize: do not track assignments to non-PAUTO
We do not lookup/devirtualize such, so we can skip tracking them.

Change-Id: I8bdb0b11c694e4b2326c236093508a356a6a6964
Reviewed-on: https://go-review.googlesource.com/c/go/+/711160
Reviewed-by: Keith Randall <khr@golang.org>
Auto-Submit: Keith Randall <khr@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@google.com>
2025-10-14 11:31:45 -07:00
Mateusz Poliwczak
0ddb5ed465 cmd/compile/internal/devirtualize: use FatalfAt instead of Fatalf where possible
Change-Id: I5e9e9c89336446720c3c21347969e4126a6a6964
Reviewed-on: https://go-review.googlesource.com/c/go/+/711140
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Auto-Submit: Keith Randall <khr@golang.org>
2025-10-14 11:31:42 -07:00
Damien Neil
0a239bcc99 Revert "net/url: disallow raw IPv6 addresses in host"
This reverts commit e3be2d1b2b.

Reason for revert: Causes extensive failures in Google-internal testing.

Change-Id: I232f547fc326dff7df959d25f3a89777ea33b201
Reviewed-on: https://go-review.googlesource.com/c/go/+/711800
Auto-Submit: Damien Neil <dneil@google.com>
Reviewed-by: Sean Liao <sean@liao.dev>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
2025-10-14 10:43:46 -07:00
Mateusz Poliwczak
5a9ef44bc0 cmd/compile/internal/devirtualize: fix OCONVNOP assertion
Fixes #75863

Change-Id: I1e5a0f3880dcd5f820a5b6f4540c49b16a6a6964
Reviewed-on: https://go-review.googlesource.com/c/go/+/711141
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Lasse Folger <lassefolger@google.com>
Auto-Submit: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-10-14 09:33:37 -07:00
Robert Griesemer
3765758b96 go/types, types2: minor cleanup (remove TODO)
Follow-up to CL 711420.

Change-Id: If577e96f413e46b98dd86d11605de1004637851a
Reviewed-on: https://go-review.googlesource.com/c/go/+/711540
Reviewed-by: Robert Griesemer <gri@google.com>
Reviewed-by: Mark Freeman <markfreeman@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-10-14 08:50:15 -07:00
Filippo Valsorda
f6b9d56aff crypto/internal/fips140/entropy: fix benign race
Fixes #75690
Fixes #75842

Change-Id: I6a6a696420f51f28f48535c34cf347e2cbd4add5
Reviewed-on: https://go-review.googlesource.com/c/go/+/710058
Auto-Submit: Filippo Valsorda <filippo@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Roland Shoemaker <roland@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-10-14 07:57:03 -07:00
Filippo Valsorda
60f6d2f623 crypto/internal/fips140/entropy: support SHA-384 sizes for ACVP tests
Change-Id: I6a6a6964decc662d753ee3eec357570bd3c95e2d
Reviewed-on: https://go-review.googlesource.com/c/go/+/710056
Auto-Submit: Filippo Valsorda <filippo@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Roland Shoemaker <roland@golang.org>
Reviewed-by: Nooras Saba‎ <noorassaba@google.com>
Reviewed-by: Daniel McCarney <daniel@binaryparadox.net>
2025-10-14 07:56:59 -07:00
Joe Tsai
6fd8e88d07 encoding/json/v2: restrict presence of default options
Originally, DefaultOptionsV1 and DefaultOptionsV2 represented
the full set of all options with specific ones set to true or false.

However, there are certain options such as WithIndent or WithMarshalers
that are neither v1 or v2 specific.
At some point we removed whitespace related options from the set:
https://github.com/go-json-experiment/json/pull/26

This avoids DefaultOptionsV1 or DefaultOptionsV2 from affecting
any previously set whitespace. However, why are whitespace options
special and thus excluded from the set? What about Marshalers?

As a more principaled way to address this, we restrict
DefaultOptionsV1 and DefaultOptionsV2 to only be the options
where the default setting changes between v1 and v2.
All other options are unpopulated.

This avoids a panic with GetOption(DefaultOptionsV2, WithMarshalers)
since DefaultOptionsV2 previously had the presence bit for
Marshalers set to true, but had no actual value.
Now, the presence bit is set to false, so the value is not consulted.

Fixes #75149

Change-Id: I30b45abd35404578b4135cc3bad1a1a2993cb0cf
Reviewed-on: https://go-review.googlesource.com/c/go/+/710878
Reviewed-by: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Damien Neil <dneil@google.com>
2025-10-13 17:01:45 -07:00
Robert Griesemer
1abc6b0204 go/types, types2: permit type cycles through type parameter lists
Issue #49439 was about a deadlock during type inference inside
a type parameter list of a recursive constraint. As a remedy
we disallowed recursive type parameter lists.

In the meantime we have removed support for type inference for
type arguments to generic types; the Go 1.18 generic release
didn't support it.

As a consequence, the fix for #49439, CL 361922, is probably
not needed anymore: cycles through type parameter lists are ok.

Fixes #68162.
For #49439.

Change-Id: Ie9deb3274914d428e8e45071cee5e68abf8afe9c
Reviewed-on: https://go-review.googlesource.com/c/go/+/711420
Commit-Queue: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
Reviewed-by: Mark Freeman <markfreeman@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
TryBot-Bypass: Robert Griesemer <gri@google.com>
2025-10-13 14:27:13 -07:00
Russ Cox
9fdd6904da strconv: add tests that Java once mishandled
Change-Id: I372233d8494665b3300f9a186c883a4254435e1c
Reviewed-on: https://go-review.googlesource.com/c/go/+/710617
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: David Chase <drchase@google.com>
2025-10-13 12:35:20 -07:00
Keith Randall
9b8742f2e7 cmd/compile: don't depend on arch-dependent conversions in the compiler
Leave those constant foldings for runtime, similar to how we do it
for NaN generation.

These are the only instances I could find in cmd/compile/..., using

objdump -d ../pkg/tool/darwin_arm64/compile| egrep "(fcvtz|>:)" | grep -B1 fcvt

(There are instances in other places, like runtime and reflect, but I don't
think those places would affect compiler output.)

Change-Id: I4113fe4570115e4765825cf442cb1fde97cf2f27
Reviewed-on: https://go-review.googlesource.com/c/go/+/711281
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Keith Randall <khr@google.com>
2025-10-13 12:19:32 -07:00
Joe Tsai
0e64ee1286 encoding/json/v2: report EOF for top-level values in UnmarshalDecode
The fully streaming UnmarshalJSONFrom method and UnmarshalFromFunc
introduce an edge case where they can encounter EOF in the stream,
where it should be reported upstream as EOF rather than
ErrUnexpectedEOF or be wrapped within a SemanticError.

This is not possible with other unmarshal methods since the
"json" package would read the appropriate JSON value
before calling the custom method or function.

To avoid custom unmarshal methods from encountering EOF,
check whether the stream is already at EOF for top-level values
before calling the custom method.

Also, when wrapping EOF within a SemanticError, convert it
to ErrUnexpectedEOF to better indicate that this is unexpected.

Fixes #75802

Change-Id: I001396734b7e95b5337f77b71326284974ee730a
Reviewed-on: https://go-review.googlesource.com/c/go/+/710877
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
Reviewed-by: Carlos Amedee <carlos@golang.org>
2025-10-13 10:44:23 -07:00
Julien Cretel
6bcd97d9f4 all: replace calls to errors.As with errors.AsType
This change replaces most occurrences (in code as well as in comments) of
errors.As with errors.AsType. It leaves the errors package and vendored
code untouched.

Change-Id: I3bde73f318a0b408bdb8f5a251494af15a13118a
GitHub-Last-Rev: 8aaaa36a5a
GitHub-Pull-Request: golang/go#75698
Reviewed-on: https://go-review.googlesource.com/c/go/+/708495
Auto-Submit: Michael Pratt <mpratt@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
2025-10-13 10:12:48 -07:00
Roland Shoemaker
1cd71689f2 crypto/x509: rework fix for CVE-2025-58187
In CL 709854 we enabled strict validation for a number of properties of
domain names (and their constraints). This caused significant breakage,
since we didn't previously disallow the creation of certificates which
contained these malformed domains.

Rollback a number of the properties we enforced, making domainNameValid
only enforce the same properties that domainToReverseLabels does. Since
this also undoes some of the DoS protections our initial fix enabled,
this change also adds caching of constraints in isValid (which perhaps
is the fix we should've initially chosen).

Updates #75835
Fixes #75828

Change-Id: Ie6ca6b4f30e9b8a143692b64757f7bbf4671ed0e
Reviewed-on: https://go-review.googlesource.com/c/go/+/710735
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Damien Neil <dneil@google.com>
2025-10-11 16:12:44 -07:00
Cherry Mui
8aa1efa223 cmd/link: in TestFallocate, only check number of blocks on Darwin
The number-of-blocks check was introduced when fixing a Darwin-
specific bug. On Darwin, the file allocation syscall is a bit
tricky. On Linux and BSDs, it is more straightforward and unlikely
to go wrong.

The test itself, on the other hand, is less reliable on Linux (and
perhaps BSDs), as it is considered less portable and is an
implementation detail of the file system.

Given these two reasons, only check it on Darwin.

Fixes #75795.

Change-Id: I3da891fd60a141c3eca5d0f5ec20c2cad65b8862
Reviewed-on: https://go-review.googlesource.com/c/go/+/711095
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
2025-10-11 08:51:54 -07:00
Joe Tsai
b497a29d25 encoding/json: fix regression in quoted numbers under goexperiment.jsonv2
The legacy parsing of quoted numbers in v1 was according to
the Go grammar for a number, rather than
the JSON grammar for a number.
The former is a superset of the latter.

This is a historical mistake, but usages exist that depend on it.
We already have branches for StringifyWithLegacySemantics
to handle quoted nulls, so we can expand it to handle this.

Fixes #75619

Change-Id: Ic07802539b7cbe0e1f53bd0f7e9bb344a8447203
Reviewed-on: https://go-review.googlesource.com/c/go/+/709615
Reviewed-by: Damien Neil <dneil@google.com>
Auto-Submit: Joseph Tsai <joetsai@digital-static.net>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
2025-10-10 18:03:36 -07:00
David Chase
48bb7a6114 cmd/compile: repair bisection behavior for float-to-unsigned conversion
My stab at a bisect-reproducer failed, but I verified that
it fixed the problem described in the issue.

Updates #75834

Change-Id: I9e0dfacd2bbd22cbc557e144920ee3417a48088c
Reviewed-on: https://go-review.googlesource.com/c/go/+/710997
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
2025-10-10 16:21:25 -07:00
Michael Anthony Knyszek
e8a53538b4 runtime: fail TestGoroutineLeakProfile on data race
Some of the programs in testdata/testgoroutineleakprofile have data
races because they were taken from a corpus that showcases general Go
concurrency bugs, not just leaked goroutines.

This causes some flakiness as tests might fail due to, for example, a
concurrent map access, even outside of race mode.

Let's just call data races a failure and fix them in the examples. As
far as I can tell, there are only two that show up consistently.

Fixes #75732.

Change-Id: I160b3a1cdce4c2de3f2320b68b4083292e02b557
Reviewed-on: https://go-review.googlesource.com/c/go/+/710756
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Carlos Amedee <carlos@golang.org>
Auto-Submit: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
2025-10-10 15:58:20 -07:00
Sean Liao
e3be2d1b2b net/url: disallow raw IPv6 addresses in host
RFC 3986 requires square brackets around IPv6 addresses.
Parse's acceptance of raw IPv6 addresses is non compliant,
and complicates splitting out a port.

Fixes #31024
Fixes #75223

Change-Id: I477dc420a7441cb33156627dbd5e46d88c677f1e
Reviewed-on: https://go-review.googlesource.com/c/go/+/710176
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
2025-10-10 14:47:41 -07:00
Sean Liao
aced4c79a2 net/http: strip request body headers on POST to GET redirects
According to WHATWG Fetch, when the body is dropped in a redirect,
headers that describe the body should also be dropped.
https://fetch.spec.whatwg.org/#http-redirect-fetch

Fixes #57273

Change-Id: I84598f69608e95c1b556ea0ce5953ed43bf2d824
Reviewed-on: https://go-review.googlesource.com/c/go/+/710395
Auto-Submit: Damien Neil <dneil@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-10-10 14:39:53 -07:00
cuishuang
584a89fe74 all: omit unnecessary reassignment
The new version of Go has been optimized, and variables do not need
to be reassigned.

Change-Id: I0374b049271e53510f2b162f6821fb3595f2c8ff
Reviewed-on: https://go-review.googlesource.com/c/go/+/710835
Auto-Submit: Michael Pratt <mpratt@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
2025-10-10 14:38:27 -07:00