diff options
author | Russ Cox <rsc@golang.org> | 2015-08-04 23:44:06 -0400 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2015-08-05 05:31:34 +0000 |
commit | 2a60d77059201c9f1f09cb4885f690859d7bc643 (patch) | |
tree | ff5caa8443a4603f40c184eb2f6ba2753bfdc9a2 | |
parent | 31b0b73924e83fe3341e5c5ebca8854febcb3157 (diff) | |
download | go-2a60d77059201c9f1f09cb4885f690859d7bc643.tar.gz go-2a60d77059201c9f1f09cb4885f690859d7bc643.zip |
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 <iant@golang.org>
Reviewed-by: Dave Cheney <dave@cheney.net>
-rw-r--r-- | src/runtime/tls_arm.s | 12 |
1 files changed, 11 insertions, 1 deletions
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 |