diff options
| author | David Crawshaw <crawshaw@golang.org> | 2016-08-25 21:58:45 -0400 |
|---|---|---|
| committer | David Crawshaw <crawshaw@golang.org> | 2016-09-16 14:49:13 +0000 |
| commit | eced6754c2f2ce98cb5bacbdbfcbbaa4a6a69d53 (patch) | |
| tree | 0450fbe9c27799556daef1148c816e3645c61ccc /src/cmd/link/internal/amd64 | |
| parent | 79167bbd9c71017e18836a3e5e40261b57012358 (diff) | |
| download | go-eced6754c2f2ce98cb5bacbdbfcbbaa4a6a69d53.tar.xz | |
cmd/link: -buildmode=plugin support for linux
This CL contains several linker changes to support creating plugins.
It collects the exported plugin symbols provided by the compiler and
includes them in the moduledata.
It treats a binary as being dynamically linked if it imports the plugin
package. This lets the dynamic linker de-duplicate symbols.
Change-Id: I099b6f38dda26306eba5c41dbe7862f5a5918d95
Reviewed-on: https://go-review.googlesource.com/27820
Run-TryBot: David Crawshaw <crawshaw@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/cmd/link/internal/amd64')
| -rw-r--r-- | src/cmd/link/internal/amd64/asm.go | 5 | ||||
| -rw-r--r-- | src/cmd/link/internal/amd64/obj.go | 4 |
2 files changed, 4 insertions, 5 deletions
diff --git a/src/cmd/link/internal/amd64/asm.go b/src/cmd/link/internal/amd64/asm.go index 0d8444eea4..ea31d6a739 100644 --- a/src/cmd/link/internal/amd64/asm.go +++ b/src/cmd/link/internal/amd64/asm.go @@ -59,7 +59,7 @@ func gentext(ctxt *ld.Link) { return } addmoduledata := ld.Linklookup(ctxt, "runtime.addmoduledata", 0) - if addmoduledata.Type == obj.STEXT { + if addmoduledata.Type == obj.STEXT && ld.Buildmode != ld.BuildmodePlugin { // we're linking a module containing the runtime -> no need for // an init function return @@ -86,6 +86,9 @@ func gentext(ctxt *ld.Link) { // c: c3 retq o(0xc3) ctxt.Textp = append(ctxt.Textp, initfunc) + if ld.Buildmode == ld.BuildmodePlugin { + ctxt.Textp = append(ctxt.Textp, addmoduledata) + } initarray_entry := ld.Linklookup(ctxt, "go.link.addmoduledatainit", 0) initarray_entry.Attr |= ld.AttrReachable initarray_entry.Attr |= ld.AttrLocal diff --git a/src/cmd/link/internal/amd64/obj.go b/src/cmd/link/internal/amd64/obj.go index 0494050d86..5f85b0b2b3 100644 --- a/src/cmd/link/internal/amd64/obj.go +++ b/src/cmd/link/internal/amd64/obj.go @@ -90,10 +90,6 @@ func archinit(ctxt *ld.Link) { ld.Linkmode = ld.LinkInternal } - if ld.Buildmode == ld.BuildmodeCArchive || ld.Buildmode == ld.BuildmodeCShared || ctxt.DynlinkingGo() { - ld.Linkmode = ld.LinkExternal - } - switch ld.Headtype { default: if ld.Linkmode == ld.LinkAuto { |
