diff options
author | Than McIntosh <thanm@google.com> | 2019-09-04 11:25:06 -0400 |
---|---|---|
committer | Than McIntosh <thanm@google.com> | 2019-09-06 12:16:32 +0000 |
commit | b1a20253fe8a1f099a23735c9a613b433df67261 (patch) | |
tree | e2b1e5cc57c0b7afccfa5047afa6ca684d01e83e /src | |
parent | c7dc5e92ddb7c6d4e71edd7f24f9314e81a8413b (diff) | |
download | go-git-b1a20253fe8a1f099a23735c9a613b433df67261.tar.gz |
cmd/link: memoize/cache whether plugin.Open symbol available
Perform a single lookup of "plugin.Open" at the point where we set the
loaded flag for the context, then cache whether the result is nil, so
that we can consult this cached value later on (instead of having to
look up the symbol each time). This helps speed up the DynLinkingGo()
context method, which is called from within some very hot loops in the
linker (when linking 'hyperkube' from kubernetes, reduces total calls
to "sym.(*Symbols).ROLookup" from 6.5M to 4.3M)
Change-Id: I92a2ea2b21d24f67aec0a7afeef4acc77c095adf
Reviewed-on: https://go-review.googlesource.com/c/go/+/193260
Reviewed-by: Jeremy Faller <jeremy@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/cmd/link/internal/ld/lib.go | 10 | ||||
-rw-r--r-- | src/cmd/link/internal/ld/link.go | 1 |
2 files changed, 9 insertions, 2 deletions
diff --git a/src/cmd/link/internal/ld/lib.go b/src/cmd/link/internal/ld/lib.go index 92dc9ba061..1deab660b7 100644 --- a/src/cmd/link/internal/ld/lib.go +++ b/src/cmd/link/internal/ld/lib.go @@ -173,12 +173,15 @@ func (ctxt *Link) DynlinkingGo() bool { if !ctxt.Loaded { panic("DynlinkingGo called before all symbols loaded") } - return ctxt.BuildMode == BuildModeShared || ctxt.linkShared || ctxt.BuildMode == BuildModePlugin || ctxt.CanUsePlugins() + return ctxt.BuildMode == BuildModeShared || ctxt.linkShared || ctxt.BuildMode == BuildModePlugin || ctxt.canUsePlugins } // CanUsePlugins reports whether a plugins can be used func (ctxt *Link) CanUsePlugins() bool { - return ctxt.Syms.ROLookup("plugin.Open", sym.SymVerABIInternal) != nil + if !ctxt.Loaded { + panic("CanUsePlugins called before all symbols loaded") + } + return ctxt.canUsePlugins } // UseRelro reports whether to make use of "read only relocations" aka @@ -595,6 +598,9 @@ func (ctxt *Link) loadlib() { // We've loaded all the code now. ctxt.Loaded = true + // Record whether we can use plugins. + ctxt.canUsePlugins = (ctxt.Syms.ROLookup("plugin.Open", sym.SymVerABIInternal) != nil) + // If there are no dynamic libraries needed, gcc disables dynamic linking. // Because of this, glibc's dynamic ELF loader occasionally (like in version 2.13) // assumes that a dynamic binary always refers to at least one dynamic library. diff --git a/src/cmd/link/internal/ld/link.go b/src/cmd/link/internal/ld/link.go index d3ffacf54e..dc39f084bf 100644 --- a/src/cmd/link/internal/ld/link.go +++ b/src/cmd/link/internal/ld/link.go @@ -67,6 +67,7 @@ type Link struct { linkShared bool // link against installed Go shared libraries LinkMode LinkMode BuildMode BuildMode + canUsePlugins bool // initialized when Loaded is set to true compressDWARF bool Tlsg *sym.Symbol |