Fix build on sparc64-linux-gnu.
[official-gcc.git] / libsanitizer / configure.ac
blob02c7398fcc62aed47aefe18944ef32f8287bb661
1 #                                               -*- Autoconf -*-
2 # Process this file with autoconf to produce a configure script.
4 AC_INIT(package-unused, version-unused, libsanitizer)
5 AC_CONFIG_SRCDIR([include/sanitizer/common_interface_defs.h])
7 AM_ENABLE_MULTILIB(, ..)
9 AC_MSG_CHECKING([for --enable-version-specific-runtime-libs])
10 AC_ARG_ENABLE(version-specific-runtime-libs,
11 [  --enable-version-specific-runtime-libs    Specify that runtime libraries should be installed in a compiler-specific directory ],
12 [case "$enableval" in
13  yes) version_specific_libs=yes ;;
14  no)  version_specific_libs=no ;;
15  *)   AC_MSG_ERROR([Unknown argument to enable/disable version-specific libs]);;
16  esac],
17 [version_specific_libs=no])
18 AC_MSG_RESULT($version_specific_libs)
20 AC_USE_SYSTEM_EXTENSIONS
22 # Do not delete or change the following two lines.  For why, see
23 # http://gcc.gnu.org/ml/libstdc++/2003-07/msg00451.html
24 AC_CANONICAL_SYSTEM
25 target_alias=${target_alias-$host_alias}
26 AC_SUBST(target_alias)
27 GCC_LIBSTDCXX_RAW_CXX_FLAGS
29 AM_INIT_AUTOMAKE(foreign no-dist)
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 lstat readlink)
97 # Common libraries that we need to link against for all sanitizer libs.
98 link_sanitizer_common='-lpthread -lm'
100 # At least for glibc, shm_open is in librt.  But don't pull that
101 # in if it still doesn't give us the function we want.  This
102 # test is copied from libgomp.
103 AC_CHECK_LIB(rt, shm_open,
104   [link_sanitizer_common="-lrt $link_sanitizer_common"])
106 # Do a configure time check for -ldl
107 AC_CHECK_LIB(dl, dlsym,
108   [link_sanitizer_common="-ldl $link_sanitizer_common"])
110 # Set up the set of additional libraries that we need to link against for libasan.
111 link_libasan=$link_sanitizer_common
112 AC_SUBST(link_libasan)
114 # Set up the set of additional libraries that we need to link against for libtsan.
115 link_libtsan=$link_sanitizer_common
116 AC_SUBST(link_libtsan)
118 # Set up the set of additional libraries that we need to link against for libubsan.
119 link_libubsan=$link_sanitizer_common
120 AC_SUBST(link_libubsan)
122 # Set up the set of additional libraries that we need to link against for liblsan.
123 link_liblsan=$link_sanitizer_common
124 AC_SUBST(link_liblsan)
127 # At least for glibc, clock_gettime is in librt.  But don't pull that
128 # in if it still doesn't give us the function we want.  This
129 # test is copied from libgomp.
130 AC_CHECK_LIB(rt, clock_gettime,
131   [link_libasan="-lrt $link_libasan"
132 link_libtsan="-lrt $link_libtsan"
133 # Other sanitizers do not override clock_* API
136 case "$host" in
137   *-*-darwin*) MAC_INTERPOSE=true ; enable_static=no ;;
138   *) MAC_INTERPOSE=false ;;
139 esac
140 AM_CONDITIONAL(USING_MAC_INTERPOSE, $MAC_INTERPOSE)
142 backtrace_supported=yes
144 AC_MSG_CHECKING([for necessary platform features])
145 case "$target" in
146   *-*-linux*)
147     # Some old Linux distributions miss required syscalls.
148     sanitizer_supported=no
149     AC_TRY_COMPILE([#include <sys/syscall.h>],[
150       syscall (__NR_gettid);
151       syscall (__NR_futex);
152       syscall (__NR_exit_group);
153     ], [sanitizer_supported=yes])
154     ;;
155   *)
156     sanitizer_supported=yes
157     ;;
158 esac
159 AC_MSG_RESULT($sanitizer_supported)
160 AM_CONDITIONAL(SANITIZER_SUPPORTED, test "$sanitizer_supported" = yes)
162 # Test for __sync support.
163 AC_CACHE_CHECK([__sync extensions],
164 [libsanitizer_cv_sys_sync],
165 [if test -n "${with_target_subdir}"; then
166    libsanitizer_cv_sys_sync=yes
167  else
168    AC_LINK_IFELSE(
169      [AC_LANG_PROGRAM([int i;],
170                       [__sync_bool_compare_and_swap (&i, i, i);
171                        __sync_lock_test_and_set (&i, 1);
172                        __sync_lock_release (&i);])],
173      [libsanitizer_cv_sys_sync=yes],
174      [libsanitizer_cv_sys_sync=no])
175  fi])
176 if test "$libsanitizer_cv_sys_sync" = "yes"; then
177   AC_DEFINE([HAVE_SYNC_FUNCTIONS], 1,
178             [Define to 1 if you have the __sync functions])
181 # Test for __atomic support.
182 AC_CACHE_CHECK([__atomic extensions],
183 [libsanitizer_cv_sys_atomic],
184 [if test -n "${with_target_subdir}"; then
185    libsanitizer_cv_sys_atomic=yes
186  else
187    AC_LINK_IFELSE(
188      [AC_LANG_PROGRAM([int i;],
189                       [__atomic_load_n (&i, __ATOMIC_ACQUIRE);
190                        __atomic_store_n (&i, 1, __ATOMIC_RELEASE);])],
191      [libsanitizer_cv_sys_atomic=yes],
192      [libsanitizer_cv_sys_atomic=no])
193  fi])
194 if test "$libsanitizer_cv_sys_atomic" = "yes"; then
195   AC_DEFINE([HAVE_ATOMIC_FUNCTIONS], 1,
196             [Define to 1 if you have the __atomic functions])
199 # The library needs to be able to read the executable itself.  Compile
200 # a file to determine the executable format.  The awk script
201 # filetype.awk prints out the file type.
202 AC_CACHE_CHECK([output filetype],
203 [libsanitizer_cv_sys_filetype],
204 [filetype=
205 AC_COMPILE_IFELSE(
206   [AC_LANG_PROGRAM([int i;], [int j;])],
207   [filetype=`${AWK} -f $srcdir/../libbacktrace/filetype.awk conftest.$ac_objext`],
208   [AC_MSG_FAILURE([compiler failed])])
209 libsanitizer_cv_sys_filetype=$filetype])
211 # Match the file type to decide what files to compile.
212 FORMAT_FILE=
213 case "$libsanitizer_cv_sys_filetype" in
214 elf*) FORMAT_FILE="elf.lo" ;;
215 *) AC_MSG_WARN([could not determine output file type])
216    FORMAT_FILE="unknown.lo"
217    backtrace_supported=no
218    ;;
219 esac
220 AC_SUBST(FORMAT_FILE)
222 # ELF defines.
223 elfsize=
224 case "$libsanitizer_cv_sys_filetype" in
225 elf32) elfsize=32 ;;
226 elf64) elfsize=64 ;;
227 esac
228 AC_DEFINE_UNQUOTED([BACKTRACE_ELF_SIZE], [$elfsize], [ELF size: 32 or 64])
230 BACKTRACE_SUPPORTED=0
231 if test "$backtrace_supported" = "yes"; then
232   BACKTRACE_SUPPORTED=1
234 AC_SUBST(BACKTRACE_SUPPORTED)
236 GCC_HEADER_STDINT(gstdint.h)
238 AC_CHECK_HEADERS(sys/mman.h alloca.h)
239 if test "$ac_cv_header_sys_mman_h" = "no"; then
240   have_mmap=no
241 else
242   if test -n "${with_target_subdir}"; then
243     # When built as a GCC target library, we can't do a link test.  We
244     # simply assume that if we have mman.h, we have mmap.
245     have_mmap=yes
246   else
247     AC_CHECK_FUNC(mmap, [have_mmap=yes], [have_mmap=no])
248   fi
250 if test "$have_mmap" = "no"; then
251   VIEW_FILE=read.lo
252   ALLOC_FILE=alloc.lo
253 else
254   VIEW_FILE=mmapio.lo
255   AC_PREPROC_IFELSE([AC_LANG_SOURCE([
256 #include <sys/mman.h>
257 #if !defined(MAP_ANONYMOUS) && !defined(MAP_ANON)
258   #error no MAP_ANONYMOUS
259 #endif
260 ])], [ALLOC_FILE=mmap.lo], [ALLOC_FILE=alloc.lo])
262 AC_SUBST(VIEW_FILE)
263 AC_SUBST(ALLOC_FILE)
265 BACKTRACE_USES_MALLOC=0
266 if test "$ALLOC_FILE" = "alloc.lo"; then
267   BACKTRACE_USES_MALLOC=1
269 AC_SUBST(BACKTRACE_USES_MALLOC)
271 # Don't care about thread support
272 BACKTRACE_SUPPORTS_THREADS=0
273 AC_SUBST(BACKTRACE_SUPPORTS_THREADS)
275 # Check for dl_iterate_phdr.
276 AC_CHECK_HEADERS(link.h)
277 if test "$ac_cv_header_link_h" = "no"; then
278   have_dl_iterate_phdr=no
279 else
280   # When built as a GCC target library, we can't do a link test.
281   AC_EGREP_HEADER([dl_iterate_phdr], [link.h], [have_dl_iterate_phdr=yes],
282                   [have_dl_iterate_phdr=no])
283   case "${host}" in
284   *-*-solaris2.10*)
285     # Avoid dl_iterate_phdr on Solaris 10, where it is in the
286     # header file but is only in -ldl.
287     have_dl_iterate_phdr=no ;;
288   esac
290 if test "$have_dl_iterate_phdr" = "yes"; then
291   AC_DEFINE(HAVE_DL_ITERATE_PHDR, 1, [Define if dl_iterate_phdr is available.])
294 # Check for the fcntl function.
295 if test -n "${with_target_subdir}"; then
296    case "${host}" in
297    *-*-mingw*) have_fcntl=no ;;
298    *) have_fcntl=yes ;;
299    esac
300 else
301   AC_CHECK_FUNC(fcntl, [have_fcntl=yes], [have_fcntl=no])
303 if test "$have_fcntl" = "yes"; then
304   AC_DEFINE([HAVE_FCNTL], 1,
305             [Define to 1 if you have the fcntl function])
308 AC_CHECK_DECLS(strnlen)
310 # Check for getexecname function.
311 if test -n "${with_target_subdir}"; then
312    case "${host}" in
313    *-*-solaris2*) have_getexecname=yes ;;
314    *) have_getexecname=no ;;
315    esac
316 else
317   AC_CHECK_FUNC(getexecname, [have_getexecname=yes], [have_getexecname=no])
319 if test "$have_getexecname" = "yes"; then
320   AC_DEFINE(HAVE_GETEXECNAME, 1, [Define if getexecname is available.])
323 # Check for rpc/xdr.h
324 AC_CHECK_HEADERS(rpc/xdr.h)
325 if test x"$ac_cv_header_rpc_xdr_h" = xyes; then
326   rpc_defs="$rpc_defs -DHAVE_RPC_XDR_H=1"
327 else
328   rpc_defs="$rpc_defs -DHAVE_RPC_XDR_H=0"
331 # Check for tirpc/rpc/xdr.h
332 AC_CHECK_HEADERS(tirpc/rpc/xdr.h)
333 if test x"$ac_cv_header_tirpc_rpc_xdr_h" = xyes; then
334   rpc_defs="$rpc_defs -DHAVE_TIRPC_RPC_XDR_H=1"
335 else
336   rpc_defs="$rpc_defs -DHAVE_TIRPC_RPC_XDR_H=0"
339 AC_SUBST([RPC_DEFS], [$rpc_defs])
341 AM_CONDITIONAL(LIBBACKTRACE_SUPPORTED,
342                [test "x${BACKTRACE_SUPPORTED}x${BACKTRACE_USES_MALLOC}" = "x1x0"])
344 AH_BOTTOM([#include "libbacktrace/backtrace-rename.h"])
345 AC_CONFIG_FILES([Makefile libsanitizer.spec libbacktrace/backtrace-supported.h])
346 AC_CONFIG_HEADER(config.h)
348 AC_CONFIG_FILES(AC_FOREACH([DIR], [interception sanitizer_common libbacktrace lsan asan ubsan], [DIR/Makefile ]),
349   [cat > vpsed$$ << \_EOF
350 s!`test -f '$<' || echo '$(srcdir)/'`!!
351 _EOF
352    sed -f vpsed$$ $ac_file > tmp$$
353    mv tmp$$ $ac_file
354    rm vpsed$$
355    echo 'MULTISUBDIR =' >> $ac_file
356    ml_norecursion=yes
357    . ${multi_basedir}/config-ml.in
358    AS_UNSET([ml_norecursion])
361 if test "x$TSAN_SUPPORTED" = "xyes"; then
362   AC_CONFIG_FILES(AC_FOREACH([DIR], [tsan], [DIR/Makefile ]), 
363     [cat > vpsed$$ << \_EOF
364 s!`test -f '$<' || echo '$(srcdir)/'`!!
365 _EOF
366     sed -f vpsed$$ $ac_file > tmp$$
367     mv tmp$$ $ac_file
368     rm vpsed$$
369     echo 'MULTISUBDIR =' >> $ac_file
370     ml_norecursion=yes
371     . ${multi_basedir}/config-ml.in
372     AS_UNSET([ml_norecursion])
376 AC_SUBST([TSAN_TARGET_DEPENDENT_OBJECTS])
377 AC_SUBST([SANITIZER_COMMON_TARGET_DEPENDENT_OBJECTS])
379 # Determine what GCC version number to use in filesystem paths.
380 GCC_BASE_VER
382 # Add CET specific flags if Intel CET is enabled.
383 GCC_CET_FLAGS(CET_FLAGS)
384 EXTRA_CFLAGS="$EXTRA_CFLAGS $CET_FLAGS"
385 EXTRA_CXXFLAGS="$EXTRA_CXXFLAGS $CET_FLAGS"
386 EXTRA_ASFLAGS=$CET_FLAGS
387 AC_SUBST(EXTRA_ASFLAGS)
388 AC_SUBST(EXTRA_CFLAGS)
389 AC_SUBST(EXTRA_CXXFLAGS)
391 AC_OUTPUT