From ddc4c146a46cd8ae3a4f1f9b7f0cd14f4bb2aca4 Mon Sep 17 00:00:00 2001 From: Michael Hudson-Doyle Date: Tue, 12 May 2015 16:07:05 +1200 Subject: [PATCH] cmd/internal/ld: prevent creation of .dynamic and .dynsym symbols when externally linking This allows the removal of a fudge in data.go. We have to defer the calls to adddynlib on non-Darwin until after we have decided whether we are externally or internally linking. The Macho/ELF separation could do with some cleaning up, but: code freeze. Fixing this once rather than per-arch is what inspired the previous CLs. Change-Id: I0166f7078a045dc09827745479211247466c0c54 Reviewed-on: https://go-review.googlesource.com/10002 Run-TryBot: Michael Hudson-Doyle TryBot-Result: Gobot Gobot Reviewed-by: Russ Cox --- src/cmd/internal/ld/data.go | 8 +------- src/cmd/internal/ld/go.go | 19 ++++++++++++------- src/cmd/internal/ld/lib.go | 1 + 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/cmd/internal/ld/data.go b/src/cmd/internal/ld/data.go index b0157547c3..b65b667f98 100644 --- a/src/cmd/internal/ld/data.go +++ b/src/cmd/internal/ld/data.go @@ -1127,13 +1127,7 @@ func proggenaddsym(g *ProgGen, s *LSym) { proggenskip(g, g.pos, s.Value-g.pos) g.pos = s.Value - // The test for names beginning with . here is meant - // to keep .dynamic and .dynsym from turning up as - // conservative symbols. They should be marked SELFSECT - // and not SDATA, but sometimes that doesn't happen. - // Leave debugging the SDATA issue for the Go rewrite. - - if s.Gotype == nil && s.Size >= int64(Thearch.Ptrsize) && s.Name[0] != '.' { + if s.Gotype == nil && s.Size >= int64(Thearch.Ptrsize) { Diag("missing Go type information for global symbol: %s size %d", s.Name, int(s.Size)) return } diff --git a/src/cmd/internal/ld/go.go b/src/cmd/internal/ld/go.go index a5b09202e8..875b8d2e17 100644 --- a/src/cmd/internal/ld/go.go +++ b/src/cmd/internal/ld/go.go @@ -416,7 +416,11 @@ func loadcgo(file string, pkg string, p string) { // to force a link of foo.so. havedynamic = 1 - adddynlib(lib) + if HEADTYPE == obj.Hdarwin { + Machoadddynlib(lib) + } else { + dynlib = append(dynlib, lib) + } continue } @@ -537,7 +541,7 @@ err: var seenlib = make(map[string]bool) func adddynlib(lib string) { - if seenlib[lib] { + if seenlib[lib] || Linkmode == LinkExternal { return } seenlib[lib] = true @@ -548,15 +552,13 @@ func adddynlib(lib string) { Addstring(s, "") } Elfwritedynent(Linklookup(Ctxt, ".dynamic", 0), DT_NEEDED, uint64(Addstring(s, lib))) - } else if HEADTYPE == obj.Hdarwin { - Machoadddynlib(lib) } else { Diag("adddynlib: unsupported binary format") } } func Adddynsym(ctxt *Link, s *LSym) { - if s.Dynid >= 0 { + if s.Dynid >= 0 || Linkmode == LinkExternal { return } @@ -774,8 +776,11 @@ func addexport() { return } - for i := 0; i < len(dynexp); i++ { - Adddynsym(Ctxt, dynexp[i]) + for _, exp := range dynexp { + Adddynsym(Ctxt, exp) + } + for _, lib := range dynlib { + adddynlib(lib) } } diff --git a/src/cmd/internal/ld/lib.go b/src/cmd/internal/ld/lib.go index cc0840c04a..a0d03ef22d 100644 --- a/src/cmd/internal/ld/lib.go +++ b/src/cmd/internal/ld/lib.go @@ -178,6 +178,7 @@ var ( Thelinkarch *LinkArch outfile string dynexp []*LSym + dynlib []string ldflag []string havedynamic int Funcalign int -- 2.50.0