cmd/link: don't mark a symbol's Gotype reachable

A symbol being reachable doesn't imply its type descriptor is
needed. Don't mark it.

If the type is converted to interface somewhere in the program,
there will be an explicit use of the type descriptor, which
will make it marked.

A println("hello") program before and after

-rwxr-xr-x  1 cherryyz  primarygroup  1259824 Apr 30 23:00 hello
-rwxr-xr-x  1 cherryyz  primarygroup  1169680 Apr 30 23:10 hello

Updates #38782.
Updates #6853.

Change-Id: I88884c126ce75ba073f1ba059c4b892c87d2ac96
Reviewed-on: https://go-review.googlesource.com/c/go/+/231397
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alessandro Arzilli <alessandro.arzilli@gmail.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
Cherry Zhang 2020-04-30 23:10:35 -04:00
parent 3cec330fab
commit 44d22869a8
4 changed files with 71 additions and 34 deletions

View file

@ -6,6 +6,7 @@ package ld
import (
"bytes"
"cmd/internal/goobj2"
"cmd/internal/objabi"
"cmd/internal/sys"
"cmd/link/internal/loader"
@ -154,7 +155,15 @@ func (d *deadcodePass) flood() {
}
naux := d.ldr.NAux(symIdx)
for i := 0; i < naux; i++ {
d.mark(d.ldr.Aux2(symIdx, i).Sym(), symIdx)
a := d.ldr.Aux2(symIdx, i)
if a.Type() == goobj2.AuxGotype && !d.ctxt.linkShared {
// A symbol being reachable doesn't imply we need its
// type descriptor. Don't mark it.
// XXX we need that for GCProg generation when linking
// shared library. why?
continue
}
d.mark(a.Sym(), symIdx)
}
// Some host object symbols have an outer object, which acts like a
// "carrier" symbol, or it holds all the symbols for a particular