]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: always mark runtime.unreachableMethod symbol
authorCherry Mui <cherryyz@google.com>
Thu, 13 May 2021 20:48:50 +0000 (16:48 -0400)
committerCherry Mui <cherryyz@google.com>
Thu, 13 May 2021 21:16:06 +0000 (21:16 +0000)
In the deadcode path we mark runtime.unreachableMethod symbol,
which is a special symbol used for redirecting unreachable
methods. Currently this code is conditioned on not -linkshared.
This is wrong. It should be marked with -linkshared mode as well.

In fact, -linkshared should only affect the entry symbol. Change
the code accordingly.

Change-Id: I252abf850212a930f275589ef0035a43e52cb9cc
Reviewed-on: https://go-review.googlesource.com/c/go/+/319893
Trust: Cherry Mui <cherryyz@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Jeremy Faller <jeremy@golang.org>
src/cmd/link/internal/ld/deadcode.go

index 1ed5598c99d510b1d71ed85c89c21ad04dba9063..416e5da39838fe73a68f663c6914869571a444ba 100644 (file)
@@ -65,26 +65,26 @@ func (d *deadcodePass) init() {
                        }
                }
                names = append(names, *flagEntrySymbol)
-               // runtime.unreachableMethod is a function that will throw if called.
-               // We redirect unreachable methods to it.
-               names = append(names, "runtime.unreachableMethod")
-               if !d.ctxt.linkShared && d.ctxt.BuildMode != BuildModePlugin {
-                       // runtime.buildVersion and runtime.modinfo are referenced in .go.buildinfo section
-                       // (see function buildinfo in data.go). They should normally be reachable from the
-                       // runtime. Just make it explicit, in case.
-                       names = append(names, "runtime.buildVersion", "runtime.modinfo")
-               }
-               if d.ctxt.BuildMode == BuildModePlugin {
-                       names = append(names, objabi.PathToPrefix(*flagPluginPath)+"..inittask", objabi.PathToPrefix(*flagPluginPath)+".main", "go.plugin.tabs")
-
-                       // We don't keep the go.plugin.exports symbol,
-                       // but we do keep the symbols it refers to.
-                       exportsIdx := d.ldr.Lookup("go.plugin.exports", 0)
-                       if exportsIdx != 0 {
-                               relocs := d.ldr.Relocs(exportsIdx)
-                               for i := 0; i < relocs.Count(); i++ {
-                                       d.mark(relocs.At(i).Sym(), 0)
-                               }
+       }
+       // runtime.unreachableMethod is a function that will throw if called.
+       // We redirect unreachable methods to it.
+       names = append(names, "runtime.unreachableMethod")
+       if !d.ctxt.linkShared && d.ctxt.BuildMode != BuildModePlugin {
+               // runtime.buildVersion and runtime.modinfo are referenced in .go.buildinfo section
+               // (see function buildinfo in data.go). They should normally be reachable from the
+               // runtime. Just make it explicit, in case.
+               names = append(names, "runtime.buildVersion", "runtime.modinfo")
+       }
+       if d.ctxt.BuildMode == BuildModePlugin {
+               names = append(names, objabi.PathToPrefix(*flagPluginPath)+"..inittask", objabi.PathToPrefix(*flagPluginPath)+".main", "go.plugin.tabs")
+
+               // We don't keep the go.plugin.exports symbol,
+               // but we do keep the symbols it refers to.
+               exportsIdx := d.ldr.Lookup("go.plugin.exports", 0)
+               if exportsIdx != 0 {
+                       relocs := d.ldr.Relocs(exportsIdx)
+                       for i := 0; i < relocs.Count(); i++ {
+                               d.mark(relocs.At(i).Sym(), 0)
                        }
                }
        }