Projects
openEuler:24.03:SP1:Everything:64G
golang
Sign Up
Log In
Username
Password
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
Expand all
Collapse all
Changes of Revision 2
View file
_service:tar_scm:golang.spec
Changed
@@ -66,7 +66,7 @@ Name: golang Version: 1.21.4 -Release: 17 +Release: 23 Summary: The Go Programming Language License: BSD and Public Domain URL: https://golang.org/ @@ -135,6 +135,12 @@ 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 +Patch6020: backport-0020-release-branch.go1.21-runtime-pprof-fix-generics-fun.patch +Patch6021: 0124-CVE-2024-34155-track-depth-in-nested-element-lists.patch ExclusiveArch: %{golang_arches} @@ -374,6 +380,24 @@ %files devel -f go-tests.list -f go-misc.list -f go-src.list %changelog +* Sat Oct 5 2024 Yu Peng <yupeng@kylinos.cn> - 1.21.4-23 +- fix CVE-2024-34155 + +* Wed Oct 09 2024 EulerOSWander <314264452@qq.com> - 1.21.4-22 +- runtime/pprof:fix generics function names + +* 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
View file
_service:tar_scm:0124-CVE-2024-34155-track-depth-in-nested-element-lists.patch
Added
@@ -0,0 +1,60 @@ +commit b232596139dbe96a62edbe3a2a203e856bf556eb +Author: Roland Shoemaker <bracewell@google.com> +Date: Mon Jun 10 15:34:12 2024 -0700 + + release-branch.go1.22 go/parser: track depth in nested element lists + + Prevents stack exhaustion with extremely deeply nested literal values, + i.e. field values in structs. + + Updates #69138 + Fixes #69142 + Fixes CVE-2024-34155 + + Change-Id: I2e8e33b44105cc169d7ed1ae83fb56df0c10f1ee + Reviewed-on: https://go-internal-review.googlesource.com/c/go/+/1520 + Reviewed-by: Robert Griesemer <gri@google.com> + Reviewed-by: Damien Neil <dneil@google.com> + Reviewed-by: Russ Cox <rsc@google.com> + (cherry picked from commit eb1b038c0d01761694e7a735ef87ac9164c6568e) + Reviewed-on: https://go-internal-review.googlesource.com/c/go/+/1561 + Reviewed-by: Tatiana Bradley <tatianabradley@google.com> + Reviewed-on: https://go-review.googlesource.com/c/go/+/611181 + Reviewed-by: Michael Pratt <mpratt@google.com> + TryBot-Bypass: Dmitri Shuralyov <dmitshur@google.com> + Auto-Submit: Dmitri Shuralyov <dmitshur@google.com> + Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> + +diff --git a/src/go/parser/parser.go b/src/go/parser/parser.go +index 17808b366f..f268dea1a6 100644 +--- a/src/go/parser/parser.go ++++ b/src/go/parser/parser.go +@@ -1676,6 +1676,8 @@ func (p *parser) parseElementList() (list ast.Expr) { + } + + func (p *parser) parseLiteralValue(typ ast.Expr) ast.Expr { ++ defer decNestLev(incNestLev(p)) ++ + if p.trace { + defer un(trace(p, "LiteralValue")) + } +diff --git a/src/go/parser/parser_test.go b/src/go/parser/parser_test.go +index 43b3416b27..c6dca66760 100644 +--- a/src/go/parser/parser_test.go ++++ b/src/go/parser/parser_test.go +@@ -598,10 +598,11 @@ var parseDepthTests = struct { + {name: "chan2", format: "package main; var x «<-chan »int"}, + {name: "interface", format: "package main; var x «interface { M() «int» }»", scope: true, scopeMultiplier: 2}, // Scopes: InterfaceType, FuncType + {name: "map", format: "package main; var x «mapint»int"}, +- {name: "slicelit", format: "package main; var x = «any{«»}»", parseMultiplier: 2}, // Parser nodes: UnaryExpr, CompositeLit +- {name: "arraylit", format: "package main; var x = «1any{«nil»}»", parseMultiplier: 2}, // Parser nodes: UnaryExpr, CompositeLit +- {name: "structlit", format: "package main; var x = «struct{x any}{«nil»}»", parseMultiplier: 2}, // Parser nodes: UnaryExpr, CompositeLit +- {name: "maplit", format: "package main; var x = «mapintany{1:«nil»}»", parseMultiplier: 2}, // Parser nodes: CompositeLit, KeyValueExpr ++ {name: "slicelit", format: "package main; var x = any{«any{«»}»}", parseMultiplier: 3}, // Parser nodes: UnaryExpr, CompositeLit ++ {name: "arraylit", format: "package main; var x = «1any{«nil»}»", parseMultiplier: 3}, // Parser nodes: UnaryExpr, CompositeLit ++ {name: "structlit", format: "package main; var x = «struct{x any}{«nil»}»", parseMultiplier: 3}, // Parser nodes: UnaryExpr, CompositeLit ++ {name: "maplit", format: "package main; var x = «mapintany{1:«nil»}»", parseMultiplier: 3}, // Parser nodes: CompositeLit, KeyValueExpr ++ {name: "element", format: "package main; var x = struct{x any}{x: «{«»}»}"}, + {name: "dot", format: "package main; var x = «x.»x"}, + {name: "index", format: "package main; var x = x«1»"}, + {name: "slice", format: "package main; var x = x«1:2»"},
View file
_service:tar_scm:backport-0016-release-branch.go1.21-internal-poll-add-SPLICE_F_NON.patch
Added
@@ -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 +
View file
_service:tar_scm:backport-0017-release-branch.go1.21-runtime-call-enableMetadataHug.patch
Added
@@ -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 +
View file
_service:tar_scm:backport-0018-release-branch.go1.21-cmd-compile-fix-findIndVar-so-.patch
Added
@@ -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 +
View file
_service:tar_scm:backport-0019-release-branch.go1.21-cmd-compile-fix-escape-analysi.patch
Added
@@ -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(ks0, &call.Argsi) ++ } ++ 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 +
View file
_service:tar_scm:backport-0020-release-branch.go1.21-runtime-pprof-fix-generics-fun.patch
Added
@@ -0,0 +1,134 @@ +From 2e4454a248c40017e922db682f231c5a0330f4b2 Mon Sep 17 00:00:00 2001 +From: Tolya Korniltsev <korniltsev.anatoly@gmail.com> +Date: Mon, 4 Dec 2023 17:53:29 +0700 +Subject: PATCH 07/20 release-branch.go1.21 runtime/pprof: fix generics + function names + +Conflict:NA +Reference:https://go-review.googlesource.com/c/go/+/546815 + +profileBuilder is using Frame->Function as key for checking if we already +emitted a function. However for generics functions it has dots there ..., +so sometimes for different functions with different generics types, +the profileBuilder emits wrong functions. + +For #64528 +For #64609 + +Change-Id: I8b39245e0b18f4288ce758c912c6748f87cba39a +Reviewed-on: https://go-review.googlesource.com/c/go/+/546815 +Reviewed-by: Cherry Mui <cherryyz@google.com> +LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> +Reviewed-by: Michael Pratt <mpratt@google.com> +(cherry picked from commit 20a03fc7130d8d99b513071c7e413b436ea649a2) +Reviewed-on: https://go-review.googlesource.com/c/go/+/549535 +Auto-Submit: Matthew Dempsky <mdempsky@google.com> +--- + src/runtime/pprof/proto.go | 7 ++-- + src/runtime/pprof/protomem_test.go | 62 ++++++++++++++++++++++++++++++ + 2 files changed, 66 insertions(+), 3 deletions(-) + +diff --git a/src/runtime/pprof/proto.go b/src/runtime/pprof/proto.go +index cdc4bd7c80d8..db9384eb214e 100644 +--- a/src/runtime/pprof/proto.go ++++ b/src/runtime/pprof/proto.go +@@ -611,13 +611,14 @@ func (b *profileBuilder) emitLocation() uint64 { + b.pb.uint64Opt(tagLocation_Address, uint64(firstFrame.PC)) + for _, frame := range b.deck.frames { + // Write out each line in frame expansion. +- funcID := uint64(b.funcsframe.Function) ++ funcName := runtime_FrameSymbolName(&frame) ++ funcID := uint64(b.funcsfuncName) + if funcID == 0 { + funcID = uint64(len(b.funcs)) + 1 +- b.funcsframe.Function = int(funcID) ++ b.funcsfuncName = int(funcID) + newFuncs = append(newFuncs, newFunc{ + id: funcID, +- name: runtime_FrameSymbolName(&frame), ++ name: funcName, + file: frame.File, + startLine: int64(runtime_FrameStartLine(&frame)), + }) +diff --git a/src/runtime/pprof/protomem_test.go b/src/runtime/pprof/protomem_test.go +index 156f6286a92f..505c323d6867 100644 +--- a/src/runtime/pprof/protomem_test.go ++++ b/src/runtime/pprof/protomem_test.go +@@ -6,8 +6,11 @@ package pprof + + import ( + "bytes" ++ "fmt" + "internal/profile" + "runtime" ++ "slices" ++ "strings" + "testing" + ) + +@@ -82,3 +85,62 @@ func TestConvertMemProfile(t *testing.T) { + }) + } + } ++ ++func genericAllocFuncT interface{ uint32 | uint64 }(n int) T { ++ return make(T, n) ++} ++ ++func profileToString(p *profile.Profile) string { ++ var res string ++ for _, s := range p.Sample { ++ var funcs string ++ for i := len(s.Location) - 1; i >= 0; i-- { ++ loc := s.Locationi ++ for j := len(loc.Line) - 1; j >= 0; j-- { ++ line := loc.Linej ++ funcs = append(funcs, line.Function.Name) ++ } ++ } ++ res = append(res, fmt.Sprintf("%s %v", strings.Join(funcs, ";"), s.Value)) ++ } ++ return res ++} ++ ++// This is a regression test for https://go.dev/issue/64528 . ++func TestGenericsHashKeyInPprofBuilder(t *testing.T) { ++ previousRate := runtime.MemProfileRate ++ runtime.MemProfileRate = 1 ++ defer func() { ++ runtime.MemProfileRate = previousRate ++ }() ++ for _, sz := range int{128, 256} { ++ genericAllocFuncuint32(sz / 4) ++ } ++ for _, sz := range int{32, 64} { ++ genericAllocFuncuint64(sz / 8) ++ } ++ ++ runtime.GC() ++ buf := bytes.NewBuffer(nil) ++ if err := WriteHeapProfile(buf); err != nil { ++ t.Fatalf("writing profile: %v", err) ++ } ++ p, err := profile.Parse(buf) ++ if err != nil { ++ t.Fatalf("profile.Parse: %v", err) ++ } ++ ++ actual := profileToString(p) ++ expected := string{ ++ "testing.tRunner;runtime/pprof.TestGenericsHashKeyInPprofBuilder;runtime/pprof.genericAllocFuncgo.shape.uint32 1 128 0 0", ++ "testing.tRunner;runtime/pprof.TestGenericsHashKeyInPprofBuilder;runtime/pprof.genericAllocFuncgo.shape.uint32 1 256 0 0", ++ "testing.tRunner;runtime/pprof.TestGenericsHashKeyInPprofBuilder;runtime/pprof.genericAllocFuncgo.shape.uint64 1 32 0 0", ++ "testing.tRunner;runtime/pprof.TestGenericsHashKeyInPprofBuilder;runtime/pprof.genericAllocFuncgo.shape.uint64 1 64 0 0", ++ } ++ ++ for _, l := range expected { ++ if !slices.Contains(actual, l) { ++ t.Errorf("profile = %v\nwant = %v", strings.Join(actual, "\n"), l) ++ } ++ } ++} +-- +2.33.0 +
View file
_service
Changed
@@ -2,7 +2,7 @@ <service name="tar_scm"> <param name="scm">git</param> <param name="url">git@gitee.com:src-openeuler/golang.git</param> - <param name="revision">openEuler-24.03-LTS-Next</param> + <param name="revision">openEuler-24.03-LTS-SP1</param> <param name="exclude">*</param> <param name="extract">*</param> </service>
Locations
Projects
Search
Status Monitor
Help
Open Build Service
OBS Manuals
API Documentation
OBS Portal
Reporting a Bug
Contact
Mailing List
Forums
Chat (IRC)
Twitter
Open Build Service (OBS)
is an
openSUSE project
.
浙ICP备2022010568号-2