1dnl Copyright (C) 2000-2022 Free Software Foundation, Inc. 2dnl 3dnl GCC is free software; you can redistribute it and/or modify 4dnl it under the terms of the GNU General Public License as published by 5dnl the Free Software Foundation; either version 3, or (at your option) 6dnl any later version. 7dnl 8dnl GCC is distributed in the hope that it will be useful, 9dnl but WITHOUT ANY WARRANTY; without even the implied warranty of 10dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11dnl GNU General Public License for more details. 12dnl 13dnl You should have received a copy of the GNU General Public License 14dnl along with GCC; see the file COPYING3. If not see 15dnl <http://www.gnu.org/licenses/>. 16 17dnl See whether strncmp reads past the end of its string parameters. 18dnl On some versions of SunOS4 at least, strncmp reads a word at a time 19dnl but erroneously reads past the end of strings. This can cause 20dnl a SEGV in some cases. 21AC_DEFUN([libiberty_AC_FUNC_STRNCMP], 22[AC_REQUIRE([AC_FUNC_MMAP]) 23AC_CACHE_CHECK([for working strncmp], ac_cv_func_strncmp_works, 24[AC_TRY_RUN([ 25/* Test by Jim Wilson and Kaveh Ghazi. 26 Check whether strncmp reads past the end of its string parameters. */ 27#include <sys/types.h> 28 29#ifdef HAVE_FCNTL_H 30#include <fcntl.h> 31#endif 32 33#ifdef HAVE_SYS_MMAN_H 34#include <sys/mman.h> 35#endif 36 37#ifndef MAP_ANON 38#ifdef MAP_ANONYMOUS 39#define MAP_ANON MAP_ANONYMOUS 40#else 41#define MAP_ANON MAP_FILE 42#endif 43#endif 44 45#ifndef MAP_FILE 46#define MAP_FILE 0 47#endif 48#ifndef O_RDONLY 49#define O_RDONLY 0 50#endif 51 52#define MAP_LEN 0x10000 53 54main () 55{ 56#if defined(HAVE_MMAP) || defined(HAVE_MMAP_ANYWHERE) 57 char *p; 58 int dev_zero; 59 60 dev_zero = open ("/dev/zero", O_RDONLY); 61 if (dev_zero < 0) 62 exit (1); 63 64 p = (char *) mmap (0, MAP_LEN, PROT_READ|PROT_WRITE, 65 MAP_ANON|MAP_PRIVATE, dev_zero, 0); 66 if (p == (char *)-1) 67 p = (char *) mmap (0, MAP_LEN, PROT_READ|PROT_WRITE, 68 MAP_ANON|MAP_PRIVATE, -1, 0); 69 if (p == (char *)-1) 70 exit (2); 71 else 72 { 73 char *string = "__si_type_info"; 74 char *q = (char *) p + MAP_LEN - strlen (string) - 2; 75 char *r = (char *) p + 0xe; 76 77 strcpy (q, string); 78 strcpy (r, string); 79 strncmp (r, q, 14); 80 } 81#endif /* HAVE_MMAP || HAVE_MMAP_ANYWHERE */ 82 exit (0); 83} 84], ac_cv_func_strncmp_works=yes, ac_cv_func_strncmp_works=no, 85 ac_cv_func_strncmp_works=yes) 86rm -f core core.* *.core]) 87if test $ac_cv_func_strncmp_works = no ; then 88 AC_LIBOBJ([strncmp]) 89fi 90]) 91 92dnl See if errno must be declared even when <errno.h> is included. 93AC_DEFUN([libiberty_AC_DECLARE_ERRNO], 94[AC_CACHE_CHECK(whether errno must be declared, libiberty_cv_declare_errno, 95[AC_TRY_COMPILE( 96[#include <errno.h>], 97[int x = errno;], 98libiberty_cv_declare_errno=no, 99libiberty_cv_declare_errno=yes)]) 100if test $libiberty_cv_declare_errno = yes 101then AC_DEFINE(NEED_DECLARATION_ERRNO, 1, 102 [Define if errno must be declared even when <errno.h> is included.]) 103fi 104]) 105 106dnl See whether we need a declaration for a function. 107AC_DEFUN([libiberty_NEED_DECLARATION], 108[AC_MSG_CHECKING([whether $1 must be declared]) 109AC_CACHE_VAL(libiberty_cv_decl_needed_$1, 110[AC_TRY_COMPILE([ 111#include "confdefs.h" 112#include <stdio.h> 113#ifdef HAVE_STRING_H 114#include <string.h> 115#else 116#ifdef HAVE_STRINGS_H 117#include <strings.h> 118#endif 119#endif 120#ifdef HAVE_STDLIB_H 121#include <stdlib.h> 122#endif 123#ifdef HAVE_UNISTD_H 124#include <unistd.h> 125#endif], 126[char *(*pfn) = (char *(*)) $1], 127libiberty_cv_decl_needed_$1=no, libiberty_cv_decl_needed_$1=yes)]) 128AC_MSG_RESULT($libiberty_cv_decl_needed_$1) 129if test $libiberty_cv_decl_needed_$1 = yes; then 130 AC_DEFINE([NEED_DECLARATION_]translit($1, [a-z], [A-Z]), 1, 131 [Define if $1 is not declared in system header files.]) 132fi 133])dnl 134 135# We always want a C version of alloca() compiled into libiberty, 136# because native-compiler support for the real alloca is so !@#$% 137# unreliable that GCC has decided to use it only when being compiled 138# by GCC. This is the part of AC_FUNC_ALLOCA that calculates the 139# information alloca.c needs. 140AC_DEFUN([libiberty_AC_FUNC_C_ALLOCA], 141[AC_CACHE_CHECK(whether alloca needs Cray hooks, ac_cv_os_cray, 142[AC_EGREP_CPP(webecray, 143[#if defined(CRAY) && ! defined(CRAY2) 144webecray 145#else 146wenotbecray 147#endif 148], ac_cv_os_cray=yes, ac_cv_os_cray=no)]) 149if test $ac_cv_os_cray = yes; then 150 for ac_func in _getb67 GETB67 getb67; do 151 AC_CHECK_FUNC($ac_func, 152 [AC_DEFINE_UNQUOTED(CRAY_STACKSEG_END, $ac_func, 153 [Define to one of _getb67, GETB67, getb67 for Cray-2 and Cray-YMP 154 systems. This function is required for alloca.c support on those 155 systems.]) break]) 156 done 157fi 158 159AC_CACHE_CHECK(stack direction for C alloca, ac_cv_c_stack_direction, 160[AC_TRY_RUN([find_stack_direction () 161{ 162 static char *addr = 0; 163 auto char dummy; 164 if (addr == 0) 165 { 166 addr = &dummy; 167 return find_stack_direction (); 168 } 169 else 170 return (&dummy > addr) ? 1 : -1; 171} 172main () 173{ 174 exit (find_stack_direction() < 0); 175}], 176 ac_cv_c_stack_direction=1, 177 ac_cv_c_stack_direction=-1, 178 ac_cv_c_stack_direction=0)]) 179AC_DEFINE_UNQUOTED(STACK_DIRECTION, $ac_cv_c_stack_direction, 180 [Define if you know the direction of stack growth for your system; 181 otherwise it will be automatically deduced at run-time. 182 STACK_DIRECTION > 0 => grows toward higher addresses 183 STACK_DIRECTION < 0 => grows toward lower addresses 184 STACK_DIRECTION = 0 => direction of growth unknown]) 185]) 186