1 # stack-direction.m4 serial 7
2 dnl Copyright (C) 2002-2021 Free Software Foundation, Inc.
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 dnl Written by Bruno Haible.
11 # Determine the stack direction. Define the C macro STACK_DIRECTION.
12 AC_DEFUN([SV_STACK_DIRECTION],
14 AC_REQUIRE([AC_CANONICAL_HOST])
15 AC_CACHE_CHECK([for stack direction], [sv_cv_stack_direction_msg], [
17 dnl See the #define STACK_GROWS_DOWNWARD in gcc-3.1/gcc/config/*/*.h.
22 arm* | strongarm* | xscale* | \
25 c1 | c2 | c32 | c34 | c38 | \
58 sv_cv_stack_direction=-1 ;;
65 sv_cv_stack_direction=1 ;;
67 if test $cross_compiling = no; then
68 cat > conftest.c <<EOF
71 find_stack_direction (int *addr, int depth)
76 *addr = addr < &dummy ? 1 : addr == &dummy ? 0 : -1;
77 dir = depth ? find_stack_direction (addr, depth - 1) : 0;
81 main (int argc, char *argv[])
83 printf ("%d\n", find_stack_direction (NULL, argc + 20));
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.])