From 069f9d96d179becc61231d566c9a75f1ec26e991 Mon Sep 17 00:00:00 2001
From: Ian Lance Taylor
Date: Fri, 11 Dec 2020 19:10:00 -0800
Subject: [release-branch.go1.15] doc/go1.15: mention 1.15.3 cgo restriction on
empty structs
For #40954
Change-Id: I6a30aed31a16e820817f4ca5c7f591222e922946
Reviewed-on: https://go-review.googlesource.com/c/go/+/277432
Trust: Ian Lance Taylor
Reviewed-by: Keith Randall
(cherry picked from commit 129bb1917b4914f0743ec9b4ef0dfb74df39c07d)
Reviewed-on: https://go-review.googlesource.com/c/go/+/278573
Run-TryBot: Ian Lance Taylor
TryBot-Result: Go Bot
Reviewed-by: Dmitri Shuralyov
---
doc/go1.15.html | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/doc/go1.15.html b/doc/go1.15.html
index c691bf3bd5..c9997c0ca3 100644
--- a/doc/go1.15.html
+++ b/doc/go1.15.html
@@ -397,6 +397,19 @@ Do not send CLs removing the interior tags from such phrases.
documentation for more information.
+
+ In Go 1.15.3 and later, cgo will not permit Go code to allocate an
+ undefined struct type (a C struct defined as just struct
+ S;
or similar) on the stack or heap.
+ Go code will only be permitted to use pointers to those types.
+ Allocating an instance of such a struct and passing a pointer, or a
+ full struct value, to C code was always unsafe and unlikely to work
+ correctly; it is now forbidden.
+ The fix is to either rewrite the Go code to use only pointers, or to
+ ensure that the Go code sees the full definition of the struct by
+ including the appropriate C header file.
+
+
X.509 CommonName deprecation
--
cgit v1.2.3-54-g00ecf
From aaef93bba34740d793e987d95355feb312f01cfd Mon Sep 17 00:00:00 2001
From: Jay Conrod
Date: Wed, 20 Jan 2021 09:45:03 -0500
Subject: [release-branch.go1.15] cmd/go: fix mod_get_fallback test
Fixes #43797
Change-Id: I3d791d0ac9ce0b523c78c649aaf5e339a7f63b76
Reviewed-on: https://go-review.googlesource.com/c/go/+/284797
Trust: Jay Conrod
Run-TryBot: Jay Conrod
Reviewed-by: Bryan C. Mills
TryBot-Result: Go Bot
(cherry picked from commit be28e5abc5ddca0d6b2d8c91b7bb9c05717154e7)
Reviewed-on: https://go-review.googlesource.com/c/go/+/284799
---
src/cmd/go/testdata/script/mod_get_fallback.txt | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/cmd/go/testdata/script/mod_get_fallback.txt b/src/cmd/go/testdata/script/mod_get_fallback.txt
index a9834a324e..9733fa366b 100644
--- a/src/cmd/go/testdata/script/mod_get_fallback.txt
+++ b/src/cmd/go/testdata/script/mod_get_fallback.txt
@@ -6,5 +6,5 @@ env GOPROXY=https://proxy.golang.org,direct
env GOSUMDB=off
go get -x -v -d golang.org/x/tools/cmd/goimports
-stderr '# get https://proxy.golang.org/golang.org/x/tools/@latest'
+stderr '# get https://proxy.golang.org/golang.org/x/tools/@v/list'
! stderr '# get https://golang.org'
--
cgit v1.2.3-54-g00ecf
From e540758b604dd46b682593e284cf77a61ce3fde6 Mon Sep 17 00:00:00 2001
From: Roland Shoemaker
Date: Wed, 20 Jan 2021 09:06:12 -0800
Subject: [release-branch.go1.15] internal/execabs: only run tests on platforms
that support them
Fixes #43793
Change-Id: I3bf022a28b194f0089ea96d93e56bbd9fb7e0aa8
Reviewed-on: https://go-review.googlesource.com/c/go/+/285056
Trust: Roland Shoemaker
Run-TryBot: Roland Shoemaker
Reviewed-by: Dmitri Shuralyov
---
src/internal/execabs/execabs_test.go | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/src/internal/execabs/execabs_test.go b/src/internal/execabs/execabs_test.go
index a0b88dd2a0..1a197b8701 100644
--- a/src/internal/execabs/execabs_test.go
+++ b/src/internal/execabs/execabs_test.go
@@ -7,6 +7,7 @@ package execabs
import (
"context"
"fmt"
+ "internal/testenv"
"io/ioutil"
"os"
"os/exec"
@@ -30,6 +31,8 @@ func TestFixCmd(t *testing.T) {
}
func TestCommand(t *testing.T) {
+ testenv.MustHaveExec(t)
+
for _, cmd := range []func(string) *Cmd{
func(s string) *Cmd { return Command(s) },
func(s string) *Cmd { return CommandContext(context.Background(), s) },
@@ -71,6 +74,8 @@ func TestCommand(t *testing.T) {
}
func TestLookPath(t *testing.T) {
+ testenv.MustHaveExec(t)
+
tmpDir, err := ioutil.TempDir("", "execabs-test")
if err != nil {
t.Fatalf("ioutil.TempDir failed: %s", err)
--
cgit v1.2.3-54-g00ecf
From 27d5fccd2119099c70ab6a4418626beac7a97b4b Mon Sep 17 00:00:00 2001
From: Keith Randall
Date: Thu, 7 Jan 2021 14:57:53 -0800
Subject: [release-branch.go1.15] cmd/compile: don't short-circuit copies whose
source is volatile
Current optimization: When we copy a->b and then b->c, we might as well
copy a->c instead of b->c (then b might be dead and go away).
*Except* if a is a volatile location (might be clobbered by a call).
In that case, we really do want to copy a immediately, because there
might be a call before we can do the a->c copy.
User calls can't happen in between, because the rule matches up the
memory states. But calls inserted for memory barriers, particularly
runtime.typedmemmove, can.
(I guess we could introduce a register-calling-convention version
of runtime.typedmemmove, but that seems a bigger change than this one.)
Fixes #43575
Change-Id: Ifa518bb1a6f3a8dd46c352d4fd54ea9713b3eb1a
Reviewed-on: https://go-review.googlesource.com/c/go/+/282492
Trust: Keith Randall
Trust: Josh Bleecher Snyder
Run-TryBot: Keith Randall
TryBot-Result: Go Bot
Reviewed-by: Josh Bleecher Snyder
(cherry picked from commit 304f769ffc68e64244266b3aadbf91e6738c0064)
Reviewed-on: https://go-review.googlesource.com/c/go/+/282558
Trust: Dmitri Shuralyov
---
src/cmd/compile/internal/ssa/gen/generic.rules | 4 +--
src/cmd/compile/internal/ssa/rewritegeneric.go | 8 +++---
test/fixedbugs/issue43570.go | 40 ++++++++++++++++++++++++++
3 files changed, 46 insertions(+), 6 deletions(-)
create mode 100644 test/fixedbugs/issue43570.go
diff --git a/src/cmd/compile/internal/ssa/gen/generic.rules b/src/cmd/compile/internal/ssa/gen/generic.rules
index ed5bfc81fd..8bbe913380 100644
--- a/src/cmd/compile/internal/ssa/gen/generic.rules
+++ b/src/cmd/compile/internal/ssa/gen/generic.rules
@@ -2404,7 +2404,7 @@
(Move {t1} [s] dst tmp1 midmem:(Move {t2} [s] tmp2 src _))
&& t1.Compare(t2) == types.CMPeq
&& isSamePtr(tmp1, tmp2)
- && isStackPtr(src)
+ && isStackPtr(src) && !isVolatile(src)
&& disjoint(src, s, tmp2, s)
&& (disjoint(src, s, dst, s) || isInlinableMemmove(dst, src, s, config))
=> (Move {t1} [s] dst src midmem)
@@ -2413,7 +2413,7 @@
(Move {t1} [s] dst tmp1 midmem:(VarDef (Move {t2} [s] tmp2 src _)))
&& t1.Compare(t2) == types.CMPeq
&& isSamePtr(tmp1, tmp2)
- && isStackPtr(src)
+ && isStackPtr(src) && !isVolatile(src)
&& disjoint(src, s, tmp2, s)
&& (disjoint(src, s, dst, s) || isInlinableMemmove(dst, src, s, config))
=> (Move {t1} [s] dst src midmem)
diff --git a/src/cmd/compile/internal/ssa/rewritegeneric.go b/src/cmd/compile/internal/ssa/rewritegeneric.go
index 9f4e1b95bd..6a09616aad 100644
--- a/src/cmd/compile/internal/ssa/rewritegeneric.go
+++ b/src/cmd/compile/internal/ssa/rewritegeneric.go
@@ -13666,7 +13666,7 @@ func rewriteValuegeneric_OpMove(v *Value) bool {
return true
}
// match: (Move {t1} [s] dst tmp1 midmem:(Move {t2} [s] tmp2 src _))
- // cond: t1.Compare(t2) == types.CMPeq && isSamePtr(tmp1, tmp2) && isStackPtr(src) && disjoint(src, s, tmp2, s) && (disjoint(src, s, dst, s) || isInlinableMemmove(dst, src, s, config))
+ // cond: t1.Compare(t2) == types.CMPeq && isSamePtr(tmp1, tmp2) && isStackPtr(src) && !isVolatile(src) && disjoint(src, s, tmp2, s) && (disjoint(src, s, dst, s) || isInlinableMemmove(dst, src, s, config))
// result: (Move {t1} [s] dst src midmem)
for {
s := auxIntToInt64(v.AuxInt)
@@ -13680,7 +13680,7 @@ func rewriteValuegeneric_OpMove(v *Value) bool {
t2 := auxToType(midmem.Aux)
src := midmem.Args[1]
tmp2 := midmem.Args[0]
- if !(t1.Compare(t2) == types.CMPeq && isSamePtr(tmp1, tmp2) && isStackPtr(src) && disjoint(src, s, tmp2, s) && (disjoint(src, s, dst, s) || isInlinableMemmove(dst, src, s, config))) {
+ if !(t1.Compare(t2) == types.CMPeq && isSamePtr(tmp1, tmp2) && isStackPtr(src) && !isVolatile(src) && disjoint(src, s, tmp2, s) && (disjoint(src, s, dst, s) || isInlinableMemmove(dst, src, s, config))) {
break
}
v.reset(OpMove)
@@ -13690,7 +13690,7 @@ func rewriteValuegeneric_OpMove(v *Value) bool {
return true
}
// match: (Move {t1} [s] dst tmp1 midmem:(VarDef (Move {t2} [s] tmp2 src _)))
- // cond: t1.Compare(t2) == types.CMPeq && isSamePtr(tmp1, tmp2) && isStackPtr(src) && disjoint(src, s, tmp2, s) && (disjoint(src, s, dst, s) || isInlinableMemmove(dst, src, s, config))
+ // cond: t1.Compare(t2) == types.CMPeq && isSamePtr(tmp1, tmp2) && isStackPtr(src) && !isVolatile(src) && disjoint(src, s, tmp2, s) && (disjoint(src, s, dst, s) || isInlinableMemmove(dst, src, s, config))
// result: (Move {t1} [s] dst src midmem)
for {
s := auxIntToInt64(v.AuxInt)
@@ -13708,7 +13708,7 @@ func rewriteValuegeneric_OpMove(v *Value) bool {
t2 := auxToType(midmem_0.Aux)
src := midmem_0.Args[1]
tmp2 := midmem_0.Args[0]
- if !(t1.Compare(t2) == types.CMPeq && isSamePtr(tmp1, tmp2) && isStackPtr(src) && disjoint(src, s, tmp2, s) && (disjoint(src, s, dst, s) || isInlinableMemmove(dst, src, s, config))) {
+ if !(t1.Compare(t2) == types.CMPeq && isSamePtr(tmp1, tmp2) && isStackPtr(src) && !isVolatile(src) && disjoint(src, s, tmp2, s) && (disjoint(src, s, dst, s) || isInlinableMemmove(dst, src, s, config))) {
break
}
v.reset(OpMove)
diff --git a/test/fixedbugs/issue43570.go b/test/fixedbugs/issue43570.go
new file mode 100644
index 0000000000..d073fde5f6
--- /dev/null
+++ b/test/fixedbugs/issue43570.go
@@ -0,0 +1,40 @@
+// run
+
+// Copyright 2021 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+import "fmt"
+
+type T [8]*int
+
+//go:noinline
+func f(x int) T {
+ return T{}
+}
+
+//go:noinline
+func g(x int, t T) {
+ if t != (T{}) {
+ panic(fmt.Sprintf("bad: %v", t))
+ }
+}
+
+func main() {
+ const N = 10000
+ var q T
+ func() {
+ for i := 0; i < N; i++ {
+ q = f(0)
+ g(0, q)
+ sink = make([]byte, 1024)
+ }
+ }()
+ // Note that the closure is a trick to get the write to q to be a
+ // write to a pointer that is known to be non-nil and requires
+ // a write barrier.
+}
+
+var sink []byte
--
cgit v1.2.3-54-g00ecf
From 9bb97ea047890e900dae04202a231685492c4b18 Mon Sep 17 00:00:00 2001
From: Jay Conrod
Date: Fri, 22 Jan 2021 16:59:16 -0500
Subject: [release-branch.go1.15] cmd/go: fix get_update_unknown_protocol test
This test needs to run in GOPATH mode. It broke when a go.mod file was
added to github.com/golang/example. This change sets GO111MODULE=off,
which matches master since CL 255051.
Fixes #43861
Change-Id: I9ea109a99509fac3185756a0f0d852a84c677bf5
Reviewed-on: https://go-review.googlesource.com/c/go/+/285956
Trust: Jay Conrod
Run-TryBot: Jay Conrod
TryBot-Result: Go Bot
Reviewed-by: Bryan C. Mills
---
src/cmd/go/testdata/script/get_update_unknown_protocol.txt | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/cmd/go/testdata/script/get_update_unknown_protocol.txt b/src/cmd/go/testdata/script/get_update_unknown_protocol.txt
index 85c2e24bc8..b00adea70b 100644
--- a/src/cmd/go/testdata/script/get_update_unknown_protocol.txt
+++ b/src/cmd/go/testdata/script/get_update_unknown_protocol.txt
@@ -1,5 +1,6 @@
[!net] skip
[!exec:git] skip
+env GO111MODULE=off
# Clone the repo via HTTPS manually.
exec git clone -q https://github.com/golang/example github.com/golang/example
@@ -10,4 +11,4 @@ cd github.com/golang/example
exec git remote set-url origin xyz://github.com/golang/example
exec git config --local url.https://github.com/.insteadOf xyz://github.com/
-go get -d -u -f github.com/golang/example/hello
\ No newline at end of file
+go get -d -u -f github.com/golang/example/hello
--
cgit v1.2.3-54-g00ecf
From a01db0df00fed281f6a9673eb93fe6acae6197cf Mon Sep 17 00:00:00 2001
From: Damien Neil
Date: Fri, 29 Jan 2021 11:01:37 -0800
Subject: [release-branch.go1.15] net/http: update bundled x/net/http2
Updates bundled http2 to x/net git rev 16c2bbf55 for:
http2: send a nil error if we cancel a delayed body write
https://golang.org/cl/288013
http2: wait until the request body has been written
https://golang.org/cl/288012
Created by:
go mod edit -replace=golang.org/x/net=golang.org/x/net@release-branch.go1.15-bundle
GOFLAGS='-mod=mod' go generate -run=bundle std
go mod edit -dropreplace=golang.org/x/net
go get -d golang.org/x/net@release-branch.go1.15
go mod tidy
go mod vendor
Fixes golang/go#42539
Change-Id: I299c6d4a67ebc036e45c978e4d03cba73717b363
Reviewed-on: https://go-review.googlesource.com/c/go/+/288112
Trust: Damien Neil
Run-TryBot: Damien Neil
Reviewed-by: Dmitri Shuralyov
---
src/net/http/h2_bundle.go | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/src/net/http/h2_bundle.go b/src/net/http/h2_bundle.go
index b03b84d2f3..678c6eb9d4 100644
--- a/src/net/http/h2_bundle.go
+++ b/src/net/http/h2_bundle.go
@@ -7592,6 +7592,9 @@ func (cc *http2ClientConn) roundTrip(req *Request) (res *Response, gotErrAfterRe
// we can keep it.
bodyWriter.cancel()
cs.abortRequestBodyWrite(http2errStopReqBodyWrite)
+ if hasBody && !bodyWritten {
+ <-bodyWriter.resc
+ }
}
if re.err != nil {
cc.forgetStreamID(cs.ID)
@@ -7612,6 +7615,7 @@ func (cc *http2ClientConn) roundTrip(req *Request) (res *Response, gotErrAfterRe
} else {
bodyWriter.cancel()
cs.abortRequestBodyWrite(http2errStopReqBodyWriteAndCancel)
+ <-bodyWriter.resc
}
cc.forgetStreamID(cs.ID)
return nil, cs.getStartedWrite(), http2errTimeout
@@ -7621,6 +7625,7 @@ func (cc *http2ClientConn) roundTrip(req *Request) (res *Response, gotErrAfterRe
} else {
bodyWriter.cancel()
cs.abortRequestBodyWrite(http2errStopReqBodyWriteAndCancel)
+ <-bodyWriter.resc
}
cc.forgetStreamID(cs.ID)
return nil, cs.getStartedWrite(), ctx.Err()
@@ -7630,6 +7635,7 @@ func (cc *http2ClientConn) roundTrip(req *Request) (res *Response, gotErrAfterRe
} else {
bodyWriter.cancel()
cs.abortRequestBodyWrite(http2errStopReqBodyWriteAndCancel)
+ <-bodyWriter.resc
}
cc.forgetStreamID(cs.ID)
return nil, cs.getStartedWrite(), http2errRequestCanceled
@@ -7639,6 +7645,7 @@ func (cc *http2ClientConn) roundTrip(req *Request) (res *Response, gotErrAfterRe
// forgetStreamID.
return nil, cs.getStartedWrite(), cs.resetErr
case err := <-bodyWriter.resc:
+ bodyWritten = true
// Prefer the read loop's response, if available. Issue 16102.
select {
case re := <-readLoopResCh:
@@ -7649,7 +7656,6 @@ func (cc *http2ClientConn) roundTrip(req *Request) (res *Response, gotErrAfterRe
cc.forgetStreamID(cs.ID)
return nil, cs.getStartedWrite(), err
}
- bodyWritten = true
if d := cc.responseHeaderTimeout(); d != 0 {
timer := time.NewTimer(d)
defer timer.Stop()
@@ -9060,7 +9066,9 @@ func (t *http2Transport) getBodyWriterState(cs *http2clientStream, body io.Reade
func (s http2bodyWriterState) cancel() {
if s.timer != nil {
- s.timer.Stop()
+ if s.timer.Stop() {
+ s.resc <- nil
+ }
}
}
--
cgit v1.2.3-54-g00ecf
From 4a48a7d7bda25a844a7e597e96041b55c9f32d4d Mon Sep 17 00:00:00 2001
From: Jay Conrod
Date: Fri, 22 Jan 2021 14:27:24 -0500
Subject: [release-branch.go1.15] cmd/go: don't lookup the path for CC when
invoking cgo
Previously, if CC was a path without separators (like gcc or clang),
we'd look it up in PATH in cmd/go using internal/execabs.LookPath,
then pass the resolved path to cgo in CC.
This caused a regression: if the directory in PATH containing CC has a
space, cgo splits it and interprets it as multiple arguments.
With this change, cmd/go no longer resolves CC before invoking
cgo. cgo does the path lookup on each invocation. This reverts the
security fix CL 284780, but that was redundant with the addition of
internal/execabs (CL 955304), which still protects us.
NOTE: This CL includes a related test fix from CL 286292.
Fixes #43860
Change-Id: I65d91a1e303856df8653881eb6e2e75a3bf95c49
Reviewed-on: https://go-review.googlesource.com/c/go/+/285873
Trust: Jay Conrod
Run-TryBot: Jay Conrod
TryBot-Result: Go Bot
Reviewed-by: Bryan C. Mills
(cherry picked from commit a2cef9b544708ecae983ed8836ee2425a28aab68)
Reviewed-on: https://go-review.googlesource.com/c/go/+/285954
Run-TryBot: Dmitri Shuralyov
---
src/cmd/go/internal/work/action.go | 3 --
src/cmd/go/internal/work/exec.go | 27 +++----------
src/cmd/go/testdata/script/cgo_path.txt | 12 +++++-
src/cmd/go/testdata/script/cgo_path_space.txt | 56 +++++++++++++++++++++++++++
4 files changed, 72 insertions(+), 26 deletions(-)
create mode 100644 src/cmd/go/testdata/script/cgo_path_space.txt
diff --git a/src/cmd/go/internal/work/action.go b/src/cmd/go/internal/work/action.go
index 03ca301bdd..6b5f9e4807 100644
--- a/src/cmd/go/internal/work/action.go
+++ b/src/cmd/go/internal/work/action.go
@@ -56,9 +56,6 @@ type Builder struct {
id sync.Mutex
toolIDCache map[string]string // tool name -> tool ID
buildIDCache map[string]string // file name -> build ID
-
- cgoEnvOnce sync.Once
- cgoEnvCache []string
}
// NOTE: Much of Action would not need to be exported if not for test.
diff --git a/src/cmd/go/internal/work/exec.go b/src/cmd/go/internal/work/exec.go
index f5f9951afa..eb1efd9f82 100644
--- a/src/cmd/go/internal/work/exec.go
+++ b/src/cmd/go/internal/work/exec.go
@@ -1081,7 +1081,10 @@ func (b *Builder) vet(a *Action) error {
}
// TODO(rsc): Why do we pass $GCCGO to go vet?
- env := b.cgoEnv()
+ env := b.cCompilerEnv()
+ if cfg.BuildToolchainName == "gccgo" {
+ env = append(env, "GCCGO="+BuildToolchain.compiler())
+ }
p := a.Package
tool := VetTool
@@ -2015,24 +2018,6 @@ func (b *Builder) cCompilerEnv() []string {
return []string{"TERM=dumb"}
}
-// cgoEnv returns environment variables to set when running cgo.
-// Some of these pass through to cgo running the C compiler,
-// so it includes cCompilerEnv.
-func (b *Builder) cgoEnv() []string {
- b.cgoEnvOnce.Do(func() {
- cc, err := exec.LookPath(b.ccExe()[0])
- if err != nil || filepath.Base(cc) == cc { // reject relative path
- cc = "/missing-cc"
- }
- gccgo := GccgoBin
- if filepath.Base(gccgo) == gccgo { // reject relative path
- gccgo = "/missing-gccgo"
- }
- b.cgoEnvCache = append(b.cCompilerEnv(), "CC="+cc, "GCCGO="+gccgo)
- })
- return b.cgoEnvCache
-}
-
// mkdir makes the named directory.
func (b *Builder) Mkdir(dir string) error {
// Make Mkdir(a.Objdir) a no-op instead of an error when a.Objdir == "".
@@ -2622,7 +2607,7 @@ func (b *Builder) cgo(a *Action, cgoExe, objdir string, pcCFLAGS, pcLDFLAGS, cgo
// along to the host linker. At this point in the code, cgoLDFLAGS
// consists of the original $CGO_LDFLAGS (unchecked) and all the
// flags put together from source code (checked).
- cgoenv := b.cgoEnv()
+ cgoenv := b.cCompilerEnv()
if len(cgoLDFLAGS) > 0 {
flags := make([]string, len(cgoLDFLAGS))
for i, f := range cgoLDFLAGS {
@@ -2843,7 +2828,7 @@ func (b *Builder) dynimport(a *Action, p *load.Package, objdir, importGo, cgoExe
if p.Standard && p.ImportPath == "runtime/cgo" {
cgoflags = []string{"-dynlinker"} // record path to dynamic linker
}
- return b.run(a, p.Dir, p.ImportPath, b.cgoEnv(), cfg.BuildToolexec, cgoExe, "-dynpackage", p.Name, "-dynimport", dynobj, "-dynout", importGo, cgoflags)
+ return b.run(a, p.Dir, p.ImportPath, b.cCompilerEnv(), cfg.BuildToolexec, cgoExe, "-dynpackage", p.Name, "-dynimport", dynobj, "-dynout", importGo, cgoflags)
}
// Run SWIG on all SWIG input files.
diff --git a/src/cmd/go/testdata/script/cgo_path.txt b/src/cmd/go/testdata/script/cgo_path.txt
index 0d15998426..3eba71bc15 100644
--- a/src/cmd/go/testdata/script/cgo_path.txt
+++ b/src/cmd/go/testdata/script/cgo_path.txt
@@ -1,12 +1,20 @@
[!cgo] skip
+# Set CC explicitly to something that requires a PATH lookup.
+# Normally, the default is gcc or clang, but if CC was set during make.bash,
+# that becomes the default.
+[exec:clang] env CC=clang
+[exec:gcc] env CC=gcc
+[!exec:clang] [!exec:gcc] skip 'Unknown C compiler'
+
env GOCACHE=$WORK/gocache # Looking for compile flags, so need a clean cache.
[!windows] env PATH=.:$PATH
-[!windows] chmod 0777 p/gcc p/clang
+[!windows] chmod 0755 p/gcc p/clang
[!windows] exists -exec p/gcc p/clang
[windows] exists -exec p/gcc.bat p/clang.bat
! exists p/bug.txt
-go build -x
+! go build -x
+stderr '^cgo: exec (clang|gcc): (clang|gcc) resolves to executable in current directory \(.[/\\](clang|gcc)(.bat)?\)$'
! exists p/bug.txt
-- go.mod --
diff --git a/src/cmd/go/testdata/script/cgo_path_space.txt b/src/cmd/go/testdata/script/cgo_path_space.txt
new file mode 100644
index 0000000000..654295dc69
--- /dev/null
+++ b/src/cmd/go/testdata/script/cgo_path_space.txt
@@ -0,0 +1,56 @@
+# Check that if the PATH directory containing the C compiler has a space,
+# we can still use that compiler with cgo.
+# Verifies #43808.
+[!cgo] skip
+
+# Set CC explicitly to something that requires a PATH lookup.
+# Normally, the default is gcc or clang, but if CC was set during make.bash,
+# that becomes the default.
+[exec:clang] env CC=clang
+[exec:gcc] env CC=gcc
+[!exec:clang] [!exec:gcc] skip 'Unknown C compiler'
+
+[!windows] chmod 0755 $WORK/'program files'/clang
+[!windows] chmod 0755 $WORK/'program files'/gcc
+[!windows] exists -exec $WORK/'program files'/clang
+[!windows] exists -exec $WORK/'program files'/gcc
+[!windows] env PATH=$WORK/'program files':$PATH
+[windows] exists -exec $WORK/'program files'/gcc.bat
+[windows] exists -exec $WORK/'program files'/clang.bat
+[windows] env PATH=$WORK\'program files';%PATH%
+
+! exists $WORK/log.txt
+? go build -x
+exists $WORK/log.txt
+rm $WORK/log.txt
+
+# TODO(#41400, #43078): when CC is set explicitly, it should be allowed to
+# contain spaces separating arguments, and it should be possible to quote
+# arguments with spaces (including the path), as in CGO_CFLAGS and other
+# variables. For now, this doesn't work.
+[!windows] env CC=$WORK/'program files'/gcc
+[windows] env CC=$WORK\'program files'\gcc.bat
+! go build -x
+! exists $WORK/log.txt
+
+-- go.mod --
+module m
+
+-- m.go --
+package m
+
+// #define X 1
+import "C"
+
+-- $WORK/program files/gcc --
+#!/bin/sh
+
+echo ok >$WORK/log.txt
+-- $WORK/program files/clang --
+#!/bin/sh
+
+echo ok >$WORK/log.txt
+-- $WORK/program files/gcc.bat --
+echo ok >%WORK%\log.txt
+-- $WORK/program files/clang.bat --
+echo ok >%WORK%\log.txt
--
cgit v1.2.3-54-g00ecf
From aa9b48cd1837644a1555fd7a370800924cef627a Mon Sep 17 00:00:00 2001
From: Derek Parker
Date: Wed, 25 Nov 2020 16:31:57 +0000
Subject: [release-branch.go1.15] cmd/link/internal/ld/pe: fix segfault adding
resource section
The resource symbol may have been copied to the mmap'd
output buffer. If so, certain conditions can cause that
mmap'd output buffer to be munmap'd before we get a chance
to use it. To avoid any issues we copy the data to the heap
when the resource symbol exists.
Fixes #42384
Change-Id: I32ef5420802d7313a3d965b8badfbcfb9f0fba4a
GitHub-Last-Rev: 7b0f43011d06083ee3e871e48a87847636f738f9
GitHub-Pull-Request: golang/go#42427
Reviewed-on: https://go-review.googlesource.com/c/go/+/268018
Run-TryBot: Carlos Amedee
TryBot-Result: Go Bot
Reviewed-by: Russ Cox
Reviewed-by: Cherry Zhang
Reviewed-by: Than McIntosh
Trust: Carlos Amedee
---
src/cmd/link/internal/ld/pe.go | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/src/cmd/link/internal/ld/pe.go b/src/cmd/link/internal/ld/pe.go
index c9cb25dbe5..5d68ca7d9c 100644
--- a/src/cmd/link/internal/ld/pe.go
+++ b/src/cmd/link/internal/ld/pe.go
@@ -1515,6 +1515,18 @@ func Asmbpe(ctxt *Link) {
case sys.AMD64, sys.I386, sys.ARM:
}
+ if rsrcsym != 0 {
+ // The resource symbol may have been copied to the mmap'd
+ // output buffer. If so, certain conditions can cause that
+ // mmap'd output buffer to be munmap'd before we get a chance
+ // to use it. To avoid any issues we copy the data to the heap
+ // when the resource symbol exists.
+ rsrc := ctxt.loader.Syms[rsrcsym]
+ data := make([]byte, len(rsrc.P))
+ copy(data, rsrc.P)
+ rsrc.P = data
+ }
+
t := pefile.addSection(".text", int(Segtext.Length), int(Segtext.Length))
t.characteristics = IMAGE_SCN_CNT_CODE | IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_EXECUTE | IMAGE_SCN_MEM_READ
if ctxt.LinkMode == LinkExternal {
--
cgit v1.2.3-54-g00ecf
From 58dc4452620ebefa75742661c538b8406b213b4a Mon Sep 17 00:00:00 2001
From: Than McIntosh
Date: Tue, 15 Dec 2020 15:54:25 -0500
Subject: [release-branch.go1.15] cmd/internal/goobj2: fix buglet in object
file reader
The code in the Go object file reader was casting a pointer to mmaped
memory into a large array prior to performing a read of the
relocations section:
return (*[1<<20]Reloc)(unsafe.Pointer(&r.b[off]))[:n:n]
For very large object files, this artificial array isn't large enough
(that is, there are more than 1048576 relocs to read), so update the
code to use a larger artifical array size.
Fixes #43214.
Updates #41621.
Change-Id: Ic047c8aef4f8a3839f2e7e3594bce652ebd6bd5b
Reviewed-on: https://go-review.googlesource.com/c/go/+/278492
Run-TryBot: Than McIntosh
TryBot-Result: Go Bot
Reviewed-by: Cherry Zhang
Reviewed-by: Jeremy Faller
Trust: Than McIntosh
(cherry picked from commit f4e7a6b905ce60448e506a3f6578d01b60602cdd)
Reviewed-on: https://go-review.googlesource.com/c/go/+/278673
---
src/cmd/internal/goobj2/objfile.go | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/src/cmd/internal/goobj2/objfile.go b/src/cmd/internal/goobj2/objfile.go
index 7f728e4f76..aba9b9856e 100644
--- a/src/cmd/internal/goobj2/objfile.go
+++ b/src/cmd/internal/goobj2/objfile.go
@@ -379,6 +379,11 @@ func (a *Aux) Write(w *Writer) { w.Bytes(a[:]) }
// for testing
func (a *Aux) fromBytes(b []byte) { copy(a[:], b) }
+// Used to construct an artifically large array type when reading an
+// item from the object file relocs section or aux sym section (needs
+// to work on 32-bit as well as 64-bit). See issue 41621.
+const huge = (1<<31 - 1) / RelocSize
+
// Referenced symbol name.
//
// Serialized format:
@@ -652,7 +657,7 @@ func (r *Reader) Reloc(i int, j int) *Reloc {
func (r *Reader) Relocs(i int) []Reloc {
off := r.RelocOff(i, 0)
n := r.NReloc(i)
- return (*[1 << 20]Reloc)(unsafe.Pointer(&r.b[off]))[:n:n]
+ return (*[huge]Reloc)(unsafe.Pointer(&r.b[off]))[:n:n]
}
// NAux returns the number of aux symbols of the i-th symbol.
@@ -678,7 +683,7 @@ func (r *Reader) Aux(i int, j int) *Aux {
func (r *Reader) Auxs(i int) []Aux {
off := r.AuxOff(i, 0)
n := r.NAux(i)
- return (*[1 << 20]Aux)(unsafe.Pointer(&r.b[off]))[:n:n]
+ return (*[huge]Aux)(unsafe.Pointer(&r.b[off]))[:n:n]
}
// DataOff returns the offset of the i-th symbol's data.
--
cgit v1.2.3-54-g00ecf
From 3171f483775c7eb8d38b68f53d8fd5078db7f967 Mon Sep 17 00:00:00 2001
From: Ian Lance Taylor
Date: Tue, 19 Jan 2021 21:30:36 -0800
Subject: [release-branch.go1.15] runtime: don't adjust timer pp field in
timerWaiting status
Before this CL, the following sequence was possible:
* GC scavenger starts and sets up scavenge.timer
* GC calls readyForScavenger, but sysmon is sleeping
* program calls runtime.GOMAXPROCS to shrink number of processors
* procresize destroys a P, the one that scavenge.timer is on
* (*pp).destroy calls moveTimers, which gets to the scavenger timer
* scavenger timer is timerWaiting, and moveTimers clears t.pp
* sysmon wakes up and calls wakeScavenger
* wakeScavengers calls stopTimer on scavenger.timer, still timerWaiting
* stopTimer calls deltimer which loads t.pp, which is still nil
* stopTimer tries to increment deletedTimers on nil t.pp, and crashes
The point of vulnerability is the time that t.pp is set to nil by
moveTimers and the time that t.pp is set to non-nil by moveTimers,
which is a few instructions at most. So it's not likely and in
particular is quite unlikely on x86. But with a more relaxed memory
model the area of vulnerability can be somewhat larger. This appears
to tbe the cause of two builder failures in a few months on linux-mips.
This CL fixes the problem by making moveTimers change the status from
timerWaiting to timerMoving while t.pp is clear. That will cause
deltimer to wait until the status is back to timerWaiting, at which
point t.pp has been set again.
For #43712
Fixes #43833
Change-Id: I66838319ecfbf15be66c1fac88d9bd40e2295852
Reviewed-on: https://go-review.googlesource.com/c/go/+/284775
Trust: Ian Lance Taylor
Reviewed-by: Michael Knyszek
Reviewed-by: Michael Pratt
(cherry picked from commit d2d155d1ae8c704a37f42fd3ebb1f3846f78e4d4)
Reviewed-on: https://go-review.googlesource.com/c/go/+/287092
Run-TryBot: Carlos Amedee
---
src/runtime/time.go | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/src/runtime/time.go b/src/runtime/time.go
index fdb5066b24..ec3eae9cca 100644
--- a/src/runtime/time.go
+++ b/src/runtime/time.go
@@ -594,8 +594,14 @@ func moveTimers(pp *p, timers []*timer) {
for {
switch s := atomic.Load(&t.status); s {
case timerWaiting:
+ if !atomic.Cas(&t.status, s, timerMoving) {
+ continue
+ }
t.pp = 0
doaddtimer(pp, t)
+ if !atomic.Cas(&t.status, timerMoving, timerWaiting) {
+ badTimer()
+ }
break loop
case timerModifiedEarlier, timerModifiedLater:
if !atomic.Cas(&t.status, s, timerMoving) {
--
cgit v1.2.3-54-g00ecf
From c3e1c3800bfb56bf1b0c3d696f59f42b16bd4fc2 Mon Sep 17 00:00:00 2001
From: Elias Naur
Date: Fri, 25 Dec 2020 11:14:11 +0100
Subject: [release-branch.go1.15] runtime/cgo: fix Android build with NDK 22
Fixes #43406
Change-Id: I7d2b70098a4ba4dcb325fb0be076043789b86135
Reviewed-on: https://go-review.googlesource.com/c/go/+/280312
Run-TryBot: Elias Naur
TryBot-Result: Go Bot
Reviewed-by: Ian Lance Taylor
Trust: Elias Naur
(cherry picked from commit 1d78139128d6d839d7da0aeb10b3e51b6c7c0749)
Reviewed-on: https://go-review.googlesource.com/c/go/+/289149
---
src/runtime/cgo/gcc_linux_386.c | 2 +-
src/runtime/cgo/gcc_linux_amd64.c | 2 +-
src/runtime/cgo/gcc_linux_arm.c | 2 +-
src/runtime/cgo/gcc_linux_arm64.c | 2 +-
4 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/runtime/cgo/gcc_linux_386.c b/src/runtime/cgo/gcc_linux_386.c
index ece9f933c5..70c942aeb8 100644
--- a/src/runtime/cgo/gcc_linux_386.c
+++ b/src/runtime/cgo/gcc_linux_386.c
@@ -12,7 +12,7 @@ static void *threadentry(void*);
static void (*setg_gcc)(void*);
// This will be set in gcc_android.c for android-specific customization.
-void (*x_cgo_inittls)(void **tlsg, void **tlsbase);
+void (*x_cgo_inittls)(void **tlsg, void **tlsbase) __attribute__((common));
void
x_cgo_init(G *g, void (*setg)(void*), void **tlsg, void **tlsbase)
diff --git a/src/runtime/cgo/gcc_linux_amd64.c b/src/runtime/cgo/gcc_linux_amd64.c
index 9134e0df92..f2bf6482cb 100644
--- a/src/runtime/cgo/gcc_linux_amd64.c
+++ b/src/runtime/cgo/gcc_linux_amd64.c
@@ -14,7 +14,7 @@ static void* threadentry(void*);
static void (*setg_gcc)(void*);
// This will be set in gcc_android.c for android-specific customization.
-void (*x_cgo_inittls)(void **tlsg, void **tlsbase);
+void (*x_cgo_inittls)(void **tlsg, void **tlsbase) __attribute__((common));
void
x_cgo_init(G *g, void (*setg)(void*), void **tlsg, void **tlsbase)
diff --git a/src/runtime/cgo/gcc_linux_arm.c b/src/runtime/cgo/gcc_linux_arm.c
index 61855b96b2..5bc0fee90d 100644
--- a/src/runtime/cgo/gcc_linux_arm.c
+++ b/src/runtime/cgo/gcc_linux_arm.c
@@ -10,7 +10,7 @@
static void *threadentry(void*);
-void (*x_cgo_inittls)(void **tlsg, void **tlsbase);
+void (*x_cgo_inittls)(void **tlsg, void **tlsbase) __attribute__((common));
static void (*setg_gcc)(void*);
void
diff --git a/src/runtime/cgo/gcc_linux_arm64.c b/src/runtime/cgo/gcc_linux_arm64.c
index 261c884ac9..17ff274fbb 100644
--- a/src/runtime/cgo/gcc_linux_arm64.c
+++ b/src/runtime/cgo/gcc_linux_arm64.c
@@ -12,7 +12,7 @@
static void *threadentry(void*);
-void (*x_cgo_inittls)(void **tlsg, void **tlsbase);
+void (*x_cgo_inittls)(void **tlsg, void **tlsbase) __attribute__((common));
static void (*setg_gcc)(void*);
void
--
cgit v1.2.3-54-g00ecf
From fa6752a5370735b8c2404d6de5191f2eea67130f Mon Sep 17 00:00:00 2001
From: Carlos Amedee
Date: Thu, 4 Feb 2021 11:17:11 -0500
Subject: [release-branch.go1.15] go1.15.8
Change-Id: Ic8824cabbc8ae62360e0cda4b7c5604db7d405f3
Reviewed-on: https://go-review.googlesource.com/c/go/+/289694
Run-TryBot: Carlos Amedee
TryBot-Result: Go Bot
Reviewed-by: Alexander Rakoczy
Trust: Alexander Rakoczy
Trust: Carlos Amedee
---
VERSION | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/VERSION b/VERSION
index 4b2ef0eb64..3a2ab1d27f 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-go1.15.7
\ No newline at end of file
+go1.15.8
\ No newline at end of file
--
cgit v1.2.3-54-g00ecf