mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/internal/obj: move STEXT-only LSym fields into new FuncInfo struct
Shrinks LSym somewhat for non-STEXT LSyms, which are much more common. While here, switch to tracking Automs in a slice instead of a linked list. (Previously, this would have made LSyms larger.) Passes toolstash-check. Change-Id: I082e50e1d1f1b544c9e06b6e412a186be6a4a2b5 Reviewed-on: https://go-review.googlesource.com/37872 Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
This commit is contained in:
parent
7a98bdf1c2
commit
9cb2ee0ff2
6 changed files with 44 additions and 36 deletions
|
|
@ -436,6 +436,10 @@ func gendebug(fnsym *obj.LSym, decls []*Node) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if fnsym.FuncInfo == nil {
|
||||||
|
fnsym.FuncInfo = new(obj.FuncInfo)
|
||||||
|
}
|
||||||
|
|
||||||
for _, n := range decls {
|
for _, n := range decls {
|
||||||
if n.Op != ONAME { // might be OTYPE or OLITERAL
|
if n.Op != ONAME { // might be OTYPE or OLITERAL
|
||||||
continue
|
continue
|
||||||
|
|
@ -461,8 +465,13 @@ func gendebug(fnsym *obj.LSym, decls []*Node) {
|
||||||
Gotype: Linksym(ngotype(n)),
|
Gotype: Linksym(ngotype(n)),
|
||||||
}
|
}
|
||||||
|
|
||||||
a.Link = fnsym.Autom
|
fnsym.Autom = append(fnsym.Autom, a)
|
||||||
fnsym.Autom = a
|
}
|
||||||
|
|
||||||
|
// Reverse to make toolstash happy.
|
||||||
|
// TODO(mdempsky): Remove.
|
||||||
|
for i, j := 0, len(fnsym.Autom)-1; i < j; i, j = i+1, j-1 {
|
||||||
|
fnsym.Autom[i], fnsym.Autom[j] = fnsym.Autom[j], fnsym.Autom[i]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -326,15 +326,22 @@ type LSym struct {
|
||||||
Attribute
|
Attribute
|
||||||
|
|
||||||
RefIdx int // Index of this symbol in the symbol reference list.
|
RefIdx int // Index of this symbol in the symbol reference list.
|
||||||
Args int32
|
|
||||||
Locals int32
|
|
||||||
Size int64
|
Size int64
|
||||||
Gotype *LSym
|
Gotype *LSym
|
||||||
Autom *Auto
|
|
||||||
Text *Prog
|
|
||||||
Pcln *Pcln
|
|
||||||
P []byte
|
P []byte
|
||||||
R []Reloc
|
R []Reloc
|
||||||
|
|
||||||
|
// TODO(mdempsky): De-anonymize field.
|
||||||
|
*FuncInfo
|
||||||
|
}
|
||||||
|
|
||||||
|
// A FuncInfo contains extra fields for STEXT symbols.
|
||||||
|
type FuncInfo struct {
|
||||||
|
Args int32
|
||||||
|
Locals int32
|
||||||
|
Text *Prog
|
||||||
|
Autom []*Auto
|
||||||
|
Pcln Pcln
|
||||||
}
|
}
|
||||||
|
|
||||||
// Attribute is a set of symbol attributes.
|
// Attribute is a set of symbol attributes.
|
||||||
|
|
@ -691,7 +698,6 @@ func (r RelocType) IsDirectJump() bool {
|
||||||
|
|
||||||
type Auto struct {
|
type Auto struct {
|
||||||
Asym *LSym
|
Asym *LSym
|
||||||
Link *Auto
|
|
||||||
Aoffset int32
|
Aoffset int32
|
||||||
Name AddrName
|
Name AddrName
|
||||||
Gotype *LSym
|
Gotype *LSym
|
||||||
|
|
|
||||||
|
|
@ -153,7 +153,7 @@ func (w *objWriter) addLengths(s *LSym) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
pc := s.Pcln
|
pc := &s.Pcln
|
||||||
|
|
||||||
data := 0
|
data := 0
|
||||||
data += len(pc.Pcsp.P)
|
data += len(pc.Pcsp.P)
|
||||||
|
|
@ -167,11 +167,7 @@ func (w *objWriter) addLengths(s *LSym) {
|
||||||
w.nData += data
|
w.nData += data
|
||||||
w.nPcdata += len(pc.Pcdata)
|
w.nPcdata += len(pc.Pcdata)
|
||||||
|
|
||||||
autom := 0
|
w.nAutom += len(s.Autom)
|
||||||
for a := s.Autom; a != nil; a = a.Link {
|
|
||||||
autom++
|
|
||||||
}
|
|
||||||
w.nAutom += autom
|
|
||||||
w.nFuncdata += len(pc.Funcdataoff)
|
w.nFuncdata += len(pc.Funcdataoff)
|
||||||
w.nFile += len(pc.File)
|
w.nFile += len(pc.File)
|
||||||
}
|
}
|
||||||
|
|
@ -227,7 +223,7 @@ func WriteObjFile(ctxt *Link, b *bufio.Writer) {
|
||||||
// Data block
|
// Data block
|
||||||
for _, s := range ctxt.Text {
|
for _, s := range ctxt.Text {
|
||||||
w.wr.Write(s.P)
|
w.wr.Write(s.P)
|
||||||
pc := s.Pcln
|
pc := &s.Pcln
|
||||||
w.wr.Write(pc.Pcsp.P)
|
w.wr.Write(pc.Pcsp.P)
|
||||||
w.wr.Write(pc.Pcfile.P)
|
w.wr.Write(pc.Pcfile.P)
|
||||||
w.wr.Write(pc.Pcline.P)
|
w.wr.Write(pc.Pcline.P)
|
||||||
|
|
@ -294,11 +290,11 @@ func (w *objWriter) writeRefs(s *LSym) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.Type == STEXT {
|
if s.Type == STEXT {
|
||||||
for a := s.Autom; a != nil; a = a.Link {
|
for _, a := range s.Autom {
|
||||||
w.writeRef(a.Asym, false)
|
w.writeRef(a.Asym, false)
|
||||||
w.writeRef(a.Gotype, false)
|
w.writeRef(a.Gotype, false)
|
||||||
}
|
}
|
||||||
pc := s.Pcln
|
pc := &s.Pcln
|
||||||
for _, d := range pc.Funcdata {
|
for _, d := range pc.Funcdata {
|
||||||
w.writeRef(d, false)
|
w.writeRef(d, false)
|
||||||
}
|
}
|
||||||
|
|
@ -338,15 +334,15 @@ func (w *objWriter) writeSymDebug(s *LSym) {
|
||||||
fmt.Fprintf(ctxt.Bso, " leaf")
|
fmt.Fprintf(ctxt.Bso, " leaf")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Fprintf(ctxt.Bso, "\n")
|
fmt.Fprintf(ctxt.Bso, "\n")
|
||||||
|
if s.Type == STEXT {
|
||||||
for p := s.Text; p != nil; p = p.Link {
|
for p := s.Text; p != nil; p = p.Link {
|
||||||
fmt.Fprintf(ctxt.Bso, "\t%#04x %v\n", uint(int(p.Pc)), p)
|
fmt.Fprintf(ctxt.Bso, "\t%#04x %v\n", uint(int(p.Pc)), p)
|
||||||
}
|
}
|
||||||
var c int
|
}
|
||||||
var j int
|
for i := 0; i < len(s.P); i += 16 {
|
||||||
for i := 0; i < len(s.P); {
|
|
||||||
fmt.Fprintf(ctxt.Bso, "\t%#04x", uint(i))
|
fmt.Fprintf(ctxt.Bso, "\t%#04x", uint(i))
|
||||||
|
j := i
|
||||||
for j = i; j < i+16 && j < len(s.P); j++ {
|
for j = i; j < i+16 && j < len(s.P); j++ {
|
||||||
fmt.Fprintf(ctxt.Bso, " %02x", s.P[j])
|
fmt.Fprintf(ctxt.Bso, " %02x", s.P[j])
|
||||||
}
|
}
|
||||||
|
|
@ -355,7 +351,7 @@ func (w *objWriter) writeSymDebug(s *LSym) {
|
||||||
}
|
}
|
||||||
fmt.Fprintf(ctxt.Bso, " ")
|
fmt.Fprintf(ctxt.Bso, " ")
|
||||||
for j = i; j < i+16 && j < len(s.P); j++ {
|
for j = i; j < i+16 && j < len(s.P); j++ {
|
||||||
c = int(s.P[j])
|
c := int(s.P[j])
|
||||||
if ' ' <= c && c <= 0x7e {
|
if ' ' <= c && c <= 0x7e {
|
||||||
fmt.Fprintf(ctxt.Bso, "%c", c)
|
fmt.Fprintf(ctxt.Bso, "%c", c)
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -364,7 +360,6 @@ func (w *objWriter) writeSymDebug(s *LSym) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Fprintf(ctxt.Bso, "\n")
|
fmt.Fprintf(ctxt.Bso, "\n")
|
||||||
i += 16
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sort.Sort(relocByOff(s.R)) // generate stable output
|
sort.Sort(relocByOff(s.R)) // generate stable output
|
||||||
|
|
@ -440,12 +435,8 @@ func (w *objWriter) writeSym(s *LSym) {
|
||||||
flags |= 1 << 2
|
flags |= 1 << 2
|
||||||
}
|
}
|
||||||
w.writeInt(flags)
|
w.writeInt(flags)
|
||||||
n := 0
|
w.writeInt(int64(len(s.Autom)))
|
||||||
for a := s.Autom; a != nil; a = a.Link {
|
for _, a := range s.Autom {
|
||||||
n++
|
|
||||||
}
|
|
||||||
w.writeInt(int64(n))
|
|
||||||
for a := s.Autom; a != nil; a = a.Link {
|
|
||||||
w.writeRefIndex(a.Asym)
|
w.writeRefIndex(a.Asym)
|
||||||
w.writeInt(int64(a.Aoffset))
|
w.writeInt(int64(a.Aoffset))
|
||||||
if a.Name == NAME_AUTO {
|
if a.Name == NAME_AUTO {
|
||||||
|
|
@ -458,7 +449,7 @@ func (w *objWriter) writeSym(s *LSym) {
|
||||||
w.writeRefIndex(a.Gotype)
|
w.writeRefIndex(a.Gotype)
|
||||||
}
|
}
|
||||||
|
|
||||||
pc := s.Pcln
|
pc := &s.Pcln
|
||||||
w.writeInt(int64(len(pc.Pcsp.P)))
|
w.writeInt(int64(len(pc.Pcsp.P)))
|
||||||
w.writeInt(int64(len(pc.Pcfile.P)))
|
w.writeInt(int64(len(pc.Pcfile.P)))
|
||||||
w.writeInt(int64(len(pc.Pcline.P)))
|
w.writeInt(int64(len(pc.Pcline.P)))
|
||||||
|
|
@ -575,7 +566,7 @@ func gendwarf(ctxt *Link, text []*LSym) []*LSym {
|
||||||
var vars []*dwarf.Var
|
var vars []*dwarf.Var
|
||||||
var abbrev int
|
var abbrev int
|
||||||
var offs int32
|
var offs int32
|
||||||
for a := s.Autom; a != nil; a = a.Link {
|
for _, a := range s.Autom {
|
||||||
switch a.Name {
|
switch a.Name {
|
||||||
case NAME_AUTO:
|
case NAME_AUTO:
|
||||||
abbrev = dwarf.DW_ABRV_AUTO
|
abbrev = dwarf.DW_ABRV_AUTO
|
||||||
|
|
|
||||||
|
|
@ -254,8 +254,7 @@ func pctopcdata(ctxt *Link, sym *LSym, oldval int32, p *Prog, phase int32, arg i
|
||||||
func linkpcln(ctxt *Link, cursym *LSym) {
|
func linkpcln(ctxt *Link, cursym *LSym) {
|
||||||
ctxt.Cursym = cursym
|
ctxt.Cursym = cursym
|
||||||
|
|
||||||
pcln := new(Pcln)
|
pcln := &cursym.Pcln
|
||||||
cursym.Pcln = pcln
|
|
||||||
|
|
||||||
npcdata := 0
|
npcdata := 0
|
||||||
nfuncdata := 0
|
nfuncdata := 0
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,9 @@ func flushplist(ctxt *Link, plist *Plist, freeProgs bool) {
|
||||||
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if s.FuncInfo == nil {
|
||||||
|
s.FuncInfo = new(FuncInfo)
|
||||||
|
}
|
||||||
|
|
||||||
if s.Text != nil {
|
if s.Text != nil {
|
||||||
log.Fatalf("duplicate TEXT for %s", s.Name)
|
log.Fatalf("duplicate TEXT for %s", s.Name)
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ func TestSizeof(t *testing.T) {
|
||||||
_64bit uintptr // size on 64bit platforms
|
_64bit uintptr // size on 64bit platforms
|
||||||
}{
|
}{
|
||||||
{Addr{}, 40, 64},
|
{Addr{}, 40, 64},
|
||||||
{LSym{}, 76, 128},
|
{LSym{}, 60, 104},
|
||||||
{Prog{}, 148, 232},
|
{Prog{}, 148, 232},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue