diff options
| author | Ian Lance Taylor <iant@golang.org> | 2025-12-11 20:50:05 -0800 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2026-03-26 17:37:59 -0700 |
| commit | 87fae3622dacca9cfa5026c712df40af694a4e6a (patch) | |
| tree | f7bc61ad5a773db548366cb840e8483766b11b35 /src/runtime | |
| parent | 2dbd51e3b4bf29e6204caf0465258ced601494a2 (diff) | |
| download | go-87fae3622dacca9cfa5026c712df40af694a4e6a.tar.xz | |
reflect, runtime: replace reflect.typelinks to return types, not offsets
Change reflect to call a new function to get the compiled type descriptors,
returning the type pointers directly rather than the type offsets.
We have to keep the existing reflect.typelinks for third party
packages that break the rules and call it directly using linkname.
Change-Id: I476efb6bd7836a7a5f396c97bbe4b2c1a2428990
Reviewed-on: https://go-review.googlesource.com/c/go/+/729502
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Antonio Camacho <antoniocho444@gmail.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
Diffstat (limited to 'src/runtime')
| -rw-r--r-- | src/runtime/runtime1.go | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/runtime/runtime1.go b/src/runtime/runtime1.go index 10754eee1c..8da3682261 100644 --- a/src/runtime/runtime1.go +++ b/src/runtime/runtime1.go @@ -5,6 +5,7 @@ package runtime import ( + "internal/abi" "internal/bytealg" "internal/goarch" "internal/runtime/atomic" @@ -627,6 +628,9 @@ func releasem(mp *m) { // Do not remove or change the type signature. // See go.dev/issue/67401. // +// This is obsolete and only remains for external packages. +// New code should use reflect_compiledTypelinks. +// //go:linkname reflect_typelinks reflect.typelinks func reflect_typelinks() ([]unsafe.Pointer, [][]int32) { modules := activeModules() @@ -649,6 +653,23 @@ func reflect_typelinks() ([]unsafe.Pointer, [][]int32) { return sections, ret } +// reflect_compiledTypelinks returns the typelink types +// generated by the compiler for all current modules. +// The normal case is a single module, so this returns one +// slice for the main module, and a slice of slices, normally nil, +// for other modules. +// +//go:linkname reflect_compiledTypelinks reflect.compiledTypelinks +func reflect_compiledTypelinks() ([]*abi.Type, [][]*abi.Type) { + modules := activeModules() + firstTypes := moduleTypelinks(modules[0]) + var rest [][]*abi.Type + for _, md := range modules[1:] { + rest = append(rest, moduleTypelinks(md)) + } + return firstTypes, rest +} + // reflect_resolveNameOff resolves a name offset from a base pointer. // // reflect_resolveNameOff is for package reflect, |
