From 16029babe24c516230399205a74becb2c215e11a Mon Sep 17 00:00:00 2001 From: Shahar Kohanim Date: Thu, 17 Mar 2016 13:18:34 +0200 Subject: [PATCH] cmd/compile: deduplicate symbol references MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/cmd/internal/obj/objfile.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/cmd/internal/obj/objfile.go b/src/cmd/internal/obj/objfile.go index f782644d88..ee49517b68 100644 --- a/src/cmd/internal/obj/objfile.go +++ b/src/cmd/internal/obj/objfile.go @@ -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) { -- 2.48.1