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