Skip to content

Commit ef225d1

Browse files
rscgopherbot
authored andcommitted
all: document legacy //go:linkname for modules with ≥100,000 dependents
For #67401. Change-Id: I51f5b561ee11eb242e3b1585d591281d0df4fc24 Reviewed-on: https://go-review.googlesource.com/c/go/+/587215 Auto-Submit: Russ Cox <[email protected]> Reviewed-by: Cherry Mui <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent dca577d commit ef225d1

15 files changed

+166
-10
lines changed

Diff for: src/reflect/badlinkname.go

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import (
1717

1818
//go:linkname add
1919
//go:linkname ifaceIndir
20-
//go:linkname mapassign
2120
//go:linkname rtypeOff
2221
//go:linkname toType
2322
//go:linkname typesByString

Diff for: src/reflect/value.go

+9
Original file line numberDiff line numberDiff line change
@@ -3870,6 +3870,15 @@ func mapaccess_faststr(t *abi.Type, m unsafe.Pointer, key string) (val unsafe.Po
38703870
//go:noescape
38713871
func mapassign0(t *abi.Type, m unsafe.Pointer, key, val unsafe.Pointer)
38723872

3873+
// mapassign should be an internal detail,
3874+
// but widely used packages access it using linkname.
3875+
// Notable members of the hall of shame include:
3876+
// - github.com/modern-go/reflect2
3877+
//
3878+
// Do not remove or change the type signature.
3879+
// See go.dev/issue/67401.
3880+
//
3881+
//go:linkname mapassign
38733882
func mapassign(t *abi.Type, m unsafe.Pointer, key, val unsafe.Pointer) {
38743883
contentEscapes(key)
38753884
contentEscapes(val)

Diff for: src/runtime/iface.go

+7
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,13 @@ func buildInterfaceSwitchCache(oldC *abi.InterfaceSwitchCache, typ *_type, case_
624624
// causes a cache lookup to fail immediately.)
625625
var emptyInterfaceSwitchCache = abi.InterfaceSwitchCache{Mask: 0}
626626

627+
// reflect_ifaceE2I is for package reflect,
628+
// but widely used packages access it using linkname.
629+
// Notable members of the hall of shame include:
630+
// - github.com/modern-go/reflect2
631+
//
632+
// Do not remove or change the type signature.
633+
//
627634
//go:linkname reflect_ifaceE2I reflect.ifaceE2I
628635
func reflect_ifaceE2I(inter *interfacetype, e eface, dst *iface) {
629636
*dst = iface{assertE2I(inter, e._type), e.data}

Diff for: src/runtime/linkname.go

-3
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@ import _ "unsafe"
3737
// used in runtime/coverage and in tests
3838
//go:linkname addExitHook
3939

40-
// used in x/sys/cpu
41-
//go:linkname getAuxv
42-
4340
// used in tests
4441
//go:linkname extraMInUse
4542
//go:linkname getm

Diff for: src/runtime/malloc.go

+16
Original file line numberDiff line numberDiff line change
@@ -1371,6 +1371,14 @@ func newobject(typ *_type) unsafe.Pointer {
13711371
return mallocgc(typ.Size_, typ, true)
13721372
}
13731373

1374+
// reflect_unsafe_New is meant for package reflect,
1375+
// but widely used packages access it using linkname.
1376+
// Notable members of the hall of shame include:
1377+
// - github.com/modern-go/reflect2
1378+
//
1379+
// Do not remove or change the type signature.
1380+
// See go.dev/issue/67401.
1381+
//
13741382
//go:linkname reflect_unsafe_New reflect.unsafe_New
13751383
func reflect_unsafe_New(typ *_type) unsafe.Pointer {
13761384
return mallocgc(typ.Size_, typ, true)
@@ -1393,6 +1401,14 @@ func newarray(typ *_type, n int) unsafe.Pointer {
13931401
return mallocgc(mem, typ, true)
13941402
}
13951403

1404+
// reflect_unsafe_NewArray is meant for package reflect,
1405+
// but widely used packages access it using linkname.
1406+
// Notable members of the hall of shame include:
1407+
// - github.com/modern-go/reflect2
1408+
//
1409+
// Do not remove or change the type signature.
1410+
// See go.dev/issue/67401.
1411+
//
13961412
//go:linkname reflect_unsafe_NewArray reflect.unsafe_NewArray
13971413
func reflect_unsafe_NewArray(typ *_type, n int) unsafe.Pointer {
13981414
return newarray(typ, n)

Diff for: src/runtime/map.go

+32
Original file line numberDiff line numberDiff line change
@@ -1293,6 +1293,14 @@ func advanceEvacuationMark(h *hmap, t *maptype, newbit uintptr) {
12931293

12941294
// Reflect stubs. Called from ../reflect/asm_*.s
12951295

1296+
// reflect_makemap is for package reflect,
1297+
// but widely used packages access it using linkname.
1298+
// Notable members of the hall of shame include:
1299+
// - github.com/modern-go/reflect2
1300+
//
1301+
// Do not remove or change the type signature.
1302+
// See go.dev/issue/67401.
1303+
//
12961304
//go:linkname reflect_makemap reflect.makemap
12971305
func reflect_makemap(t *maptype, cap int) *hmap {
12981306
// Check invariants and reflects math.
@@ -1332,6 +1340,14 @@ func reflect_makemap(t *maptype, cap int) *hmap {
13321340
return makemap(t, cap, nil)
13331341
}
13341342

1343+
// reflect_mapaccess is for package reflect,
1344+
// but widely used packages access it using linkname.
1345+
// Notable members of the hall of shame include:
1346+
// - github.com/modern-go/reflect2
1347+
//
1348+
// Do not remove or change the type signature.
1349+
// See go.dev/issue/67401.
1350+
//
13351351
//go:linkname reflect_mapaccess reflect.mapaccess
13361352
func reflect_mapaccess(t *maptype, h *hmap, key unsafe.Pointer) unsafe.Pointer {
13371353
elem, ok := mapaccess2(t, h, key)
@@ -1374,11 +1390,27 @@ func reflect_mapdelete_faststr(t *maptype, h *hmap, key string) {
13741390
mapdelete_faststr(t, h, key)
13751391
}
13761392

1393+
// reflect_mapiterinit is for package reflect,
1394+
// but widely used packages access it using linkname.
1395+
// Notable members of the hall of shame include:
1396+
// - github.com/modern-go/reflect2
1397+
//
1398+
// Do not remove or change the type signature.
1399+
// See go.dev/issue/67401.
1400+
//
13771401
//go:linkname reflect_mapiterinit reflect.mapiterinit
13781402
func reflect_mapiterinit(t *maptype, h *hmap, it *hiter) {
13791403
mapiterinit(t, h, it)
13801404
}
13811405

1406+
// reflect_mapiternext is for package reflect,
1407+
// but widely used packages access it using linkname.
1408+
// Notable members of the hall of shame include:
1409+
// - github.com/modern-go/reflect2
1410+
//
1411+
// Do not remove or change the type signature.
1412+
// See go.dev/issue/67401.
1413+
//
13821414
//go:linkname reflect_mapiternext reflect.mapiternext
13831415
func reflect_mapiternext(it *hiter) {
13841416
mapiternext(it)

Diff for: src/runtime/mbarrier.go

+16
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,14 @@ func wbMove(typ *_type, dst, src unsafe.Pointer) {
199199
bulkBarrierPreWrite(uintptr(dst), uintptr(src), typ.PtrBytes, typ)
200200
}
201201

202+
// reflect_typedmemmove is meant for package reflect,
203+
// but widely used packages access it using linkname.
204+
// Notable members of the hall of shame include:
205+
// - github.com/modern-go/reflect2
206+
//
207+
// Do not remove or change the type signature.
208+
// See go.dev/issue/67401.
209+
//
202210
//go:linkname reflect_typedmemmove reflect.typedmemmove
203211
func reflect_typedmemmove(typ *_type, dst, src unsafe.Pointer) {
204212
if raceenabled {
@@ -303,6 +311,14 @@ func typedslicecopy(typ *_type, dstPtr unsafe.Pointer, dstLen int, srcPtr unsafe
303311
return n
304312
}
305313

314+
// reflect_typedslicecopy is meant for package reflect,
315+
// but widely used packages access it using linkname.
316+
// Notable members of the hall of shame include:
317+
// - github.com/modern-go/reflect2
318+
//
319+
// Do not remove or change the type signature.
320+
// See go.dev/issue/67401.
321+
//
306322
//go:linkname reflect_typedslicecopy reflect.typedslicecopy
307323
func reflect_typedslicecopy(elemType *_type, dst, src slice) int {
308324
if !elemType.Pointers() {

Diff for: src/runtime/runtime.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -295,4 +295,9 @@ func setCrashFD(fd uintptr) uintptr {
295295
// It contains an even number of elements, (tag, value) pairs.
296296
var auxv []uintptr
297297

298-
func getAuxv() []uintptr { return auxv } // accessed from x/sys/cpu; see issue 57336
298+
// golang.org/x/sys/cpu uses getAuxv via linkname.
299+
// Do not remove or change the type signature.
300+
// (See go.dev/issue/57336.)
301+
//
302+
//go:linkname getAuxv
303+
func getAuxv() []uintptr { return auxv }

Diff for: src/runtime/runtime1.go

+16
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,14 @@ func releasem(mp *m) {
614614
}
615615
}
616616

617+
// reflect_typelinks is meant for package reflect,
618+
// but widely used packages access it using linkname.
619+
// Notable members of the hall of shame include:
620+
// - github.com/modern-go/reflect2
621+
//
622+
// Do not remove or change the type signature.
623+
// See go.dev/issue/67401.
624+
//
617625
//go:linkname reflect_typelinks reflect.typelinks
618626
func reflect_typelinks() ([]unsafe.Pointer, [][]int32) {
619627
modules := activeModules()
@@ -635,6 +643,14 @@ func reflect_resolveNameOff(ptrInModule unsafe.Pointer, off int32) unsafe.Pointe
635643

636644
// reflect_resolveTypeOff resolves an *rtype offset from a base type.
637645
//
646+
// reflect_resolveTypeOff is meant for package reflect,
647+
// but widely used packages access it using linkname.
648+
// Notable members of the hall of shame include:
649+
// - github.com/modern-go/reflect2
650+
//
651+
// Do not remove or change the type signature.
652+
// See go.dev/issue/67401.
653+
//
638654
//go:linkname reflect_resolveTypeOff reflect.resolveTypeOff
639655
func reflect_resolveTypeOff(rtype unsafe.Pointer, off int32) unsafe.Pointer {
640656
return unsafe.Pointer(toRType((*_type)(rtype)).typeOff(typeOff(off)))

Diff for: src/runtime/sys_darwin.go

+24
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ import (
1616
// and we need to know whether to check 32 or 64 bits of the result.
1717
// (Some libc functions that return 32 bits put junk in the upper 32 bits of AX.)
1818

19+
// golang.org/x/sys linknames syscall_syscall
20+
// (in addition to standard package syscall).
21+
// Do not remove or change the type signature.
22+
//
1923
//go:linkname syscall_syscall syscall.syscall
2024
//go:nosplit
2125
func syscall_syscall(fn, a1, a2, a3 uintptr) (r1, r2, err uintptr) {
@@ -38,6 +42,10 @@ func syscall_syscallX(fn, a1, a2, a3 uintptr) (r1, r2, err uintptr) {
3842
}
3943
func syscallX()
4044

45+
// golang.org/x/sys linknames syscall.syscall6
46+
// (in addition to standard package syscall).
47+
// Do not remove or change the type signature.
48+
//
4149
//go:linkname syscall_syscall6 syscall.syscall6
4250
//go:nosplit
4351
func syscall_syscall6(fn, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2, err uintptr) {
@@ -49,6 +57,10 @@ func syscall_syscall6(fn, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2, err uintptr)
4957
}
5058
func syscall6()
5159

60+
// golang.org/x/sys linknames syscall.syscall9
61+
// (in addition to standard package syscall).
62+
// Do not remove or change the type signature.
63+
//
5264
//go:linkname syscall_syscall9 syscall.syscall9
5365
//go:nosplit
5466
//go:cgo_unsafe_args
@@ -71,6 +83,10 @@ func syscall_syscall6X(fn, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2, err uintptr)
7183
}
7284
func syscall6X()
7385

86+
// golang.org/x/sys linknames syscall.syscallPtr
87+
// (in addition to standard package syscall).
88+
// Do not remove or change the type signature.
89+
//
7490
//go:linkname syscall_syscallPtr syscall.syscallPtr
7591
//go:nosplit
7692
func syscall_syscallPtr(fn, a1, a2, a3 uintptr) (r1, r2, err uintptr) {
@@ -82,6 +98,10 @@ func syscall_syscallPtr(fn, a1, a2, a3 uintptr) (r1, r2, err uintptr) {
8298
}
8399
func syscallPtr()
84100

101+
// golang.org/x/sys linknames syscall_rawSyscall
102+
// (in addition to standard package syscall).
103+
// Do not remove or change the type signature.
104+
//
85105
//go:linkname syscall_rawSyscall syscall.rawSyscall
86106
//go:nosplit
87107
func syscall_rawSyscall(fn, a1, a2, a3 uintptr) (r1, r2, err uintptr) {
@@ -90,6 +110,10 @@ func syscall_rawSyscall(fn, a1, a2, a3 uintptr) (r1, r2, err uintptr) {
90110
return args.r1, args.r2, args.err
91111
}
92112

113+
// golang.org/x/sys linknames syscall_rawSyscall6
114+
// (in addition to standard package syscall).
115+
// Do not remove or change the type signature.
116+
//
93117
//go:linkname syscall_rawSyscall6 syscall.rawSyscall6
94118
//go:nosplit
95119
func syscall_rawSyscall6(fn, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2, err uintptr) {

Diff for: src/runtime/sys_openbsd3.go

+20
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ import (
1717
// and we need to know whether to check 32 or 64 bits of the result.
1818
// (Some libc functions that return 32 bits put junk in the upper 32 bits of AX.)
1919

20+
// golang.org/x/sys linknames syscall_syscall
21+
// (in addition to standard package syscall).
22+
// Do not remove or change the type signature.
23+
//
2024
//go:linkname syscall_syscall syscall.syscall
2125
//go:nosplit
2226
//go:cgo_unsafe_args
@@ -39,6 +43,10 @@ func syscall_syscallX(fn, a1, a2, a3 uintptr) (r1, r2, err uintptr) {
3943
}
4044
func syscallX()
4145

46+
// golang.org/x/sys linknames syscall.syscall6
47+
// (in addition to standard package syscall).
48+
// Do not remove or change the type signature.
49+
//
4250
//go:linkname syscall_syscall6 syscall.syscall6
4351
//go:nosplit
4452
//go:cgo_unsafe_args
@@ -61,6 +69,10 @@ func syscall_syscall6X(fn, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2, err uintptr)
6169
}
6270
func syscall6X()
6371

72+
// golang.org/x/sys linknames syscall.syscall10
73+
// (in addition to standard package syscall).
74+
// Do not remove or change the type signature.
75+
//
6476
//go:linkname syscall_syscall10 syscall.syscall10
6577
//go:nosplit
6678
//go:cgo_unsafe_args
@@ -83,6 +95,10 @@ func syscall_syscall10X(fn, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10 uintptr) (r1
8395
}
8496
func syscall10X()
8597

98+
// golang.org/x/sys linknames syscall_rawSyscall
99+
// (in addition to standard package syscall).
100+
// Do not remove or change the type signature.
101+
//
86102
//go:linkname syscall_rawSyscall syscall.rawSyscall
87103
//go:nosplit
88104
//go:cgo_unsafe_args
@@ -91,6 +107,10 @@ func syscall_rawSyscall(fn, a1, a2, a3 uintptr) (r1, r2, err uintptr) {
91107
return
92108
}
93109

110+
// golang.org/x/sys linknames syscall_rawSyscall6
111+
// (in addition to standard package syscall).
112+
// Do not remove or change the type signature.
113+
//
94114
//go:linkname syscall_rawSyscall6 syscall.rawSyscall6
95115
//go:nosplit
96116
//go:cgo_unsafe_args

Diff for: src/runtime/syscall_windows.go

+8
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,10 @@ func syscall_loadsystemlibrary(filename *uint16) (handle, err uintptr) {
423423
return
424424
}
425425

426+
// golang.org/x/sys linknames syscall.loadlibrary
427+
// (in addition to standard package syscall).
428+
// Do not remove or change the type signature.
429+
//
426430
//go:linkname syscall_loadlibrary syscall.loadlibrary
427431
func syscall_loadlibrary(filename *uint16) (handle, err uintptr) {
428432
handle, _, err = syscall_SyscallN(uintptr(unsafe.Pointer(_LoadLibraryW)), uintptr(unsafe.Pointer(filename)))
@@ -433,6 +437,10 @@ func syscall_loadlibrary(filename *uint16) (handle, err uintptr) {
433437
return
434438
}
435439

440+
// golang.org/x/sys linknames syscall.getprocaddress
441+
// (in addition to standard package syscall).
442+
// Do not remove or change the type signature.
443+
//
436444
//go:linkname syscall_getprocaddress syscall.getprocaddress
437445
func syscall_getprocaddress(handle uintptr, procname *byte) (outhandle, err uintptr) {
438446
outhandle, _, err = syscall_SyscallN(uintptr(unsafe.Pointer(_GetProcAddress)), handle, uintptr(unsafe.Pointer(procname)))

Diff for: src/syscall/badlinkname_unix.go

+4
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,9 @@ import _ "unsafe"
1414
// This may change in the future. Please do not depend on them
1515
// in new code.
1616

17+
// golang.org/x/sys linknames getsockopt.
18+
// Do not remove or change the type signature.
19+
//
1720
//go:linkname getsockopt
21+
1822
//go:linkname setsockopt

Diff for: src/syscall/linkname_bsd.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,7 @@ import _ "unsafe"
1111
// used by internal/syscall/unix
1212
//go:linkname ioctlPtr
1313

14-
// used by x/net/route
14+
// golang.org/x/net linknames sysctl.
15+
// Do not remove or change the type signature.
16+
//
1517
//go:linkname sysctl

Diff for: src/syscall/syscall_linux.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -1284,12 +1284,13 @@ func Munmap(b []byte) (err error) {
12841284
//sys Mlockall(flags int) (err error)
12851285
//sys Munlockall() (err error)
12861286

1287-
// prlimit is accessed from x/sys/unix.
1288-
//go:linkname prlimit
1289-
12901287
// prlimit changes a resource limit. We use a single definition so that
12911288
// we can tell StartProcess to not restore the original NOFILE limit.
1292-
// This is unexported but can be called from x/sys/unix.
1289+
//
1290+
// golang.org/x/sys linknames prlimit.
1291+
// Do not remove or change the type signature.
1292+
//
1293+
//go:linkname prlimit
12931294
func prlimit(pid int, resource int, newlimit *Rlimit, old *Rlimit) (err error) {
12941295
err = prlimit1(pid, resource, newlimit, old)
12951296
if err == nil && newlimit != nil && resource == RLIMIT_NOFILE && (pid == 0 || pid == Getpid()) {

0 commit comments

Comments
 (0)