cockroachdb / cockroachdb/cockroach
*: remove instances of `go:linkname` throughout repository
- Dominant language
- Go
- Stars
- 32.5k
- Forks
- 4.1k
- PR merge metrics
- PR metrics pending
Description
With Go 1.23, the [Go linker](https://go.dev/doc/go1.23#linker) is much more restrictive about uses of `go:linkname` and will specifically disallow linking to internal standard library symbols. For now it seems we are safe to upgrade to Go 1.23 as they have surveyed major open-source repositories including `cockroach` to find instances of `go:linkname` and allow-listed already-linkname'd symbols. However, things are liable to change in the future and symbols may be removed from the allow-list. We recognize this usage of `go:linkname` is an anti-pattern that should be addressed.
Additionally, ~each of these is something that is liable to break in an upgrade and requires extra scrutiny on upgrades or else the code will behave unpredictably or unsafely. Removing these instances and replacing them with public, supported API's will minimize the amount of work that must be done with Go upgrades.
Some of these usages would be easiest to remove by up-streaming the relevant functionality into the Go toolchain (e.g. `goschedstats`)
```
pkg/sql/sem/builtins/pgcrypto_builtins.go
25: _ "unsafe" // required to use go:linkname
36: _ "golang.org/x/crypto/bcrypt" // linked to by go:linkname
423:// bcryptLinked accesses private method bcrypt.bcrypt by using go:linkname.
425://go:linkname bcryptLinked golang.org/x/crypto/bcrypt.bcrypt
pkg/testutils/bazelcodecover/code_cover_on.go
62://go:linkname runtime_addExitHook runtime.addExitHook
pkg/storage/slice_go1.9.go
18:// The go:linkname directives provides backdoor access to private functions in
23://go:linkname mallocgc runtime.mallocgc
pkg/util/goschedstats/runtime_go1.23.go
29: _ "unsafe" // required by go:linkname
168://go:linkname allp runtime.allp
171://go:linkname sched runtime.sched
174://go:linkname lock runtime.lock
177://go:linkname unlock runtime.unlock
pkg/util/goschedstats/runtime_go1.20_21_22.go
21: _ "unsafe" // required by go:linkname
160://go:linkname allp runtime.allp
163://go:linkname sched runtime.sched
166://go:linkname lock runtime.lock
169://go:linkname unlock runtime.unlock
pkg/util/goschedstats/runtime_go1.19.go
21: _ "unsafe" // required by go:linkname
126://go:linkname allp runtime.allp
129://go:linkname sched runtime.sched
132://go:linkname lock runtime.lock
135://go:linkname unlock runtime.unlock
pkg/util/grunning/enabled.go
18:import _ "unsafe" // for go:linkname
23://go:linkname grunningnanos runtime.grunningnanos
pkg/util/randutil/rand.go
22: _ "unsafe" // required by go:linkname
201://go:linkname FastUint32 runtime.fastrand
pkg/util/ctxutil/context.go
83://go:linkname context_cancelCtxKey context.cancelCtxKey
pkg/util/ctxutil/canceler_1_20.go
47://go:linkname context_removeChild context.removeChild
50://go:linkname context_propagateCancel context.propagateCancel
```
For now I'm assigning this to dev-inf for lack of a better owner.
Jira issue: CRDB-41282
Contributor guide
Assessment
This issue has not been assessed yet.