1# stack-direction.m4 serial 2 (libsigsegv-2.11) 2dnl Copyright (C) 2002-2009, 2013-2014 Bruno Haible <bruno@clisp.org> 3dnl This file is free software, distributed under the terms of the GNU 4dnl General Public License. As a special exception to the GNU General 5dnl Public License, this file may be distributed as part of a program 6dnl that contains a configuration script generated by Autoconf, under 7dnl the same distribution terms as the rest of that program. 8 9# Determine the stack direction. Define the C macro STACK_DIRECTION. 10AC_DEFUN([SV_STACK_DIRECTION], 11[ 12 AC_CACHE_CHECK([for stack direction], [sv_cv_stack_direction_msg], [ 13 case "$host_cpu" in 14 dnl See the #define STACK_GROWS_DOWNWARD in gcc-3.1/gcc/config/*/*.h. 15 a29k | \ 16 aarch64* | \ 17 alpha* | \ 18 arc | \ 19 arm* | strongarm* | xscale* | \ 20 avr | avr32 | \ 21 bfin | \ 22 c1 | c2 | c32 | c34 | c38 | \ 23 clipper | \ 24 cris | \ 25 d30v | \ 26 elxsi | \ 27 fr30 | \ 28 h8300 | \ 29 i?86 | x86_64 | \ 30 i860 | \ 31 ia64 | \ 32 m32r | \ 33 m68* | \ 34 m88k | \ 35 mcore | \ 36 microblaze | \ 37 mips* | \ 38 mmix | \ 39 mn10200 | \ 40 mn10300 | \ 41 nios2 | \ 42 ns32k | \ 43 pdp11 | \ 44 pj* | \ 45 powerpc* | rs6000 | \ 46 romp | \ 47 s390* | \ 48 sh* | \ 49 sparc* | \ 50 v850 | \ 51 vax | \ 52 xtensa) 53 sv_cv_stack_direction=-1 ;; 54 c4x | \ 55 dsp16xx | \ 56 i960 | \ 57 hppa* | parisc* | \ 58 stormy16 | \ 59 we32k) 60 sv_cv_stack_direction=1 ;; 61 *) 62 if test $cross_compiling = no; then 63 cat > conftest.c <<EOF 64#include <stdio.h> 65int 66get_stack_direction () 67{ 68 auto char dummy; 69 static char *dummyaddr = (char *)0; 70 if (dummyaddr != (char *)0) 71 return &dummy > dummyaddr ? 1 : &dummy < dummyaddr ? -1 : 0; 72 else 73 { 74 dummyaddr = &dummy; 75 { 76 int result = get_stack_direction (); 77 /* The next assignment avoids tail recursion elimination 78 (IRIX 6.4 CC). */ 79 dummyaddr = (char *)0; 80 return result; 81 } 82 } 83} 84int 85main () 86{ 87 printf ("%d\n", get_stack_direction ()); 88 return 0; 89} 90EOF 91 AC_TRY_EVAL([ac_link]) 92 sv_cv_stack_direction=`./conftest` 93 else 94 sv_cv_stack_direction=0 95 fi 96 ;; 97 esac 98 case $sv_cv_stack_direction in 99 1) sv_cv_stack_direction_msg="grows up";; 100 -1) sv_cv_stack_direction_msg="grows down";; 101 *) sv_cv_stack_direction_msg="unknown";; 102 esac 103 ]) 104 AC_DEFINE_UNQUOTED([STACK_DIRECTION], [$sv_cv_stack_direction], 105 [Define as the direction of stack growth for your system. 106 STACK_DIRECTION > 0 => grows toward higher addresses 107 STACK_DIRECTION < 0 => grows toward lower addresses 108 STACK_DIRECTION = 0 => spaghetti stack.]) 109]) 110