diff options
author | Jeremy Faller <jeremy@golang.org> | 2020-07-16 16:18:49 -0400 |
---|---|---|
committer | Jeremy Faller <jeremy@golang.org> | 2020-07-31 13:55:07 +0000 |
commit | 6ac9914383bc88d014cbc681dae758372e6ca823 (patch) | |
tree | 1f41b4cbe03c274902ad26b6e19d33edbb5d6803 /src/debug | |
parent | 3067a8dc02f62c287a8ccd3fcf16bfdf4f687f5f (diff) | |
download | go-6ac9914383bc88d014cbc681dae758372e6ca823.tar.gz go-6ac9914383bc88d014cbc681dae758372e6ca823.zip |
[dev.link] create runtime.funcnametab
Move the function names out of runtime.pclntab_old, creating
runtime.funcnametab. There is an unfortunate artifact in this change in
that calculating the funcID still requires loading the name. Future work
will likely pull this out and put it into the object file Funcs.
ls -l cmd/compile (darwin):
before: 18524016
after: 18519952
The difference in size can be attributed to alignment in pclntab_old.
Change-Id: Ibcbb230d4632178f8fcd0667165f5335786381f8
Reviewed-on: https://go-review.googlesource.com/c/go/+/243223
Reviewed-by: Austin Clements <austin@google.com>
Diffstat (limited to 'src/debug')
-rw-r--r-- | src/debug/gosym/pclntab.go | 40 |
1 files changed, 28 insertions, 12 deletions
diff --git a/src/debug/gosym/pclntab.go b/src/debug/gosym/pclntab.go index 8c7ace17cd..e5c50520fc 100644 --- a/src/debug/gosym/pclntab.go +++ b/src/debug/gosym/pclntab.go @@ -49,16 +49,18 @@ type LineTable struct { version version // Go 1.2/1.16 state - binary binary.ByteOrder - quantum uint32 - ptrsize uint32 - funcdata []byte - functab []byte - nfunctab uint32 - filetab []byte - nfiletab uint32 - fileMap map[string]uint32 - strings map[uint32]string // interned substrings of Data, keyed by offset + binary binary.ByteOrder + quantum uint32 + ptrsize uint32 + funcnametab []byte + funcdata []byte + functab []byte + nfunctab uint32 + filetab []byte + nfiletab uint32 + fileMap map[string]uint32 + funcNames map[uint32]string // cache the function names + strings map[uint32]string // interned substrings of Data, keyed by offset } // NOTE(rsc): This is wrong for GOARCH=arm, which uses a quantum of 4, @@ -139,7 +141,7 @@ func (t *LineTable) LineToPC(line int, maxpc uint64) uint64 { // Text must be the start address of the // corresponding text segment. func NewLineTable(data []byte, text uint64) *LineTable { - return &LineTable{Data: data, PC: text, Line: 0, strings: make(map[uint32]string)} + return &LineTable{Data: data, PC: text, Line: 0, funcNames: make(map[uint32]string), strings: make(map[uint32]string)} } // Go 1.2 symbol table format. @@ -222,6 +224,8 @@ func (t *LineTable) parsePclnTab() { case ver116: t.nfunctab = uint32(t.uintptr(t.Data[8:])) offset := t.uintptr(t.Data[8+t.ptrsize:]) + t.funcnametab = t.Data[offset:] + offset = t.uintptr(t.Data[8+2*t.ptrsize:]) t.funcdata = t.Data[offset:] t.functab = t.Data[offset:] functabsize := t.nfunctab*2*t.ptrsize + t.ptrsize @@ -233,6 +237,7 @@ func (t *LineTable) parsePclnTab() { case ver12: t.nfunctab = uint32(t.uintptr(t.Data[8:])) t.funcdata = t.Data + t.funcnametab = t.Data t.functab = t.Data[8+t.ptrsize:] functabsize := t.nfunctab*2*t.ptrsize + t.ptrsize fileoff := t.binary.Uint32(t.functab[functabsize:]) @@ -265,7 +270,7 @@ func (t *LineTable) go12Funcs() []Func { f.Sym = &Sym{ Value: f.Entry, Type: 'T', - Name: t.string(t.binary.Uint32(info[t.ptrsize:])), + Name: t.funcName(t.binary.Uint32(info[t.ptrsize:])), GoType: 0, Func: f, } @@ -314,6 +319,17 @@ func (t *LineTable) readvarint(pp *[]byte) uint32 { return v } +// funcName returns the name of the function found at off. +func (t *LineTable) funcName(off uint32) string { + if s, ok := t.funcNames[off]; ok { + return s + } + i := bytes.IndexByte(t.funcnametab[off:], 0) + s := string(t.funcnametab[off : off+uint32(i)]) + t.funcNames[off] = s + return s +} + // string returns a Go string found at off. func (t *LineTable) string(off uint32) string { if s, ok := t.strings[off]; ok { |