1
0
mirror of https://github.com/golang/go synced 2024-11-23 23:40:13 -07:00
Commit Graph

52661 Commits

Author SHA1 Message Date
David Taylor
a4af356075 crypto/tls: avoid extra allocations in steady-state Handshake calls
The Read and Write methods of *tls.Conn call Handshake
unconditionally, every time they are called, expecting it to only
perform a new handshake if required.

However in go 1.17 handshakeContext was extended to set up a
cancelable Context, and importantly did so prior to checking if a
handshake is required. This thus causes it to allocate on every call,
even in those that are no-ops when called in a Read or Write on an
established connection, sometimes leading to very large numbers of
allocations during reads.

This change adds an early return, prior to setting up the context or
proceeding into the handshakeMutex and checking the handshake error, if
the handshake status atomic indicates handshake is already complete.

name                                     old allocs/op  new allocs/op  delta
Throughput/MaxPacket/1MB/TLSv12-10          1.07k ± 0%     0.62k ± 0%  -42.16%  (p=0.000 n=4+5)
Throughput/MaxPacket/1MB/TLSv13-10          1.70k ± 0%     1.25k ± 0%     ~     (p=0.079 n=4+5)
Throughput/MaxPacket/2MB/TLSv12-10          1.62k ± 0%     0.73k ± 0%  -55.18%  (p=0.008 n=5+5)
Throughput/MaxPacket/2MB/TLSv13-10          2.26k ± 0%     1.36k ± 0%  -39.64%  (p=0.008 n=5+5)
Throughput/MaxPacket/4MB/TLSv12-10          2.74k ± 0%     0.95k ± 0%  -65.35%  (p=0.008 n=5+5)
Throughput/MaxPacket/4MB/TLSv13-10          3.37k ± 0%     1.58k ± 0%  -53.15%  (p=0.008 n=5+5)
Throughput/MaxPacket/8MB/TLSv12-10          4.96k ± 0%     1.39k ± 0%  -72.06%  (p=0.016 n=4+5)
Throughput/MaxPacket/8MB/TLSv13-10          5.60k ± 0%     2.01k ± 0%  -64.05%  (p=0.008 n=5+5)
Throughput/MaxPacket/16MB/TLSv12-10         9.42k ± 0%     2.27k ± 1%  -75.92%  (p=0.016 n=4+5)
Throughput/MaxPacket/16MB/TLSv13-10         10.0k ± 0%      2.9k ± 0%  -71.39%  (p=0.008 n=5+5)
Throughput/MaxPacket/32MB/TLSv12-10         18.3k ± 0%      4.0k ± 0%  -77.97%  (p=0.008 n=5+5)
Throughput/MaxPacket/32MB/TLSv13-10         18.9k ± 0%      4.6k ± 0%  -75.62%  (p=0.008 n=5+5)
Throughput/MaxPacket/64MB/TLSv12-10         36.2k ± 0%      7.5k ± 0%  -79.15%  (p=0.008 n=5+5)
Throughput/MaxPacket/64MB/TLSv13-10         36.7k ± 0%      8.1k ± 0%  -78.06%  (p=0.008 n=5+5)
Throughput/DynamicPacket/1MB/TLSv12-10      1.12k ± 0%     0.63k ± 0%  -44.20%  (p=0.008 n=5+5)
Throughput/DynamicPacket/1MB/TLSv13-10      1.76k ± 0%     1.26k ± 0%  -28.22%  (p=0.016 n=5+4)
Throughput/DynamicPacket/2MB/TLSv12-10      1.68k ± 0%     0.74k ± 0%  -56.11%  (p=0.008 n=5+5)
Throughput/DynamicPacket/2MB/TLSv13-10      2.32k ± 0%     1.37k ± 0%  -40.80%  (p=0.008 n=5+5)
Throughput/DynamicPacket/4MB/TLSv12-10      2.80k ± 0%     0.96k ± 0%  -65.81%  (p=0.008 n=5+5)
Throughput/DynamicPacket/4MB/TLSv13-10      3.43k ± 0%     1.59k ± 0%  -53.57%  (p=0.008 n=5+5)
Throughput/DynamicPacket/8MB/TLSv12-10      5.03k ± 0%     1.39k ± 0%  -72.27%  (p=0.008 n=5+5)
Throughput/DynamicPacket/8MB/TLSv13-10      5.66k ± 0%     2.02k ± 0%  -64.27%  (p=0.008 n=5+5)
Throughput/DynamicPacket/16MB/TLSv12-10     9.48k ± 0%     2.28k ± 1%  -75.98%  (p=0.008 n=5+5)
Throughput/DynamicPacket/16MB/TLSv13-10     10.1k ± 0%      2.9k ± 0%  -71.34%  (p=0.008 n=5+5)
Throughput/DynamicPacket/32MB/TLSv12-10     18.4k ± 0%      4.0k ± 0%  -78.13%  (p=0.008 n=5+5)
Throughput/DynamicPacket/32MB/TLSv13-10     19.0k ± 0%      4.6k ± 0%  -75.54%  (p=0.008 n=5+5)
Throughput/DynamicPacket/64MB/TLSv12-10     36.2k ± 0%      7.6k ± 1%  -79.02%  (p=0.008 n=5+5)
Throughput/DynamicPacket/64MB/TLSv13-10     36.8k ± 0%      8.2k ± 1%  -77.76%  (p=0.008 n=5+5)

Fixes #50657

Change-Id: Iacb1f9bf7802022960d9dbce141b8c0587a614d4
Reviewed-on: https://go-review.googlesource.com/c/go/+/379034
Reviewed-by: David Chase <drchase@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Filippo Valsorda <valsorda@google.com>
Auto-Submit: Filippo Valsorda <filippo@golang.org>
Run-TryBot: Filippo Valsorda <filippo@golang.org>
2022-05-06 20:17:52 +00:00
Than McIntosh
054323d809 debug/pe: rework reading of aux symbols to fix endianity problems
This patch reworks CL 394534 to fix things so that reading auxiliary
symbol info works properly in a cross-endian mode (running
debug/pe-based tool on a big-endian system). The previous
implementation read in all symbol records using the primary symbol
format, then just used a pointer cast to convert to the auxiliary
format, which doesn't play well if host and target have different
endianness.

Fixes #52079.

Change-Id: I143d94d9313a265f11ca7befd254bdb150698834
Reviewed-on: https://go-review.googlesource.com/c/go/+/397485
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
2022-05-06 18:07:48 +00:00
Paul E. Murphy
f495b36ccd crypto/aes: rewrite ppc64le block crypting
This unrolls the counter loop and simplifies the load/storing
of text/ciphertext and keys by using unaligned VSX memory
operations.

Performance delta on POWER9:

name     old time/op   new time/op    delta
Encrypt   19.9ns ± 0%    14.9ns ± 0%  -24.95%
Decrypt   19.8ns ± 0%    14.6ns ± 0%  -26.12%

Change-Id: Iba98d5c1d88c6bead45bc04c97ae64bcb6fc9f21
Reviewed-on: https://go-review.googlesource.com/c/go/+/404354
Run-TryBot: Paul Murphy <murp@ibm.com>
Reviewed-by: Lynn Boger <laboger@linux.vnet.ibm.com>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Filippo Valsorda <valsorda@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-05-06 17:56:48 +00:00
Paul E. Murphy
9c9090eb1d cmd/link: generate PPC64 ABI register save/restore functions if needed
They are usually needed when internally linking gcc code
compiled with -Os. These are typically generated by ld
or gold, but are missing when linking internally.

The PPC64 ELF ABI describes a set of functions to save/restore
non-volatile, callee-save registers using R1/R0/R12:

 _savegpr0_n: Save Rn-R31 relative to R1, save LR (in R0), return
 _restgpr0_n: Restore Rn-R31 from R1, and return to saved LR
  _savefpr_n: Save Fn-F31 based on R1, and save LR (in R0), return
  _restfpr_n: Restore Fn-F31 from R1, and return to 16(R1)
 _savegpr1_n: Save Rn-R31 based on R12, return
 _restgpr1_n: Restore Rn-R31 based on R12, return
   _savevr_m: Save VRm-VR31 based on R0, R12 is scratch, return
   _restvr_m: Restore VRm-VR31 based on R0, R12 is scratch, return

 m is a value 20<=m<=31
 n is a value 14<=n<=31

Add several new functions similar to those suggested by the
PPC64 ELFv2 ABI. And update the linker to scan external relocs
for these calls, and redirect them to runtime.elf_<func>+offset
in runtime/asm_ppc64x.go.

Similarly, code which generates plt stubs is moved into
a dedicated function. This avoids an extra scan of relocs.

fixes #52336

Change-Id: I2f0f8b5b081a7b294dff5c92b4b1db8eba9a9400
Reviewed-on: https://go-review.googlesource.com/c/go/+/400796
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: David Chase <drchase@google.com>
Run-TryBot: Paul Murphy <murp@ibm.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-05-06 17:56:28 +00:00
Paul E. Murphy
4a5711c3cf cmd/compile,cmd/asm: fix ppc64 usage of BI argument of BC opcode
Avoid coercing the CR bit into a GPR register type argument, and
move the existing usage to CRx_y register types. And, update the
compiler usage to this. This transformation is done internally,
so it should not alter existing assembly code.

Likewise, add assembly tests for all optab entries of BC/BR. This
found some cases which were not possible to realize with handwritten
asm, or assemble to something very unexpected if generated by the
compiler. The following optab entries are removed, and the cases
simplified or removed:

{as: ABR, a3: C_SCON, a6: C_LR, type_: 18, size: 4}

  This existed only to pass the BH hint to JMP (LR) from compiler
  generated code. It cannot be matched with asm. Instead, add and
  support 4-operand form "BC{,L} $BO, $BI, $BH, (LR)".

{as: ABR, a1: C_REG, a6: C_CTR, type_: 18, size: 4}

  Could be used like  "BR R1, (CTR)", but always compiles to bctr
  irrespective of arg 1. Any usage should be rewritten as "JMP (CTR)",
  or rewritten if this was not the intended behavior.

{as: ABR, a6: C_ZOREG, type_: 15, size: 8}:
{as: ABC, a6: C_ZOREG, type_: 15, size: 8},

  Not reachable: 0(reg) is coerced to reg in assembler frontend.

{as: ABC, a2: C_REG, a6: C_LR, type_: 18, size: 4}
{as: ABC, a2: C_REG, a6: C_CTR, type_: 18, size: 4}

  Only usable from the compiler. However, the compiler does not
  generate this form today. Without a BO operand (usually in a1), it
  is not clear what this should assemble to.

Change-Id: I1b5151f884a5877e4a610e6fd41261e8e64c5454
Reviewed-on: https://go-review.googlesource.com/c/go/+/357775
Reviewed-by: Lynn Boger <laboger@linux.vnet.ibm.com>
Run-TryBot: Paul Murphy <murp@ibm.com>
Reviewed-by: Than McIntosh <thanm@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
2022-05-06 17:56:02 +00:00
Jason A. Donenfeld
091e913414 crypto/rand: fix race on r.used
This race is benign, but it still trips up the race detector, so turn
this into an atomic read.

Fixes #52739.

Change-Id: Ib53362286b456513c8c69d6d2d73c6c90ec095f3
Reviewed-on: https://go-review.googlesource.com/c/go/+/404475
Auto-Submit: Jason Donenfeld <Jason@zx2c4.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Jason Donenfeld <Jason@zx2c4.com>
2022-05-06 17:41:30 +00:00
Cherry Mui
2049649e8b cmd/link: fix handling of visibility hidden symbols
There is a TODO comment that checking hidden visibility is
probably not the right thing to do. I think it is indeed not. Here
we are not referencing symbols across DSO boundaries, just within
an executable binary. The hidden visibility is for references from
another DSO. So it doesn't actually matter.

This makes cgo internal linking tests work on ARM64 with newer
GCC. It failed and was disabled due to a visibility hidden symbol
in libgcc.a that we didn't handle correctly. Specifically, the
problem is that we didn't mark visibility hidden symbol references
SXREF, which caused the loader to not think it is an unresolved
external symbol, which in turn made it not loading an object file
from the libgcc.a archive which contains the actual definition.
Later stage when we try to resolve the relocation, we couldn't
resolve it. Enable the test as it works now.

Fixes #39466.

Change-Id: I2759e3ae15e7a7a1ab9a820223b688ad894509ed
Reviewed-on: https://go-review.googlesource.com/c/go/+/404296
Reviewed-by: Than McIntosh <thanm@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-05-06 17:37:38 +00:00
Ian Lance Taylor
280e640224 test: add test that crashed gofrontend
For #52535

Change-Id: I6798a8379163497ebebcdadf836b8569735c282b
Reviewed-on: https://go-review.googlesource.com/c/go/+/404496
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Ian Lance Taylor <iant@google.com>
2022-05-06 17:37:12 +00:00
Roland Shoemaker
0aee59736f crypto/x509: fix EKU nesting enforcement
The path building rework broke the enforcement of EKU nesting, this
change goes back to using the old method of enforcement, since it ends
up being more efficient to check the chains after building, rather than
at each step during path building.

Fixes #52659

Change-Id: Ic7c3717a10c33905677cf7bc4bc0a20f5f15f259
Reviewed-on: https://go-review.googlesource.com/c/go/+/403554
Reviewed-by: Damien Neil <dneil@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Filippo Valsorda <valsorda@google.com>
Run-TryBot: Roland Shoemaker <roland@golang.org>
Auto-Submit: Roland Shoemaker <roland@golang.org>
2022-05-06 17:05:06 +00:00
Robert Griesemer
5fcd1badf7 go/printer: fix printing for possibly ambiguous type constraints
This is a port of the printer changes from CLs 402256 and 404397
in the syntax package to go/printer, with adjustments for the
different AST structure and test framework.

For #52559.

Change-Id: Ib7165979a4bd9df91f7f0f1c23b756a41ca31eb3
Reviewed-on: https://go-review.googlesource.com/c/go/+/404194
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2022-05-06 16:18:34 +00:00
Robert Griesemer
ea6c828455 cmd/compile/internal/syntax: fix printing of ambiguous constraint literals
Without this change, the type parameter list "[P T | T]" is printed
as "[P T | T,]" in an attempt to avoid an ambiguity. But the type
parameter P cannot syntactically combine with the constraint T | T
and make a new valid expression.

This change introduces a specific combinesWithName predicate that
reports whether a constraint expression can combine with a type
parameter name to form a new valid (value) expression.

Use combinesWithName to accurately determine when a comma is needed.

For #49482.

Change-Id: Id1d17a18f0c9af04495da7b0453e83798f32b04a
Reviewed-on: https://go-review.googlesource.com/c/go/+/404397
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2022-05-06 16:18:28 +00:00
Tobias Klauser
7f71e1fc28 runtime/cgo: remove memset in _cgo_sys_thread_start on linux
pthread_attr_init in glibc and musl libc already explicitly clear the
pthread_attr argument before setting it, see
https://sourceware.org/git/?p=glibc.git;a=blob;f=nptl/pthread_attr_init.c
and https://git.musl-libc.org/cgit/musl/log/src/thread/pthread_attr_init.c

It looks like pthread_attr_init has been implemented like this for a
long time in both libcs. The comment and memset in _cgo_sys_thread_start
probably stem from a time where not all libcs did the explicit memset in
pthread_attr_init.

Also, the memset in _cgo_sys_thread_start is not performed on all linux
platforms further indicating that this isn't an issue anymore.

Change-Id: I920148b5d24751195ced7af5bb7c52a7f8293259
Reviewed-on: https://go-review.googlesource.com/c/go/+/404275
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
2022-05-06 15:32:04 +00:00
Jorropo
119da6358b debug/buildinfo: avoid nil defererence for invalid XCOFF
I've made it return 0 following what the other DataStart implementation
do when they do not found the section.

Fixes #52718

Change-Id: I44292fed15bb21b9aba712ad15ed74e0ce231b5a
GitHub-Last-Rev: 081a35ebec
GitHub-Pull-Request: golang/go#52722
Reviewed-on: https://go-review.googlesource.com/c/go/+/404254
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: David Chase <drchase@google.com>
2022-05-06 14:33:48 +00:00
zhangyunhao
f87e28d1b9 A: add ByteDance Ltd. (Corporate CLA)
Change-Id: Ia670d96ce4926c88d5d955d31dd89837b236a806
Reviewed-on: https://go-review.googlesource.com/c/go/+/403994
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: mzh <mzh@golangcn.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-05-06 04:25:34 +00:00
Meng Zhuo
3ea3bc0e96 cmd/compile: update TestStmtLines threshold for riscv64
CL402374 default regabi for riscv64 but TestStmtLines
keep fail trybot within a tiny overlimit (2.006% > 2%).
This CL update this threshold to 3% for riscv64 as an
acceptable temporary solution.

Change-Id: I5c6f37099a76bc048998eb95f49944dbe55492f4
Reviewed-on: https://go-review.googlesource.com/c/go/+/404195
Run-TryBot: mzh <mzh@golangcn.org>
Reviewed-by: David Chase <drchase@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
2022-05-06 04:22:04 +00:00
Ian Lance Taylor
7dd9884562 sync/atomic: don't run 64-bit uintptr tests on 32-bit systems
The tests don't work on big-endian systems. This change handles more
of the tests added in CL 381317 like the other existing tests.

Fixes #52723

Change-Id: Ie9e048e75dbe0b5aca61b51cd0c50d7d878ff6d6
Reviewed-on: https://go-review.googlesource.com/c/go/+/404495
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Auto-Submit: Ian Lance Taylor <iant@google.com>
2022-05-06 02:40:50 +00:00
Lynn Boger
f99511d59b crypto/internal/nistec: re-enable ppc64le asm for P-256
Add support for ppc64le assembler to p256. Most of the changes
are due to the change in nistec interfaces.

There is a change to p256MovCond based on a reviewer's comment.

LXVD2X replaces the use of LXVW4X in one function.

In addition, some refactoring has been done to this file to
reduce size and improve readability:
- Eliminate the use of defines to switch between V and VSX
registers. V regs can be used for instructions some that
previously required VSX.
- Use XXPERMDI instead of VPERM to swap bytes loaded and
stored with LXVD2X and STXVD2X instructions. This eliminates
the need to load the byte swap string into a vector.
- Use VMRGEW and VMRGOW instead of VPERM in the VMULT
macros. This also avoids the need to load byte strings to
swap the high and low values.

These changes reduce the file by about 10% and shows an
improvement of about 2% at runtime.

For #52182

Change-Id: Ic48050fc81bb273b7b4023e54864f4255dcc2a4f
Reviewed-on: https://go-review.googlesource.com/c/go/+/399755
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Filippo Valsorda <filippo@golang.org>
Run-TryBot: Filippo Valsorda <filippo@golang.org>
Reviewed-by: Filippo Valsorda <valsorda@google.com>
Reviewed-by: Paul Murphy <murp@ibm.com>
2022-05-05 23:41:16 +00:00
Filippo Valsorda
86536b934a go/types,cmd/compile/internal/types2: fix TestStdlib
CL 402556 moved a special-cased package and broke the longtests.

Change-Id: I10b48e0912c1cee0eabc342ed1c1704ed79946bd
Reviewed-on: https://go-review.googlesource.com/c/go/+/404474
Reviewed-by: Damien Neil <dneil@google.com>
Run-TryBot: Filippo Valsorda <filippo@golang.org>
Reviewed-by: Filippo Valsorda <valsorda@google.com>
Auto-Submit: Filippo Valsorda <valsorda@google.com>
Reviewed-by: Roland Shoemaker <roland@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-05-05 22:53:14 +00:00
Roland Shoemaker
bb1f441618 crypto/rand: properly handle large Read on windows
Use the batched reader to chunk large Read calls on windows to a max of
1 << 31 - 1 bytes. This prevents an infinite loop when trying to read
more than 1 << 32 -1 bytes, due to how RtlGenRandom works.

This change moves the batched function from rand_unix.go to rand.go,
since it is now needed for both windows and unix implementations.

Fixes #52561

Change-Id: Id98fc4b1427e5cb2132762a445b2aed646a37473
Reviewed-on: https://go-review.googlesource.com/c/go/+/402257
Run-TryBot: Roland Shoemaker <roland@golang.org>
Reviewed-by: Filippo Valsorda <filippo@golang.org>
Reviewed-by: Filippo Valsorda <valsorda@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-05-05 22:44:02 +00:00
Filippo Valsorda
7c74b0db8a crypto/ed25519/internal/edwards25519: move to crypto/internal/edwards25519
This will allow us to use crypto/internal/edwards25519/field from
crypto/ecdh to implement X25519, dropping the dependency on
golang.org/x/crypto/curve25519.

For #52182

Change-Id: I3be9debc6e13bf06944b98668f34313a975914d0
Reviewed-on: https://go-review.googlesource.com/c/go/+/402556
Reviewed-by: Roland Shoemaker <roland@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Run-TryBot: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-05-05 21:53:10 +00:00
Filippo Valsorda
52de40120d crypto/elliptic/internal/nistec: move to crypto/internal/nistec
So it's reachable from crypto/ecdsa and the upcoming crypto/ecdh.

No code changes.

For #52182

Change-Id: Ie3216052f46c6ef7ec64d8b87a233a9c50c4b16a
Reviewed-on: https://go-review.googlesource.com/c/go/+/398674
Run-TryBot: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Roland Shoemaker <roland@golang.org>
2022-05-05 21:53:03 +00:00
Filippo Valsorda
a218b3520a crypto/elliptic: panic when operating on invalid points
Fixes #50975
For #52182

Change-Id: I4a98d965436c7034877b8c0146bb0bd5b802d6fa
Reviewed-on: https://go-review.googlesource.com/c/go/+/382995
Reviewed-by: David Chase <drchase@google.com>
Run-TryBot: Filippo Valsorda <filippo@golang.org>
Reviewed-by: Roland Shoemaker <roland@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-05-05 21:52:55 +00:00
Filippo Valsorda
52e24b492d crypto/elliptic: implement UnmarshalCompressed in nistec
For #52182

Change-Id: If9eace36b757ada6cb5123cc60f1e10d4e8280c5
Reviewed-on: https://go-review.googlesource.com/c/go/+/396935
Reviewed-by: Roland Shoemaker <roland@golang.org>
Reviewed-by: Fernando Lobato Meeser <felobato@google.com>
Run-TryBot: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-05-05 21:52:46 +00:00
Filippo Valsorda
50b1add5a7 crypto/elliptic: precompute ScalarBaseMult doublings
name                    old time/op    new time/op    delta
pkg:crypto/ecdsa goos:darwin goarch:amd64
Sign/P224-16               250µs ± 2%      91µs ± 2%  -63.42%  (p=0.000 n=10+9)
Sign/P384-16               955µs ± 3%     311µs ± 2%  -67.48%  (p=0.000 n=10+10)
Sign/P521-16              2.74ms ± 2%    0.82ms ± 2%  -69.95%  (p=0.000 n=10+10)
Verify/P224-16             440µs ± 3%     282µs ± 5%  -35.94%  (p=0.000 n=9+10)
Verify/P384-16            1.72ms ± 2%    1.07ms ± 1%  -38.02%  (p=0.000 n=10+9)
Verify/P521-16            5.10ms ± 2%    3.18ms ± 3%  -37.70%  (p=0.000 n=10+10)
GenerateKey/P224-16        225µs ± 3%      67µs ± 4%  -70.42%  (p=0.000 n=9+10)
GenerateKey/P384-16        881µs ± 1%     241µs ± 2%  -72.67%  (p=0.000 n=10+10)
GenerateKey/P521-16       2.62ms ± 3%    0.69ms ± 3%  -73.78%  (p=0.000 n=10+9)
pkg:crypto/elliptic/internal/nistec goos:darwin goarch:amd64
ScalarMult/P224-16         219µs ± 4%     209µs ± 3%   -4.57%  (p=0.003 n=10+10)
ScalarMult/P384-16         838µs ± 2%     823µs ± 1%   -1.72%  (p=0.004 n=10+9)
ScalarMult/P521-16        2.48ms ± 2%    2.45ms ± 2%     ~     (p=0.052 n=10+10)
ScalarBaseMult/P224-16     214µs ± 4%      54µs ± 4%  -74.88%  (p=0.000 n=10+10)
ScalarBaseMult/P384-16     828µs ± 2%     196µs ± 3%  -76.38%  (p=0.000 n=10+10)
ScalarBaseMult/P521-16    2.50ms ± 3%    0.55ms ± 2%  -77.96%  (p=0.000 n=10+10)

Updates #52424
For #52182

Change-Id: I2be3c2b8cdeead512063ef489e43805f4ee71d0f
Reviewed-on: https://go-review.googlesource.com/c/go/+/404174
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Filippo Valsorda <filippo@golang.org>
Reviewed-by: Fernando Lobato Meeser <felobato@google.com>
Reviewed-by: Roland Shoemaker <roland@golang.org>
2022-05-05 21:52:34 +00:00
Filippo Valsorda
0b4f2416a2 crypto/elliptic: clean up and document P-256 assembly interface
For #52182

Change-Id: I8a68fda3e54bdea48b0dfe528fe293d47bdcd145
Reviewed-on: https://go-review.googlesource.com/c/go/+/396255
Reviewed-by: Fernando Lobato Meeser <felobato@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Filippo Valsorda <filippo@golang.org>
Reviewed-by: Roland Shoemaker <roland@golang.org>
2022-05-05 21:52:24 +00:00
Filippo Valsorda
10d1189464 crypto/elliptic: move P-256 amd64/arm64 assembly to nistec
The goal of this CL is to move the implementation to the new interface
with the least amount of changes possible. A follow-up CL will add
documentation and cleanup the assembly API.

  * SetBytes does the element and point validity checks now, which were
    previously implemented with big.Int.

  * p256BaseMult would return (0:0:1) if the scalar was zero, which is
    not a valid encoding of the point at infinity, but would get
    flattened into (0,0) by p256PointToAffine. The rest of the code can
    cope with any encoding with Z = 0, not just (t²:t³:0) with t != 0.

  * CombinedMult was only avoiding the big.Int and affine conversion
    overhead, which is now gone when operating entirely on nistec types,
    so it can be implemented entirely in the crypto/elliptic wrapper,
    and will automatically benefit all NIST curves.

  * Scalar multiplication can't operate on arbitrarily sized scalars (it
    was using big.Int to reduce them), which is fair enough. Changed the
    nistec point interface to let ScalarMult and ScalarBaseMult reject
    scalars. The crypto/elliptic wrapper still does the big.Int
    reduction as needed.

The ppc64le/s390x assembly is disabled but retained to make review of
the change that will re-enable it easier.

Very small performance changes, which we will more then recoup when
crypto/ecdsa moves to invoking nistec directly.

name                                  old time/op    new time/op    delta
pkg:crypto/elliptic goos:darwin goarch:arm64
ScalarBaseMult/P256-8                   11.3µs ± 0%    11.4µs ± 0%    +0.87%  (p=0.000 n=8+10)
ScalarMult/P256-8                       42.2µs ± 0%    42.2µs ± 0%      ~     (p=0.825 n=10+9)
MarshalUnmarshal/P256/Uncompressed-8     801ns ± 1%     334ns ± 0%   -58.29%  (p=0.000 n=9+10)
MarshalUnmarshal/P256/Compressed-8       798ns ± 0%     334ns ± 0%   -58.13%  (p=0.000 n=10+10)
pkg:crypto/ecdsa goos:darwin goarch:arm64
Sign/P256-8                             19.3µs ± 1%    19.4µs ± 0%    +0.81%  (p=0.003 n=8+9)
Verify/P256-8                           56.6µs ± 0%    56.3µs ± 1%    -0.48%  (p=0.003 n=7+10)
GenerateKey/P256-8                      11.9µs ± 0%    12.0µs ± 0%    +1.22%  (p=0.000 n=7+9)

For #52182

Change-Id: I0690a387e20018f38da55141c0d2659280b1a630
Reviewed-on: https://go-review.googlesource.com/c/go/+/395775
Reviewed-by: Fernando Lobato Meeser <felobato@google.com>
Run-TryBot: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Roland Shoemaker <roland@golang.org>
2022-05-05 21:52:18 +00:00
Filippo Valsorda
68c2e9eede crypto/elliptic: replace generic P-256 with fiat-crypto
For #52182

Change-Id: I8d8b4c3d8299fbd59b0bf48e5c8b7b41c533a2cc
Reviewed-on: https://go-review.googlesource.com/c/go/+/360114
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Roland Shoemaker <roland@golang.org>
Run-TryBot: Filippo Valsorda <filippo@golang.org>
Reviewed-by: Fernando Lobato Meeser <felobato@google.com>
2022-05-05 21:52:08 +00:00
Filippo Valsorda
2515a4214e crypto/elliptic: generate nistec group implementations from template
For #52182

Change-Id: I4dedd8ed9f57f6fc394c71cd20c3b27c3ea29a95
Reviewed-on: https://go-review.googlesource.com/c/go/+/396414
Run-TryBot: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Roland Shoemaker <roland@golang.org>
2022-05-05 21:51:48 +00:00
Lynn Boger
c9f67c289f cmd/compile/internal: intrinsify publicationBarrier on ppc64x
This enables publicationBarrier to be used as an intrinsic
on ppc64le/ppc64.

A call to this appears in test/bench/go1 BinaryTree17

Change-Id: If53528a82de99688270473cbe23472f37046ad65
Reviewed-on: https://go-review.googlesource.com/c/go/+/404056
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Lynn Boger <laboger@linux.vnet.ibm.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: David Chase <drchase@google.com>
2022-05-05 21:14:11 +00:00
Paul E. Murphy
6269dc29a0 crypto/aes: move ppc64le to cipher_asm.go
Move the aesCipherGCM struct definition into cipher_asm.go, it is
needed to compile this file, but isn't used on PPC64.

Also, generate a KeySizeError if the key length is not supported
as was done in the ppc64le implementation, and is done in the
generic code.

Change-Id: I025fc63d614b57dac65a18d1ac3dbeec99356292
Reviewed-on: https://go-review.googlesource.com/c/go/+/399254
Reviewed-by: Filippo Valsorda <valsorda@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Lynn Boger <laboger@linux.vnet.ibm.com>
Reviewed-by: Filippo Valsorda <filippo@golang.org>
Run-TryBot: Paul Murphy <murp@ibm.com>
2022-05-05 20:23:07 +00:00
Russ Cox
fa603aaa4e crypto/internal/boring: avoid false positive in cgo pointer check in SHA calls
Discovered running recent changes against Google internal tests.

Change-Id: Ief51eae82c9f27d2a2a70c4fb2b1086fa8b3f9d8
Reviewed-on: https://go-review.googlesource.com/c/go/+/404295
Auto-Submit: Russ Cox <rsc@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Russ Cox <rsc@golang.org>
2022-05-05 19:31:33 +00:00
Matthew Dempsky
72d1cb092e cmd/compile/internal/pkginit: fix typecheck.DeclFunc call
CL 403935 changed the API for typecheck.DeclFunc, while CL 403851 was
submitted in the mean time and added another call to it.

Change-Id: I0de59f34197bf241c1dd42cffbab7a91f9eb825d
Reviewed-on: https://go-review.googlesource.com/c/go/+/404434
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Auto-Submit: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: David Chase <drchase@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-05-05 19:09:47 +00:00
Matthew Dempsky
983906fa6d cmd/compile/internal/ir: remove FuncType and OTFUNC
No longer needed. We now always directly construct TFUNC types when
needed.

Change-Id: I1bb286c08539cbf97e331824f0f5464b5fd9c873
Reviewed-on: https://go-review.googlesource.com/c/go/+/403936
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
2022-05-05 18:49:32 +00:00
Matthew Dempsky
a7ab208cbb cmd/compile/internal/typecheck: simplify DeclFunc
This CL reworks DeclFunc so that we no longer need to internally
create an ir.FuncType. The next CL will remove ir.FuncType entirely.

Change-Id: I1c02b1b0c35221f2448d6d3ab35cb327a2da40e4
Reviewed-on: https://go-review.googlesource.com/c/go/+/403935
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: David Chase <drchase@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-05-05 18:49:25 +00:00
Matthew Dempsky
5073c1c740 cmd/compile: construct ir.FuncType within typecheck.DeclFunc
Currently all typecheck.DeclFunc callers already construct a fresh new
ir.FuncType, which is the last type expression kind that we represent
in IR.

This CL pushes all of the ir.FuncType construction down into
typecheck.DeclFunc. The next CL will simplify the internals so that we
can get rid of ir.FuncType altogether.

Change-Id: I221ed324f157eb38bb57c8886609f53cc4fd99fe
Reviewed-on: https://go-review.googlesource.com/c/go/+/403848
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
2022-05-05 18:49:17 +00:00
Matthew Dempsky
cce0064399 cmd/compile/internal/typecheck: trim unused code
Unused since CL 403839.

Change-Id: Ib416778738523be11213c82a9e1a4cdaa8afb294
Reviewed-on: https://go-review.googlesource.com/c/go/+/403847
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
2022-05-05 18:49:11 +00:00
Matthew Dempsky
cf66a82b0b cmd/compile/internal/ir: prune down possible Ntype nodes
Ident, ParenExpr, SelectorExpr, and StarExpr used to need to be
allowed as Ntypes for the old -G=0 type checker to represent some type
expressions before type checking, but now they're only ever used to
represent value expressions.

Change-Id: Idd4901ae6149ecc81acf1c52de3bc914d9e73418
Reviewed-on: https://go-review.googlesource.com/c/go/+/403844
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
2022-05-05 18:49:04 +00:00
Matthew Dempsky
3abe8fe00b cmd/compile: change ir.InstExpr.Targs from Node to Ntype
Type arguments are always type expressions, which are semantically
represented by Ntype.

In fact, the slice should probably just be []*types.Type instead, and
that would remove a lot of ir.TypeNode wrapping/unwrapping. But this
lead to issues within the stenciling code, and I can't immediately
make sense why.

Change-Id: Ib944db30e4d21284bc2d8d954b68ecb70b4205a9
Reviewed-on: https://go-review.googlesource.com/c/go/+/403843
Reviewed-by: David Chase <drchase@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
2022-05-05 18:48:54 +00:00
Matthew Dempsky
025a9c3438 cmd/compile: remove ir.TypeAssertExpr.Ntype
As with ir.CompLitExpr.Ntype, there's no need for
ir.TypeAssertExpr.Ntype in a pure-types2 world.

Change-Id: Iff48c98330f072fd6b26099e13a19c56adecdc42
Reviewed-on: https://go-review.googlesource.com/c/go/+/403842
Reviewed-by: David Chase <drchase@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
2022-05-05 18:48:46 +00:00
Matthew Dempsky
27b844f767 cmd/compile: remove ir.CompLitExpr.Ntype field
It's no longer needed, since type expressions are all evaluated by
types2. We can just use Node.Type instead.

Change-Id: If523bd96f96fc4f2337a26f563f84e4f194e654a
Reviewed-on: https://go-review.googlesource.com/c/go/+/403841
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: David Chase <drchase@google.com>
2022-05-05 18:48:39 +00:00
Matthew Dempsky
3ffc230a9f cmd/compile: change ir.NewCompLitExpr from Ntype to *types.Type
All callers were already using TypeNode to get an Ntype anyway, so
just push the TypeNode constructor down into NewCompLitExpr. Prep
refactoring for next CL to remove the Ntype field.

Change-Id: I671935afca707aaab11d1c46e39902bd37a485ba
Reviewed-on: https://go-review.googlesource.com/c/go/+/403840
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
2022-05-05 18:48:32 +00:00
Matthew Dempsky
a6a49d128b cmd/compile: remove ir.Name.Ntype
No longer needed now that IR construction uses types2.

Change-Id: If8b7aff80cd8472be7d87fd3a36da911a5df163c
Reviewed-on: https://go-review.googlesource.com/c/go/+/403839
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: David Chase <drchase@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-05-05 18:48:25 +00:00
Matthew Dempsky
e94fe09c33 cmd/compile: remove ir.Name.TypeDefn
This method used to be needed so the legacy typechecker could report
type declaration loops, but that's handled by types2 now.

Change-Id: Ie0d89e6dcff277778b12ed960b6b31669fd903a7
Reviewed-on: https://go-review.googlesource.com/c/go/+/403838
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
2022-05-05 18:48:17 +00:00
Matthew Dempsky
115c3bfad5 cmd/compile/internal/typecheck: avoid use of Name.Ntype for assignments
Prep refactoring for the next CL, which removes Name.Ntype
entirely. Pulled out separately because this logic is a little subtle,
so this should be easier to bisect in case there's something I'm
missing here.

Change-Id: I4ffec6ee62fcd036582e8d2c963edcbd8bac184f
Reviewed-on: https://go-review.googlesource.com/c/go/+/403837
Reviewed-by: David Chase <drchase@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
2022-05-05 18:48:08 +00:00
Matthew Dempsky
53647a1994 cmd/compile: remove ir.TypeNodeAt
It's deprecated and no longer needed.

Simplify underlying code while here.

Change-Id: I2a6810867d76d8a82ac0d1e6e546a63e6f132736
Reviewed-on: https://go-review.googlesource.com/c/go/+/403836
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
2022-05-05 18:48:01 +00:00
Matthew Dempsky
14fed2c8f1 cmd/compile: remove ir.Field.Ntype
It's never assigned/initialized, so replace all uses with nil.

Change-Id: If224075aab925536114d4ff77b3aaf6b4659c983
Reviewed-on: https://go-review.googlesource.com/c/go/+/403835
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
2022-05-05 18:47:55 +00:00
Matthew Dempsky
73fb829f59 cmd/compile: remove ir.NewField's ntyp parameter
ir.NewField is always called with ntyp as nil.

Change-Id: Iccab4ce20ae70d056370a6469278e68774e685f3
Reviewed-on: https://go-review.googlesource.com/c/go/+/403834
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
2022-05-05 18:47:47 +00:00
Rhys Hiltner
7b1f8b62be runtime: prefer curg for execution trace profile
The CPU profiler adds goroutine labels to its samples based on
getg().m.curg. That allows the profile to correctly attribute work that
the runtime does on behalf of that goroutine on the M's g0 stack via
systemstack calls, such as using runtime.Callers to record the call
stack.

Those labels also cover work on the g0 stack via mcall. When the active
goroutine calls runtime.Gosched, it will receive attribution of its
share of the scheduler work necessary to find the next runnable
goroutine.

The execution tracer's attribution of CPU samples to specific goroutines
should match. When curg is set, attribute the CPU samples to that
goroutine's ID.

Fixes #52693

Change-Id: Ic9af92e153abd8477559e48bc8ebaf3739527b94
Reviewed-on: https://go-review.googlesource.com/c/go/+/404055
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Rhys Hiltner <rhys@justin.tv>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-05-05 18:17:08 +00:00
Roland Shoemaker
fdb640b7a1 crypto/x509: disable signing with MD5WithRSA
MD5 is hopelessly broken, we already don't allow verification of
MD5 signatures, we shouldn't support generating them.

Fixes #42125

Change-Id: Ib25d750e6fc72a03198a505ac71e6d2c99eff2ed
Reviewed-on: https://go-review.googlesource.com/c/go/+/285872
Run-TryBot: Roland Shoemaker <roland@golang.org>
Reviewed-by: Katie Hockman <katie@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Filippo Valsorda <filippo@golang.org>
Reviewed-by: David Chase <drchase@google.com>
2022-05-05 15:43:29 +00:00
Russ Cox
485a572243 cmd: use 128-bit SHA256 & encode in base64 for content hashes
We used to use SHA1 for content hashes, but CL 402595 changed
all the “don't care” hashes to cmd/internal/notsha256 (negated SHA256).
This made object files a little bit bigger: fmt.a on my Mac laptop grows
from 910678 to 937612 bytes (+3%).

To remove that growth, truncate the hash we use for these purposes
to 128 bits (half a SHA256), and also use base64 instead of hex for
encoding it when a string form is needed. This brings fmt.a down to
901706 bytes (-1% from original, -4% from current).

Change-Id: Id81da1cf3ee85ed130b3cda73aa697d8c0053a62
Reviewed-on: https://go-review.googlesource.com/c/go/+/404294
Auto-Submit: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
2022-05-05 14:44:31 +00:00