Commit 00470609 authored by Michael Hudson-Doyle's avatar Michael Hudson-Doyle Committed by Russ Cox

cmd/5l, etc, cmd/internal/ld: consolidate implementations of adddynlib

They were all essentially the same.

Change-Id: I6e0b548cda6e4bbe2ec3b3025b746d1f6d332d48
Reviewed-on: https://go-review.googlesource.com/10000
Run-TryBot: Michael Hudson-Doyle <michael.hudson@canonical.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarRuss Cox <rsc@golang.org>
parent c3c047a6
......@@ -37,24 +37,6 @@ import (
"log"
)
func needlib(name string) int {
if name[0] == '\x00' {
return 0
}
/* reuse hash code in symbol table */
p := fmt.Sprintf(".dynlib.%s", name)
s := ld.Linklookup(ld.Ctxt, p, 0)
if s.Type == 0 {
s.Type = 100 // avoid SDATA, etc.
return 1
}
return 0
}
func gentext() {
}
......@@ -557,24 +539,6 @@ func adddynsym(ctxt *ld.Link, s *ld.LSym) {
}
}
func adddynlib(lib string) {
if needlib(lib) == 0 {
return
}
if ld.Iself {
s := ld.Linklookup(ld.Ctxt, ".dynstr", 0)
if s.Size == 0 {
ld.Addstring(s, "")
}
ld.Elfwritedynent(ld.Linklookup(ld.Ctxt, ".dynamic", 0), ld.DT_NEEDED, uint64(ld.Addstring(s, lib)))
} else if ld.HEADTYPE == obj.Hdarwin {
ld.Machoadddynlib(lib)
} else {
ld.Diag("adddynlib: unsupported binary format")
}
}
func asmb() {
if ld.Debug['v'] != 0 {
fmt.Fprintf(&ld.Bso, "%5.2f asmb\n", obj.Cputime())
......
......@@ -58,7 +58,6 @@ func linkarchinit() {
ld.Thearch.Dwarfregsp = DWARFREGSP
ld.Thearch.Dwarfreglr = DWARFREGLR
ld.Thearch.Adddynlib = adddynlib
ld.Thearch.Adddynrel = adddynrel
ld.Thearch.Adddynsym = adddynsym
ld.Thearch.Archinit = archinit
......
......@@ -44,24 +44,6 @@ func PADDR(x uint32) uint32 {
var zeroes string
func needlib(name string) int {
if name[0] == '\x00' {
return 0
}
/* reuse hash code in symbol table */
p := fmt.Sprintf(".elfload.%s", name)
s := ld.Linklookup(ld.Ctxt, p, 0)
if s.Type == 0 {
s.Type = 100 // avoid SDATA, etc.
return 1
}
return 0
}
func Addcall(ctxt *ld.Link, s *ld.LSym, t *ld.LSym) int64 {
s.Reachable = true
i := s.Size
......@@ -673,7 +655,7 @@ func adddynsym(ctxt *ld.Link, s *ld.LSym) {
/* size of object */
ld.Adduint64(ctxt, d, uint64(s.Size))
if s.Cgoexport&ld.CgoExportDynamic == 0 && s.Dynimplib != "" && needlib(s.Dynimplib) != 0 {
if s.Cgoexport&ld.CgoExportDynamic == 0 && s.Dynimplib != "" && !ld.Seenlib[s.Dynimplib] {
ld.Elfwritedynent(ld.Linklookup(ctxt, ".dynamic", 0), ld.DT_NEEDED, uint64(ld.Addstring(ld.Linklookup(ctxt, ".dynstr", 0), s.Dynimplib)))
}
} else if ld.HEADTYPE == obj.Hdarwin {
......@@ -685,24 +667,6 @@ func adddynsym(ctxt *ld.Link, s *ld.LSym) {
}
}
func adddynlib(lib string) {
if needlib(lib) == 0 {
return
}
if ld.Iself {
s := ld.Linklookup(ld.Ctxt, ".dynstr", 0)
if s.Size == 0 {
ld.Addstring(s, "")
}
ld.Elfwritedynent(ld.Linklookup(ld.Ctxt, ".dynamic", 0), ld.DT_NEEDED, uint64(ld.Addstring(s, lib)))
} else if ld.HEADTYPE == obj.Hdarwin {
ld.Machoadddynlib(lib)
} else {
ld.Diag("adddynlib: unsupported binary format")
}
}
func asmb() {
if ld.Debug['v'] != 0 {
fmt.Fprintf(&ld.Bso, "%5.2f asmb\n", obj.Cputime())
......
......@@ -61,7 +61,6 @@ func linkarchinit() {
ld.Thearch.Dwarfregsp = DWARFREGSP
ld.Thearch.Dwarfreglr = DWARFREGLR
ld.Thearch.Adddynlib = adddynlib
ld.Thearch.Adddynrel = adddynrel
ld.Thearch.Adddynsym = adddynsym
ld.Thearch.Archinit = archinit
......
......@@ -40,24 +40,6 @@ import (
func gentext() {}
func needlib(name string) int {
if name[0] == '\x00' {
return 0
}
/* reuse hash code in symbol table */
p := fmt.Sprintf(".dynlib.%s", name)
s := ld.Linklookup(ld.Ctxt, p, 0)
if s.Type == 0 {
s.Type = 100 // avoid SDATA, etc.
return 1
}
return 0
}
func adddynrela(rel *ld.LSym, s *ld.LSym, r *ld.Reloc) {
log.Fatalf("adddynrela not implemented")
}
......@@ -297,24 +279,6 @@ func adddynsym(ctxt *ld.Link, s *ld.LSym) {
// TODO(minux): implement when needed.
}
func adddynlib(lib string) {
if needlib(lib) == 0 {
return
}
if ld.Iself {
s := ld.Linklookup(ld.Ctxt, ".dynstr", 0)
if s.Size == 0 {
ld.Addstring(s, "")
}
ld.Elfwritedynent(ld.Linklookup(ld.Ctxt, ".dynamic", 0), ld.DT_NEEDED, uint64(ld.Addstring(s, lib)))
} else if ld.HEADTYPE == obj.Hdarwin {
ld.Machoadddynlib(lib)
} else {
ld.Diag("adddynlib: unsupported binary format")
}
}
func asmb() {
if ld.Debug['v'] != 0 {
fmt.Fprintf(&ld.Bso, "%5.2f asmb\n", obj.Cputime())
......
......@@ -58,7 +58,6 @@ func linkarchinit() {
ld.Thearch.Dwarfregsp = DWARFREGSP
ld.Thearch.Dwarfreglr = DWARFREGLR
ld.Thearch.Adddynlib = adddynlib
ld.Thearch.Adddynrel = adddynrel
ld.Thearch.Adddynsym = adddynsym
ld.Thearch.Archinit = archinit
......
......@@ -37,24 +37,6 @@ import (
"log"
)
func needlib(name string) int {
if name[0] == '\x00' {
return 0
}
/* reuse hash code in symbol table */
p := fmt.Sprintf(".dynlib.%s", name)
s := ld.Linklookup(ld.Ctxt, p, 0)
if s.Type == 0 {
s.Type = 100 // avoid SDATA, etc.
return 1
}
return 0
}
func gentext() {
}
......@@ -548,24 +530,6 @@ func adddynsym(ctxt *ld.Link, s *ld.LSym) {
}
}
func adddynlib(lib string) {
if needlib(lib) == 0 {
return
}
if ld.Iself {
s := ld.Linklookup(ld.Ctxt, ".dynstr", 0)
if s.Size == 0 {
ld.Addstring(s, "")
}
ld.Elfwritedynent(ld.Linklookup(ld.Ctxt, ".dynamic", 0), ld.DT_NEEDED, uint64(ld.Addstring(s, lib)))
} else if ld.HEADTYPE == obj.Hdarwin {
ld.Machoadddynlib(lib)
} else if ld.HEADTYPE != obj.Hwindows {
ld.Diag("adddynlib: unsupported binary format")
}
}
func asmb() {
if ld.Debug['v'] != 0 {
fmt.Fprintf(&ld.Bso, "%5.2f asmb\n", obj.Cputime())
......
......@@ -58,7 +58,6 @@ func linkarchinit() {
ld.Thearch.Dwarfregsp = DWARFREGSP
ld.Thearch.Dwarfreglr = DWARFREGLR
ld.Thearch.Adddynlib = adddynlib
ld.Thearch.Adddynrel = adddynrel
ld.Thearch.Adddynsym = adddynsym
ld.Thearch.Archinit = archinit
......
......@@ -38,24 +38,6 @@ import (
"log"
)
func needlib(name string) int {
if name[0] == '\x00' {
return 0
}
/* reuse hash code in symbol table */
p := fmt.Sprintf(".dynlib.%s", name)
s := ld.Linklookup(ld.Ctxt, p, 0)
if s.Type == 0 {
s.Type = 100 // avoid SDATA, etc.
return 1
}
return 0
}
func gentext() {
var s *ld.LSym
var stub *ld.LSym
......@@ -670,22 +652,6 @@ func adddynsym(ctxt *ld.Link, s *ld.LSym) {
}
}
func adddynlib(lib string) {
if needlib(lib) == 0 {
return
}
if ld.Iself {
s := ld.Linklookup(ld.Ctxt, ".dynstr", 0)
if s.Size == 0 {
ld.Addstring(s, "")
}
ld.Elfwritedynent(ld.Linklookup(ld.Ctxt, ".dynamic", 0), ld.DT_NEEDED, uint64(ld.Addstring(s, lib)))
} else {
ld.Diag("adddynlib: unsupported binary format")
}
}
func asmb() {
if ld.Debug['v'] != 0 {
fmt.Fprintf(&ld.Bso, "%5.2f asmb\n", obj.Cputime())
......
......@@ -62,7 +62,6 @@ func linkarchinit() {
ld.Thearch.Dwarfregsp = DWARFREGSP
ld.Thearch.Dwarfreglr = DWARFREGLR
ld.Thearch.Adddynlib = adddynlib
ld.Thearch.Adddynrel = adddynrel
ld.Thearch.Adddynsym = adddynsym
ld.Thearch.Archinit = archinit
......
......@@ -416,7 +416,7 @@ func loadcgo(file string, pkg string, p string) {
// to force a link of foo.so.
havedynamic = 1
Thearch.Adddynlib(lib)
adddynlib(lib)
continue
}
......@@ -534,6 +534,27 @@ err:
nerrors++
}
var Seenlib = make(map[string]bool)
func adddynlib(lib string) {
if Seenlib[lib] {
return
}
Seenlib[lib] = true
if Iself {
s := Linklookup(Ctxt, ".dynstr", 0)
if s.Size == 0 {
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")
}
}
var markq *LSym
var emarkq *LSym
......
......@@ -94,7 +94,6 @@ type Arch struct {
Openbsddynld string
Dragonflydynld string
Solarisdynld string
Adddynlib func(string)
Adddynrel func(*LSym, *Reloc)
Adddynsym func(*Link, *LSym)
Archinit func()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment