Skip to content

Commit

Permalink
runtime: align stack in 386 lib startup before calling C function
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Austin Clements <[email protected]>
  • Loading branch information
ianlancetaylor committed Oct 18, 2017
1 parent 4c8e8fc commit 4875459
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/runtime/asm_386.s
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 4875459

Please sign in to comment.