1 # stack-direction.m4 serial 6
2 dnl Copyright (C) 2002-2021 Bruno Haible <bruno@clisp.org>
3 dnl Copyright (C) 2002-2021 Free Software Foundation, Inc.
4 dnl This file is free software, distributed under the terms of the GNU
5 dnl General Public License. As a special exception to the GNU General
6 dnl Public License, this file may be distributed as part of a program
7 dnl that contains a configuration script generated by Autoconf, under
8 dnl the same distribution terms as the rest of that program.
10 # Determine the stack direction. Define the C macro STACK_DIRECTION.
11 AC_DEFUN([SV_STACK_DIRECTION],
13 AC_REQUIRE([AC_CANONICAL_HOST])
14 AC_CACHE_CHECK([for stack direction], [sv_cv_stack_direction_msg], [
16 dnl See the #define STACK_GROWS_DOWNWARD in gcc-3.1/gcc/config/*/*.h.
21 arm* | strongarm* | xscale* | \
24 c1 | c2 | c32 | c34 | c38 | \
57 sv_cv_stack_direction=-1 ;;
64 sv_cv_stack_direction=1 ;;
66 if test $cross_compiling = no; then
67 cat > conftest.c <<EOF
70 find_stack_direction (int *addr, int depth)
75 *addr = addr < &dummy ? 1 : addr == &dummy ? 0 : -1;
76 dir = depth ? find_stack_direction (addr, depth - 1) : 0;
80 main (int argc, char *argv[])
82 printf ("%d\n", find_stack_direction (NULL, argc + 20));
86 AC_TRY_EVAL([ac_link])
87 sv_cv_stack_direction=`./conftest`
89 sv_cv_stack_direction=0
93 case $sv_cv_stack_direction in
94 1) sv_cv_stack_direction_msg="grows up";;
95 -1) sv_cv_stack_direction_msg="grows down";;
96 *) sv_cv_stack_direction_msg="unknown";;
99 AC_DEFINE_UNQUOTED([STACK_DIRECTION], [$sv_cv_stack_direction],
100 [Define as the direction of stack growth for your system.
101 STACK_DIRECTION > 0 => grows toward higher addresses
102 STACK_DIRECTION < 0 => grows toward lower addresses
103 STACK_DIRECTION = 0 => spaghetti stack.])