From e180e2c27c3c3f06a4df6352386efedc15a1e38c Mon Sep 17 00:00:00 2001 From: Cherry Mui Date: Tue, 28 Sep 2021 17:07:01 -0400 Subject: cmd/internal/goobj, cmd/link: remove funcdataoff FUNCDATA is always a symbol reference with 0 offset. Assert the offset is 0 and remove funcdataoff. Change-Id: I326815365c9db5aeef6b869df5d78a9957bc16a6 Reviewed-on: https://go-review.googlesource.com/c/go/+/352894 Trust: Cherry Mui Reviewed-by: Than McIntosh --- src/cmd/link/internal/loader/loader.go | 62 +++++++++++++++------------------- 1 file changed, 28 insertions(+), 34 deletions(-) (limited to 'src/cmd/link/internal/loader/loader.go') diff --git a/src/cmd/link/internal/loader/loader.go b/src/cmd/link/internal/loader/loader.go index ec145da26d..9b7888e940 100644 --- a/src/cmd/link/internal/loader/loader.go +++ b/src/cmd/link/internal/loader/loader.go @@ -1930,12 +1930,38 @@ func (l *Loader) NumPcdata(i Sym) int { return n } +// Returns all funcdata symbols of symbol i. +// tmp is a scratch space. +func (l *Loader) Funcdata(i Sym, tmp []Sym) []Sym { + fd := tmp[:0] + r, auxs := l.auxs(i) + for j := range auxs { + a := &auxs[j] + if a.Type() == goobj.AuxFuncdata { + fd = append(fd, l.resolve(r, a.Sym())) + } + } + return fd +} + +// Returns the number of funcdata for symbol i. +func (l *Loader) NumFuncdata(i Sym) int { + n := 0 + _, auxs := l.auxs(i) + for j := range auxs { + a := &auxs[j] + if a.Type() == goobj.AuxFuncdata { + n++ + } + } + return n +} + // FuncInfo provides hooks to access goobj.FuncInfo in the objects. type FuncInfo struct { l *Loader r *oReader data []byte - auxs []goobj.Aux lengths goobj.FuncInfoLengths } @@ -1963,38 +1989,6 @@ func (fi *FuncInfo) Preload() { fi.lengths = (*goobj.FuncInfo)(nil).ReadFuncInfoLengths(fi.data) } -func (fi *FuncInfo) NumFuncdataoff() uint32 { - if !fi.lengths.Initialized { - panic("need to call Preload first") - } - return fi.lengths.NumFuncdataoff -} - -func (fi *FuncInfo) Funcdataoff(k int) int64 { - if !fi.lengths.Initialized { - panic("need to call Preload first") - } - return (*goobj.FuncInfo)(nil).ReadFuncdataoff(fi.data, fi.lengths.FuncdataoffOff, uint32(k)) -} - -func (fi *FuncInfo) Funcdata(syms []Sym) []Sym { - if !fi.lengths.Initialized { - panic("need to call Preload first") - } - if int(fi.lengths.NumFuncdataoff) > cap(syms) { - syms = make([]Sym, 0, fi.lengths.NumFuncdataoff) - } else { - syms = syms[:0] - } - for j := range fi.auxs { - a := &fi.auxs[j] - if a.Type() == goobj.AuxFuncdata { - syms = append(syms, fi.l.resolve(fi.r, a.Sym())) - } - } - return syms -} - func (fi *FuncInfo) NumFile() uint32 { if !fi.lengths.Initialized { panic("need to call Preload first") @@ -2051,7 +2045,7 @@ func (l *Loader) FuncInfo(i Sym) FuncInfo { a := &auxs[j] if a.Type() == goobj.AuxFuncInfo { b := r.Data(a.Sym().SymIdx) - return FuncInfo{l, r, b, auxs, goobj.FuncInfoLengths{}} + return FuncInfo{l, r, b, goobj.FuncInfoLengths{}} } } return FuncInfo{} -- cgit v1.3