all: document legacy //go:linkname for modules with ≥500 dependents

For #67401.

Change-Id: I7dd28c3b01a1a647f84929d15412aa43ab0089ee
Reviewed-on: https://go-review.googlesource.com/c/go/+/587575
Reviewed-by: Cherry Mui <cherryyz@google.com>
Auto-Submit: Russ Cox <rsc@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
Russ Cox 2024-05-22 15:03:13 -04:00 committed by Gopher Robot
parent 1d3d6ae725
commit 05cbbf985f
23 changed files with 264 additions and 52 deletions

View File

@ -13,4 +13,3 @@ import _ "unsafe"
// in new code.
//go:linkname convertAssign
//go:linkname drivers

View File

@ -29,12 +29,22 @@ import (
"sync"
"sync/atomic"
"time"
_ "unsafe"
)
var (
driversMu sync.RWMutex
drivers = make(map[string]driver.Driver)
)
var driversMu sync.RWMutex
// drivers should be an internal detail,
// but widely used packages access it using linkname.
// (It is extra wrong that they linkname drivers but not driversMu.)
// Notable members of the hall of shame include:
// - github.com/instana/go-sensor
//
// Do not remove or change the type signature.
// See go.dev/issue/67401.
//
//go:linkname drivers
var drivers = make(map[string]driver.Driver)
// nowFunc returns the current time; it's overridden in tests.
var nowFunc = time.Now

View File

@ -39,6 +39,16 @@ func CompareString(a, b string) int {
return runtime_cmpstring(a, b)
}
// runtime.cmpstring calls are emitted by the compiler.
//
// runtime.cmpstring should be an internal detail,
// but widely used packages access it using linkname.
// Notable members of the hall of shame include:
// - github.com/bytedance/gopkg
//
// Do not remove or change the type signature.
// See go.dev/issue/67401.
//
//go:linkname runtime_cmpstring runtime.cmpstring
func runtime_cmpstring(a, b string) int {
l := len(a)

View File

@ -6,6 +6,8 @@
package cpu
import _ "unsafe" // for linkname
func osInit() {
ARM64.HasATOMICS = sysctlEnabled([]byte("hw.optional.armv8_1_atomics\x00"))
ARM64.HasCRC32 = sysctlEnabled([]byte("hw.optional.armv8_crc32\x00"))
@ -24,6 +26,15 @@ func osInit() {
//go:noescape
func getsysctlbyname(name []byte) (int32, int32)
// sysctlEnabled should be an internal detail,
// but widely used packages access it using linkname.
// Notable members of the hall of shame include:
// - github.com/bytedance/gopkg
//
// Do not remove or change the type signature.
// See go.dev/issue/67401.
//
//go:linkname sysctlEnabled
func sysctlEnabled(name []byte) bool {
ret, value := getsysctlbyname(name)
if ret < 0 {

View File

@ -13,4 +13,3 @@ import _ "unsafe"
// in new code.
//go:linkname defaultNS
//go:linkname isDomainName

View File

@ -76,6 +76,16 @@ func equalASCIIName(x, y dnsmessage.Name) bool {
// isDomainName checks if a string is a presentation-format domain name
// (currently restricted to hostname-compatible "preferred name" LDH labels and
// SRV-like "underscore labels"; see golang.org/issue/12421).
//
// isDomainName should be an internal detail,
// but widely used packages access it using linkname.
// Notable members of the hall of shame include:
// - github.com/sagernet/sing
//
// Do not remove or change the type signature.
// See go.dev/issue/67401.
//
//go:linkname isDomainName
func isDomainName(s string) bool {
// The root domain name is valid. See golang.org/issue/45715.
if s == "." {

View File

@ -20,10 +20,8 @@ import _ "unsafe"
//go:linkname cloneURLValues
//go:linkname newBufioReader
//go:linkname newBufioWriterSize
//go:linkname parseBasicAuth
//go:linkname putBufioReader
//go:linkname putBufioWriter
//go:linkname readRequest
// The compiler doesn't allow linknames on methods, for good reasons.
// We use this trick to push linknames of the methods.

View File

@ -25,6 +25,7 @@ import (
"strconv"
"strings"
"sync"
_ "unsafe" // for linkname
"golang.org/x/net/http/httpguts"
"golang.org/x/net/idna"
@ -986,6 +987,16 @@ func (r *Request) BasicAuth() (username, password string, ok bool) {
// parseBasicAuth parses an HTTP Basic Authentication string.
// "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==" returns ("Aladdin", "open sesame", true).
//
// parseBasicAuth should be an internal detail,
// but widely used packages access it using linkname.
// Notable members of the hall of shame include:
// - github.com/sagernet/sing
//
// Do not remove or change the type signature.
// See go.dev/issue/67401.
//
//go:linkname parseBasicAuth
func parseBasicAuth(auth string) (username, password string, ok bool) {
const prefix = "Basic "
// Case insensitive prefix match. See Issue 22736.
@ -1061,6 +1072,15 @@ func ReadRequest(b *bufio.Reader) (*Request, error) {
return req, err
}
// readRequest should be an internal detail,
// but widely used packages access it using linkname.
// Notable members of the hall of shame include:
// - github.com/sagernet/sing
//
// Do not remove or change the type signature.
// See go.dev/issue/67401.
//
//go:linkname readRequest
func readRequest(b *bufio.Reader) (req *Request, err error) {
tp := newTextprotoReader(b)
defer putTextprotoReader(tp)

View File

@ -9,6 +9,7 @@ import (
"internal/itoa"
"sync"
"time"
_ "unsafe"
)
// BUG(mikio): On JS, methods and functions related to
@ -17,6 +18,16 @@ import (
// BUG(mikio): On AIX, DragonFly BSD, NetBSD, OpenBSD, Plan 9 and
// Solaris, the MulticastAddrs method of Interface is not implemented.
// errNoSuchInterface should be an internal detail,
// but widely used packages access it using linkname.
// Notable members of the hall of shame include:
// - github.com/sagernet/sing
//
// Do not remove or change the type signature.
// See go.dev/issue/67401.
//
//go:linkname errNoSuchInterface
var (
errInvalidInterface = errors.New("invalid network interface")
errInvalidInterfaceIndex = errors.New("invalid network interface index")

View File

@ -1,20 +0,0 @@
// Copyright 2024 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 url
import _ "unsafe"
// As of Go 1.22, the symbols below are found to be pulled via
// linkname in the wild. We provide a push linkname here, to
// keep them accessible with pull linknames.
// This may change in the future. Please do not depend on them
// in new code.
// The compiler doesn't allow linknames on methods, for good reasons.
// We use this trick to push linknames of the methods.
// Do not call them in this package.
//go:linkname badlinkname_URL_setPath net/url.(*URL).setPath
func badlinkname_URL_setPath(*URL, string) error

View File

@ -17,6 +17,7 @@ import (
"slices"
"strconv"
"strings"
_ "unsafe" // for linkname
)
// Error reports an error and the operation and URL that caused it.
@ -677,6 +678,16 @@ func parseHost(host string) (string, error) {
// - setPath("/foo%2fbar") will set Path="/foo/bar" and RawPath="/foo%2fbar"
// setPath will return an error only if the provided path contains an invalid
// escaping.
//
// setPath should be an internal detail,
// but widely used packages access it using linkname.
// Notable members of the hall of shame include:
// - github.com/sagernet/sing
//
// Do not remove or change the type signature.
// See go.dev/issue/67401.
//
//go:linkname badSetPath net/url.(*URL).setPath
func (u *URL) setPath(p string) error {
path, err := unescape(p, encodePath)
if err != nil {
@ -692,6 +703,9 @@ func (u *URL) setPath(p string) error {
return nil
}
// for linkname because we cannot linkname methods directly
func badSetPath(*URL, string) error
// EscapedPath returns the escaped form of u.Path.
// In general there are multiple possible escaped forms of any path.
// EscapedPath returns u.RawPath when it is a valid escaping of u.Path.

View File

@ -50,6 +50,7 @@ var useAeshash bool
// but widely used packages access it using linkname.
// Notable members of the hall of shame include:
// - github.com/dgraph-io/ristretto
// - github.com/outcaste-io/ristretto
//
// Do not remove or change the type signature.
// See go.dev/issue/67401.
@ -65,6 +66,7 @@ func memhash64(p unsafe.Pointer, h uintptr) uintptr
// Notable members of the hall of shame include:
// - github.com/aristanetworks/goarista
// - github.com/bytedance/sonic
// - github.com/bytedance/go-tagexpr/v2
//
// Do not remove or change the type signature.
// See go.dev/issue/67401.
@ -140,6 +142,7 @@ func interhash(p unsafe.Pointer, h uintptr) uintptr {
// nilinterhash should be an internal detail,
// but widely used packages access it using linkname.
// Notable members of the hall of shame include:
// - github.com/anacrolix/stm
// - github.com/aristanetworks/goarista
//
// Do not remove or change the type signature.

View File

@ -18,6 +18,15 @@ import (
// atomicwb performs a write barrier before an atomic pointer write.
// The caller should guard the call with "if writeBarrier.enabled".
//
// atomicwb should be an internal detail,
// but widely used packages access it using linkname.
// Notable members of the hall of shame include:
// - github.com/bytedance/gopkg
//
// Do not remove or change the type signature.
// See go.dev/issue/67401.
//
//go:linkname atomicwb
//go:nosplit
func atomicwb(ptr *unsafe.Pointer, new unsafe.Pointer) {
slot := (*uintptr)(unsafe.Pointer(ptr))

View File

@ -18,23 +18,17 @@ import _ "unsafe"
// See go.dev/issue/67401.
//go:linkname add
//go:linkname atomicwb
//go:linkname callers
//go:linkname entersyscallblock
//go:linkname fastexprand
//go:linkname gopanic
//go:linkname gopark
//go:linkname goready
//go:linkname goyield
//go:linkname procPin
//go:linkname procUnpin
//go:linkname sched
//go:linkname startTheWorld
//go:linkname stopTheWorld
//go:linkname stringHash
//go:linkname typehash
//go:linkname wakep
// Notable members of the hall of shame include:
// - github.com/dgraph-io/ristretto
// - github.com/outcaste-io/ristretto
// - github.com/clubpay/ronykit
//go:linkname cputicks

View File

@ -969,9 +969,11 @@ func (c *mcache) nextFree(spc spanClass) (v gclinkptr, s *mspan, shouldhelpgc bo
// mallocgc should be an internal detail,
// but widely used packages access it using linkname.
// Notable members of the hall of shame include:
// - github.com/bytedance/gopkg
// - github.com/bytedance/sonic
// - github.com/ugorji/go/codec
// - github.com/cockroachdb/cockroach
// - github.com/cockroachdb/pebble
// - github.com/ugorji/go/codec
//
// Do not remove or change the type signature.
// See go.dev/issue/67401.

View File

@ -1703,6 +1703,14 @@ var poolcleanup func()
var boringCaches []unsafe.Pointer // for crypto/internal/boring
var uniqueMapCleanup chan struct{} // for unique
// sync_runtime_registerPoolCleanup should be an internal detail,
// but widely used packages access it using linkname.
// Notable members of the hall of shame include:
// - github.com/bytedance/gopkg
//
// Do not remove or change the type signature.
// See go.dev/issue/67401.
//
//go:linkname sync_runtime_registerPoolCleanup sync.runtime_registerPoolCleanup
func sync_runtime_registerPoolCleanup(f func()) {
poolcleanup = f

View File

@ -1033,6 +1033,8 @@ func sync_fatal(s string) {
// - github.com/bytedance/sonic
// - github.com/cockroachdb/pebble
// - github.com/dgraph-io/ristretto
// - github.com/outcaste-io/ristretto
// - gvisor.dev/gvisor
//
// Do not remove or change the type signature.
// See go.dev/issue/67401.

View File

@ -382,6 +382,16 @@ func goschedIfBusy() {
// Reason explains why the goroutine has been parked. It is displayed in stack
// traces and heap dumps. Reasons should be unique and descriptive. Do not
// re-use reasons, add new ones.
//
// gopark should be an internal detail,
// but widely used packages access it using linkname.
// Notable members of the hall of shame include:
// - gvisor.dev/gvisor
//
// Do not remove or change the type signature.
// See go.dev/issue/67401.
//
//go:linkname gopark
func gopark(unlockf func(*g, unsafe.Pointer) bool, lock unsafe.Pointer, reason waitReason, traceReason traceBlockReason, traceskip int) {
if reason != waitReasonSleep {
checkTimeouts() // timeouts may expire while two goroutines keep the scheduler busy
@ -408,6 +418,15 @@ func goparkunlock(lock *mutex, reason waitReason, traceReason traceBlockReason,
gopark(parkunlock_c, unsafe.Pointer(lock), reason, traceReason, traceskip)
}
// goready should be an internal detail,
// but widely used packages access it using linkname.
// Notable members of the hall of shame include:
// - gvisor.dev/gvisor
//
// Do not remove or change the type signature.
// See go.dev/issue/67401.
//
//go:linkname goready
func goready(gp *g, traceskip int) {
systemstack(func() {
ready(gp, traceskip, true)
@ -3034,6 +3053,16 @@ func handoffp(pp *p) {
// Tries to add one more P to execute G's.
// Called when a G is made runnable (newproc, ready).
// Must be called with a P.
//
// wakep should be an internal detail,
// but widely used packages access it using linkname.
// Notable members of the hall of shame include:
// - gvisor.dev/gvisor
//
// Do not remove or change the type signature.
// See go.dev/issue/67401.
//
//go:linkname wakep
func wakep() {
// Be conservative about spinning threads, only start one if none exist
// already.
@ -4163,6 +4192,16 @@ func preemptPark(gp *g) {
// goyield is like Gosched, but it:
// - emits a GoPreempt trace event instead of a GoSched trace event
// - puts the current G on the runq of the current P instead of the globrunq
//
// goyield should be an internal detail,
// but widely used packages access it using linkname.
// Notable members of the hall of shame include:
// - gvisor.dev/gvisor
//
// Do not remove or change the type signature.
// See go.dev/issue/67401.
//
//go:linkname goyield
func goyield() {
checkTimeouts()
mcall(goyield_m)
@ -4397,6 +4436,14 @@ func reentersyscall(pc, sp, bp uintptr) {
//
// This is exported via linkname to assembly in the syscall package and x/sys.
//
// Other packages should not be accessing entersyscall directly,
// but widely used packages access it using linkname.
// Notable members of the hall of shame include:
// - gvisor.dev/gvisor
//
// Do not remove or change the type signature.
// See go.dev/issue/67401.
//
//go:nosplit
//go:linkname entersyscall
func entersyscall() {
@ -4449,7 +4496,16 @@ func entersyscall_gcwait() {
}
// The same as entersyscall(), but with a hint that the syscall is blocking.
// entersyscallblock should be an internal detail,
// but widely used packages access it using linkname.
// Notable members of the hall of shame include:
// - gvisor.dev/gvisor
//
// Do not remove or change the type signature.
// See go.dev/issue/67401.
//
//go:linkname entersyscallblock
//go:nosplit
func entersyscallblock() {
gp := getg()
@ -4511,6 +4567,14 @@ func entersyscallblock_handoff() {
//
// This is exported via linkname to assembly in the syscall package.
//
// exitsyscall should be an internal detail,
// but widely used packages access it using linkname.
// Notable members of the hall of shame include:
// - gvisor.dev/gvisor
//
// Do not remove or change the type signature.
// See go.dev/issue/67401.
//
//go:nosplit
//go:nowritebarrierrec
//go:linkname exitsyscall
@ -4735,6 +4799,7 @@ func exitsyscall0(gp *g) {
// but widely used packages access it using linkname.
// Notable members of the hall of shame include:
// - github.com/containerd/containerd
// - gvisor.dev/gvisor
//
// Do not remove or change the type signature.
// See go.dev/issue/67401.
@ -4764,6 +4829,7 @@ func syscall_runtime_BeforeFork() {
// but widely used packages access it using linkname.
// Notable members of the hall of shame include:
// - github.com/containerd/containerd
// - gvisor.dev/gvisor
//
// Do not remove or change the type signature.
// See go.dev/issue/67401.
@ -4797,6 +4863,7 @@ var inForkedChild bool
// but widely used packages access it using linkname.
// Notable members of the hall of shame include:
// - github.com/containerd/containerd
// - gvisor.dev/gvisor
//
// Do not remove or change the type signature.
// See go.dev/issue/67401.
@ -6968,6 +7035,15 @@ func setMaxThreads(in int) (out int) {
return
}
// procPin should be an internal detail,
// but widely used packages access it using linkname.
// Notable members of the hall of shame include:
// - github.com/bytedance/gopkg
//
// Do not remove or change the type signature.
// See go.dev/issue/67401.
//
//go:linkname procPin
//go:nosplit
func procPin() int {
gp := getg()
@ -6977,6 +7053,15 @@ func procPin() int {
return int(mp.p.ptr().id)
}
// procUnpin should be an internal detail,
// but widely used packages access it using linkname.
// Notable members of the hall of shame include:
// - github.com/bytedance/gopkg
//
// Do not remove or change the type signature.
// See go.dev/issue/67401.
//
//go:linkname procUnpin
//go:nosplit
func procUnpin() {
gp := getg()
@ -7009,6 +7094,14 @@ func sync_atomic_runtime_procUnpin() {
// Active spinning for sync.Mutex.
//
// sync_runtime_canSpin should be an internal detail,
// but widely used packages access it using linkname.
// Notable members of the hall of shame include:
// - gvisor.dev/gvisor
//
// Do not remove or change the type signature.
// See go.dev/issue/67401.
//
//go:linkname sync_runtime_canSpin sync.runtime_canSpin
//go:nosplit
func sync_runtime_canSpin(i int) bool {
@ -7026,6 +7119,14 @@ func sync_runtime_canSpin(i int) bool {
return true
}
// sync_runtime_doSpin should be an internal detail,
// but widely used packages access it using linkname.
// Notable members of the hall of shame include:
// - gvisor.dev/gvisor
//
// Do not remove or change the type signature.
// See go.dev/issue/67401.
//
//go:linkname sync_runtime_doSpin sync.runtime_doSpin
//go:nosplit
func sync_runtime_doSpin() {

View File

@ -178,6 +178,15 @@ func randn(n uint32) uint32 {
// the rule is that other packages using runtime-provided
// randomness must always use rand.
//
// cheaprand should be an internal detail,
// but widely used packages access it using linkname.
// Notable members of the hall of shame include:
// - github.com/bytedance/gopkg
//
// Do not remove or change the type signature.
// See go.dev/issue/67401.
//
//go:linkname cheaprand
//go:nosplit
func cheaprand() uint32 {
mp := getg().m

View File

@ -57,6 +57,14 @@ func (t *semTable) rootFor(addr *uint32) *semaRoot {
return &t[(uintptr(unsafe.Pointer(addr))>>3)%semTabSize].root
}
// sync_runtime_Semacquire should be an internal detail,
// but widely used packages access it using linkname.
// Notable members of the hall of shame include:
// - gvisor.dev/gvisor
//
// Do not remove or change the type signature.
// See go.dev/issue/67401.
//
//go:linkname sync_runtime_Semacquire sync.runtime_Semacquire
func sync_runtime_Semacquire(addr *uint32) {
semacquire1(addr, false, semaBlockProfile, 0, waitReasonSemacquire)
@ -67,6 +75,14 @@ func poll_runtime_Semacquire(addr *uint32) {
semacquire1(addr, false, semaBlockProfile, 0, waitReasonSemacquire)
}
// sync_runtime_Semrelease should be an internal detail,
// but widely used packages access it using linkname.
// Notable members of the hall of shame include:
// - gvisor.dev/gvisor
//
// Do not remove or change the type signature.
// See go.dev/issue/67401.
//
//go:linkname sync_runtime_Semrelease sync.runtime_Semrelease
func sync_runtime_Semrelease(addr *uint32, handoff bool, skipframes int) {
semrelease1(addr, handoff, skipframes)

View File

@ -88,6 +88,7 @@ func badsystemstack() {
// Notable members of the hall of shame include:
// - github.com/bytedance/sonic
// - github.com/dgraph-io/ristretto
// - github.com/outcaste-io/ristretto
//
// Do not remove or change the type signature.
// See go.dev/issue/67401.
@ -122,6 +123,7 @@ func reflect_memclrNoHeapPointers(ptr unsafe.Pointer, n uintptr) {
// - github.com/ebitengine/purego
// - github.com/tetratelabs/wazero
// - github.com/ugorji/go/codec
// - gvisor.dev/gvisor
//
// Do not remove or change the type signature.
// See go.dev/issue/67401.
@ -161,6 +163,7 @@ func memequal(a, b unsafe.Pointer, size uintptr) bool
// noescape should be an internal detail,
// but widely used packages access it using linkname.
// Notable members of the hall of shame include:
// - github.com/bytedance/gopkg
// - github.com/ebitengine/purego
//
// Do not remove or change the type signature.
@ -245,6 +248,15 @@ func breakpoint()
//go:noescape
func reflectcall(stackArgsType *_type, fn, stackArgs unsafe.Pointer, stackArgsSize, stackRetOffset, frameSize uint32, regArgs *abi.RegArgs)
// procyield should be an internal detail,
// but widely used packages access it using linkname.
// Notable members of the hall of shame include:
// - github.com/slackhq/nebula
//
// Do not remove or change the type signature.
// See go.dev/issue/67401.
//
//go:linkname procyield
func procyield(cycles uint32)
type neverCallThisFunction struct{}

View File

@ -1,15 +0,0 @@
// Copyright 2024 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 sync
import _ "unsafe"
// As of Go 1.22, the symbols below are found to be pulled via
// linkname in the wild. We provide a push linkname here, to
// keep them accessible with pull linknames.
// This may change in the future. Please do not depend on them
// in new code.
//go:linkname poolCleanup

View File

@ -242,6 +242,15 @@ func (p *Pool) pinSlow() (*poolLocal, int) {
return &local[pid], pid
}
// poolCleanup should be an internal detail,
// but widely used packages access it using linkname.
// Notable members of the hall of shame include:
// - github.com/bytedance/gopkg
//
// Do not remove or change the type signature.
// See go.dev/issue/67401.
//
//go:linkname poolCleanup
func poolCleanup() {
// This function is called with the world stopped, at the beginning of a garbage collection.
// It must not allocate and probably should not call any runtime functions.