diff options
| author | Ian Lance Taylor <iant@golang.org> | 2025-11-25 22:44:11 -0800 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2026-01-27 13:47:14 -0800 |
| commit | 481ab86aafe0cac177df793c9946c5ef2126137c (patch) | |
| tree | dbe3504b8dae8baaf51c933b57b62503db98d356 /src/runtime/runtime1.go | |
| parent | 251f3aa6ee6fc3925fe8e64cd4b403bfa73b93ab (diff) | |
| download | go-481ab86aafe0cac177df793c9946c5ef2126137c.tar.xz | |
cmd/link, runtime: remove typelinks
Instead of adding a typelinks section to a Go binary,
mark the start and end of the typelinked type descriptors.
The runtime can then step through the descriptors to find them all,
rather than relying on the extra linker-generated offset list.
The runtime steps through the type descriptors lazily,
as many Go programs don't need the typelinks list at all.
This reduces the size of cmd/go by 15K bytes, which isn't much
but it's not nothing.
A future CL will change the reflect package to use the type pointers
directly rather than converting to offsets and then back to type pointers.
For #6853
Change-Id: Id0af4ce81c5b1cea899fc92b6ff9d2db8ce4c267
Reviewed-on: https://go-review.googlesource.com/c/go/+/724261
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/runtime/runtime1.go')
| -rw-r--r-- | src/runtime/runtime1.go | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/runtime/runtime1.go b/src/runtime/runtime1.go index 965ff8ab51..9b1dd585ca 100644 --- a/src/runtime/runtime1.go +++ b/src/runtime/runtime1.go @@ -630,11 +630,21 @@ func releasem(mp *m) { //go:linkname reflect_typelinks reflect.typelinks func reflect_typelinks() ([]unsafe.Pointer, [][]int32) { modules := activeModules() + + typesToOffsets := func(md *moduledata) []int32 { + types := moduleTypelinks(md) + ret := make([]int32, 0, len(types)) + for _, typ := range types { + ret = append(ret, int32(uintptr(unsafe.Pointer(typ))-md.types)) + } + return ret + } + sections := []unsafe.Pointer{unsafe.Pointer(modules[0].types)} - ret := [][]int32{modules[0].typelinks} + ret := [][]int32{typesToOffsets(modules[0])} for _, md := range modules[1:] { sections = append(sections, unsafe.Pointer(md.types)) - ret = append(ret, md.typelinks) + ret = append(ret, typesToOffsets(md)) } return sections, ret } |
