1130561Sobriensinclude(../config/acx.m4) 2130561Sobriensinclude(../config/no-executables.m4) 3218822Sdimsinclude(../config/warnings.m4) 4130561Sobrien 577298Sobriendnl See whether strncmp reads past the end of its string parameters. 677298Sobriendnl On some versions of SunOS4 at least, strncmp reads a word at a time 777298Sobriendnl but erroneously reads past the end of strings. This can cause 877298Sobriendnl a SEGV in some cases. 977298SobrienAC_DEFUN(libiberty_AC_FUNC_STRNCMP, 1077298Sobrien[AC_REQUIRE([AC_FUNC_MMAP]) 1177298SobrienAC_CACHE_CHECK([for working strncmp], ac_cv_func_strncmp_works, 1277298Sobrien[AC_TRY_RUN([ 1377298Sobrien/* Test by Jim Wilson and Kaveh Ghazi. 1477298Sobrien Check whether strncmp reads past the end of its string parameters. */ 1577298Sobrien#include <sys/types.h> 1677298Sobrien 1777298Sobrien#ifdef HAVE_FCNTL_H 1877298Sobrien#include <fcntl.h> 1977298Sobrien#endif 2077298Sobrien 2177298Sobrien#ifdef HAVE_SYS_MMAN_H 2277298Sobrien#include <sys/mman.h> 2377298Sobrien#endif 2477298Sobrien 2577298Sobrien#ifndef MAP_ANON 2677298Sobrien#ifdef MAP_ANONYMOUS 2777298Sobrien#define MAP_ANON MAP_ANONYMOUS 2877298Sobrien#else 2977298Sobrien#define MAP_ANON MAP_FILE 3077298Sobrien#endif 3177298Sobrien#endif 3277298Sobrien 3377298Sobrien#ifndef MAP_FILE 3477298Sobrien#define MAP_FILE 0 3577298Sobrien#endif 3677298Sobrien#ifndef O_RDONLY 3777298Sobrien#define O_RDONLY 0 3877298Sobrien#endif 3977298Sobrien 4077298Sobrien#define MAP_LEN 0x10000 4177298Sobrien 4277298Sobrienmain () 4377298Sobrien{ 4477298Sobrien#if defined(HAVE_MMAP) || defined(HAVE_MMAP_ANYWHERE) 4577298Sobrien char *p; 4677298Sobrien int dev_zero; 4777298Sobrien 4877298Sobrien dev_zero = open ("/dev/zero", O_RDONLY); 4977298Sobrien if (dev_zero < 0) 5077298Sobrien exit (1); 5177298Sobrien 5277298Sobrien p = (char *) mmap (0, MAP_LEN, PROT_READ|PROT_WRITE, 5377298Sobrien MAP_ANON|MAP_PRIVATE, dev_zero, 0); 5477298Sobrien if (p == (char *)-1) 5589857Sobrien p = (char *) mmap (0, MAP_LEN, PROT_READ|PROT_WRITE, 5689857Sobrien MAP_ANON|MAP_PRIVATE, -1, 0); 5789857Sobrien if (p == (char *)-1) 5877298Sobrien exit (2); 5977298Sobrien else 6077298Sobrien { 6177298Sobrien char *string = "__si_type_info"; 6277298Sobrien char *q = (char *) p + MAP_LEN - strlen (string) - 2; 6377298Sobrien char *r = (char *) p + 0xe; 6477298Sobrien 6577298Sobrien strcpy (q, string); 6677298Sobrien strcpy (r, string); 6777298Sobrien strncmp (r, q, 14); 6877298Sobrien } 6977298Sobrien#endif /* HAVE_MMAP || HAVE_MMAP_ANYWHERE */ 7077298Sobrien exit (0); 7177298Sobrien} 7277298Sobrien], ac_cv_func_strncmp_works=yes, ac_cv_func_strncmp_works=no, 7377298Sobrien ac_cv_func_strncmp_works=no) 7477298Sobrienrm -f core core.* *.core]) 7577298Sobrienif test $ac_cv_func_strncmp_works = no ; then 76130561Sobrien AC_LIBOBJ([strncmp]) 7777298Sobrienfi 7877298Sobrien]) 7977298Sobrien 8077298Sobriendnl See if errno must be declared even when <errno.h> is included. 8177298SobrienAC_DEFUN(libiberty_AC_DECLARE_ERRNO, 8277298Sobrien[AC_CACHE_CHECK(whether errno must be declared, libiberty_cv_declare_errno, 8377298Sobrien[AC_TRY_COMPILE( 8477298Sobrien[#include <errno.h>], 8577298Sobrien[int x = errno;], 8677298Sobrienlibiberty_cv_declare_errno=no, 8777298Sobrienlibiberty_cv_declare_errno=yes)]) 8877298Sobrienif test $libiberty_cv_declare_errno = yes 8977298Sobrienthen AC_DEFINE(NEED_DECLARATION_ERRNO, 1, 9077298Sobrien [Define if errno must be declared even when <errno.h> is included.]) 9177298Sobrienfi 9277298Sobrien]) 9377298Sobrien 94130561Sobriendnl See whether we need a declaration for a function. 95130561SobrienAC_DEFUN(libiberty_NEED_DECLARATION, 96130561Sobrien[AC_MSG_CHECKING([whether $1 must be declared]) 97130561SobrienAC_CACHE_VAL(libiberty_cv_decl_needed_$1, 98130561Sobrien[AC_TRY_COMPILE([ 99130561Sobrien#include "confdefs.h" 100130561Sobrien#include <stdio.h> 101130561Sobrien#ifdef HAVE_STRING_H 102130561Sobrien#include <string.h> 103130561Sobrien#else 104130561Sobrien#ifdef HAVE_STRINGS_H 105130561Sobrien#include <strings.h> 106130561Sobrien#endif 107130561Sobrien#endif 108130561Sobrien#ifdef HAVE_STDLIB_H 109130561Sobrien#include <stdlib.h> 110130561Sobrien#endif 111130561Sobrien#ifdef HAVE_UNISTD_H 112130561Sobrien#include <unistd.h> 113130561Sobrien#endif], 114130561Sobrien[char *(*pfn) = (char *(*)) $1], 115130561Sobrienlibiberty_cv_decl_needed_$1=no, libiberty_cv_decl_needed_$1=yes)]) 116130561SobrienAC_MSG_RESULT($libiberty_cv_decl_needed_$1) 117130561Sobrienif test $libiberty_cv_decl_needed_$1 = yes; then 118130561Sobrien AC_DEFINE([NEED_DECLARATION_]translit($1, [a-z], [A-Z]), 1, 119130561Sobrien [Define if $1 is not declared in system header files.]) 12077298Sobrienfi 121130561Sobrien])dnl 12277298Sobrien 12389857Sobrien# We always want a C version of alloca() compiled into libiberty, 12489857Sobrien# because native-compiler support for the real alloca is so !@#$% 12589857Sobrien# unreliable that GCC has decided to use it only when being compiled 12689857Sobrien# by GCC. This is the part of AC_FUNC_ALLOCA that calculates the 12789857Sobrien# information alloca.c needs. 12889857SobrienAC_DEFUN(libiberty_AC_FUNC_C_ALLOCA, 12989857Sobrien[AC_CACHE_CHECK(whether alloca needs Cray hooks, ac_cv_os_cray, 13089857Sobrien[AC_EGREP_CPP(webecray, 13189857Sobrien[#if defined(CRAY) && ! defined(CRAY2) 13289857Sobrienwebecray 13389857Sobrien#else 13489857Sobrienwenotbecray 13589857Sobrien#endif 13689857Sobrien], ac_cv_os_cray=yes, ac_cv_os_cray=no)]) 13789857Sobrienif test $ac_cv_os_cray = yes; then 13889857Sobrien for ac_func in _getb67 GETB67 getb67; do 13989857Sobrien AC_CHECK_FUNC($ac_func, 14089857Sobrien [AC_DEFINE_UNQUOTED(CRAY_STACKSEG_END, $ac_func, 14189857Sobrien [Define to one of _getb67, GETB67, getb67 for Cray-2 and Cray-YMP 14289857Sobrien systems. This function is required for alloca.c support on those 14389857Sobrien systems.]) break]) 14489857Sobrien done 14589857Sobrienfi 14689857Sobrien 14789857SobrienAC_CACHE_CHECK(stack direction for C alloca, ac_cv_c_stack_direction, 14889857Sobrien[AC_TRY_RUN([find_stack_direction () 14989857Sobrien{ 15089857Sobrien static char *addr = 0; 15189857Sobrien auto char dummy; 15289857Sobrien if (addr == 0) 15389857Sobrien { 15489857Sobrien addr = &dummy; 15589857Sobrien return find_stack_direction (); 15689857Sobrien } 15789857Sobrien else 15889857Sobrien return (&dummy > addr) ? 1 : -1; 15989857Sobrien} 16089857Sobrienmain () 16189857Sobrien{ 16289857Sobrien exit (find_stack_direction() < 0); 16389857Sobrien}], 16489857Sobrien ac_cv_c_stack_direction=1, 16589857Sobrien ac_cv_c_stack_direction=-1, 16689857Sobrien ac_cv_c_stack_direction=0)]) 16789857SobrienAC_DEFINE_UNQUOTED(STACK_DIRECTION, $ac_cv_c_stack_direction, 16889857Sobrien [Define if you know the direction of stack growth for your system; 16989857Sobrien otherwise it will be automatically deduced at run-time. 17089857Sobrien STACK_DIRECTION > 0 => grows toward higher addresses 17189857Sobrien STACK_DIRECTION < 0 => grows toward lower addresses 17289857Sobrien STACK_DIRECTION = 0 => direction of growth unknown]) 17389857Sobrien]) 174130561Sobrien 175130561Sobrien# AC_LANG_FUNC_LINK_TRY(C)(FUNCTION) 176130561Sobrien# ---------------------------------- 177130561Sobrien# Don't include <ctype.h> because on OSF/1 3.0 it includes 178130561Sobrien# <sys/types.h> which includes <sys/select.h> which contains a 179130561Sobrien# prototype for select. Similarly for bzero. 180130561Sobrien# 181130561Sobrien# This test used to merely assign f=$1 in main(), but that was 182130561Sobrien# optimized away by HP unbundled cc A.05.36 for ia64 under +O3, 183130561Sobrien# presumably on the basis that there's no need to do that store if the 184130561Sobrien# program is about to exit. Conversely, the AIX linker optimizes an 185130561Sobrien# unused external declaration that initializes f=$1. So this test 186130561Sobrien# program has both an external initialization of f, and a use of f in 187130561Sobrien# main that affects the exit status. 188130561Sobrien# 189130561Sobrienm4_define([AC_LANG_FUNC_LINK_TRY(C)], 190130561Sobrien[AC_LANG_PROGRAM( 191130561Sobrien[/* System header to define __stub macros and hopefully few prototypes, 192130561Sobrien which can conflict with char $1 (); below. 193130561Sobrien Prefer <limits.h> to <assert.h> if __STDC__ is defined, since 194130561Sobrien <limits.h> exists even on freestanding compilers. Under hpux, 195130561Sobrien including <limits.h> includes <sys/time.h> and causes problems 196130561Sobrien checking for functions defined therein. */ 197130561Sobrien#if defined (__STDC__) && !defined (_HPUX_SOURCE) 198130561Sobrien# include <limits.h> 199130561Sobrien#else 200130561Sobrien# include <assert.h> 201130561Sobrien#endif 202130561Sobrien/* Override any gcc2 internal prototype to avoid an error. */ 203130561Sobrien#ifdef __cplusplus 204130561Sobrienextern "C" 205130561Sobrien{ 206130561Sobrien#endif 207130561Sobrien/* We use char because int might match the return type of a gcc2 208130561Sobrien builtin and then its argument prototype would still apply. */ 209130561Sobrienchar $1 (); 210130561Sobrien/* The GNU C library defines this for functions which it implements 211130561Sobrien to always fail with ENOSYS. Some functions are actually named 212130561Sobrien something starting with __ and the normal name is an alias. */ 213130561Sobrien#if defined (__stub_$1) || defined (__stub___$1) 214130561Sobrienchoke me 215130561Sobrien#else 216130561Sobrienchar (*f) () = $1; 217130561Sobrien#endif 218130561Sobrien#ifdef __cplusplus 219130561Sobrien} 220130561Sobrien#endif 221130561Sobrien], [return f != $1;])]) 222130561Sobrien 223