mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
[dev.link] cmd/link: implement live method tracking in deadcode2
This essentially replicates the logic of live method tracking and type symbol decoding, rewritten to operate on indices instead of Symbols. TODO: the special handling of reflect.Type.Method has not been implemented. TODO: the symbol name is used too much. It ought to be a better way to do it. Change-Id: I860ee7a506c00833902e4870d15aea698a705dd9 Reviewed-on: https://go-review.googlesource.com/c/go/+/199078 Reviewed-by: Than McIntosh <thanm@google.com>
This commit is contained in:
parent
cc21e4d130
commit
7d6f79e617
2 changed files with 268 additions and 16 deletions
|
|
@ -235,10 +235,10 @@ func (l *Loader) NSym() int {
|
|||
|
||||
// Returns the raw (unpatched) name of the i-th symbol.
|
||||
func (l *Loader) RawSymName(i Sym) string {
|
||||
r, li := l.ToLocal(i)
|
||||
if r == nil {
|
||||
if l.extStart != 0 && i >= l.extStart {
|
||||
return ""
|
||||
}
|
||||
r, li := l.ToLocal(i)
|
||||
osym := goobj2.Sym{}
|
||||
osym.Read(r.Reader, r.SymOff(li))
|
||||
return osym.Name
|
||||
|
|
@ -246,10 +246,10 @@ func (l *Loader) RawSymName(i Sym) string {
|
|||
|
||||
// Returns the (patched) name of the i-th symbol.
|
||||
func (l *Loader) SymName(i Sym) string {
|
||||
r, li := l.ToLocal(i)
|
||||
if r == nil {
|
||||
if l.extStart != 0 && i >= l.extStart {
|
||||
return ""
|
||||
}
|
||||
r, li := l.ToLocal(i)
|
||||
osym := goobj2.Sym{}
|
||||
osym.Read(r.Reader, r.SymOff(li))
|
||||
return strings.Replace(osym.Name, "\"\".", r.pkgprefix, -1)
|
||||
|
|
@ -257,27 +257,39 @@ func (l *Loader) SymName(i Sym) string {
|
|||
|
||||
// Returns the type of the i-th symbol.
|
||||
func (l *Loader) SymType(i Sym) sym.SymKind {
|
||||
r, li := l.ToLocal(i)
|
||||
if r == nil {
|
||||
if l.extStart != 0 && i >= l.extStart {
|
||||
return 0
|
||||
}
|
||||
r, li := l.ToLocal(i)
|
||||
osym := goobj2.Sym{}
|
||||
osym.Read(r.Reader, r.SymOff(li))
|
||||
return sym.AbiSymKindToSymKind[objabi.SymKind(osym.Type)]
|
||||
}
|
||||
|
||||
// Returns the symbol content of the i-th symbol. i is global index.
|
||||
func (l *Loader) Data(i Sym) []byte {
|
||||
if l.extStart != 0 && i >= l.extStart {
|
||||
return nil
|
||||
}
|
||||
r, li := l.ToLocal(i)
|
||||
return r.Data(li)
|
||||
}
|
||||
|
||||
// Returns the number of aux symbols given a global index.
|
||||
func (l *Loader) NAux(i Sym) int {
|
||||
r, li := l.ToLocal(i)
|
||||
if r == nil {
|
||||
if l.extStart != 0 && i >= l.extStart {
|
||||
return 0
|
||||
}
|
||||
r, li := l.ToLocal(i)
|
||||
return r.NAux(li)
|
||||
}
|
||||
|
||||
// Returns the referred symbol of the j-th aux symbol of the i-th
|
||||
// symbol.
|
||||
func (l *Loader) AuxSym(i Sym, j int) Sym {
|
||||
if l.extStart != 0 && i >= l.extStart {
|
||||
return 0
|
||||
}
|
||||
r, li := l.ToLocal(i)
|
||||
a := goobj2.Aux{}
|
||||
a.Read(r.Reader, r.AuxOff(li, j))
|
||||
|
|
@ -305,10 +317,10 @@ func (relocs *Relocs) At(j int) Reloc {
|
|||
|
||||
// Relocs returns a Relocs object for the given global sym.
|
||||
func (l *Loader) Relocs(i Sym) Relocs {
|
||||
r, li := l.ToLocal(i)
|
||||
if r == nil {
|
||||
if l.extStart != 0 && i >= l.extStart {
|
||||
return Relocs{}
|
||||
}
|
||||
r, li := l.ToLocal(i)
|
||||
return l.relocs(r, li)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue