diff options
| author | Cherry Zhang <cherryyz@google.com> | 2021-02-25 20:01:53 -0500 |
|---|---|---|
| committer | Cherry Zhang <cherryyz@google.com> | 2021-02-26 16:27:08 +0000 |
| commit | a655208c9ecd2fee4de6deff35a863b1c28a091c (patch) | |
| tree | 3a175147b63495465a363aebd68a2b7d71d2fb67 /src/cmd/link/internal/ld/deadcode.go | |
| parent | 23943a67378040340d835734a55dee7cb639e586 (diff) | |
| download | go-a655208c9ecd2fee4de6deff35a863b1c28a091c.tar.xz | |
cmd/link: handle types as converted to interface when dynlink
When using plugins, a type (whose value) may be pass to a plugin
and get converted to interface there, or vice versa. We need to
treat the type as potentially converted to interface, and retain
its methods.
Should fix #44586.
Change-Id: I80dd35e68baedaa852a317543ccd78d94628d13b
Reviewed-on: https://go-review.googlesource.com/c/go/+/296709
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>
Diffstat (limited to 'src/cmd/link/internal/ld/deadcode.go')
| -rw-r--r-- | src/cmd/link/internal/ld/deadcode.go | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/cmd/link/internal/ld/deadcode.go b/src/cmd/link/internal/ld/deadcode.go index 1874103b93..ebde41499e 100644 --- a/src/cmd/link/internal/ld/deadcode.go +++ b/src/cmd/link/internal/ld/deadcode.go @@ -24,6 +24,7 @@ type deadcodePass struct { ifaceMethod map[methodsig]bool // methods declared in reached interfaces markableMethods []methodref // methods of reached types reflectSeen bool // whether we have seen a reflect method call + dynlink bool methodsigstmp []methodsig // scratch buffer for decoding method signatures } @@ -34,6 +35,7 @@ func (d *deadcodePass) init() { if objabi.Fieldtrack_enabled != 0 { d.ldr.Reachparent = make([]loader.Sym, d.ldr.NSym()) } + d.dynlink = d.ctxt.DynlinkingGo() if d.ctxt.BuildMode == BuildModeShared { // Mark all symbols defined in this library as reachable when @@ -115,6 +117,11 @@ func (d *deadcodePass) flood() { var usedInIface bool if isgotype { + if d.dynlink { + // When dynaamic linking, a type may be passed across DSO + // boundary and get converted to interface at the other side. + d.ldr.SetAttrUsedInIface(symIdx, true) + } usedInIface = d.ldr.AttrUsedInIface(symIdx) } |
