Skip to content

Commit aa5540c

Browse files
committed
cmd/compile: make map.zero symbol content-addressable
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. To fix this problem, mark map.zero symbols as content-addressable, since the loader's content addressability processing path already supports selection of the larger symbol in cases where there are dups. Fixes golang#46653. Change-Id: Iabd2feef01d448670ba795c7eaddc48c191ea276 Reviewed-on: https://go-review.googlesource.com/c/go/+/326211 Trust: Than McIntosh <[email protected]> Run-TryBot: Than McIntosh <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Cherry Mui <[email protected]>
1 parent 07ca28d commit aa5540c

4 files changed

Lines changed: 102 additions & 0 deletions

File tree

src/cmd/compile/internal/gc/obj.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ func dumpdata() {
148148
if reflectdata.ZeroSize > 0 {
149149
zero := base.PkgLinksym("go.map", "zero", obj.ABI0)
150150
objw.Global(zero, int32(reflectdata.ZeroSize), obj.DUPOK|obj.RODATA)
151+
zero.Set(obj.AttrContentAddressable, true)
151152
}
152153

153154
staticdata.WriteFuncSyms()
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// Copyright 2021 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package a
6+
7+
func Bad() {
8+
m := make(map[int64]A)
9+
a := m[0]
10+
if len(a.B.C1.D2.E2.F1) != 0 ||
11+
len(a.B.C1.D2.E2.F2) != 0 ||
12+
len(a.B.C1.D2.E2.F3) != 0 ||
13+
len(a.B.C1.D2.E2.F4) != 0 ||
14+
len(a.B.C1.D2.E2.F5) != 0 ||
15+
len(a.B.C1.D2.E2.F6) != 0 ||
16+
len(a.B.C1.D2.E2.F7) != 0 ||
17+
len(a.B.C1.D2.E2.F8) != 0 ||
18+
len(a.B.C1.D2.E2.F9) != 0 ||
19+
len(a.B.C1.D2.E2.F10) != 0 ||
20+
len(a.B.C1.D2.E2.F11) != 0 ||
21+
len(a.B.C1.D2.E2.F16) != 0 {
22+
panic("bad")
23+
}
24+
}
25+
26+
type A struct {
27+
B
28+
}
29+
30+
type B struct {
31+
C1 C
32+
C2 C
33+
}
34+
35+
type C struct {
36+
D1 D
37+
D2 D
38+
}
39+
40+
type D struct {
41+
E1 E
42+
E2 E
43+
E3 E
44+
E4 E
45+
}
46+
47+
type E struct {
48+
F1 string
49+
F2 string
50+
F3 string
51+
F4 string
52+
F5 string
53+
F6 string
54+
F7 string
55+
F8 string
56+
F9 string
57+
F10 string
58+
F11 string
59+
F12 string
60+
F13 string
61+
F14 string
62+
F15 string
63+
F16 string
64+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2021 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package main
6+
7+
import (
8+
bad "issue46653.dir/bad"
9+
)
10+
11+
func main() {
12+
bad.Bad()
13+
}
14+
15+
func neverCalled() L {
16+
m := make(map[string]L)
17+
return m[""]
18+
}
19+
20+
type L struct {
21+
A Data
22+
B Data
23+
}
24+
25+
type Data struct {
26+
F1 [22][]string
27+
}

test/fixedbugs/issue46653.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// runindir
2+
3+
// Copyright 2021 The Go Authors. All rights reserved.
4+
// Use of this source code is governed by a BSD-style
5+
// license that can be found in the LICENSE file.
6+
7+
// Test to verify compiler and linker handling of multiple
8+
// competing map.zero symbol definitions.
9+
10+
package ignored

0 commit comments

Comments
 (0)