diff options
| author | Ian Lance Taylor <iant@golang.org> | 2015-04-20 10:32:39 -0700 |
|---|---|---|
| committer | Ian Lance Taylor <iant@golang.org> | 2015-04-20 18:09:41 +0000 |
| commit | 357a013060686aa90432dba93faa01196452eabe (patch) | |
| tree | 6d23e73e5d6abed37dcf4ed0bd8b15a028363ea1 /src/runtime | |
| parent | 725aa3451a73498ed43cf2279f1609a4dffbe04a (diff) | |
| download | go-357a013060686aa90432dba93faa01196452eabe.tar.xz | |
runtime: save registers in linux/{386,amd64} lib entry point
The callee-saved registers must be saved because for the c-shared case
this code is invoked from C code in the system library, and that code
expects the registers to be saved. The tests were passing because in
the normal case the code calls a cgo function that naturally saves
callee-saved registers anyhow. However, it fails when the code takes
the non-cgo path.
Change-Id: I9c1f5e884f5a72db9614478049b1863641c8b2b9
Reviewed-on: https://go-review.googlesource.com/9114
Reviewed-by: David Crawshaw <crawshaw@golang.org>
Diffstat (limited to 'src/runtime')
| -rw-r--r-- | src/runtime/rt0_linux_386.s | 23 | ||||
| -rw-r--r-- | src/runtime/rt0_linux_amd64.s | 22 |
2 files changed, 38 insertions, 7 deletions
diff --git a/src/runtime/rt0_linux_386.s b/src/runtime/rt0_linux_386.s index 14d9f54826..f98642bc03 100644 --- a/src/runtime/rt0_linux_386.s +++ b/src/runtime/rt0_linux_386.s @@ -14,12 +14,20 @@ TEXT _rt0_386_linux(SB),NOSPLIT,$8 // When building with -buildmode=c-shared, this symbol is called when the shared // library is loaded. -TEXT _rt0_386_linux_lib(SB),NOSPLIT,$12 - MOVL 16(SP), AX +TEXT _rt0_386_linux_lib(SB),NOSPLIT,$0 + PUSHL BP + MOVL SP, BP + PUSHL BX + PUSHL SI + PUSHL DI + + MOVL 8(BP), AX MOVL AX, _rt0_386_linux_lib_argc<>(SB) - MOVL 20(SP), AX + MOVL 12(BP), AX MOVL AX, _rt0_386_linux_lib_argv<>(SB) + SUBL $8, SP + // Create a new thread to do the runtime initialization. MOVL _cgo_sys_thread_create(SB), AX TESTL AX, AX @@ -28,7 +36,7 @@ TEXT _rt0_386_linux_lib(SB),NOSPLIT,$12 MOVL BX, 0(SP) MOVL $0, 4(SP) CALL AX - RET + JMP restore nocgo: MOVL $0x800000, 0(SP) // stacksize = 8192KB @@ -37,6 +45,13 @@ nocgo: MOVL $0, 8(SP) // fnarg MOVL $runtime·newosproc0(SB), AX CALL AX + +restore: + ADDL $8, SP + POPL DI + POPL SI + POPL BX + POPL BP RET TEXT _rt0_386_linux_lib_go(SB),NOSPLIT,$12 diff --git a/src/runtime/rt0_linux_amd64.s b/src/runtime/rt0_linux_amd64.s index 9010aba271..ee1dbc6cd1 100644 --- a/src/runtime/rt0_linux_amd64.s +++ b/src/runtime/rt0_linux_amd64.s @@ -12,7 +12,14 @@ TEXT _rt0_amd64_linux(SB),NOSPLIT,$-8 // When building with -buildmode=c-shared, this symbol is called when the shared // library is loaded. -TEXT _rt0_amd64_linux_lib(SB),NOSPLIT,$40 +TEXT _rt0_amd64_linux_lib(SB),NOSPLIT,$0x58 + MOVQ BX, 0x18(SP) + MOVQ BP, 0x20(SP) + MOVQ R12, 0x28(SP) + MOVQ R13, 0x30(SP) + MOVQ R14, 0x38(SP) + MOVQ R15, 0x40(SP) + MOVQ DI, _rt0_amd64_linux_lib_argc<>(SB) MOVQ SI, _rt0_amd64_linux_lib_argv<>(SB) @@ -23,14 +30,23 @@ TEXT _rt0_amd64_linux_lib(SB),NOSPLIT,$40 MOVQ $_rt0_amd64_linux_lib_go(SB), DI MOVQ $0, SI CALL AX - RET + JMP restore + 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 $0, 0x10(SP) // fnarg MOVQ $runtime·newosproc0(SB), AX CALL AX + +restore: + MOVQ 0x18(SP), BX + MOVQ 0x20(SP), BP + MOVQ 0x28(SP), R12 + MOVQ 0x30(SP), R13 + MOVQ 0x38(SP), R14 + MOVQ 0x40(SP), R15 RET TEXT _rt0_amd64_linux_lib_go(SB),NOSPLIT,$0 |
