configure.ac 12 KB

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