Commit 16029bab authored by Shahar Kohanim's avatar Shahar Kohanim Committed by Ian Lance Taylor

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: default avatarIan Lance Taylor <iant@golang.org>
parent 2d03b5b5
...@@ -345,10 +345,31 @@ func Writeobjfile(ctxt *Link, b *Biobuf) { ...@@ -345,10 +345,31 @@ func Writeobjfile(ctxt *Link, b *Biobuf) {
fmt.Fprintf(b, "go13ld") 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) { func wrref(ctxt *Link, b *Biobuf, s *LSym, isPath bool) {
if s == nil || s.RefIdx != 0 { if s == nil || s.RefIdx != 0 {
return 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) Bputc(b, 0xfe)
if isPath { if isPath {
wrstring(b, filepath.ToSlash(s.Name)) wrstring(b, filepath.ToSlash(s.Name))
...@@ -358,6 +379,7 @@ func wrref(ctxt *Link, b *Biobuf, s *LSym, isPath bool) { ...@@ -358,6 +379,7 @@ func wrref(ctxt *Link, b *Biobuf, s *LSym, isPath bool) {
wrint(b, int64(s.Version)) wrint(b, int64(s.Version))
ctxt.RefsWritten++ ctxt.RefsWritten++
s.RefIdx = ctxt.RefsWritten s.RefIdx = ctxt.RefsWritten
m[s.Name] = ctxt.RefsWritten
} }
func writerefs(ctxt *Link, b *Biobuf, s *LSym) { func writerefs(ctxt *Link, b *Biobuf, s *LSym) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment