Skip to content

Commit 8391579

Browse files
prattmicgopherbot
authored andcommitted
runtime: migrate missing map linkname allowlists
The swissmap implementation forgot to copy some of the linkname allowlists from the old implementation. Copy them from map_noswiss.go. Some were missing linkname entirely; others were linknamed but missing the hall of shame comment. For #54766. Change-Id: Icc715384123e73d868b4cb729ab639abcd6bbfd7 Reviewed-on: https://go-review.googlesource.com/c/go/+/635995 Reviewed-by: Cherry Mui <[email protected]> Auto-Submit: Michael Pratt <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent 80a2982 commit 8391579

File tree

1 file changed

+158
-0
lines changed

1 file changed

+158
-0
lines changed

src/runtime/map_swiss.go

+158
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,16 @@ func makemap64(t *abi.SwissMapType, hint int64, m *maps.Map) *maps.Map {
3939
// makemap_small implements Go map creation for make(map[k]v) and
4040
// make(map[k]v, hint) when hint is known to be at most abi.SwissMapGroupSlots
4141
// at compile time and the map needs to be allocated on the heap.
42+
//
43+
// makemap_small should be an internal detail,
44+
// but widely used packages access it using linkname.
45+
// Notable members of the hall of shame include:
46+
// - github.com/bytedance/sonic
47+
//
48+
// Do not remove or change the type signature.
49+
// See go.dev/issue/67401.
50+
//
51+
//go:linkname makemap_small
4252
func makemap_small() *maps.Map {
4353
return maps.NewEmptyMap()
4454
}
@@ -48,6 +58,16 @@ func makemap_small() *maps.Map {
4858
// can be created on the stack, m and optionally m.dirPtr may be non-nil.
4959
// If m != nil, the map can be created directly in m.
5060
// If m.dirPtr != nil, it points to a group usable for a small map.
61+
//
62+
// makemap should be an internal detail,
63+
// but widely used packages access it using linkname.
64+
// Notable members of the hall of shame include:
65+
// - github.com/ugorji/go/codec
66+
//
67+
// Do not remove or change the type signature.
68+
// See go.dev/issue/67401.
69+
//
70+
//go:linkname makemap
5171
func makemap(t *abi.SwissMapType, hint int, m *maps.Map) *maps.Map {
5272
if hint < 0 {
5373
hint = 0
@@ -68,6 +88,15 @@ func makemap(t *abi.SwissMapType, hint int, m *maps.Map) *maps.Map {
6888
//go:linkname mapaccess1
6989
func mapaccess1(t *abi.SwissMapType, m *maps.Map, key unsafe.Pointer) unsafe.Pointer
7090

91+
// mapaccess2 should be an internal detail,
92+
// but widely used packages access it using linkname.
93+
// Notable members of the hall of shame include:
94+
// - github.com/ugorji/go/codec
95+
//
96+
// Do not remove or change the type signature.
97+
// See go.dev/issue/67401.
98+
//
99+
//go:linkname mapaccess2
71100
func mapaccess2(t *abi.SwissMapType, m *maps.Map, key unsafe.Pointer) (unsafe.Pointer, bool)
72101

73102
func mapaccess1_fat(t *abi.SwissMapType, m *maps.Map, key, zero unsafe.Pointer) unsafe.Pointer {
@@ -89,9 +118,29 @@ func mapaccess2_fat(t *abi.SwissMapType, m *maps.Map, key, zero unsafe.Pointer)
89118
// mapassign is pushed from internal/runtime/maps. We could just call it, but
90119
// we want to avoid one layer of call.
91120
//
121+
// mapassign should be an internal detail,
122+
// but widely used packages access it using linkname.
123+
// Notable members of the hall of shame include:
124+
// - github.com/bytedance/sonic
125+
// - github.com/RomiChan/protobuf
126+
// - github.com/segmentio/encoding
127+
// - github.com/ugorji/go/codec
128+
//
129+
// Do not remove or change the type signature.
130+
// See go.dev/issue/67401.
131+
//
92132
//go:linkname mapassign
93133
func mapassign(t *abi.SwissMapType, m *maps.Map, key unsafe.Pointer) unsafe.Pointer
94134

135+
// mapdelete should be an internal detail,
136+
// but widely used packages access it using linkname.
137+
// Notable members of the hall of shame include:
138+
// - github.com/ugorji/go/codec
139+
//
140+
// Do not remove or change the type signature.
141+
// See go.dev/issue/67401.
142+
//
143+
//go:linkname mapdelete
95144
func mapdelete(t *abi.SwissMapType, m *maps.Map, key unsafe.Pointer) {
96145
if raceenabled && m != nil {
97146
callerpc := sys.GetCallerPC()
@@ -113,6 +162,21 @@ func mapdelete(t *abi.SwissMapType, m *maps.Map, key unsafe.Pointer) {
113162
// The Iter struct pointed to by 'it' is allocated on the stack
114163
// by the compilers order pass or on the heap by reflect_mapiterinit.
115164
// Both need to have zeroed hiter since the struct contains pointers.
165+
//
166+
// mapiterinit should be an internal detail,
167+
// but widely used packages access it using linkname.
168+
// Notable members of the hall of shame include:
169+
// - github.com/bytedance/sonic
170+
// - github.com/goccy/go-json
171+
// - github.com/RomiChan/protobuf
172+
// - github.com/segmentio/encoding
173+
// - github.com/ugorji/go/codec
174+
// - github.com/wI2L/jettison
175+
//
176+
// Do not remove or change the type signature.
177+
// See go.dev/issue/67401.
178+
//
179+
//go:linkname mapiterinit
116180
func mapiterinit(t *abi.SwissMapType, m *maps.Map, it *maps.Iter) {
117181
if raceenabled && m != nil {
118182
callerpc := sys.GetCallerPC()
@@ -123,6 +187,19 @@ func mapiterinit(t *abi.SwissMapType, m *maps.Map, it *maps.Iter) {
123187
it.Next()
124188
}
125189

190+
// mapiternext should be an internal detail,
191+
// but widely used packages access it using linkname.
192+
// Notable members of the hall of shame include:
193+
// - github.com/bytedance/sonic
194+
// - github.com/RomiChan/protobuf
195+
// - github.com/segmentio/encoding
196+
// - github.com/ugorji/go/codec
197+
// - gonum.org/v1/gonum
198+
//
199+
// Do not remove or change the type signature.
200+
// See go.dev/issue/67401.
201+
//
202+
//go:linkname mapiternext
126203
func mapiternext(it *maps.Iter) {
127204
if raceenabled {
128205
callerpc := sys.GetCallerPC()
@@ -145,6 +222,19 @@ func mapclear(t *abi.SwissMapType, m *maps.Map) {
145222

146223
// Reflect stubs. Called from ../reflect/asm_*.s
147224

225+
// reflect_makemap is for package reflect,
226+
// but widely used packages access it using linkname.
227+
// Notable members of the hall of shame include:
228+
// - gitee.com/quant1x/gox
229+
// - github.com/modern-go/reflect2
230+
// - github.com/goccy/go-json
231+
// - github.com/RomiChan/protobuf
232+
// - github.com/segmentio/encoding
233+
// - github.com/v2pro/plz
234+
//
235+
// Do not remove or change the type signature.
236+
// See go.dev/issue/67401.
237+
//
148238
//go:linkname reflect_makemap reflect.makemap
149239
func reflect_makemap(t *abi.SwissMapType, cap int) *maps.Map {
150240
// Check invariants and reflects math.
@@ -156,6 +246,16 @@ func reflect_makemap(t *abi.SwissMapType, cap int) *maps.Map {
156246
return makemap(t, cap, nil)
157247
}
158248

249+
// reflect_mapaccess is for package reflect,
250+
// but widely used packages access it using linkname.
251+
// Notable members of the hall of shame include:
252+
// - gitee.com/quant1x/gox
253+
// - github.com/modern-go/reflect2
254+
// - github.com/v2pro/plz
255+
//
256+
// Do not remove or change the type signature.
257+
// See go.dev/issue/67401.
258+
//
159259
//go:linkname reflect_mapaccess reflect.mapaccess
160260
func reflect_mapaccess(t *abi.SwissMapType, m *maps.Map, key unsafe.Pointer) unsafe.Pointer {
161261
elem, ok := mapaccess2(t, m, key)
@@ -176,6 +276,14 @@ func reflect_mapaccess_faststr(t *abi.SwissMapType, m *maps.Map, key string) uns
176276
return elem
177277
}
178278

279+
// reflect_mapassign is for package reflect,
280+
// but widely used packages access it using linkname.
281+
// Notable members of the hall of shame include:
282+
// - gitee.com/quant1x/gox
283+
// - github.com/v2pro/plz
284+
//
285+
// Do not remove or change the type signature.
286+
//
179287
//go:linkname reflect_mapassign reflect.mapassign0
180288
func reflect_mapassign(t *abi.SwissMapType, m *maps.Map, key unsafe.Pointer, elem unsafe.Pointer) {
181289
p := mapassign(t, m, key)
@@ -198,26 +306,76 @@ func reflect_mapdelete_faststr(t *abi.SwissMapType, m *maps.Map, key string) {
198306
mapdelete_faststr(t, m, key)
199307
}
200308

309+
// reflect_mapiterinit is for package reflect,
310+
// but widely used packages access it using linkname.
311+
// Notable members of the hall of shame include:
312+
// - github.com/modern-go/reflect2
313+
// - gitee.com/quant1x/gox
314+
// - github.com/v2pro/plz
315+
// - github.com/wI2L/jettison
316+
//
317+
// Do not remove or change the type signature.
318+
// See go.dev/issue/67401.
319+
//
201320
//go:linkname reflect_mapiterinit reflect.mapiterinit
202321
func reflect_mapiterinit(t *abi.SwissMapType, m *maps.Map, it *maps.Iter) {
203322
mapiterinit(t, m, it)
204323
}
205324

325+
// reflect_mapiternext is for package reflect,
326+
// but widely used packages access it using linkname.
327+
// Notable members of the hall of shame include:
328+
// - gitee.com/quant1x/gox
329+
// - github.com/modern-go/reflect2
330+
// - github.com/goccy/go-json
331+
// - github.com/v2pro/plz
332+
// - github.com/wI2L/jettison
333+
//
334+
// Do not remove or change the type signature.
335+
// See go.dev/issue/67401.
336+
//
206337
//go:linkname reflect_mapiternext reflect.mapiternext
207338
func reflect_mapiternext(it *maps.Iter) {
208339
mapiternext(it)
209340
}
210341

342+
// reflect_mapiterkey was for package reflect,
343+
// but widely used packages access it using linkname.
344+
// Notable members of the hall of shame include:
345+
// - github.com/goccy/go-json
346+
// - gonum.org/v1/gonum
347+
//
348+
// Do not remove or change the type signature.
349+
// See go.dev/issue/67401.
350+
//
211351
//go:linkname reflect_mapiterkey reflect.mapiterkey
212352
func reflect_mapiterkey(it *maps.Iter) unsafe.Pointer {
213353
return it.Key()
214354
}
215355

356+
// reflect_mapiterelem was for package reflect,
357+
// but widely used packages access it using linkname.
358+
// Notable members of the hall of shame include:
359+
// - github.com/goccy/go-json
360+
// - gonum.org/v1/gonum
361+
//
362+
// Do not remove or change the type signature.
363+
// See go.dev/issue/67401.
364+
//
216365
//go:linkname reflect_mapiterelem reflect.mapiterelem
217366
func reflect_mapiterelem(it *maps.Iter) unsafe.Pointer {
218367
return it.Elem()
219368
}
220369

370+
// reflect_maplen is for package reflect,
371+
// but widely used packages access it using linkname.
372+
// Notable members of the hall of shame include:
373+
// - github.com/goccy/go-json
374+
// - github.com/wI2L/jettison
375+
//
376+
// Do not remove or change the type signature.
377+
// See go.dev/issue/67401.
378+
//
221379
//go:linkname reflect_maplen reflect.maplen
222380
func reflect_maplen(m *maps.Map) int {
223381
if m == nil {

0 commit comments

Comments
 (0)