]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: make Allsym a slice
authorDavid Crawshaw <crawshaw@golang.org>
Wed, 2 Mar 2016 20:59:38 +0000 (15:59 -0500)
committerDavid Crawshaw <crawshaw@golang.org>
Wed, 2 Mar 2016 23:28:17 +0000 (23:28 +0000)
Looks a tiny bit faster, which is a surprise. Probably noise.
Motivation is making the LSym structure a little easier to understand.

Linking juju, best of 10:

before: real 0m4.811s user 0m5.582s
after:  real 0m4.611s user 0m5.267s

Change-Id: Idbedaf4a6e6e199036a1bbb6760e98c94ed2c282
Reviewed-on: https://go-review.googlesource.com/20142
Reviewed-by: Michael Hudson-Doyle <michael.hudson@canonical.com>
Run-TryBot: David Crawshaw <crawshaw@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/cmd/link/internal/ld/ar.go
src/cmd/link/internal/ld/data.go
src/cmd/link/internal/ld/elf.go
src/cmd/link/internal/ld/go.go
src/cmd/link/internal/ld/lib.go
src/cmd/link/internal/ld/link.go
src/cmd/link/internal/ld/macho.go
src/cmd/link/internal/ld/pe.go
src/cmd/link/internal/ld/sym.go
src/cmd/link/internal/ld/symtab.go

index 321dd243b202f5158cc290bbf5b6a31c2b47dbe7..d07756071d9dea218ee61fbd238e752087e38aa0 100644 (file)
@@ -97,7 +97,7 @@ func hostArchive(name string) {
        any := true
        for any {
                var load []uint64
-               for s := Ctxt.Allsym; s != nil; s = s.Allsym {
+               for _, s := range Ctxt.Allsym {
                        for _, r := range s.R {
                                if r.Sym != nil && r.Sym.Type&obj.SMASK == obj.SXREF {
                                        if off := armap[r.Sym.Name]; off != 0 && !loaded[off] {
index d5e591a04530734edaa4c8968c087ee297835f11..d4abe7002216e99cabef0535653ff7eb1b0b3643 100644 (file)
@@ -1006,7 +1006,7 @@ func addinitarrdata(s *LSym) {
 }
 
 func dosymtype() {
-       for s := Ctxt.Allsym; s != nil; s = s.Allsym {
+       for _, s := range Ctxt.Allsym {
                if len(s.P) > 0 {
                        if s.Type == obj.SBSS {
                                s.Type = obj.SDATA
@@ -1145,7 +1145,7 @@ func dodata() {
        var last *LSym
        datap = nil
 
-       for s := Ctxt.Allsym; s != nil; s = s.Allsym {
+       for _, s := range Ctxt.Allsym {
                if !s.Reachable || s.Special != 0 {
                        continue
                }
index 6d34978d5a0c0b9a790a5a3df3266ed977f44b42..8dd4df395740ca21a8a51b04d6c5b3e53141a0a8 100644 (file)
@@ -1361,9 +1361,7 @@ func elfdynhash() {
        buckets := make([]uint32, nbucket)
 
        var b int
-       var hc uint32
-       var name string
-       for sy := Ctxt.Allsym; sy != nil; sy = sy.Allsym {
+       for _, sy := range Ctxt.Allsym {
                if sy.Dynid <= 0 {
                        continue
                }
@@ -1372,8 +1370,8 @@ func elfdynhash() {
                        need[sy.Dynid] = addelflib(&needlib, sy.Dynimplib, sy.Dynimpvers)
                }
 
-               name = sy.Extname
-               hc = elfhash([]byte(name))
+               name := sy.Extname
+               hc := elfhash([]byte(name))
 
                b = int(hc % uint32(nbucket))
                chain[sy.Dynid] = buckets[b]
index b261c4e73a35c4be6925cd70e13b29efed0a3042..98e99bcd2986eee28b98b9c50dbe02c3a7de005f 100644 (file)
@@ -449,7 +449,7 @@ func deadcode() {
        if Buildmode == BuildmodeShared {
                // Mark all symbols defined in this library as reachable when
                // building a shared library.
-               for s := Ctxt.Allsym; s != nil; s = s.Allsym {
+               for _, s := range Ctxt.Allsym {
                        if s.Type != 0 && s.Type != obj.SDYNIMPORT {
                                mark(s)
                        }
@@ -471,7 +471,7 @@ func deadcode() {
                markflood()
 
                // keep each beginning with 'typelink.' if the symbol it points at is being kept.
-               for s := Ctxt.Allsym; s != nil; s = s.Allsym {
+               for _, s := range Ctxt.Allsym {
                        if strings.HasPrefix(s.Name, "go.typelink.") {
                                s.Reachable = len(s.R) == 1 && s.R[0].Sym.Reachable
                        }
@@ -503,7 +503,7 @@ func deadcode() {
                }
        }
 
-       for s := Ctxt.Allsym; s != nil; s = s.Allsym {
+       for _, s := range Ctxt.Allsym {
                if strings.HasPrefix(s.Name, "go.weak.") {
                        s.Special = 1 // do not lay out in data segment
                        s.Reachable = true
@@ -513,14 +513,13 @@ func deadcode() {
 
        // record field tracking references
        var buf bytes.Buffer
-       var p *LSym
-       for s := Ctxt.Allsym; s != nil; s = s.Allsym {
+       for _, s := range Ctxt.Allsym {
                if strings.HasPrefix(s.Name, "go.track.") {
                        s.Special = 1 // do not lay out in data segment
                        s.Hidden = true
                        if s.Reachable {
                                buf.WriteString(s.Name[9:])
-                               for p = s.Reachparent; p != nil; p = p.Reachparent {
+                               for p := s.Reachparent; p != nil; p = p.Reachparent {
                                        buf.WriteString("\t")
                                        buf.WriteString(p.Name)
                                }
@@ -543,13 +542,11 @@ func deadcode() {
 }
 
 func doweak() {
-       var t *LSym
-
        // resolve weak references only if
        // target symbol will be in binary anyway.
-       for s := Ctxt.Allsym; s != nil; s = s.Allsym {
+       for _, s := range Ctxt.Allsym {
                if strings.HasPrefix(s.Name, "go.weak.") {
-                       t = Linkrlookup(Ctxt, s.Name[8:], int(s.Version))
+                       t := Linkrlookup(Ctxt, s.Name[8:], int(s.Version))
                        if t != nil && t.Type != 0 && t.Reachable {
                                s.Value = t.Value
                                s.Type = t.Type
index d14106887bba7c6b48851f547d23510c59e236e3..93467dbfc98d1cc50fa32691a03929ce57fd0a98 100644 (file)
@@ -599,7 +599,7 @@ func loadlib() {
        if Linkmode == LinkInternal {
                // Drop all the cgo_import_static declarations.
                // Turns out we won't be needing them.
-               for s := Ctxt.Allsym; s != nil; s = s.Allsym {
+               for _, s := range Ctxt.Allsym {
                        if s.Type == obj.SHOSTOBJ {
                                // If a symbol was marked both
                                // cgo_import_static and cgo_import_dynamic,
@@ -679,7 +679,7 @@ func loadlib() {
                // If we have any undefined symbols in external
                // objects, try to read them from the libgcc file.
                any := false
-               for s := Ctxt.Allsym; s != nil; s = s.Allsym {
+               for _, s := range Ctxt.Allsym {
                        for _, r := range s.R {
                                if r.Sym != nil && r.Sym.Type&obj.SMASK == obj.SXREF && r.Sym.Name != ".got" {
                                        any = true
@@ -1904,7 +1904,7 @@ func genasmsym(put func(*LSym, string, int, int64, int64, int, *LSym)) {
                put(s, s.Name, 'T', s.Value, s.Size, int(s.Version), nil)
        }
 
-       for s := Ctxt.Allsym; s != nil; s = s.Allsym {
+       for _, s := range Ctxt.Allsym {
                if s.Hidden || ((s.Name == "" || s.Name[0] == '.') && s.Version == 0 && s.Name != ".rathole" && s.Name != ".TOC.") {
                        continue
                }
index beb142e44f6b76edf6441a397e70fd9e4c5b9487..4b63a80f1f811b6c9c16a870dfb8fda6558a8ffd 100644 (file)
@@ -67,7 +67,6 @@ type LSym struct {
        Locals      int32
        Value       int64
        Size        int64
-       Allsym      *LSym
        Next        *LSym
        Sub         *LSym
        Outer       *LSym
@@ -142,7 +141,7 @@ type Link struct {
        Windows    int32
        Goroot     string
        Hash       map[symVer]*LSym
-       Allsym     *LSym
+       Allsym     []*LSym
        Nsymbol    int32
        Tlsg       *LSym
        Libdir     []string
index d88a414dbf135a47a38f97a6f95d247d155b165b..8add7db8c16fade993ff621fc0dc2c90a683d543 100644 (file)
@@ -652,7 +652,7 @@ func (x machoscmp) Less(i, j int) bool {
 
 func machogenasmsym(put func(*LSym, string, int, int64, int64, int, *LSym)) {
        genasmsym(put)
-       for s := Ctxt.Allsym; s != nil; s = s.Allsym {
+       for _, s := range Ctxt.Allsym {
                if s.Type == obj.SDYNIMPORT || s.Type == obj.SHOSTOBJ {
                        if s.Reachable {
                                put(s, "", 'D', 0, 0, 0, nil)
index 00fbb170b60533a94c7ce0329dbbcd298b0402dd..407cba4e52fc08e28e35e3d4ed488e25737c30f7 100644 (file)
@@ -487,7 +487,7 @@ func initdynimport() *Dll {
 
        dr = nil
        var m *Imp
-       for s := Ctxt.Allsym; s != nil; s = s.Allsym {
+       for _, s := range Ctxt.Allsym {
                if !s.Reachable || s.Type != obj.SDYNIMPORT {
                        continue
                }
@@ -692,7 +692,7 @@ func (s byExtname) Less(i, j int) bool { return s[i].Extname < s[j].Extname }
 
 func initdynexport() {
        nexport = 0
-       for s := Ctxt.Allsym; s != nil; s = s.Allsym {
+       for _, s := range Ctxt.Allsym {
                if !s.Reachable || s.Cgoexport&CgoExportDynamic == 0 {
                        continue
                }
index 5f31e59e09d19f3214dd6a4a746d4e5cc7eadd14..6df4839468d63c6478012927313a142a043db4d6 100644 (file)
@@ -57,12 +57,13 @@ var headers = []struct {
 }
 
 func linknew(arch *LinkArch) *Link {
-       ctxt := new(Link)
-       // Preallocate about 2mb for hash
-       ctxt.Hash = make(map[symVer]*LSym, 100000)
-       ctxt.Arch = arch
-       ctxt.Version = obj.HistVersion
-       ctxt.Goroot = obj.Getgoroot()
+       ctxt := &Link{
+               Hash:    make(map[symVer]*LSym, 100000), // preallocate about 2mb for hash
+               Allsym:  make([]*LSym, 0, 100000),
+               Arch:    arch,
+               Version: obj.HistVersion,
+               Goroot:  obj.Getgoroot(),
+       }
 
        p := obj.Getgoarch()
        if p != arch.Name {
@@ -168,15 +169,10 @@ func linknewsym(ctxt *Link, symb string, v int) *LSym {
        s.Plt = -1
        s.Got = -1
        s.Name = symb
-       s.Type = 0
        s.Version = int16(v)
-       s.Value = 0
-       s.Size = 0
        ctxt.Nsymbol++
 
-       s.Allsym = ctxt.Allsym
-       ctxt.Allsym = s
-
+       ctxt.Allsym = append(ctxt.Allsym, s)
        return s
 }
 
index af22322c4f225dc68ca93ef648ecd5bebe14de0a..17e1aff2ab268528b11511df7cffdd4e7b900134 100644 (file)
@@ -461,7 +461,7 @@ func symtab() {
        // within a type they sort by size, so the .* symbols
        // just defined above will be first.
        // hide the specific symbols.
-       for s := Ctxt.Allsym; s != nil; s = s.Allsym {
+       for _, s := range Ctxt.Allsym {
                if !s.Reachable || s.Special != 0 || s.Type != obj.SRODATA {
                        continue
                }