]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: make DynlinkingGo a method
authorDavid Crawshaw <crawshaw@golang.org>
Fri, 26 Aug 2016 01:06:10 +0000 (21:06 -0400)
committerDavid Crawshaw <crawshaw@golang.org>
Fri, 26 Aug 2016 20:06:58 +0000 (20:06 +0000)
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>

16 files changed:
src/cmd/link/internal/amd64/asm.go
src/cmd/link/internal/amd64/obj.go
src/cmd/link/internal/arm/asm.go
src/cmd/link/internal/arm/obj.go
src/cmd/link/internal/arm64/asm.go
src/cmd/link/internal/arm64/obj.go
src/cmd/link/internal/ld/data.go
src/cmd/link/internal/ld/deadcode.go
src/cmd/link/internal/ld/lib.go
src/cmd/link/internal/ld/objfile.go
src/cmd/link/internal/ld/symtab.go
src/cmd/link/internal/ppc64/asm.go
src/cmd/link/internal/s390x/asm.go
src/cmd/link/internal/s390x/obj.go
src/cmd/link/internal/x86/asm.go
src/cmd/link/internal/x86/obj.go

index d5c052cb05d0f7304c0065e25aa7e942f6dd373b..ded36643285ef1d40202a53e2aa743752e944070 100644 (file)
@@ -55,7 +55,7 @@ func Addcall(ctxt *ld.Link, s *ld.Symbol, t *ld.Symbol) int64 {
 }
 
 func gentext(ctxt *ld.Link) {
-       if !ld.DynlinkingGo() {
+       if !ctxt.DynlinkingGo() {
                return
        }
        addmoduledata := ld.Linklookup(ctxt, "runtime.addmoduledata", 0)
@@ -342,7 +342,7 @@ func elfreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) int {
        case obj.R_CALL:
                if r.Siz == 4 {
                        if r.Xsym.Type == obj.SDYNIMPORT {
-                               if ld.DynlinkingGo() {
+                               if ctxt.DynlinkingGo() {
                                        ld.Thearch.Vput(ld.R_X86_64_PLT32 | uint64(elfsym)<<32)
                                } else {
                                        ld.Thearch.Vput(ld.R_X86_64_GOTPCREL | uint64(elfsym)<<32)
index 9e6cdd72eabda37aae5fa1a43114095bec0e2bcd..5c1fafd56fff36e9c566c85c1e9095b8892e4f3a 100644 (file)
@@ -89,7 +89,7 @@ func archinit(ctxt *ld.Link) {
                ld.Linkmode = ld.LinkInternal
        }
 
-       if ld.Buildmode == ld.BuildmodeCArchive || ld.Buildmode == ld.BuildmodeCShared || ld.DynlinkingGo() {
+       if ld.Buildmode == ld.BuildmodeCArchive || ld.Buildmode == ld.BuildmodeCShared || ctxt.DynlinkingGo() {
                ld.Linkmode = ld.LinkExternal
        }
 
index c2cc0814d037676809c0c5071ed0e64e0f00a800..06a6d2d17da74916659aefa0ee908b8609470e44 100644 (file)
@@ -59,7 +59,7 @@ import (
 //                      c: R_ARM_GOT_PREL       local.moduledata
 
 func gentext(ctxt *ld.Link) {
-       if !ld.DynlinkingGo() {
+       if !ctxt.DynlinkingGo() {
                return
        }
        addmoduledata := ld.Linklookup(ctxt, "runtime.addmoduledata", 0)
index 9ae5d2084d49d5617da57264fdf3bb89791c27bf..7af55f89c007e94df119a83e073f858fb59fbdb9 100644 (file)
@@ -85,7 +85,7 @@ func archinit(ctxt *ld.Link) {
                ld.Linkmode = ld.LinkInternal
        }
 
-       if ld.Buildmode == ld.BuildmodeCArchive || ld.Buildmode == ld.BuildmodeCShared || ld.DynlinkingGo() {
+       if ld.Buildmode == ld.BuildmodeCArchive || ld.Buildmode == ld.BuildmodeCShared || ctxt.DynlinkingGo() {
                ld.Linkmode = ld.LinkExternal
        }
 
index 85c452b615f83287b626d464fa3a7450613c1937..9ec2224a65f4aaeef9aeb218713a14734e4d2409 100644 (file)
@@ -39,7 +39,7 @@ import (
 )
 
 func gentext(ctxt *ld.Link) {
-       if !ld.DynlinkingGo() {
+       if !ctxt.DynlinkingGo() {
                return
        }
        addmoduledata := ld.Linklookup(ctxt, "runtime.addmoduledata", 0)
@@ -249,7 +249,7 @@ func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int {
                        // (https://sourceware.org/bugzilla/show_bug.cgi?id=18270). So
                        // we convert the adrp; ld64 + R_ARM64_GOTPCREL into adrp;
                        // add + R_ADDRARM64.
-                       if !(r.Sym.Version != 0 || (r.Sym.Type&obj.SHIDDEN != 0) || r.Sym.Attr.Local()) && r.Sym.Type == obj.STEXT && ld.DynlinkingGo() {
+                       if !(r.Sym.Version != 0 || (r.Sym.Type&obj.SHIDDEN != 0) || r.Sym.Attr.Local()) && r.Sym.Type == obj.STEXT && ctxt.DynlinkingGo() {
                                if o2&0xffc00000 != 0xf9400000 {
                                        ctxt.Diag("R_ARM64_GOTPCREL against unexpected instruction %x", o2)
                                }
index 488f6a9cbcc76092e9b6083eb2bf26796473dc17..8ee7dae459bd0b3934efe6f617dcf1b725a5e429 100644 (file)
@@ -103,7 +103,7 @@ func archinit(ctxt *ld.Link) {
                break
        }
 
-       if ld.Buildmode == ld.BuildmodeCShared || ld.DynlinkingGo() {
+       if ld.Buildmode == ld.BuildmodeCShared || ctxt.DynlinkingGo() {
                ld.Linkmode = ld.LinkExternal
        }
 
index c413a6f1ece6b084cdc33d2ed82ee8c91c256fb6..fdf99d602b86a6ac11f1f4bddda67d3945c12353 100644 (file)
@@ -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)
                        }
index 6fd5ee3cbb1d22fb7aac673e50297a86e2a7c62a..27e5a19a7a5a1cd985ae1d85c683e9c09b74f76a 100644 (file)
@@ -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
index d11871484278dadb5c99b444a0edc217228e0eff..3033258e77943c9d4e8028cc5573db21488c87e6 100644 (file)
@@ -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)
                }
index dace73161a91919fd821fa74c91977bc3d023064..5bb6e1e8af3d86b2c6b70c3b232cf8a3eeb39409 100644 (file)
@@ -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
index 6ff16aba6e84885b5b14aac5ccafd655b0a555fc..6a2ccd5d0bdffd19bd7d7d8cd46f59300f89e1aa 100644 (file)
@@ -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() {
index cf888b692f7102156421a0c67d92e35de6620c25..afbfca10d1535fb83ef2fd82e8b05a3842d9c6a8 100644 (file)
@@ -185,7 +185,7 @@ func genaddmoduledata(ctxt *ld.Link) {
 }
 
 func gentext(ctxt *ld.Link) {
-       if ld.DynlinkingGo() {
+       if ctxt.DynlinkingGo() {
                genaddmoduledata(ctxt)
        }
 
index d08c5af64db84de1ec8e4efaccbf504370390d7b..1d366858538624ca67f5e20fca041edac10ed44b 100644 (file)
@@ -48,7 +48,7 @@ import (
 //
 // The job of appending the moduledata is delegated to runtime.addmoduledata.
 func gentext(ctxt *ld.Link) {
-       if !ld.DynlinkingGo() {
+       if !ctxt.DynlinkingGo() {
                return
        }
        addmoduledata := ld.Linklookup(ctxt, "runtime.addmoduledata", 0)
index 044cfbba0f319eeb78af1d9207dbd4eb95bf1923..2a3d0fcb267f3b274cd97fdc2cea7e6295b9be96 100644 (file)
@@ -86,7 +86,7 @@ func archinit(ctxt *ld.Link) {
                ld.Linkmode = ld.LinkInternal
        }
 
-       if ld.Buildmode == ld.BuildmodeCArchive || ld.Buildmode == ld.BuildmodeCShared || ld.DynlinkingGo() {
+       if ld.Buildmode == ld.BuildmodeCArchive || ld.Buildmode == ld.BuildmodeCShared || ctxt.DynlinkingGo() {
                ld.Linkmode = ld.LinkExternal
        }
 
index 064af7f5f422dcf2e85ab68c8ac92f36ee253eae..d04e82447abae0e6a021c6ea4bfb52e21b142682 100644 (file)
@@ -50,7 +50,7 @@ func addcall(ctxt *ld.Link, s *ld.Symbol, t *ld.Symbol) {
 }
 
 func gentext(ctxt *ld.Link) {
-       if ld.DynlinkingGo() {
+       if ctxt.DynlinkingGo() {
                // We need get_pc_thunk.
        } else {
                switch ld.Buildmode {
index 46ca62c28bf9bc898cc0368ea4ec34e34e5bc7a6..f5722780b798a77b6ad336c8719072bad8b24d35 100644 (file)
@@ -85,7 +85,7 @@ func archinit(ctxt *ld.Link) {
                ld.Linkmode = ld.LinkInternal
        }
 
-       if (ld.Buildmode == ld.BuildmodeCArchive && ld.Iself) || ld.Buildmode == ld.BuildmodeCShared || ld.Buildmode == ld.BuildmodePIE || ld.DynlinkingGo() {
+       if (ld.Buildmode == ld.BuildmodeCArchive && ld.Iself) || ld.Buildmode == ld.BuildmodeCShared || ld.Buildmode == ld.BuildmodePIE || ctxt.DynlinkingGo() {
                ld.Linkmode = ld.LinkExternal
                got := ld.Linklookup(ctxt, "_GLOBAL_OFFSET_TABLE_", 0)
                got.Type = obj.SDYNIMPORT