]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/internal/ld: prevent creation of .dynamic and .dynsym symbols when externally...
authorMichael Hudson-Doyle <michael.hudson@canonical.com>
Tue, 12 May 2015 04:07:05 +0000 (16:07 +1200)
committerRuss Cox <rsc@golang.org>
Fri, 15 May 2015 20:09:12 +0000 (20:09 +0000)
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 <michael.hudson@canonical.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
src/cmd/internal/ld/data.go
src/cmd/internal/ld/go.go
src/cmd/internal/ld/lib.go

index b0157547c384f8d5037b78d38043c846a7890cd0..b65b667f98b6fdaede693de855c403539ba02f88 100644 (file)
@@ -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
        }
index a5b09202e8cbb90152816d1c6ec17fc974ff9430..875b8d2e176bfaf38db8a637397f74a0c4209454 100644 (file)
@@ -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)
        }
 }
 
index cc0840c04abd4542d6b272aad80fdece4203d11b..a0d03ef22d98c1b6c521f090d4000209180ce030 100644 (file)
@@ -178,6 +178,7 @@ var (
        Thelinkarch        *LinkArch
        outfile            string
        dynexp             []*LSym
+       dynlib             []string
        ldflag             []string
        havedynamic        int
        Funcalign          int