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

47994 Commits

Author SHA1 Message Date
Tobias Klauser
565e70fcef cmd/link/internal/ld: use linkerFlagSupported to check -Qunused-arguments
Rather than checking the linker name or its path for the string "clang",
use linkerFlagSupported to determine whether the -Qunused-arguments flag
may be passed to the linker.

Fixes #45241

Change-Id: I4c1e4d4ecba4cf5823e8f39cfda5d20404ebf513
Reviewed-on: https://go-review.googlesource.com/c/go/+/304692
Trust: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
2021-03-29 08:11:13 +00:00
smasher164
6f90ee36e9 math: simplify comparison in FMA when swapping p and z
Discovered by Junchen Li on CL 246858, the comparison before p and z are
swapped can be simplified from

    pe < ze || (pe == ze && (pm1 < zm1 || (pm1 == zm1 && pm2 < zm2)))

to

    pe < ze || pe == ze && pm1 < zm1

because zm2 is initialized to 0 before the branch.

Change-Id: Iee92d570038df2b0f8941ef6e422a022654ab2d6
Reviewed-on: https://go-review.googlesource.com/c/go/+/247241
Run-TryBot: Akhil Indurti <aindurti@gmail.com>
Run-TryBot: Emmanuel Odeke <emmanuel@orijtech.com>
Trust: Emmanuel Odeke <emmanuel@orijtech.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
2021-03-29 06:45:05 +00:00
qcrao
d10241fcf6 runtime: fix some typos
Change-Id: I18b9508904f19d5aa68355c937c30b5fdf35442c
Reviewed-on: https://go-review.googlesource.com/c/go/+/305249
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
2021-03-29 06:21:31 +00:00
fanzha02
ba6bd967d2 cmd/compile/internal/ssa: strengthen phiopt pass
The current phiopt pass just transforms the following code
  x := false
  if b { x = true}
into
  x = b

But we find code in runtime.atoi like this:
  neg := false
  if s[0] == '-' {
    neg = true
    s = s[1:]
  }

The current phiopt pass does not covert it into code like:
  neg := s[0] == '-'
  if neg { s = s[1:] }

Therefore, this patch strengthens the phiopt pass so that the
boolean Phi value "neg" can be replaced with a copy of control
value "s[0] == '-'", thereby using "cmp+cset" instead of a branch.

But in some cases even replacing the boolean Phis cannot eliminate
this branch. In the following case, this patch replaces "d" with a
copy of "a<0", but the regalloc pass will insert the "Load {c}"
value into an empty block to split the live ranges, which causes
the branch to not be eliminated.

For example:
  func test(a, b, c int) (bool, int) {
    d := false
    if (a<0) {
      if (b<0) {
        c = c+1
      }
      d = true
    }
    return d, c
  }

The optimized assembly code:
  MOVD "".a(FP), R0
  TBZ $63, R0, 48
  MOVD "".c+16(FP), R1
  ADD $1, R1, R2
  MOVD "".b+8(FP), R3
  CMP ZR, R3
  CSEL LT, R2, R1, R1
  CMP ZR, R0
  CSET LT, R0
  MOVB R0, "".~r3+24(FP)
  MOVD R1, "".~r4+32(FP)
  RET (R30)
  MOVD "".c+16(FP), R1
  JMP 28

The benchmark:

name          old time/op            new time/op            delta
pkg:cmd/compile/internal/ssa goos:linux goarch:arm64
PhioptPass  117783.250000ns +- 1%  117219.111111ns +- 1%   ~  (p=0.074  n=8+9)

Statistical data from compilecmp tool:

compilecmp local/master -> HEAD
local/master (a826f7dc45): debug/dwarf: support DW_FORM_rnglistx aka formRnglistx
HEAD (e57e003c10): cmd/compile/internal/ssa: strengthen phiopt pass

benchstat -geomean  /tmp/2516644532 /tmp/1075915815
completed 50 of 50, estimated time remaining 0s (ETA 7:10PM)
name                      old time/op       new time/op       delta
Template                        554ms _ 3%        553ms _ 3%    ~     (p=0.986 n=49+48)
Unicode                         252ms _ 4%        249ms _ 4%  -1.33%  (p=0.002 n=47+49)
GoTypes                         3.16s _ 3%        3.18s _ 3%  +0.77%  (p=0.022 n=44+48)
Compiler                        257ms _ 4%        258ms _ 4%    ~     (p=0.121 n=50+49)
SSA                             24.2s _ 4%        24.2s _ 5%    ~     (p=0.694 n=49+50)
Flate                           338ms _ 4%        338ms _ 4%    ~     (p=0.592 n=43+46)
GoParser                        506ms _ 3%        507ms _ 3%    ~     (p=0.942 n=49+50)
Reflect                         1.37s _ 4%        1.37s _ 5%    ~     (p=0.408 n=50+50)
Tar                             486ms _ 3%        487ms _ 4%    ~     (p=0.911 n=47+50)
XML                             619ms _ 2%        619ms _ 3%    ~     (p=0.368 n=46+48)
LinkCompiler                    1.29s _31%        1.32s _23%    ~     (p=0.306 n=49+44)
ExternalLinkCompiler            3.39s _10%        3.36s _ 6%    ~     (p=0.311 n=48+46)
LinkWithoutDebugCompiler        846ms _37%        793ms _24%  -6.29%  (p=0.040 n=50+49)
[Geo mean]                      974ms             971ms       -0.36%

name                      old user-time/op  new user-time/op  delta
Template                        910ms _12%        893ms _13%    ~     (p=0.098 n=49+49)
Unicode                         495ms _28%        492ms _18%    ~     (p=0.562 n=50+46)
GoTypes                         4.42s _15%        4.39s _13%    ~     (p=0.684 n=49+50)
Compiler                        419ms _22%        422ms _16%    ~     (p=0.579 n=48+50)
SSA                             36.5s _ 7%        36.6s _ 8%    ~     (p=0.465 n=50+47)
Flate                           521ms _21%        523ms _16%    ~     (p=0.889 n=50+47)
GoParser                        810ms _12%        792ms _15%    ~     (p=0.149 n=50+50)
Reflect                         1.98s _13%        2.02s _13%    ~     (p=0.144 n=47+50)
Tar                             826ms _15%        806ms _19%    ~     (p=0.115 n=49+49)
XML                             988ms _14%       1003ms _14%    ~     (p=0.179 n=50+50)
LinkCompiler                    1.79s _ 8%        1.84s _11%  +2.81%  (p=0.001 n=49+49)
ExternalLinkCompiler            3.69s _ 4%        3.71s _ 3%    ~     (p=0.261 n=50+50)
LinkWithoutDebugCompiler        838ms _10%        827ms _11%    ~     (p=0.323 n=50+48)
[Geo mean]                      1.44s             1.44s       -0.05%

name                      old alloc/op      new alloc/op      delta
Template                       39.0MB _ 1%       39.0MB _ 1%    ~     (p=0.445 n=50+49)
Unicode                        28.5MB _ 0%       28.5MB _ 0%    ~     (p=0.460 n=50+50)
GoTypes                         169MB _ 1%        169MB _ 1%    ~     (p=0.092 n=48+50)
Compiler                       23.4MB _ 1%       23.4MB _ 1%  -0.19%  (p=0.032 n=50+49)
SSA                            1.54GB _ 0%       1.55GB _ 1%  +0.14%  (p=0.001 n=50+50)
Flate                          23.8MB _ 1%       23.8MB _ 2%    ~     (p=0.702 n=49+49)
GoParser                       35.4MB _ 1%       35.4MB _ 1%    ~     (p=0.786 n=50+50)
Reflect                        85.3MB _ 1%       85.3MB _ 1%    ~     (p=0.298 n=50+50)
Tar                            34.6MB _ 2%       34.6MB _ 2%    ~     (p=0.683 n=50+50)
XML                            44.5MB _ 3%       44.0MB _ 2%  -1.05%  (p=0.000 n=50+46)
LinkCompiler                    136MB _ 0%        136MB _ 0%  +0.01%  (p=0.005 n=50+50)
ExternalLinkCompiler            128MB _ 0%        128MB _ 0%    ~     (p=0.179 n=50+50)
LinkWithoutDebugCompiler       84.3MB _ 0%       84.3MB _ 0%  +0.01%  (p=0.006 n=50+50)
[Geo mean]                     70.7MB            70.6MB       -0.07%

name                      old allocs/op     new allocs/op     delta
Template                         410k _ 0%         410k _ 0%    ~     (p=0.606 n=48+49)
Unicode                          310k _ 0%         310k _ 0%    ~     (p=0.674 n=50+50)
GoTypes                         1.81M _ 0%        1.81M _ 0%    ~     (p=0.674 n=50+50)
Compiler                         202k _ 0%         202k _ 0%  +0.02%  (p=0.046 n=50+50)
SSA                             16.3M _ 0%        16.3M _ 0%  +0.10%  (p=0.000 n=50+50)
Flate                            244k _ 0%         244k _ 0%    ~     (p=0.834 n=49+50)
GoParser                         380k _ 0%         380k _ 0%    ~     (p=0.410 n=50+50)
Reflect                         1.08M _ 0%        1.08M _ 0%    ~     (p=0.782 n=48+50)
Tar                              368k _ 0%         368k _ 0%    ~     (p=0.585 n=50+49)
XML                              453k _ 0%         453k _ 0%  -0.01%  (p=0.025 n=49+49)
LinkCompiler                     713k _ 0%         713k _ 0%  +0.01%  (p=0.044 n=50+50)
ExternalLinkCompiler             794k _ 0%         794k _ 0%  +0.01%  (p=0.000 n=50+49)
LinkWithoutDebugCompiler         251k _ 0%         251k _ 0%    ~     (p=0.092 n=47+50)
[Geo mean]                       615k              615k       +0.01%

name                      old maxRSS/op     new maxRSS/op     delta
Template                        37.0M _ 4%        37.2M _ 3%    ~     (p=0.062 n=48+48)
Unicode                         36.9M _ 5%        37.3M _ 4%  +1.10%  (p=0.021 n=50+47)
GoTypes                         94.3M _ 3%        94.9M _ 4%  +0.69%  (p=0.022 n=45+46)
Compiler                        33.4M _ 3%        33.4M _ 5%    ~     (p=0.964 n=49+50)
SSA                              741M _ 3%         738M _ 3%    ~     (p=0.164 n=50+50)
Flate                           28.5M _ 6%        28.8M _ 4%  +1.07%  (p=0.009 n=50+49)
GoParser                        35.0M _ 3%        35.3M _ 4%  +0.83%  (p=0.010 n=50+48)
Reflect                         57.2M _ 6%        57.1M _ 4%    ~     (p=0.815 n=50+49)
Tar                             34.9M _ 3%        35.0M _ 3%    ~     (p=0.134 n=49+48)
XML                             39.5M _ 5%        40.0M _ 3%  +1.35%  (p=0.001 n=50+48)
LinkCompiler                     220M _ 2%         220M _ 2%    ~     (p=0.547 n=49+48)
ExternalLinkCompiler             235M _ 2%         236M _ 2%    ~     (p=0.538 n=47+44)
LinkWithoutDebugCompiler         179M _ 1%         179M _ 1%    ~     (p=0.775 n=50+50)
[Geo mean]                      74.9M             75.2M       +0.43%

name                      old text-bytes    new text-bytes    delta
HelloSize                       784kB _ 0%        784kB _ 0%  +0.01%  (p=0.000 n=50+50)

name                      old data-bytes    new data-bytes    delta
HelloSize                      13.1kB _ 0%       13.1kB _ 0%    ~     (all equal)

name                      old bss-bytes     new bss-bytes     delta
HelloSize                       206kB _ 0%        206kB _ 0%    ~     (all equal)

name                      old exe-bytes     new exe-bytes     delta
HelloSize                      1.28MB _ 0%       1.28MB _ 0%  +0.00%  (p=0.000 n=50+50)

file      before    after     _       %
addr2line 4006300   4004484   -1816   -0.045%
api       5029956   5029324   -632    -0.013%
asm       4936311   4939423   +3112   +0.063%
buildid   2595059   2595291   +232    +0.009%
cgo       4401029   4397333   -3696   -0.084%
compile   22246677  22246863  +186    +0.001%
cover     4443825   4443065   -760    -0.017%
dist      3366078   3365838   -240    -0.007%
doc       3776391   3776615   +224    +0.006%
fix       3218800   3218648   -152    -0.005%
link      6365321   6365345   +24     +0.000%
nm        3923625   3923857   +232    +0.006%
objdump   4295569   4295041   -528    -0.012%
pack      2390745   2389217   -1528   -0.064%
pprof     12870094  12866942  -3152   -0.024%
test2json 2587265   2587073   -192    -0.007%
trace     9612629   9613981   +1352   +0.014%
vet       6791008   6792072   +1064   +0.016%
total     106856682 106850412 -6270   -0.006%

Update #37608

Change-Id: Ic6206b22fd1faf570be9fd3c2511aa6c4ce38cdb
Reviewed-on: https://go-review.googlesource.com/c/go/+/252937
Trust: fannie zhang <Fannie.Zhang@arm.com>
Run-TryBot: fannie zhang <Fannie.Zhang@arm.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
2021-03-29 05:50:11 +00:00
Cuong Manh Le
23ffb5b9ae runtime: overwrite existing keys for mapassign_faststr variant
Fixes #45045

Change-Id: Ifcc7bd31591870446ce3e5127489a0b887d413f1
Reviewed-on: https://go-review.googlesource.com/c/go/+/305089
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
2021-03-28 03:27:04 +00:00
Conrad Irwin
49dccf141f time: add Time.Unix{Milli,Micro} and to-Time helpers UnixMicro, UnixMilli
Adds helper functions for users working with other systems which
represent time in milliseconds or microseconds since the Unix epoch.

Fixes #44196

Change-Id: Ibc4490b52ddec94ebd0c692cb7b52a33e4536759
Reviewed-on: https://go-review.googlesource.com/c/go/+/293349
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-27 05:38:26 +00:00
Baokun Lee
2de1f42857 net: clear completed Buffers to permit earlier collection
Fixes #45163

Change-Id: Ie034145e3818930bb19371d73ec6960cbdc55aa7
Reviewed-on: https://go-review.googlesource.com/c/go/+/303829
Run-TryBot: Baokun Lee <bk@golangcn.org>
Trust: Baokun Lee <bk@golangcn.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
2021-03-27 03:59:08 +00:00
Pat Gavlin
359f44910f cmd/compile: fix long RMW bit operations on AMD64
Under certain circumstances, the existing rules for bit operations can
produce code that writes beyond its intended bounds. For example,
consider the following code:

    func repro(b []byte, addr, bit int32) {
	    _ = b[3]
	    v := uint32(b[0]) | uint32(b[1])<<8 | uint32(b[2])<<16 | uint32(b[3])<<24 | 1<<(bit&31)
	    b[0] = byte(v)
	    b[1] = byte(v >> 8)
	    b[2] = byte(v >> 16)
	    b[3] = byte(v >> 24)
    }

Roughly speaking:

1. The expression `1 << (bit & 31)` is rewritten into `(SHLL 1 bit)`
2. The expression `uint32(b[0]) | uint32(b[1])<<8 | uint32(b[2])<<16 |
   uint32(b[3])<<24` is rewritten into `(MOVLload &b[0])`
3. The statements `b[0] = byte(v) ... b[3] = byte(v >> 24)` are
   rewritten into `(MOVLstore &b[0], v)`
4. `(ORL (SHLL 1, bit) (MOVLload &b[0]))` is rewritten into
   `(BTSL (MOVLload &b[0]) bit)`. This is a valid transformation because
   the destination is a register: in this case, the bit offset is masked
   by the number of bits in the destination register. This is identical
   to the masking performed by `SHL`.
5. `(MOVLstore &b[0] (BTSL (MOVLload &b[0]) bit))` is rewritten into
   `(BTSLmodify &b[0] bit)`. This is an invalid transformation because
   the destination is memory: in this case, the bit offset is not
   masked, and the chosen instruction may write outside its intended
   32-bit location.

These changes fix the invalid rewrite performed in step (5) by
explicitly maksing the bit offset operand to `BT(S|R|C)(L|Q)modify`. In
the example above, the adjusted rules produce
`(BTSLmodify &b[0] (ANDLconst [31] bit))` in step (5).

These changes also add several new rules to rewrite bit sets, toggles,
and clears that are rooted at `(OR|XOR|AND)(L|Q)modify` operators into
appropriate `BT(S|R|C)(L|Q)modify` operators. These rules catch cases
where `MOV(L|Q)store ((OR|XOR|AND)(L|Q) ...)` is rewritten to
`(OR|XOR|AND)(L|Q)modify` before the `(OR|XOR|AND)(L|Q) ...` can be
rewritten to `BT(S|R|C)(L|Q) ...`.

Overall, compilecmp reports small improvements in code size on
darwin/amd64 when the changes to the compiler itself are exlcuded:

file                               before   after    Δ       %
runtime.s                          536464   536412   -52     -0.010%
bytes.s                            32629    32593    -36     -0.110%
strings.s                          44565    44529    -36     -0.081%
os/signal.s                        7967     7959     -8      -0.100%
cmd/vendor/golang.org/x/sys/unix.s 81686    81678    -8      -0.010%
math/big.s                         188235   188253   +18     +0.010%
cmd/link/internal/loader.s         89295    89056    -239    -0.268%
cmd/link/internal/ld.s             633551   633232   -319    -0.050%
cmd/link/internal/arm.s            18934    18928    -6      -0.032%
cmd/link/internal/arm64.s          31814    31801    -13     -0.041%
cmd/link/internal/riscv64.s        7347     7345     -2      -0.027%
cmd/compile/internal/ssa.s         4029173  4033066  +3893   +0.097%
total                              21298280 21301472 +3192   +0.015%

Change-Id: I2e560548b515865129e1724e150e30540e9d29ce
GitHub-Last-Rev: 9a42bd29a5
GitHub-Pull-Request: golang/go#45242
Reviewed-on: https://go-review.googlesource.com/c/go/+/304869
Reviewed-by: Keith Randall <khr@golang.org>
Trust: Josh Bleecher Snyder <josharian@gmail.com>
2021-03-26 19:40:37 +00:00
Tobias Klauser
98a902323f cmd/vendor, cmd/pprof: use golang.org/x/term directly
The cmd/pprof package currently uses golang.org/x/crypto/ssh/terminal
which - as of CL 258003 - is merely a wrapper around golang.org/x/term.

Thus, drop the dependency on golang.org/x/crypto/ssh/terminal and use
golang.org/x/term directly.

Change-Id: Ib15f1f110c338b9dba4a91a873171948ae6298a4
Reviewed-on: https://go-review.googlesource.com/c/go/+/304691
Trust: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
2021-03-26 06:03:20 +00:00
fanzha02
3a0061822e cmd/compile: add arm64 rules to optimize go codes to constant 0
Optimize the following codes to constant 0.

  function shift (x uint32) uint64 {
    return uint64(x) >> 32
  }

Change-Id: Ida6b39d713cc119ad5a2f01fd54bfd252cf2c975
Reviewed-on: https://go-review.googlesource.com/c/go/+/303830
Trust: fannie zhang <Fannie.Zhang@arm.com>
Run-TryBot: fannie zhang <Fannie.Zhang@arm.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2021-03-26 01:57:35 +00:00
Dan Scales
b587b050ca cmd/compile: add transform functions for OXDOT and builtins
Pull out the tranformation part of the typechecking functions for:
 - selector expressions (OXDOT)
 - calls to builtin functions (which go through the typechecker loop
   twice, once for the call and once for each different kind of
   builtin).

Some of the transformation functions create new nodes that should have
the same type as the original node. For consistency, now each of the
transformation functions requires that the node passed in has its type
and typecheck flag set. If the transformation function replaces or adds
new nodes, it will set the type and typecheck flag for those new nodes.

As usual, passes all the gotests, even with -G=3 enabled.

Change-Id: Ic48b0ce5f58425f4a358afa78315bfc7c28066c4
Reviewed-on: https://go-review.googlesource.com/c/go/+/304729
Trust: Dan Scales <danscales@google.com>
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Dan Scales <danscales@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-03-25 23:23:10 +00:00
Michel Levieux
374b190475 io/fs: implement FileInfoToDirEntry
Implements FileInfoToDirEntry which converts an fs.FileInfo to fs.DirEntry.

Fixes #42387.

Change-Id: Ie723b6ed583c6c5ecf22bbe64e3b6496f5114254
Reviewed-on: https://go-review.googlesource.com/c/go/+/293649
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
2021-03-25 21:35:05 +00:00
Cherry Zhang
11b4aee05b cmd/compile: mark R16, R17 clobbered for non-standard calls on ARM64
On ARM64, (external) linker generated trampoline may clobber R16
and R17. In CL 183842 we change Duff's devices not to use those
registers. However, this is not enough. The register allocator
also needs to know that these registers may be clobbered in any
calls that don't follow the standard Go calling convention. This
include Duff's devices and the write barrier.

Fixes #32773, second attempt.

Change-Id: Ia52a891d9bbb8515c927617dd53aee5af5bd9aa4
Reviewed-on: https://go-review.googlesource.com/c/go/+/184437
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Meng Zhuo <mzh@golangcn.org>
Reviewed-by: Keith Randall <khr@golang.org>
Trust: Meng Zhuo <mzh@golangcn.org>
2021-03-25 21:30:55 +00:00
cui
5834ce1dd7 cmd/compile/internal/ssa: unnecessary loop break
Change-Id: I32860a36b4acf5412c20bac2e8ebbb3965b796fe
GitHub-Last-Rev: c007639016
GitHub-Pull-Request: golang/go#43617
Reviewed-on: https://go-review.googlesource.com/c/go/+/282832
Reviewed-by: Keith Randall <khr@golang.org>
Run-TryBot: Keith Randall <khr@golang.org>
Trust: Cherry Zhang <cherryyz@google.com>
2021-03-25 21:28:23 +00:00
Tobias Klauser
691db3737c cmd/cover: use golang.org/x/tools/cover directly
As suggested by Bryan in CL 249759, remove the forwarding aliases in
cmd/cover and use the symbols from golang.org/x/tools directly.

cmd/cover is not an importable package, so it is fine to remove these
exported symbols.

Change-Id: I887c5e9349f2dbe4c90be57f708412b844e18081
Reviewed-on: https://go-review.googlesource.com/c/go/+/304690
Trust: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
2021-03-25 20:57:58 +00:00
Damien Neil
5cec8b85e5 net/http/httptest: wait for user ConnState hooks
Ensure that user ConnState callbacks have completed before returning
from (*httptest.Server).Close.

Fixes: #37510
Fixes: #37505
Fixes: #45237
Change-Id: I8fe7baa089fbe4f3836bf6ae9767c7b1270d1331
Reviewed-on: https://go-review.googlesource.com/c/go/+/304829
Trust: Damien Neil <dneil@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
2021-03-25 20:28:20 +00:00
Josh Rickmar
7ce361737f net: only perform IPv4 map check for AF_INET6 sockets
This change avoids executing syscalls testing if IPv4 address mapping
is possible unless the socket being opened belongs to the AF_INET6
family.

In a pledged OpenBSD process, this test is only allowed when the
"inet" pledge is granted; however this check was also being performed
for AF_UNIX sockets (separately permitted under the "unix" pledge),
and would cause the process to be killed by the kernel.  By avoiding
the IPv4 address mapping check until the socket is checked to be
AF_INET6, a pledged OpenBSD process using AF_UNIX sockets without the
"inet" pledge won't be killed for this misbehavior.

The OpenBSD kernel is not currently ready to support using UNIX domain
sockets with only the "unix" pledge (and without "inet"), but this is
one change necessary to support this.

Change-Id: If6962a7ad999b71bcfc9fd8e10d9c4067fa3f338
GitHub-Last-Rev: 3c5541b334
GitHub-Pull-Request: golang/go#45155
Reviewed-on: https://go-review.googlesource.com/c/go/+/303276
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Aaron Bieber <deftly@gmail.com>
Trust: Ian Lance Taylor <iant@golang.org>
2021-03-25 19:55:42 +00:00
Robert Griesemer
569c86d23b cmd/compile/internal/types2: review of importer_test.go
This is a small helper file that provides a default importer
for the type checker tests. There is no go/types equivalent.

The actual change is removing the "// UNREVIEWED" marker.

Change-Id: Ic1f9858bdd9b818d9ddad754e072d9d14d8fb9b3
Reviewed-on: https://go-review.googlesource.com/c/go/+/304252
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-03-25 19:24:25 +00:00
Robert Griesemer
ada77d23ae cmd/compile/internal/types2: review of examples test
The only changes between (equivalent, and reviewed) go/types/examples directory
are in examples/types.go2. The go/types/examples/types.go2 file should be updated
accordingly.

$ f=examples/types.go2; diff $f $HOME/goroot/src/go/types/$f
1d0
< // UNREVIEWED
109c108
< var _ (T /* ERROR cannot use generic type T */ )[ /* ERROR unexpected \[ */ int]
---
> var _ (T /* ERROR cannot use generic type T */ )[ /* ERROR expected ';' */ int]
147a147,154
> // We accept parenthesized embedded struct fields so we can distinguish between
> // a named field with a parenthesized type foo (T) and an embedded parameterized
> // type (foo(T)), similarly to interface embedding.
> // They still need to be valid embedded types after the parentheses are stripped
> // (i.e., in contrast to interfaces, we cannot embed a struct literal). The name
> // of the embedded field is derived as before, after stripping parentheses.
> // (7/14/2020: See comment above. We probably will revert this generalized ability
> // if we go with [] for type parameters.)
149,152c156,158
< 	( /* ERROR cannot parenthesize */ int8)
< 	( /* ERROR cannot parenthesize */ *int16)
< 	*( /* ERROR cannot parenthesize */ int32)
< 	List[int]
---
> 	int8
> 	*int16
> 	*List[int]
155,156c161
< 	* /* ERROR int16 redeclared */ int16
< 	List /* ERROR List redeclared */ [int]
---
> 	* /* ERROR List redeclared */ List[int]
280a286
>

The actual changes are removing the "// UNREVIEWED" markers.

Change-Id: I8a80fa11f3c84f9a403c690b537973a53e1adc2c
Reviewed-on: https://go-review.googlesource.com/c/go/+/304250
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-03-25 19:23:18 +00:00
Robert Griesemer
2c8692d45f cmd/compile/internal/types2: review of example_test.go
The changes between (equivalent, and reviewed) go/types/example_test.go
and example_test.go can be seen by comparing patchset 1 and 2. The actual
changes are removing the "// UNREVIEWED" marker.

The primary differences to go/types/example_test.go are:
- use of syntax instead of go/ast package
- no ExampleMethodSet test (types2 doesn't have MethodSet)
- some code in ExampleInfo is disabled due to less precise
  position information provided by the syntax tree

Change-Id: I035284357acc8ecb7849022b5a9d873ae2235987
Reviewed-on: https://go-review.googlesource.com/c/go/+/304249
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-03-25 19:21:34 +00:00
Robert Griesemer
ffa9983b99 cmd/compile/internal/types2: review of api_test.go
The changes between (equivalent, and reviewed) go/types/api_test.go
and api_test.go can be seen by comparing patchset 1 and 2. The actual
changes are removing the "// UNREVIEWED" marker, the addition of the
TestConvertibleTo and TestAssignableTo tests, and adjustments to test
prefixes (genericPkg, brokenPkg to be in line with go/types).

There are several differences to go/types/api_test.go:
- use of syntax rather than go/ast package
- use of the parseSrc helper function
- TestTypesInfo test entries reflect different handling of untyped nil
- TestInferredInfo is (for go1.17) in another file controlled by a build
  constraint in go/types
- TestSelection test is currently skipped (types2 position information
  is not accurate enough)
- TestScopeLookupParent doesn't have access to a scanner and instead
  relies on syntax.CommentsDo.
- Broken packages are assumed to contain generic code for the tests.

Change-Id: Ic14e6fb9d6bef5416df39e465b5994de76f84097
Reviewed-on: https://go-review.googlesource.com/c/go/+/304131
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-03-25 19:20:52 +00:00
Robert Griesemer
34ef294b76 cmd/compile/internal/types2: review of lookup.go
The changes between (equivalent, and reviewed) go/types/lookup.go
and lookup.go can be seen by comparing patchset 1 and 2. The actual
changes are removing the "// UNREVIEWED" marker.

Note: The function ptrRecv in types2/lookup.go is found in
      methodset.go in go/types (methodset.go doesn't exist
      in types2).

Change-Id: I48cfd3df0947becb4c3b5e55b89263917bcfbf16
Reviewed-on: https://go-review.googlesource.com/c/go/+/304129
Reviewed-by: Robert Findley <rfindley@google.com>
Trust: Robert Griesemer <gri@golang.org>
2021-03-25 19:16:13 +00:00
Robert Griesemer
0fc595ec99 cmd/compile/internal/types2: review of check.go
The changes between (equivalent, and reviewed) go/types/check.go
and check.go can be seen by comparing patchset 1 and 2. The actual
changes are removing the "// UNREVIEWED" marker.

The primary differences to go/types/check.go are:
- use of syntax instead of go/ast package
- tracing is controlled via flag not the "trace" constant

Change-Id: I1c9998afb3e0b7e29f5b169d3a4054cf22841490
Reviewed-on: https://go-review.googlesource.com/c/go/+/304109
Reviewed-by: Robert Findley <rfindley@google.com>
Trust: Robert Griesemer <gri@golang.org>
2021-03-25 19:13:14 +00:00
Johan Jansson
74fe516c35 cmd/go: add -benchtime to cacheable test flags
Add -benchtime to the list of flags that allow caching test results.

If -benchtime is set without -bench, no benchmarks are run. The cache
does not need to be invalidated in this case.

If -benchtime is set with -bench, benchmarks are run. The cache is
invalidated due to the -bench flag in this case.

Fixes #44555

Change-Id: I2eb5c9f389a587d150fb984590d145251d0fa2dc
Reviewed-on: https://go-review.googlesource.com/c/go/+/304689
Reviewed-by: Jay Conrod <jayconrod@google.com>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Trust: Jay Conrod <jayconrod@google.com>
Run-TryBot: Jay Conrod <jayconrod@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-03-25 18:05:10 +00:00
Paul E. Murphy
82a1e0f9d3 cmd/link: make symbol data writable before toc fixup
On ppc64le, we need to insert a load to restore the toc
pointer in R2 after calling into plt stubs. Sometimes the
symbol data is loaded into readonly memory. This is the
case when linking with the race detector code.

Likewise, add extra checks to ensure we can, and are
replacing a nop.

Change-Id: Iea9d9ee7a5ba0f4ce285f4d0422823de1c037cb7
Reviewed-on: https://go-review.googlesource.com/c/go/+/304430
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-25 17:01:28 +00:00
Elias506
4d66d77cd2 database/sql: remove unnecessary types in composite literals
Change-Id: I30c576f826c82cbc62ce28ea7f4886702bd6605d
GitHub-Last-Rev: 2fead200db
GitHub-Pull-Request: golang/go#42618
Reviewed-on: https://go-review.googlesource.com/c/go/+/270000
Reviewed-by: Daniel Theophanes <kardianos@gmail.com>
Trust: Cherry Zhang <cherryyz@google.com>
2021-03-25 14:46:50 +00:00
Than McIntosh
53941b6150 cmd/compile: fix defer desugar keepalive arg handling buglet
Fix a bug in the go/defer desugar handling of keepalive arguments. The
go/defer wrapping code has special handling for calls whose arguments
are pointers that have been cast to "uintptr", so as to insure that
call "keepalive" machinery for such calls continues to work. This
patch fixes a bug in the special case code to insure that it doesn't
kick in for other situations where you have an unsafe.Pointer ->
uintptr argument (outside the keepalive context).

Fixes make.bat on windows with GOEXPERIMENT=regabidefer in effect.

Change-Id: I9db89c4c73f0db1235901a4fae57f62f88c94ac3
Reviewed-on: https://go-review.googlesource.com/c/go/+/304457
Trust: Than McIntosh <thanm@google.com>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Reviewed-by: David Chase <drchase@google.com>
2021-03-25 14:42:40 +00:00
Ayan George
9f4d5c94b0 cmd/go: emit error when listing with -f and -json
Fixes #44738
Change-Id: Ie57ddcbe87408c9644313ec2a9ea347b4d6de76b
Reviewed-on: https://go-review.googlesource.com/c/go/+/298029
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Trust: Jay Conrod <jayconrod@google.com>
2021-03-25 13:57:08 +00:00
Aman Gupta
402d784b8f path/filepath: make Rel handle Windows UNC share
Fixes #41230

Change-Id: Iea15e4ae6d56328333fd22de5d78dfcad78ef1bc
Reviewed-on: https://go-review.googlesource.com/c/go/+/253197
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
Trust: Alex Brainman <alex.brainman@gmail.com>
Trust: Emmanuel Odeke <emmanuel@orijtech.com>
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-03-25 08:43:17 +00:00
Robert Griesemer
dec3d00b28 cmd/compile/internal/types2: review of stdlib_test.go
The changes between (equivalent, and reviewed) go/types/stdlib_test.go
and stdlib_test.go can be seen by comparing patchset 1 and 2. The actual
changes are removing the "// UNREVIEWED" marker, using the os package
instead of ioutil, and some comment adjustments. Also, bug251.go passes
because of recent changes.

The primary difference is in the firstComment function which
doesn't have access to a scanner and instead uses the syntax
package's CommentsDu function.

Change-Id: I946ffadc97e87c692f76f369a1b16cceee528477
Reviewed-on: https://go-review.googlesource.com/c/go/+/304130
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-03-25 04:21:29 +00:00
Robert Griesemer
ddcdbb417b cmd/compile/internal/types2: review of assignments.go
The changes between (equivalent, and reviewed) go/types/assignments.go
and assignments.go can be seen by comparing patchset 1 and 2. The actual
changes are removing the "// UNREVIEWED" marker.

The primary differences to go/types/assignments.go are:
- use of syntax instead of go/ast package
- no reporting of error codes (for now)
- different handling of nil values (we can't use Typ[UntypedNil]
  to represent an untyped nil because types2 gives such nil values
  context-dependent types)

Change-Id: I5d8a58f43ca8ed2daa060c46842a6ebc11b3cb35
Reviewed-on: https://go-review.googlesource.com/c/go/+/304051
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-03-25 04:14:58 +00:00
Robert Griesemer
607f99904e cmd/compile/internal/types2: review of api.go
The changes between (equivalent, and reviewed) go/types/api.go
and api.go can be seen by comparing patchset 1 and 2. The actual
changes are removing the "// UNREVIEWED" marker.

The primary differences to go/types/api.go are:
- use of syntax instead of go/ast package
- use of simpler Error type (for now)
- additional exported Config flags
- different handling of nil values (we can't use Typ[UntypedNil]
  to represent an untyped nil because types2 gives such nil values
  context-dependent types)

Change-Id: I7d46b29d460c656d7a36fe70108a370383266373
Reviewed-on: https://go-review.googlesource.com/c/go/+/304050
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-03-25 04:11:06 +00:00
Robert Griesemer
c69515c9fd cmd/compile/internal/types2: review of expr.go
The changes between (equivalent, and reviewed) go/types/expr.go
and expr.go can be seen by comparing patchset 1 and 2. The actual
changes are removing the "// UNREVIEWED" marker.

The primary differences to go/types/expr.go are:
- use of package syntax rather than ast
- no reporting of error codes in errors
- implicit conversions of untyped nil lead to a typed nil
  (in go/types, nil remains untyped)

Change-Id: I1e235b20ebda597eb7ce597d1749f26431addde2
Reviewed-on: https://go-review.googlesource.com/c/go/+/303092
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-03-25 04:06:37 +00:00
Bryan C. Mills
4889afe8f8 cmd/go/internal/load: use setLoadPackageDataError in loadImport
This makes the error handling in loadImport somewhat more uniform,
with no discernable effect on reported errors.

Noticed in CL 303869.

Updates #36087
Updates #38034

This somewhat simplifies the code, with no discernable effect on

Change-Id: I30521f658f264d6f99d1844d6701269bbb372246
Reviewed-on: https://go-review.googlesource.com/c/go/+/304069
Trust: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
2021-03-25 03:19:56 +00:00
Bryan C. Mills
adb037d67a cmd/go: attribute direct imports from indirect dependencies to the importing package
For #36460
Updates #40775

Change-Id: I833ee8ee733151aafcff508bf91d0e6e37c50032
Reviewed-on: https://go-review.googlesource.com/c/go/+/303869
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>
2021-03-25 03:17:51 +00:00
Bryan C. Mills
954879d6d1 cmd/go/internal/modload: replace the global buildList with structured requirements
This is intended to be a pure-refactoring change, with very little
observable change in the behavior of the 'go' command. A few error
messages have prefixes changed (by virtue of being attached to
packages or modules instead of the build list overall), and
'go list -m' (without arguments) no longer loads the complete module
graph in order to provide the name of the (local) main module.

The previous modload.buildList variable contained a flattened build
list, from which the go.mod file was reconstructed using various
heuristics and metadata cobbled together from the original go.mod
file, the package loader (which was occasionally constructed without
actually loading packages, for the sole purpose of populating
otherwise-unrelated metadata!), and the updated build list.

This change replaces that variable with a new package-level variable,
named "requirements". The new variable is structured to match the
structure of the go.mod file: it explicitly specifies the roots of the
module graph, from which the complete module graph and complete build
list can be reconstructed (and cached) on demand. Similarly, the
"direct" markings on the go.mod requirements are now stored alongside
the requirements themselves, rather than side-channeled through the
loader.

The requirements are now plumbed explicitly though the modload
package, with accesses to the package-level variable occurring only
within top-level exported functions. The structured requirements are
logically immutable, so a new copy of the requirements is constructed
whenever the requirements are changed, substantially reducing implicit
communication-by-sharing in the package.

For #36460
Updates #40775

Change-Id: I97bb0381708f9d3e42af385b5c88a7038e1f0556
Reviewed-on: https://go-review.googlesource.com/c/go/+/293689
Trust: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
2021-03-25 03:17:36 +00:00
Bryan C. Mills
a95e2ae280 test: skip fixedbugs/issue36705 on Windows
This test is verifying that setting or unsetting an environment
variable in Go via the "os" package makes that change visible to the C
getenv function. The test has been failing on Windows since CL 304569;
it isn't clear to me whether it was running at all before that point.

On Windows the getenv and _putenv C functions are not thread-safe,
so Go's os.Setenv and os.Getenv use the SetEnvironmentVariable and
GetEnvironmentVariable system calls instead. That seems to work fine
in practice; however, changes via SetEnvironmentVariable are
empirically not visible to the C getenv function on certain versions
of Windows.

The MSDN getenv documentation¹ states that ‘getenv operates only on
the data structures accessible to the run-time library and not on the
environment “segment” created for the process by the operating system.
Therefore, programs that use the envp argument to main or wmain may
retrieve invalid information.’ That may be related to what we're
seeing here.

(https://github.com/curl/curl/issues/4774 describes this same behavior
observed in the curl project.)

¹https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/getenv-wgetenv?view=msvc-160#remarks

Updates #36705

Change-Id: I222792f75c650f32c5025b0fa3edab232ff66353
Reviewed-on: https://go-review.googlesource.com/c/go/+/304669
Trust: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-03-25 02:50:11 +00:00
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