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,
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>
17 #ifdef HAVE_SYS_MMAN_H
23 #define MAP_ANON MAP_ANONYMOUS
25 #define MAP_ANON MAP_FILE
36 #define MAP_LEN 0x10000
40 #if defined(HAVE_MMAP) || defined(HAVE_MMAP_ANYWHERE)
44 dev_zero = open ("/dev/zero", O_RDONLY);
48 p = (char *) mmap (0, MAP_LEN, PROT_READ|PROT_WRITE,
49 MAP_ANON|MAP_PRIVATE, dev_zero, 0);
51 p = (char *) mmap (0, MAP_LEN, PROT_READ|PROT_WRITE,
52 MAP_ANON|MAP_PRIVATE, -1, 0);
57 char *string = "__si_type_info";
58 char *q = (char *) p + MAP_LEN - strlen (string) - 2;
59 char *r = (char *) p + 0xe;
65 #endif /* HAVE_MMAP || HAVE_MMAP_ANYWHERE */
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"
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,
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.])
90 # FIXME: We temporarily define our own version of AC_PROG_CC. This is
91 # copied from autoconf 2.12, but does not call AC_PROG_CC_WORKS. We
92 # are probably using a cross compiler, which will not be able to fully
93 # link an executable. This should really be fixed in autoconf
96 AC_DEFUN(LIB_AC_PROG_CC,
97 [AC_BEFORE([$0], [AC_PROG_CPP])dnl
98 AC_PROVIDE([AC_PROG_CC])
99 AC_CHECK_PROG(CC, gcc, gcc)
100 if test -z "$CC"; then
101 AC_CHECK_PROG(CC, cc, cc, , , /usr/ucb/cc)
102 test -z "$CC" && AC_MSG_ERROR([no acceptable cc found in \$PATH])
107 if test $ac_cv_prog_gcc = yes; then
109 ac_libiberty_warn_cflags='-W -Wall -Wtraditional -pedantic'
110 dnl Check whether -g works, even if CFLAGS is set, in case the package
111 dnl plays around with CFLAGS (such as to build both debugging and
112 dnl normal versions of a library), tasteless as that idea is.
113 ac_test_CFLAGS="${CFLAGS+set}"
114 ac_save_CFLAGS="$CFLAGS"
117 if test "$ac_test_CFLAGS" = set; then
118 CFLAGS="$ac_save_CFLAGS"
119 elif test $ac_cv_prog_cc_g = yes; then
126 ac_libiberty_warn_cflags=
127 test "${CFLAGS+set}" = set || CFLAGS="-g"
129 AC_SUBST(ac_libiberty_warn_cflags)
132 # Work around a bug in autoheader. This can go away when we switch to
133 # autoconf >2.50. The use of define instead of AC_DEFUN is
135 define(AC_DEFINE_NOAUTOHEADER,
136 [cat >> confdefs.h <<\EOF
137 [#define] $1 ifelse($#, 2, [$2], $#, 3, [$2], 1)
141 # We always want a C version of alloca() compiled into libiberty,
142 # because native-compiler support for the real alloca is so !@#$%
143 # unreliable that GCC has decided to use it only when being compiled
144 # by GCC. This is the part of AC_FUNC_ALLOCA that calculates the
145 # information alloca.c needs.
146 AC_DEFUN(libiberty_AC_FUNC_C_ALLOCA,
147 [AC_CACHE_CHECK(whether alloca needs Cray hooks, ac_cv_os_cray,
148 [AC_EGREP_CPP(webecray,
149 [#if defined(CRAY) && ! defined(CRAY2)
154 ], ac_cv_os_cray=yes, ac_cv_os_cray=no)])
155 if test $ac_cv_os_cray = yes; then
156 for ac_func in _getb67 GETB67 getb67; do
157 AC_CHECK_FUNC($ac_func,
158 [AC_DEFINE_UNQUOTED(CRAY_STACKSEG_END, $ac_func,
159 [Define to one of _getb67, GETB67, getb67 for Cray-2 and Cray-YMP
160 systems. This function is required for alloca.c support on those
165 AC_CACHE_CHECK(stack direction for C alloca, ac_cv_c_stack_direction,
166 [AC_TRY_RUN([find_stack_direction ()
168 static char *addr = 0;
173 return find_stack_direction ();
176 return (&dummy > addr) ? 1 : -1;
180 exit (find_stack_direction() < 0);
182 ac_cv_c_stack_direction=1,
183 ac_cv_c_stack_direction=-1,
184 ac_cv_c_stack_direction=0)])
185 AC_DEFINE_UNQUOTED(STACK_DIRECTION, $ac_cv_c_stack_direction,
186 [Define if you know the direction of stack growth for your system;
187 otherwise it will be automatically deduced at run-time.
188 STACK_DIRECTION > 0 => grows toward higher addresses
189 STACK_DIRECTION < 0 => grows toward lower addresses
190 STACK_DIRECTION = 0 => direction of growth unknown])