diff options
author | Keith Randall <khr@golang.org> | 2021-05-22 21:59:00 -0700 |
---|---|---|
committer | Keith Randall <khr@golang.org> | 2021-05-24 17:43:50 +0000 |
commit | a22e3172200d4bdd0afcbbe6564dbb67fea4b03a (patch) | |
tree | f01dd9e10b280efcd72a70653c118d47e142998e /src/cmd/compile/internal/reflectdata | |
parent | 4356e7e85fcd8f59de6bc1fd1db6e4f01a92f19e (diff) | |
download | go-a22e3172200d4bdd0afcbbe6564dbb67fea4b03a.tar.gz go-a22e3172200d4bdd0afcbbe6564dbb67fea4b03a.zip |
cmd/compile: always include underlying type for map types
This is a different fix for #37716.
Should help make the fix for #46283 easier, since we will no longer
need to keep compiler-generated hash functions and the runtime
hash function in sync.
Change-Id: I84cb93144e425dcd03afc552b5fbd0f2d2cc6d39
Reviewed-on: https://go-review.googlesource.com/c/go/+/322150
Trust: Keith Randall <khr@golang.org>
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Diffstat (limited to 'src/cmd/compile/internal/reflectdata')
-rw-r--r-- | src/cmd/compile/internal/reflectdata/reflect.go | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/cmd/compile/internal/reflectdata/reflect.go b/src/cmd/compile/internal/reflectdata/reflect.go index 8c0e33f6df..b3688fca67 100644 --- a/src/cmd/compile/internal/reflectdata/reflect.go +++ b/src/cmd/compile/internal/reflectdata/reflect.go @@ -1112,6 +1112,15 @@ func writeType(t *types.Type) *obj.LSym { } ot = objw.Uint32(lsym, ot, flags) ot = dextratype(lsym, ot, t, 0) + if u := t.Underlying(); u != t { + // If t is a named map type, also keep the underlying map + // type live in the binary. This is important to make sure that + // a named map and that same map cast to its underlying type via + // reflection, use the same hash function. See issue 37716. + r := obj.Addrel(lsym) + r.Sym = writeType(u) + r.Type = objabi.R_KEEP + } case types.TPTR: if t.Elem().Kind() == types.TANY { |