]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: deduplicate symbol references
authorShahar Kohanim <skohanim@gmail.com>
Thu, 17 Mar 2016 11:18:34 +0000 (13:18 +0200)
committerIan Lance Taylor <iant@golang.org>
Thu, 17 Mar 2016 20:09:40 +0000 (20:09 +0000)
Reduces size of archives in pkg/linux_amd64 by 1.4MB (3.2%),
slightly improving link time.

name       old s/op   new s/op   delta
LinkCmdGo  0.52 ± 3%  0.51 ± 2%  -0.65%  (p=0.000 n=98+99)

Change-Id: I7e265f4d4dd08967c5c5d55c1045e533466bbbec
Reviewed-on: https://go-review.googlesource.com/20802
Run-TryBot: David Crawshaw <crawshaw@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/cmd/internal/obj/objfile.go

index f782644d883a1c828627bf9aa78bfcee4771a3b5..ee49517b684b633b8e3794c2cb3e20ccfbaa0039 100644 (file)
@@ -345,10 +345,31 @@ func Writeobjfile(ctxt *Link, b *Biobuf) {
        fmt.Fprintf(b, "go13ld")
 }
 
+// Provide the the index of a symbol reference by symbol name.
+// One map for versioned symbols and one for unversioned symbols.
+// Used for deduplicating the symbol reference list.
+var refIdx = make(map[string]int)
+var vrefIdx = make(map[string]int)
+
 func wrref(ctxt *Link, b *Biobuf, s *LSym, isPath bool) {
        if s == nil || s.RefIdx != 0 {
                return
        }
+       var m map[string]int
+       switch s.Version {
+       case 0:
+               m = refIdx
+       case 1:
+               m = vrefIdx
+       default:
+               log.Fatalf("%s: invalid version number %d", s.Name, s.Version)
+       }
+
+       idx := m[s.Name]
+       if idx != 0 {
+               s.RefIdx = idx
+               return
+       }
        Bputc(b, 0xfe)
        if isPath {
                wrstring(b, filepath.ToSlash(s.Name))
@@ -358,6 +379,7 @@ func wrref(ctxt *Link, b *Biobuf, s *LSym, isPath bool) {
        wrint(b, int64(s.Version))
        ctxt.RefsWritten++
        s.RefIdx = ctxt.RefsWritten
+       m[s.Name] = ctxt.RefsWritten
 }
 
 func writerefs(ctxt *Link, b *Biobuf, s *LSym) {