[Pixman] [PATCH 3/3] configure.ac: Use -mstackrealign on x86-32 for SSE2 and SSSE3

Søren Sandmann sandmann at cs.au.dk
Thu Oct 10 13:19:36 PDT 2013


From: Søren Sandmann Pedersen <ssp at redhat.com>

Code compiled by GCC with -msse2 and -mssse3 assumes a 16 byte aligned
stack, but on x86-32 such alignment is not guaranteed.

Instead of using the __force_align_arg_pointer__ attribute on all
entry points that could potentially call into code compiled with
-msse2 or -mssse3, just compile pixman-sse2.c and pixman-ssse3.c with
-mstackrealign when the target CPU is x86-32 and the compiler supports
this option.

This fixes the glyph-test crash introduced by the previous commit and
also

     https://bugs.freedesktop.org/show_bug.cgi?id=68300

V2: Simply add -mstackrealign on x86-32 when the compiler appears to
support it instead of trying to detect the GCC version specifically.
---
 configure.ac         |   16 ++++++++++++----
 pixman/pixman-sse2.c |    6 ------
 pixman/pixman.c      |   19 -------------------
 3 files changed, 12 insertions(+), 29 deletions(-)

diff --git a/configure.ac b/configure.ac
index 68d8d6e..4875a6d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -59,6 +59,7 @@ m4_define([pixman_micro], 1)
 m4_define([pixman_version],[pixman_major.pixman_minor.pixman_micro])
 
 AC_INIT(pixman, pixman_version, [pixman at lists.freedesktop.org], pixman)
+AC_CANONICAL_SYSTEM
 AM_INIT_AUTOMAKE([foreign dist-bzip2])
 
 # Suppress verbose compile lines
@@ -66,8 +67,6 @@ m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
 
 AC_CONFIG_HEADERS(config.h)
 
-AC_CANONICAL_HOST
-
 test_CFLAGS=${CFLAGS+set} # We may override autoconf default CFLAGS.
 
 AC_PROG_CC
@@ -391,6 +390,15 @@ fi
 AM_CONDITIONAL(USE_X86_MMX, test $have_mmx_intrinsics = yes)
 
 dnl ===========================================================================
+dnl Detect whether -mstackrealign is useful
+case $target_cpu in
+   i[[34567]]86)
+	PIXMAN_CHECK_CFLAG(-mstackrealign,,[STACKREALIGN="-mstackrealign"])
+	;;
+esac
+
+echo the target cpu is $target_cpu
+dnl ===========================================================================
 dnl Check for SSE2
 
 if test "x$SSE2_CFLAGS" = "x" ; then
@@ -400,7 +408,7 @@ if test "x$SSE2_CFLAGS" = "x" ; then
          SSE2_CFLAGS="-xarch=sse2"
       fi
    else
-      SSE2_CFLAGS="-msse2 -Winline"
+      SSE2_CFLAGS="-msse2 -Winline $STACKREALIGN"
    fi
 fi
 
@@ -449,7 +457,7 @@ dnl ===========================================================================
 dnl Check for SSSE3
 
 if test "x$SSSE3_CFLAGS" = "x" ; then
-    SSSE3_CFLAGS="-mssse3 -Winline"
+    SSSE3_CFLAGS="-mssse3 -Winline $STACKREALIGN"
 fi
 
 have_ssse3_intrinsics=no
diff --git a/pixman/pixman-sse2.c b/pixman/pixman-sse2.c
index 2ab2690..5d326f4 100644
--- a/pixman/pixman-sse2.c
+++ b/pixman/pixman-sse2.c
@@ -3312,9 +3312,6 @@ sse2_composite_over_n_8_8888 (pixman_implementation_t *imp,
 
 }
 
-#if defined(__GNUC__) && !defined(__x86_64__) && !defined(__amd64__)
-__attribute__((__force_align_arg_pointer__))
-#endif
 static pixman_bool_t
 sse2_fill (pixman_implementation_t *imp,
            uint32_t *               bits,
@@ -6411,9 +6408,6 @@ static const pixman_iter_info_t sse2_iters[] =
     { PIXMAN_null },
 };
 
-#if defined(__GNUC__) && !defined(__x86_64__) && !defined(__amd64__)
-__attribute__((__force_align_arg_pointer__))
-#endif
 pixman_implementation_t *
 _pixman_implementation_create_sse2 (pixman_implementation_t *fallback)
 {
diff --git a/pixman/pixman.c b/pixman/pixman.c
index 9555cea..5490e59 100644
--- a/pixman/pixman.c
+++ b/pixman/pixman.c
@@ -547,25 +547,6 @@ analyze_extent (pixman_image_t       *image,
     return TRUE;
 }
 
-/*
- * Work around GCC bug causing crashes in Mozilla with SSE2
- *
- * When using -msse, gcc generates movdqa instructions assuming that
- * the stack is 16 byte aligned. Unfortunately some applications, such
- * as Mozilla and Mono, end up aligning the stack to 4 bytes, which
- * causes the movdqa instructions to fail.
- *
- * The __force_align_arg_pointer__ makes gcc generate a prologue that
- * realigns the stack pointer to 16 bytes.
- *
- * On x86-64 this is not necessary because the standard ABI already
- * calls for a 16 byte aligned stack.
- *
- * See https://bugs.freedesktop.org/show_bug.cgi?id=15693
- */
-#if defined (USE_SSE2) && defined(__GNUC__) && !defined(__x86_64__) && !defined(__amd64__)
-__attribute__((__force_align_arg_pointer__))
-#endif
 PIXMAN_EXPORT void
 pixman_image_composite32 (pixman_op_t      op,
                           pixman_image_t * src,
-- 
1.7.1



More information about the Pixman mailing list