configure.ac 10 KB

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