Skip to content

Commit 795e8c2

Browse files
committed
cmd/go: address DWARF linker issues with -buildmode=plugin on Darwin
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 <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Cherry Zhang <[email protected]> Reviewed-by: Emmanuel Odeke <[email protected]>
1 parent 64c9ee9 commit 795e8c2

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

src/cmd/link/internal/ld/data.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@ func relocsym(ctxt *Link, s *sym.Symbol) {
157157
if r.Sym != nil && ((r.Sym.Type == sym.Sxxx && !r.Sym.Attr.VisibilityHidden()) || r.Sym.Type == sym.SXREF) {
158158
// When putting the runtime but not main into a shared library
159159
// these symbols are undefined and that's OK.
160-
if ctxt.BuildMode == BuildModeShared {
161-
if r.Sym.Name == "main.main" || r.Sym.Name == "main..inittask" {
160+
if ctxt.BuildMode == BuildModeShared || ctxt.BuildMode == BuildModePlugin {
161+
if r.Sym.Name == "main.main" || (ctxt.BuildMode != BuildModePlugin && r.Sym.Name == "main..inittask") {
162162
r.Sym.Type = sym.SDYNIMPORT
163163
} else if strings.HasPrefix(r.Sym.Name, "go.info.") {
164164
// Skip go.info symbols. They are only needed to communicate

src/cmd/link/internal/ld/dwarf.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -944,6 +944,11 @@ func calcCompUnitRanges(ctxt *Link) {
944944
if s.FuncInfo == nil {
945945
continue
946946
}
947+
// Skip linker-created functions (ex: runtime.addmoduledata), since they
948+
// don't have DWARF to begin with.
949+
if s.Unit == nil {
950+
continue
951+
}
947952
unit := s.Unit
948953
// Update PC ranges.
949954
//

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ func (ctxt *Link) loadlib() {
437437
// We now have enough information to determine the link mode.
438438
determineLinkMode(ctxt)
439439

440-
if ctxt.LinkMode == LinkExternal && !iscgo && ctxt.LibraryByPkg["runtime/cgo"] == nil && !(objabi.GOOS == "darwin" && (ctxt.Arch.Family == sys.AMD64 || ctxt.Arch.Family == sys.I386)) {
440+
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)) {
441441
// This indicates a user requested -linkmode=external.
442442
// The startup code uses an import of runtime/cgo to decide
443443
// whether to initialize the TLS. So give it one. This could

0 commit comments

Comments
 (0)