]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: align stack pointer during initcgo call on arm
authorRuss Cox <rsc@golang.org>
Wed, 5 Aug 2015 03:44:06 +0000 (23:44 -0400)
committerRuss Cox <rsc@golang.org>
Wed, 5 Aug 2015 05:31:34 +0000 (05:31 +0000)
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>
src/runtime/tls_arm.s

index d130d42cf2ef7e8bcf1a81eb32249fc35db1dd83..d37970e1f831e6ac46a646ce8b5722ba7d856e8f 100644 (file)
@@ -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