1
0
mirror of https://github.com/golang/go synced 2024-11-22 22:20:03 -07:00

cmd/compile: deduplicate symbol references

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>
This commit is contained in:
Shahar Kohanim 2016-03-17 13:18:34 +02:00 committed by Ian Lance Taylor
parent 2d03b5b572
commit 16029babe2

View 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) {