]>
Commit | Line | Data |
---|---|---|
eb383413 L |
1 | dnl See whether strncmp reads past the end of its string parameters. |
2 | dnl On some versions of SunOS4 at least, strncmp reads a word at a time | |
3 | dnl but erroneously reads past the end of strings. This can cause | |
4 | dnl a SEGV in some cases. | |
5 | AC_DEFUN(libiberty_AC_FUNC_STRNCMP, | |
6 | [AC_REQUIRE([AC_FUNC_MMAP]) | |
7 | AC_CACHE_CHECK([for working strncmp], ac_cv_func_strncmp_works, | |
8 | [AC_TRY_RUN([ | |
9 | /* Test by Jim Wilson and Kaveh Ghazi. | |
10 | Check whether strncmp reads past the end of its string parameters. */ | |
11 | #include <sys/types.h> | |
12 | ||
13 | #ifdef HAVE_FCNTL_H | |
14 | #include <fcntl.h> | |
15 | #endif | |
16 | ||
17 | #ifdef HAVE_SYS_MMAN_H | |
18 | #include <sys/mman.h> | |
19 | #endif | |
20 | ||
21 | #ifndef MAP_ANON | |
22 | #ifdef MAP_ANONYMOUS | |
23 | #define MAP_ANON MAP_ANONYMOUS | |
24 | #else | |
25 | #define MAP_ANON MAP_FILE | |
26 | #endif | |
27 | #endif | |
28 | ||
29 | #ifndef MAP_FILE | |
30 | #define MAP_FILE 0 | |
31 | #endif | |
32 | #ifndef O_RDONLY | |
33 | #define O_RDONLY 0 | |
34 | #endif | |
35 | ||
36 | #define MAP_LEN 0x10000 | |
37 | ||
38 | main () | |
39 | { | |
40 | #if defined(HAVE_MMAP) || defined(HAVE_MMAP_ANYWHERE) | |
41 | char *p; | |
42 | int dev_zero; | |
43 | ||
44 | dev_zero = open ("/dev/zero", O_RDONLY); | |
45 | if (dev_zero < 0) | |
46 | exit (1); | |
47 | ||
48 | p = (char *) mmap (0, MAP_LEN, PROT_READ|PROT_WRITE, | |
49 | MAP_ANON|MAP_PRIVATE, dev_zero, 0); | |
f348a7b1 DD |
50 | if (p == (char *)-1) |
51 | p = (char *) mmap (0, MAP_LEN, PROT_READ|PROT_WRITE, | |
52 | MAP_ANON|MAP_PRIVATE, -1, 0); | |
eb383413 L |
53 | if (p == (char *)-1) |
54 | exit (2); | |
55 | else | |
56 | { | |
57 | char *string = "__si_type_info"; | |
58 | char *q = (char *) p + MAP_LEN - strlen (string) - 2; | |
59 | char *r = (char *) p + 0xe; | |
60 | ||
61 | strcpy (q, string); | |
62 | strcpy (r, string); | |
63 | strncmp (r, q, 14); | |
64 | } | |
65 | #endif /* HAVE_MMAP || HAVE_MMAP_ANYWHERE */ | |
66 | exit (0); | |
67 | } | |
68 | ], ac_cv_func_strncmp_works=yes, ac_cv_func_strncmp_works=no, | |
69 | ac_cv_func_strncmp_works=no) | |
70 | rm -f core core.* *.core]) | |
71 | if test $ac_cv_func_strncmp_works = no ; then | |
72 | LIBOBJS="$LIBOBJS strncmp.o" | |
73 | fi | |
74 | ]) | |
7d3ffcaf JL |
75 | |
76 | dnl See if errno must be declared even when <errno.h> is included. | |
77 | AC_DEFUN(libiberty_AC_DECLARE_ERRNO, | |
78 | [AC_CACHE_CHECK(whether errno must be declared, libiberty_cv_declare_errno, | |
79 | [AC_TRY_COMPILE( | |
80 | [#include <errno.h>], | |
81 | [int x = errno;], | |
82 | libiberty_cv_declare_errno=no, | |
83 | libiberty_cv_declare_errno=yes)]) | |
84 | if test $libiberty_cv_declare_errno = yes | |
85 | then AC_DEFINE(NEED_DECLARATION_ERRNO, 1, | |
86 | [Define if errno must be declared even when <errno.h> is included.]) | |
87 | fi | |
88 | ]) | |
2ea7befd | 89 | |
ba61a412 DJ |
90 | dnl See whether we need a declaration for a function. |
91 | AC_DEFUN(libiberty_NEED_DECLARATION, | |
92 | [AC_MSG_CHECKING([whether $1 must be declared]) | |
93 | AC_CACHE_VAL(libiberty_cv_decl_needed_$1, | |
94 | [AC_TRY_COMPILE([ | |
95 | #include "confdefs.h" | |
96 | #include <stdio.h> | |
97 | #ifdef HAVE_STRING_H | |
98 | #include <string.h> | |
99 | #else | |
100 | #ifdef HAVE_STRINGS_H | |
101 | #include <strings.h> | |
102 | #endif | |
103 | #endif | |
104 | #ifdef HAVE_STDLIB_H | |
105 | #include <stdlib.h> | |
106 | #endif | |
107 | #ifdef HAVE_UNISTD_H | |
108 | #include <unistd.h> | |
109 | #endif], | |
110 | [char *(*pfn) = (char *(*)) $1], | |
111 | libiberty_cv_decl_needed_$1=no, libiberty_cv_decl_needed_$1=yes)]) | |
112 | AC_MSG_RESULT($libiberty_cv_decl_needed_$1) | |
113 | if test $libiberty_cv_decl_needed_$1 = yes; then | |
114 | AC_DEFINE([NEED_DECLARATION_]translit($1, [a-z], [A-Z]), 1, | |
115 | [Define if $1 is not declared in system header files.]) | |
116 | fi | |
117 | ])dnl | |
118 | ||
2ea7befd DD |
119 | # FIXME: We temporarily define our own version of AC_PROG_CC. This is |
120 | # copied from autoconf 2.12, but does not call AC_PROG_CC_WORKS. We | |
121 | # are probably using a cross compiler, which will not be able to fully | |
122 | # link an executable. This should really be fixed in autoconf | |
123 | # itself. | |
124 | ||
125 | AC_DEFUN(LIB_AC_PROG_CC, | |
126 | [AC_BEFORE([$0], [AC_PROG_CPP])dnl | |
127 | AC_PROVIDE([AC_PROG_CC]) | |
128 | AC_CHECK_PROG(CC, gcc, gcc) | |
129 | if test -z "$CC"; then | |
130 | AC_CHECK_PROG(CC, cc, cc, , , /usr/ucb/cc) | |
131 | test -z "$CC" && AC_MSG_ERROR([no acceptable cc found in \$PATH]) | |
132 | fi | |
133 | ||
134 | AC_PROG_CC_GNU | |
135 | ||
136 | if test $ac_cv_prog_gcc = yes; then | |
137 | GCC=yes | |
138 | ac_libiberty_warn_cflags='-W -Wall -Wtraditional -pedantic' | |
139 | dnl Check whether -g works, even if CFLAGS is set, in case the package | |
140 | dnl plays around with CFLAGS (such as to build both debugging and | |
141 | dnl normal versions of a library), tasteless as that idea is. | |
142 | ac_test_CFLAGS="${CFLAGS+set}" | |
143 | ac_save_CFLAGS="$CFLAGS" | |
144 | CFLAGS= | |
145 | AC_PROG_CC_G | |
146 | if test "$ac_test_CFLAGS" = set; then | |
147 | CFLAGS="$ac_save_CFLAGS" | |
148 | elif test $ac_cv_prog_cc_g = yes; then | |
149 | CFLAGS="-g -O2" | |
150 | else | |
151 | CFLAGS="-O2" | |
152 | fi | |
153 | else | |
154 | GCC= | |
155 | ac_libiberty_warn_cflags= | |
156 | test "${CFLAGS+set}" = set || CFLAGS="-g" | |
157 | fi | |
158 | AC_SUBST(ac_libiberty_warn_cflags) | |
159 | ]) | |
160 | ||
161 | # Work around a bug in autoheader. This can go away when we switch to | |
162 | # autoconf >2.50. The use of define instead of AC_DEFUN is | |
163 | # deliberate. | |
164 | define(AC_DEFINE_NOAUTOHEADER, | |
165 | [cat >> confdefs.h <<\EOF | |
166 | [#define] $1 ifelse($#, 2, [$2], $#, 3, [$2], 1) | |
167 | EOF | |
168 | ]) | |
30673bf5 DD |
169 | |
170 | # We always want a C version of alloca() compiled into libiberty, | |
171 | # because native-compiler support for the real alloca is so !@#$% | |
172 | # unreliable that GCC has decided to use it only when being compiled | |
173 | # by GCC. This is the part of AC_FUNC_ALLOCA that calculates the | |
174 | # information alloca.c needs. | |
175 | AC_DEFUN(libiberty_AC_FUNC_C_ALLOCA, | |
176 | [AC_CACHE_CHECK(whether alloca needs Cray hooks, ac_cv_os_cray, | |
177 | [AC_EGREP_CPP(webecray, | |
178 | [#if defined(CRAY) && ! defined(CRAY2) | |
179 | webecray | |
180 | #else | |
181 | wenotbecray | |
182 | #endif | |
183 | ], ac_cv_os_cray=yes, ac_cv_os_cray=no)]) | |
184 | if test $ac_cv_os_cray = yes; then | |
185 | for ac_func in _getb67 GETB67 getb67; do | |
186 | AC_CHECK_FUNC($ac_func, | |
187 | [AC_DEFINE_UNQUOTED(CRAY_STACKSEG_END, $ac_func, | |
188 | [Define to one of _getb67, GETB67, getb67 for Cray-2 and Cray-YMP | |
189 | systems. This function is required for alloca.c support on those | |
190 | systems.]) break]) | |
191 | done | |
192 | fi | |
193 | ||
194 | AC_CACHE_CHECK(stack direction for C alloca, ac_cv_c_stack_direction, | |
195 | [AC_TRY_RUN([find_stack_direction () | |
196 | { | |
197 | static char *addr = 0; | |
198 | auto char dummy; | |
199 | if (addr == 0) | |
200 | { | |
201 | addr = &dummy; | |
202 | return find_stack_direction (); | |
203 | } | |
204 | else | |
205 | return (&dummy > addr) ? 1 : -1; | |
206 | } | |
207 | main () | |
208 | { | |
209 | exit (find_stack_direction() < 0); | |
210 | }], | |
211 | ac_cv_c_stack_direction=1, | |
212 | ac_cv_c_stack_direction=-1, | |
213 | ac_cv_c_stack_direction=0)]) | |
214 | AC_DEFINE_UNQUOTED(STACK_DIRECTION, $ac_cv_c_stack_direction, | |
215 | [Define if you know the direction of stack growth for your system; | |
216 | otherwise it will be automatically deduced at run-time. | |
217 | STACK_DIRECTION > 0 => grows toward higher addresses | |
218 | STACK_DIRECTION < 0 => grows toward lower addresses | |
219 | STACK_DIRECTION = 0 => direction of growth unknown]) | |
220 | ]) |