Commit ed41054b authored by David Crawshaw's avatar David Crawshaw

cmd/link: process data symbols with slices

First (and largest single) step to switching cmd/link from linked
lists of symbols to slices.

Sort sections independently and concurrently.
This reduces jujud link times on linux/amd64 by ~4%.

Updates #15374

Change-Id: I452bc8f33081039468636502fe3c1cc8d6ed9efa
Reviewed-on: https://go-review.googlesource.com/22205Reviewed-by: default avatarMichael Hudson-Doyle <michael.hudson@canonical.com>
parent cda0aa16
This diff is collapsed.
......@@ -1670,7 +1670,7 @@ func elfshreloc(sect *Section) *ElfShdr {
return sh
}
func elfrelocsect(sect *Section, first *LSym) {
func elfrelocsect(sect *Section, syms []*LSym) {
// If main section is SHT_NOBITS, nothing to relocate.
// Also nothing to relocate in .shstrtab.
if sect.Vaddr >= sect.Seg.Vaddr+sect.Seg.Filelen {
......@@ -1681,18 +1681,18 @@ func elfrelocsect(sect *Section, first *LSym) {
}
sect.Reloff = uint64(Cpos())
var sym *LSym
for sym = first; sym != nil; sym = sym.Next {
if !sym.Attr.Reachable() {
for i, s := range syms {
if !s.Attr.Reachable() {
continue
}
if uint64(sym.Value) >= sect.Vaddr {
if uint64(s.Value) >= sect.Vaddr {
syms = syms[i:]
break
}
}
eaddr := int32(sect.Vaddr + sect.Length)
for ; sym != nil; sym = sym.Next {
for _, sym := range syms {
if !sym.Attr.Reachable() {
continue
}
......@@ -1710,7 +1710,6 @@ func elfrelocsect(sect *Section, first *LSym) {
Diag("missing xsym in relocation")
continue
}
if r.Xsym.ElfsymForReloc() == 0 {
Diag("reloc %d to non-elf symbol %s (outer=%s) %d", r.Type, r.Sym.Name, r.Xsym.Name, r.Sym.Type)
}
......@@ -1728,7 +1727,7 @@ func Elfemitreloc() {
Cput(0)
}
elfrelocsect(Segtext.Sect, Ctxt.Textp)
elfrelocsect(Segtext.Sect, list2slice(Ctxt.Textp))
for sect := Segtext.Sect.Next; sect != nil; sect = sect.Next {
elfrelocsect(sect, datap)
}
......@@ -1739,7 +1738,7 @@ func Elfemitreloc() {
elfrelocsect(sect, datap)
}
for sect := Segdwarf.Sect; sect != nil; sect = sect.Next {
elfrelocsect(sect, dwarfp)
elfrelocsect(sect, list2slice(dwarfp))
}
}
......
......@@ -130,7 +130,6 @@ func (r *Rpath) String() string {
var (
Thearch Arch
datap *LSym
Debug [128]int
Lcsize int32
rpath Rpath
......@@ -2109,7 +2108,7 @@ func undef() {
for s := Ctxt.Textp; s != nil; s = s.Next {
undefsym(s)
}
for s := datap; s != nil; s = s.Next {
for _, s := range datap {
undefsym(s)
}
if nerrors > 0 {
......
......@@ -806,25 +806,25 @@ func Domacholink() int64 {
return Rnd(int64(size), int64(INITRND))
}
func machorelocsect(sect *Section, first *LSym) {
func machorelocsect(sect *Section, syms []*LSym) {
// If main section has no bits, nothing to relocate.
if sect.Vaddr >= sect.Seg.Vaddr+sect.Seg.Filelen {
return
}
sect.Reloff = uint64(Cpos())
var sym *LSym
for sym = first; sym != nil; sym = sym.Next {
if !sym.Attr.Reachable() {
for i, s := range syms {
if !s.Attr.Reachable() {
continue
}
if uint64(sym.Value) >= sect.Vaddr {
if uint64(s.Value) >= sect.Vaddr {
syms = syms[i:]
break
}
}
eaddr := int32(sect.Vaddr + sect.Length)
for ; sym != nil; sym = sym.Next {
for _, sym := range syms {
if !sym.Attr.Reachable() {
continue
}
......@@ -852,7 +852,7 @@ func Machoemitreloc() {
Cput(0)
}
machorelocsect(Segtext.Sect, Ctxt.Textp)
machorelocsect(Segtext.Sect, list2slice(Ctxt.Textp))
for sect := Segtext.Sect.Next; sect != nil; sect = sect.Next {
machorelocsect(sect, datap)
}
......@@ -860,6 +860,6 @@ func Machoemitreloc() {
machorelocsect(sect, datap)
}
for sect := Segdwarf.Sect; sect != nil; sect = sect.Next {
machorelocsect(sect, dwarfp)
machorelocsect(sect, list2slice(dwarfp))
}
}
......@@ -764,7 +764,7 @@ func addexports() {
// perelocsect relocates symbols from first in section sect, and returns
// the total number of relocations emitted.
func perelocsect(sect *Section, first *LSym) int {
func perelocsect(sect *Section, syms []*LSym) int {
// If main section has no bits, nothing to relocate.
if sect.Vaddr >= sect.Seg.Vaddr+sect.Seg.Filelen {
return 0
......@@ -773,18 +773,18 @@ func perelocsect(sect *Section, first *LSym) int {
relocs := 0
sect.Reloff = uint64(Cpos())
var sym *LSym
for sym = first; sym != nil; sym = sym.Next {
if !sym.Attr.Reachable() {
for i, s := range syms {
if !s.Attr.Reachable() {
continue
}
if uint64(sym.Value) >= sect.Vaddr {
if uint64(s.Value) >= sect.Vaddr {
syms = syms[i:]
break
}
}
eaddr := int32(sect.Vaddr + sect.Length)
for ; sym != nil; sym = sym.Next {
for _, sym := range syms {
if !sym.Attr.Reachable() {
continue
}
......@@ -831,7 +831,7 @@ func peemitreloc(text, data, ctors *IMAGE_SECTION_HEADER) {
Lputl(0)
Wputl(0)
n := perelocsect(Segtext.Sect, Ctxt.Textp) + 1
n := perelocsect(Segtext.Sect, list2slice(Ctxt.Textp)) + 1
for sect := Segtext.Sect.Next; sect != nil; sect = sect.Next {
n += perelocsect(sect, datap)
}
......
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