[dev.link] cmd/link: create sym.Symbols after deadcode in newobj mode

With the new object files, now we can run the deadcode pass on
indices instead of Symbol structs, so we can delay creating
Symbols after the deadcode pass. Then we only need to create
reachable symbols.

Not create Symbols in LoadNew and LoadRefs, and recombine
LoadReloc into LoadFull.

Split loadcgo into two parts: the first finds root symbols, the
second create Symbols and sets attributes. The first runs before
the deadcode pass, while the second runs after.

TODO: currently there are still symbols that are not marked
reachable but still used. This includes DWARF symbols, file
symbols, and type symbols that are referenced by DWARF symbols.
We still need to create them (conservatively).

Change-Id: I695779c9312be9d49ab1683957ac3e72e1f65a1e
Reviewed-on: https://go-review.googlesource.com/c/go/+/199643
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
This commit is contained in:
Cherry Zhang 2019-10-04 22:05:41 -04:00
parent 90fe9c7c5c
commit cab29ebd84
6 changed files with 217 additions and 238 deletions

View file

@ -65,8 +65,8 @@ func deadcode(ctxt *Link) {
d.init()
d.flood()
callSym := ctxt.Lookup("reflect.Value.Call", sym.SymVerABIInternal)
methSym := ctxt.Lookup("reflect.Value.Method", sym.SymVerABIInternal)
callSym := ctxt.Syms.ROLookup("reflect.Value.Call", sym.SymVerABIInternal)
methSym := ctxt.Syms.ROLookup("reflect.Value.Method", sym.SymVerABIInternal)
reflectSeen := false
if ctxt.DynlinkingGo() {
@ -292,7 +292,7 @@ func (d *deadcodepass) init() {
// We don't keep the go.plugin.exports symbol,
// but we do keep the symbols it refers to.
exports := d.ctxt.Lookup("go.plugin.exports", 0)
exports := d.ctxt.Syms.ROLookup("go.plugin.exports", 0)
if exports != nil {
for i := range exports.R {
d.mark(exports.R[i].Sym, nil)
@ -307,9 +307,9 @@ func (d *deadcodepass) init() {
for _, name := range names {
// Mark symbol as an data/ABI0 symbol.
d.mark(d.ctxt.Lookup(name, 0), nil)
d.mark(d.ctxt.Syms.ROLookup(name, 0), nil)
// Also mark any Go functions (internal ABI).
d.mark(d.ctxt.Lookup(name, sym.SymVerABIInternal), nil)
d.mark(d.ctxt.Syms.ROLookup(name, sym.SymVerABIInternal), nil)
}
}