acinclude.m4 5.2 KB

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