1
0
mirror of https://github.com/golang/go synced 2024-11-26 19:41:19 -07:00
Commit Graph

47257 Commits

Author SHA1 Message Date
Kevin Burke
80157b5144 crypto/x509: fix spelling error
Change-Id: Ieb1900531f42acf2c8b98ac89fceb8b87c8e5d0c
Reviewed-on: https://go-review.googlesource.com/c/go/+/304609
Reviewed-by: Roland Shoemaker <roland@golang.org>
Trust: Kevin Burke <kev@inburke.com>
2021-03-25 00:15:42 +00:00
Dan Scales
e7e0995cba cmd/compile: create/use noder2 transform functions for more node types
Pull out the transformation part of the typechecking functions for:
 - assignment statements
 - return statements
 - send statements
 - select statements
 - type conversions
 - normal function/method calls
 - index operations

The transform functions are like the original typechecking functions,
but with all code removed related to:
  - Detecting compile-time errors (already done by types2)
  - Setting the actual type of existing nodes (already done based on
    info from types2)
  - Dealing with untyped constants

Moved all the transformation functions to a separate file, transform.go.

Continuing with the same pattern, we delay transforming a node if it has
any type params in its args, marking it with a typecheck flag of 3, and
do the actual transformation during stenciling.

Assignment statements are tricky, since their transformation must be
delayed if any of the left or right-hands-sides are delayed.

Still to do are:
 - selector expressions (OXDOT)
 - composite literal expressions (OCOMPLIT)
 - builtin function calls

Change-Id: Ie608cadbbc69b40db0067a5536cf707dd974aacc
Reviewed-on: https://go-review.googlesource.com/c/go/+/304049
Run-TryBot: Dan Scales <danscales@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Dan Scales <danscales@google.com>
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-03-25 00:06:23 +00:00
Ian Lance Taylor
29ed12d4c7 testing: update permitted number of -race goroutines
The value 8128 appears to be correct as of 2021-03-23. The value is
determined by the value of kMaxTid currently at

https://github.com/llvm/llvm-project/blob/main/compiler-rt/lib/tsan/rtl/tsan_defs.h#L68

Fixes #45193

Change-Id: If4a30d7dbebd6775bede42f565dc8a741b8b036c
Reviewed-on: https://go-review.googlesource.com/c/go/+/304254
Trust: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Dmitry Vyukov <dvyukov@google.com>
2021-03-24 21:51:22 +00:00
Ian Lance Taylor
179bcd787e test: only run bug513.go if cgo is enabled
Change-Id: I868eeb79edaba9e3afc1407ae18b89daf7e67037
Reviewed-on: https://go-review.googlesource.com/c/go/+/304570
Trust: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-03-24 21:20:10 +00:00
Ian Lance Taylor
63e9f6d5f0 test: recognize cgo build tag
This requires us to add a fake argument to issue36705.go so that the
test driver will build it with "go run" rather than "go tool compile".

Change-Id: Id08b97d898ee3e9d6c1fbb072a0a9317ed9faedd
Reviewed-on: https://go-review.googlesource.com/c/go/+/304569
Trust: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2021-03-24 21:19:57 +00:00
Dmitri Shuralyov
dade83a588 cmd/internal/moddeps: fix false positive when $TMPDIR is symlinked
os.Getwd notes that if the current directory can be reached via
multiple paths (due to symbolic links), Getwd may return any one
of them. A way to ensure that the desired path is used is to set
the PWD environment variable pointing to it.

The go generate command has started to update the PWD environment
variable as of CL 287152, which was the missing link previously
resulting in mkwinsyscall misunderstanding whether it's inside
the std lib when symbolic links are involved (issue 44079).

Now all that's left is for us to also set the PWD environment
variable when invoking the go command in the test, so that it
too knows the intended working directory path to use.

Fixes #44080.
Updates #44079.
Updates #43862.

Change-Id: I65c9d19d0979f486800b9b328c9b45a1a3180e81
Reviewed-on: https://go-review.googlesource.com/c/go/+/304449
Trust: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
2021-03-24 20:19:44 +00:00
Michael Anthony Knyszek
fef5a15396 runtime: bypass ABI wrapper when calling needm on Windows
On Windows, when calling into needm in cgocallback on a new thread that
is unknown to the Go runtime, we currently call through an ABI wrapper.
The ABI wrapper tries to restore the G register from TLS.

On other platforms, TLS is set up just enough that the wrapper will
simply load a nil g from TLS, but on Windows TLS isn't set up at all, so
there's nowhere for the wrapper to load from.

So, bypass the wrapper in the call to needm. needm takes no arguments
and returns no results so there are no special ABI considerations,
except that we must clear X15 which is used as a zero register in Go
code (a function normally performed by the ABI wrapper). needm is also
otherwise already special and carefully crafted to avoid doing anything
that would require a valid G or M, at least until it is able to create
one.

While we're here, this change simplifies setg so that it doesn't set up
TLS on Windows and instead provides an OS-specific osSetupTLS to do
that.

The result of this is that setg(nil) no longer clears the TLS space
pointer on Windows. There's exactly one place this is used (dropm) where
it doesn't matter anymore, and an empty TLS means that setg's wrapper
will crash on the return path. Another result is that the G slot in the
TLS will be properly cleared, however, which isn't true today.

For #40724.

Change-Id: I65c3d924a3b16abe667b06fd91d467d6d5da31d7
Reviewed-on: https://go-review.googlesource.com/c/go/+/303070
Trust: Michael Knyszek <mknyszek@google.com>
Run-TryBot: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2021-03-24 19:18:50 +00:00
Keith Randall
771c57e68e cmd/compile: disable shortcircuit optimization for intertwined phi values
We need to be careful that when doing value graph surgery, we not
re-substitute a value that has already been substituted. That can lead
to confusing a previous iteration's value with the current iteration's
value.

The simple fix in this CL just aborts the optimization if it detects
intertwined phis (a phi which is the argument to another phi). It
might be possible to keep the optimization with a more complicated
CL, but:
  1) This CL is clearly safe to backport.
  2) There were no instances of this abort triggering in
     all.bash, prior to the test introduced in this CL.

Fixes #45175

Change-Id: I2411dca03948653c053291f6829a76bec0c32330
Reviewed-on: https://go-review.googlesource.com/c/go/+/304251
Trust: Keith Randall <khr@golang.org>
Trust: Josh Bleecher Snyder <josharian@gmail.com>
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2021-03-24 17:54:03 +00:00
Cherry Zhang
fd5e0bd385 cmd/link: mangle function names with ABI on PE
When ABI wrappers are used, we may end up with two functions
having the same name. On ELF we mangle the name with ABI. Do the
same for PE.

TODO: other platforms?

Change-Id: If89f214a6286bc28c062c1aa1bad78dc353a9231
Reviewed-on: https://go-review.googlesource.com/c/go/+/304432
Trust: Cherry Zhang <cherryyz@google.com>
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
2021-03-24 16:45:00 +00:00
Damien Neil
6f62f852ef net/http: fix request cancellation race
When a in-flight request is cancelled, (*Transport).cancelRequest is
called. The cancelRequest function looks up and invokes a cancel
function before returning. The function lookup happens with reqMu held,
but the cancel function is invoked after dropping the mutex.

If two calls to cancelRequest are made at the same time, it is possible
for one to return before the cancel function has been invoked.

This race causes flakiness in TestClientTimeoutCancel:
  - The test cancels a request while a read from the request body is
    pending.
  - One goroutine calls (*Transport).cancelRequest. This goroutine
    will eventually invoke the cancel function.
  - Another goroutine calls (*Transport).cancelRequest and closes the
    request body. The cancelRequest call returns without invoking
    the cancel function.
  - The read from the request body returns an error. The reader
    checks to see if the request has been canceled, but concludes
    that it has not (because the cancel function hasn't been invoked
    yet).

To avoid this race condition, call the cancel function with the
transport reqMu mutex held.

Calling the cancel function with the mutex held does not introduce any
deadlocks that I can see. The only non-noop request cancel functions
are:

A send to a buffered channel:
https://go.googlesource.com/go/+/refs/heads/master/src/net/http/transport.go#1362

The (*persistConn).cancelRequest function, which does not cancel any
other requests:
https://go.googlesource.com/go/+/refs/heads/master/src/net/http/transport.go#2526

Fixes #34658.

Change-Id: I1b83dce9b0b1d5cf7c7da7dbd03d0fc90c9f5038
Reviewed-on: https://go-review.googlesource.com/c/go/+/303489
Trust: Damien Neil <dneil@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
2021-03-24 16:26:07 +00:00
Cherry Zhang
0e31de280f math/big: don't require runtime.(*Frame).Next symbol present
I don't know why the test requires runtime.(*Frame).Next symbol
present in the binary under test. I assume it is just some
sanity check? With CL 268479 runtime.(*Frame).Next can be pruned
by the linker. Replace it with runtime.main which should always
be present.

May fix the longtest builders.

Change-Id: Id3104c058b2786057ff58be41b1d35aeac2f3073
Reviewed-on: https://go-review.googlesource.com/c/go/+/304431
Trust: Cherry Zhang <cherryyz@google.com>
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
2021-03-24 15:51:26 +00:00
Paul E. Murphy
975b097307 cmd/link: separate elf addend size from reloc size
The size of the field may be smaller than the addend,
such is the case with R_PPC64_TOC16_HA/LO and similar
relocations.

Add an extra return value to ldelf.relSize to account for
addend size which may be larger than the relocated field,
and fix the related ppc64 relocations.

Such relocs can be seen in large PIC blobs such
as the ppc64le race detector included with golang.

Change-Id: I457186fea5d0ec5572b9bbf79bb7fa21a36cc1b0
Reviewed-on: https://go-review.googlesource.com/c/go/+/303990
Run-TryBot: Paul Murphy <murp@ibm.com>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Reviewed-by: Lynn Boger <laboger@linux.vnet.ibm.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Lynn Boger <laboger@linux.vnet.ibm.com>
2021-03-24 14:52:14 +00:00
Cherry Zhang
e8700f1ce6 cmd/compile, cmd/link: use weak reference in itab
When converting a type T to a non-empty interface I, we build the
itab which contains the code pointers of the methods. Currently,
this brings those methods live (if the itab is live), even if the
interface method is never used. This CL changes the itab to use
weak references, so the methods can be pruned if not otherwise
live.

Fixes #42421.

Change-Id: Iee5de2ba11d603c5a102a2ba60440d839a7f9702
Reviewed-on: https://go-review.googlesource.com/c/go/+/268479
Trust: Cherry Zhang <cherryyz@google.com>
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
2021-03-24 14:38:53 +00:00
Paul E. Murphy
747f426944 cmd/internal/obj: remove bogus load/store optab entries from ppc64
No valid operation should match those removed by this patch. They
kind of look as if they match X-form load/stores on ppc64, but the
second argument is always ignored when translating to machine code.

Similarly, it should be noted an X-form memory access encodes into
an Addr which is a classified as a ZOREG argument with a non-zero
index, and a register type Addr.

Change-Id: I1adbb020d1b2612b18949d0e7eda05dbb3e8a25c
Reviewed-on: https://go-review.googlesource.com/c/go/+/303329
Reviewed-by: Carlos Eduardo Seo <carlos.seo@linaro.org>
Reviewed-by: Lynn Boger <laboger@linux.vnet.ibm.com>
Run-TryBot: Paul Murphy <murp@ibm.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Carlos Eduardo Seo <carlos.seo@linaro.org>
2021-03-24 14:20:32 +00:00
Jay Conrod
d8960e65a2 cmd/go: move psuedo-version and version sorting to x/mod
Fixes #44969

Change-Id: I01e7b1cf73f0f506aa805bbfe4a9ccaed3d44efe
Reviewed-on: https://go-review.googlesource.com/c/go/+/304229
Trust: Jay Conrod <jayconrod@google.com>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
2021-03-24 13:54:14 +00:00
Tobias Klauser
2e94401277 os/exec: use testenv.SkipFlaky in TestExtraFilesFDShuffle
Change-Id: Icc1980ea0f6363c667bf91371404a8df6ed6b8ab
Reviewed-on: https://go-review.googlesource.com/c/go/+/303950
Trust: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
2021-03-24 05:15:53 +00:00
David Chase
4357f71ca7 cmd/compile: remove more dead code and data structures
Remove more now-redundant code, methods, and types
associated with transition to register ABI.
Repaired some broken comments.

Tested on link-register architectures (arm64, ppc64le)

Updates #40724.

Change-Id: Ie8433f6d38ec4a1d9705f22dcb596f267d81f203
Reviewed-on: https://go-review.googlesource.com/c/go/+/304189
Trust: David Chase <drchase@google.com>
Run-TryBot: David Chase <drchase@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2021-03-24 03:16:14 +00:00
David Chase
14ef2d8c01 cmd/compile: fix array case in types-for-register parameter
Corrected typo/thinko.

We should keep the test for this, but it doesn't run yet because of reflection
as far as I know (but I am not testing w/ GOEXPERIMENT).

See https://github.com/golang/go/issues/44816#issuecomment-805297295

Updates #40724
Updates #44816

Change-Id: Ia12d0d4db00a8ec7174e72de460173876bd17874
Reviewed-on: https://go-review.googlesource.com/c/go/+/304233
Trust: David Chase <drchase@google.com>
Run-TryBot: David Chase <drchase@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2021-03-24 03:03:18 +00:00
Ian Lance Taylor
87a3ac5f53 cmd/compile: don't let -race override explicit -d=checkptr=0
Change-Id: Icfa204761045b72a8ea173fd55eddf1f0e58d819
Reviewed-on: https://go-review.googlesource.com/c/go/+/304253
Trust: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2021-03-23 23:09:33 +00:00
Than McIntosh
769d4b68ef cmd/compile: wrap/desugar defer calls for register abi
Adds code to the compiler's "order" phase to rewrite go and defer
statements to always be argument-less. E.g.

 defer f(x,y)       =>     x1, y1 := x, y
			   defer func() { f(x1, y1) }

This transformation is not beneficial on its own, but it helps
simplify runtime defer handling for the new register ABI (when
invoking deferred functions on the panic path, the runtime doesn't
need to manage the complexity of determining which args to pass in
register vs memory).

This feature is currently enabled by default if GOEXPERIMENT=regabi or
GOEXPERIMENT=regabidefer is in effect.

Included in this CL are some workarounds in the runtime to insure that
"go" statement targets in the runtime are argument-less already (since
wrapping them can potentially introduce heap-allocated closures, which
are currently not allowed). The expectation is that these workarounds
will be temporary, and can go away once we either A) change the rules
about heap-allocated closures, or B) implement some other scheme for
handling go statements.

Change-Id: I01060d79a6b140c6f0838d6e6813f807ccdca319
Reviewed-on: https://go-review.googlesource.com/c/go/+/298669
Trust: Than McIntosh <thanm@google.com>
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Reviewed-by: David Chase <drchase@google.com>
2021-03-23 23:08:19 +00:00
Shuhei Takahashi
4e27aa6cd2 os/exec: simplify TestContextCancel
TestContextCancel is a test that ensures a process is killed soon after
canceling the context, even if Wait is not called (#16222). The test
checks whether the process exited without calling Wait by writing some
data to its stdin.

Currently the test involves two goroutines writing to stdin and reading
from stdout. However the reading goroutine is not very necessary to
detect the process exit.

This patch simplifies the test by connecting the process stdout to
/dev/null.

For #42061

Change-Id: I0447a1c024ee5abb050c627ec3766b731b02181a
Reviewed-on: https://go-review.googlesource.com/c/go/+/303352
Trust: Emmanuel Odeke <emmanuel@orijtech.com>
Run-TryBot: Emmanuel Odeke <emmanuel@orijtech.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2021-03-23 22:36:59 +00:00
Simão Gomes Viana
dc289d3dcb io: fix spelling in documentation for io.Discard
In the process of refactoring ioutil.Discard to io.Discard in
CL 263141 "an" should have been changed to "a" but was likely
missed in the process.

This commit corrects the spelling of the documentation.

Change-Id: I0609c45878291f8f01560efc3f3e6fba191e095b
GitHub-Last-Rev: e3257ca272
GitHub-Pull-Request: golang/go#45190
Reviewed-on: https://go-review.googlesource.com/c/go/+/304209
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
Trust: Robert Griesemer <gri@golang.org>
2021-03-23 22:17:52 +00:00
Than McIntosh
2887ef499a cmd/compile/internal/test: update abi tests for recent spec changes
The internal ABI spec was recently updated to include specific
language covering "past-the-end" pointers and structs containing
trailing zero-sized fields. Add a unit test that makes sure we do the
right thing in this case. Fix a couple comments in other unit tests.

Change-Id: I18d373d11e122aec74b316837843887272676c63
Reviewed-on: https://go-review.googlesource.com/c/go/+/303809
Trust: Than McIntosh <thanm@google.com>
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
2021-03-23 19:05:35 +00:00
Daniel Martí
c59b17e5a2 cmd/go: make -coverpkg=all skip test-only packages
Otherwise, the added test would fail in an unnecessary way:

	go build example.com/cov/onlytest: no non-test Go files ...

The test script is mimicking other cover_pkgall_*.txt scripts, so it
similarly tests both GOPATH and module modes.

Fixes #27333.

Change-Id: Ie60be569b31d49b173a78556c0669a87ada6799e
Reviewed-on: https://go-review.googlesource.com/c/go/+/288292
Trust: Daniel Martí <mvdan@mvdan.cc>
Trust: Jay Conrod <jayconrod@google.com>
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
2021-03-23 18:14:47 +00:00
Artur M. Wolff
05250429ae net/http: treat MaxBytesReader's negative limits as equivalent to zero limit
Current MaxBytesReader behaviour differs from its documentation. It's
not similar enough to io.LimitReader. It panics when limit (n) < -1 and
returns [-1, <nil>] when limit (n) = -1. To fix that, we treat all
negative limits as equivalent to 0.

It would be possible to make MaxBytesReader analogically identical in
behaviour to io.LimitReader, but that would require to stop
maxBytesReader's Read from reading past the limit. Read always reads one
more byte (if possible) for non-negative limits and returns a non-EOF
error. This behaviour will now apply to all limits.

Fixes #45101

Change-Id: I25d1877dbff1eb4b195c8741fe5e4a025d01ebc0
Reviewed-on: https://go-review.googlesource.com/c/go/+/303171
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Trust: Damien Neil <dneil@google.com>
Trust: Dmitri Shuralyov <dmitshur@golang.org>
Run-TryBot: Damien Neil <dneil@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-03-23 17:46:42 +00:00
David Chase
9b78c68a15 cmd/compile: remove AuxCall.results, cleanup ssagen/ssa.go
More cleanup to remove unnecessary parts of AuxCall.
Passed testing on arm64 (a link-register architecture)
in addition to amd64 so very likely okay.

(Gratuitously updated commit message to see if it will
correctly this time.)

Updates #40724

Change-Id: Iaece952ceb5066149a5d32aaa14b36755f26bb8e
Reviewed-on: https://go-review.googlesource.com/c/go/+/303433
Trust: David Chase <drchase@google.com>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2021-03-23 16:47:43 +00:00
Zhang Boyang
53dd0d7809 net: make go resolver aware of network parameter
Currently, the go resolver always send two DNS queries (A and AAAA) even
if tcp4/udp4/ip4 or tcp6/udp6/ip6 is used. This can cause unwanted
latencies when making IPv4-only or IPv6-only connections.

This change make go resolver aware of network parameter. Now, only one A
query is sent when tcp4/udp4/ip4 is used, and vice versa for
tcp6/udp6/ip6.

Fixes #45024

Change-Id: I815f909e6df5f7242cfc900f7dfecca628c3a2c8
GitHub-Last-Rev: 3d30c486de
GitHub-Pull-Request: golang/go#45016
Reviewed-on: https://go-review.googlesource.com/c/go/+/301709
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Trust: Emmanuel Odeke <emmanuel@orijtech.com>
2021-03-23 11:14:58 +00:00
Robert Griesemer
f4b918384d test: enable fixedbugs/bug193.go for -G compiler option
Temporarily disable a questionable test case in fixedbugs/bug193.go
and enable the test as a whole. See the issues below for details.

Updates #45114.
Updates #45117.

Change-Id: I1de6f8d79b592eeeec139cd92b6c9cac56a9a74b
Reviewed-on: https://go-review.googlesource.com/c/go/+/303094
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
2021-03-23 05:12:39 +00:00
Robert Griesemer
cd26192aba go/types: remove superfluous code for shift checking
Negative constant shift counts are already handled
earlier in the code. No need anymore for this extra
section.

With this change, the shift code matches types2
with respect to the function logic.

Change-Id: Ic8b7f382271c79ab66021e30955cd9bac092332b
Reviewed-on: https://go-review.googlesource.com/c/go/+/303093
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-03-23 05:12:12 +00:00
Robert Griesemer
e7aa0f9f28 go/types, types2: add a test case for shifts that used to fail
For #42989.

Change-Id: Ic354edde23ed7bfb4cb3eec2794f7213ed862b47
Reviewed-on: https://go-review.googlesource.com/c/go/+/303090
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-03-23 05:11:39 +00:00
Robert Griesemer
8f19394b62 cmd/compile/internal/types2: refactor untyped conversions
Based on https://golang.org/cl/284256 for go/types.
Brings this code more in line with go/types.

Adjusted various tests to match new error messages which
generally are now better: for assignment errors, instead
of a generic "cannot convert" we now say "cannot use"
followed by a clearer reason as to why not.

Major differences to go/types with respect to the changed
files:

- Some of the new code now returns error codes, but they
  are only used internally for now, and not reported with
  errors.

- go/types does not "convert" untyped nil values to target
  types, but here we do. This is unchanged from how types2
  handled this before this CL.

Change-Id: If45336d7ee679ece100f6d9d9f291a6ea55004d8
Reviewed-on: https://go-review.googlesource.com/c/go/+/302757
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-03-23 05:11:09 +00:00
Dan Scales
0265b6475f cmd/compile: replace calls to typecheck with transform functions
For additions, compares, and slices, create transform functions that do
just the transformations for those nodes by the typecheck package (given
that the code has been fully typechecked by types2). For nodes that have
no args with typeparams, we call these transform functions directly in
noder2. But for nodes that have args with typeparams, we have to delay
and call the tranform functions during stenciling, since we don't know
the specific types involved.

We indicate that a node still needs transformation by setting Typecheck
to a new value 3. This value means the current type of the node has been
set (via types2), but the node may still need transformation.

Had to export typcheck.IsCmp and typecheck.Assignop from the typecheck
package.

Added new tests list2.go (required delaying compare typecheck/transform
because of != compare in checkList) and adder.go (requires delaying add
typecheck/transform, since it can do addition for numbers or strings).

There are several more transformation functions needed for expressions
(indexing, calls, etc.) and several more complicated ones needed for
statements (mainly various kinds of assignments).

Change-Id: I7d89d13a4108308ea0304a4b815ab60b40c59b0a
Reviewed-on: https://go-review.googlesource.com/c/go/+/303091
Run-TryBot: Dan Scales <danscales@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Dan Scales <danscales@google.com>
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-03-23 04:23:52 +00:00
Jason A. Donenfeld
b8371d495b runtime: support long paths without fixup on Windows 10 >= 1607
Windows 10 >= 1607 allows CreateFile and friends to use long paths if
bit 0x80 of the PEB's BitField member is set.

In time this means we'll be able to entirely drop our long path hacks,
which have never really worked right (see bugs below). Until that point,
we'll simply have things working well on recent Windows.

Updates #41734.
Updates #21782.
Updates #36375.

Change-Id: I765de6ea4859dd4e4b8ca80af7f337994734118e
Reviewed-on: https://go-review.googlesource.com/c/go/+/291291
Trust: Jason A. Donenfeld <Jason@zx2c4.com>
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2021-03-23 03:49:17 +00:00
fanzha02
b182ba7fab cmd/compile: optimize codes with arm64 REV16 instruction
Optimize some patterns into rev16/rev16w instruction.

Pattern1:
    (c & 0xff00ff00)>>8 | (c & 0x00ff00ff)<<8
To:
    rev16w c

Pattern2:
    (c & 0xff00ff00ff00ff00)>>8 | (c & 0x00ff00ff00ff00ff)<<8
To:
    rev16 c

This patch is a copy of CL 239637, contributed by Alice Xu(dianhong.xu@arm.com).

Change-Id: I96936c1db87618bc1903c04221c7e9b2779455b3
Reviewed-on: https://go-review.googlesource.com/c/go/+/268377
Trust: fannie zhang <Fannie.Zhang@arm.com>
Run-TryBot: fannie zhang <Fannie.Zhang@arm.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2021-03-23 01:36:23 +00:00
eric fang
d25476ebb2 cmd/internal/obj/arm64: fix constant pool size calculation error
The current calculation method of constant pool size is:
  c.pool.size = -c.pool.size & (funcAlign - 1)
  c.pool.size += uint32(sz)
This doesn't make sense. This CL changes it as:
  if q.As == ADWORD {
    c.pool.size = roundUp(c.pool.size, 8)
  }
  c.pool.size += uint32(sz)
which takes into account the padding size generated by aligning DWORD to
8 bytes.

It's unnecessary to set the Pc field in addpool and addpool128 because
the Pc value will be reset in function span7, so remove the related lines.

Change-Id: I5eb8f259be55a6b97fc2c20958b4a602bffa4f88
Reviewed-on: https://go-review.googlesource.com/c/go/+/298609
Reviewed-by: eric fang <eric.fang@arm.com>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Trust: eric fang <eric.fang@arm.com>
Run-TryBot: eric fang <eric.fang@arm.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-03-23 01:21:24 +00:00
Than McIntosh
c819907754 cmd/{compile,link}: relocate generation of DWARF for global vars
Move DWARF generation for global variables from the linker to the
compiler. This effectively parallelizes this part of DWARF generation,
speeds up the linker minutely, and gives us a slightly more rational
implementation (there was really no compelling reason to do DWARF gen
for globals in the linker).

Change-Id: I0c1c98d3a647258697e90eb91d1d8a9f6f7f376a
Reviewed-on: https://go-review.googlesource.com/c/go/+/295011
Trust: Than McIntosh <thanm@google.com>
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Jeremy Faller <jeremy@golang.org>
2021-03-23 00:29:52 +00:00
6543
1c9e587b90 net: add IP.IsPrivate
Adds a new method IsPrivate to check if an IP is
private according to RFC 1918 & RFC 4193.

Fixes #29146

Change-Id: If77b9e1746d86029df66ae9f18437b1f65a18b59
GitHub-Last-Rev: 09f4ba7598
GitHub-Pull-Request: golang/go#42793
Reviewed-on: https://go-review.googlesource.com/c/go/+/272668
Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Emmanuel Odeke <emmanuel@orijtech.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-03-22 21:35:40 +00:00
Than McIntosh
d9691ffa37 cmd/compile/internal/walk: relocate a stray comment
The explanatory comment and the associated version counter variable
for the helper routine "wrapCall" seem to have been left behind in
walk.go during the big refactoring -- move it back to where it should
be, next to wrapCall in stmt.go. Also fix a small buglet in the
comment itself.

Change-Id: I8637a838214b216581be59e01149a72282a46526
Reviewed-on: https://go-review.googlesource.com/c/go/+/303729
Trust: Than McIntosh <thanm@google.com>
Run-TryBot: Than McIntosh <thanm@google.com>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2021-03-22 20:20:58 +00:00
David Chase
a93849b9e2 cmd/compile: remove now-redundant AuxCall.args
Cleanup, ABI information subsumes this.

Updates #40724

Change-Id: I6c69da44380f7b0d159b22acacbd68dc000e4725
Reviewed-on: https://go-review.googlesource.com/c/go/+/303432
Run-TryBot: David Chase <drchase@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2021-03-22 19:09:53 +00:00
David Chase
196c33e92d cmd/compile: fix WriteFuncMap for new ABI.
replaced old type-based logic with new abi-based logic;
earlier versions of this CL compared them for equality.
For not-in-a-register, they match everywhere tested.

also modified GetFrameOffset to make it more like the one it replaces;
the LocalsOffset is subtracted.

Change-Id: I65ce7f0646c493c277df6b6f46e4839a0d886ac9
Reviewed-on: https://go-review.googlesource.com/c/go/+/302072
Trust: David Chase <drchase@google.com>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2021-03-22 18:42:15 +00:00
Shuhei Takahashi
ba6b8e75ed os/exec: avoid flaky Wait in TestContextCancel
This change just increases the timeout to 1 minute to avoid test
flakiness.

Fixes #42061

Change-Id: Id258488ee8f062cd5e68b68bb5cf11e15fdbb396
Reviewed-on: https://go-review.googlesource.com/c/go/+/303351
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Trust: Benny Siegert <bsiegert@gmail.com>
2021-03-22 18:41:13 +00:00
Jason A. Donenfeld
78afca22c9 runtime: fix bogus NtCurrentTeb()->TlsSlots[n] calculation on windows/arm64
runtime.save_g adds X18 to runtime.tls_g in order to have a pointer to
thread local storage. X18 represents a pointer to the TEB on ARM64 and
runtime.tls_g is set in runtime.wintls at initialization time. This
function calls TlsAlloc to allocate a "TLS slot", which is supposed to
index into NtCurrentTeb()->TlsSlots. So the full calculation we want is:

    X18 + offsetof(TEB, TlsSlots) + 8*TlsAllocReturnValue

It makes sense to store the complete value of "offsetof(TEB,
TlsSlots) + TlsAllocReturnValue" into runtime.tls_g so that the
calculation can simplify to:

    X18 + runtime.tls_g

But, instead of computing that, we're currently doing something kind of
strange, in which we:

    - call TlsAlloc, which puts its return value into X0
    - make sure X0 is less than 64, so we don't overflow
    - set runtime.tls_g to 8*X1 + offsetof(TEB, TlsSlots)

The question is: why are we using X1 instead of X0? What is in X1?

Probably it was, by luck, zero before, and TlsAlloc returned zero, so
there was no problem. But on recent versions of Windows, X1 is some
other garbage value and not zero, so we eventually crash when trying to
dereference X18 + runtime.tls_g.

This commit fixes the problem by just computing:

   runtime.tls_g = 8*X0 + offsetof(TEB, TlsSlots)

Fixes #45138.

Change-Id: I560426bae7468217bd183ac6c6eb4b56a3815b09
Reviewed-on: https://go-review.googlesource.com/c/go/+/303273
Trust: Jason A. Donenfeld <Jason@zx2c4.com>
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2021-03-22 17:50:42 +00:00
Joel Sing
8fd0f83552 cmd/compile/internal/ssa: correct sign extension for consts on riscv64
Correct sign extension handling for consts on riscv64. This fixes a bug
in part exposed by CL 302609 - previously 64 bit consts were rewritten into
multiple 32 bit consts and the expansion would result in sign/zero extension
not being eliminated. With this change a MOVDconst with a 64 bit value can be
followed by a MOV{B,H,W}reg, which will be eliminated without actually
truncating to a smaller value.

Change-Id: I8d9cd380217466997b341e008a1f139bc11a0d51
Reviewed-on: https://go-review.googlesource.com/c/go/+/303350
Trust: Joel Sing <joel@sing.id.au>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2021-03-22 16:13:55 +00:00
Daniel Martí
5437b5a24b cmd/compile: disallow rewrite rules from declaring reserved names
If I change a rule in ARM64.rules to use the variable name "b" in a
conflicting way, rulegen would previously not complain, and the compiler
would later give a confusing error:

	$ go run *.go && go build cmd/compile/internal/ssa
	# cmd/compile/internal/ssa
	../rewriteARM64.go:24236:10: b.NewValue0 undefined (type int64 has no field or method NewValue0)

Make rulegen complain early about those cases. Sometimes they might
happen to be harmless, but in general they can easily cause confusion or
unintended effect due to shadowing.

After the change, with the same conflicting rule:

	$ go run *.go && go build cmd/compile/internal/ssa
	2021/03/22 11:31:49 rule ARM64.rules:495 uses the reserved name b
	exit status 1

Note that 24 existing rules were using reserved names. It seems like the
shadowing was harmless, as it wasn't causing typechecking issues nor did
it seem to cause unintended behavior when the rule rewrite code ran.

The bool values "b" were renamed "t", since that seems to have a
precedent in other rules and in the fmt package.

Sequential values like "a b c" were renamed to "x y z", since "b" is
reserved.

Finally, "typ" was renamed to "_typ", since there doesn't seem to be an
obviously better answer.

Passes all three of:

	$ GOARCH=amd64 go build -toolexec 'toolstash -cmp' -a std
	$ GOARCH=arm64 go build -toolexec 'toolstash -cmp' -a std
	$ GOARCH=mips64 go build -toolexec 'toolstash -cmp' -a std

Fixes #45154.

Change-Id: I1cce194dc7b477886a9c218c17973e996bcedccf
Reviewed-on: https://go-review.googlesource.com/c/go/+/303549
Trust: Daniel Martí <mvdan@mvdan.cc>
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
2021-03-22 16:02:08 +00:00
Daniel Martí
bd8b3fe5be cmd/compile: make no-op rewrite funcs smaller
This doesn't change any behavior, but should help the compiler realise
that these funcs really do nothing at all.

Change-Id: Ib26c02ef264691acac983538ec300f91d6ff98db
Reviewed-on: https://go-review.googlesource.com/c/go/+/280314
Trust: Daniel Martí <mvdan@mvdan.cc>
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
2021-03-22 16:01:44 +00:00
Bryan C. Mills
e838c76a6e cmd/go/internal/modload: remove go116EnableNarrowAll constant
This constant existed in case there was a serious problem with the
change to the "all" pattern in Go 1.16 (CL 240623), so that we could
roll back the change in behavior by just flipping the constant without
introducing merge conflicts elsewhere.

Go 1.16 has been out for a while and the new "all" behavior seems fine,
so we can jettison this feature flag.

For #36460

Change-Id: Ic2730edcee81514d56c7086e11542468eb63c84a
Reviewed-on: https://go-review.googlesource.com/c/go/+/303431
Trust: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
2021-03-22 15:24:20 +00:00
eric fang
d8394bfc7f cmd/internal/obj/arm64: mark functions with small stacks NOSPLIT
This change omits the stack check on arm64 when the size of a stack
frame is less than obj.StackSmall.

The effect is not very significant, because CL 92040 has set the leaf
function with a framesize of 0 to NOFRAME, which makes the code
prologue on arm64 much closer to other architectures. But it is not
without effect, for example, it is effective for std library functions
such as runtime.usleep, fmt.isSpace, etc. Since this CL is very simple,
I think this optimization is worthwhile.

compilecmp results on linux/arm64:
name                      old time/op       new time/op       delta
Template                        284ms ± 1%        283ms ± 1%  -0.29%  (p=0.000 n=50+50)
Unicode                         125ms ± 2%        125ms ± 1%    ~     (p=0.445 n=49+49)
GoTypes                         1.70s ± 1%        1.69s ± 1%  -0.36%  (p=0.000 n=50+50)
Compiler                        124ms ± 1%        124ms ± 1%  -0.31%  (p=0.003 n=48+48)
SSA                             12.7s ± 1%        12.7s ± 1%    ~     (p=0.117 n=50+50)
Flate                           172ms ± 1%        171ms ± 1%  -0.55%  (p=0.000 n=50+50)
GoParser                        265ms ± 1%        264ms ± 1%  -0.23%  (p=0.000 n=47+48)
Reflect                         653ms ± 1%        646ms ± 1%  -1.12%  (p=0.000 n=48+50)
Tar                             246ms ± 1%        245ms ± 1%  -0.41%  (p=0.000 n=46+47)
XML                             328ms ± 1%        327ms ± 1%  -0.18%  (p=0.020 n=46+50)
LinkCompiler                    599ms ± 1%        598ms ± 1%    ~     (p=0.237 n=50+49)
ExternalLinkCompiler            1.87s ± 1%        1.87s ± 1%  -0.18%  (p=0.000 n=50+50)
LinkWithoutDebugCompiler        365ms ± 1%        364ms ± 2%    ~     (p=0.131 n=50+50)
[Geo mean]                      490ms             488ms       -0.32%

name                      old alloc/op      new alloc/op      delta
Template                       38.8MB ± 1%       38.8MB ± 1%  +0.16%  (p=0.013 n=47+49)
Unicode                        28.4MB ± 0%       28.4MB ± 0%    ~     (p=0.512 n=46+44)
GoTypes                         169MB ± 1%        169MB ± 1%    ~     (p=0.628 n=50+50)
Compiler                       23.2MB ± 1%       23.2MB ± 1%    ~     (p=0.424 n=46+44)
SSA                            1.55GB ± 0%       1.55GB ± 0%    ~     (p=0.603 n=48+50)
Flate                          23.7MB ± 1%       23.8MB ± 1%    ~     (p=0.797 n=50+50)
GoParser                       35.3MB ± 1%       35.3MB ± 1%    ~     (p=0.932 n=49+49)
Reflect                        85.0MB ± 0%       84.9MB ± 0%  -0.05%  (p=0.038 n=45+40)
Tar                            34.4MB ± 1%       34.5MB ± 1%    ~     (p=0.288 n=50+50)
XML                            43.8MB ± 2%       43.9MB ± 2%    ~     (p=0.798 n=46+49)
LinkCompiler                    136MB ± 0%        136MB ± 0%    ~     (p=0.750 n=50+50)
ExternalLinkCompiler            127MB ± 0%        127MB ± 0%    ~     (p=0.852 n=50+50)
LinkWithoutDebugCompiler       84.1MB ± 0%       84.1MB ± 0%    ~     (p=0.890 n=50+50)
[Geo mean]                     70.4MB            70.4MB       +0.01%

file      before    after     Δ       %
addr2line 4006004   4006012   +8      +0.000%
asm       4936863   4936919   +56     +0.001%
buildid   2594947   2594859   -88     -0.003%
cgo       4399702   4399806   +104    +0.002%
compile   22233139  22233107  -32     -0.000%
cover     4443681   4443785   +104    +0.002%
dist      3365902   3365806   -96     -0.003%
doc       3776175   3776231   +56     +0.001%
fix       3218624   3218552   -72     -0.002%
nm        3923345   3923329   -16     -0.000%
objdump   4295473   4295673   +200    +0.005%
pack      2390561   2390497   -64     -0.003%
pprof     12866419  12866275  -144    -0.001%
test2json 2587113   2587129   +16     +0.001%
trace     9609814   9609710   -104    -0.001%
vet       6790272   6791048   +776    +0.011%
total     106832751 106833455 +704    +0.001%

Updates #13379 (for arm64)

Change-Id: I07664ab0b978c66c0b18b8482222e9ba3772290d
Reviewed-on: https://go-review.googlesource.com/c/go/+/302853
Reviewed-by: eric fang <eric.fang@arm.com>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Trust: eric fang <eric.fang@arm.com>
Run-TryBot: eric fang <eric.fang@arm.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-03-22 03:52:31 +00:00
Youfu Zhang
e0fae78e1d runtime: fix stack alignment for Windows amd64 lib entry
Windows amd64 calling convention requires 16-bytes aligned
stack pointer. Before this patch, the real frame size is
0x48 (frame size) + 0x10 (frame pointer & return address),
which does not satisfy the alignment requirement.

_cgo_sys_thread_create eventually calls NtCreateThread,
which receives a pointer to a ThreadContext structure
allocated from (mis-aligned) stack, and may fail with
STATUS_DATATYPE_MISALIGNMENT on some implementations.

BP is saved/restored by prolog/epilog.
AX, CX, DX are volatile, no need to save and restore.

Fixes #41075

Change-Id: I01c0a22b4bf3b4cfdebf4df587445aa46c667973
GitHub-Last-Rev: 15d2bd740e
GitHub-Pull-Request: golang/go#44524
Reviewed-on: https://go-review.googlesource.com/c/go/+/295329
Trust: Alex Brainman <alex.brainman@gmail.com>
Trust: Jason A. Donenfeld <Jason@zx2c4.com>
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Jason A. Donenfeld <Jason@zx2c4.com>
Reviewed-by: Christopher Nelson <nadiasvertex@gmail.com>
2021-03-20 17:08:03 +00:00
Cherry Zhang
6ae3b70ef2 cmd/compile: add clobberdeadreg mode
When -clobberdeadreg flag is set, the compiler inserts code that
clobbers integer registers at call sites. This may be helpful for
debugging register ABI.

Only implemented on AMD64 for now.

Change-Id: Ia203d3f891c30fd95d0103489056fe01d63a2899
Reviewed-on: https://go-review.googlesource.com/c/go/+/302809
Trust: Cherry Zhang <cherryyz@google.com>
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
2021-03-19 23:21:21 +00:00
Dilyn Corner
9f2a71b6e7 make.bash: this change modifies Go to correctly select a dyamic linker
Alpine Linux is not the only musl-based Linux distribution. Checking for
/etc/alpine-release excludes many other distributions (Oasis, KISS,
Sabotage, sta.li). Not having the correct GO_LDSO set during go builds will
result in the wrong linker/loader on nonalpine musl systems for pie builds.
Instead, the dynamic loader should be checked for every system and set. This
results in the correct dynamic linker being found on glibc systems
(/lib/ld-linux-x86-64.so.2) and musl systems (/lib/ld-musl-x84_64.so.1).

Fixes #45034

Change-Id: I4c9389abc759aa34431dc6c781022636b81d6910
GitHub-Last-Rev: e17b9eb106
GitHub-Pull-Request: golang/go#45036
Reviewed-on: https://go-review.googlesource.com/c/go/+/301989
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Cherry Zhang <cherryyz@google.com>
2021-03-19 22:32:03 +00:00