1
0
mirror of https://github.com/golang/go synced 2024-11-17 12:04:43 -07:00

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 <cherryyz@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
Cherry Mui 2022-03-21 20:07:06 -04:00
parent 20ba3f5de5
commit 909a7a3213

View 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.