From: Cherry Zhang Date: Sat, 18 Apr 2020 00:41:59 +0000 (-0400) Subject: cmd/link: stop checking reflect.Value.Call in deadcode pass X-Git-Tag: go1.15beta1~514 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=b0da26a668fd6d4e351a00ca76695c5a233e84a2;p=gostls13.git cmd/link: stop checking reflect.Value.Call in deadcode pass In the linker's deadcode pass, we need to keep a method live if it can be reached through reflection. We do this by marking all exported method live if reflect.Value.Method or reflect.Type.Method is used. Currently we also check for reflect.Value.Call, which is unnecessary because in order to call a method through reflection, the method must be obtained through reflect.Value.Method or reflect.Type.Method, which we already check. Per discussion in https://groups.google.com/d/msg/golang-dev/eG9It63-Bxg/_bnoVy-eAwAJ Thanks Brad, Russ, and Ian for bringing this up. Change-Id: I8e9529a224bb898dbf5752674cc9d155db386c14 Reviewed-on: https://go-review.googlesource.com/c/go/+/228792 Reviewed-by: Brad Fitzpatrick --- diff --git a/src/cmd/link/internal/ld/deadcode2.go b/src/cmd/link/internal/ld/deadcode2.go index 3342efe39f..1aa65aee78 100644 --- a/src/cmd/link/internal/ld/deadcode2.go +++ b/src/cmd/link/internal/ld/deadcode2.go @@ -219,7 +219,6 @@ func deadcode2(ctxt *Link) { d.init() d.flood() - callSym := ldr.Lookup("reflect.Value.Call", sym.SymVerABIInternal) methSym := ldr.Lookup("reflect.Value.Method", sym.SymVerABIInternal) if ctxt.DynlinkingGo() { // Exported methods may satisfy interfaces we don't know @@ -231,7 +230,7 @@ func deadcode2(ctxt *Link) { // Methods might be called via reflection. Give up on // static analysis, mark all exported methods of // all reachable types as reachable. - d.reflectSeen = d.reflectSeen || (callSym != 0 && ldr.AttrReachable(callSym)) || (methSym != 0 && ldr.AttrReachable(methSym)) + d.reflectSeen = d.reflectSeen || (methSym != 0 && ldr.AttrReachable(methSym)) // Mark all methods that could satisfy a discovered // interface as reachable. We recheck old marked interfaces