]> Cypherpunks repositories - gostls13.git/commit
[release-branch.go1.20] cmd/compile: fix reproducible build of aliased generic types
authorMatthew Dempsky <mdempsky@google.com>
Wed, 12 Apr 2023 19:41:45 +0000 (12:41 -0700)
committerGopher Robot <gobot@golang.org>
Mon, 24 Apr 2023 14:06:53 +0000 (14:06 +0000)
commitee42d468f50e863f240a8b11e521feaf7f9114c9
tree5c73e0d0aee5f5aa54714b16a4b5cd4f07787176
parent446493f5b8dc1c1425862153bf39643a99b10bec
[release-branch.go1.20] 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 #59585.

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>
(cherry picked from commit f58c6cccc44752146aabcd50a30865e34817a4b4)
Reviewed-on: https://go-review.googlesource.com/c/go/+/484160
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Auto-Submit: Dmitri Shuralyov <dmitshur@google.com>
src/cmd/compile/internal/noder/linker.go
src/cmd/go/testdata/script/build_issue59571.txt [new file with mode: 0644]