]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: patch up symbols only once per object file
authorShahar Kohanim <skohanim@gmail.com>
Sun, 20 Mar 2016 15:22:57 +0000 (17:22 +0200)
committerDavid Crawshaw <crawshaw@golang.org>
Sun, 20 Mar 2016 17:36:30 +0000 (17:36 +0000)
name       old s/op   new s/op   delta
LinkCmdGo  0.57 ± 5%  0.55 ± 6%  -2.37%  (p=0.000 n=97+98)

GOGC=off:

name       old s/op   new s/op   delta
LinkCmdGo  0.48 ± 3%  0.47 ± 3%  -2.90%  (p=0.000 n=100+100)

Change-Id: I1a36dbf84914cacb79842bc0ddb1e26b4c5a5828
Reviewed-on: https://go-review.googlesource.com/20917
Reviewed-by: David Crawshaw <crawshaw@golang.org>
Run-TryBot: David Crawshaw <crawshaw@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/cmd/link/internal/ld/objfile.go

index ef773b87bab8b3d05581bac48e5e1e3c6a817e6b..b842fe15d0ced2ae296d0ed042e4c2ba226dc101 100644 (file)
@@ -386,8 +386,35 @@ func readref(ctxt *Link, f *obj.Biobuf, pkg string, pn string) {
        if v == 1 {
                v = ctxt.Version
        }
-       lsym := Linklookup(ctxt, name, v)
-       ctxt.CurRefs = append(ctxt.CurRefs, lsym)
+       s := Linklookup(ctxt, name, v)
+       ctxt.CurRefs = append(ctxt.CurRefs, s)
+
+       if s == nil || v != 0 {
+               return
+       }
+       if s.Name[0] == '$' && len(s.Name) > 5 && s.Type == 0 && len(s.P) == 0 {
+               x, err := strconv.ParseUint(s.Name[5:], 16, 64)
+               if err != nil {
+                       log.Panicf("failed to parse $-symbol %s: %v", s.Name, err)
+               }
+               s.Type = obj.SRODATA
+               s.Attr |= AttrLocal
+               switch s.Name[:5] {
+               case "$f32.":
+                       if uint64(uint32(x)) != x {
+                               log.Panicf("$-symbol %s too large: %d", s.Name, x)
+                       }
+                       Adduint32(ctxt, s, uint32(x))
+               case "$f64.", "$i64.":
+                       Adduint64(ctxt, s, x)
+               default:
+                       log.Panicf("unrecognized $-symbol: %s", s.Name)
+               }
+               s.Attr.Set(AttrReachable, false)
+       }
+       if strings.HasPrefix(s.Name, "runtime.gcbits.") {
+               s.Attr |= AttrLocal
+       }
 }
 
 func rdint64(f *obj.Biobuf) int64 {
@@ -509,37 +536,5 @@ func rdsymName(f *obj.Biobuf, pkg string) string {
 
 func rdsym(ctxt *Link, f *obj.Biobuf, pkg string) *LSym {
        i := rdint(f)
-       if i == 0 {
-               return nil
-       }
-
-       s := ctxt.CurRefs[i]
-       if s == nil || s.Version != 0 {
-               return s
-       }
-
-       if s.Name[0] == '$' && len(s.Name) > 5 && s.Type == 0 {
-               x, err := strconv.ParseUint(s.Name[5:], 16, 64)
-               if err != nil {
-                       log.Panicf("failed to parse $-symbol %s: %v", s.Name, err)
-               }
-               s.Type = obj.SRODATA
-               s.Attr |= AttrLocal
-               switch s.Name[:5] {
-               case "$f32.":
-                       if uint64(uint32(x)) != x {
-                               log.Panicf("$-symbol %s too large: %d", s.Name, x)
-                       }
-                       Adduint32(ctxt, s, uint32(x))
-               case "$f64.", "$i64.":
-                       Adduint64(ctxt, s, x)
-               default:
-                       log.Panicf("unrecognized $-symbol: %s", s.Name)
-               }
-               s.Attr.Set(AttrReachable, false)
-       }
-       if strings.HasPrefix(s.Name, "runtime.gcbits.") {
-               s.Attr |= AttrLocal
-       }
-       return s
+       return ctxt.CurRefs[i]
 }