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