]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: re-use duplicate symbol object
authorMichael Hudson-Doyle <michael.hudson@canonical.com>
Mon, 21 Mar 2016 04:29:29 +0000 (17:29 +1300)
committerMichael Hudson-Doyle <michael.hudson@canonical.com>
Mon, 21 Mar 2016 07:48:30 +0000 (07:48 +0000)
Nothing cares about it.

I did this after looking at the memprof output, but it helps performance a bit:

name       old s/op    new s/op    delta
LinkCmdGo   0.44 ± 3%   0.43 ± 3%  -2.20%   (p=0.000 n=94+90)
LinkJuju    3.98 ± 5%   3.94 ± 5%  -1.19%  (p=0.000 n=100+91)

As well as MaxRSS (i.e. what /usr/bin/time -f '%M' prints):

name       old MaxRSS  new MaxRSS  delta
LinkCmdGo   130k ± 0%   120k ± 3%  -7.79%   (p=0.000 n=79+90)
LinkJuju    862k ± 6%   827k ± 8%  -4.01%  (p=0.000 n=100+99)

Change-Id: I6306b7b3369576a688659e2ecdb0815b4152ae96
Reviewed-on: https://go-review.googlesource.com/20972
Run-TryBot: Michael Hudson-Doyle <michael.hudson@canonical.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/cmd/link/internal/ld/objfile.go
src/cmd/link/internal/ld/sym.go

index a049fcfe4a24c5860ed33893424cd9da371308a1..6e5bf37b60de6b40cfc2a5c56ad24577c079a939 100644 (file)
@@ -175,6 +175,8 @@ func ldobjfile(ctxt *Link, f *obj.Biobuf, pkg string, length int64, pn string) {
        }
 }
 
+var dupSym = &LSym{Name: ".dup"}
+
 func readsym(ctxt *Link, f *obj.Biobuf, buf *[]byte, pkg string, pn string) {
        if obj.Bgetc(f) != 0xfe {
                log.Fatalf("readsym out of sync")
@@ -209,7 +211,7 @@ func readsym(ctxt *Link, f *obj.Biobuf, buf *[]byte, pkg string, pn string) {
                }
                if len(s.P) > 0 {
                        dup = s
-                       s = linknewsym(ctxt, ".dup", -1)
+                       s = dupSym
                }
        }
 
@@ -232,17 +234,15 @@ overwrite:
                s.Size = int64(size)
        }
        s.Attr.Set(AttrLocal, local)
-       if typ != nil { // if bss sym defined multiple times, take type from any one def
+       if typ != nil {
                s.Gotype = typ
        }
-       if dup != nil && typ != nil {
+       if dup != nil && typ != nil { // if bss sym defined multiple times, take type from any one def
                dup.Gotype = typ
        }
        s.P = data
-       s.P = s.P[:len(data)]
        if nreloc > 0 {
                s.R = make([]Reloc, nreloc)
-               s.R = s.R[:nreloc]
                var r *Reloc
                for i := 0; i < nreloc; i++ {
                        r = &s.R[i]
index e4fce6a5db6bc9b3dd064a2a91434a0730121ec8..86e0544f0d92d6932df80e3e302209ef0f4a7377 100644 (file)
@@ -172,12 +172,8 @@ func linknewsym(ctxt *Link, symb string, v int) *LSym {
        s.Name = symb
        s.Version = int16(v)
        ctxt.Nsymbol++
+       ctxt.Allsym = append(ctxt.Allsym, s)
 
-       if v != -1 {
-               ctxt.Allsym = append(ctxt.Allsym, s)
-       } else if v < -1 {
-               ctxt.Diag("invalid version %d in linknewsym", v)
-       }
        return s
 }