OSDN Git Service

2005-05-06 Kelley Cook <kcook@gcc.gnu.org>
[pf3gnuchains/gcc-fork.git] / libiberty / aclocal.m4
1 sinclude(../config/acx.m4)
2 sinclude(../config/no-executables.m4)
3
4 dnl See whether strncmp reads past the end of its string parameters.
5 dnl On some versions of SunOS4 at least, strncmp reads a word at a time
6 dnl but erroneously reads past the end of strings.  This can cause
7 dnl a SEGV in some cases.
8 AC_DEFUN(libiberty_AC_FUNC_STRNCMP,
9 [AC_REQUIRE([AC_FUNC_MMAP])
10 AC_CACHE_CHECK([for working strncmp], ac_cv_func_strncmp_works,
11 [AC_TRY_RUN([
12 /* Test by Jim Wilson and Kaveh Ghazi.
13    Check whether strncmp reads past the end of its string parameters. */
14 #include <sys/types.h>
15
16 #ifdef HAVE_FCNTL_H
17 #include <fcntl.h>
18 #endif
19
20 #ifdef HAVE_SYS_MMAN_H
21 #include <sys/mman.h>
22 #endif
23
24 #ifndef MAP_ANON
25 #ifdef MAP_ANONYMOUS
26 #define MAP_ANON MAP_ANONYMOUS
27 #else
28 #define MAP_ANON MAP_FILE
29 #endif
30 #endif
31
32 #ifndef MAP_FILE
33 #define MAP_FILE 0
34 #endif
35 #ifndef O_RDONLY
36 #define O_RDONLY 0
37 #endif
38
39 #define MAP_LEN 0x10000
40
41 main ()
42 {
43 #if defined(HAVE_MMAP) || defined(HAVE_MMAP_ANYWHERE)
44   char *p;
45   int dev_zero;
46
47   dev_zero = open ("/dev/zero", O_RDONLY);
48   if (dev_zero < 0)
49     exit (1);
50   
51   p = (char *) mmap (0, MAP_LEN, PROT_READ|PROT_WRITE,
52                      MAP_ANON|MAP_PRIVATE, dev_zero, 0);
53   if (p == (char *)-1)
54     p = (char *) mmap (0, MAP_LEN, PROT_READ|PROT_WRITE,
55                        MAP_ANON|MAP_PRIVATE, -1, 0);
56   if (p == (char *)-1)
57     exit (2);
58   else
59     {
60       char *string = "__si_type_info";
61       char *q = (char *) p + MAP_LEN - strlen (string) - 2;
62       char *r = (char *) p + 0xe;
63
64       strcpy (q, string);
65       strcpy (r, string);
66       strncmp (r, q, 14);
67     }
68 #endif /* HAVE_MMAP || HAVE_MMAP_ANYWHERE */
69   exit (0);
70 }
71 ], ac_cv_func_strncmp_works=yes, ac_cv_func_strncmp_works=no,
72   ac_cv_func_strncmp_works=no)
73 rm -f core core.* *.core])
74 if test $ac_cv_func_strncmp_works = no ; then
75   AC_LIBOBJ([strncmp])
76 fi
77 ])
78
79 dnl See if errno must be declared even when <errno.h> is included.
80 AC_DEFUN(libiberty_AC_DECLARE_ERRNO,
81 [AC_CACHE_CHECK(whether errno must be declared, libiberty_cv_declare_errno,
82 [AC_TRY_COMPILE(
83 [#include <errno.h>],
84 [int x = errno;],
85 libiberty_cv_declare_errno=no,
86 libiberty_cv_declare_errno=yes)])
87 if test $libiberty_cv_declare_errno = yes
88 then AC_DEFINE(NEED_DECLARATION_ERRNO, 1,
89   [Define if errno must be declared even when <errno.h> is included.])
90 fi
91 ])
92
93 dnl See whether we need a declaration for a function.
94 AC_DEFUN(libiberty_NEED_DECLARATION,
95 [AC_MSG_CHECKING([whether $1 must be declared])
96 AC_CACHE_VAL(libiberty_cv_decl_needed_$1,
97 [AC_TRY_COMPILE([
98 #include "confdefs.h"
99 #include <stdio.h>
100 #ifdef HAVE_STRING_H
101 #include <string.h>
102 #else
103 #ifdef HAVE_STRINGS_H
104 #include <strings.h>
105 #endif
106 #endif
107 #ifdef HAVE_STDLIB_H
108 #include <stdlib.h>
109 #endif
110 #ifdef HAVE_UNISTD_H
111 #include <unistd.h>
112 #endif],
113 [char *(*pfn) = (char *(*)) $1],
114 libiberty_cv_decl_needed_$1=no, libiberty_cv_decl_needed_$1=yes)])
115 AC_MSG_RESULT($libiberty_cv_decl_needed_$1)
116 if test $libiberty_cv_decl_needed_$1 = yes; then
117   AC_DEFINE([NEED_DECLARATION_]translit($1, [a-z], [A-Z]), 1,
118             [Define if $1 is not declared in system header files.])
119 fi
120 ])dnl
121
122 # Work around a bug in autoheader.  This can go away when we switch to
123 # autoconf >2.50.  The use of define instead of AC_DEFUN is
124 # deliberate.
125 define(AC_DEFINE_NOAUTOHEADER,
126 [cat >> confdefs.h <<\EOF
127 [#define] $1 ifelse($#, 2, [$2], $#, 3, [$2], 1)
128 EOF
129 ])
130
131 # We always want a C version of alloca() compiled into libiberty,
132 # because native-compiler support for the real alloca is so !@#$%
133 # unreliable that GCC has decided to use it only when being compiled
134 # by GCC.  This is the part of AC_FUNC_ALLOCA that calculates the
135 # information alloca.c needs.
136 AC_DEFUN(libiberty_AC_FUNC_C_ALLOCA,
137 [AC_CACHE_CHECK(whether alloca needs Cray hooks, ac_cv_os_cray,
138 [AC_EGREP_CPP(webecray,
139 [#if defined(CRAY) && ! defined(CRAY2)
140 webecray
141 #else
142 wenotbecray
143 #endif
144 ], ac_cv_os_cray=yes, ac_cv_os_cray=no)])
145 if test $ac_cv_os_cray = yes; then
146   for ac_func in _getb67 GETB67 getb67; do
147     AC_CHECK_FUNC($ac_func, 
148       [AC_DEFINE_UNQUOTED(CRAY_STACKSEG_END, $ac_func, 
149   [Define to one of _getb67, GETB67, getb67 for Cray-2 and Cray-YMP
150    systems. This function is required for alloca.c support on those
151    systems.])  break])
152   done
153 fi
154
155 AC_CACHE_CHECK(stack direction for C alloca, ac_cv_c_stack_direction,
156 [AC_TRY_RUN([find_stack_direction ()
157 {
158   static char *addr = 0;
159   auto char dummy;
160   if (addr == 0)
161     {
162       addr = &dummy;
163       return find_stack_direction ();
164     }
165   else
166     return (&dummy > addr) ? 1 : -1;
167 }
168 main ()
169 {
170   exit (find_stack_direction() < 0);
171 }], 
172   ac_cv_c_stack_direction=1,
173   ac_cv_c_stack_direction=-1,
174   ac_cv_c_stack_direction=0)])
175 AC_DEFINE_UNQUOTED(STACK_DIRECTION, $ac_cv_c_stack_direction,
176   [Define if you know the direction of stack growth for your system;
177    otherwise it will be automatically deduced at run-time.
178         STACK_DIRECTION > 0 => grows toward higher addresses
179         STACK_DIRECTION < 0 => grows toward lower addresses
180         STACK_DIRECTION = 0 => direction of growth unknown])
181 ])
182
183 # AC_LANG_FUNC_LINK_TRY(C)(FUNCTION)
184 # ----------------------------------
185 # Don't include <ctype.h> because on OSF/1 3.0 it includes
186 # <sys/types.h> which includes <sys/select.h> which contains a
187 # prototype for select.  Similarly for bzero.
188 #
189 # This test used to merely assign f=$1 in main(), but that was
190 # optimized away by HP unbundled cc A.05.36 for ia64 under +O3,
191 # presumably on the basis that there's no need to do that store if the
192 # program is about to exit.  Conversely, the AIX linker optimizes an
193 # unused external declaration that initializes f=$1.  So this test
194 # program has both an external initialization of f, and a use of f in
195 # main that affects the exit status.
196 #
197 m4_define([AC_LANG_FUNC_LINK_TRY(C)],
198 [AC_LANG_PROGRAM(
199 [/* System header to define __stub macros and hopefully few prototypes,
200     which can conflict with char $1 (); below.
201     Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
202     <limits.h> exists even on freestanding compilers.  Under hpux,
203     including <limits.h> includes <sys/time.h> and causes problems
204     checking for functions defined therein.  */
205 #if defined (__STDC__) && !defined (_HPUX_SOURCE)
206 # include <limits.h>
207 #else
208 # include <assert.h>
209 #endif
210 /* Override any gcc2 internal prototype to avoid an error.  */
211 #ifdef __cplusplus
212 extern "C"
213 {
214 #endif
215 /* We use char because int might match the return type of a gcc2
216    builtin and then its argument prototype would still apply.  */
217 char $1 ();
218 /* The GNU C library defines this for functions which it implements
219     to always fail with ENOSYS.  Some functions are actually named
220     something starting with __ and the normal name is an alias.  */
221 #if defined (__stub_$1) || defined (__stub___$1)
222 choke me
223 #else
224 char (*f) () = $1;
225 #endif
226 #ifdef __cplusplus
227 }
228 #endif
229 ], [return f != $1;])])
230