Skip to content

Commit 519b011

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

14 files changed

+103
-8
lines changed

src/reflect/badlinkname.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ import (
1717
// See go.dev/issue/67401
1818
// and go.dev/issue/67279.
1919

20-
//go:linkname add
21-
//go:linkname typesByString
22-
2320
// ifaceIndir reports whether t is stored indirectly in an interface value.
2421
// It is no longer used by this package and is here entirely for the
2522
// linkname uses.

src/reflect/type.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -935,6 +935,16 @@ func canRangeFunc2(t *abi.Type) bool {
935935
// record why the addition is safe, which is to say why the addition
936936
// does not cause x to advance to the very end of p's allocation
937937
// and therefore point incorrectly at the next block in memory.
938+
//
939+
// add should be an internal detail (and is trivially copyable),
940+
// but widely used packages access it using linkname.
941+
// Notable members of the hall of shame include:
942+
// - github.com/vmware/govmomi
943+
//
944+
// Do not remove or change the type signature.
945+
// See go.dev/issue/67401.
946+
//
947+
//go:linkname add
938948
func add(p unsafe.Pointer, x uintptr, whySafe string) unsafe.Pointer {
939949
return unsafe.Pointer(uintptr(p) + x)
940950
}
@@ -1649,6 +1659,16 @@ func rtypeOff(section unsafe.Pointer, off int32) *abi.Type {
16491659
// the given string representation.
16501660
// It may be empty (no known types with that string) or may have
16511661
// multiple elements (multiple types with that string).
1662+
//
1663+
// typesByString should be an internal detail,
1664+
// but widely used packages access it using linkname.
1665+
// Notable members of the hall of shame include:
1666+
// - github.com/aristanetworks/goarista
1667+
//
1668+
// Do not remove or change the type signature.
1669+
// See go.dev/issue/67401.
1670+
//
1671+
//go:linkname typesByString
16521672
func typesByString(s string) []*abi.Type {
16531673
sections, offset := typelinks()
16541674
var ret []*abi.Type

src/runtime/alg.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ func memhash64(p unsafe.Pointer, h uintptr) uintptr
6363
// strhash should be an internal detail,
6464
// but widely used packages access it using linkname.
6565
// Notable members of the hall of shame include:
66+
// - github.com/aristanetworks/goarista
6667
// - github.com/bytedance/sonic
6768
//
6869
// Do not remove or change the type signature.
@@ -136,6 +137,15 @@ func interhash(p unsafe.Pointer, h uintptr) uintptr {
136137
}
137138
}
138139

140+
// nilinterhash should be an internal detail,
141+
// but widely used packages access it using linkname.
142+
// Notable members of the hall of shame include:
143+
// - github.com/aristanetworks/goarista
144+
//
145+
// Do not remove or change the type signature.
146+
// See go.dev/issue/67401.
147+
//
148+
//go:linkname nilinterhash
139149
func nilinterhash(p unsafe.Pointer, h uintptr) uintptr {
140150
a := (*eface)(p)
141151
t := a._type

src/runtime/badlinkname.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ import _ "unsafe"
2727
//go:linkname gopark
2828
//go:linkname goready
2929
//go:linkname goyield
30-
//go:linkname nilinterhash
31-
//go:linkname noescape
3230
//go:linkname procPin
3331
//go:linkname procUnpin
3432
//go:linkname sched

src/runtime/cgo.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,28 @@ var (
3535
)
3636

3737
// iscgo is set to true by the runtime/cgo package
38+
//
39+
// iscgo should be an internal detail,
40+
// but widely used packages access it using linkname.
41+
// Notable members of the hall of shame include:
42+
// - github.com/ebitengine/purego
43+
//
44+
// Do not remove or change the type signature.
45+
// See go.dev/issue/67401.
46+
//
47+
//go:linkname iscgo
3848
var iscgo bool
3949

4050
// set_crosscall2 is set by the runtime/cgo package
51+
// set_crosscall2 should be an internal detail,
52+
// but widely used packages access it using linkname.
53+
// Notable members of the hall of shame include:
54+
// - github.com/ebitengine/purego
55+
//
56+
// Do not remove or change the type signature.
57+
// See go.dev/issue/67401.
58+
//
59+
//go:linkname set_crosscall2
4160
var set_crosscall2 func()
4261

4362
// cgoHasExtraM is set on startup when an extra M is created for cgo.

src/runtime/cgocall.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,15 @@ var ncgocall uint64 // number of cgo calls in total for dead m
121121
// platforms. Syscalls may have untyped arguments on the stack, so
122122
// it's not safe to grow or scan the stack.
123123
//
124+
// cgocall should be an internal detail,
125+
// but widely used packages access it using linkname.
126+
// Notable members of the hall of shame include:
127+
// - github.com/ebitengine/purego
128+
//
129+
// Do not remove or change the type signature.
130+
// See go.dev/issue/67401.
131+
//
132+
//go:linkname cgocall
124133
//go:nosplit
125134
func cgocall(fn, arg unsafe.Pointer) int32 {
126135
if !iscgo && GOOS != "solaris" && GOOS != "illumos" && GOOS != "windows" {

src/runtime/env_posix.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,26 @@ func lowerASCII(c byte) byte {
4242
return c
4343
}
4444

45-
var _cgo_setenv unsafe.Pointer // pointer to C function
45+
// _cgo_setenv should be an internal detail,
46+
// but widely used packages access it using linkname.
47+
// Notable members of the hall of shame include:
48+
// - github.com/ebitengine/purego
49+
//
50+
// Do not remove or change the type signature.
51+
// See go.dev/issue/67401.
52+
//
53+
//go:linkname _cgo_setenv
54+
var _cgo_setenv unsafe.Pointer // pointer to C function
55+
56+
// _cgo_unsetenv should be an internal detail,
57+
// but widely used packages access it using linkname.
58+
// Notable members of the hall of shame include:
59+
// - github.com/ebitengine/purego
60+
//
61+
// Do not remove or change the type signature.
62+
// See go.dev/issue/67401.
63+
//
64+
//go:linkname _cgo_unsetenv
4665
var _cgo_unsetenv unsafe.Pointer // pointer to C function
4766

4867
// Update the C environment if cgo is loaded.

src/runtime/linkname.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import _ "unsafe"
1313
//go:linkname goarm
1414

1515
// used by cgo
16-
//go:linkname cgocall
1716
//go:linkname _cgo_panic_internal
1817
//go:linkname cgoAlwaysFalse
1918
//go:linkname cgoUse

src/runtime/malloc.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -971,6 +971,7 @@ func (c *mcache) nextFree(spc spanClass) (v gclinkptr, s *mspan, shouldhelpgc bo
971971
// Notable members of the hall of shame include:
972972
// - github.com/bytedance/sonic
973973
// - github.com/ugorji/go/codec
974+
// - github.com/cockroachdb/pebble
974975
//
975976
// Do not remove or change the type signature.
976977
// See go.dev/issue/67401.
@@ -1429,6 +1430,7 @@ func newarray(typ *_type, n int) unsafe.Pointer {
14291430
// - github.com/bytedance/sonic
14301431
// - github.com/goccy/json
14311432
// - github.com/modern-go/reflect2
1433+
// - github.com/segmentio/kafka-go
14321434
//
14331435
// Do not remove or change the type signature.
14341436
// See go.dev/issue/67401.

src/runtime/panic.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,6 +1031,7 @@ func sync_fatal(s string) {
10311031
// but widely used packages access it using linkname.
10321032
// Notable members of the hall of shame include:
10331033
// - github.com/bytedance/sonic
1034+
// - github.com/cockroachdb/pebble
10341035
// - github.com/dgraph-io/ristretto
10351036
//
10361037
// Do not remove or change the type signature.

src/runtime/runtime.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,14 @@ var auxv []uintptr
300300
// Do not remove or change the type signature.
301301
// (See go.dev/issue/57336.)
302302
//
303+
// getAuxv should be an internal detail,
304+
// but widely used packages access it using linkname.
305+
// Notable members of the hall of shame include:
306+
// - github.com/cilium/ebpf
307+
//
308+
// Do not remove or change the type signature.
309+
// See go.dev/issue/67401.
310+
//
303311
//go:linkname getAuxv
304312
func getAuxv() []uintptr { return auxv }
305313

src/runtime/runtime1.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,7 @@ func releasem(mp *m) {
619619
// Notable members of the hall of shame include:
620620
// - github.com/goccy/json
621621
// - github.com/modern-go/reflect2
622+
// - github.com/vmware/govmomi
622623
//
623624
// Do not remove or change the type signature.
624625
// See go.dev/issue/67401.

src/runtime/stubs.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ func reflect_memclrNoHeapPointers(ptr unsafe.Pointer, n uintptr) {
120120
// Notable members of the hall of shame include:
121121
// - github.com/bytedance/sonic
122122
// - github.com/ugorji/go/codec
123+
// - github.com/ebitengine/purego
123124
//
124125
// Do not remove or change the type signature.
125126
// See go.dev/issue/67401.
@@ -156,6 +157,15 @@ func memequal(a, b unsafe.Pointer, size uintptr) bool
156157
// compiles down to zero instructions.
157158
// USE CAREFULLY!
158159
//
160+
// noescape should be an internal detail,
161+
// but widely used packages access it using linkname.
162+
// Notable members of the hall of shame include:
163+
// - github.com/ebitengine/purego
164+
//
165+
// Do not remove or change the type signature.
166+
// See go.dev/issue/67401.
167+
//
168+
//go:linkname noescape
159169
//go:nosplit
160170
func noescape(p unsafe.Pointer) unsafe.Pointer {
161171
x := uintptr(p)

src/runtime/time_nofake.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ import "unsafe"
1414
// Zero means not to use faketime.
1515
var faketime int64
1616

17-
// Many external packages linkname nanotime to get a fast monotonic time.
17+
// Exported via linkname for use by time and internal/poll.
18+
//
19+
// Many external packages also linkname nanotime for a fast monotonic time.
1820
// Such code should be updated to use:
1921
//
2022
// var start = time.Now() // at init time

0 commit comments

Comments
 (0)