1
0
mirror of https://github.com/golang/go synced 2024-11-18 20:14:43 -07:00

[dev.link] cmd/oldlink: update with recent linker changes

Port CL 228792, CL 228877, and CL 228881 to old linker.

Change-Id: Id3fdc413a9f7b38887ae8cc7bca5904933be93de
Reviewed-on: https://go-review.googlesource.com/c/go/+/229001
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Jeremy Faller <jeremy@golang.org>
This commit is contained in:
Cherry Zhang 2020-04-20 12:06:07 -04:00
parent 7658648871
commit dce26bdbc1

View File

@ -27,7 +27,8 @@ import (
// //
// 1. direct call // 1. direct call
// 2. through a reachable interface type // 2. through a reachable interface type
// 3. reflect.Value.Call, .Method, or reflect.Method.Func // 3. reflect.Value.Method (or MethodByName), or reflect.Type.Method
// (or MethodByName)
// //
// The first case is handled by the flood fill, a directly called method // The first case is handled by the flood fill, a directly called method
// is marked as reachable. // is marked as reachable.
@ -38,9 +39,9 @@ import (
// as reachable. This is extremely conservative, but easy and correct. // as reachable. This is extremely conservative, but easy and correct.
// //
// The third case is handled by looking to see if any of: // The third case is handled by looking to see if any of:
// - reflect.Value.Call is reachable // - reflect.Value.Method or MethodByName is reachable
// - reflect.Value.Method is reachable // - reflect.Type.Method or MethodByName is called (through the
// - reflect.Type.Method or MethodByName is called. // REFLECTMETHOD attribute marked by the compiler).
// If any of these happen, all bets are off and all exported methods // If any of these happen, all bets are off and all exported methods
// of reachable types are marked reachable. // of reachable types are marked reachable.
// //
@ -65,8 +66,8 @@ func deadcode(ctxt *Link) {
d.init() d.init()
d.flood() d.flood()
callSym := ctxt.Syms.ROLookup("reflect.Value.Call", sym.SymVerABIInternal)
methSym := ctxt.Syms.ROLookup("reflect.Value.Method", sym.SymVerABIInternal) methSym := ctxt.Syms.ROLookup("reflect.Value.Method", sym.SymVerABIInternal)
methByNameSym := ctxt.Syms.ROLookup("reflect.Value.MethodByName", sym.SymVerABIInternal)
reflectSeen := false reflectSeen := false
if ctxt.DynlinkingGo() { if ctxt.DynlinkingGo() {
@ -77,7 +78,7 @@ func deadcode(ctxt *Link) {
for { for {
if !reflectSeen { if !reflectSeen {
if d.reflectMethod || (callSym != nil && callSym.Attr.Reachable()) || (methSym != nil && methSym.Attr.Reachable()) { if d.reflectMethod || (methSym != nil && methSym.Attr.Reachable()) || (methByNameSym != nil && methByNameSym.Attr.Reachable()) {
// Methods might be called via reflection. Give up on // Methods might be called via reflection. Give up on
// static analysis, mark all exported methods of // static analysis, mark all exported methods of
// all reachable types as reachable. // all reachable types as reachable.