| 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.
|
|---|
| 8 |
|
|---|
| 9 | dnl Written by Bruno Haible.
|
|---|
| 10 |
|
|---|
| 11 | # Determine the stack direction. Define the C macro STACK_DIRECTION.
|
|---|
| 12 | AC_DEFUN([SV_STACK_DIRECTION],
|
|---|
| 13 | [
|
|---|
| 14 | AC_REQUIRE([AC_CANONICAL_HOST])
|
|---|
| 15 | AC_CACHE_CHECK([for stack direction], [sv_cv_stack_direction_msg], [
|
|---|
| 16 | case "$host_cpu" in
|
|---|
| 17 | dnl See the #define STACK_GROWS_DOWNWARD in gcc-3.1/gcc/config/*/*.h.
|
|---|
| 18 | a29k | \
|
|---|
| 19 | aarch64* | \
|
|---|
| 20 | alpha* | \
|
|---|
| 21 | arc | \
|
|---|
| 22 | arm* | strongarm* | xscale* | \
|
|---|
| 23 | avr | avr32 | \
|
|---|
| 24 | bfin | \
|
|---|
| 25 | c1 | c2 | c32 | c34 | c38 | \
|
|---|
| 26 | clipper | \
|
|---|
| 27 | cris | \
|
|---|
| 28 | d30v | \
|
|---|
| 29 | elxsi | \
|
|---|
| 30 | fr30 | \
|
|---|
| 31 | h8300 | \
|
|---|
| 32 | i?86 | x86_64 | \
|
|---|
| 33 | i860 | \
|
|---|
| 34 | ia64 | \
|
|---|
| 35 | m32r | \
|
|---|
| 36 | m68* | \
|
|---|
| 37 | m88k | \
|
|---|
| 38 | mcore | \
|
|---|
| 39 | microblaze | \
|
|---|
| 40 | mips* | \
|
|---|
| 41 | mmix | \
|
|---|
| 42 | mn10200 | \
|
|---|
| 43 | mn10300 | \
|
|---|
| 44 | nios2 | \
|
|---|
| 45 | nds32* | \
|
|---|
| 46 | ns32k | \
|
|---|
| 47 | pdp11 | \
|
|---|
| 48 | pj* | \
|
|---|
| 49 | powerpc* | rs6000 | \
|
|---|
| 50 | riscv* | \
|
|---|
| 51 | romp | \
|
|---|
| 52 | s390* | \
|
|---|
| 53 | sh* | \
|
|---|
| 54 | sparc* | \
|
|---|
| 55 | v850 | \
|
|---|
| 56 | vax | \
|
|---|
| 57 | xtensa)
|
|---|
| 58 | sv_cv_stack_direction=-1 ;;
|
|---|
| 59 | c4x | \
|
|---|
| 60 | dsp16xx | \
|
|---|
| 61 | i960 | \
|
|---|
| 62 | hppa* | parisc* | \
|
|---|
| 63 | stormy16 | \
|
|---|
| 64 | we32k)
|
|---|
| 65 | sv_cv_stack_direction=1 ;;
|
|---|
| 66 | *)
|
|---|
| 67 | if test $cross_compiling = no; then
|
|---|
| 68 | cat > conftest.c <<EOF
|
|---|
| 69 | #include <stdio.h>
|
|---|
| 70 | int
|
|---|
| 71 | find_stack_direction (int *addr, int depth)
|
|---|
| 72 | {
|
|---|
| 73 | int dir, dummy = 0;
|
|---|
| 74 | if (! addr)
|
|---|
| 75 | addr = &dummy;
|
|---|
| 76 | *addr = addr < &dummy ? 1 : addr == &dummy ? 0 : -1;
|
|---|
| 77 | dir = depth ? find_stack_direction (addr, depth - 1) : 0;
|
|---|
| 78 | return dir + dummy;
|
|---|
| 79 | }
|
|---|
| 80 | int
|
|---|
| 81 | main (int argc, char *argv[])
|
|---|
| 82 | {
|
|---|
| 83 | printf ("%d\n", find_stack_direction (NULL, argc + 20));
|
|---|
| 84 | return 0;
|
|---|
| 85 | }
|
|---|
| 86 | EOF
|
|---|
| 87 | AC_TRY_EVAL([ac_link])
|
|---|
| 88 | sv_cv_stack_direction=`./conftest`
|
|---|
| 89 | else
|
|---|
| 90 | sv_cv_stack_direction=0
|
|---|
| 91 | fi
|
|---|
| 92 | ;;
|
|---|
| 93 | esac
|
|---|
| 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";;
|
|---|
| 98 | esac
|
|---|
| 99 | ])
|
|---|
| 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.])
|
|---|
| 105 | ])
|
|---|