]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: don't mark non-generic defined type symbol dupok
authorCherry Mui <cherryyz@google.com>
Tue, 22 Mar 2022 00:07:06 +0000 (20:07 -0400)
committerCherry Mui <cherryyz@google.com>
Wed, 23 Mar 2022 16:12:07 +0000 (16:12 +0000)
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 <cherryyz@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
src/cmd/compile/internal/reflectdata/reflect.go

index 56f6891c66ab796835fc72c0d5a38f9b128a7081..c49444179edb71ca1e491c6b608150c8318732c1 100644 (file)
@@ -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.