From 4cac885741b845bd7f4aaad5bc9844b44eb23136 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Wed, 22 May 2024 15:46:02 -0400 Subject: [PATCH] =?utf8?q?all:=20document=20legacy=20//go:linkname=20for?= =?utf8?q?=20modules=20with=20=E2=89=A5200=20dependents?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Ignored these linknames which have not worked for a while: github.com/xtls/xray-core: context.newCancelCtx removed in CL 463999 (Feb 2023) github.com/u-root/u-root: funcPC removed in CL 513837 (Jul 2023) tinygo.org/x/drivers: net.useNetdev never existed For #67401. Change-Id: I9293f4ef197bb5552b431de8939fa94988a060ce Reviewed-on: https://go-review.googlesource.com/c/go/+/587576 Auto-Submit: Russ Cox Reviewed-by: Cherry Mui LUCI-TryBot-Result: Go LUCI --- src/crypto/tls/badlinkname.go | 1 - src/crypto/tls/cipher_suites.go | 9 ++++ src/crypto/tls/common.go | 10 +++++ src/net/http/badlinkname.go | 6 --- src/net/http/clone.go | 47 +++++++++++++++++++ src/net/http/transport.go | 11 +++++ src/runtime/alg.go | 16 +++++++ src/runtime/badlinkname.go | 1 - src/runtime/iface.go | 1 + src/runtime/malloc.go | 3 ++ src/runtime/map.go | 28 +++++++++++- src/runtime/map_fast32.go | 1 + src/runtime/map_fast64.go | 2 + src/runtime/map_faststr.go | 1 + src/runtime/mbarrier.go | 2 + src/runtime/mgc.go | 1 + src/runtime/proc.go | 4 ++ src/runtime/proflabel.go | 16 +++++++ src/runtime/runtime1.go | 19 ++++++++ src/runtime/slice.go | 1 + src/runtime/string.go | 10 +++++ src/runtime/stubs.go | 16 +++++++ src/runtime/symtab.go | 80 ++++++++++++++++++++++++++++++++- src/runtime/sys_darwin.go | 9 ++++ src/runtime/time_nofake.go | 8 ++++ src/runtime/timestub.go | 10 +++++ src/runtime/type.go | 18 ++++++++ src/time/badlinkname.go | 2 - src/time/format.go | 11 +++++ src/time/time.go | 10 +++++ 30 files changed, 342 insertions(+), 12 deletions(-) diff --git a/src/crypto/tls/badlinkname.go b/src/crypto/tls/badlinkname.go index 4eef04d1ff..841030abb4 100644 --- a/src/crypto/tls/badlinkname.go +++ b/src/crypto/tls/badlinkname.go @@ -12,7 +12,6 @@ import _ "unsafe" // This may change in the future. Please do not depend on them // in new code. -//go:linkname aeadAESGCMTLS13 //go:linkname cipherSuiteTLS13ByID //go:linkname errShutdown diff --git a/src/crypto/tls/cipher_suites.go b/src/crypto/tls/cipher_suites.go index 5f37bf6eb4..b2f330bc63 100644 --- a/src/crypto/tls/cipher_suites.go +++ b/src/crypto/tls/cipher_suites.go @@ -533,6 +533,15 @@ func aeadAESGCM(key, noncePrefix []byte) aead { return ret } +// aeadAESGCMTLS13 should be an internal detail, +// but widely used packages access it using linkname. +// Notable members of the hall of shame include: +// - github.com/xtls/xray-core +// +// Do not remove or change the type signature. +// See go.dev/issue/67401. +// +//go:linkname aeadAESGCMTLS13 func aeadAESGCMTLS13(key, nonceMask []byte) aead { if len(nonceMask) != aeadNonceLength { panic("tls: internal error: wrong nonce length") diff --git a/src/crypto/tls/common.go b/src/crypto/tls/common.go index 601d5b8e4c..498d345285 100644 --- a/src/crypto/tls/common.go +++ b/src/crypto/tls/common.go @@ -25,6 +25,7 @@ import ( "strings" "sync" "time" + _ "unsafe" // for linkname ) const ( @@ -1129,6 +1130,15 @@ func (c *Config) mutualVersion(isClient bool, peerVersions []uint16) (uint16, bo return 0, false } +// errNoCertificates should be an internal detail, +// but widely used packages access it using linkname. +// Notable members of the hall of shame include: +// - github.com/xtls/xray-core +// +// Do not remove or change the type signature. +// See go.dev/issue/67401. +// +//go:linkname errNoCertificates var errNoCertificates = errors.New("tls: no certificates configured") // getCertificate returns the best certificate for the given ClientHelloInfo, diff --git a/src/net/http/badlinkname.go b/src/net/http/badlinkname.go index 98726b1071..c714edf5f2 100644 --- a/src/net/http/badlinkname.go +++ b/src/net/http/badlinkname.go @@ -12,12 +12,6 @@ import _ "unsafe" // This may change in the future. Please do not depend on them // in new code. -//go:linkname cloneMultipartFileHeader -//go:linkname cloneMultipartForm -//go:linkname cloneOrMakeHeader -//go:linkname cloneTLSConfig -//go:linkname cloneURL -//go:linkname cloneURLValues //go:linkname newBufioReader //go:linkname newBufioWriterSize //go:linkname putBufioReader diff --git a/src/net/http/clone.go b/src/net/http/clone.go index 3a3375bff7..71f4242273 100644 --- a/src/net/http/clone.go +++ b/src/net/http/clone.go @@ -8,8 +8,18 @@ import ( "mime/multipart" "net/textproto" "net/url" + _ "unsafe" // for linkname ) +// cloneURLValues should be an internal detail, +// but widely used packages access it using linkname. +// Notable members of the hall of shame include: +// - github.com/searKing/golang +// +// Do not remove or change the type signature. +// See go.dev/issue/67401. +// +//go:linkname cloneURLValues func cloneURLValues(v url.Values) url.Values { if v == nil { return nil @@ -19,6 +29,15 @@ func cloneURLValues(v url.Values) url.Values { return url.Values(Header(v).Clone()) } +// cloneURL should be an internal detail, +// but widely used packages access it using linkname. +// Notable members of the hall of shame include: +// - github.com/searKing/golang +// +// Do not remove or change the type signature. +// See go.dev/issue/67401. +// +//go:linkname cloneURL func cloneURL(u *url.URL) *url.URL { if u == nil { return nil @@ -32,6 +51,15 @@ func cloneURL(u *url.URL) *url.URL { return u2 } +// cloneMultipartForm should be an internal detail, +// but widely used packages access it using linkname. +// Notable members of the hall of shame include: +// - github.com/searKing/golang +// +// Do not remove or change the type signature. +// See go.dev/issue/67401. +// +//go:linkname cloneMultipartForm func cloneMultipartForm(f *multipart.Form) *multipart.Form { if f == nil { return nil @@ -53,6 +81,15 @@ func cloneMultipartForm(f *multipart.Form) *multipart.Form { return f2 } +// cloneMultipartFileHeader should be an internal detail, +// but widely used packages access it using linkname. +// Notable members of the hall of shame include: +// - github.com/searKing/golang +// +// Do not remove or change the type signature. +// See go.dev/issue/67401. +// +//go:linkname cloneMultipartFileHeader func cloneMultipartFileHeader(fh *multipart.FileHeader) *multipart.FileHeader { if fh == nil { return nil @@ -65,6 +102,16 @@ func cloneMultipartFileHeader(fh *multipart.FileHeader) *multipart.FileHeader { // cloneOrMakeHeader invokes Header.Clone but if the // result is nil, it'll instead make and return a non-nil Header. +// +// cloneOrMakeHeader should be an internal detail, +// but widely used packages access it using linkname. +// Notable members of the hall of shame include: +// - github.com/searKing/golang +// +// Do not remove or change the type signature. +// See go.dev/issue/67401. +// +//go:linkname cloneOrMakeHeader func cloneOrMakeHeader(hdr Header) Header { clone := hdr.Clone() if clone == nil { diff --git a/src/net/http/transport.go b/src/net/http/transport.go index 0d4332c344..a1ff7ebe32 100644 --- a/src/net/http/transport.go +++ b/src/net/http/transport.go @@ -30,6 +30,7 @@ import ( "sync" "sync/atomic" "time" + _ "unsafe" "golang.org/x/net/http/httpguts" "golang.org/x/net/http/httpproxy" @@ -2983,6 +2984,16 @@ func (fakeLocker) Unlock() {} // cloneTLSConfig returns a shallow clone of cfg, or a new zero tls.Config if // cfg is nil. This is safe to call even if cfg is in active use by a TLS // client or server. +// +// cloneTLSConfig should be an internal detail, +// but widely used packages access it using linkname. +// Notable members of the hall of shame include: +// - github.com/searKing/golang +// +// Do not remove or change the type signature. +// See go.dev/issue/67401. +// +//go:linkname cloneTLSConfig func cloneTLSConfig(cfg *tls.Config) *tls.Config { if cfg == nil { return &tls.Config{} diff --git a/src/runtime/alg.go b/src/runtime/alg.go index f40cc9b8b6..c11ef4c6ef 100644 --- a/src/runtime/alg.go +++ b/src/runtime/alg.go @@ -49,8 +49,12 @@ var useAeshash bool // memhash should be an internal detail, // but widely used packages access it using linkname. // Notable members of the hall of shame include: +// - github.com/aacfactory/fns // - github.com/dgraph-io/ristretto +// - github.com/nbd-wtf/go-nostr // - github.com/outcaste-io/ristretto +// - github.com/puzpuzpuz/xsync/v2 +// - github.com/puzpuzpuz/xsync/v3 // // Do not remove or change the type signature. // See go.dev/issue/67401. @@ -67,6 +71,7 @@ func memhash64(p unsafe.Pointer, h uintptr) uintptr // - github.com/aristanetworks/goarista // - github.com/bytedance/sonic // - github.com/bytedance/go-tagexpr/v2 +// - github.com/cloudwego/frugal // // Do not remove or change the type signature. // See go.dev/issue/67401. @@ -176,6 +181,17 @@ func nilinterhash(p unsafe.Pointer, h uintptr) uintptr { // maps generated by reflect.MapOf (reflect_typehash, below). // Note: this function must match the compiler generated // functions exactly. See issue 37716. +// +// typehash should be an internal detail, +// but widely used packages access it using linkname. +// Notable members of the hall of shame include: +// - github.com/puzpuzpuz/xsync/v2 +// - github.com/puzpuzpuz/xsync/v3 +// +// Do not remove or change the type signature. +// See go.dev/issue/67401. +// +//go:linkname typehash func typehash(t *_type, p unsafe.Pointer, h uintptr) uintptr { if t.TFlag&abi.TFlagRegularMemory != 0 { // Handle ptr sizes specially, see issue 37086. diff --git a/src/runtime/badlinkname.go b/src/runtime/badlinkname.go index 47ce44ada8..a0bdab2ca6 100644 --- a/src/runtime/badlinkname.go +++ b/src/runtime/badlinkname.go @@ -25,7 +25,6 @@ import _ "unsafe" //go:linkname startTheWorld //go:linkname stopTheWorld //go:linkname stringHash -//go:linkname typehash // Notable members of the hall of shame include: // - github.com/dgraph-io/ristretto diff --git a/src/runtime/iface.go b/src/runtime/iface.go index 94bc07e380..9dcc25cf23 100644 --- a/src/runtime/iface.go +++ b/src/runtime/iface.go @@ -663,6 +663,7 @@ var emptyInterfaceSwitchCache = abi.InterfaceSwitchCache{Mask: 0} // reflect_ifaceE2I is for package reflect, // but widely used packages access it using linkname. // Notable members of the hall of shame include: +// - gitee.com/quant1x/gox // - github.com/modern-go/reflect2 // // Do not remove or change the type signature. diff --git a/src/runtime/malloc.go b/src/runtime/malloc.go index 75f25a94e4..70a198a81c 100644 --- a/src/runtime/malloc.go +++ b/src/runtime/malloc.go @@ -971,6 +971,7 @@ func (c *mcache) nextFree(spc spanClass) (v gclinkptr, s *mspan, shouldhelpgc bo // Notable members of the hall of shame include: // - github.com/bytedance/gopkg // - github.com/bytedance/sonic +// - github.com/cloudwego/frugal // - github.com/cockroachdb/cockroach // - github.com/cockroachdb/pebble // - github.com/ugorji/go/codec @@ -1388,6 +1389,7 @@ func newobject(typ *_type) unsafe.Pointer { // reflect_unsafe_New is meant for package reflect, // but widely used packages access it using linkname. // Notable members of the hall of shame include: +// - gitee.com/quant1x/gox // - github.com/goccy/json // - github.com/modern-go/reflect2 // @@ -1430,6 +1432,7 @@ func newarray(typ *_type, n int) unsafe.Pointer { // reflect_unsafe_NewArray is meant for package reflect, // but widely used packages access it using linkname. // Notable members of the hall of shame include: +// - gitee.com/quant1x/gox // - github.com/bytedance/sonic // - github.com/goccy/json // - github.com/modern-go/reflect2 diff --git a/src/runtime/map.go b/src/runtime/map.go index 4818cdcd92..5b13fda304 100644 --- a/src/runtime/map.go +++ b/src/runtime/map.go @@ -308,6 +308,7 @@ func makemap_small() *hmap { // makemap should be an internal detail, // but widely used packages access it using linkname. // Notable members of the hall of shame include: +// - github.com/cloudwego/frugal // - github.com/ugorji/go/codec // // Do not remove or change the type signature. @@ -602,6 +603,7 @@ func mapaccess2_fat(t *maptype, h *hmap, key, zero unsafe.Pointer) (unsafe.Point // but widely used packages access it using linkname. // Notable members of the hall of shame include: // - github.com/bytedance/sonic +// - github.com/cloudwego/frugal // - github.com/segmentio/encoding // - github.com/ugorji/go/codec // @@ -860,6 +862,7 @@ search: // but widely used packages access it using linkname. // Notable members of the hall of shame include: // - github.com/bytedance/sonic +// - github.com/cloudwego/frugal // - github.com/goccy/go-json // - github.com/segmentio/encoding // - github.com/ugorji/go/codec @@ -918,8 +921,9 @@ func mapiterinit(t *maptype, h *hmap, it *hiter) { // but widely used packages access it using linkname. // Notable members of the hall of shame include: // - github.com/bytedance/sonic -// - github.com/ugorji/go/codec +// - github.com/cloudwego/frugal // - github.com/segmentio/encoding +// - github.com/ugorji/go/codec // - gonum.org/v1/gonum // // Do not remove or change the type signature. @@ -1053,6 +1057,17 @@ next: } // mapclear deletes all keys from a map. +// It is called by the compiler. +// +// mapclear should be an internal detail, +// but widely used packages access it using linkname. +// Notable members of the hall of shame include: +// - github.com/cloudwego/frugal +// +// Do not remove or change the type signature. +// See go.dev/issue/67401. +// +//go:linkname mapclear func mapclear(t *maptype, h *hmap) { if raceenabled && h != nil { callerpc := getcallerpc() @@ -1371,6 +1386,7 @@ func advanceEvacuationMark(h *hmap, t *maptype, newbit uintptr) { // reflect_makemap is for package reflect, // but widely used packages access it using linkname. // Notable members of the hall of shame include: +// - gitee.com/quant1x/gox // - github.com/modern-go/reflect2 // - github.com/goccy/go-json // - github.com/segmentio/encoding @@ -1420,6 +1436,7 @@ func reflect_makemap(t *maptype, cap int) *hmap { // reflect_mapaccess is for package reflect, // but widely used packages access it using linkname. // Notable members of the hall of shame include: +// - gitee.com/quant1x/gox // - github.com/modern-go/reflect2 // // Do not remove or change the type signature. @@ -1445,6 +1462,13 @@ func reflect_mapaccess_faststr(t *maptype, h *hmap, key string) unsafe.Pointer { return elem } +// reflect_mapassign is for package reflect, +// but widely used packages access it using linkname. +// Notable members of the hall of shame include: +// - gitee.com/quant1x/gox +// +// Do not remove or change the type signature. +// //go:linkname reflect_mapassign reflect.mapassign0 func reflect_mapassign(t *maptype, h *hmap, key unsafe.Pointer, elem unsafe.Pointer) { p := mapassign(t, h, key) @@ -1471,6 +1495,7 @@ func reflect_mapdelete_faststr(t *maptype, h *hmap, key string) { // but widely used packages access it using linkname. // Notable members of the hall of shame include: // - github.com/modern-go/reflect2 +// - gitee.com/quant1x/gox // // Do not remove or change the type signature. // See go.dev/issue/67401. @@ -1483,6 +1508,7 @@ func reflect_mapiterinit(t *maptype, h *hmap, it *hiter) { // reflect_mapiternext is for package reflect, // but widely used packages access it using linkname. // Notable members of the hall of shame include: +// - gitee.com/quant1x/gox // - github.com/modern-go/reflect2 // - github.com/goccy/go-json // diff --git a/src/runtime/map_fast32.go b/src/runtime/map_fast32.go index f3d830ea43..0eb8562f51 100644 --- a/src/runtime/map_fast32.go +++ b/src/runtime/map_fast32.go @@ -103,6 +103,7 @@ func mapaccess2_fast32(t *maptype, h *hmap, key uint32) (unsafe.Pointer, bool) { // but widely used packages access it using linkname. // Notable members of the hall of shame include: // - github.com/bytedance/sonic +// - github.com/cloudwego/frugal // - github.com/ugorji/go/codec // // Do not remove or change the type signature. diff --git a/src/runtime/map_fast64.go b/src/runtime/map_fast64.go index 29cee968cd..aca60eb2a8 100644 --- a/src/runtime/map_fast64.go +++ b/src/runtime/map_fast64.go @@ -103,6 +103,7 @@ func mapaccess2_fast64(t *maptype, h *hmap, key uint64) (unsafe.Pointer, bool) { // but widely used packages access it using linkname. // Notable members of the hall of shame include: // - github.com/bytedance/sonic +// - github.com/cloudwego/frugal // - github.com/ugorji/go/codec // // Do not remove or change the type signature. @@ -203,6 +204,7 @@ done: // but widely used packages access it using linkname. // Notable members of the hall of shame include: // - github.com/bytedance/sonic +// - github.com/cloudwego/frugal // - github.com/ugorji/go/codec // // Do not remove or change the type signature. diff --git a/src/runtime/map_faststr.go b/src/runtime/map_faststr.go index 1494348be7..5461a9f81e 100644 --- a/src/runtime/map_faststr.go +++ b/src/runtime/map_faststr.go @@ -213,6 +213,7 @@ dohash: // but widely used packages access it using linkname. // Notable members of the hall of shame include: // - github.com/bytedance/sonic +// - github.com/cloudwego/frugal // - github.com/ugorji/go/codec // // Do not remove or change the type signature. diff --git a/src/runtime/mbarrier.go b/src/runtime/mbarrier.go index c90c5f729e..c83e5c6fcd 100644 --- a/src/runtime/mbarrier.go +++ b/src/runtime/mbarrier.go @@ -211,6 +211,7 @@ func wbMove(typ *_type, dst, src unsafe.Pointer) { // reflect_typedmemmove is meant for package reflect, // but widely used packages access it using linkname. // Notable members of the hall of shame include: +// - gitee.com/quant1x/gox // - github.com/goccy/json // - github.com/modern-go/reflect2 // - github.com/ugorji/go/codec @@ -334,6 +335,7 @@ func typedslicecopy(typ *_type, dstPtr unsafe.Pointer, dstLen int, srcPtr unsafe // reflect_typedslicecopy is meant for package reflect, // but widely used packages access it using linkname. // Notable members of the hall of shame include: +// - gitee.com/quant1x/gox // - github.com/modern-go/reflect2 // - github.com/segmentio/encoding // diff --git a/src/runtime/mgc.go b/src/runtime/mgc.go index d78b2f7692..9874a9afde 100644 --- a/src/runtime/mgc.go +++ b/src/runtime/mgc.go @@ -220,6 +220,7 @@ var gcphase uint32 // but widely used packages access it using linkname. // Notable members of the hall of shame include: // - github.com/bytedance/sonic +// - github.com/cloudwego/frugal // // Do not remove or change the type signature. // See go.dev/issue/67401. diff --git a/src/runtime/proc.go b/src/runtime/proc.go index a948149936..68296bd1e4 100644 --- a/src/runtime/proc.go +++ b/src/runtime/proc.go @@ -7039,6 +7039,7 @@ func setMaxThreads(in int) (out int) { // but widely used packages access it using linkname. // Notable members of the hall of shame include: // - github.com/bytedance/gopkg +// - github.com/choleraehyq/pid // // Do not remove or change the type signature. // See go.dev/issue/67401. @@ -7057,6 +7058,7 @@ func procPin() int { // but widely used packages access it using linkname. // Notable members of the hall of shame include: // - github.com/bytedance/gopkg +// - github.com/choleraehyq/pid // // Do not remove or change the type signature. // See go.dev/issue/67401. @@ -7097,6 +7099,7 @@ func sync_atomic_runtime_procUnpin() { // sync_runtime_canSpin should be an internal detail, // but widely used packages access it using linkname. // Notable members of the hall of shame include: +// - github.com/livekit/protocol // - gvisor.dev/gvisor // // Do not remove or change the type signature. @@ -7122,6 +7125,7 @@ func sync_runtime_canSpin(i int) bool { // sync_runtime_doSpin should be an internal detail, // but widely used packages access it using linkname. // Notable members of the hall of shame include: +// - github.com/livekit/protocol // - gvisor.dev/gvisor // // Do not remove or change the type signature. diff --git a/src/runtime/proflabel.go b/src/runtime/proflabel.go index b2a161729e..7c29c0ef83 100644 --- a/src/runtime/proflabel.go +++ b/src/runtime/proflabel.go @@ -8,6 +8,14 @@ import "unsafe" var labelSync uintptr +// runtime_setProfLabel should be an internal detail, +// but widely used packages access it using linkname. +// Notable members of the hall of shame include: +// - github.com/DataDog/datadog-agent +// +// Do not remove or change the type signature. +// See go.dev/issue/67401. +// //go:linkname runtime_setProfLabel runtime/pprof.runtime_setProfLabel func runtime_setProfLabel(labels unsafe.Pointer) { // Introduce race edge for read-back via profile. @@ -34,6 +42,14 @@ func runtime_setProfLabel(labels unsafe.Pointer) { getg().labels = labels } +// runtime_getProfLabel should be an internal detail, +// but widely used packages access it using linkname. +// Notable members of the hall of shame include: +// - github.com/DataDog/datadog-agent +// +// Do not remove or change the type signature. +// See go.dev/issue/67401. +// //go:linkname runtime_getProfLabel runtime/pprof.runtime_getProfLabel func runtime_getProfLabel() unsafe.Pointer { return getg().labels diff --git a/src/runtime/runtime1.go b/src/runtime/runtime1.go index 378f0d8ea3..6086d3a0d8 100644 --- a/src/runtime/runtime1.go +++ b/src/runtime/runtime1.go @@ -617,6 +617,7 @@ func releasem(mp *m) { // reflect_typelinks is meant for package reflect, // but widely used packages access it using linkname. // Notable members of the hall of shame include: +// - gitee.com/quant1x/gox // - github.com/goccy/json // - github.com/modern-go/reflect2 // - github.com/vmware/govmomi @@ -638,6 +639,14 @@ func reflect_typelinks() ([]unsafe.Pointer, [][]int32) { // reflect_resolveNameOff resolves a name offset from a base pointer. // +// reflect_resolveNameOff is for package reflect, +// but widely used packages access it using linkname. +// Notable members of the hall of shame include: +// - github.com/agiledragon/gomonkey/v2 +// +// Do not remove or change the type signature. +// See go.dev/issue/67401. +// //go:linkname reflect_resolveNameOff reflect.resolveNameOff func reflect_resolveNameOff(ptrInModule unsafe.Pointer, off int32) unsafe.Pointer { return unsafe.Pointer(resolveNameOff(ptrInModule, nameOff(off)).Bytes) @@ -648,6 +657,7 @@ func reflect_resolveNameOff(ptrInModule unsafe.Pointer, off int32) unsafe.Pointe // reflect_resolveTypeOff is meant for package reflect, // but widely used packages access it using linkname. // Notable members of the hall of shame include: +// - gitee.com/quant1x/gox // - github.com/modern-go/reflect2 // // Do not remove or change the type signature. @@ -660,6 +670,15 @@ func reflect_resolveTypeOff(rtype unsafe.Pointer, off int32) unsafe.Pointer { // reflect_resolveTextOff resolves a function pointer offset from a base type. // +// reflect_resolveTextOff is for package reflect, +// but widely used packages access it using linkname. +// Notable members of the hall of shame include: +// - github.com/cloudwego/frugal +// - github.com/agiledragon/gomonkey/v2 +// +// Do not remove or change the type signature. +// See go.dev/issue/67401. +// //go:linkname reflect_resolveTextOff reflect.resolveTextOff func reflect_resolveTextOff(rtype unsafe.Pointer, off int32) unsafe.Pointer { return toRType((*_type)(rtype)).textOff(textOff(off)) diff --git a/src/runtime/slice.go b/src/runtime/slice.go index 7ffca036c0..b91caf0dfe 100644 --- a/src/runtime/slice.go +++ b/src/runtime/slice.go @@ -166,6 +166,7 @@ func makeslice64(et *_type, len64, cap64 int64) unsafe.Pointer { // but widely used packages access it using linkname. // Notable members of the hall of shame include: // - github.com/bytedance/sonic +// - github.com/chenzhuoyu/iasm // - github.com/ugorji/go/codec // // Do not remove or change the type signature. diff --git a/src/runtime/string.go b/src/runtime/string.go index d45888b7a8..5bdb25b9db 100644 --- a/src/runtime/string.go +++ b/src/runtime/string.go @@ -78,6 +78,16 @@ func concatstring5(buf *tmpBuf, a0, a1, a2, a3, a4 string) string { // n is the length of the slice. // Buf is a fixed-size buffer for the result, // it is not nil if the result does not escape. +// +// slicebytetostring should be an internal detail, +// but widely used packages access it using linkname. +// Notable members of the hall of shame include: +// - github.com/cloudwego/frugal +// +// Do not remove or change the type signature. +// See go.dev/issue/67401. +// +//go:linkname slicebytetostring func slicebytetostring(buf *tmpBuf, ptr *byte, n int) string { if n == 0 { // Turns out to be a relatively common case. diff --git a/src/runtime/stubs.go b/src/runtime/stubs.go index 69ffacc62c..ff4fe5eafd 100644 --- a/src/runtime/stubs.go +++ b/src/runtime/stubs.go @@ -87,6 +87,8 @@ func badsystemstack() { // but widely used packages access it using linkname. // Notable members of the hall of shame include: // - github.com/bytedance/sonic +// - github.com/chenzhuoyu/iasm +// - github.com/cloudwego/frugal // - github.com/dgraph-io/ristretto // - github.com/outcaste-io/ristretto // @@ -120,6 +122,7 @@ func reflect_memclrNoHeapPointers(ptr unsafe.Pointer, n uintptr) { // but widely used packages access it using linkname. // Notable members of the hall of shame include: // - github.com/bytedance/sonic +// - github.com/cloudwego/frugal // - github.com/ebitengine/purego // - github.com/tetratelabs/wazero // - github.com/ugorji/go/codec @@ -165,6 +168,7 @@ func memequal(a, b unsafe.Pointer, size uintptr) bool // Notable members of the hall of shame include: // - github.com/bytedance/gopkg // - github.com/ebitengine/purego +// - github.com/puzpuzpuz/xsync/v3 // // Do not remove or change the type signature. // See go.dev/issue/67401. @@ -345,7 +349,18 @@ func getclosureptr() uintptr func asmcgocall(fn, arg unsafe.Pointer) int32 func morestack() + +// morestack_noctxt should be an internal detail, +// but widely used packages access it using linkname. +// Notable members of the hall of shame include: +// - github.com/cloudwego/frugal +// +// Do not remove or change the type signature. +// See go.dev/issue/67401. +// +//go:linkname morestack_noctxt func morestack_noctxt() + func rt0_go() // return0 is a stub used to return 0 from deferproc. @@ -435,6 +450,7 @@ func gcWriteBarrier1() // but widely used packages access it using linkname. // Notable members of the hall of shame include: // - github.com/bytedance/sonic +// - github.com/cloudwego/frugal // // Do not remove or change the type signature. // See go.dev/issue/67401. diff --git a/src/runtime/symtab.go b/src/runtime/symtab.go index a7ce9c3a7e..40f0be6542 100644 --- a/src/runtime/symtab.go +++ b/src/runtime/symtab.go @@ -437,8 +437,19 @@ type modulehash struct { // To make sure the map isn't collected, we keep a second reference here. var pinnedTypemaps []map[typeOff]*_type -var firstmoduledata moduledata // linker symbol +var firstmoduledata moduledata // linker symbol + +// lastmoduledatap should be an internal detail, +// but widely used packages access it using linkname. +// Notable members of the hall of shame include: +// - github.com/cloudwego/frugal +// +// Do not remove or change the type signature. +// See go.dev/issue/67401. +// +//go:linkname lastmoduledatap var lastmoduledatap *moduledata // linker symbol + var modulesSlice *[]*moduledata // see activeModules // activeModules returns a slice of active modules. @@ -547,6 +558,15 @@ func moduledataverify() { const debugPcln = false +// moduledataverify1 should be an internal detail, +// but widely used packages access it using linkname. +// Notable members of the hall of shame include: +// - github.com/cloudwego/frugal +// +// Do not remove or change the type signature. +// See go.dev/issue/67401. +// +//go:linkname moduledataverify1 func moduledataverify1(datap *moduledata) { // Check that the pclntab's format is valid. hdr := datap.pcHeader @@ -674,6 +694,16 @@ func (md *moduledata) funcName(nameOff int32) string { // If pc represents multiple functions because of inlining, it returns // the *Func describing the innermost function, but with an entry of // the outermost function. +// +// For completely unclear reasons, even though they can import runtime, +// some widely used packages access this using linkname. +// Notable members of the hall of shame include: +// - gitee.com/quant1x/gox +// +// Do not remove or change the type signature. +// See go.dev/issue/67401. +// +//go:linkname FuncForPC func FuncForPC(pc uintptr) *Func { f := findfunc(pc) if !f.valid() { @@ -793,7 +823,16 @@ func (f funcInfo) entry() uintptr { // It is nosplit because it's part of the isgoexception // implementation. // +// findfunc should be an internal detail, +// but widely used packages access it using linkname. +// Notable members of the hall of shame include: +// - github.com/cloudwego/frugal +// +// Do not remove or change the type signature. +// See go.dev/issue/67401. +// //go:nosplit +//go:linkname findfunc func findfunc(pc uintptr) funcInfo { datap := findmoduledatap(pc) if datap == nil { @@ -1101,6 +1140,16 @@ func pcdatavalue1(f funcInfo, table uint32, targetpc uintptr, strict bool) int32 } // Like pcdatavalue, but also return the start PC of this PCData value. +// +// pcdatavalue2 should be an internal detail, +// but widely used packages access it using linkname. +// Notable members of the hall of shame include: +// - github.com/cloudwego/frugal +// +// Do not remove or change the type signature. +// See go.dev/issue/67401. +// +//go:linkname pcdatavalue2 func pcdatavalue2(f funcInfo, table uint32, targetpc uintptr) (int32, uintptr) { if table >= f.npcdata { return -1, 0 @@ -1110,6 +1159,16 @@ func pcdatavalue2(f funcInfo, table uint32, targetpc uintptr) (int32, uintptr) { // funcdata returns a pointer to the ith funcdata for f. // funcdata should be kept in sync with cmd/link:writeFuncs. +// +// funcdata should be an internal detail, +// but widely used packages access it using linkname. +// Notable members of the hall of shame include: +// - github.com/cloudwego/frugal +// +// Do not remove or change the type signature. +// See go.dev/issue/67401. +// +//go:linkname funcdata func funcdata(f funcInfo, i uint8) unsafe.Pointer { if i < 0 || i >= f.nfuncdata { return nil @@ -1129,6 +1188,16 @@ func funcdata(f funcInfo, i uint8) unsafe.Pointer { } // step advances to the next pc, value pair in the encoded table. +// +// step should be an internal detail, +// but widely used packages access it using linkname. +// Notable members of the hall of shame include: +// - github.com/cloudwego/frugal +// +// Do not remove or change the type signature. +// See go.dev/issue/67401. +// +//go:linkname step func step(p []byte, pc *uintptr, val *int32, first bool) (newp []byte, ok bool) { // For both uvdelta and pcdelta, the common case (~70%) // is that they are a single byte. If so, avoid calling readvarint. @@ -1174,6 +1243,15 @@ type stackmap struct { bytedata [1]byte // bitmaps, each starting on a byte boundary } +// stackmapdata should be an internal detail, +// but widely used packages access it using linkname. +// Notable members of the hall of shame include: +// - github.com/cloudwego/frugal +// +// Do not remove or change the type signature. +// See go.dev/issue/67401. +// +//go:linkname stackmapdata //go:nowritebarrier func stackmapdata(stkmap *stackmap, n int32) bitvector { // Check this invariant only when stackDebug is on at all. diff --git a/src/runtime/sys_darwin.go b/src/runtime/sys_darwin.go index d8fa39429f..1e4b2ac79e 100644 --- a/src/runtime/sys_darwin.go +++ b/src/runtime/sys_darwin.go @@ -380,6 +380,15 @@ func nanotime1() int64 { } func nanotime_trampoline() +// walltime should be an internal detail, +// but widely used packages access it using linkname. +// Notable members of the hall of shame include: +// - gitee.com/quant1x/gox +// +// Do not remove or change the type signature. +// See go.dev/issue/67401. +// +//go:linkname walltime //go:nosplit //go:cgo_unsafe_args func walltime() (int64, int32) { diff --git a/src/runtime/time_nofake.go b/src/runtime/time_nofake.go index e455f64b9f..130ff12816 100644 --- a/src/runtime/time_nofake.go +++ b/src/runtime/time_nofake.go @@ -36,6 +36,14 @@ func nanotime() int64 { // overrideWrite allows write to be redirected externally, by // linkname'ing this and set it to a write function. // +// overrideWrite should be an internal detail, +// but widely used packages access it using linkname. +// Notable members of the hall of shame include: +// - golang.zx2c4.com/wireguard/windows +// +// Do not remove or change the type signature. +// See go.dev/issue/67401. +// //go:linkname overrideWrite var overrideWrite func(fd uintptr, p unsafe.Pointer, n int32) int32 diff --git a/src/runtime/timestub.go b/src/runtime/timestub.go index 1d2926b43d..a9d71c1fd4 100644 --- a/src/runtime/timestub.go +++ b/src/runtime/timestub.go @@ -11,6 +11,16 @@ package runtime import _ "unsafe" // for go:linkname +// time_now should be an internal detail, +// but widely used packages access it using linkname. +// Notable members of the hall of shame include: +// - gitee.com/quant1x/gox +// - github.com/sethvargo/go-limiter +// - github.com/ulule/limiter/v3 +// +// Do not remove or change the type signature. +// See go.dev/issue/67401. +// //go:linkname time_now time.now func time_now() (sec int64, nsec int32, mono int64) { sec, nsec = walltime() diff --git a/src/runtime/type.go b/src/runtime/type.go index a2975c4a99..201340752b 100644 --- a/src/runtime/type.go +++ b/src/runtime/type.go @@ -106,6 +106,15 @@ func reflectOffsUnlock() { unlock(&reflectOffs.lock) } +// resolveNameOff should be an internal detail, +// but widely used packages access it using linkname. +// Notable members of the hall of shame include: +// - github.com/cloudwego/frugal +// +// Do not remove or change the type signature. +// See go.dev/issue/67401. +// +//go:linkname resolveNameOff func resolveNameOff(ptrInModule unsafe.Pointer, off nameOff) name { if off == 0 { return name{} @@ -140,6 +149,15 @@ func (t rtype) nameOff(off nameOff) name { return resolveNameOff(unsafe.Pointer(t.Type), off) } +// resolveTypeOff should be an internal detail, +// but widely used packages access it using linkname. +// Notable members of the hall of shame include: +// - github.com/cloudwego/frugal +// +// Do not remove or change the type signature. +// See go.dev/issue/67401. +// +//go:linkname resolveTypeOff func resolveTypeOff(ptrInModule unsafe.Pointer, off typeOff) *_type { if off == 0 || off == -1 { // -1 is the sentinel value for unreachable code. diff --git a/src/time/badlinkname.go b/src/time/badlinkname.go index 96d2e31862..097a823ccf 100644 --- a/src/time/badlinkname.go +++ b/src/time/badlinkname.go @@ -13,5 +13,3 @@ import _ "unsafe" // in new code. //go:linkname absClock -//go:linkname absDate -//go:linkname nextStdChunk diff --git a/src/time/format.go b/src/time/format.go index c823bce4d8..07f1f804c1 100644 --- a/src/time/format.go +++ b/src/time/format.go @@ -7,6 +7,7 @@ package time import ( "errors" "internal/stringslite" + _ "unsafe" // for linkname ) // These are predefined layouts for use in [Time.Format] and [time.Parse]. @@ -184,6 +185,16 @@ func startsWithLowerCase(str string) bool { // nextStdChunk finds the first occurrence of a std string in // layout and returns the text before, the std string, and the text after. +// +// nextStdChunk should be an internal detail, +// but widely used packages access it using linkname. +// Notable members of the hall of shame include: +// - github.com/searKing/golang/go +// +// Do not remove or change the type signature. +// See go.dev/issue/67401. +// +//go:linkname nextStdChunk func nextStdChunk(layout string) (prefix string, std int, suffix string) { for i := 0; i < len(layout); i++ { switch c := int(layout[i]); c { diff --git a/src/time/time.go b/src/time/time.go index 0bbdeaecf5..63ee6f6f94 100644 --- a/src/time/time.go +++ b/src/time/time.go @@ -988,6 +988,16 @@ func (t Time) date(full bool) (year int, month Month, day int, yday int) { } // absDate is like date but operates on an absolute time. +// +// absDate should be an internal detail, +// but widely used packages access it using linkname. +// Notable members of the hall of shame include: +// - gitee.com/quant1x/gox +// +// Do not remove or change the type signature. +// See go.dev/issue/67401. +// +//go:linkname absDate func absDate(abs uint64, full bool) (year int, month Month, day int, yday int) { // Split into time and day. d := abs / secondsPerDay -- 2.48.1