From eced6754c2f2ce98cb5bacbdbfcbbaa4a6a69d53 Mon Sep 17 00:00:00 2001 From: David Crawshaw Date: Thu, 25 Aug 2016 21:58:45 -0400 Subject: 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 TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/cmd/link/internal/ld/deadcode.go | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/cmd/link/internal/ld/deadcode.go') diff --git a/src/cmd/link/internal/ld/deadcode.go b/src/cmd/link/internal/ld/deadcode.go index 9f49cf2dfc..6d3f74a039 100644 --- a/src/cmd/link/internal/ld/deadcode.go +++ b/src/cmd/link/internal/ld/deadcode.go @@ -243,6 +243,16 @@ func (d *deadcodepass) init() { names = append(names, *flagEntrySymbol) if *FlagLinkshared && (Buildmode == BuildmodeExe || Buildmode == BuildmodePIE) { names = append(names, "main.main", "main.init") + } else if Buildmode == BuildmodePlugin { + pluginInit := d.ctxt.Library[0].Pkg + ".init" + names = append(names, pluginInit, "go.plugin.tabs") + + // We don't keep the go.plugin.exports symbol, + // but we do keep the symbols it refers to. + exports := Linkrlookup(d.ctxt, "go.plugin.exports", 0) + for _, r := range exports.R { + d.mark(r.Sym, nil) + } } for _, name := range markextra { names = append(names, name) -- cgit v1.3-5-g9baa