diff options
author | Keith Randall <khr@google.com> | 2019-02-05 16:22:38 -0800 |
---|---|---|
committer | Keith Randall <khr@golang.org> | 2019-03-18 20:10:55 +0000 |
commit | d949d0b9252be1fffeadd65183a6bab3acf3de7a (patch) | |
tree | 842d96e7575d306fafd07322dbd7771ba56929ea /src/plugin | |
parent | 991c85a750574a608daf70330e26070f8cd97bb4 (diff) | |
download | go-d949d0b9252be1fffeadd65183a6bab3acf3de7a.tar.gz go-d949d0b9252be1fffeadd65183a6bab3acf3de7a.zip |
cmd/compile: reorganize init functions
Instead of writing an init function per package that does the same
thing for every package, just write that implementation once in the
runtime. Change the compiler to generate a data structure that encodes
the required initialization operations.
Reduces cmd/go binary size by 0.3%+. Most of the init code is gone,
including all the corresponding stack map info. The .inittask
structures that replace them are quite a bit smaller.
Most usefully to me, there is no longer an init function in every -S output.
(There is an .inittask global there, but it's much less distracting.)
After this CL we could change the name of the "init.ializers" function
back to just "init".
Update #6853
R=go1.13
Change-Id: Iec82b205cc52fe3ade4d36406933c97dbc9c01b1
Reviewed-on: https://go-review.googlesource.com/c/go/+/161337
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
Diffstat (limited to 'src/plugin')
-rw-r--r-- | src/plugin/plugin_dlopen.go | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/src/plugin/plugin_dlopen.go b/src/plugin/plugin_dlopen.go index f24093989f..03d3f08717 100644 --- a/src/plugin/plugin_dlopen.go +++ b/src/plugin/plugin_dlopen.go @@ -92,15 +92,13 @@ func open(name string) (*Plugin, error) { plugins[filepath] = p pluginsMu.Unlock() - initStr := make([]byte, len(pluginpath)+6) + initStr := make([]byte, len(pluginpath)+len("..inittask")+1) // +1 for terminating NUL copy(initStr, pluginpath) - copy(initStr[len(pluginpath):], ".init") + copy(initStr[len(pluginpath):], "..inittask") - initFuncPC := C.pluginLookup(h, (*C.char)(unsafe.Pointer(&initStr[0])), &cErr) - if initFuncPC != nil { - initFuncP := &initFuncPC - initFunc := *(*func())(unsafe.Pointer(&initFuncP)) - initFunc() + initTask := C.pluginLookup(h, (*C.char)(unsafe.Pointer(&initStr[0])), &cErr) + if initTask != nil { + doInit(initTask) } // Fill out the value of each plugin symbol. @@ -150,3 +148,7 @@ var ( // lastmoduleinit is defined in package runtime func lastmoduleinit() (pluginpath string, syms map[string]interface{}, errstr string) + +// doInit is defined in package runtime +//go:linkname doInit runtime.doInit +func doInit(t unsafe.Pointer) // t should be a *runtime.initTask |