2 # Process this file with autoconf to produce a configure script.
5 AC_INIT(package-unused, version-unused, libsanitizer)
6 AC_CONFIG_SRCDIR([include/sanitizer/common_interface_defs.h])
8 AM_ENABLE_MULTILIB(, ..)
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 ],
14 yes) version_specific_libs=yes ;;
15 no) version_specific_libs=no ;;
16 *) AC_MSG_ERROR([Unknown argument to enable/disable version-specific libs]);;
18 [version_specific_libs=no])
19 AC_MSG_RESULT($version_specific_libs)
21 AC_USE_SYSTEM_EXTENSIONS
23 # Do not delete or change the following two lines. For why, see
24 # http://gcc.gnu.org/ml/libstdc++/2003-07/msg00451.html
26 target_alias=${target_alias-$host_alias}
27 AC_SUBST(target_alias)
28 GCC_LIBSTDCXX_RAW_CXX_FLAGS
30 AM_INIT_AUTOMAKE(foreign no-dist)
33 # Calculate toolexeclibdir
34 # Also toolexecdir, though it's only used in toolexeclibdir
35 case ${version_specific_libs} in
37 # Need the gcc compiler version to know where to install libraries
38 # and header files if --enable-version-specific-runtime-libs option
40 toolexecdir='$(libdir)/gcc/$(target_alias)'
41 toolexeclibdir='$(toolexecdir)/$(gcc_version)$(MULTISUBDIR)'
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'
50 toolexecdir='$(libdir)/gcc-lib/$(target_alias)'
51 toolexeclibdir='$(libdir)'
53 multi_os_directory=`$CC -print-multi-os-directory`
54 case $multi_os_directory in
55 .) ;; # Avoid trailing /.
56 *) toolexeclibdir=$toolexeclibdir/$multi_os_directory ;;
61 AC_SUBST(toolexeclibdir)
63 # Checks for programs.
74 "") AC_MSG_ERROR([can't build without awk]) ;;
77 AC_SUBST(enable_shared)
78 AC_SUBST(enable_static)
80 AC_CHECK_SIZEOF([void *])
82 if test "${multilib}" = "yes"; then
83 multilib_arg="--enable-multilib"
88 # Get target configury.
91 . ${srcdir}/configure.tgt
92 AM_CONDITIONAL(TSAN_SUPPORTED, [test "x$TSAN_SUPPORTED" = "xyes"])
93 AM_CONDITIONAL(LSAN_SUPPORTED, [test "x$LSAN_SUPPORTED" = "xyes"])
95 # Check for functions needed.
96 AC_CHECK_FUNCS(clock_getres clock_gettime clock_settime)
98 # Common libraries that we need to link against for all sanitizer libs.
99 link_sanitizer_common='-lpthread -lm'
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"])
107 # Do a configure time check for -ldl
108 AC_CHECK_LIB(dl, dlsym,
109 [link_sanitizer_common="-ldl $link_sanitizer_common"])
111 # Set up the set of additional libraries that we need to link against for libasan.
112 link_libasan=$link_sanitizer_common
113 AC_SUBST(link_libasan)
115 # Set up the set of additional libraries that we need to link against for libtsan.
116 link_libtsan=$link_sanitizer_common
117 AC_SUBST(link_libtsan)
119 # Set up the set of additional libraries that we need to link against for libubsan.
120 link_libubsan=$link_sanitizer_common
121 AC_SUBST(link_libubsan)
123 # Set up the set of additional libraries that we need to link against for liblsan.
124 link_liblsan=$link_sanitizer_common
125 AC_SUBST(link_liblsan)
128 # At least for glibc, clock_gettime is in librt. But don't pull that
129 # in if it still doesn't give us the function we want. This
130 # test is copied from libgomp.
131 AC_CHECK_LIB(rt, clock_gettime,
132 [link_libasan="-lrt $link_libasan"
133 link_libtsan="-lrt $link_libtsan"
134 # Other sanitizers do not override clock_* API
138 *-*-darwin*) MAC_INTERPOSE=true ; enable_static=no ;;
139 *) MAC_INTERPOSE=false ;;
141 AM_CONDITIONAL(USING_MAC_INTERPOSE, $MAC_INTERPOSE)
143 backtrace_supported=yes
145 AC_MSG_CHECKING([for necessary platform features])
148 # Some old Linux distributions miss required syscalls.
149 sanitizer_supported=no
150 AC_TRY_COMPILE([#include <sys/syscall.h>],[
151 syscall (__NR_gettid);
152 syscall (__NR_futex);
153 syscall (__NR_exit_group);
154 ], [sanitizer_supported=yes])
157 sanitizer_supported=yes
160 AC_MSG_RESULT($sanitizer_supported)
161 AM_CONDITIONAL(SANITIZER_SUPPORTED, test "$sanitizer_supported" = yes)
163 # Test for __sync support.
164 AC_CACHE_CHECK([__sync extensions],
165 [libsanitizer_cv_sys_sync],
166 [if test -n "${with_target_subdir}"; then
167 libsanitizer_cv_sys_sync=yes
170 [AC_LANG_PROGRAM([int i;],
171 [__sync_bool_compare_and_swap (&i, i, i);
172 __sync_lock_test_and_set (&i, 1);
173 __sync_lock_release (&i);])],
174 [libsanitizer_cv_sys_sync=yes],
175 [libsanitizer_cv_sys_sync=no])
177 if test "$libsanitizer_cv_sys_sync" = "yes"; then
178 AC_DEFINE([HAVE_SYNC_FUNCTIONS], 1,
179 [Define to 1 if you have the __sync functions])
182 # Test for __atomic support.
183 AC_CACHE_CHECK([__atomic extensions],
184 [libsanitizer_cv_sys_atomic],
185 [if test -n "${with_target_subdir}"; then
186 libsanitizer_cv_sys_atomic=yes
189 [AC_LANG_PROGRAM([int i;],
190 [__atomic_load_n (&i, __ATOMIC_ACQUIRE);
191 __atomic_store_n (&i, 1, __ATOMIC_RELEASE);])],
192 [libsanitizer_cv_sys_atomic=yes],
193 [libsanitizer_cv_sys_atomic=no])
195 if test "$libsanitizer_cv_sys_atomic" = "yes"; then
196 AC_DEFINE([HAVE_ATOMIC_FUNCTIONS], 1,
197 [Define to 1 if you have the __atomic functions])
200 # The library needs to be able to read the executable itself. Compile
201 # a file to determine the executable format. The awk script
202 # filetype.awk prints out the file type.
203 AC_CACHE_CHECK([output filetype],
204 [libsanitizer_cv_sys_filetype],
207 [AC_LANG_PROGRAM([int i;], [int j;])],
208 [filetype=`${AWK} -f $srcdir/../libbacktrace/filetype.awk conftest.$ac_objext`],
209 [AC_MSG_FAILURE([compiler failed])])
210 libsanitizer_cv_sys_filetype=$filetype])
212 # Match the file type to decide what files to compile.
214 case "$libsanitizer_cv_sys_filetype" in
215 elf*) FORMAT_FILE="elf.lo" ;;
216 *) AC_MSG_WARN([could not determine output file type])
217 FORMAT_FILE="unknown.lo"
218 backtrace_supported=no
221 AC_SUBST(FORMAT_FILE)
225 case "$libsanitizer_cv_sys_filetype" in
229 AC_DEFINE_UNQUOTED([BACKTRACE_ELF_SIZE], [$elfsize], [ELF size: 32 or 64])
231 BACKTRACE_SUPPORTED=0
232 if test "$backtrace_supported" = "yes"; then
233 BACKTRACE_SUPPORTED=1
235 AC_SUBST(BACKTRACE_SUPPORTED)
237 GCC_HEADER_STDINT(gstdint.h)
239 AC_CHECK_HEADERS(sys/mman.h alloca.h)
240 if test "$ac_cv_header_sys_mman_h" = "no"; then
243 if test -n "${with_target_subdir}"; then
244 # When built as a GCC target library, we can't do a link test. We
245 # simply assume that if we have mman.h, we have mmap.
248 AC_CHECK_FUNC(mmap, [have_mmap=yes], [have_mmap=no])
251 if test "$have_mmap" = "no"; then
257 #include <sys/mman.h>
258 #if !defined(MAP_ANONYMOUS) && !defined(MAP_ANON)
259 #error no MAP_ANONYMOUS
261 ], [ALLOC_FILE=mmap.lo], [ALLOC_FILE=alloc.lo])
266 BACKTRACE_USES_MALLOC=0
267 if test "$ALLOC_FILE" = "alloc.lo"; then
268 BACKTRACE_USES_MALLOC=1
270 AC_SUBST(BACKTRACE_USES_MALLOC)
272 # Don't care about thread support
273 BACKTRACE_SUPPORTS_THREADS=0
274 AC_SUBST(BACKTRACE_SUPPORTS_THREADS)
276 # Check for dl_iterate_phdr.
277 AC_CHECK_HEADERS(link.h)
278 if test "$ac_cv_header_link_h" = "no"; then
279 have_dl_iterate_phdr=no
281 # When built as a GCC target library, we can't do a link test.
282 AC_EGREP_HEADER([dl_iterate_phdr], [link.h], [have_dl_iterate_phdr=yes],
283 [have_dl_iterate_phdr=no])
286 # Avoid dl_iterate_phdr on Solaris 10, where it is in the
287 # header file but is only in -ldl.
288 have_dl_iterate_phdr=no ;;
291 if test "$have_dl_iterate_phdr" = "yes"; then
292 AC_DEFINE(HAVE_DL_ITERATE_PHDR, 1, [Define if dl_iterate_phdr is available.])
295 # Check for the fcntl function.
296 if test -n "${with_target_subdir}"; then
298 *-*-mingw*) have_fcntl=no ;;
302 AC_CHECK_FUNC(fcntl, [have_fcntl=yes], [have_fcntl=no])
304 if test "$have_fcntl" = "yes"; then
305 AC_DEFINE([HAVE_FCNTL], 1,
306 [Define to 1 if you have the fcntl function])
309 AC_CHECK_DECLS(strnlen)
311 # Check for getexecname function.
312 if test -n "${with_target_subdir}"; then
314 *-*-solaris2*) have_getexecname=yes ;;
315 *) have_getexecname=no ;;
318 AC_CHECK_FUNC(getexecname, [have_getexecname=yes], [have_getexecname=no])
320 if test "$have_getexecname" = "yes"; then
321 AC_DEFINE(HAVE_GETEXECNAME, 1, [Define if getexecname is available.])
324 # Check for rpc/xdr.h
325 AC_CHECK_HEADERS(rpc/xdr.h)
326 if test x"$ac_cv_header_rpc_xdr_h" = xyes; then
327 rpc_defs="$rpc_defs -DHAVE_RPC_XDR_H=1"
329 rpc_defs="$rpc_defs -DHAVE_RPC_XDR_H=0"
332 # Check for tirpc/rpc/xdr.h
333 AC_CHECK_HEADERS(tirpc/rpc/xdr.h)
334 if test x"$ac_cv_header_tirpc_rpc_xdr_h" = xyes; then
335 rpc_defs="$rpc_defs -DHAVE_TIRPC_RPC_XDR_H=1"
337 rpc_defs="$rpc_defs -DHAVE_TIRPC_RPC_XDR_H=0"
340 AC_SUBST([RPC_DEFS], [$rpc_defs])
342 dnl If this file is processed by autoconf-2.67 or later then the CPPFLAGS
343 dnl "-o conftest.iii" can disappear, conftest.iii be replaced with
344 dnl conftest.i in the sed command line, and the rm deleted.
345 dnl Not all cpp's accept -o, and gcc -E does not accept a second file
346 dnl argument as the output file.
347 AC_CACHE_CHECK([obstack params],
348 [libsanitizer_cv_sys_obstack],
349 [save_cppflags=$CPPFLAGS
350 CPPFLAGS="-I${srcdir}/../include -o conftest.iii $CPPFLAGS"
351 AC_PREPROC_IFELSE([AC_LANG_SOURCE([
353 #ifdef _OBSTACK_SIZE_T
359 [libsanitizer_cv_sys_obstack=`sed -e '/^#/d;/^[ ]*$/d' conftest.iii | sed -e '$!d;s/size_t/SIZE_T/'`],
360 [libsanitizer_cv_sys_obstack=int])
361 CPPFLAGS=$save_cppflags
364 AC_SUBST([OBSTACK_DEFS], [-D_OBSTACK_SIZE_T=\"$libsanitizer_cv_sys_obstack\"])
366 AM_CONDITIONAL(LIBBACKTRACE_SUPPORTED,
367 [test "x${BACKTRACE_SUPPORTED}x${BACKTRACE_USES_MALLOC}" = "x1x0"])
369 AH_BOTTOM([#include "libbacktrace/backtrace-rename.h"])
370 AC_CONFIG_FILES([Makefile libsanitizer.spec libbacktrace/backtrace-supported.h])
371 AC_CONFIG_HEADER(config.h)
373 AC_CONFIG_FILES(AC_FOREACH([DIR], [interception sanitizer_common libbacktrace lsan asan ubsan], [DIR/Makefile ]),
374 [cat > vpsed$$ << \_EOF
375 s!`test -f '$<' || echo '$(srcdir)/'`!!
377 sed -f vpsed$$ $ac_file > tmp$$
380 echo 'MULTISUBDIR =' >> $ac_file
382 . ${multi_basedir}/config-ml.in
383 AS_UNSET([ml_norecursion])
386 if test "x$TSAN_SUPPORTED" = "xyes"; then
387 AC_CONFIG_FILES(AC_FOREACH([DIR], [tsan], [DIR/Makefile ]),
388 [cat > vpsed$$ << \_EOF
389 s!`test -f '$<' || echo '$(srcdir)/'`!!
391 sed -f vpsed$$ $ac_file > tmp$$
394 echo 'MULTISUBDIR =' >> $ac_file
396 . ${multi_basedir}/config-ml.in
397 AS_UNSET([ml_norecursion])
401 AC_SUBST([TSAN_TARGET_DEPENDENT_OBJECTS])