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 ],
13 yes) version_specific_libs=yes ;;
14 no) version_specific_libs=no ;;
15 *) AC_MSG_ERROR([Unknown argument to enable/disable version-specific libs]);;
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
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)
32 # Calculate toolexeclibdir
33 # Also toolexecdir, though it's only used in toolexeclibdir
34 case ${version_specific_libs} in
36 # Need the gcc compiler version to know where to install libraries
37 # and header files if --enable-version-specific-runtime-libs option
39 toolexecdir='$(libdir)/gcc/$(target_alias)'
40 toolexeclibdir='$(toolexecdir)/$(gcc_version)$(MULTISUBDIR)'
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'
49 toolexecdir='$(libdir)/gcc-lib/$(target_alias)'
50 toolexeclibdir='$(libdir)'
52 multi_os_directory=`$CC -print-multi-os-directory`
53 case $multi_os_directory in
54 .) ;; # Avoid trailing /.
55 *) toolexeclibdir=$toolexeclibdir/$multi_os_directory ;;
60 AC_SUBST(toolexeclibdir)
62 # Checks for programs.
73 "") AC_MSG_ERROR([can't build without awk]) ;;
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"
87 # Get target configury.
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
137 *-*-darwin*) MAC_INTERPOSE=true ; enable_static=no ;;
138 *) MAC_INTERPOSE=false ;;
140 AM_CONDITIONAL(USING_MAC_INTERPOSE, $MAC_INTERPOSE)
142 backtrace_supported=yes
144 AC_MSG_CHECKING([for necessary platform features])
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])
156 sanitizer_supported=yes
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
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])
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
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])
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],
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.
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
220 AC_SUBST(FORMAT_FILE)
224 case "$libsanitizer_cv_sys_filetype" in
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
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.
247 AC_CHECK_FUNC(mmap, [have_mmap=yes], [have_mmap=no])
250 if test "$have_mmap" = "no"; then
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
260 ])], [ALLOC_FILE=mmap.lo], [ALLOC_FILE=alloc.lo])
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
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])
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 ;;
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
297 *-*-mingw*) have_fcntl=no ;;
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
313 *-*-solaris2*) have_getexecname=yes ;;
314 *) have_getexecname=no ;;
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"
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"
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)/'`!!
352 sed -f vpsed$$ $ac_file > tmp$$
355 echo 'MULTISUBDIR =' >> $ac_file
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)/'`!!
366 sed -f vpsed$$ $ac_file > tmp$$
369 echo 'MULTISUBDIR =' >> $ac_file
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.
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)