]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: don't mark a symbol's GoType reachable when -linkshared
authorCherry Zhang <cherryyz@google.com>
Fri, 18 Sep 2020 15:56:43 +0000 (11:56 -0400)
committerCherry Zhang <cherryyz@google.com>
Fri, 18 Sep 2020 19:41:09 +0000 (19:41 +0000)
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 <cherryyz@google.com>
Run-TryBot: Cherry Zhang <cherryyz@google.com>
Reviewed-by: Jeremy Faller <jeremy@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
TryBot-Result: Go Bot <gobot@golang.org>

src/cmd/link/internal/ld/deadcode.go
src/cmd/link/internal/ld/lib.go

index d2604b27a96af7c7edc2d7efbba608a7ebc6b209..7f14aa3d2786dd3864e96725458c0af4a564693f 100644 (file)
@@ -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)
index 4295b2a660b6a13b41aa2671dec4ef9d0c6eff69..b2ca658c3ce6c8e39405b05c9e252292c3c09c39 100644 (file)
@@ -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)