|
| 1 | +package runtime |
| 2 | + |
| 3 | +import "unsafe" |
| 4 | + |
| 5 | +// Previously we used the following |
| 6 | +// |
| 7 | +// //go:linkname goRuntimeInt64Hash runtime.int64Hash //go:noescape func |
| 8 | +// goRuntimeInt64Hash(i uint64, seed uintptr) uintptr |
| 9 | +// |
| 10 | +// //go:linkname goRuntimeEfaceHash runtime.efaceHash //go:noescape func |
| 11 | +// goRuntimeEfaceHash(i interface{}, seed uintptr) uintptr |
| 12 | +// |
| 13 | +// But since go 1.23 it is no longer allowed to use //go.linkname to refer to |
| 14 | +// internal symbols in the standard library (see |
| 15 | +// https://tip.golang.org/doc/go1.23#linker). |
| 16 | +// |
| 17 | +// This means the above is no longer possible - fortunately, these functions are |
| 18 | +// implemented in Go and the functions they call are all exceptions to the rule. |
| 19 | +// So we work around the new restriction by copying those implementations into |
| 20 | +// our codebase. |
| 21 | +// |
| 22 | +// This should be fairly stable as the reasons why memhash64, nilinterhash and |
| 23 | +// noescape are exceptions is that they are used in a number of major open |
| 24 | +// source projects. |
| 25 | + |
| 26 | +// The two functions below are copied from |
| 27 | +// https://github.com/golang/go/blob/release-branch.go1.23/src/runtime/alg.go#L446-L452 |
| 28 | + |
| 29 | +func goRuntimeInt64Hash(i uint64, seed uintptr) uintptr { |
| 30 | + return memhash64(noescape(unsafe.Pointer(&i)), seed) |
| 31 | +} |
| 32 | + |
| 33 | +func goRuntimeEfaceHash(i interface{}, seed uintptr) uintptr { |
| 34 | + return nilinterhash(noescape(unsafe.Pointer(&i)), seed) |
| 35 | +} |
| 36 | + |
| 37 | +//go:linkname memhash64 runtime.memhash64 |
| 38 | +//go:noescape |
| 39 | +func memhash64(p unsafe.Pointer, h uintptr) uintptr |
| 40 | + |
| 41 | +//go:linkname nilinterhash runtime.nilinterhash |
| 42 | +//go:noescape |
| 43 | +func nilinterhash(p unsafe.Pointer, h uintptr) uintptr |
| 44 | + |
| 45 | +//go:linkname noescape runtime.noescape |
| 46 | +//go:noescape |
| 47 | +func noescape(p unsafe.Pointer) unsafe.Pointer |
0 commit comments