]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: address DWARF linker issues with -buildmode=plugin on Darwin
authorThan McIntosh <thanm@google.com>
Wed, 19 Jun 2019 19:14:54 +0000 (15:14 -0400)
committerThan McIntosh <thanm@google.com>
Mon, 11 Nov 2019 17:37:48 +0000 (17:37 +0000)
Assorted fixups in the linker needed to enable turning back on
DWARF generation when building plugins for Darwin. Includes:

 - don't suppress import of runtime/cgo in the linker for
   Darwin if we are linking in plugin mode

 - in calcCompUnitRanges handle the case where we encounter
   linker-generated functions that have no associated Unit (and
   also have no DWARF)

 - generalize a guard in relocsym() include so as to avoid
   triggering a spurious error on go.info symbols in plugin mode

Updates #21647.
Updates #27502.

Change-Id: I317fea97bef2f3461e31498e63f9fd6d8b8f4b23
Reviewed-on: https://go-review.googlesource.com/c/go/+/182959
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
src/cmd/link/internal/ld/data.go
src/cmd/link/internal/ld/dwarf.go
src/cmd/link/internal/ld/lib.go

index 3c24717433cf6c864f03a50b729f952d57ace91c..32d1111ea3a9e7cdae3bda70f8f3f6ff0b9573c4 100644 (file)
@@ -157,8 +157,8 @@ func relocsym(ctxt *Link, s *sym.Symbol) {
                if r.Sym != nil && ((r.Sym.Type == sym.Sxxx && !r.Sym.Attr.VisibilityHidden()) || r.Sym.Type == sym.SXREF) {
                        // When putting the runtime but not main into a shared library
                        // these symbols are undefined and that's OK.
-                       if ctxt.BuildMode == BuildModeShared {
-                               if r.Sym.Name == "main.main" || r.Sym.Name == "main..inittask" {
+                       if ctxt.BuildMode == BuildModeShared || ctxt.BuildMode == BuildModePlugin {
+                               if r.Sym.Name == "main.main" || (ctxt.BuildMode != BuildModePlugin && r.Sym.Name == "main..inittask") {
                                        r.Sym.Type = sym.SDYNIMPORT
                                } else if strings.HasPrefix(r.Sym.Name, "go.info.") {
                                        // Skip go.info symbols. They are only needed to communicate
index f5af90b0282f7003655cd11adf4b7b5108ee99a3..f9cb0e98c335053148b797564817850d92a7e27b 100644 (file)
@@ -944,6 +944,11 @@ func calcCompUnitRanges(ctxt *Link) {
                if s.FuncInfo == nil {
                        continue
                }
+               // Skip linker-created functions (ex: runtime.addmoduledata), since they
+               // don't have DWARF to begin with.
+               if s.Unit == nil {
+                       continue
+               }
                unit := s.Unit
                // Update PC ranges.
                //
index 0bd9a8c7358c4c6d631c9be0b9d3c4060512d314..09a5f2a711ddd85c58c4488a88ecc4fbb65cb45e 100644 (file)
@@ -437,7 +437,7 @@ func (ctxt *Link) loadlib() {
        // We now have enough information to determine the link mode.
        determineLinkMode(ctxt)
 
-       if ctxt.LinkMode == LinkExternal && !iscgo && ctxt.LibraryByPkg["runtime/cgo"] == nil && !(objabi.GOOS == "darwin" && (ctxt.Arch.Family == sys.AMD64 || ctxt.Arch.Family == sys.I386)) {
+       if ctxt.LinkMode == LinkExternal && !iscgo && ctxt.LibraryByPkg["runtime/cgo"] == nil && !(objabi.GOOS == "darwin" && ctxt.BuildMode != BuildModePlugin && (ctxt.Arch.Family == sys.AMD64 || ctxt.Arch.Family == sys.I386)) {
                // This indicates a user requested -linkmode=external.
                // The startup code uses an import of runtime/cgo to decide
                // whether to initialize the TLS.  So give it one. This could