1 # stack-direction.m4 serial 1 (libsigsegv-2.8)
2 dnl Copyright (C) 2002-2009 Bruno Haible <bruno@clisp.org>
3 dnl This file is free software, distributed under the terms of the GNU
4 dnl General Public License. As a special exception to the GNU General
5 dnl Public License, this file may be distributed as part of a program
6 dnl that contains a configuration script generated by Autoconf, under
7 dnl the same distribution terms as the rest of that program.
9 # Determine the stack direction. Define the C macro STACK_DIRECTION.
10 AC_DEFUN([SV_STACK_DIRECTION],
12 AC_CACHE_CHECK([for stack direction], [sv_cv_stack_direction_msg], [
14 dnl See the #define STACK_GROWS_DOWNWARD in gcc-3.1/gcc/config/*/*.h.
18 arm* | strongarm* | xscale* | \
20 c1 | c2 | c32 | c34 | c38 | \
49 sv_cv_stack_direction=-1 ;;
56 sv_cv_stack_direction=1 ;;
58 if test $cross_compiling = no; then
59 cat > conftest.c <<EOF
62 get_stack_direction ()
65 static char *dummyaddr = (char *)0;
66 if (dummyaddr != (char *)0)
67 return &dummy > dummyaddr ? 1 : &dummy < dummyaddr ? -1 : 0;
72 int result = get_stack_direction ();
73 /* The next assignment avoids tail recursion elimination
75 dummyaddr = (char *)0;
83 printf ("%d\n", get_stack_direction ());
87 AC_TRY_EVAL([ac_link])
88 sv_cv_stack_direction=`./conftest`
90 sv_cv_stack_direction=0
94 case $sv_cv_stack_direction in
95 1) sv_cv_stack_direction_msg="grows up";;
96 -1) sv_cv_stack_direction_msg="grows down";;
97 *) sv_cv_stack_direction_msg="unknown";;
100 AC_DEFINE_UNQUOTED([STACK_DIRECTION], [$sv_cv_stack_direction],
101 [Define as the direction of stack growth for your system.
102 STACK_DIRECTION > 0 => grows toward higher addresses
103 STACK_DIRECTION < 0 => grows toward lower addresses
104 STACK_DIRECTION = 0 => spaghetti stack.])