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