1169695Skansinclude(../config/acx.m4) 2169695Skansinclude(../config/no-executables.m4) 3169695Skan 4169695Skandnl See whether strncmp reads past the end of its string parameters. 5169695Skandnl On some versions of SunOS4 at least, strncmp reads a word at a time 6169695Skandnl but erroneously reads past the end of strings. This can cause 7169695Skandnl a SEGV in some cases. 8169695SkanAC_DEFUN(libiberty_AC_FUNC_STRNCMP, 9169695Skan[AC_REQUIRE([AC_FUNC_MMAP]) 10169695SkanAC_CACHE_CHECK([for working strncmp], ac_cv_func_strncmp_works, 11169695Skan[AC_TRY_RUN([ 12169695Skan/* Test by Jim Wilson and Kaveh Ghazi. 13169695Skan Check whether strncmp reads past the end of its string parameters. */ 14169695Skan#include <sys/types.h> 15169695Skan 16169695Skan#ifdef HAVE_FCNTL_H 17169695Skan#include <fcntl.h> 18169695Skan#endif 19169695Skan 20169695Skan#ifdef HAVE_SYS_MMAN_H 21169695Skan#include <sys/mman.h> 22169695Skan#endif 23169695Skan 24169695Skan#ifndef MAP_ANON 25169695Skan#ifdef MAP_ANONYMOUS 26169695Skan#define MAP_ANON MAP_ANONYMOUS 27169695Skan#else 28169695Skan#define MAP_ANON MAP_FILE 29169695Skan#endif 30169695Skan#endif 31169695Skan 32169695Skan#ifndef MAP_FILE 33169695Skan#define MAP_FILE 0 34169695Skan#endif 35169695Skan#ifndef O_RDONLY 36169695Skan#define O_RDONLY 0 37169695Skan#endif 38169695Skan 39169695Skan#define MAP_LEN 0x10000 40169695Skan 41169695Skanmain () 42169695Skan{ 43169695Skan#if defined(HAVE_MMAP) || defined(HAVE_MMAP_ANYWHERE) 44169695Skan char *p; 45169695Skan int dev_zero; 46169695Skan 47169695Skan dev_zero = open ("/dev/zero", O_RDONLY); 48169695Skan if (dev_zero < 0) 49169695Skan exit (1); 50169695Skan 51169695Skan p = (char *) mmap (0, MAP_LEN, PROT_READ|PROT_WRITE, 52169695Skan MAP_ANON|MAP_PRIVATE, dev_zero, 0); 53169695Skan if (p == (char *)-1) 54169695Skan p = (char *) mmap (0, MAP_LEN, PROT_READ|PROT_WRITE, 55169695Skan MAP_ANON|MAP_PRIVATE, -1, 0); 56169695Skan if (p == (char *)-1) 57169695Skan exit (2); 58169695Skan else 59169695Skan { 60169695Skan char *string = "__si_type_info"; 61169695Skan char *q = (char *) p + MAP_LEN - strlen (string) - 2; 62169695Skan char *r = (char *) p + 0xe; 63169695Skan 64169695Skan strcpy (q, string); 65169695Skan strcpy (r, string); 66169695Skan strncmp (r, q, 14); 67169695Skan } 68169695Skan#endif /* HAVE_MMAP || HAVE_MMAP_ANYWHERE */ 69169695Skan exit (0); 70169695Skan} 71169695Skan], ac_cv_func_strncmp_works=yes, ac_cv_func_strncmp_works=no, 72169695Skan ac_cv_func_strncmp_works=no) 73169695Skanrm -f core core.* *.core]) 74169695Skanif test $ac_cv_func_strncmp_works = no ; then 75169695Skan AC_LIBOBJ([strncmp]) 76169695Skanfi 77169695Skan]) 78169695Skan 79169695Skandnl See if errno must be declared even when <errno.h> is included. 80169695SkanAC_DEFUN(libiberty_AC_DECLARE_ERRNO, 81169695Skan[AC_CACHE_CHECK(whether errno must be declared, libiberty_cv_declare_errno, 82169695Skan[AC_TRY_COMPILE( 83169695Skan[#include <errno.h>], 84169695Skan[int x = errno;], 85169695Skanlibiberty_cv_declare_errno=no, 86169695Skanlibiberty_cv_declare_errno=yes)]) 87169695Skanif test $libiberty_cv_declare_errno = yes 88169695Skanthen AC_DEFINE(NEED_DECLARATION_ERRNO, 1, 89169695Skan [Define if errno must be declared even when <errno.h> is included.]) 90169695Skanfi 91169695Skan]) 92169695Skan 93169695Skandnl See whether we need a declaration for a function. 94169695SkanAC_DEFUN(libiberty_NEED_DECLARATION, 95169695Skan[AC_MSG_CHECKING([whether $1 must be declared]) 96169695SkanAC_CACHE_VAL(libiberty_cv_decl_needed_$1, 97169695Skan[AC_TRY_COMPILE([ 98169695Skan#include "confdefs.h" 99169695Skan#include <stdio.h> 100169695Skan#ifdef HAVE_STRING_H 101169695Skan#include <string.h> 102169695Skan#else 103169695Skan#ifdef HAVE_STRINGS_H 104169695Skan#include <strings.h> 105169695Skan#endif 106169695Skan#endif 107169695Skan#ifdef HAVE_STDLIB_H 108169695Skan#include <stdlib.h> 109169695Skan#endif 110169695Skan#ifdef HAVE_UNISTD_H 111169695Skan#include <unistd.h> 112169695Skan#endif], 113169695Skan[char *(*pfn) = (char *(*)) $1], 114169695Skanlibiberty_cv_decl_needed_$1=no, libiberty_cv_decl_needed_$1=yes)]) 115169695SkanAC_MSG_RESULT($libiberty_cv_decl_needed_$1) 116169695Skanif test $libiberty_cv_decl_needed_$1 = yes; then 117169695Skan AC_DEFINE([NEED_DECLARATION_]translit($1, [a-z], [A-Z]), 1, 118169695Skan [Define if $1 is not declared in system header files.]) 119169695Skanfi 120169695Skan])dnl 121169695Skan 122169695Skan# We always want a C version of alloca() compiled into libiberty, 123169695Skan# because native-compiler support for the real alloca is so !@#$% 124169695Skan# unreliable that GCC has decided to use it only when being compiled 125169695Skan# by GCC. This is the part of AC_FUNC_ALLOCA that calculates the 126169695Skan# information alloca.c needs. 127169695SkanAC_DEFUN(libiberty_AC_FUNC_C_ALLOCA, 128169695Skan[AC_CACHE_CHECK(whether alloca needs Cray hooks, ac_cv_os_cray, 129169695Skan[AC_EGREP_CPP(webecray, 130169695Skan[#if defined(CRAY) && ! defined(CRAY2) 131169695Skanwebecray 132169695Skan#else 133169695Skanwenotbecray 134169695Skan#endif 135169695Skan], ac_cv_os_cray=yes, ac_cv_os_cray=no)]) 136169695Skanif test $ac_cv_os_cray = yes; then 137169695Skan for ac_func in _getb67 GETB67 getb67; do 138169695Skan AC_CHECK_FUNC($ac_func, 139169695Skan [AC_DEFINE_UNQUOTED(CRAY_STACKSEG_END, $ac_func, 140169695Skan [Define to one of _getb67, GETB67, getb67 for Cray-2 and Cray-YMP 141169695Skan systems. This function is required for alloca.c support on those 142169695Skan systems.]) break]) 143169695Skan done 144169695Skanfi 145169695Skan 146169695SkanAC_CACHE_CHECK(stack direction for C alloca, ac_cv_c_stack_direction, 147169695Skan[AC_TRY_RUN([find_stack_direction () 148169695Skan{ 149169695Skan static char *addr = 0; 150169695Skan auto char dummy; 151169695Skan if (addr == 0) 152169695Skan { 153169695Skan addr = &dummy; 154169695Skan return find_stack_direction (); 155169695Skan } 156169695Skan else 157169695Skan return (&dummy > addr) ? 1 : -1; 158169695Skan} 159169695Skanmain () 160169695Skan{ 161169695Skan exit (find_stack_direction() < 0); 162169695Skan}], 163169695Skan ac_cv_c_stack_direction=1, 164169695Skan ac_cv_c_stack_direction=-1, 165169695Skan ac_cv_c_stack_direction=0)]) 166169695SkanAC_DEFINE_UNQUOTED(STACK_DIRECTION, $ac_cv_c_stack_direction, 167169695Skan [Define if you know the direction of stack growth for your system; 168169695Skan otherwise it will be automatically deduced at run-time. 169169695Skan STACK_DIRECTION > 0 => grows toward higher addresses 170169695Skan STACK_DIRECTION < 0 => grows toward lower addresses 171169695Skan STACK_DIRECTION = 0 => direction of growth unknown]) 172169695Skan]) 173169695Skan 174169695Skan# AC_LANG_FUNC_LINK_TRY(C)(FUNCTION) 175169695Skan# ---------------------------------- 176169695Skan# Don't include <ctype.h> because on OSF/1 3.0 it includes 177169695Skan# <sys/types.h> which includes <sys/select.h> which contains a 178169695Skan# prototype for select. Similarly for bzero. 179169695Skan# 180169695Skan# This test used to merely assign f=$1 in main(), but that was 181169695Skan# optimized away by HP unbundled cc A.05.36 for ia64 under +O3, 182169695Skan# presumably on the basis that there's no need to do that store if the 183169695Skan# program is about to exit. Conversely, the AIX linker optimizes an 184169695Skan# unused external declaration that initializes f=$1. So this test 185169695Skan# program has both an external initialization of f, and a use of f in 186169695Skan# main that affects the exit status. 187169695Skan# 188169695Skanm4_define([AC_LANG_FUNC_LINK_TRY(C)], 189169695Skan[AC_LANG_PROGRAM( 190169695Skan[/* System header to define __stub macros and hopefully few prototypes, 191169695Skan which can conflict with char $1 (); below. 192169695Skan Prefer <limits.h> to <assert.h> if __STDC__ is defined, since 193169695Skan <limits.h> exists even on freestanding compilers. Under hpux, 194169695Skan including <limits.h> includes <sys/time.h> and causes problems 195169695Skan checking for functions defined therein. */ 196169695Skan#if defined (__STDC__) && !defined (_HPUX_SOURCE) 197169695Skan# include <limits.h> 198169695Skan#else 199169695Skan# include <assert.h> 200169695Skan#endif 201169695Skan/* Override any gcc2 internal prototype to avoid an error. */ 202169695Skan#ifdef __cplusplus 203169695Skanextern "C" 204169695Skan{ 205169695Skan#endif 206169695Skan/* We use char because int might match the return type of a gcc2 207169695Skan builtin and then its argument prototype would still apply. */ 208169695Skanchar $1 (); 209169695Skan/* The GNU C library defines this for functions which it implements 210169695Skan to always fail with ENOSYS. Some functions are actually named 211169695Skan something starting with __ and the normal name is an alias. */ 212169695Skan#if defined (__stub_$1) || defined (__stub___$1) 213169695Skanchoke me 214169695Skan#else 215169695Skanchar (*f) () = $1; 216169695Skan#endif 217169695Skan#ifdef __cplusplus 218169695Skan} 219169695Skan#endif 220169695Skan], [return f != $1;])]) 221169695Skan 222