aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/noder
diff options
context:
space:
mode:
authorMatthew Dempsky <mdempsky@google.com>2023-04-12 12:41:45 -0700
committerGopher Robot <gobot@golang.org>2023-04-12 20:54:38 +0000
commitf58c6cccc44752146aabcd50a30865e34817a4b4 (patch)
tree0029888dfec4b4ad042ba6f643f60dd3e5d0bf7f /src/cmd/compile/internal/noder
parent12e65dbdb112ac03049362bf8c0dbeeeb0392c0e (diff)
downloadgo-f58c6cccc44752146aabcd50a30865e34817a4b4.tar.xz
cmd/compile: fix reproducible build of aliased generic types
Due to a missing "&& !alias" check, the unified linker was treating type aliases the same as defined types for the purpose of exporting method bodies. The methods will get exported anyway alongside the aliased type, so this mistake is normally harmless. However, if multiple type aliases instantiated the same generic type but with different type arguments, this could result in the same (generic) method body being exported multiple times under different symbol names. Further, because bodies aren't expected to be exported multiple times, we were sorting them simply based on index. And consequently, the sort wasn't total and is sensitive to the map iteration order used while ranging over linker.bodies. The fix is simply to add the missing "&& !alias" check, so that we don't end up with duplicate bodies in the first place. Thanks rsc@ for providing a minimal repro case. Fixes #59571. Change-Id: Iaa55968cc7110b601e2f0f9b620901c2d55f7014 Reviewed-on: https://go-review.googlesource.com/c/go/+/484155 Reviewed-by: Keith Randall <khr@google.com> Auto-Submit: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
Diffstat (limited to 'src/cmd/compile/internal/noder')
-rw-r--r--src/cmd/compile/internal/noder/linker.go2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/cmd/compile/internal/noder/linker.go b/src/cmd/compile/internal/noder/linker.go
index 44de017ae5..0efe6b630b 100644
--- a/src/cmd/compile/internal/noder/linker.go
+++ b/src/cmd/compile/internal/noder/linker.go
@@ -199,7 +199,7 @@ func (l *linker) relocObj(pr *pkgReader, idx pkgbits.Index) pkgbits.Index {
l.exportBody(obj, local)
}
- if obj.Op() == ir.OTYPE {
+ if obj.Op() == ir.OTYPE && !obj.Alias() {
if typ := obj.Type(); !typ.IsInterface() {
for _, method := range typ.Methods().Slice() {
l.exportBody(method.Nname.(*ir.Name), local)