1#                                               -*- Autoconf -*-
2# Process this file with autoconf to produce a configure script.
3
4AC_PREREQ([2.64])
5AC_INIT(package-unused, version-unused, libsanitizer)
6AC_CONFIG_SRCDIR([include/sanitizer/common_interface_defs.h])
7
8AM_ENABLE_MULTILIB(, ..)
9
10AC_MSG_CHECKING([for --enable-version-specific-runtime-libs])
11AC_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])
19AC_MSG_RESULT($version_specific_libs)
20
21AC_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
25AC_CANONICAL_SYSTEM
26target_alias=${target_alias-$host_alias}
27AC_SUBST(target_alias)
28GCC_LIBSTDCXX_RAW_CXX_FLAGS
29
30AM_INIT_AUTOMAKE(foreign no-dist)
31AM_MAINTAINER_MODE
32
33# Calculate toolexeclibdir
34# Also toolexecdir, though it's only used in toolexeclibdir
35case ${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    ;;
59esac
60AC_SUBST(toolexecdir)
61AC_SUBST(toolexeclibdir)
62
63# Checks for programs.
64AC_PROG_CC
65AC_PROG_CXX
66AM_PROG_AS
67AC_PROG_RANLIB
68
69AC_LIBTOOL_DLOPEN
70AM_PROG_LIBTOOL
71
72AC_PROG_AWK
73case "$AWK" in
74"") AC_MSG_ERROR([can't build without awk]) ;;
75esac
76
77AC_SUBST(enable_shared)
78AC_SUBST(enable_static)
79
80AC_CHECK_SIZEOF([void *])
81
82if test "${multilib}" = "yes"; then
83  multilib_arg="--enable-multilib"
84else
85  multilib_arg=
86fi
87
88# Get target configury.
89unset TSAN_SUPPORTED
90unset LSAN_SUPPORTED
91. ${srcdir}/configure.tgt
92AM_CONDITIONAL(TSAN_SUPPORTED, [test "x$TSAN_SUPPORTED" = "xyes"])
93AM_CONDITIONAL(LSAN_SUPPORTED, [test "x$LSAN_SUPPORTED" = "xyes"])
94
95# Check for functions needed.
96AC_CHECK_FUNCS(clock_getres clock_gettime clock_settime)
97
98# Common libraries that we need to link against for all sanitizer libs.
99link_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.
104AC_CHECK_LIB(rt, shm_open,
105  [link_sanitizer_common="-lrt $link_sanitizer_common"])
106
107# Do a configure time check for -ldl
108AC_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.
112link_libasan=$link_sanitizer_common
113AC_SUBST(link_libasan)
114
115# Set up the set of additional libraries that we need to link against for libtsan.
116link_libtsan=$link_sanitizer_common
117AC_SUBST(link_libtsan)
118
119# Set up the set of additional libraries that we need to link against for libubsan.
120link_libubsan=$link_sanitizer_common
121AC_SUBST(link_libubsan)
122
123# Set up the set of additional libraries that we need to link against for liblsan.
124link_liblsan=$link_sanitizer_common
125AC_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.
131AC_CHECK_LIB(rt, clock_gettime,
132  [link_libasan="-lrt $link_libasan"
133link_libtsan="-lrt $link_libtsan"
134# Other sanitizers do not override clock_* API
135])
136
137case "$host" in
138  *-*-darwin*) MAC_INTERPOSE=true ; enable_static=no ;;
139  *) MAC_INTERPOSE=false ;;
140esac
141AM_CONDITIONAL(USING_MAC_INTERPOSE, $MAC_INTERPOSE)
142
143backtrace_supported=yes
144
145AC_MSG_CHECKING([for necessary platform features])
146case "$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    ;;
159esac
160AC_MSG_RESULT($sanitizer_supported)
161AM_CONDITIONAL(SANITIZER_SUPPORTED, test "$sanitizer_supported" = yes)
162
163# Test for __sync support.
164AC_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])
177if test "$libsanitizer_cv_sys_sync" = "yes"; then
178  AC_DEFINE([HAVE_SYNC_FUNCTIONS], 1,
179	    [Define to 1 if you have the __sync functions])
180fi
181
182# Test for __atomic support.
183AC_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])
195if test "$libsanitizer_cv_sys_atomic" = "yes"; then
196  AC_DEFINE([HAVE_ATOMIC_FUNCTIONS], 1,
197	    [Define to 1 if you have the __atomic functions])
198fi
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.
203AC_CACHE_CHECK([output filetype],
204[libsanitizer_cv_sys_filetype],
205[filetype=
206AC_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])])
210libsanitizer_cv_sys_filetype=$filetype])
211
212# Match the file type to decide what files to compile.
213FORMAT_FILE=
214case "$libsanitizer_cv_sys_filetype" in
215elf*) FORMAT_FILE="elf.lo" ;;
216*) AC_MSG_WARN([could not determine output file type])
217   FORMAT_FILE="unknown.lo"
218   backtrace_supported=no
219   ;;
220esac
221AC_SUBST(FORMAT_FILE)
222
223# ELF defines.
224elfsize=
225case "$libsanitizer_cv_sys_filetype" in
226elf32) elfsize=32 ;;
227elf64) elfsize=64 ;;
228esac
229AC_DEFINE_UNQUOTED([BACKTRACE_ELF_SIZE], [$elfsize], [ELF size: 32 or 64])
230
231BACKTRACE_SUPPORTED=0
232if test "$backtrace_supported" = "yes"; then
233  BACKTRACE_SUPPORTED=1
234fi
235AC_SUBST(BACKTRACE_SUPPORTED)
236
237GCC_HEADER_STDINT(gstdint.h)
238
239AC_CHECK_HEADERS(sys/mman.h alloca.h)
240if test "$ac_cv_header_sys_mman_h" = "no"; then
241  have_mmap=no
242else
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
250fi
251if test "$have_mmap" = "no"; then
252  VIEW_FILE=read.lo
253  ALLOC_FILE=alloc.lo
254else
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])
262fi
263AC_SUBST(VIEW_FILE)
264AC_SUBST(ALLOC_FILE)
265
266BACKTRACE_USES_MALLOC=0
267if test "$ALLOC_FILE" = "alloc.lo"; then
268  BACKTRACE_USES_MALLOC=1
269fi
270AC_SUBST(BACKTRACE_USES_MALLOC)
271
272# Don't care about thread support
273BACKTRACE_SUPPORTS_THREADS=0
274AC_SUBST(BACKTRACE_SUPPORTS_THREADS)
275
276# Check for dl_iterate_phdr.
277AC_CHECK_HEADERS(link.h)
278if test "$ac_cv_header_link_h" = "no"; then
279  have_dl_iterate_phdr=no
280else
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
290fi
291if test "$have_dl_iterate_phdr" = "yes"; then
292  AC_DEFINE(HAVE_DL_ITERATE_PHDR, 1, [Define if dl_iterate_phdr is available.])
293fi
294
295# Check for the fcntl function.
296if test -n "${with_target_subdir}"; then
297   case "${host}" in
298   *-*-mingw*) have_fcntl=no ;;
299   *) have_fcntl=yes ;;
300   esac
301else
302  AC_CHECK_FUNC(fcntl, [have_fcntl=yes], [have_fcntl=no])
303fi
304if test "$have_fcntl" = "yes"; then
305  AC_DEFINE([HAVE_FCNTL], 1,
306	    [Define to 1 if you have the fcntl function])
307fi
308
309AC_CHECK_DECLS(strnlen)
310
311# Check for getexecname function.
312if test -n "${with_target_subdir}"; then
313   case "${host}" in
314   *-*-solaris2*) have_getexecname=yes ;;
315   *) have_getexecname=no ;;
316   esac
317else
318  AC_CHECK_FUNC(getexecname, [have_getexecname=yes], [have_getexecname=no])
319fi
320if test "$have_getexecname" = "yes"; then
321  AC_DEFINE(HAVE_GETEXECNAME, 1, [Define if getexecname is available.])
322fi
323
324# Check for rpc/xdr.h
325AC_CHECK_HEADERS(rpc/xdr.h)
326if test x"$ac_cv_header_rpc_xdr_h" = xyes; then
327  rpc_defs="$rpc_defs -DHAVE_RPC_XDR_H=1"
328else
329  rpc_defs="$rpc_defs -DHAVE_RPC_XDR_H=0"
330fi
331
332# Check for tirpc/rpc/xdr.h
333AC_CHECK_HEADERS(tirpc/rpc/xdr.h)
334if test x"$ac_cv_header_tirpc_rpc_xdr_h" = xyes; then
335  rpc_defs="$rpc_defs -DHAVE_TIRPC_RPC_XDR_H=1"
336else
337  rpc_defs="$rpc_defs -DHAVE_TIRPC_RPC_XDR_H=0"
338fi
339
340AC_SUBST([RPC_DEFS], [$rpc_defs])
341
342AM_CONDITIONAL(LIBBACKTRACE_SUPPORTED,
343	       [test "x${BACKTRACE_SUPPORTED}x${BACKTRACE_USES_MALLOC}" = "x1x0"])
344
345AH_BOTTOM([#include "libbacktrace/backtrace-rename.h"])
346AC_CONFIG_FILES([Makefile libsanitizer.spec libbacktrace/backtrace-supported.h])
347AC_CONFIG_HEADER(config.h)
348
349AC_CONFIG_FILES(AC_FOREACH([DIR], [interception sanitizer_common libbacktrace lsan asan ubsan], [DIR/Makefile ]),
350  [cat > vpsed$$ << \_EOF
351s!`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
362if test "x$TSAN_SUPPORTED" = "xyes"; then
363  AC_CONFIG_FILES(AC_FOREACH([DIR], [tsan], [DIR/Makefile ]),
364    [cat > vpsed$$ << \_EOF
365s!`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])
375fi
376
377AC_SUBST([TSAN_TARGET_DEPENDENT_OBJECTS])
378AC_SUBST([SANITIZER_COMMON_TARGET_DEPENDENT_OBJECTS])
379
380# Determine what GCC version number to use in filesystem paths.
381GCC_BASE_VER
382
383# Add CET specific flags if Intel CET is enabled.
384GCC_CET_FLAGS(CET_FLAGS)
385EXTRA_CFLAGS="$EXTRA_CFLAGS $CET_FLAGS"
386EXTRA_CXXFLAGS="$EXTRA_CXXFLAGS $CET_FLAGS"
387EXTRA_ASFLAGS=$CET_FLAGS
388AC_SUBST(EXTRA_ASFLAGS)
389AC_SUBST(EXTRA_CFLAGS)
390AC_SUBST(EXTRA_CXXFLAGS)
391
392AC_OUTPUT
393