Debian Codegraph @

m4/stack-direction.m4

raw
1 # stack-direction.m4
2 # serial 12
3 dnl Copyright (C) 2002-2025 Free Software Foundation, Inc.
4 dnl This file is free software, distributed under the terms of the GNU
5 dnl General Public License as published by the Free Software Foundation;
6 dnl either version 2 of the License, or (at your option) any later version.
7 dnl As a special exception to the GNU General Public License, this file
8 dnl may be distributed as part of a program that contains a configuration
9 dnl script generated by Autoconf, under the same distribution terms as
10 dnl the rest of that program.
11
12 dnl Written by Bruno Haible.
13
14 # Determine the stack direction. Define the C macro STACK_DIRECTION.
15 AC_DEFUN([SV_STACK_DIRECTION],
16 [
17 AC_REQUIRE([AC_CANONICAL_HOST])
18 AC_CACHE_CHECK([for stack direction], [sv_cv_stack_direction_msg], [
19 case "$host_cpu" in
20 dnl See the #define STACK_GROWS_DOWNWARD in gcc-3.1/gcc/config/*/*.h.
21 a29k | \
22 aarch64* | \
23 alpha* | \
24 arc | arceb | arc32 | arc64 | \
25 arm* | strongarm* | xscale* | \
26 avr | avr32 | \
27 bfin | \
28 c1 | c2 | c32 | c34 | c38 | \
29 clipper | \
30 cr16 | \
31 cris | \
32 csky | \
33 d30v | \
34 epiphany | \
35 elxsi | \
36 fr30 | \
37 frv | \
38 ft32 | \
39 h8300 | \
40 i?86 | x86_64 | \
41 i860 | \
42 ia64 | \
43 iq2000 | \
44 lm32 | \
45 loongarch* | \
46 m32c | \
47 m32r | \
48 m68* | \
49 m88k | \
50 mcore | \
51 microblaze* | \
52 mips* | \
53 mmix | \
54 mn10200 | \
55 mn10300 | \
56 moxie | \
57 msp430 | \
58 nds32* | \
59 nios2 | nios2eb | nios2el | \
60 ns32k | \
61 nvptx | \
62 or1k | \
63 pdp11 | \
64 pj* | \
65 powerpc* | rs6000 | \
66 pru | \
67 riscv* | \
68 rl78 | \
69 romp | \
70 rx | \
71 s390* | \
72 sh* | \
73 sparc* | \
74 tic6x | \
75 tilegx | \
76 tilepro | \
77 v850 | \
78 vax | \
79 visium | \
80 xtensa)
81 sv_cv_stack_direction=-1 ;;
82 c4x | \
83 dsp16xx | \
84 i960 | \
85 hppa* | parisc* | \
86 stormy16 | \
87 we32k)
88 sv_cv_stack_direction=1 ;;
89 *)
90 if test $cross_compiling = no; then
91 cat > conftest.c <<EOF
92 #include <stdio.h>
93 int
94 find_stack_direction (int *addr, int depth)
95 {
96 int dir, dummy = 0;
97 if (! addr)
98 addr = &dummy;
99 *addr = addr < &dummy ? 1 : addr == &dummy ? 0 : -1;
100 dir = depth ? find_stack_direction (addr, depth - 1) : 0;
101 return dir + dummy;
102 }
103 int
104 main (int argc, char *argv[[]])
105 {
106 printf ("%d\n", find_stack_direction (NULL, argc + 20));
107 return 0;
108 }
109 EOF
110 AC_TRY_EVAL([ac_link])
111 sv_cv_stack_direction=`./conftest`
112 else
113 sv_cv_stack_direction=0
114 fi
115 ;;
116 esac
117 case $sv_cv_stack_direction in
118 1) sv_cv_stack_direction_msg="grows up";;
119 -1) sv_cv_stack_direction_msg="grows down";;
120 *) sv_cv_stack_direction_msg="unknown";;
121 esac
122 ])
123 AC_DEFINE_UNQUOTED([STACK_DIRECTION], [$sv_cv_stack_direction],
124 [Define as the direction of stack growth for your system.
125 STACK_DIRECTION > 0 => grows toward higher addresses
126 STACK_DIRECTION < 0 => grows toward lower addresses
127 STACK_DIRECTION = 0 => spaghetti stack.])
128 ])