From: Russ Cox Date: Wed, 5 Aug 2015 03:44:06 +0000 (-0400) Subject: runtime: align stack pointer during initcgo call on arm X-Git-Tag: go1.5rc1~25 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=2a60d77059201c9f1f09cb4885f690859d7bc643;p=gostls13.git runtime: align stack pointer during initcgo call on arm This is what is causing freebsd/arm to crash mysteriously when using cgo. The bug was introduced in golang.org/cl/4030, which moved this code out of rt0_go and into its own function. The ARM ABI says that calls must be made with the stack pointer at an 8-byte boundary, but only FreeBSD seems to crash when this is violated. Fixes #10119. Change-Id: Ibdbe76b2c7b80943ab66b8abbb38b47acb70b1e5 Reviewed-on: https://go-review.googlesource.com/13161 Reviewed-by: Ian Lance Taylor Reviewed-by: Dave Cheney --- diff --git a/src/runtime/tls_arm.s b/src/runtime/tls_arm.s index d130d42cf2..d37970e1f8 100644 --- a/src/runtime/tls_arm.s +++ b/src/runtime/tls_arm.s @@ -77,7 +77,17 @@ TEXT runtime·load_g(SB),NOSPLIT,$0 MOVW 0(R0), g RET -TEXT runtime·_initcgo(SB),NOSPLIT,$0 +// This is called from rt0_go, which runs on the system stack +// using the initial stack allocated by the OS. +// It calls back into standard C using the BL (R4) below. +// To do that, the stack pointer must be 8-byte-aligned +// on some systems, notably FreeBSD. +// The ARM ABI says the stack pointer must be 8-byte-aligned +// on entry to any function, but only FreeBSD's C library seems to care. +// The caller was 8-byte aligned, but we push an LR. +// Declare a dummy word ($4, not $0) to make sure the +// frame is 8 bytes and stays 8-byte-aligned. +TEXT runtime·_initcgo(SB),NOSPLIT,$4 #ifndef GOOS_nacl // if there is an _cgo_init, call it. MOVW _cgo_init(SB), R4