This is the mail archive of the
libffi-discuss@sourceware.org
mailing list for the libffi project.
[PATCH] x86: Align the stack to 16-bytes before making the call
- From: Andrew Haley <aph at redhat dot com>
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>, libffi-discuss at sourceware dot org
- Date: Wed, 07 Jul 2010 16:58:54 +0100
- Subject: [PATCH] x86: Align the stack to 16-bytes before making the call
Applied for Neil Roberts to gcc trunk.
Andrew.
>From 89d2865bcf30bc020399a74b3053d46ef7750a28 Mon Sep 17 00:00:00 2001
From: Neil Roberts <neil@linux.intel.com>
Date: Fri, 26 Feb 2010 14:42:49 +0000
Subject: [PATCH] x86: Align the stack to 16-bytes before making the call
If gcc is targetting i686 then it will use SSE registers for the
floating point operations. It will then sometimes use 16-byte
temporary variables on the stack to store the registers and it will
use aligned instructions to access them. This will segfault if the
variable is not aligned to 16-bytes. Apparently GCC assumes that the
stack is 16-byte aligned when a function is entered and it uses this
to position its temporary variables. Therefore libffi needs to align
the stack or the called function will crash in some circumstances.
2010-07-07 Neil Roberts <neil@linux.intel.com>
* src/x86/sysv.S (ffi_call_SYSV): Align the stack pointer to
16-bytes.
Index: libffi/src/x86/sysv.S
===================================================================
--- libffi/src/x86/sysv.S (revision 161921)
+++ libffi/src/x86/sysv.S (working copy)
@@ -48,6 +48,9 @@
movl 16(%ebp),%ecx
subl %ecx,%esp
+ /* Align the stack pointer to 16-bytes */
+ andl $0xfffffff0, %esp
+
movl %esp,%eax
/* Place all of the ffi_prep_args in position */