]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: align stack in 386 lib startup before calling C function
authorIan Lance Taylor <iant@golang.org>
Tue, 17 Oct 2017 22:38:13 +0000 (15:38 -0700)
committerIan Lance Taylor <iant@golang.org>
Wed, 18 Oct 2017 16:58:14 +0000 (16:58 +0000)
Fixes Darwin 386 build. It turns out that the Darwin pthread_create
function saves the SSE registers, and therefore requires an aligned stack.
This worked before https://golang.org/cl/70530 because the stack sizes
were chosen to leave the stack aligned.

Change-Id: I911a9e8dcde4e41e595d5ef9b9a1ca733e154de6
Reviewed-on: https://go-review.googlesource.com/71432
Reviewed-by: Robert Griesemer <gri@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
src/runtime/asm_386.s

index 319b61579a4978cfc6aef27c2b5c668567592ec4..ef82756397bbd85c05decd9d2432be8a2d511edb 100644 (file)
@@ -45,14 +45,20 @@ TEXT _rt0_386_lib(SB),NOSPLIT,$0
        MOVL    _cgo_sys_thread_create(SB), AX
        TESTL   AX, AX
        JZ      nocgo
+
+       // Align stack to call C function.
+       // We moved SP to BP above, but BP was clobbered by the libpreinit call.
+       MOVL    SP, BP
+       ANDL    $~15, SP
+
        MOVL    $_rt0_386_lib_go(SB), BX
        MOVL    BX, 0(SP)
        MOVL    $0, 4(SP)
 
-       // TODO: We are calling a C function here so we should be
-       // aligning the stack.
-
        CALL    AX
+
+       MOVL    BP, SP
+
        JMP     restore
 
 nocgo: