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