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