runtime: initialize shared library at library-load time

This is Part 2 of the change, see Part 1 here: in https://go-review.googlesource.com/#/c/7692/

Suggested by iant@, we use the library initialization entry point to:
    - create a new OS thread and run the "regular" runtime init stack on
      that thread
    - return immediately from the main (i.e., loader) thread
    - at the first CGO invocation, we wait for the runtime initialization
      to complete.

The above mechanism is implemented only on linux_amd64.  Next step is to
support it on linux_arm.  Other platforms don't yet support shared library
compiling/linking, but we intend to use the same strategy there as well.

Change-Id: Ib2c81b1b83bee837134084b75a3beecfb8de6bf4
Reviewed-on: https://go-review.googlesource.com/8094
Run-TryBot: Srdjan Petrovic <spetrovic@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
Srdjan Petrovic 2015-03-25 17:50:35 -07:00 committed by Ian Lance Taylor
parent 167562f652
commit e8694c8196
18 changed files with 263 additions and 18 deletions

View file

@ -66,6 +66,10 @@ func main() {
gcenable()
if islibrary {
// Allocate new M as main_main() is expected to block forever.
systemstack(newextram)
}
if iscgo {
if _cgo_thread_start == nil {
throw("_cgo_thread_start missing")
@ -84,6 +88,10 @@ func main() {
throw("_cgo_unsetenv missing")
}
}
if _cgo_notify_runtime_init_done == nil {
throw("_cgo_notify_runtime_init_done missing")
}
cgocall(_cgo_notify_runtime_init_done, nil)
}
main_init()