mirror of
https://github.com/golang/go
synced 2024-11-23 18:40:03 -07:00
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 <michael.hudson@canonical.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
This commit is contained in:
parent
4cfff271c2
commit
ddc4c146a4
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -178,6 +178,7 @@ var (
|
||||
Thelinkarch *LinkArch
|
||||
outfile string
|
||||
dynexp []*LSym
|
||||
dynlib []string
|
||||
ldflag []string
|
||||
havedynamic int
|
||||
Funcalign int
|
||||
|
Loading…
Reference in New Issue
Block a user