gcc/testsuite/
[official-gcc.git] / libsanitizer / configure.ac
blobe6721312d0ce78eb8adc4525cd755a12080baa14
1 #                                               -*- Autoconf -*-
2 # Process this file with autoconf to produce a configure script.
4 AC_PREREQ([2.64])
5 AC_INIT(package-unused, version-unused, libsanitizer)
6 AC_CONFIG_SRCDIR([include/sanitizer/common_interface_defs.h])
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)
19 AC_USE_SYSTEM_EXTENSIONS
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
28 AM_INIT_AUTOMAKE(foreign no-dist)
29 AM_ENABLE_MULTILIB(, ..)
30 AM_MAINTAINER_MODE
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)
62 # Checks for programs.
63 AC_PROG_CC
64 AC_PROG_CXX
65 AM_PROG_AS
66 AC_PROG_RANLIB
68 AC_LIBTOOL_DLOPEN
69 AM_PROG_LIBTOOL
71 AC_PROG_AWK
72 case "$AWK" in
73 "") AC_MSG_ERROR([can't build without awk]) ;;
74 esac
76 AC_SUBST(enable_shared)
77 AC_SUBST(enable_static)
79 AC_CHECK_SIZEOF([void *])
81 if test "${multilib}" = "yes"; then
82   multilib_arg="--enable-multilib"
83 else
84   multilib_arg=
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"])
94 # Check for functions needed.
95 AC_CHECK_FUNCS(clock_getres clock_gettime clock_settime)
97 # Common libraries that we need to link against for all sanitizer libs.
98 link_sanitizer_common='-lpthread -ldl -lm'
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)
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)
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)
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)
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
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)
133 backtrace_supported=yes
135 AC_MSG_CHECKING([for necessary platform features])
136 case "$target" in
137   *-*-linux*)
138     # Some old Linux distributions miss required syscalls.
139     sanitizer_supported=no
140     AC_TRY_COMPILE([#include <sys/syscall.h>],[
141       syscall (__NR_gettid);
142       syscall (__NR_futex);
143       syscall (__NR_exit_group);
144     ], [sanitizer_supported=yes])
145     ;;
146   *)
147     sanitizer_supported=yes
148     ;;
149 esac
150 AC_MSG_RESULT($sanitizer_supported)
151 AM_CONDITIONAL(SANITIZER_SUPPORTED, test "$sanitizer_supported" = yes)
153 # Test for __sync support.
154 AC_CACHE_CHECK([__sync extensions],
155 [libsanitizer_cv_sys_sync],
156 [if test -n "${with_target_subdir}"; then
157    libsanitizer_cv_sys_sync=yes
158  else
159    AC_LINK_IFELSE(
160      [AC_LANG_PROGRAM([int i;],
161                       [__sync_bool_compare_and_swap (&i, i, i);
162                        __sync_lock_test_and_set (&i, 1);
163                        __sync_lock_release (&i);])],
164      [libsanitizer_cv_sys_sync=yes],
165      [libsanitizer_cv_sys_sync=no])
166  fi])
167 if test "$libsanitizer_cv_sys_sync" = "yes"; then
168   AC_DEFINE([HAVE_SYNC_FUNCTIONS], 1,
169             [Define to 1 if you have the __sync functions])
172 # Test for __atomic support.
173 AC_CACHE_CHECK([__atomic extensions],
174 [libsanitizer_cv_sys_atomic],
175 [if test -n "${with_target_subdir}"; then
176    libsanitizer_cv_sys_atomic=yes
177  else
178    AC_LINK_IFELSE(
179      [AC_LANG_PROGRAM([int i;],
180                       [__atomic_load_n (&i, __ATOMIC_ACQUIRE);
181                        __atomic_store_n (&i, 1, __ATOMIC_RELEASE);])],
182      [libsanitizer_cv_sys_atomic=yes],
183      [libsanitizer_cv_sys_atomic=no])
184  fi])
185 if test "$libsanitizer_cv_sys_atomic" = "yes"; then
186   AC_DEFINE([HAVE_ATOMIC_FUNCTIONS], 1,
187             [Define to 1 if you have the __atomic functions])
190 # The library needs to be able to read the executable itself.  Compile
191 # a file to determine the executable format.  The awk script
192 # filetype.awk prints out the file type.
193 AC_CACHE_CHECK([output filetype],
194 [libsanitizer_cv_sys_filetype],
195 [filetype=
196 AC_COMPILE_IFELSE(
197   [AC_LANG_PROGRAM([int i;], [int j;])],
198   [filetype=`${AWK} -f $srcdir/../libbacktrace/filetype.awk conftest.$ac_objext`],
199   [AC_MSG_FAILURE([compiler failed])])
200 libsanitizer_cv_sys_filetype=$filetype])
202 # Match the file type to decide what files to compile.
203 FORMAT_FILE=
204 case "$libsanitizer_cv_sys_filetype" in
205 elf*) FORMAT_FILE="elf.lo" ;;
206 *) AC_MSG_WARN([could not determine output file type])
207    FORMAT_FILE="unknown.lo"
208    backtrace_supported=no
209    ;;
210 esac
211 AC_SUBST(FORMAT_FILE)
213 # ELF defines.
214 elfsize=
215 case "$libsanitizer_cv_sys_filetype" in
216 elf32) elfsize=32 ;;
217 elf64) elfsize=64 ;;
218 esac
219 AC_DEFINE_UNQUOTED([BACKTRACE_ELF_SIZE], [$elfsize], [ELF size: 32 or 64])
221 BACKTRACE_SUPPORTED=0
222 if test "$backtrace_supported" = "yes"; then
223   BACKTRACE_SUPPORTED=1
225 AC_SUBST(BACKTRACE_SUPPORTED)
227 GCC_HEADER_STDINT(gstdint.h)
229 AC_CHECK_HEADERS(sys/mman.h alloca.h)
230 if test "$ac_cv_header_sys_mman_h" = "no"; then
231   have_mmap=no
232 else
233   if test -n "${with_target_subdir}"; then
234     # When built as a GCC target library, we can't do a link test.  We
235     # simply assume that if we have mman.h, we have mmap.
236     have_mmap=yes
237   else
238     AC_CHECK_FUNC(mmap, [have_mmap=yes], [have_mmap=no])
239   fi
241 if test "$have_mmap" = "no"; then
242   VIEW_FILE=read.lo
243   ALLOC_FILE=alloc.lo
244 else
245   VIEW_FILE=mmapio.lo
246   AC_PREPROC_IFELSE([
247 #include <sys/mman.h>
248 #if !defined(MAP_ANONYMOUS) && !defined(MAP_ANON)
249   #error no MAP_ANONYMOUS
250 #endif
251 ], [ALLOC_FILE=mmap.lo], [ALLOC_FILE=alloc.lo])
253 AC_SUBST(VIEW_FILE)
254 AC_SUBST(ALLOC_FILE)
256 BACKTRACE_USES_MALLOC=0
257 if test "$ALLOC_FILE" = "alloc.lo"; then
258   BACKTRACE_USES_MALLOC=1
260 AC_SUBST(BACKTRACE_USES_MALLOC)
262 # Don't care about thread support
263 BACKTRACE_SUPPORTS_THREADS=0
264 AC_SUBST(BACKTRACE_SUPPORTS_THREADS)
266 # Check for dl_iterate_phdr.
267 AC_CHECK_HEADERS(link.h)
268 if test "$ac_cv_header_link_h" = "no"; then
269   have_dl_iterate_phdr=no
270 else
271   # When built as a GCC target library, we can't do a link test.
272   AC_EGREP_HEADER([dl_iterate_phdr], [link.h], [have_dl_iterate_phdr=yes],
273                   [have_dl_iterate_phdr=no])
274   case "${host}" in
275   *-*-solaris2.10*)
276     # Avoid dl_iterate_phdr on Solaris 10, where it is in the
277     # header file but is only in -ldl.
278     have_dl_iterate_phdr=no ;;
279   esac
281 if test "$have_dl_iterate_phdr" = "yes"; then
282   AC_DEFINE(HAVE_DL_ITERATE_PHDR, 1, [Define if dl_iterate_phdr is available.])
285 # Check for the fcntl function.
286 if test -n "${with_target_subdir}"; then
287    case "${host}" in
288    *-*-mingw*) have_fcntl=no ;;
289    *) have_fcntl=yes ;;
290    esac
291 else
292   AC_CHECK_FUNC(fcntl, [have_fcntl=yes], [have_fcntl=no])
294 if test "$have_fcntl" = "yes"; then
295   AC_DEFINE([HAVE_FCNTL], 1,
296             [Define to 1 if you have the fcntl function])
299 AC_CHECK_DECLS(strnlen)
301 # Check for getexecname function.
302 if test -n "${with_target_subdir}"; then
303    case "${host}" in
304    *-*-solaris2*) have_getexecname=yes ;;
305    *) have_getexecname=no ;;
306    esac
307 else
308   AC_CHECK_FUNC(getexecname, [have_getexecname=yes], [have_getexecname=no])
310 if test "$have_getexecname" = "yes"; then
311   AC_DEFINE(HAVE_GETEXECNAME, 1, [Define if getexecname is available.])
314 AM_CONDITIONAL(LIBBACKTRACE_SUPPORTED,
315                [test "x${BACKTRACE_SUPPORTED}x${BACKTRACE_USES_MALLOC}" = "x1x0"])
317 AH_BOTTOM([#include "libbacktrace/backtrace-rename.h"])
318 AC_CONFIG_FILES([Makefile libsanitizer.spec libbacktrace/backtrace-supported.h])
319 AC_CONFIG_HEADER(config.h)
321 AC_CONFIG_FILES(AC_FOREACH([DIR], [interception sanitizer_common libbacktrace lsan asan ubsan], [DIR/Makefile ]),
322   [cat > vpsed$$ << \_EOF
323 s!`test -f '$<' || echo '$(srcdir)/'`!!
324 _EOF
325    sed -f vpsed$$ $ac_file > tmp$$
326    mv tmp$$ $ac_file
327    rm vpsed$$
328    echo 'MULTISUBDIR =' >> $ac_file
329    ml_norecursion=yes
330    . ${multi_basedir}/config-ml.in
331    AS_UNSET([ml_norecursion])
334 if test "x$TSAN_SUPPORTED" = "xyes"; then
335   AC_CONFIG_FILES(AC_FOREACH([DIR], [tsan], [DIR/Makefile ]), 
336     [cat > vpsed$$ << \_EOF
337 s!`test -f '$<' || echo '$(srcdir)/'`!!
338 _EOF
339     sed -f vpsed$$ $ac_file > tmp$$
340     mv tmp$$ $ac_file
341     rm vpsed$$
342     echo 'MULTISUBDIR =' >> $ac_file
343     ml_norecursion=yes
344     . ${multi_basedir}/config-ml.in
345     AS_UNSET([ml_norecursion])
349 AC_OUTPUT