aboutsummaryrefslogtreecommitdiff
path: root/src/cmd
diff options
context:
space:
mode:
authorDavid Crawshaw <crawshaw@golang.org>2016-10-30 23:53:09 -0400
committerDavid Crawshaw <crawshaw@golang.org>2016-11-01 20:56:30 +0000
commitd0e408334be22158fbf58a4d02789a48f5cb911e (patch)
treefb60bd9dda17d4410751bd85bd028f12a4cac76f /src/cmd
parente22c79660d96187b672a92622d171066a0d5c5c2 (diff)
downloadgo-d0e408334be22158fbf58a4d02789a48f5cb911e.tar.xz
cmd/link: support plugins with no exported symbols
A plugin with no exported symbols is still potentially very useful. Its init functions are called on load, and it so it can have visible side effects. Fixes #17681 Change-Id: Icdca31f48e5ab13c99020a2ef724f3de47dcd74b Reviewed-on: https://go-review.googlesource.com/32437 Run-TryBot: David Crawshaw <crawshaw@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/cmd')
-rw-r--r--src/cmd/link/internal/ld/deadcode.go6
-rw-r--r--src/cmd/link/internal/ld/symtab.go3
2 files changed, 5 insertions, 4 deletions
diff --git a/src/cmd/link/internal/ld/deadcode.go b/src/cmd/link/internal/ld/deadcode.go
index 7ecc5b1ec2..ac64813228 100644
--- a/src/cmd/link/internal/ld/deadcode.go
+++ b/src/cmd/link/internal/ld/deadcode.go
@@ -252,8 +252,10 @@ func (d *deadcodepass) init() {
// We don't keep the go.plugin.exports symbol,
// but we do keep the symbols it refers to.
exports := d.ctxt.Syms.ROLookup("go.plugin.exports", 0)
- for _, r := range exports.R {
- d.mark(r.Sym, nil)
+ if exports != nil {
+ for _, r := range exports.R {
+ d.mark(r.Sym, nil)
+ }
}
}
for _, name := range markextra {
diff --git a/src/cmd/link/internal/ld/symtab.go b/src/cmd/link/internal/ld/symtab.go
index ef96c04067..323136c6f9 100644
--- a/src/cmd/link/internal/ld/symtab.go
+++ b/src/cmd/link/internal/ld/symtab.go
@@ -588,8 +588,7 @@ func (ctxt *Link) symtab() {
adduint(ctxt, moduledata, uint64(nitablinks))
adduint(ctxt, moduledata, uint64(nitablinks))
// The ptab slice
- if Buildmode == BuildmodePlugin {
- ptab := ctxt.Syms.ROLookup("go.plugin.tabs", 0)
+ if ptab := ctxt.Syms.ROLookup("go.plugin.tabs", 0); ptab != nil {
ptab.Attr |= AttrReachable
ptab.Attr |= AttrLocal
ptab.Type = obj.SRODATA