Commit 85072d5f authored by Michael Hudson-Doyle's avatar Michael Hudson-Doyle

cmd/link: remove Symbol.Next

Bye bye one more class of linked list manipulation!

Change-Id: I2412b224c847dd640f9253125d30cd5f911ce00c
Reviewed-on: https://go-review.googlesource.com/27414
Run-TryBot: Michael Hudson-Doyle <michael.hudson@canonical.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarMichael Matloob <matloob@golang.org>
parent 64f5023e
...@@ -663,7 +663,7 @@ func (ctxt *Link) reloc() { ...@@ -663,7 +663,7 @@ func (ctxt *Link) reloc() {
for _, sym := range datap { for _, sym := range datap {
relocsym(ctxt, sym) relocsym(ctxt, sym)
} }
for s := dwarfp; s != nil; s = s.Next { for _, s := range dwarfp {
relocsym(ctxt, s) relocsym(ctxt, s)
} }
} }
...@@ -746,55 +746,6 @@ func dynreloc(ctxt *Link, data *[obj.SXREF][]*Symbol) { ...@@ -746,55 +746,6 @@ func dynreloc(ctxt *Link, data *[obj.SXREF][]*Symbol) {
} }
} }
func blk(ctxt *Link, start *Symbol, addr int64, size int64) {
var sym *Symbol
for sym = start; sym != nil; sym = sym.Next {
if sym.Type&obj.SSUB == 0 && sym.Value >= addr {
break
}
}
eaddr := addr + size
for ; sym != nil; sym = sym.Next {
if sym.Type&obj.SSUB != 0 {
continue
}
if sym.Value >= eaddr {
break
}
ctxt.Cursym = sym
if sym.Value < addr {
ctxt.Diag("phase error: addr=%#x but sym=%#x type=%d", addr, sym.Value, sym.Type)
errorexit()
}
if addr < sym.Value {
strnput("", int(sym.Value-addr))
addr = sym.Value
}
Cwrite(sym.P)
addr += int64(len(sym.P))
if addr < sym.Value+sym.Size {
strnput("", int(sym.Value+sym.Size-addr))
addr = sym.Value + sym.Size
}
if addr != sym.Value+sym.Size {
ctxt.Diag("phase error: addr=%#x value+size=%#x", addr, sym.Value+sym.Size)
errorexit()
}
if sym.Value+sym.Size >= eaddr {
break
}
}
if addr < eaddr {
strnput("", int(eaddr-addr))
}
Cflush()
}
func Codeblk(ctxt *Link, addr int64, size int64) { func Codeblk(ctxt *Link, addr int64, size int64) {
CodeblkPad(ctxt, addr, size, zeros[:]) CodeblkPad(ctxt, addr, size, zeros[:])
} }
...@@ -803,7 +754,7 @@ func CodeblkPad(ctxt *Link, addr int64, size int64, pad []byte) { ...@@ -803,7 +754,7 @@ func CodeblkPad(ctxt *Link, addr int64, size int64, pad []byte) {
fmt.Fprintf(ctxt.Bso, "codeblk [%#x,%#x) at offset %#x\n", addr, addr+size, Cpos()) fmt.Fprintf(ctxt.Bso, "codeblk [%#x,%#x) at offset %#x\n", addr, addr+size, Cpos())
} }
blkSlice(ctxt, ctxt.Textp, addr, size, pad) blk(ctxt, ctxt.Textp, addr, size, pad)
/* again for printing */ /* again for printing */
if Debug['a'] == 0 { if Debug['a'] == 0 {
...@@ -864,10 +815,7 @@ func CodeblkPad(ctxt *Link, addr int64, size int64, pad []byte) { ...@@ -864,10 +815,7 @@ func CodeblkPad(ctxt *Link, addr int64, size int64, pad []byte) {
ctxt.Bso.Flush() ctxt.Bso.Flush()
} }
// blkSlice is a variant of blk that processes slices. func blk(ctxt *Link, syms []*Symbol, addr, size int64, pad []byte) {
// After text symbols are converted from a linked list to a slice,
// delete blk and give this function its name.
func blkSlice(ctxt *Link, syms []*Symbol, addr, size int64, pad []byte) {
for i, s := range syms { for i, s := range syms {
if s.Type&obj.SSUB == 0 && s.Value >= addr { if s.Type&obj.SSUB == 0 && s.Value >= addr {
syms = syms[i:] syms = syms[i:]
...@@ -918,7 +866,7 @@ func Datblk(ctxt *Link, addr int64, size int64) { ...@@ -918,7 +866,7 @@ func Datblk(ctxt *Link, addr int64, size int64) {
fmt.Fprintf(ctxt.Bso, "datblk [%#x,%#x) at offset %#x\n", addr, addr+size, Cpos()) fmt.Fprintf(ctxt.Bso, "datblk [%#x,%#x) at offset %#x\n", addr, addr+size, Cpos())
} }
blkSlice(ctxt, datap, addr, size, zeros[:]) blk(ctxt, datap, addr, size, zeros[:])
/* again for printing */ /* again for printing */
if Debug['a'] == 0 { if Debug['a'] == 0 {
...@@ -989,7 +937,7 @@ func Dwarfblk(ctxt *Link, addr int64, size int64) { ...@@ -989,7 +937,7 @@ func Dwarfblk(ctxt *Link, addr int64, size int64) {
fmt.Fprintf(ctxt.Bso, "dwarfblk [%#x,%#x) at offset %#x\n", addr, addr+size, Cpos()) fmt.Fprintf(ctxt.Bso, "dwarfblk [%#x,%#x) at offset %#x\n", addr, addr+size, Cpos())
} }
blk(ctxt, dwarfp, addr, size) blk(ctxt, dwarfp, addr, size, zeros[:])
} }
var zeros [512]byte var zeros [512]byte
...@@ -1241,14 +1189,6 @@ func checkdatsize(ctxt *Link, datsize int64, symn int) { ...@@ -1241,14 +1189,6 @@ func checkdatsize(ctxt *Link, datsize int64, symn int) {
} }
} }
func list2slice(s *Symbol) []*Symbol {
var syms []*Symbol
for ; s != nil; s = s.Next {
syms = append(syms, s)
}
return syms
}
// datap is a collection of reachable data symbols in address order. // datap is a collection of reachable data symbols in address order.
// Generated by dodata. // Generated by dodata.
var datap []*Symbol var datap []*Symbol
...@@ -1758,7 +1698,11 @@ func (ctxt *Link) dodata() { ...@@ -1758,7 +1698,11 @@ func (ctxt *Link) dodata() {
dwarfgeneratedebugsyms(ctxt) dwarfgeneratedebugsyms(ctxt)
var s *Symbol var s *Symbol
for s = dwarfp; s != nil && s.Type == obj.SDWARFSECT; s = s.Next { var i int
for i, s = range dwarfp {
if s.Type != obj.SDWARFSECT {
break
}
sect = addsection(&Segdwarf, s.Name, 04) sect = addsection(&Segdwarf, s.Name, 04)
sect.Align = 1 sect.Align = 1
datsize = Rnd(datsize, int64(sect.Align)) datsize = Rnd(datsize, int64(sect.Align))
...@@ -1771,12 +1715,15 @@ func (ctxt *Link) dodata() { ...@@ -1771,12 +1715,15 @@ func (ctxt *Link) dodata() {
} }
checkdatsize(ctxt, datsize, obj.SDWARFSECT) checkdatsize(ctxt, datsize, obj.SDWARFSECT)
if s != nil { if i < len(dwarfp) {
sect = addsection(&Segdwarf, ".debug_info", 04) sect = addsection(&Segdwarf, ".debug_info", 04)
sect.Align = 1 sect.Align = 1
datsize = Rnd(datsize, int64(sect.Align)) datsize = Rnd(datsize, int64(sect.Align))
sect.Vaddr = uint64(datsize) sect.Vaddr = uint64(datsize)
for ; s != nil && s.Type == obj.SDWARFINFO; s = s.Next { for _, s := range dwarfp[i:] {
if s.Type != obj.SDWARFINFO {
break
}
s.Sect = sect s.Sect = sect
s.Type = obj.SRODATA s.Type = obj.SRODATA
s.Value = int64(uint64(datsize) - sect.Vaddr) s.Value = int64(uint64(datsize) - sect.Vaddr)
...@@ -2095,7 +2042,7 @@ func (ctxt *Link) address() { ...@@ -2095,7 +2042,7 @@ func (ctxt *Link) address() {
} }
} }
for sym := dwarfp; sym != nil; sym = sym.Next { for _, sym := range dwarfp {
ctxt.Cursym = sym ctxt.Cursym = sym
if sym.Sect != nil { if sym.Sect != nil {
sym.Value += int64(sym.Sect.Vaddr) sym.Value += int64(sym.Sect.Vaddr)
......
...@@ -79,7 +79,7 @@ var linesec *Symbol ...@@ -79,7 +79,7 @@ var linesec *Symbol
var gdbscript string var gdbscript string
var dwarfp *Symbol var dwarfp []*Symbol
func writeabbrev(ctxt *Link, syms []*Symbol) []*Symbol { func writeabbrev(ctxt *Link, syms []*Symbol) []*Symbol {
s := Linklookup(ctxt, ".debug_abbrev", 0) s := Linklookup(ctxt, ".debug_abbrev", 0)
...@@ -1476,11 +1476,7 @@ func dwarfgeneratedebugsyms(ctxt *Link) { ...@@ -1476,11 +1476,7 @@ func dwarfgeneratedebugsyms(ctxt *Link) {
syms = writearanges(ctxt, syms) syms = writearanges(ctxt, syms)
syms = writegdbscript(ctxt, syms) syms = writegdbscript(ctxt, syms)
syms = append(syms, infosyms...) syms = append(syms, infosyms...)
dwarfp = syms[0] dwarfp = syms
for i := 1; i < len(syms); i++ {
syms[i-1].Next = syms[i]
}
syms[len(syms)-1].Next = nil
} }
/* /*
......
...@@ -1787,7 +1787,7 @@ func Elfemitreloc(ctxt *Link) { ...@@ -1787,7 +1787,7 @@ func Elfemitreloc(ctxt *Link) {
elfrelocsect(ctxt, sect, datap) elfrelocsect(ctxt, sect, datap)
} }
for sect := Segdwarf.Sect; sect != nil; sect = sect.Next { for sect := Segdwarf.Sect; sect != nil; sect = sect.Next {
elfrelocsect(ctxt, sect, list2slice(dwarfp)) elfrelocsect(ctxt, sect, dwarfp)
} }
} }
...@@ -2499,7 +2499,7 @@ elfobj: ...@@ -2499,7 +2499,7 @@ elfobj:
for sect := Segdata.Sect; sect != nil; sect = sect.Next { for sect := Segdata.Sect; sect != nil; sect = sect.Next {
elfshreloc(ctxt, sect) elfshreloc(ctxt, sect)
} }
for s := dwarfp; s != nil; s = s.Next { for _, s := range dwarfp {
if len(s.R) > 0 || s.Type == obj.SDWARFINFO { if len(s.R) > 0 || s.Type == obj.SDWARFINFO {
elfshreloc(ctxt, s.Sect) elfshreloc(ctxt, s.Sect)
} }
......
...@@ -57,7 +57,6 @@ type Symbol struct { ...@@ -57,7 +57,6 @@ type Symbol struct {
// is not set for symbols defined by the packages being linked or by symbols // is not set for symbols defined by the packages being linked or by symbols
// read by ldelf (and so is left as elf.STT_NOTYPE). // read by ldelf (and so is left as elf.STT_NOTYPE).
ElfType elf.SymType ElfType elf.SymType
Next *Symbol
Sub *Symbol Sub *Symbol
Outer *Symbol Outer *Symbol
Gotype *Symbol Gotype *Symbol
......
...@@ -863,6 +863,6 @@ func Machoemitreloc(ctxt *Link) { ...@@ -863,6 +863,6 @@ func Machoemitreloc(ctxt *Link) {
machorelocsect(ctxt, sect, datap) machorelocsect(ctxt, sect, datap)
} }
for sect := Segdwarf.Sect; sect != nil; sect = sect.Next { for sect := Segdwarf.Sect; sect != nil; sect = sect.Next {
machorelocsect(ctxt, sect, list2slice(dwarfp)) machorelocsect(ctxt, sect, dwarfp)
} }
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment