]> git.ipfire.org Git - thirdparty/gcc.git/blob - libsanitizer/configure.ac
Merge in trunk.
[thirdparty/gcc.git] / libsanitizer / configure.ac
1 # -*- Autoconf -*-
2 # Process this file with autoconf to produce a configure script.
3
4 AC_PREREQ([2.64])
5 AC_INIT(package-unused, version-unused, libsanitizer)
6 AC_CONFIG_SRCDIR([include/sanitizer/common_interface_defs.h])
7
8 AC_MSG_CHECKING([for --enable-version-specific-runtime-libs])
9 AC_ARG_ENABLE(version-specific-runtime-libs,
10 [ --enable-version-specific-runtime-libs Specify that runtime libraries should be installed in a compiler-specific directory ],
11 [case "$enableval" in
12 yes) version_specific_libs=yes ;;
13 no) version_specific_libs=no ;;
14 *) AC_MSG_ERROR([Unknown argument to enable/disable version-specific libs]);;
15 esac],
16 [version_specific_libs=no])
17 AC_MSG_RESULT($version_specific_libs)
18
19 AC_USE_SYSTEM_EXTENSIONS
20
21 # Do not delete or change the following two lines. For why, see
22 # http://gcc.gnu.org/ml/libstdc++/2003-07/msg00451.html
23 AC_CANONICAL_SYSTEM
24 target_alias=${target_alias-$host_alias}
25 AC_SUBST(target_alias)
26 GCC_LIBSTDCXX_RAW_CXX_FLAGS
27
28 AM_INIT_AUTOMAKE(foreign no-dist)
29 AM_ENABLE_MULTILIB(, ..)
30 AM_MAINTAINER_MODE
31
32 # Calculate toolexeclibdir
33 # Also toolexecdir, though it's only used in toolexeclibdir
34 case ${version_specific_libs} in
35 yes)
36 # Need the gcc compiler version to know where to install libraries
37 # and header files if --enable-version-specific-runtime-libs option
38 # is selected.
39 toolexecdir='$(libdir)/gcc/$(target_alias)'
40 toolexeclibdir='$(toolexecdir)/$(gcc_version)$(MULTISUBDIR)'
41 ;;
42 no)
43 if test -n "$with_cross_host" &&
44 test x"$with_cross_host" != x"no"; then
45 # Install a library built with a cross compiler in tooldir, not libdir.
46 toolexecdir='$(exec_prefix)/$(target_alias)'
47 toolexeclibdir='$(toolexecdir)/lib'
48 else
49 toolexecdir='$(libdir)/gcc-lib/$(target_alias)'
50 toolexeclibdir='$(libdir)'
51 fi
52 multi_os_directory=`$CC -print-multi-os-directory`
53 case $multi_os_directory in
54 .) ;; # Avoid trailing /.
55 *) toolexeclibdir=$toolexeclibdir/$multi_os_directory ;;
56 esac
57 ;;
58 esac
59 AC_SUBST(toolexecdir)
60 AC_SUBST(toolexeclibdir)
61
62 # Checks for programs.
63 AC_PROG_CC
64 AC_PROG_CXX
65 AM_PROG_AS
66 AC_PROG_RANLIB
67
68 AC_LIBTOOL_DLOPEN
69 AM_PROG_LIBTOOL
70
71 AC_PROG_AWK
72 case "$AWK" in
73 "") AC_MSG_ERROR([can't build without awk]) ;;
74 esac
75
76 AC_SUBST(enable_shared)
77 AC_SUBST(enable_static)
78
79 AC_CHECK_SIZEOF([void *])
80
81 if test "${multilib}" = "yes"; then
82 multilib_arg="--enable-multilib"
83 else
84 multilib_arg=
85 fi
86
87 # Get target configury.
88 unset TSAN_SUPPORTED
89 unset LSAN_SUPPORTED
90 . ${srcdir}/configure.tgt
91 AM_CONDITIONAL(TSAN_SUPPORTED, [test "x$TSAN_SUPPORTED" = "xyes"])
92 AM_CONDITIONAL(LSAN_SUPPORTED, [test "x$LSAN_SUPPORTED" = "xyes"])
93
94 # Check for functions needed.
95 AC_CHECK_FUNCS(clock_getres clock_gettime clock_settime)
96
97 # Common libraries that we need to link against for all sanitizer libs.
98 link_sanitizer_common='-lpthread -ldl -lm'
99
100 # Set up the set of additional libraries that we need to link against for libasan.
101 link_libasan=$link_sanitizer_common
102 AC_SUBST(link_libasan)
103
104 # Set up the set of additional libraries that we need to link against for libtsan.
105 link_libtsan=$link_sanitizer_common
106 AC_SUBST(link_libtsan)
107
108 # Set up the set of additional libraries that we need to link against for libubsan.
109 link_libubsan=$link_sanitizer_common
110 AC_SUBST(link_libubsan)
111
112 # Set up the set of additional libraries that we need to link against for liblsan.
113 link_liblsan=$link_sanitizer_common
114 AC_SUBST(link_liblsan)
115
116 # At least for glibc, clock_gettime is in librt. But don't pull that
117 # in if it still doesn't give us the function we want. This
118 # test is copied from libgomp.
119 if test $ac_cv_func_clock_gettime = no; then
120 AC_CHECK_LIB(rt, clock_gettime,
121 [link_libasan="-lrt $link_libasan"
122 link_libtsan="-lrt $link_libtsan"
123 # Other sanitizers do not override clock_* API
124 ])
125 fi
126
127 case "$host" in
128 *-*-darwin*) MAC_INTERPOSE=true ; enable_static=no ;;
129 *) MAC_INTERPOSE=false ;;
130 esac
131 AM_CONDITIONAL(USING_MAC_INTERPOSE, $MAC_INTERPOSE)
132
133 backtrace_supported=yes
134
135 # Test for __sync support.
136 AC_CACHE_CHECK([__sync extensions],
137 [libsanitizer_cv_sys_sync],
138 [if test -n "${with_target_subdir}"; then
139 libsanitizer_cv_sys_sync=yes
140 else
141 AC_LINK_IFELSE(
142 [AC_LANG_PROGRAM([int i;],
143 [__sync_bool_compare_and_swap (&i, i, i);
144 __sync_lock_test_and_set (&i, 1);
145 __sync_lock_release (&i);])],
146 [libsanitizer_cv_sys_sync=yes],
147 [libsanitizer_cv_sys_sync=no])
148 fi])
149 if test "$libsanitizer_cv_sys_sync" = "yes"; then
150 AC_DEFINE([HAVE_SYNC_FUNCTIONS], 1,
151 [Define to 1 if you have the __sync functions])
152 fi
153
154 # Test for __atomic support.
155 AC_CACHE_CHECK([__atomic extensions],
156 [libsanitizer_cv_sys_atomic],
157 [if test -n "${with_target_subdir}"; then
158 libsanitizer_cv_sys_atomic=yes
159 else
160 AC_LINK_IFELSE(
161 [AC_LANG_PROGRAM([int i;],
162 [__atomic_load_n (&i, __ATOMIC_ACQUIRE);
163 __atomic_store_n (&i, 1, __ATOMIC_RELEASE);])],
164 [libsanitizer_cv_sys_atomic=yes],
165 [libsanitizer_cv_sys_atomic=no])
166 fi])
167 if test "$libsanitizer_cv_sys_atomic" = "yes"; then
168 AC_DEFINE([HAVE_ATOMIC_FUNCTIONS], 1,
169 [Define to 1 if you have the __atomic functions])
170 fi
171
172 # The library needs to be able to read the executable itself. Compile
173 # a file to determine the executable format. The awk script
174 # filetype.awk prints out the file type.
175 AC_CACHE_CHECK([output filetype],
176 [libsanitizer_cv_sys_filetype],
177 [filetype=
178 AC_COMPILE_IFELSE(
179 [AC_LANG_PROGRAM([int i;], [int j;])],
180 [filetype=`${AWK} -f $srcdir/../libbacktrace/filetype.awk conftest.$ac_objext`],
181 [AC_MSG_FAILURE([compiler failed])])
182 libsanitizer_cv_sys_filetype=$filetype])
183
184 # Match the file type to decide what files to compile.
185 FORMAT_FILE=
186 case "$libsanitizer_cv_sys_filetype" in
187 elf*) FORMAT_FILE="elf.lo" ;;
188 *) AC_MSG_WARN([could not determine output file type])
189 FORMAT_FILE="unknown.lo"
190 backtrace_supported=no
191 ;;
192 esac
193 AC_SUBST(FORMAT_FILE)
194
195 # ELF defines.
196 elfsize=
197 case "$libsanitizer_cv_sys_filetype" in
198 elf32) elfsize=32 ;;
199 elf64) elfsize=64 ;;
200 esac
201 AC_DEFINE_UNQUOTED([BACKTRACE_ELF_SIZE], [$elfsize], [ELF size: 32 or 64])
202
203 BACKTRACE_SUPPORTED=0
204 if test "$backtrace_supported" = "yes"; then
205 BACKTRACE_SUPPORTED=1
206 fi
207 AC_SUBST(BACKTRACE_SUPPORTED)
208
209 GCC_HEADER_STDINT(gstdint.h)
210
211 AC_CHECK_HEADERS(sys/mman.h alloca.h)
212 if test "$ac_cv_header_sys_mman_h" = "no"; then
213 have_mmap=no
214 else
215 if test -n "${with_target_subdir}"; then
216 # When built as a GCC target library, we can't do a link test. We
217 # simply assume that if we have mman.h, we have mmap.
218 have_mmap=yes
219 else
220 AC_CHECK_FUNC(mmap, [have_mmap=yes], [have_mmap=no])
221 fi
222 fi
223 if test "$have_mmap" = "no"; then
224 VIEW_FILE=read.lo
225 ALLOC_FILE=alloc.lo
226 else
227 VIEW_FILE=mmapio.lo
228 AC_PREPROC_IFELSE([
229 #include <sys/mman.h>
230 #if !defined(MAP_ANONYMOUS) && !defined(MAP_ANON)
231 #error no MAP_ANONYMOUS
232 #endif
233 ], [ALLOC_FILE=mmap.lo], [ALLOC_FILE=alloc.lo])
234 fi
235 AC_SUBST(VIEW_FILE)
236 AC_SUBST(ALLOC_FILE)
237
238 BACKTRACE_USES_MALLOC=0
239 if test "$ALLOC_FILE" = "alloc.lo"; then
240 BACKTRACE_USES_MALLOC=1
241 fi
242 AC_SUBST(BACKTRACE_USES_MALLOC)
243
244 # Don't care about thread support
245 BACKTRACE_SUPPORTS_THREADS=0
246 AC_SUBST(BACKTRACE_SUPPORTS_THREADS)
247
248 # Check for dl_iterate_phdr.
249 AC_CHECK_HEADERS(link.h)
250 if test "$ac_cv_header_link_h" = "no"; then
251 have_dl_iterate_phdr=no
252 else
253 # When built as a GCC target library, we can't do a link test.
254 AC_EGREP_HEADER([dl_iterate_phdr], [link.h], [have_dl_iterate_phdr=yes],
255 [have_dl_iterate_phdr=no])
256 case "${host}" in
257 *-*-solaris2.10*)
258 # Avoid dl_iterate_phdr on Solaris 10, where it is in the
259 # header file but is only in -ldl.
260 have_dl_iterate_phdr=no ;;
261 esac
262 fi
263 if test "$have_dl_iterate_phdr" = "yes"; then
264 AC_DEFINE(HAVE_DL_ITERATE_PHDR, 1, [Define if dl_iterate_phdr is available.])
265 fi
266
267 # Check for the fcntl function.
268 if test -n "${with_target_subdir}"; then
269 case "${host}" in
270 *-*-mingw*) have_fcntl=no ;;
271 *) have_fcntl=yes ;;
272 esac
273 else
274 AC_CHECK_FUNC(fcntl, [have_fcntl=yes], [have_fcntl=no])
275 fi
276 if test "$have_fcntl" = "yes"; then
277 AC_DEFINE([HAVE_FCNTL], 1,
278 [Define to 1 if you have the fcntl function])
279 fi
280
281 AC_CHECK_DECLS(strnlen)
282
283 # Check for getexecname function.
284 if test -n "${with_target_subdir}"; then
285 case "${host}" in
286 *-*-solaris2*) have_getexecname=yes ;;
287 *) have_getexecname=no ;;
288 esac
289 else
290 AC_CHECK_FUNC(getexecname, [have_getexecname=yes], [have_getexecname=no])
291 fi
292 if test "$have_getexecname" = "yes"; then
293 AC_DEFINE(HAVE_GETEXECNAME, 1, [Define if getexecname is available.])
294 fi
295
296 AM_CONDITIONAL(LIBBACKTRACE_SUPPORTED,
297 [test "x${BACKTRACE_SUPPORTED}x${BACKTRACE_USES_MALLOC}" = "x1x0"])
298
299 AH_BOTTOM([#include "libbacktrace/backtrace-rename.h"])
300 AC_CONFIG_FILES([Makefile libsanitizer.spec libbacktrace/backtrace-supported.h])
301 AC_CONFIG_HEADER(config.h)
302
303 AC_CONFIG_FILES(AC_FOREACH([DIR], [interception sanitizer_common libbacktrace lsan asan ubsan], [DIR/Makefile ]),
304 [cat > vpsed$$ << \_EOF
305 s!`test -f '$<' || echo '$(srcdir)/'`!!
306 _EOF
307 sed -f vpsed$$ $ac_file > tmp$$
308 mv tmp$$ $ac_file
309 rm vpsed$$
310 echo 'MULTISUBDIR =' >> $ac_file
311 ml_norecursion=yes
312 . ${multi_basedir}/config-ml.in
313 AS_UNSET([ml_norecursion])
314 ])
315
316 if test "x$TSAN_SUPPORTED" = "xyes"; then
317 AC_CONFIG_FILES(AC_FOREACH([DIR], [tsan], [DIR/Makefile ]),
318 [cat > vpsed$$ << \_EOF
319 s!`test -f '$<' || echo '$(srcdir)/'`!!
320 _EOF
321 sed -f vpsed$$ $ac_file > tmp$$
322 mv tmp$$ $ac_file
323 rm vpsed$$
324 echo 'MULTISUBDIR =' >> $ac_file
325 ml_norecursion=yes
326 . ${multi_basedir}/config-ml.in
327 AS_UNSET([ml_norecursion])
328 ])
329 fi
330
331 AC_OUTPUT