]> git.ipfire.org Git - thirdparty/gcc.git/blob - libsanitizer/configure.ac
34ba09f42f21cfdf882b3aa22ded18d77bab0345
[thirdparty/gcc.git] / libsanitizer / configure.ac
1 # -*- Autoconf -*-
2 # Process this file with autoconf to produce a configure script.
3
4 AC_PREREQ([2.64])
5 AC_INIT(package-unused, version-unused, libsanitizer)
6 AC_CONFIG_SRCDIR([include/sanitizer/common_interface_defs.h])
7
8 AM_ENABLE_MULTILIB(, ..)
9
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 ],
13 [case "$enableval" in
14 yes) version_specific_libs=yes ;;
15 no) version_specific_libs=no ;;
16 *) AC_MSG_ERROR([Unknown argument to enable/disable version-specific libs]);;
17 esac],
18 [version_specific_libs=no])
19 AC_MSG_RESULT($version_specific_libs)
20
21 AC_USE_SYSTEM_EXTENSIONS
22
23 # Do not delete or change the following two lines. For why, see
24 # http://gcc.gnu.org/ml/libstdc++/2003-07/msg00451.html
25 AC_CANONICAL_SYSTEM
26 target_alias=${target_alias-$host_alias}
27 AC_SUBST(target_alias)
28 GCC_LIBSTDCXX_RAW_CXX_FLAGS
29
30 AM_INIT_AUTOMAKE(foreign no-dist)
31 AM_MAINTAINER_MODE
32
33 # Calculate toolexeclibdir
34 # Also toolexecdir, though it's only used in toolexeclibdir
35 case ${version_specific_libs} in
36 yes)
37 # Need the gcc compiler version to know where to install libraries
38 # and header files if --enable-version-specific-runtime-libs option
39 # is selected.
40 toolexecdir='$(libdir)/gcc/$(target_alias)'
41 toolexeclibdir='$(toolexecdir)/$(gcc_version)$(MULTISUBDIR)'
42 ;;
43 no)
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'
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
63 # Checks for programs.
64 AC_PROG_CC
65 AC_PROG_CXX
66 AM_PROG_AS
67 AC_PROG_RANLIB
68
69 AC_LIBTOOL_DLOPEN
70 AM_PROG_LIBTOOL
71
72 AC_PROG_AWK
73 case "$AWK" in
74 "") AC_MSG_ERROR([can't build without awk]) ;;
75 esac
76
77 AC_SUBST(enable_shared)
78 AC_SUBST(enable_static)
79
80 AC_CHECK_SIZEOF([void *])
81
82 if test "${multilib}" = "yes"; then
83 multilib_arg="--enable-multilib"
84 else
85 multilib_arg=
86 fi
87
88 # Get target configury.
89 unset TSAN_SUPPORTED
90 unset LSAN_SUPPORTED
91 . ${srcdir}/configure.tgt
92 AM_CONDITIONAL(TSAN_SUPPORTED, [test "x$TSAN_SUPPORTED" = "xyes"])
93 AM_CONDITIONAL(LSAN_SUPPORTED, [test "x$LSAN_SUPPORTED" = "xyes"])
94
95 # Check for functions needed.
96 AC_CHECK_FUNCS(clock_getres clock_gettime clock_settime lstat readlink)
97
98 # Common libraries that we need to link against for all sanitizer libs.
99 link_sanitizer_common='-lpthread -lm'
100
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"])
106
107 # Do a configure time check for -ldl
108 AC_CHECK_LIB(dl, dlsym,
109 [link_sanitizer_common="-ldl $link_sanitizer_common"])
110
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)
114
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)
118
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)
122
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)
126
127
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
135 ])
136
137 case "$host" in
138 *-*-darwin*) MAC_INTERPOSE=true ; enable_static=no ;;
139 *) MAC_INTERPOSE=false ;;
140 esac
141 AM_CONDITIONAL(USING_MAC_INTERPOSE, $MAC_INTERPOSE)
142
143 backtrace_supported=yes
144
145 AC_MSG_CHECKING([for necessary platform features])
146 case "$target" in
147 *-*-linux*)
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])
155 ;;
156 *)
157 sanitizer_supported=yes
158 ;;
159 esac
160 AC_MSG_RESULT($sanitizer_supported)
161 AM_CONDITIONAL(SANITIZER_SUPPORTED, test "$sanitizer_supported" = yes)
162
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
168 else
169 AC_LINK_IFELSE(
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])
176 fi])
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])
180 fi
181
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
187 else
188 AC_LINK_IFELSE(
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])
194 fi])
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])
198 fi
199
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],
205 [filetype=
206 AC_COMPILE_IFELSE(
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])
211
212 # Match the file type to decide what files to compile.
213 FORMAT_FILE=
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
219 ;;
220 esac
221 AC_SUBST(FORMAT_FILE)
222
223 # ELF defines.
224 elfsize=
225 case "$libsanitizer_cv_sys_filetype" in
226 elf32) elfsize=32 ;;
227 elf64) elfsize=64 ;;
228 esac
229 AC_DEFINE_UNQUOTED([BACKTRACE_ELF_SIZE], [$elfsize], [ELF size: 32 or 64])
230
231 BACKTRACE_SUPPORTED=0
232 if test "$backtrace_supported" = "yes"; then
233 BACKTRACE_SUPPORTED=1
234 fi
235 AC_SUBST(BACKTRACE_SUPPORTED)
236
237 GCC_HEADER_STDINT(gstdint.h)
238
239 AC_CHECK_HEADERS(sys/mman.h alloca.h)
240 if test "$ac_cv_header_sys_mman_h" = "no"; then
241 have_mmap=no
242 else
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.
246 have_mmap=yes
247 else
248 AC_CHECK_FUNC(mmap, [have_mmap=yes], [have_mmap=no])
249 fi
250 fi
251 if test "$have_mmap" = "no"; then
252 VIEW_FILE=read.lo
253 ALLOC_FILE=alloc.lo
254 else
255 VIEW_FILE=mmapio.lo
256 AC_PREPROC_IFELSE([
257 #include <sys/mman.h>
258 #if !defined(MAP_ANONYMOUS) && !defined(MAP_ANON)
259 #error no MAP_ANONYMOUS
260 #endif
261 ], [ALLOC_FILE=mmap.lo], [ALLOC_FILE=alloc.lo])
262 fi
263 AC_SUBST(VIEW_FILE)
264 AC_SUBST(ALLOC_FILE)
265
266 BACKTRACE_USES_MALLOC=0
267 if test "$ALLOC_FILE" = "alloc.lo"; then
268 BACKTRACE_USES_MALLOC=1
269 fi
270 AC_SUBST(BACKTRACE_USES_MALLOC)
271
272 # Don't care about thread support
273 BACKTRACE_SUPPORTS_THREADS=0
274 AC_SUBST(BACKTRACE_SUPPORTS_THREADS)
275
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
280 else
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])
284 case "${host}" in
285 *-*-solaris2.10*)
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 ;;
289 esac
290 fi
291 if test "$have_dl_iterate_phdr" = "yes"; then
292 AC_DEFINE(HAVE_DL_ITERATE_PHDR, 1, [Define if dl_iterate_phdr is available.])
293 fi
294
295 # Check for the fcntl function.
296 if test -n "${with_target_subdir}"; then
297 case "${host}" in
298 *-*-mingw*) have_fcntl=no ;;
299 *) have_fcntl=yes ;;
300 esac
301 else
302 AC_CHECK_FUNC(fcntl, [have_fcntl=yes], [have_fcntl=no])
303 fi
304 if test "$have_fcntl" = "yes"; then
305 AC_DEFINE([HAVE_FCNTL], 1,
306 [Define to 1 if you have the fcntl function])
307 fi
308
309 AC_CHECK_DECLS(strnlen)
310
311 # Check for getexecname function.
312 if test -n "${with_target_subdir}"; then
313 case "${host}" in
314 *-*-solaris2*) have_getexecname=yes ;;
315 *) have_getexecname=no ;;
316 esac
317 else
318 AC_CHECK_FUNC(getexecname, [have_getexecname=yes], [have_getexecname=no])
319 fi
320 if test "$have_getexecname" = "yes"; then
321 AC_DEFINE(HAVE_GETEXECNAME, 1, [Define if getexecname is available.])
322 fi
323
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"
328 else
329 rpc_defs="$rpc_defs -DHAVE_RPC_XDR_H=0"
330 fi
331
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"
336 else
337 rpc_defs="$rpc_defs -DHAVE_TIRPC_RPC_XDR_H=0"
338 fi
339
340 AC_SUBST([RPC_DEFS], [$rpc_defs])
341
342 AM_CONDITIONAL(LIBBACKTRACE_SUPPORTED,
343 [test "x${BACKTRACE_SUPPORTED}x${BACKTRACE_USES_MALLOC}" = "x1x0"])
344
345 AH_BOTTOM([#include "libbacktrace/backtrace-rename.h"])
346 AC_CONFIG_FILES([Makefile libsanitizer.spec libbacktrace/backtrace-supported.h])
347 AC_CONFIG_HEADER(config.h)
348
349 AC_CONFIG_FILES(AC_FOREACH([DIR], [interception sanitizer_common libbacktrace lsan asan ubsan], [DIR/Makefile ]),
350 [cat > vpsed$$ << \_EOF
351 s!`test -f '$<' || echo '$(srcdir)/'`!!
352 _EOF
353 sed -f vpsed$$ $ac_file > tmp$$
354 mv tmp$$ $ac_file
355 rm vpsed$$
356 echo 'MULTISUBDIR =' >> $ac_file
357 ml_norecursion=yes
358 . ${multi_basedir}/config-ml.in
359 AS_UNSET([ml_norecursion])
360 ])
361
362 if test "x$TSAN_SUPPORTED" = "xyes"; then
363 AC_CONFIG_FILES(AC_FOREACH([DIR], [tsan], [DIR/Makefile ]),
364 [cat > vpsed$$ << \_EOF
365 s!`test -f '$<' || echo '$(srcdir)/'`!!
366 _EOF
367 sed -f vpsed$$ $ac_file > tmp$$
368 mv tmp$$ $ac_file
369 rm vpsed$$
370 echo 'MULTISUBDIR =' >> $ac_file
371 ml_norecursion=yes
372 . ${multi_basedir}/config-ml.in
373 AS_UNSET([ml_norecursion])
374 ])
375 fi
376
377 AC_SUBST([TSAN_TARGET_DEPENDENT_OBJECTS])
378 AC_SUBST([SANITIZER_COMMON_TARGET_DEPENDENT_OBJECTS])
379
380 # Determine what GCC version number to use in filesystem paths.
381 GCC_BASE_VER
382
383 # Add CET specific flags if Intel CET is enabled.
384 GCC_CET_FLAGS(CET_FLAGS)
385 EXTRA_CFLAGS="$EXTRA_CFLAGS $CET_FLAGS"
386 EXTRA_CXXFLAGS="$EXTRA_CXXFLAGS $CET_FLAGS"
387 EXTRA_ASFLAGS=$CET_FLAGS
388 AC_SUBST(EXTRA_ASFLAGS)
389 AC_SUBST(EXTRA_CFLAGS)
390 AC_SUBST(EXTRA_CXXFLAGS)
391
392 AC_OUTPUT