aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/link/internal/ld
diff options
context:
space:
mode:
authorDavid Crawshaw <crawshaw@golang.org>2016-08-25 21:06:10 -0400
committerDavid Crawshaw <crawshaw@golang.org>2016-08-26 20:06:58 +0000
commit8f3c8a33fad917abb45ef98b3a1cd34fe9715370 (patch)
tree0b1c01640a08f3562720b5cc3bac83abeedfc0f1 /src/cmd/link/internal/ld
parent7f27f1dfdd81c978d4868917d7622e09b288ecb0 (diff)
downloadgo-8f3c8a33fad917abb45ef98b3a1cd34fe9715370.tar.xz
cmd/link: make DynlinkingGo a method
This will allow it to depend on whether plugin.Open is a symbol to be linked in. Change-Id: Ie9aa4216f2510fe8b10bc4665c8b19622b7122ea Reviewed-on: https://go-review.googlesource.com/27819 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/cmd/link/internal/ld')
-rw-r--r--src/cmd/link/internal/ld/data.go2
-rw-r--r--src/cmd/link/internal/ld/deadcode.go2
-rw-r--r--src/cmd/link/internal/ld/lib.go10
-rw-r--r--src/cmd/link/internal/ld/objfile.go2
-rw-r--r--src/cmd/link/internal/ld/symtab.go30
5 files changed, 23 insertions, 23 deletions
diff --git a/src/cmd/link/internal/ld/data.go b/src/cmd/link/internal/ld/data.go
index c413a6f1ec..fdf99d602b 100644
--- a/src/cmd/link/internal/ld/data.go
+++ b/src/cmd/link/internal/ld/data.go
@@ -360,7 +360,7 @@ func relocsym(ctxt *Link, s *Symbol) {
// We need to be able to reference dynimport symbols when linking against
// shared libraries, and Solaris needs it always
- if HEADTYPE != obj.Hsolaris && r.Sym != nil && r.Sym.Type == obj.SDYNIMPORT && !DynlinkingGo() {
+ if HEADTYPE != obj.Hsolaris && r.Sym != nil && r.Sym.Type == obj.SDYNIMPORT && !ctxt.DynlinkingGo() {
if !(SysArch.Family == sys.PPC64 && Linkmode == LinkExternal && r.Sym.Name == ".TOC.") {
ctxt.Diag("unhandled relocation for %s (type %d rtype %d)", r.Sym.Name, r.Sym.Type, r.Type)
}
diff --git a/src/cmd/link/internal/ld/deadcode.go b/src/cmd/link/internal/ld/deadcode.go
index 6fd5ee3cbb..27e5a19a7a 100644
--- a/src/cmd/link/internal/ld/deadcode.go
+++ b/src/cmd/link/internal/ld/deadcode.go
@@ -63,7 +63,7 @@ func deadcode(ctxt *Link) {
methSym := Linkrlookup(ctxt, "reflect.Value.Method", 0)
reflectSeen := false
- if DynlinkingGo() {
+ if ctxt.DynlinkingGo() {
// Exported methods may satisfy interfaces we don't know
// about yet when dynamically linking.
reflectSeen = true
diff --git a/src/cmd/link/internal/ld/lib.go b/src/cmd/link/internal/ld/lib.go
index d118714842..3033258e77 100644
--- a/src/cmd/link/internal/ld/lib.go
+++ b/src/cmd/link/internal/ld/lib.go
@@ -155,7 +155,7 @@ type Section struct {
// DynlinkingGo returns whether we are producing Go code that can live
// in separate shared libraries linked together at runtime.
-func DynlinkingGo() bool {
+func (ctxt *Link) DynlinkingGo() bool {
return Buildmode == BuildmodeShared || *FlagLinkshared
}
@@ -307,7 +307,7 @@ func libinit(ctxt *Link) {
}
}
- if !DynlinkingGo() {
+ if !ctxt.DynlinkingGo() {
Linklookup(ctxt, *flagEntrySymbol, 0).Type = obj.SXREF
}
}
@@ -466,7 +466,7 @@ func (ctxt *Link) loadlib() {
if ctxt.Library[i].Shlib != "" {
ldshlibsyms(ctxt, ctxt.Library[i].Shlib)
} else {
- if DynlinkingGo() {
+ if ctxt.DynlinkingGo() {
Exitf("cannot implicitly include runtime/cgo in a shared library")
}
objfile(ctxt, ctxt.Library[i])
@@ -998,7 +998,7 @@ func (l *Link) hostlink() {
argv = append(argv, "-shared")
}
- if Iself && DynlinkingGo() {
+ if Iself && l.DynlinkingGo() {
// We force all symbol resolution to be done at program startup
// because lazy PLT resolution can use large amounts of stack at
// times we cannot allow it to do so.
@@ -1639,7 +1639,7 @@ func stkcheck(ctxt *Link, up *chain, depth int) int {
// should never be called directly.
// onlyctxt.Diagnose the direct caller.
// TODO(mwhudson): actually think about this.
- if depth == 1 && s.Type != obj.SXREF && !DynlinkingGo() &&
+ if depth == 1 && s.Type != obj.SXREF && !ctxt.DynlinkingGo() &&
Buildmode != BuildmodeCArchive && Buildmode != BuildmodePIE && Buildmode != BuildmodeCShared {
ctxt.Diag("call to external function %s", s.Name)
}
diff --git a/src/cmd/link/internal/ld/objfile.go b/src/cmd/link/internal/ld/objfile.go
index dace73161a..5bb6e1e8af 100644
--- a/src/cmd/link/internal/ld/objfile.go
+++ b/src/cmd/link/internal/ld/objfile.go
@@ -585,7 +585,7 @@ func (r *objReader) readSymName() string {
}
r.rdBuf = adjName[:0] // in case 2*n wasn't enough
- if DynlinkingGo() {
+ if r.ctxt.DynlinkingGo() {
// These types are included in the symbol
// table when dynamically linking. To keep
// binary size down, we replace the names
diff --git a/src/cmd/link/internal/ld/symtab.go b/src/cmd/link/internal/ld/symtab.go
index 6ff16aba6e..6a2ccd5d0b 100644
--- a/src/cmd/link/internal/ld/symtab.go
+++ b/src/cmd/link/internal/ld/symtab.go
@@ -46,14 +46,6 @@ func putelfstr(s string) int {
putelfstr("")
}
- // When dynamically linking, we create Symbols by reading the names from
- // the symbol tables of the shared libraries and so the names need to
- // match exactly. Tools like DTrace will have to wait for now.
- if !DynlinkingGo() {
- // Rewrite · to . for ASCII-only tools like DTrace (sigh)
- s = strings.Replace(s, "·", ".", -1)
- }
-
off := len(Elfstrdat)
Elfstrdat = append(Elfstrdat, s...)
Elfstrdat = append(Elfstrdat, 0)
@@ -144,7 +136,7 @@ func putelfsym(ctxt *Link, x *Symbol, s string, t int, addr int64, size int64, v
// To avoid filling the dynamic table with lots of unnecessary symbols,
// mark all Go symbols local (not global) in the final executable.
// But when we're dynamically linking, we need all those global symbols.
- if !DynlinkingGo() && Linkmode == LinkExternal && !x.Attr.CgoExportStatic() && elfshnum != SHN_UNDEF {
+ if !ctxt.DynlinkingGo() && Linkmode == LinkExternal && !x.Attr.CgoExportStatic() && elfshnum != SHN_UNDEF {
bind = STB_LOCAL
}
@@ -155,14 +147,22 @@ func putelfsym(ctxt *Link, x *Symbol, s string, t int, addr int64, size int64, v
if x.Type&obj.SHIDDEN != 0 {
other = STV_HIDDEN
}
- if (Buildmode == BuildmodeCArchive || Buildmode == BuildmodePIE || DynlinkingGo()) && SysArch.Family == sys.PPC64 && type_ == STT_FUNC && x.Name != "runtime.duffzero" && x.Name != "runtime.duffcopy" {
+ if (Buildmode == BuildmodeCArchive || Buildmode == BuildmodePIE || ctxt.DynlinkingGo()) && SysArch.Family == sys.PPC64 && type_ == STT_FUNC && x.Name != "runtime.duffzero" && x.Name != "runtime.duffcopy" {
// On ppc64 the top three bits of the st_other field indicate how
// many instructions separate the global and local entry points. In
// our case it is two instructions, indicated by the value 3.
other |= 3 << 5
}
- if DynlinkingGo() && bind == STB_GLOBAL && elfbind == STB_LOCAL && x.Type == obj.STEXT {
+ // When dynamically linking, we create Symbols by reading the names from
+ // the symbol tables of the shared libraries and so the names need to
+ // match exactly. Tools like DTrace will have to wait for now.
+ if !ctxt.DynlinkingGo() {
+ // Rewrite · to . for ASCII-only tools like DTrace (sigh)
+ s = strings.Replace(s, "·", ".", -1)
+ }
+
+ if ctxt.DynlinkingGo() && bind == STB_GLOBAL && elfbind == STB_LOCAL && x.Type == obj.STEXT {
// When dynamically linking, we want references to functions defined
// in this module to always be to the function object, not to the
// PLT. We force this by writing an additional local symbol for every
@@ -376,7 +376,7 @@ func (ctxt *Link) symtab() {
s.Size = 0
s.Attr |= AttrReachable
symtyperel = s
- } else if !DynlinkingGo() {
+ } else if !ctxt.DynlinkingGo() {
s = Linklookup(ctxt, "type.*", 0)
s.Type = obj.STYPE
@@ -401,7 +401,7 @@ func (ctxt *Link) symtab() {
)
var symgofuncrel *Symbol
- if !DynlinkingGo() {
+ if !ctxt.DynlinkingGo() {
if UseRelro() {
symgofuncrel = groupSym("go.funcrel.*", obj.SGOFUNCRELRO)
} else {
@@ -435,7 +435,7 @@ func (ctxt *Link) symtab() {
switch {
case strings.HasPrefix(s.Name, "type."):
- if !DynlinkingGo() {
+ if !ctxt.DynlinkingGo() {
s.Attr |= AttrHidden
}
if UseRelro() {
@@ -478,7 +478,7 @@ func (ctxt *Link) symtab() {
s.Outer = symgcbits
case strings.HasSuffix(s.Name, "·f"):
- if !DynlinkingGo() {
+ if !ctxt.DynlinkingGo() {
s.Attr |= AttrHidden
}
if UseRelro() {