cmd/link, cmd/compile: Add symbol references to object file.

Symbols in the object file currently refer to each other using symbol name
and version. Referring to the same symbol many times in an object file takes
up space and causes redundant map lookups. Instead write out a list of unique
symbol references and have symbols refer to each other using indexes into this
list.

Credit to Michael Hudson-Doyle for kicking this off.

Reduces pkg/linux_amd64 size by 30% from 61MB to 43MB

name       old s/op   new s/op   delta
LinkCmdGo  0.74 ± 3%  0.63 ± 4%  -15.22%  (p=0.000 n=20+20)
LinkJuju   6.38 ± 6%  5.73 ± 6%  -10.16%  (p=0.000 n=20+19)

Change-Id: I7e101a0c80b8e673a3ba688295e6f80ea04e1cfb
Reviewed-on: https://go-review.googlesource.com/20099
Reviewed-by: David Crawshaw <crawshaw@golang.org>
Run-TryBot: David Crawshaw <crawshaw@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Shahar Kohanim 2016-03-14 22:57:58 +02:00 committed by David Crawshaw
parent ea4b785ae0
commit 3648d2d4cd
6 changed files with 146 additions and 73 deletions

View file

@ -314,6 +314,7 @@ type LSym struct {
Leaf uint8
Seenglobl uint8
Onlist uint8
RefIdx int // Index of this symbol in the symbol reference list.
// ReflectMethod means the function may call reflect.Type.Method or
// reflect.Type.MethodByName. Matching is imprecise (as reflect.Type
@ -649,6 +650,7 @@ type Link struct {
Textp *LSym
Etextp *LSym
Errors int
RefsWritten int // Number of symbol references already written to object file.
// state for writing objects
Text *LSym