cmd/compile, cmd/link: use weak reference in itab

When converting a type T to a non-empty interface I, we build the
itab which contains the code pointers of the methods. Currently,
this brings those methods live (if the itab is live), even if the
interface method is never used. This CL changes the itab to use
weak references, so the methods can be pruned if not otherwise
live.

Fixes #42421.

Change-Id: Iee5de2ba11d603c5a102a2ba60440d839a7f9702
Reviewed-on: https://go-review.googlesource.com/c/go/+/268479
Trust: Cherry Zhang <cherryyz@google.com>
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
This commit is contained in:
Cherry Zhang 2020-11-08 15:18:35 -05:00
parent 747f426944
commit e8700f1ce6
10 changed files with 39 additions and 2 deletions

View file

@ -118,6 +118,8 @@ type ArchSyms struct {
Dynamic loader.Sym
DynSym loader.Sym
DynStr loader.Sym
unreachableMethod loader.Sym
}
// mkArchSym is a helper for setArchSyms, to set up a special symbol.
@ -142,6 +144,7 @@ func (ctxt *Link) setArchSyms() {
ctxt.mkArchSym(".dynamic", 0, &ctxt.Dynamic)
ctxt.mkArchSym(".dynsym", 0, &ctxt.DynSym)
ctxt.mkArchSym(".dynstr", 0, &ctxt.DynStr)
ctxt.mkArchSym("runtime.unreachableMethod", sym.SymVerABIInternal, &ctxt.unreachableMethod)
if ctxt.IsPPC64() {
ctxt.mkArchSym("TOC", 0, &ctxt.TOC)