From 909a7a32138367abec92434872695fb65aa9b7d1 Mon Sep 17 00:00:00 2001 From: Cherry Mui Date: Mon, 21 Mar 2022 20:07:06 -0400 Subject: [PATCH] cmd/compile: don't mark non-generic defined type symbol dupok For a non-generic defined type, we generate its type descriptor symbol only in the defining package. So there is no duplicate and it doesn't need to be dupok. For unnamed types and instantiated types, the type descriptor can be generated in multiple packages and so still need to be dupok. Change-Id: I92ed68c998ad68c5917b77b1dfd62eac4ced6bcf Reviewed-on: https://go-review.googlesource.com/c/go/+/394636 Trust: Cherry Mui Run-TryBot: Cherry Mui TryBot-Result: Gopher Robot Reviewed-by: Matthew Dempsky --- src/cmd/compile/internal/reflectdata/reflect.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/cmd/compile/internal/reflectdata/reflect.go b/src/cmd/compile/internal/reflectdata/reflect.go index 56f6891c66a..c49444179ed 100644 --- a/src/cmd/compile/internal/reflectdata/reflect.go +++ b/src/cmd/compile/internal/reflectdata/reflect.go @@ -1196,10 +1196,17 @@ func writeType(t *types.Type) *obj.LSym { } } - ot = dextratypeData(lsym, ot, t) - objw.Global(lsym, int32(ot), int16(obj.DUPOK|obj.RODATA)) // Note: DUPOK is required to ensure that we don't end up with more - // than one type descriptor for a given type. + // than one type descriptor for a given type, if the type descriptor + // can be defined in multiple packages, that is, unnamed types and + // instantiated types. + dupok := 0 + if tbase.Sym() == nil || tbase.IsFullyInstantiated() { + dupok = obj.DUPOK + } + + ot = dextratypeData(lsym, ot, t) + objw.Global(lsym, int32(ot), int16(dupok|obj.RODATA)) // The linker will leave a table of all the typelinks for // types in the binary, so the runtime can find them.