From b51bf4febc32dfa6bb3c1cf467f1513a1d6d8b75 Mon Sep 17 00:00:00 2001 From: Than McIntosh Date: Tue, 8 Jun 2021 20:09:49 -0400 Subject: [release-branch.go1.15] cmd/link: fix handling of dupok mapzero syms The compiler machinery that generates "map.zero" symbols marks them as RODATA and DUPOK, which is problematic when a given application has multiple map zero symbols (from different packages) with varying sizes: the dupok path in the loader assumes that if two symbols have the same name, it is safe to pick any of the versions. In the case of map.zero, the link needs to select the largest symbol, not an arbitrary sym. This patch changes the linker's dupok symbol loading path to detect this problem, and in situations where we're loading a dupok symbol whose name is the same as an existing symbol but whose size is large, select the new dup over the old. Note: this fix differs from the one used in 1.16/1.17, which uses content-addressable symbols instead. Fixes #46656. Change-Id: Iabd2feef01d448670ba795c7eaddc48c191ea276 Reviewed-on: https://go-review.googlesource.com/c/go/+/326211 Trust: Than McIntosh Run-TryBot: Than McIntosh TryBot-Result: Go Bot Reviewed-by: Cherry Mui (cherry picked from commit aa5540cd82170f82c6fe11511e12de96aa58cbc1) Reviewed-on: https://go-review.googlesource.com/c/go/+/326213 --- test/fixedbugs/issue46653.dir/main.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 test/fixedbugs/issue46653.dir/main.go (limited to 'test/fixedbugs/issue46653.dir/main.go') diff --git a/test/fixedbugs/issue46653.dir/main.go b/test/fixedbugs/issue46653.dir/main.go new file mode 100644 index 0000000000..e2a96e54ec --- /dev/null +++ b/test/fixedbugs/issue46653.dir/main.go @@ -0,0 +1,27 @@ +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + bad "issue46653.dir/bad" +) + +func main() { + bad.Bad() +} + +func neverCalled() L { + m := make(map[string]L) + return m[""] +} + +type L struct { + A Data + B Data +} + +type Data struct { + F1 [22][]string +} -- cgit v1.2.3-54-g00ecf