From 93098de0cc99dc5588477da9f5a9b09d3480677d Mon Sep 17 00:00:00 2001 From: Shahar Kohanim Date: Sun, 20 Mar 2016 17:22:57 +0200 Subject: [PATCH] cmd/link: patch up symbols only once per object file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Run-TryBot: David Crawshaw TryBot-Result: Gobot Gobot --- src/cmd/link/internal/ld/objfile.go | 65 +++++++++++++---------------- 1 file changed, 30 insertions(+), 35 deletions(-) diff --git a/src/cmd/link/internal/ld/objfile.go b/src/cmd/link/internal/ld/objfile.go index ef773b87bab..b842fe15d0c 100644 --- a/src/cmd/link/internal/ld/objfile.go +++ b/src/cmd/link/internal/ld/objfile.go @@ -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] }