diff options
author | Srdjan Petrovic <spetrovic@google.com> | 2015-03-25 17:50:35 -0700 |
---|---|---|
committer | Ian Lance Taylor <iant@golang.org> | 2015-04-03 01:24:51 +0000 |
commit | e8694c8196e39328d6d61b1f32228d21112008d7 (patch) | |
tree | 3942b490997e3f0800484c4666fdd787e925bf43 /src/runtime/rt0_linux_amd64.s | |
parent | 167562f65200bc01c9ecdcf393dfa2f16de3d9c2 (diff) | |
download | go-e8694c8196e39328d6d61b1f32228d21112008d7.tar.gz go-e8694c8196e39328d6d61b1f32228d21112008d7.zip |
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>
Diffstat (limited to 'src/runtime/rt0_linux_amd64.s')
-rw-r--r-- | src/runtime/rt0_linux_amd64.s | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/src/runtime/rt0_linux_amd64.s b/src/runtime/rt0_linux_amd64.s index 9d9cb34128..0fdb393ee5 100644 --- a/src/runtime/rt0_linux_amd64.s +++ b/src/runtime/rt0_linux_amd64.s @@ -12,11 +12,38 @@ TEXT _rt0_amd64_linux(SB),NOSPLIT,$-8 // When linking with -shared, this symbol is called when the shared library // is loaded. -TEXT _rt0_amd64_linux_lib(SB),NOSPLIT,$0 - // TODO(spetrovic): Do something useful, like calling $main. (Note that - // this has to be done in a separate thread, as main is expected to block.) +TEXT _rt0_amd64_linux_lib(SB),NOSPLIT,$40 + MOVQ DI, _rt0_amd64_linux_lib_argc<>(SB) + MOVQ SI, _rt0_amd64_linux_lib_argv<>(SB) + + // Create a new thread to do the runtime initialization and return. + MOVQ _cgo_sys_thread_create(SB), AX + TESTQ AX, AX + JZ nocgo + MOVQ $_rt0_amd64_linux_lib_go(SB), DI + MOVQ $0, SI + CALL AX + RET +nocgo: + MOVQ $8388608, 0(SP) // stacksize + MOVQ $_rt0_amd64_linux_lib_go(SB), AX + MOVQ AX, 8(SP) // fn + MOVQ $0, 16(SP) // fnarg + MOVQ $runtime·newosproc0(SB), AX + CALL AX RET +TEXT _rt0_amd64_linux_lib_go(SB),NOSPLIT,$0 + MOVQ _rt0_amd64_linux_lib_argc<>(SB), DI + MOVQ _rt0_amd64_linux_lib_argv<>(SB), SI + MOVQ $runtime·rt0_go(SB), AX + JMP AX + +DATA _rt0_amd64_linux_lib_argc<>(SB)/8, $0 +GLOBL _rt0_amd64_linux_lib_argc<>(SB),NOPTR, $8 +DATA _rt0_amd64_linux_lib_argv<>(SB)/8, $0 +GLOBL _rt0_amd64_linux_lib_argv<>(SB),NOPTR, $8 + TEXT main(SB),NOSPLIT,$-8 MOVQ $runtime·rt0_go(SB), AX JMP AX |