aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCherry Mui <cherryyz@google.com>2024-04-22 15:58:29 -0400
committerCherry Mui <cherryyz@google.com>2024-04-23 01:21:39 +0000
commit9702cd980fadefe4d6740a52d32fb1ad52e984cc (patch)
treed7240bc3dfebf867f85b4387b718d5bfeb88dc13
parent0c39dc1ff72181d36f7e9fc61bfacc5a7b7c5c57 (diff)
downloadgo-9702cd980fadefe4d6740a52d32fb1ad52e984cc.tar.gz
go-9702cd980fadefe4d6740a52d32fb1ad52e984cc.zip
cmd/compile: mark closure DUPOK if the outer function is
If a function is DUPOK (e.g. an instantiation of a generic function) and contains closures, the closure also needs to be DUPOK. Otherwise, when the outer function is included in multiple packages, the closure will also be included in these packages, and the linker will dedup the outer function but not the closure, causing duplicated symbols. In normal builds it is mostly still ok as these closure symbols are only referenced by indices. But in shared build mode all symbols are named and kept live, causing an error. Should fix the shared build mode. Change-Id: I227d26e589465440335a4ec7e33d29739ed44aad Reviewed-on: https://go-review.googlesource.com/c/go/+/580917 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Than McIntosh <thanm@google.com>
-rw-r--r--src/cmd/compile/internal/ir/func.go3
1 files changed, 3 insertions, 0 deletions
diff --git a/src/cmd/compile/internal/ir/func.go b/src/cmd/compile/internal/ir/func.go
index a74bb6ebda..d20836e006 100644
--- a/src/cmd/compile/internal/ir/func.go
+++ b/src/cmd/compile/internal/ir/func.go
@@ -481,6 +481,9 @@ func closureName(outerfn *Func, pos src.XPos, why Op) *types.Sym {
func NewClosureFunc(fpos, cpos src.XPos, why Op, typ *types.Type, outerfn *Func, pkg *Package) *Func {
fn := NewFunc(fpos, fpos, closureName(outerfn, cpos, why), typ)
fn.SetIsHiddenClosure(outerfn != nil)
+ if outerfn != nil {
+ fn.SetDupok(outerfn.Dupok()) // if the outer function is dupok, so is the closure
+ }
clo := &ClosureExpr{Func: fn}
clo.op = OCLOSURE