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>
This commit is contained in:
David Crawshaw 2016-10-30 23:53:09 -04:00
parent e22c79660d
commit d0e408334b
5 changed files with 32 additions and 4 deletions

View file

@ -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 {