summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCoprDistGit <infra@openeuler.org>2024-10-11 04:29:41 +0000
committerCoprDistGit <infra@openeuler.org>2024-10-11 04:29:41 +0000
commit0e5e3c85a11f65ecd1740f9d01fa2a06383270dc (patch)
tree5a9b5be2e4c74837a68031e6e62788b3dfcc0a52
parent86d143317839566c602c276fafb1a30ad469941e (diff)
-rw-r--r--backport-0016-release-branch.go1.21-internal-poll-add-SPLICE_F_NON.patch79
-rw-r--r--backport-0017-release-branch.go1.21-runtime-call-enableMetadataHug.patch89
-rw-r--r--backport-0018-release-branch.go1.21-cmd-compile-fix-findIndVar-so-.patch91
-rw-r--r--backport-0019-release-branch.go1.21-cmd-compile-fix-escape-analysi.patch112
-rw-r--r--golang.spec18
5 files changed, 388 insertions, 1 deletions
diff --git a/backport-0016-release-branch.go1.21-internal-poll-add-SPLICE_F_NON.patch b/backport-0016-release-branch.go1.21-internal-poll-add-SPLICE_F_NON.patch
new file mode 100644
index 0000000..134d88f
--- /dev/null
+++ b/backport-0016-release-branch.go1.21-internal-poll-add-SPLICE_F_NON.patch
@@ -0,0 +1,79 @@
+From fef8644451930464ffd9f13c82bcd451f58fa575 Mon Sep 17 00:00:00 2001
+From: Andy Pan <panjf2000@gmail.com>
+Date: Tue, 17 Oct 2023 22:38:17 +0800
+Subject: [PATCH 03/20] [release-branch.go1.21] internal/poll: add
+ SPLICE_F_NONBLOCK flag for splice to avoid inconsistency with O_NONBLOCK
+
+Fixes #63801
+Updates #59041
+Updates #63795
+
+Conflict:NA
+Reference:https://go-review.googlesource.com/c/go/+/536015
+
+Details: https://github.com/golang/go/issues/59041#issuecomment-1766610087
+
+Change-Id: Id3fc1df6d86b7c4cc383d09f9465fa8f4cc2a559
+Reviewed-on: https://go-review.googlesource.com/c/go/+/536015
+Reviewed-by: Bryan Mills <bcmills@google.com>
+Reviewed-by: Ian Lance Taylor <iant@google.com>
+LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
+Auto-Submit: Ian Lance Taylor <iant@google.com>
+(cherry picked from commit 40cdf69fc9279ab28f84a6e0f965de8382c578fe)
+Reviewed-on: https://go-review.googlesource.com/c/go/+/538117
+Auto-Submit: Heschi Kreinick <heschi@google.com>
+Reviewed-by: Mauri de Souza Meneguzzo <mauri870@gmail.com>
+Reviewed-by: Heschi Kreinick <heschi@google.com>
+---
+ src/internal/poll/splice_linux.go | 21 +++++++++++++++++++--
+ 1 file changed, 19 insertions(+), 2 deletions(-)
+
+diff --git a/src/internal/poll/splice_linux.go b/src/internal/poll/splice_linux.go
+index 9505c5dcfc1e..72cca34fe4ae 100644
+--- a/src/internal/poll/splice_linux.go
++++ b/src/internal/poll/splice_linux.go
+@@ -13,6 +13,12 @@ import (
+ )
+
+ const (
++ // spliceNonblock doesn't make the splice itself necessarily nonblocking
++ // (because the actual file descriptors that are spliced from/to may block
++ // unless they have the O_NONBLOCK flag set), but it makes the splice pipe
++ // operations nonblocking.
++ spliceNonblock = 0x2
++
+ // maxSpliceSize is the maximum amount of data Splice asks
+ // the kernel to move in a single call to splice(2).
+ // We use 1MB as Splice writes data through a pipe, and 1MB is the default maximum pipe buffer size,
+@@ -89,7 +95,11 @@ func spliceDrain(pipefd int, sock *FD, max int) (int, error) {
+ return 0, err
+ }
+ for {
+- n, err := splice(pipefd, sock.Sysfd, max, 0)
++ // In theory calling splice(2) with SPLICE_F_NONBLOCK could end up an infinite loop here,
++ // because it could return EAGAIN ceaselessly when the write end of the pipe is full,
++ // but this shouldn't be a concern here, since the pipe buffer must be sufficient for
++ // this data transmission on the basis of the workflow in Splice.
++ n, err := splice(pipefd, sock.Sysfd, max, spliceNonblock)
+ if err == syscall.EINTR {
+ continue
+ }
+@@ -127,7 +137,14 @@ func splicePump(sock *FD, pipefd int, inPipe int) (int, error) {
+ }
+ written := 0
+ for inPipe > 0 {
+- n, err := splice(sock.Sysfd, pipefd, inPipe, 0)
++ // In theory calling splice(2) with SPLICE_F_NONBLOCK could end up an infinite loop here,
++ // because it could return EAGAIN ceaselessly when the read end of the pipe is empty,
++ // but this shouldn't be a concern here, since the pipe buffer must contain inPipe size of
++ // data on the basis of the workflow in Splice.
++ n, err := splice(sock.Sysfd, pipefd, inPipe, spliceNonblock)
++ if err == syscall.EINTR {
++ continue
++ }
+ // Here, the condition n == 0 && err == nil should never be
+ // observed, since Splice controls the write side of the pipe.
+ if n > 0 {
+--
+2.33.0
+
diff --git a/backport-0017-release-branch.go1.21-runtime-call-enableMetadataHug.patch b/backport-0017-release-branch.go1.21-runtime-call-enableMetadataHug.patch
new file mode 100644
index 0000000..dec6f61
--- /dev/null
+++ b/backport-0017-release-branch.go1.21-runtime-call-enableMetadataHug.patch
@@ -0,0 +1,89 @@
+From 05bf700ebeec865b73500bd6a2ae93ddbd051692 Mon Sep 17 00:00:00 2001
+From: Michael Anthony Knyszek <mknyszek@google.com>
+Date: Fri, 10 Nov 2023 21:23:38 +0000
+Subject: [PATCH 04/20] [release-branch.go1.21] runtime: call
+ enableMetadataHugePages and its callees on the systemstack
+
+Conflict:NA
+Reference:https://go-review.googlesource.com/c/go/+/541635
+
+These functions acquire the heap lock. If they're not called on the
+systemstack, a stack growth could cause a self-deadlock since stack
+growth may allocate memory from the page heap.
+
+This has been a problem for a while. If this is what's plaguing the
+ppc64 port right now, it's very surprising (and probably just
+coincidental) that it's showing up now.
+
+For #64050.
+For #64062.
+For #64067.
+Fixes #64073.
+
+Change-Id: I2b95dc134d17be63b9fe8f7a3370fe5b5438682f
+Reviewed-on: https://go-review.googlesource.com/c/go/+/541635
+LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
+Run-TryBot: Michael Knyszek <mknyszek@google.com>
+Auto-Submit: Michael Knyszek <mknyszek@google.com>
+TryBot-Result: Gopher Robot <gobot@golang.org>
+Reviewed-by: Michael Pratt <mpratt@google.com>
+Reviewed-by: Paul Murphy <murp@ibm.com>
+(cherry picked from commit 5f08b4479930af266d4a84c1533b320ed75edba7)
+Reviewed-on: https://go-review.googlesource.com/c/go/+/541955
+Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
+Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
+Auto-Submit: Dmitri Shuralyov <dmitshur@google.com>
+---
+ src/runtime/malloc.go | 4 ++++
+ src/runtime/mgc.go | 4 +++-
+ src/runtime/mpagealloc.go | 4 ++++
+ 3 files changed, 11 insertions(+), 1 deletion(-)
+
+diff --git a/src/runtime/malloc.go b/src/runtime/malloc.go
+index 44479cc2be26..b2026ad0dc72 100644
+--- a/src/runtime/malloc.go
++++ b/src/runtime/malloc.go
+@@ -853,6 +853,10 @@ retry:
+ //
+ // The heap lock must not be held over this operation, since it will briefly acquire
+ // the heap lock.
++//
++// Must be called on the system stack because it acquires the heap lock.
++//
++//go:systemstack
+ func (h *mheap) enableMetadataHugePages() {
+ // Enable huge pages for page structure.
+ h.pages.enableChunkHugePages()
+diff --git a/src/runtime/mgc.go b/src/runtime/mgc.go
+index de5ae0ae00c4..a12dbfe9df29 100644
+--- a/src/runtime/mgc.go
++++ b/src/runtime/mgc.go
+@@ -1186,7 +1186,9 @@ func gcMarkTermination() {
+
+ // Enable huge pages on some metadata if we cross a heap threshold.
+ if gcController.heapGoal() > minHeapForMetadataHugePages {
+- mheap_.enableMetadataHugePages()
++ systemstack(func() {
++ mheap_.enableMetadataHugePages()
++ })
+ }
+
+ semrelease(&worldsema)
+diff --git a/src/runtime/mpagealloc.go b/src/runtime/mpagealloc.go
+index 3e789ab85cc0..2861fa93ebf0 100644
+--- a/src/runtime/mpagealloc.go
++++ b/src/runtime/mpagealloc.go
+@@ -437,6 +437,10 @@ func (p *pageAlloc) grow(base, size uintptr) {
+ //
+ // The heap lock must not be held over this operation, since it will briefly acquire
+ // the heap lock.
++//
++// Must be called on the system stack because it acquires the heap lock.
++//
++//go:systemstack
+ func (p *pageAlloc) enableChunkHugePages() {
+ // Grab the heap lock to turn on huge pages for new chunks and clone the current
+ // heap address space ranges.
+--
+2.33.0
+
diff --git a/backport-0018-release-branch.go1.21-cmd-compile-fix-findIndVar-so-.patch b/backport-0018-release-branch.go1.21-cmd-compile-fix-findIndVar-so-.patch
new file mode 100644
index 0000000..fbd8b6a
--- /dev/null
+++ b/backport-0018-release-branch.go1.21-cmd-compile-fix-findIndVar-so-.patch
@@ -0,0 +1,91 @@
+From 4ef68a16e21a2e63f2f6bdc498fe34c9ca994011 Mon Sep 17 00:00:00 2001
+From: Jorropo <jorropo.pgm@gmail.com>
+Date: Sun, 5 Nov 2023 22:40:01 +0100
+Subject: [PATCH 05/20] [release-branch.go1.21] cmd/compile: fix findIndVar so
+ it does not match disjointed loop headers
+
+Fix #63984
+
+Conflict:NA
+Reference:https://go-review.googlesource.com/c/go/+/539977
+
+parseIndVar, prove and maybe more are on the assumption that the loop header
+is a single block. This can be wrong, ensure we don't match theses cases we
+don't know how to handle.
+
+In the future we could update them so that they know how to handle such cases
+but theses cases seems rare so I don't think the value would be really high.
+We could also run a loop canonicalization pass first which could handle this.
+
+The repro case looks weird because I massaged it so it would crash with the
+previous compiler.
+
+Change-Id: I4aa8afae9e90a17fa1085832250fc1139c97faa6
+Reviewed-on: https://go-review.googlesource.com/c/go/+/539977
+Reviewed-by: Heschi Kreinick <heschi@google.com>
+Reviewed-by: Keith Randall <khr@golang.org>
+Reviewed-by: Keith Randall <khr@google.com>
+LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
+(cherry picked from commit 8b4e1259d0e82c8fe38a1456f997a4e9d63573a2)
+Reviewed-on: https://go-review.googlesource.com/c/go/+/540535
+Reviewed-by: Jorropo <jorropo.pgm@gmail.com>
+Reviewed-by: Mauri de Souza Meneguzzo <mauri870@gmail.com>
+Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
+Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
+Auto-Submit: Dmitri Shuralyov <dmitshur@google.com>
+Reviewed-by: Michael Knyszek <mknyszek@google.com>
+---
+ src/cmd/compile/internal/ssa/loopbce.go | 7 +++++++
+ test/fixedbugs/issue63955.go | 22 ++++++++++++++++++++++
+ 2 files changed, 29 insertions(+)
+ create mode 100644 test/fixedbugs/issue63955.go
+
+diff --git a/src/cmd/compile/internal/ssa/loopbce.go b/src/cmd/compile/internal/ssa/loopbce.go
+index b7dfaa33e3bf..7f432e61ba50 100644
+--- a/src/cmd/compile/internal/ssa/loopbce.go
++++ b/src/cmd/compile/internal/ssa/loopbce.go
+@@ -127,6 +127,13 @@ func findIndVar(f *Func) []indVar {
+ less = false
+ }
+
++ if ind.Block != b {
++ // TODO: Could be extended to include disjointed loop headers.
++ // I don't think this is causing missed optimizations in real world code often.
++ // See https://go.dev/issue/63955
++ continue
++ }
++
+ // Expect the increment to be a nonzero constant.
+ if !inc.isGenericIntConst() {
+ continue
+diff --git a/test/fixedbugs/issue63955.go b/test/fixedbugs/issue63955.go
+new file mode 100644
+index 000000000000..258e874220f0
+--- /dev/null
++++ b/test/fixedbugs/issue63955.go
+@@ -0,0 +1,22 @@
++// compile
++
++// Copyright 2023 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 j
++
++func f(try func() int, shouldInc func() bool, N func(int) int) {
++ var n int
++loop: // we want to have 3 preds here, the function entry and both gotos
++ if v := try(); v == 42 || v == 1337 { // the two || are to trick findIndVar
++ if n < 30 { // this aims to be the matched block
++ if shouldInc() {
++ n++
++ goto loop
++ }
++ n = N(n) // try to prevent some block joining
++ goto loop
++ }
++ }
++}
+--
+2.33.0
+
diff --git a/backport-0019-release-branch.go1.21-cmd-compile-fix-escape-analysi.patch b/backport-0019-release-branch.go1.21-cmd-compile-fix-escape-analysi.patch
new file mode 100644
index 0000000..8aa6e2e
--- /dev/null
+++ b/backport-0019-release-branch.go1.21-cmd-compile-fix-escape-analysi.patch
@@ -0,0 +1,112 @@
+From ce09caaeea688251e21a1749ccb89d9160fe2fb2 Mon Sep 17 00:00:00 2001
+From: Matthew Dempsky <mdempsky@google.com>
+Date: Tue, 5 Dec 2023 12:56:04 -0800
+Subject: [PATCH 06/20] [release-branch.go1.21] cmd/compile: fix escape
+ analysis of string min/max
+
+Conflict:NA
+Reference:https://go-review.googlesource.com/c/go/+/547715
+
+When I was plumbing min/max support through the compiler, I was
+thinking mostly about numeric argument types. As a result, I forgot
+that escape analysis would need to be aware that min/max can operate
+on string values, which contain pointers.
+
+Updates #64565.
+Fixes #64567.
+
+Change-Id: I36127ce5a2da942401910fa0f9de922726c9f94d
+Reviewed-on: https://go-review.googlesource.com/c/go/+/547715
+Reviewed-by: Keith Randall <khr@google.com>
+Reviewed-by: Mauri de Souza Meneguzzo <mauri870@gmail.com>
+Auto-Submit: Matthew Dempsky <mdempsky@google.com>
+LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
+(cherry picked from commit 34416d7f6f93cd6562636e311c362ebe421f1a4c)
+Reviewed-on: https://go-review.googlesource.com/c/go/+/547757
+Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
+Reviewed-by: Keith Randall <khr@golang.org>
+---
+ src/cmd/compile/internal/escape/call.go | 10 +++++++++-
+ test/escape_calls.go | 7 +++++++
+ test/fixedbugs/issue64565.go | 15 +++++++++++++++
+ test/fixedbugs/issue64565.out | 3 +++
+ 4 files changed, 34 insertions(+), 1 deletion(-)
+ create mode 100644 test/fixedbugs/issue64565.go
+ create mode 100644 test/fixedbugs/issue64565.out
+
+diff --git a/src/cmd/compile/internal/escape/call.go b/src/cmd/compile/internal/escape/call.go
+index c69eca199877..36e606bf2090 100644
+--- a/src/cmd/compile/internal/escape/call.go
++++ b/src/cmd/compile/internal/escape/call.go
+@@ -186,7 +186,7 @@ func (e *escape) callCommon(ks []hole, call ir.Node, init *ir.Nodes, wrapper *ir
+ argument(e.discardHole(), &call.X)
+ argument(e.discardHole(), &call.Y)
+
+- case ir.ODELETE, ir.OMAX, ir.OMIN, ir.OPRINT, ir.OPRINTN, ir.ORECOVER:
++ case ir.ODELETE, ir.OPRINT, ir.OPRINTN, ir.ORECOVER:
+ call := call.(*ir.CallExpr)
+ fixRecoverCall(call)
+ for i := range call.Args {
+@@ -194,6 +194,14 @@ func (e *escape) callCommon(ks []hole, call ir.Node, init *ir.Nodes, wrapper *ir
+ }
+ argumentRType(&call.RType)
+
++ case ir.OMIN, ir.OMAX:
++ call := call.(*ir.CallExpr)
++ fixRecoverCall(call)
++ for i := range call.Args {
++ argument(ks[0], &call.Args[i])
++ }
++ argumentRType(&call.RType)
++
+ case ir.OLEN, ir.OCAP, ir.OREAL, ir.OIMAG, ir.OCLOSE, ir.OCLEAR:
+ call := call.(*ir.UnaryExpr)
+ argument(e.discardHole(), &call.X)
+diff --git a/test/escape_calls.go b/test/escape_calls.go
+index aa7c7f516cf9..5424c006ee4d 100644
+--- a/test/escape_calls.go
++++ b/test/escape_calls.go
+@@ -52,3 +52,10 @@ func bar() {
+ s := "string"
+ f([]string{s}) // ERROR "\[\]string{...} escapes to heap"
+ }
++
++func strmin(a, b, c string) string { // ERROR "leaking param: a to result ~r0 level=0" "leaking param: b to result ~r0 level=0" "leaking param: c to result ~r0 level=0"
++ return min(a, b, c)
++}
++func strmax(a, b, c string) string { // ERROR "leaking param: a to result ~r0 level=0" "leaking param: b to result ~r0 level=0" "leaking param: c to result ~r0 level=0"
++ return max(a, b, c)
++}
+diff --git a/test/fixedbugs/issue64565.go b/test/fixedbugs/issue64565.go
+new file mode 100644
+index 000000000000..634025ce3ece
+--- /dev/null
++++ b/test/fixedbugs/issue64565.go
+@@ -0,0 +1,15 @@
++// run
++
++// Copyright 2023 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
++
++func main() {
++ m := "0"
++ for _, c := range "321" {
++ m = max(string(c), m)
++ println(m)
++ }
++}
+diff --git a/test/fixedbugs/issue64565.out b/test/fixedbugs/issue64565.out
+new file mode 100644
+index 000000000000..1f242fa6f000
+--- /dev/null
++++ b/test/fixedbugs/issue64565.out
+@@ -0,0 +1,3 @@
++3
++3
++3
+--
+2.33.0
+
diff --git a/golang.spec b/golang.spec
index 2af841f..b9639dc 100644
--- a/golang.spec
+++ b/golang.spec
@@ -66,7 +66,7 @@
Name: golang
Version: 1.21.4
-Release: 17
+Release: 21
Summary: The Go Programming Language
License: BSD and Public Domain
URL: https://golang.org/
@@ -136,6 +136,10 @@ Patch6012: backport-0012-net-http-send-body-or-close-connection-on-expect-100.pa
Patch6013: backport-0013-release-branch.go1.21-net-http-update-bundled-golang.patch
Patch6014: backport-0014-cmd-compile-handle-constant-pointer-offsets-in-dead-.patch
Patch6015: backport-0015-release-branch.go1.21-cmd-compile-ensure-pointer-ari.patch
+Patch6016: backport-0016-release-branch.go1.21-internal-poll-add-SPLICE_F_NON.patch
+Patch6017: backport-0017-release-branch.go1.21-runtime-call-enableMetadataHug.patch
+Patch6018: backport-0018-release-branch.go1.21-cmd-compile-fix-findIndVar-so-.patch
+Patch6019: backport-0019-release-branch.go1.21-cmd-compile-fix-escape-analysi.patch
ExclusiveArch: %{golang_arches}
@@ -374,6 +378,18 @@ fi
%files devel -f go-tests.list -f go-misc.list -f go-src.list
%changelog
+* Thu Sep 19 2024 Vanient <xiadanni1@huawei.com> - 1.21.4-21
+- cmd/compile: fix escape analysis of string min/max
+
+* Thu Aug 1 2024 EulerOSWander <314264452@qq.com> - 1.21.4-20
+- cmd/compile: fix findIndVar so it does not match disjointed loop headers
+
+* Thu Aug 1 2024 EulerOSWander <314264452@qq.com> - 1.21.4-19
+- runtime: call enableMetadataHugePages and its callees on the systemstack
+
+* Thu Aug 1 2024 EulerOSWander <314264452@qq.com> - 1.21.4-18
+- internal/poll:add SPLICE_F_NONBLOCK flag for splice to avoid insonsistency with O_NONBLOCK
+
* Mon Jul 30 2024 jingxiaolu <lujingxiao@huawei.com> - 1.21.4-17
- cmd/compile: ensure pointer arithmetic happens after the nil check