From 7e54aa2c25690f5a7f5baad112d231b6ff8d4e5e Mon Sep 17 00:00:00 2001 From: Cherry Zhang Date: Fri, 18 Sep 2020 11:56:43 -0400 Subject: [PATCH] cmd/link: don't mark a symbol's GoType reachable when -linkshared In CL 231397, we stopped marking symbols' GoType reachable in general, but not when -linkshared. It was left as a TODO. This CL addresses it. The problem was that the type names are mangled in the shared library, so we need to mangle the name consistently in the executable as well (regardless of whether the symbol is reachable or not), so that the GCProg generation code can find the corresponding symbol from the shared library. Change-Id: I1040747402929a983ec581109f1681a77893682e Reviewed-on: https://go-review.googlesource.com/c/go/+/255964 Trust: Cherry Zhang Run-TryBot: Cherry Zhang Reviewed-by: Jeremy Faller Reviewed-by: Than McIntosh TryBot-Result: Go Bot --- src/cmd/link/internal/ld/deadcode.go | 6 +----- src/cmd/link/internal/ld/lib.go | 7 ++++++- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/cmd/link/internal/ld/deadcode.go b/src/cmd/link/internal/ld/deadcode.go index d2604b27a9..7f14aa3d27 100644 --- a/src/cmd/link/internal/ld/deadcode.go +++ b/src/cmd/link/internal/ld/deadcode.go @@ -174,13 +174,9 @@ func (d *deadcodePass) flood() { naux := d.ldr.NAux(symIdx) for i := 0; i < naux; i++ { a := d.ldr.Aux(symIdx, i) - if a.Type() == goobj.AuxGotype && !d.ctxt.linkShared { + if a.Type() == goobj.AuxGotype { // A symbol being reachable doesn't imply we need its // type descriptor. Don't mark it. - // TODO: when -linkshared, the GCProg generation code - // seems to need it. I'm not sure why. I think it could - // just reach to the type descriptor's data without - // requiring to mark it reachable. continue } d.mark(a.Sym(), symIdx) diff --git a/src/cmd/link/internal/ld/lib.go b/src/cmd/link/internal/ld/lib.go index 4295b2a660..b2ca658c3c 100644 --- a/src/cmd/link/internal/ld/lib.go +++ b/src/cmd/link/internal/ld/lib.go @@ -831,7 +831,12 @@ func (ctxt *Link) mangleTypeSym() { ldr := ctxt.loader for s := loader.Sym(1); s < loader.Sym(ldr.NSym()); s++ { - if !ldr.AttrReachable(s) { + if !ldr.AttrReachable(s) && !ctxt.linkShared { + // If -linkshared, the GCProg generation code may need to reach + // out to the shared library for the type descriptor's data, even + // the type descriptor itself is not actually needed at run time + // (therefore not reachable). We still need to mangle its name, + // so it is consistent with the one stored in the shared library. continue } name := ldr.SymName(s)