Commit 2a60d770 authored by Russ Cox's avatar Russ Cox

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/13161Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
Reviewed-by: default avatarDave Cheney <dave@cheney.net>
parent 31b0b739
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment