Chris@10: dnl @synopsis AX_GCC_ALIGNS_STACK([ACTION-IF-YES], [ACTION-IF-NO]) Chris@10: dnl @summary check whether gcc can align stack to 8-byte boundary Chris@10: dnl @category Misc Chris@10: dnl Chris@10: dnl Check to see if we are using a version of gcc that aligns the stack Chris@10: dnl (true in gcc-2.95+, which have the -mpreferred-stack-boundary flag). Chris@10: dnl Also, however, checks whether main() is correctly aligned by the Chris@10: dnl OS/libc/..., as well as for a bug in the stack alignment of gcc-2.95.x Chris@10: dnl (see http://gcc.gnu.org/ml/gcc-bugs/1999-11/msg00259.html). Chris@10: dnl Chris@10: dnl ACTION-IF-YES/ACTION-IF-NO are shell commands to execute if we are Chris@10: dnl using gcc and the stack is/isn't aligned, respectively. Chris@10: dnl Chris@10: dnl Requires macro: AX_CHECK_COMPILER_FLAGS, AX_GCC_VERSION Chris@10: dnl Chris@10: dnl @version 2005-05-30 Chris@10: dnl @license GPLWithACException Chris@10: dnl @author Steven G. Johnson Chris@10: AC_DEFUN([AX_GCC_ALIGNS_STACK], Chris@10: [ Chris@10: AC_REQUIRE([AC_PROG_CC]) Chris@10: ax_gcc_aligns_stack=no Chris@10: if test "$GCC" = "yes"; then Chris@10: AX_CHECK_COMPILER_FLAGS(-mpreferred-stack-boundary=4, [ Chris@10: AC_MSG_CHECKING([whether the stack is at least 8-byte aligned by gcc]) Chris@10: save_CFLAGS="$CFLAGS" Chris@10: CFLAGS="-O" Chris@10: AX_CHECK_COMPILER_FLAGS(-malign-double, CFLAGS="$CFLAGS -malign-double") Chris@10: AC_TRY_RUN([#include Chris@10: # include Chris@10: struct yuck { int blechh; }; Chris@10: int one(void) { return 1; } Chris@10: struct yuck ick(void) { struct yuck y; y.blechh = 3; return y; } Chris@10: # define CHK_ALIGN(x) if ((((long) &(x)) & 0x7)) { fprintf(stderr, "bad alignment of " #x "\n"); exit(1); } Chris@10: void blah(int foo) { double foobar; CHK_ALIGN(foobar); } Chris@10: int main2(void) {double ok1; struct yuck y; double ok2; CHK_ALIGN(ok1); Chris@10: CHK_ALIGN(ok2); y = ick(); blah(one()); return 0;} Chris@10: int main(void) { if ((((long) (__builtin_alloca(0))) & 0x7)) __builtin_alloca(4); return main2(); } Chris@10: ], [ax_gcc_aligns_stack=yes; ax_gcc_stack_align_bug=no], Chris@10: ax_gcc_stack_align_bug=yes, [AX_GCC_VERSION(3,0,0, ax_gcc_stack_align_bug=no, ax_gcc_stack_align_bug=yes)]) Chris@10: CFLAGS="$save_CFLAGS" Chris@10: AC_MSG_RESULT($ax_gcc_aligns_stack) Chris@10: ]) Chris@10: fi Chris@10: if test "$ax_gcc_aligns_stack" = yes; then Chris@10: m4_default([$1], :) Chris@10: else Chris@10: m4_default([$2], :) Chris@10: fi Chris@10: ])