• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1
2##------------------------------------------------------------##
3#
4# The multiple-architecture stuff in this file is pretty
5# cryptic.  Read docs/internals/multiple-architectures.txt
6# for at least a partial explanation of what is going on.
7#
8##------------------------------------------------------------##
9
10# Process this file with autoconf to produce a configure script.
11AC_INIT([Valgrind],[3.13.0],[valgrind-users@lists.sourceforge.net])
12AC_CONFIG_SRCDIR(coregrind/m_main.c)
13AC_CONFIG_HEADERS([config.h])
14AM_INIT_AUTOMAKE([foreign subdir-objects])
15
16AM_MAINTAINER_MODE
17
18#----------------------------------------------------------------------------
19# Do NOT modify these flags here. Except in feature tests in which case
20# the original values must be properly restored.
21#----------------------------------------------------------------------------
22CFLAGS="$CFLAGS"
23CXXFLAGS="$CXXFLAGS"
24
25#----------------------------------------------------------------------------
26# Checks for various programs.
27#----------------------------------------------------------------------------
28
29AC_PROG_LN_S
30AC_PROG_CC
31AM_PROG_CC_C_O
32AC_PROG_CPP
33AC_PROG_CXX
34# AC_PROG_OBJC apparently causes problems on older Linux distros (eg. with
35# autoconf 2.59).  If we ever have any Objective-C code in the Valgrind code
36# base (eg. most likely as Darwin-specific tests) we'll need one of the
37# following:
38# - put AC_PROG_OBJC in a Darwin-specific part of this file
39# - Use AC_PROG_OBJC here and up the minimum autoconf version
40# - Use the following, which is apparently equivalent:
41#     m4_ifdef([AC_PROG_OBJC],
42#        [AC_PROG_OBJC],
43#        [AC_CHECK_TOOL([OBJC], [gcc])
44#         AC_SUBST([OBJC])
45#         AC_SUBST([OBJCFLAGS])
46#        ])
47AC_PROG_RANLIB
48# provide a very basic definition for AC_PROG_SED if it's not provided by
49# autoconf (as e.g. in autoconf 2.59).
50m4_ifndef([AC_PROG_SED],
51          [AC_DEFUN([AC_PROG_SED],
52                    [AC_ARG_VAR([SED])
53                     AC_CHECK_PROGS([SED],[gsed sed])])])
54AC_PROG_SED
55
56# If no AR variable was specified, look up the name of the archiver. Otherwise
57# do not touch the AR variable.
58if test "x$AR" = "x"; then
59  AC_PATH_PROGS([AR], [`echo $LD | $SED 's/ld$/ar/'` "ar"], [ar])
60fi
61AC_ARG_VAR([AR],[Archiver command])
62
63# Check for the compiler support
64if test "${GCC}" != "yes" ; then
65   AC_MSG_ERROR([Valgrind relies on GCC to be compiled])
66fi
67
68# figure out where perl lives
69AC_PATH_PROG(PERL, perl)
70
71# figure out where gdb lives
72AC_PATH_PROG(GDB, gdb, "/no/gdb/was/found/at/configure/time")
73AC_DEFINE_UNQUOTED(GDB_PATH, "$GDB", [path to GDB])
74
75# some older automake's don't have it so try something on our own
76ifdef([AM_PROG_AS],[AM_PROG_AS],
77[
78AS="${CC}"
79AC_SUBST(AS)
80
81ASFLAGS=""
82AC_SUBST(ASFLAGS)
83])
84
85
86# Check if 'diff' supports -u (universal diffs) and use it if possible.
87
88AC_MSG_CHECKING([for diff -u])
89AC_SUBST(DIFF)
90
91# Comparing two identical files results in 0.
92tmpfile="tmp-xxx-yyy-zzz"
93touch $tmpfile;
94if diff -u $tmpfile $tmpfile ; then
95    AC_MSG_RESULT([yes])
96    DIFF="diff -u"
97else
98    AC_MSG_RESULT([no])
99    DIFF="diff"
100fi
101rm $tmpfile
102
103
104# We don't want gcc < 3.0
105AC_MSG_CHECKING([for a supported version of gcc])
106
107# Obtain the compiler version.
108#
109# A few examples of how the ${CC} --version output looks like:
110#
111# ######## gcc variants ########
112# Arch Linux: i686-pc-linux-gnu-gcc (GCC) 4.6.2
113# Debian Linux: gcc (Debian 4.3.2-1.1) 4.3.2
114# openSUSE: gcc (SUSE Linux) 4.5.1 20101208 [gcc-4_5-branch revision 167585]
115# Exherbo Linux: x86_64-pc-linux-gnu-gcc (Exherbo gcc-4.6.2) 4.6.2
116# MontaVista Linux for ARM: arm-none-linux-gnueabi-gcc (Sourcery G++ Lite 2009q1-203) 4.3.3
117# OS/X 10.6: i686-apple-darwin10-gcc-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5666) (dot 3)
118# OS/X 10.7: i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)
119#
120# ######## clang variants ########
121# Clang: clang version 2.9 (tags/RELEASE_29/final)
122# Apple clang: Apple clang version 3.1 (tags/Apple/clang-318.0.58) (based on LLVM 3.1svn)
123# FreeBSD clang: FreeBSD clang version 3.1 (branches/release_31 156863) 20120523
124#
125# ######## Apple LLVM variants ########
126# Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
127# Apple LLVM version 6.0 (clang-600.0.51) (based on LLVM 3.5svn)
128#
129[
130if test "x`${CC} --version | $SED -n -e 's/.*\Apple \(LLVM\) version.*clang.*/\1/p'`" = "xLLVM" ;
131then
132    is_clang="applellvm"
133    gcc_version=`${CC} --version | $SED -n -e 's/.*LLVM version \([0-9.]*\).*$/\1/p'`
134elif test "x`${CC} --version | $SED -n -e 's/.*\(clang\) version.*/\1/p'`" = "xclang" ;
135then
136    is_clang="clang"
137    # Don't use -dumpversion with clang: it will always produce "4.2.1".
138    gcc_version=`${CC} --version | $SED -n -e 's/.*clang version \([0-9.]*\).*$/\1/p'`
139elif test "x`${CC} --version | $SED -n -e 's/icc.*\(ICC\).*/\1/p'`" = "xICC" ;
140then
141    is_clang="icc"
142    gcc_version=`${CC} -dumpversion 2>/dev/null`
143else
144    is_clang="notclang"
145    gcc_version=`${CC} -dumpversion 2>/dev/null`
146    if test "x$gcc_version" = x; then
147	gcc_version=`${CC} --version | $SED -n -e 's/[^ ]*gcc[^ ]* ([^)]*) \([0-9.]*\).*$/\1/p'`
148    fi
149fi
150]
151AM_CONDITIONAL(COMPILER_IS_CLANG, test $is_clang = clang -o $is_clang = applellvm)
152AM_CONDITIONAL(COMPILER_IS_ICC, test $is_clang = icc)
153
154# Note: m4 arguments are quoted with [ and ] so square brackets in shell
155# statements have to be quoted.
156case "${is_clang}-${gcc_version}" in
157     applellvm-5.1|applellvm-6.*|applellvm-7.*|applellvm-8.*)
158	AC_MSG_RESULT([ok (Apple LLVM version ${gcc_version})])
159	;;
160     icc-1[[3-9]].*)
161	AC_MSG_RESULT([ok (ICC version ${gcc_version})])
162	;;
163     notclang-[[3-9]]|notclang-[[3-9]].*|notclang-[[1-9][0-9]]*)
164	AC_MSG_RESULT([ok (${gcc_version})])
165	;;
166     clang-2.9|clang-[[3-9]].*|clang-[[1-9][0-9]]*)
167	AC_MSG_RESULT([ok (clang-${gcc_version})])
168	;;
169     *)
170	AC_MSG_RESULT([no (${is_clang}-${gcc_version})])
171	AC_MSG_ERROR([please use gcc >= 3.0 or clang >= 2.9 or icc >= 13.0])
172	;;
173esac
174
175#----------------------------------------------------------------------------
176# Arch/OS/platform tests.
177#----------------------------------------------------------------------------
178# We create a number of arch/OS/platform-related variables.  We prefix them
179# all with "VGCONF_" which indicates that they are defined at
180# configure-time, and distinguishes them from the VGA_*/VGO_*/VGP_*
181# variables used when compiling C files.
182
183AC_CANONICAL_HOST
184
185AC_MSG_CHECKING([for a supported CPU])
186
187# ARCH_MAX reflects the most that this CPU can do: for example if it
188# is a 64-bit capable PowerPC, then it must be set to ppc64 and not ppc32.
189# Ditto for amd64.  It is used for more configuration below, but is not used
190# outside this file.
191#
192# Power PC returns powerpc for Big Endian.  This was not changed when Little
193# Endian support was added to the 64-bit architecture.  The 64-bit Little
194# Endian systems explicitly state le in the host_cpu.  For clarity in the
195# Valgrind code, the ARCH_MAX name will state LE or BE for the endianness of
196# the 64-bit system.  Big Endian is the only mode supported on 32-bit Power PC.
197# The abreviation PPC or ppc refers to 32-bit and 64-bit systems with either
198# Endianness.  The name PPC64 or ppc64 to 64-bit systems of either Endianness.
199# The names ppc64be or PPC64BE refer to only 64-bit systems that are Big
200# Endian.  Similarly, ppc64le or PPC64LE refer to only 64-bit systems that are
201# Little Endian.
202
203case "${host_cpu}" in
204     i?86)
205	AC_MSG_RESULT([ok (${host_cpu})])
206        ARCH_MAX="x86"
207        ;;
208
209     x86_64)
210        AC_MSG_RESULT([ok (${host_cpu})])
211        ARCH_MAX="amd64"
212        ;;
213
214     powerpc64)
215     # this only referrs to 64-bit Big Endian
216        AC_MSG_RESULT([ok (${host_cpu})])
217        ARCH_MAX="ppc64be"
218        ;;
219
220     powerpc64le)
221     # this only referrs to 64-bit Little Endian
222        AC_MSG_RESULT([ok (${host_cpu})])
223        ARCH_MAX="ppc64le"
224        ;;
225
226     powerpc)
227        # On Linux this means only a 32-bit capable CPU.
228        AC_MSG_RESULT([ok (${host_cpu})])
229        ARCH_MAX="ppc32"
230        ;;
231
232     s390x)
233        AC_MSG_RESULT([ok (${host_cpu})])
234        ARCH_MAX="s390x"
235        ;;
236
237     armv7*)
238	AC_MSG_RESULT([ok (${host_cpu})])
239	ARCH_MAX="arm"
240	;;
241
242     aarch64*)
243       AC_MSG_RESULT([ok (${host_cpu})])
244       ARCH_MAX="arm64"
245       ;;
246
247     mips)
248        AC_MSG_RESULT([ok (${host_cpu})])
249        ARCH_MAX="mips32"
250        ;;
251
252     mipsel)
253        AC_MSG_RESULT([ok (${host_cpu})])
254        ARCH_MAX="mips32"
255        ;;
256
257     mipsisa32r2)
258        AC_MSG_RESULT([ok (${host_cpu})])
259        ARCH_MAX="mips32"
260        ;;
261
262     mips64*)
263        AC_MSG_RESULT([ok (${host_cpu})])
264        ARCH_MAX="mips64"
265        ;;
266
267     mipsisa64*)
268        AC_MSG_RESULT([ok (${host_cpu})])
269        ARCH_MAX="mips64"
270        ;;
271
272     *)
273	AC_MSG_RESULT([no (${host_cpu})])
274	AC_MSG_ERROR([Unsupported host architecture. Sorry])
275	;;
276esac
277
278#----------------------------------------------------------------------------
279
280# Sometimes it's convenient to subvert the bi-arch build system and
281# just have a single build even though the underlying platform is
282# capable of both.  Hence handle --enable-only64bit and
283# --enable-only32bit.  Complain if both are issued :-)
284# [Actually, if either of these options are used, I think both get built,
285# but only one gets installed.  So if you use an in-place build, both can be
286# used. --njn]
287
288# Check if a 64-bit only build has been requested
289AC_CACHE_CHECK([for a 64-bit only build], vg_cv_only64bit,
290   [AC_ARG_ENABLE(only64bit,
291      [  --enable-only64bit      do a 64-bit only build],
292      [vg_cv_only64bit=$enableval],
293      [vg_cv_only64bit=no])])
294
295# Check if a 32-bit only build has been requested
296AC_CACHE_CHECK([for a 32-bit only build], vg_cv_only32bit,
297   [AC_ARG_ENABLE(only32bit,
298      [  --enable-only32bit      do a 32-bit only build],
299      [vg_cv_only32bit=$enableval],
300      [vg_cv_only32bit=no])])
301
302# Stay sane
303if test x$vg_cv_only64bit = xyes -a x$vg_cv_only32bit = xyes; then
304   AC_MSG_ERROR(
305      [Nonsensical: both --enable-only64bit and --enable-only32bit.])
306fi
307
308#----------------------------------------------------------------------------
309
310# VGCONF_OS is the primary build OS, eg. "linux".  It is passed in to
311# compilation of many C files via -VGO_$(VGCONF_OS) and
312# -VGP_$(VGCONF_ARCH_PRI)_$(VGCONF_OS).
313AC_MSG_CHECKING([for a supported OS])
314AC_SUBST(VGCONF_OS)
315
316DEFAULT_SUPP=""
317
318case "${host_os}" in
319     *linux*)
320	AC_MSG_RESULT([ok (${host_os})])
321        VGCONF_OS="linux"
322
323        # Ok, this is linux. Check the kernel version
324        AC_MSG_CHECKING([for the kernel version])
325
326        kernel=`uname -r`
327
328        case "${kernel}" in
329             0.*|1.*|2.0.*|2.1.*|2.2.*|2.3.*|2.4.*|2.5.*)
330        	    AC_MSG_RESULT([unsupported (${kernel})])
331        	    AC_MSG_ERROR([Valgrind needs a Linux kernel >= 2.6])
332        	    ;;
333
334             *)
335        	    AC_MSG_RESULT([2.6 or later (${kernel})])
336                    ;;
337        esac
338
339        ;;
340
341     *darwin*)
342        AC_MSG_RESULT([ok (${host_os})])
343        VGCONF_OS="darwin"
344        AC_DEFINE([DARWIN_10_5], 100500, [DARWIN_VERS value for Mac OS X 10.5])
345        AC_DEFINE([DARWIN_10_6], 100600, [DARWIN_VERS value for Mac OS X 10.6])
346        AC_DEFINE([DARWIN_10_7], 100700, [DARWIN_VERS value for Mac OS X 10.7])
347        AC_DEFINE([DARWIN_10_8], 100800, [DARWIN_VERS value for Mac OS X 10.8])
348        AC_DEFINE([DARWIN_10_9], 100900, [DARWIN_VERS value for Mac OS X 10.9])
349        AC_DEFINE([DARWIN_10_10], 101000, [DARWIN_VERS value for Mac OS X 10.10])
350        AC_DEFINE([DARWIN_10_11], 101100, [DARWIN_VERS value for Mac OS X 10.11])
351        AC_DEFINE([DARWIN_10_12], 101200, [DARWIN_VERS value for macOS 10.12])
352
353	AC_MSG_CHECKING([for the kernel version])
354	kernel=`uname -r`
355
356        # Nb: for Darwin we set DEFAULT_SUPP here.  That's because Darwin
357        # has only one relevant version, the OS version. The `uname` check
358        # is a good way to get that version (i.e. "Darwin 9.6.0" is Mac OS
359        # X 10.5.6, and "Darwin 10.x" is Mac OS X 10.6.x Snow Leopard,
360        # and possibly "Darwin 11.x" is Mac OS X 10.7.x Lion),
361        # and we don't know of an macros similar to __GLIBC__ to get that info.
362        #
363        # XXX: `uname -r` won't do the right thing for cross-compiles, but
364        # that's not a problem yet.
365        #
366        # jseward 21 Sept 2011: I seriously doubt whether V 3.7.0 will work
367        # on OS X 10.5.x; I haven't tested yet, and only plan to test 3.7.0
368        # on 10.6.8 and 10.7.1.  Although tempted to delete the configure
369        # time support for 10.5 (the 9.* pattern just below), I'll leave it
370        # in for now, just in case anybody wants to give it a try.  But I'm
371        # assuming that 3.7.0 is a Snow Leopard and Lion-only release.
372	case "${kernel}" in
373	     9.*)
374		  AC_MSG_RESULT([Darwin 9.x (${kernel}) / Mac OS X 10.5 Leopard])
375		  AC_DEFINE([DARWIN_VERS], DARWIN_10_5, [Darwin / Mac OS X version])
376		  DEFAULT_SUPP="darwin9.supp ${DEFAULT_SUPP}"
377		  DEFAULT_SUPP="darwin9-drd.supp ${DEFAULT_SUPP}"
378		  ;;
379	     10.*)
380		  AC_MSG_RESULT([Darwin 10.x (${kernel}) / Mac OS X 10.6 Snow Leopard])
381		  AC_DEFINE([DARWIN_VERS], DARWIN_10_6, [Darwin / Mac OS X version])
382		  DEFAULT_SUPP="darwin10.supp ${DEFAULT_SUPP}"
383		  DEFAULT_SUPP="darwin10-drd.supp ${DEFAULT_SUPP}"
384		  ;;
385	     11.*)
386		  AC_MSG_RESULT([Darwin 11.x (${kernel}) / Mac OS X 10.7 Lion])
387		  AC_DEFINE([DARWIN_VERS], DARWIN_10_7, [Darwin / Mac OS X version])
388		  DEFAULT_SUPP="darwin11.supp ${DEFAULT_SUPP}"
389		  DEFAULT_SUPP="darwin10-drd.supp ${DEFAULT_SUPP}"
390		  ;;
391	     12.*)
392		  AC_MSG_RESULT([Darwin 12.x (${kernel}) / Mac OS X 10.8 Mountain Lion])
393		  AC_DEFINE([DARWIN_VERS], DARWIN_10_8, [Darwin / Mac OS X version])
394		  DEFAULT_SUPP="darwin12.supp ${DEFAULT_SUPP}"
395		  DEFAULT_SUPP="darwin10-drd.supp ${DEFAULT_SUPP}"
396		  ;;
397	     13.*)
398		  AC_MSG_RESULT([Darwin 13.x (${kernel}) / Mac OS X 10.9 Mavericks])
399		  AC_DEFINE([DARWIN_VERS], DARWIN_10_9, [Darwin / Mac OS X version])
400		  DEFAULT_SUPP="darwin13.supp ${DEFAULT_SUPP}"
401		  DEFAULT_SUPP="darwin10-drd.supp ${DEFAULT_SUPP}"
402		  ;;
403	     14.*)
404		  AC_MSG_RESULT([Darwin 14.x (${kernel}) / Mac OS X 10.10 Yosemite])
405		  AC_DEFINE([DARWIN_VERS], DARWIN_10_10, [Darwin / Mac OS X version])
406		  DEFAULT_SUPP="darwin14.supp ${DEFAULT_SUPP}"
407		  DEFAULT_SUPP="darwin10-drd.supp ${DEFAULT_SUPP}"
408		  ;;
409	     15.*)
410		  AC_MSG_RESULT([Darwin 15.x (${kernel}) / Mac OS X 10.11 El Capitan])
411		  AC_DEFINE([DARWIN_VERS], DARWIN_10_11, [Darwin / Mac OS X version])
412		  DEFAULT_SUPP="darwin15.supp ${DEFAULT_SUPP}"
413		  DEFAULT_SUPP="darwin10-drd.supp ${DEFAULT_SUPP}"
414		  ;;
415	     16.*)
416		  AC_MSG_RESULT([Darwin 16.x (${kernel}) / macOS 10.12 Sierra])
417		  AC_DEFINE([DARWIN_VERS], DARWIN_10_12, [Darwin / Mac OS X version])
418		  DEFAULT_SUPP="darwin16.supp ${DEFAULT_SUPP}"
419		  DEFAULT_SUPP="darwin10-drd.supp ${DEFAULT_SUPP}"
420		  ;;
421             *)
422		  AC_MSG_RESULT([unsupported (${kernel})])
423		  AC_MSG_ERROR([Valgrind works on Darwin 10.x, 11.x, 12.x, 13.x, 14.x, 15.x and 16.x (Mac OS X 10.6/7/8/9/10/11 and macOS 10.12)])
424		  ;;
425	esac
426        ;;
427
428     solaris2.11*)
429        AC_MSG_RESULT([ok (${host_os})])
430        VGCONF_OS="solaris"
431        DEFAULT_SUPP="solaris11.supp ${DEFAULT_SUPP}"
432        ;;
433
434     solaris2.12*)
435        AC_MSG_RESULT([ok (${host_os})])
436        VGCONF_OS="solaris"
437        DEFAULT_SUPP="solaris12.supp ${DEFAULT_SUPP}"
438        ;;
439
440     *)
441	AC_MSG_RESULT([no (${host_os})])
442	AC_MSG_ERROR([Valgrind is operating system specific. Sorry.])
443	;;
444esac
445
446#----------------------------------------------------------------------------
447
448# If we are building on a 64 bit platform test to see if the system
449# supports building 32 bit programs and disable 32 bit support if it
450# does not support building 32 bit programs
451
452case "$ARCH_MAX-$VGCONF_OS" in
453     amd64-linux|ppc64be-linux|arm64-linux|amd64-solaris)
454        AC_MSG_CHECKING([for 32 bit build support])
455        safe_CFLAGS=$CFLAGS
456        CFLAGS="-m32"
457        AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[
458          return 0;
459        ]])], [
460        AC_MSG_RESULT([yes])
461        ], [
462        vg_cv_only64bit="yes"
463        AC_MSG_RESULT([no])
464        ])
465        CFLAGS=$safe_CFLAGS;;
466esac
467
468if test x$vg_cv_only64bit = xyes -a x$vg_cv_only32bit = xyes; then
469   AC_MSG_ERROR(
470      [--enable-only32bit was specified but system does not support 32 bit builds])
471fi
472
473#----------------------------------------------------------------------------
474
475# VGCONF_ARCH_PRI is the arch for the primary build target, eg. "amd64".  By
476# default it's the same as ARCH_MAX.  But if, say, we do a build on an amd64
477# machine, but --enable-only32bit has been requested, then ARCH_MAX (see
478# above) will be "amd64" since that reflects the most that this cpu can do,
479# but VGCONF_ARCH_PRI will be downgraded to "x86", since that reflects the
480# arch corresponding to the primary build (VGCONF_PLATFORM_PRI_CAPS).  It is
481# passed in to compilation of many C files via -VGA_$(VGCONF_ARCH_PRI) and
482# -VGP_$(VGCONF_ARCH_PRI)_$(VGCONF_OS).
483AC_SUBST(VGCONF_ARCH_PRI)
484
485# VGCONF_ARCH_SEC is the arch for the secondary build target, eg. "x86".
486# It is passed in to compilation of many C files via -VGA_$(VGCONF_ARCH_SEC)
487# and -VGP_$(VGCONF_ARCH_SEC)_$(VGCONF_OS), if there is a secondary target.
488# It is empty if there is no secondary target.
489AC_SUBST(VGCONF_ARCH_SEC)
490
491# VGCONF_PLATFORM_PRI_CAPS is the primary build target, eg. "AMD64_LINUX".
492# The entire system, including regression and performance tests, will be
493# built for this target.  The "_CAPS" indicates that the name is in capital
494# letters, and it also uses '_' rather than '-' as a separator, because it's
495# used to create various Makefile variables, which are all in caps by
496# convention and cannot contain '-' characters.  This is in contrast to
497# VGCONF_ARCH_PRI and VGCONF_OS which are not in caps.
498AC_SUBST(VGCONF_PLATFORM_PRI_CAPS)
499
500# VGCONF_PLATFORM_SEC_CAPS is the secondary build target, if there is one.
501# Valgrind and tools will also be built for this target, but not the
502# regression or performance tests.
503#
504# By default, the primary arch is the same as the "max" arch, as commented
505# above (at the definition of ARCH_MAX).  We may choose to downgrade it in
506# the big case statement just below here, in the case where we're building
507# on a 64 bit machine but have been requested only to do a 32 bit build.
508AC_SUBST(VGCONF_PLATFORM_SEC_CAPS)
509
510AC_MSG_CHECKING([for a supported CPU/OS combination])
511
512# NB.  The load address for a given platform may be specified in more
513# than one place, in some cases, depending on whether we're doing a biarch,
514# 32-bit only or 64-bit only build.  eg see case for amd64-linux below.
515# Be careful to give consistent values in all subcases.  Also, all four
516# valt_load_addres_{pri,sec}_{norml,inner} values must always be set,
517# even if it is to "0xUNSET".
518#
519case "$ARCH_MAX-$VGCONF_OS" in
520     x86-linux)
521        VGCONF_ARCH_PRI="x86"
522        VGCONF_ARCH_SEC=""
523	VGCONF_PLATFORM_PRI_CAPS="X86_LINUX"
524	VGCONF_PLATFORM_SEC_CAPS=""
525        valt_load_address_pri_norml="0x58000000"
526        valt_load_address_pri_inner="0x38000000"
527        valt_load_address_sec_norml="0xUNSET"
528        valt_load_address_sec_inner="0xUNSET"
529        AC_MSG_RESULT([ok (${ARCH_MAX}-${VGCONF_OS})])
530	;;
531     amd64-linux)
532        valt_load_address_sec_norml="0xUNSET"
533        valt_load_address_sec_inner="0xUNSET"
534	if test x$vg_cv_only64bit = xyes; then
535           VGCONF_ARCH_PRI="amd64"
536           VGCONF_ARCH_SEC=""
537	   VGCONF_PLATFORM_PRI_CAPS="AMD64_LINUX"
538	   VGCONF_PLATFORM_SEC_CAPS=""
539           valt_load_address_pri_norml="0x58000000"
540           valt_load_address_pri_inner="0x38000000"
541	elif test x$vg_cv_only32bit = xyes; then
542	   VGCONF_ARCH_PRI="x86"
543           VGCONF_ARCH_SEC=""
544	   VGCONF_PLATFORM_PRI_CAPS="X86_LINUX"
545	   VGCONF_PLATFORM_SEC_CAPS=""
546           valt_load_address_pri_norml="0x58000000"
547           valt_load_address_pri_inner="0x38000000"
548	else
549           VGCONF_ARCH_PRI="amd64"
550           VGCONF_ARCH_SEC="x86"
551	   VGCONF_PLATFORM_PRI_CAPS="AMD64_LINUX"
552	   VGCONF_PLATFORM_SEC_CAPS="X86_LINUX"
553           valt_load_address_pri_norml="0x58000000"
554           valt_load_address_pri_inner="0x38000000"
555           valt_load_address_sec_norml="0x58000000"
556           valt_load_address_sec_inner="0x38000000"
557	fi
558        AC_MSG_RESULT([ok (${ARCH_MAX}-${VGCONF_OS})])
559	;;
560     ppc32-linux)
561        VGCONF_ARCH_PRI="ppc32"
562        VGCONF_ARCH_SEC=""
563	VGCONF_PLATFORM_PRI_CAPS="PPC32_LINUX"
564	VGCONF_PLATFORM_SEC_CAPS=""
565        valt_load_address_pri_norml="0x58000000"
566        valt_load_address_pri_inner="0x38000000"
567        valt_load_address_sec_norml="0xUNSET"
568        valt_load_address_sec_inner="0xUNSET"
569        AC_MSG_RESULT([ok (${ARCH_MAX}-${VGCONF_OS})])
570	;;
571     ppc64be-linux)
572        valt_load_address_sec_norml="0xUNSET"
573        valt_load_address_sec_inner="0xUNSET"
574	if test x$vg_cv_only64bit = xyes; then
575	   VGCONF_ARCH_PRI="ppc64be"
576           VGCONF_ARCH_SEC=""
577	   VGCONF_PLATFORM_PRI_CAPS="PPC64BE_LINUX"
578	   VGCONF_PLATFORM_SEC_CAPS=""
579           valt_load_address_pri_norml="0x58000000"
580           valt_load_address_pri_inner="0x38000000"
581	elif test x$vg_cv_only32bit = xyes; then
582	   VGCONF_ARCH_PRI="ppc32"
583           VGCONF_ARCH_SEC=""
584	   VGCONF_PLATFORM_PRI_CAPS="PPC32_LINUX"
585	   VGCONF_PLATFORM_SEC_CAPS=""
586           valt_load_address_pri_norml="0x58000000"
587           valt_load_address_pri_inner="0x38000000"
588	else
589	   VGCONF_ARCH_PRI="ppc64be"
590           VGCONF_ARCH_SEC="ppc32"
591	   VGCONF_PLATFORM_PRI_CAPS="PPC64BE_LINUX"
592	   VGCONF_PLATFORM_SEC_CAPS="PPC32_LINUX"
593           valt_load_address_pri_norml="0x58000000"
594           valt_load_address_pri_inner="0x38000000"
595           valt_load_address_sec_norml="0x58000000"
596           valt_load_address_sec_inner="0x38000000"
597	fi
598        AC_MSG_RESULT([ok (${ARCH_MAX}-${VGCONF_OS})])
599	;;
600     ppc64le-linux)
601        # Little Endian is only supported on PPC64
602        valt_load_address_sec_norml="0xUNSET"
603        valt_load_address_sec_inner="0xUNSET"
604        VGCONF_ARCH_PRI="ppc64le"
605        VGCONF_ARCH_SEC=""
606        VGCONF_PLATFORM_PRI_CAPS="PPC64LE_LINUX"
607        VGCONF_PLATFORM_SEC_CAPS=""
608        valt_load_address_pri_norml="0x58000000"
609        valt_load_address_pri_inner="0x38000000"
610        AC_MSG_RESULT([ok (${ARCH_MAX}-${VGCONF_OS})])
611       ;;
612     # Darwin gets identified as 32-bit even when it supports 64-bit.
613     # (Not sure why, possibly because 'uname' returns "i386"?)  Just about
614     # all Macs support both 32-bit and 64-bit, so we just build both.  If
615     # someone has a really old 32-bit only machine they can (hopefully?)
616     # build with --enable-only32bit.  See bug 243362.
617     x86-darwin|amd64-darwin)
618        ARCH_MAX="amd64"
619        valt_load_address_sec_norml="0xUNSET"
620        valt_load_address_sec_inner="0xUNSET"
621	if test x$vg_cv_only64bit = xyes; then
622           VGCONF_ARCH_PRI="amd64"
623           VGCONF_ARCH_SEC=""
624	   VGCONF_PLATFORM_PRI_CAPS="AMD64_DARWIN"
625	   VGCONF_PLATFORM_SEC_CAPS=""
626           valt_load_address_pri_norml="0x158000000"
627           valt_load_address_pri_inner="0x138000000"
628	elif test x$vg_cv_only32bit = xyes; then
629           VGCONF_ARCH_PRI="x86"
630           VGCONF_ARCH_SEC=""
631	   VGCONF_PLATFORM_PRI_CAPS="X86_DARWIN"
632	   VGCONF_PLATFORM_SEC_CAPS=""
633	   VGCONF_ARCH_PRI_CAPS="x86"
634           valt_load_address_pri_norml="0x58000000"
635           valt_load_address_pri_inner="0x38000000"
636	else
637           VGCONF_ARCH_PRI="amd64"
638           VGCONF_ARCH_SEC="x86"
639	   VGCONF_PLATFORM_PRI_CAPS="AMD64_DARWIN"
640	   VGCONF_PLATFORM_SEC_CAPS="X86_DARWIN"
641           valt_load_address_pri_norml="0x158000000"
642           valt_load_address_pri_inner="0x138000000"
643           valt_load_address_sec_norml="0x58000000"
644           valt_load_address_sec_inner="0x38000000"
645	fi
646        AC_MSG_RESULT([ok (${ARCH_MAX}-${VGCONF_OS})])
647	;;
648     arm-linux)
649	VGCONF_ARCH_PRI="arm"
650	VGCONF_PLATFORM_PRI_CAPS="ARM_LINUX"
651	VGCONF_PLATFORM_SEC_CAPS=""
652	valt_load_address_pri_norml="0x58000000"
653	valt_load_address_pri_inner="0x38000000"
654        valt_load_address_sec_norml="0xUNSET"
655        valt_load_address_sec_inner="0xUNSET"
656	AC_MSG_RESULT([ok (${host_cpu}-${host_os})])
657	;;
658     arm64-linux)
659        valt_load_address_sec_norml="0xUNSET"
660        valt_load_address_sec_inner="0xUNSET"
661        if test x$vg_cv_only64bit = xyes; then
662           VGCONF_ARCH_PRI="arm64"
663           VGCONF_ARCH_SEC=""
664           VGCONF_PLATFORM_PRI_CAPS="ARM64_LINUX"
665           VGCONF_PLATFORM_SEC_CAPS=""
666           valt_load_address_pri_norml="0x58000000"
667           valt_load_address_pri_inner="0x38000000"
668        elif test x$vg_cv_only32bit = xyes; then
669           VGCONF_ARCH_PRI="arm"
670           VGCONF_ARCH_SEC=""
671           VGCONF_PLATFORM_PRI_CAPS="ARM_LINUX"
672           VGCONF_PLATFORM_SEC_CAPS=""
673           valt_load_address_pri_norml="0x58000000"
674           valt_load_address_pri_inner="0x38000000"
675        else
676           VGCONF_ARCH_PRI="arm64"
677           VGCONF_ARCH_SEC="arm"
678           VGCONF_PLATFORM_PRI_CAPS="ARM64_LINUX"
679           VGCONF_PLATFORM_SEC_CAPS="ARM_LINUX"
680           valt_load_address_pri_norml="0x58000000"
681           valt_load_address_pri_inner="0x38000000"
682           valt_load_address_sec_norml="0x58000000"
683           valt_load_address_sec_inner="0x38000000"
684        fi
685        AC_MSG_RESULT([ok (${ARCH_MAX}-${VGCONF_OS})])
686        ;;
687     s390x-linux)
688        VGCONF_ARCH_PRI="s390x"
689        VGCONF_ARCH_SEC=""
690        VGCONF_PLATFORM_PRI_CAPS="S390X_LINUX"
691        VGCONF_PLATFORM_SEC_CAPS=""
692        # To improve branch prediction hit rate we want to have
693        # the generated code close to valgrind (host) code
694        valt_load_address_pri_norml="0x800000000"
695        valt_load_address_pri_inner="0x810000000"
696        valt_load_address_sec_norml="0xUNSET"
697        valt_load_address_sec_inner="0xUNSET"
698        AC_MSG_RESULT([ok (${ARCH_MAX}-${VGCONF_OS})])
699        ;;
700     mips32-linux)
701        VGCONF_ARCH_PRI="mips32"
702        VGCONF_PLATFORM_PRI_CAPS="MIPS32_LINUX"
703        VGCONF_PLATFORM_SEC_CAPS=""
704        valt_load_address_pri_norml="0x58000000"
705        valt_load_address_pri_inner="0x38000000"
706        valt_load_address_sec_norml="0xUNSET"
707        valt_load_address_sec_inner="0xUNSET"
708        AC_MSG_RESULT([ok (${ARCH_MAX}-${VGCONF_OS})])
709        ;;
710     mips64-linux)
711        VGCONF_ARCH_PRI="mips64"
712        VGCONF_PLATFORM_PRI_CAPS="MIPS64_LINUX"
713        VGCONF_PLATFORM_SEC_CAPS=""
714        valt_load_address_pri_norml="0x58000000"
715        valt_load_address_pri_inner="0x38000000"
716        valt_load_address_sec_norml="0xUNSET"
717        valt_load_address_sec_inner="0xUNSET"
718        AC_MSG_RESULT([ok (${ARCH_MAX}-${VGCONF_OS})])
719        ;;
720     x86-solaris)
721        VGCONF_ARCH_PRI="x86"
722        VGCONF_ARCH_SEC=""
723        VGCONF_PLATFORM_PRI_CAPS="X86_SOLARIS"
724        VGCONF_PLATFORM_SEC_CAPS=""
725        valt_load_address_pri_norml="0x58000000"
726        valt_load_address_pri_inner="0x38000000"
727        valt_load_address_sec_norml="0xUNSET"
728        valt_load_address_sec_inner="0xUNSET"
729        AC_MSG_RESULT([ok (${ARCH_MAX}-${VGCONF_OS})])
730        ;;
731     amd64-solaris)
732        valt_load_address_sec_norml="0xUNSET"
733        valt_load_address_sec_inner="0xUNSET"
734        if test x$vg_cv_only64bit = xyes; then
735           VGCONF_ARCH_PRI="amd64"
736           VGCONF_ARCH_SEC=""
737           VGCONF_PLATFORM_PRI_CAPS="AMD64_SOLARIS"
738           VGCONF_PLATFORM_SEC_CAPS=""
739           valt_load_address_pri_norml="0x58000000"
740           valt_load_address_pri_inner="0x38000000"
741        elif test x$vg_cv_only32bit = xyes; then
742           VGCONF_ARCH_PRI="x86"
743           VGCONF_ARCH_SEC=""
744           VGCONF_PLATFORM_PRI_CAPS="X86_SOLARIS"
745           VGCONF_PLATFORM_SEC_CAPS=""
746           valt_load_address_pri_norml="0x58000000"
747           valt_load_address_pri_inner="0x38000000"
748        else
749           VGCONF_ARCH_PRI="amd64"
750           VGCONF_ARCH_SEC="x86"
751           VGCONF_PLATFORM_PRI_CAPS="AMD64_SOLARIS"
752           VGCONF_PLATFORM_SEC_CAPS="X86_SOLARIS"
753           valt_load_address_pri_norml="0x58000000"
754           valt_load_address_pri_inner="0x38000000"
755           valt_load_address_sec_norml="0x58000000"
756           valt_load_address_sec_inner="0x38000000"
757        fi
758        AC_MSG_RESULT([ok (${ARCH_MAX}-${VGCONF_OS})])
759        ;;
760    *)
761        VGCONF_ARCH_PRI="unknown"
762        VGCONF_ARCH_SEC="unknown"
763	VGCONF_PLATFORM_PRI_CAPS="UNKNOWN"
764	VGCONF_PLATFORM_SEC_CAPS="UNKNOWN"
765        valt_load_address_pri_norml="0xUNSET"
766        valt_load_address_pri_inner="0xUNSET"
767        valt_load_address_sec_norml="0xUNSET"
768        valt_load_address_sec_inner="0xUNSET"
769        AC_MSG_RESULT([no (${ARCH_MAX}-${VGCONF_OS})])
770        AC_MSG_ERROR([Valgrind is platform specific. Sorry. Please consider doing a port.])
771        ;;
772esac
773
774#----------------------------------------------------------------------------
775
776# Set up VGCONF_ARCHS_INCLUDE_<arch>.  Either one or two of these become
777# defined.
778AM_CONDITIONAL(VGCONF_ARCHS_INCLUDE_X86,
779               test x$VGCONF_PLATFORM_PRI_CAPS = xX86_LINUX \
780                 -o x$VGCONF_PLATFORM_SEC_CAPS = xX86_LINUX \
781                 -o x$VGCONF_PLATFORM_PRI_CAPS = xX86_DARWIN \
782                 -o x$VGCONF_PLATFORM_SEC_CAPS = xX86_DARWIN \
783                 -o x$VGCONF_PLATFORM_PRI_CAPS = xX86_SOLARIS \
784                 -o x$VGCONF_PLATFORM_SEC_CAPS = xX86_SOLARIS )
785AM_CONDITIONAL(VGCONF_ARCHS_INCLUDE_AMD64,
786               test x$VGCONF_PLATFORM_PRI_CAPS = xAMD64_LINUX \
787                 -o x$VGCONF_PLATFORM_PRI_CAPS = xAMD64_DARWIN \
788                 -o x$VGCONF_PLATFORM_PRI_CAPS = xAMD64_SOLARIS )
789AM_CONDITIONAL(VGCONF_ARCHS_INCLUDE_PPC32,
790               test x$VGCONF_PLATFORM_PRI_CAPS = xPPC32_LINUX \
791                 -o x$VGCONF_PLATFORM_SEC_CAPS = xPPC32_LINUX )
792AM_CONDITIONAL(VGCONF_ARCHS_INCLUDE_PPC64,
793               test x$VGCONF_PLATFORM_PRI_CAPS = xPPC64BE_LINUX \
794                 -o x$VGCONF_PLATFORM_PRI_CAPS = xPPC64LE_LINUX )
795AM_CONDITIONAL(VGCONF_ARCHS_INCLUDE_ARM,
796               test x$VGCONF_PLATFORM_PRI_CAPS = xARM_LINUX \
797                 -o x$VGCONF_PLATFORM_SEC_CAPS = xARM_LINUX )
798AM_CONDITIONAL(VGCONF_ARCHS_INCLUDE_ARM64,
799               test x$VGCONF_PLATFORM_PRI_CAPS = xARM64_LINUX )
800AM_CONDITIONAL(VGCONF_ARCHS_INCLUDE_S390X,
801               test x$VGCONF_PLATFORM_PRI_CAPS = xS390X_LINUX )
802AM_CONDITIONAL(VGCONF_ARCHS_INCLUDE_MIPS32,
803               test x$VGCONF_PLATFORM_PRI_CAPS = xMIPS32_LINUX )
804AM_CONDITIONAL(VGCONF_ARCHS_INCLUDE_MIPS64,
805               test x$VGCONF_PLATFORM_PRI_CAPS = xMIPS64_LINUX )
806
807# Set up VGCONF_PLATFORMS_INCLUDE_<platform>.  Either one or two of these
808# become defined.
809AM_CONDITIONAL(VGCONF_PLATFORMS_INCLUDE_X86_LINUX,
810               test x$VGCONF_PLATFORM_PRI_CAPS = xX86_LINUX \
811                 -o x$VGCONF_PLATFORM_SEC_CAPS = xX86_LINUX)
812AM_CONDITIONAL(VGCONF_PLATFORMS_INCLUDE_AMD64_LINUX,
813               test x$VGCONF_PLATFORM_PRI_CAPS = xAMD64_LINUX)
814AM_CONDITIONAL(VGCONF_PLATFORMS_INCLUDE_PPC32_LINUX,
815               test x$VGCONF_PLATFORM_PRI_CAPS = xPPC32_LINUX \
816                 -o x$VGCONF_PLATFORM_SEC_CAPS = xPPC32_LINUX)
817AM_CONDITIONAL(VGCONF_PLATFORMS_INCLUDE_PPC64BE_LINUX,
818               test x$VGCONF_PLATFORM_PRI_CAPS = xPPC64BE_LINUX)
819AM_CONDITIONAL(VGCONF_PLATFORMS_INCLUDE_PPC64LE_LINUX,
820               test x$VGCONF_PLATFORM_PRI_CAPS = xPPC64LE_LINUX)
821AM_CONDITIONAL(VGCONF_PLATFORMS_INCLUDE_ARM_LINUX,
822               test x$VGCONF_PLATFORM_PRI_CAPS = xARM_LINUX \
823                 -o x$VGCONF_PLATFORM_SEC_CAPS = xARM_LINUX)
824AM_CONDITIONAL(VGCONF_PLATFORMS_INCLUDE_ARM64_LINUX,
825               test x$VGCONF_PLATFORM_PRI_CAPS = xARM64_LINUX)
826AM_CONDITIONAL(VGCONF_PLATFORMS_INCLUDE_S390X_LINUX,
827               test x$VGCONF_PLATFORM_PRI_CAPS = xS390X_LINUX \
828                 -o x$VGCONF_PLATFORM_SEC_CAPS = xS390X_LINUX)
829AM_CONDITIONAL(VGCONF_PLATFORMS_INCLUDE_MIPS32_LINUX,
830               test x$VGCONF_PLATFORM_PRI_CAPS = xMIPS32_LINUX)
831AM_CONDITIONAL(VGCONF_PLATFORMS_INCLUDE_MIPS64_LINUX,
832               test x$VGCONF_PLATFORM_PRI_CAPS = xMIPS64_LINUX)
833AM_CONDITIONAL(VGCONF_PLATFORMS_INCLUDE_X86_DARWIN,
834               test x$VGCONF_PLATFORM_PRI_CAPS = xX86_DARWIN \
835                 -o x$VGCONF_PLATFORM_SEC_CAPS = xX86_DARWIN)
836AM_CONDITIONAL(VGCONF_PLATFORMS_INCLUDE_AMD64_DARWIN,
837               test x$VGCONF_PLATFORM_PRI_CAPS = xAMD64_DARWIN)
838AM_CONDITIONAL(VGCONF_PLATFORMS_INCLUDE_X86_SOLARIS,
839               test x$VGCONF_PLATFORM_PRI_CAPS = xX86_SOLARIS \
840                 -o x$VGCONF_PLATFORM_SEC_CAPS = xX86_SOLARIS)
841AM_CONDITIONAL(VGCONF_PLATFORMS_INCLUDE_AMD64_SOLARIS,
842               test x$VGCONF_PLATFORM_PRI_CAPS = xAMD64_SOLARIS)
843
844
845# Similarly, set up VGCONF_OS_IS_<os>.  Exactly one of these becomes defined.
846# Relies on the assumption that the primary and secondary targets are
847# for the same OS, so therefore only necessary to test the primary.
848AM_CONDITIONAL(VGCONF_OS_IS_LINUX,
849               test x$VGCONF_PLATFORM_PRI_CAPS = xX86_LINUX \
850                 -o x$VGCONF_PLATFORM_PRI_CAPS = xAMD64_LINUX \
851                 -o x$VGCONF_PLATFORM_PRI_CAPS = xPPC32_LINUX \
852                 -o x$VGCONF_PLATFORM_PRI_CAPS = xPPC64BE_LINUX \
853                 -o x$VGCONF_PLATFORM_PRI_CAPS = xPPC64LE_LINUX \
854                 -o x$VGCONF_PLATFORM_PRI_CAPS = xARM_LINUX \
855                 -o x$VGCONF_PLATFORM_PRI_CAPS = xARM64_LINUX \
856                 -o x$VGCONF_PLATFORM_PRI_CAPS = xS390X_LINUX \
857                 -o x$VGCONF_PLATFORM_PRI_CAPS = xMIPS32_LINUX \
858                 -o x$VGCONF_PLATFORM_PRI_CAPS = xMIPS64_LINUX)
859AM_CONDITIONAL(VGCONF_OS_IS_DARWIN,
860               test x$VGCONF_PLATFORM_PRI_CAPS = xX86_DARWIN \
861                 -o x$VGCONF_PLATFORM_PRI_CAPS = xAMD64_DARWIN)
862AM_CONDITIONAL(VGCONF_OS_IS_SOLARIS,
863               test x$VGCONF_PLATFORM_PRI_CAPS = xX86_SOLARIS \
864                 -o x$VGCONF_PLATFORM_PRI_CAPS = xAMD64_SOLARIS)
865
866
867# Sometimes, in the Makefile.am files, it's useful to know whether or not
868# there is a secondary target.
869AM_CONDITIONAL(VGCONF_HAVE_PLATFORM_SEC,
870               test x$VGCONF_PLATFORM_SEC_CAPS != x)
871
872dnl automake-1.10 does not have AM_COND_IF (added in 1.11), so we supply a
873dnl fallback definition
874dnl The macro is courtesy of Dave Hart:
875dnl   https://lists.gnu.org/archive/html/automake/2010-12/msg00045.html
876m4_ifndef([AM_COND_IF], [AC_DEFUN([AM_COND_IF], [
877if test -z "$$1_TRUE"; then :
878  m4_n([$2])[]dnl
879m4_ifval([$3],
880[else
881  $3
882])dnl
883fi[]dnl
884])])
885
886#----------------------------------------------------------------------------
887# Inner Valgrind?
888#----------------------------------------------------------------------------
889
890# Check if this should be built as an inner Valgrind, to be run within
891# another Valgrind.  Choose the load address accordingly.
892AC_SUBST(VALT_LOAD_ADDRESS_PRI)
893AC_SUBST(VALT_LOAD_ADDRESS_SEC)
894AC_CACHE_CHECK([for use as an inner Valgrind], vg_cv_inner,
895   [AC_ARG_ENABLE(inner,
896      [  --enable-inner          enables self-hosting],
897      [vg_cv_inner=$enableval],
898      [vg_cv_inner=no])])
899if test "$vg_cv_inner" = yes; then
900    AC_DEFINE([ENABLE_INNER], 1, [configured to run as an inner Valgrind])
901    VALT_LOAD_ADDRESS_PRI=$valt_load_address_pri_inner
902    VALT_LOAD_ADDRESS_SEC=$valt_load_address_sec_inner
903else
904    VALT_LOAD_ADDRESS_PRI=$valt_load_address_pri_norml
905    VALT_LOAD_ADDRESS_SEC=$valt_load_address_sec_norml
906fi
907
908#----------------------------------------------------------------------------
909# Undefined behaviour sanitiser
910#----------------------------------------------------------------------------
911# Check whether we should build with the undefined beahviour sanitiser.
912
913AC_CACHE_CHECK([for using the undefined behaviour sanitiser], vg_cv_ubsan,
914   [AC_ARG_ENABLE(ubsan,
915      [  --enable-ubsan          enables the undefined behaviour sanitiser],
916      [vg_cv_ubsan=$enableval],
917      [vg_cv_ubsan=no])])
918
919#----------------------------------------------------------------------------
920# Extra fine-tuning of installation directories
921#----------------------------------------------------------------------------
922AC_ARG_WITH(tmpdir,
923   [  --with-tmpdir=PATH      Specify path for temporary files],
924   tmpdir="$withval",
925   tmpdir="/tmp")
926AC_DEFINE_UNQUOTED(VG_TMPDIR, "$tmpdir", [Temporary files directory])
927AC_SUBST(VG_TMPDIR, [$tmpdir])
928
929
930#----------------------------------------------------------------------------
931# Libc and suppressions
932#----------------------------------------------------------------------------
933# This variable will collect the suppression files to be used.
934AC_SUBST(DEFAULT_SUPP)
935
936AC_CHECK_HEADER([features.h])
937
938if test x$ac_cv_header_features_h = xyes; then
939  rm -f conftest.$ac_ext
940  cat <<_ACEOF >conftest.$ac_ext
941#include <features.h>
942#if defined(__GNU_LIBRARY__) && defined(__GLIBC__) && defined(__GLIBC_MINOR__)
943glibc version is: __GLIBC__ __GLIBC_MINOR__
944#endif
945_ACEOF
946  GLIBC_VERSION="`$CPP -P conftest.$ac_ext | $SED -n 's/^glibc version is: //p' | $SED 's/ /./g'`"
947fi
948
949# not really a version check
950AC_EGREP_CPP([DARWIN_LIBC], [
951#include <sys/cdefs.h>
952#if defined(__DARWIN_VERS_1050)
953  DARWIN_LIBC
954#endif
955],
956GLIBC_VERSION="darwin")
957
958# not really a version check
959AC_EGREP_CPP([BIONIC_LIBC], [
960#if defined(__ANDROID__)
961  BIONIC_LIBC
962#endif
963],
964GLIBC_VERSION="bionic")
965
966# there is only one version of libc on Solaris
967if test x$VGCONF_PLATFORM_PRI_CAPS = xX86_SOLARIS \
968     -o x$VGCONF_PLATFORM_PRI_CAPS = xAMD64_SOLARIS; then
969    GLIBC_VERSION="solaris"
970fi
971
972# GLIBC_VERSION is empty if a musl libc is used, so use the toolchain tuple
973# in this case.
974if test x$GLIBC_VERSION = x; then
975    if $CC -dumpmachine | grep -q musl; then
976        GLIBC_VERSION=musl
977    fi
978fi
979
980AC_MSG_CHECKING([the glibc version])
981
982case "${GLIBC_VERSION}" in
983     2.2)
984	AC_MSG_RESULT(${GLIBC_VERSION} family)
985	DEFAULT_SUPP="glibc-2.2.supp ${DEFAULT_SUPP}"
986	DEFAULT_SUPP="glibc-2.2-LinuxThreads-helgrind.supp ${DEFAULT_SUPP}"
987	DEFAULT_SUPP="glibc-2.X-drd.supp ${DEFAULT_SUPP}"
988	;;
989     2.[[3-6]])
990	AC_MSG_RESULT(${GLIBC_VERSION} family)
991	DEFAULT_SUPP="glibc-${GLIBC_VERSION}.supp ${DEFAULT_SUPP}"
992	DEFAULT_SUPP="glibc-2.34567-NPTL-helgrind.supp ${DEFAULT_SUPP}"
993	DEFAULT_SUPP="glibc-2.X-drd.supp ${DEFAULT_SUPP}"
994	;;
995     2.[[7-9]])
996	AC_MSG_RESULT(${GLIBC_VERSION} family)
997	DEFAULT_SUPP="glibc-2.X.supp ${DEFAULT_SUPP}"
998	DEFAULT_SUPP="glibc-2.34567-NPTL-helgrind.supp ${DEFAULT_SUPP}"
999	DEFAULT_SUPP="glibc-2.X-drd.supp ${DEFAULT_SUPP}"
1000	;;
1001     2.10|2.11)
1002	AC_MSG_RESULT(${GLIBC_VERSION} family)
1003	AC_DEFINE([GLIBC_MANDATORY_STRLEN_REDIRECT], 1,
1004		  [Define to 1 if strlen() has been optimized heavily (amd64 glibc >= 2.10)])
1005	DEFAULT_SUPP="glibc-2.X.supp ${DEFAULT_SUPP}"
1006	DEFAULT_SUPP="glibc-2.34567-NPTL-helgrind.supp ${DEFAULT_SUPP}"
1007	DEFAULT_SUPP="glibc-2.X-drd.supp ${DEFAULT_SUPP}"
1008	;;
1009     2.*)
1010	AC_MSG_RESULT(${GLIBC_VERSION} family)
1011	AC_DEFINE([GLIBC_MANDATORY_STRLEN_REDIRECT], 1,
1012		  [Define to 1 if strlen() has been optimized heavily (amd64 glibc >= 2.10)])
1013	AC_DEFINE([GLIBC_MANDATORY_INDEX_AND_STRLEN_REDIRECT], 1,
1014		  [Define to 1 if index() and strlen() have been optimized heavily (x86 glibc >= 2.12)])
1015	DEFAULT_SUPP="glibc-2.X.supp ${DEFAULT_SUPP}"
1016	DEFAULT_SUPP="glibc-2.34567-NPTL-helgrind.supp ${DEFAULT_SUPP}"
1017	DEFAULT_SUPP="glibc-2.X-drd.supp ${DEFAULT_SUPP}"
1018	;;
1019     darwin)
1020	AC_MSG_RESULT(Darwin)
1021	AC_DEFINE([DARWIN_LIBC], 1, [Define to 1 if you're using Darwin])
1022	# DEFAULT_SUPP set by kernel version check above.
1023	;;
1024     bionic)
1025	AC_MSG_RESULT(Bionic)
1026	AC_DEFINE([BIONIC_LIBC], 1, [Define to 1 if you're using Bionic])
1027	DEFAULT_SUPP="bionic.supp ${DEFAULT_SUPP}"
1028	;;
1029     solaris)
1030	AC_MSG_RESULT(Solaris)
1031	# DEFAULT_SUPP set in host_os switch-case above.
1032	# No other suppression file is used.
1033	;;
1034     musl)
1035	AC_MSG_RESULT(Musl)
1036	AC_DEFINE([MUSL_LIBC], 1, [Define to 1 if you're using Musl libc])
1037	# no DEFAULT_SUPP file yet for musl libc.
1038	;;
1039     2.0|2.1|*)
1040	AC_MSG_RESULT([unsupported version ${GLIBC_VERSION}])
1041	AC_MSG_ERROR([Valgrind requires glibc version 2.2 or later, uClibc,])
1042	AC_MSG_ERROR([musl libc, Darwin libc, Bionic libc or Solaris libc])
1043	;;
1044esac
1045
1046AC_SUBST(GLIBC_VERSION)
1047
1048
1049if test "$VGCONF_OS" != "solaris"; then
1050    # Add default suppressions for the X client libraries.  Make no
1051    # attempt to detect whether such libraries are installed on the
1052    # build machine (or even if any X facilities are present); just
1053    # add the suppressions antidisirregardless.
1054    DEFAULT_SUPP="xfree-4.supp ${DEFAULT_SUPP}"
1055    DEFAULT_SUPP="xfree-3.supp ${DEFAULT_SUPP}"
1056
1057    # Add glibc and X11 suppressions for exp-sgcheck
1058    DEFAULT_SUPP="exp-sgcheck.supp ${DEFAULT_SUPP}"
1059fi
1060
1061
1062#----------------------------------------------------------------------------
1063# Platform variants?
1064#----------------------------------------------------------------------------
1065
1066# Normally the PLAT = (ARCH, OS) characterisation of the platform is enough.
1067# But there are times where we need a bit more control.  The motivating
1068# and currently only case is Android: this is almost identical to
1069# {x86,arm,mips}-linux, but not quite.  So this introduces the concept of
1070# platform variant tags, which get passed in the compile as
1071# -DVGPV_<arch>_<os>_<variant> along with the main -DVGP_<arch>_<os> definition.
1072#
1073# In almost all cases, the <variant> bit is "vanilla".  But for Android
1074# it is "android" instead.
1075#
1076# Consequently (eg), plain arm-linux would build with
1077#
1078#   -DVGP_arm_linux -DVGPV_arm_linux_vanilla
1079#
1080# whilst an Android build would have
1081#
1082#   -DVGP_arm_linux -DVGPV_arm_linux_android
1083#
1084# Same for x86. The setup of the platform variant is pushed relatively far
1085# down this file in order that we can inspect any of the variables set above.
1086
1087# In the normal case ..
1088VGCONF_PLATVARIANT="vanilla"
1089
1090# Android ?
1091if test "$GLIBC_VERSION" = "bionic";
1092then
1093   VGCONF_PLATVARIANT="android"
1094fi
1095
1096AC_SUBST(VGCONF_PLATVARIANT)
1097
1098
1099# FIXME: do we also want to define automake variables
1100# VGCONF_PLATVARIANT_IS_<WHATEVER>, where WHATEVER is (currently)
1101# VANILLA or ANDROID ?  This would be in the style of VGCONF_ARCHS_INCLUDE,
1102# VGCONF_PLATFORMS_INCLUDE and VGCONF_OS_IS above?  Could easily enough
1103# do that.  Problem is that we can't do and-ing in Makefile.am's, but
1104# that's what we'd need to do to use this, since what we'd want to write
1105# is something like
1106#
1107# VGCONF_PLATFORMS_INCLUDE_ARM_LINUX && VGCONF_PLATVARIANT_IS_ANDROID
1108#
1109# Hmm.  Can't think of a nice clean solution to this.
1110
1111AM_CONDITIONAL(VGCONF_PLATVARIANT_IS_VANILLA,
1112               test x$VGCONF_PLATVARIANT = xvanilla)
1113AM_CONDITIONAL(VGCONF_PLATVARIANT_IS_ANDROID,
1114               test x$VGCONF_PLATVARIANT = xandroid)
1115
1116
1117#----------------------------------------------------------------------------
1118# Checking for various library functions and other definitions
1119#----------------------------------------------------------------------------
1120
1121# Check for AT_FDCWD
1122
1123AC_MSG_CHECKING([for AT_FDCWD])
1124AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1125#define _GNU_SOURCE
1126#include <fcntl.h>
1127#include <unistd.h>
1128]], [[
1129  int a = AT_FDCWD;
1130]])], [
1131ac_have_at_fdcwd=yes
1132AC_MSG_RESULT([yes])
1133], [
1134ac_have_at_fdcwd=no
1135AC_MSG_RESULT([no])
1136])
1137
1138AM_CONDITIONAL([HAVE_AT_FDCWD], [test x$ac_have_at_fdcwd = xyes])
1139
1140# Check for stpncpy function definition in string.h
1141# This explicitly checks with _GNU_SOURCE defined since that is also
1142# used in the test case (some systems might define it without anyway
1143# since stpncpy is part of The Open Group Base Specifications Issue 7
1144# IEEE Std 1003.1-2008.
1145AC_MSG_CHECKING([for stpncpy])
1146AC_LINK_IFELSE([AC_LANG_PROGRAM([[
1147#define _GNU_SOURCE
1148#include <string.h>
1149]], [[
1150  char *d;
1151  char *s;
1152  size_t n = 0;
1153  char *r = stpncpy(d, s, n);
1154]])], [
1155ac_have_gnu_stpncpy=yes
1156AC_MSG_RESULT([yes])
1157], [
1158ac_have_gnu_stpncpy=no
1159AC_MSG_RESULT([no])
1160])
1161
1162AM_CONDITIONAL([HAVE_GNU_STPNCPY], [test x$ac_have_gnu_stpncpy = xyes])
1163
1164# Check for PTRACE_GETREGS
1165
1166AC_MSG_CHECKING([for PTRACE_GETREGS])
1167AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1168#include <stdlib.h>
1169#include <stddef.h>
1170#include <sys/ptrace.h>
1171#include <sys/user.h>
1172]], [[
1173  void *p;
1174  long res = ptrace (PTRACE_GETREGS, 0, p, p);
1175]])], [
1176AC_MSG_RESULT([yes])
1177AC_DEFINE([HAVE_PTRACE_GETREGS], 1,
1178          [Define to 1 if you have the `PTRACE_GETREGS' ptrace request.])
1179], [
1180AC_MSG_RESULT([no])
1181])
1182
1183
1184# Check for CLOCK_MONOTONIC
1185
1186AC_MSG_CHECKING([for CLOCK_MONOTONIC])
1187
1188AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1189#include <time.h>
1190]], [[
1191  struct timespec t;
1192  clock_gettime(CLOCK_MONOTONIC, &t);
1193  return 0;
1194]])], [
1195AC_MSG_RESULT([yes])
1196AC_DEFINE([HAVE_CLOCK_MONOTONIC], 1,
1197          [Define to 1 if you have the `CLOCK_MONOTONIC' constant.])
1198], [
1199AC_MSG_RESULT([no])
1200])
1201
1202
1203# Check for ELF32/64_CHDR
1204
1205AC_CHECK_TYPES([Elf32_Chdr, Elf64_Chdr], [], [], [[#include <elf.h>]])
1206
1207
1208# Check for PTHREAD_RWLOCK_T
1209
1210AC_MSG_CHECKING([for pthread_rwlock_t])
1211
1212AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1213#define _GNU_SOURCE
1214#include <pthread.h>
1215]], [[
1216  pthread_rwlock_t rwl;
1217]])], [
1218AC_MSG_RESULT([yes])
1219AC_DEFINE([HAVE_PTHREAD_RWLOCK_T], 1,
1220          [Define to 1 if you have the `pthread_rwlock_t' type.])
1221], [
1222AC_MSG_RESULT([no])
1223])
1224
1225
1226# Check for PTHREAD_MUTEX_ADAPTIVE_NP
1227
1228AC_MSG_CHECKING([for PTHREAD_MUTEX_ADAPTIVE_NP])
1229
1230AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1231#define _GNU_SOURCE
1232#include <pthread.h>
1233]], [[
1234  return (PTHREAD_MUTEX_ADAPTIVE_NP);
1235]])], [
1236AC_MSG_RESULT([yes])
1237AC_DEFINE([HAVE_PTHREAD_MUTEX_ADAPTIVE_NP], 1,
1238          [Define to 1 if you have the `PTHREAD_MUTEX_ADAPTIVE_NP' constant.])
1239], [
1240AC_MSG_RESULT([no])
1241])
1242
1243
1244# Check for PTHREAD_MUTEX_ERRORCHECK_NP
1245
1246AC_MSG_CHECKING([for PTHREAD_MUTEX_ERRORCHECK_NP])
1247
1248AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1249#define _GNU_SOURCE
1250#include <pthread.h>
1251]], [[
1252  return (PTHREAD_MUTEX_ERRORCHECK_NP);
1253]])], [
1254AC_MSG_RESULT([yes])
1255AC_DEFINE([HAVE_PTHREAD_MUTEX_ERRORCHECK_NP], 1,
1256          [Define to 1 if you have the `PTHREAD_MUTEX_ERRORCHECK_NP' constant.])
1257], [
1258AC_MSG_RESULT([no])
1259])
1260
1261
1262# Check for PTHREAD_MUTEX_RECURSIVE_NP
1263
1264AC_MSG_CHECKING([for PTHREAD_MUTEX_RECURSIVE_NP])
1265
1266AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1267#define _GNU_SOURCE
1268#include <pthread.h>
1269]], [[
1270  return (PTHREAD_MUTEX_RECURSIVE_NP);
1271]])], [
1272AC_MSG_RESULT([yes])
1273AC_DEFINE([HAVE_PTHREAD_MUTEX_RECURSIVE_NP], 1,
1274          [Define to 1 if you have the `PTHREAD_MUTEX_RECURSIVE_NP' constant.])
1275], [
1276AC_MSG_RESULT([no])
1277])
1278
1279
1280# Check for PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
1281
1282AC_MSG_CHECKING([for PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP])
1283
1284AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1285#define _GNU_SOURCE
1286#include <pthread.h>
1287]], [[
1288  pthread_mutex_t m = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
1289  return 0;
1290]])], [
1291AC_MSG_RESULT([yes])
1292AC_DEFINE([HAVE_PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP], 1,
1293          [Define to 1 if you have the `PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP' constant.])
1294], [
1295AC_MSG_RESULT([no])
1296])
1297
1298
1299# Check whether pthread_mutex_t has a member called __m_kind.
1300
1301AC_CHECK_MEMBER([pthread_mutex_t.__m_kind],
1302	        [AC_DEFINE([HAVE_PTHREAD_MUTEX_T__M_KIND],
1303		           1,
1304			   [Define to 1 if pthread_mutex_t has a member called __m_kind.])
1305                ],
1306		[],
1307		[#include <pthread.h>])
1308
1309
1310# Check whether pthread_mutex_t has a member called __data.__kind.
1311
1312AC_CHECK_MEMBER([pthread_mutex_t.__data.__kind],
1313                [AC_DEFINE([HAVE_PTHREAD_MUTEX_T__DATA__KIND],
1314		          1,
1315			  [Define to 1 if pthread_mutex_t has a member __data.__kind.])
1316                ],
1317		[],
1318		[#include <pthread.h>])
1319
1320# Convenience function.  Set flags based on the existing HWCAP entries.
1321# The AT_HWCAP entries are generated by glibc, and are based on
1322# functions supported by the hardware/system/libc.
1323# Subsequent support for whether the capability will actually be utilized
1324# will also be checked against the compiler capabilities.
1325# called as
1326#      AC_HWCAP_CONTAINS_FLAG[hwcap_string_to_match],[VARIABLE_TO_SET]
1327AC_DEFUN([AC_HWCAP_CONTAINS_FLAG],[
1328  AUXV_CHECK_FOR=$1
1329  AC_MSG_CHECKING([if AT_HWCAP contains the $AUXV_CHECK_FOR indicator])
1330  if LD_SHOW_AUXV=1 `which true` | grep ^AT_HWCAP | grep -q -w ${AUXV_CHECK_FOR}
1331  then
1332    AC_MSG_RESULT([yes])
1333    AC_SUBST([$2],[yes])
1334  else
1335    AC_MSG_RESULT([no])
1336    AC_SUBST([$2],[])
1337  fi
1338])
1339
1340# gather hardware capabilities. (hardware/kernel/libc)
1341AC_HWCAP_CONTAINS_FLAG([altivec],[HWCAP_HAS_ALTIVEC])
1342AC_HWCAP_CONTAINS_FLAG([vsx],[HWCAP_HAS_VSX])
1343AC_HWCAP_CONTAINS_FLAG([dfp],[HWCAP_HAS_DFP])
1344AC_HWCAP_CONTAINS_FLAG([arch_2_05],[HWCAP_HAS_ISA_2_05])
1345AC_HWCAP_CONTAINS_FLAG([arch_2_06],[HWCAP_HAS_ISA_2_06])
1346AC_HWCAP_CONTAINS_FLAG([arch_2_07],[HWCAP_HAS_ISA_2_07])
1347AC_HWCAP_CONTAINS_FLAG([arch_3_00],[HWCAP_HAS_ISA_3_00])
1348AC_HWCAP_CONTAINS_FLAG([htm],[HWCAP_HAS_HTM])
1349
1350# ISA Levels
1351AM_CONDITIONAL(HAS_ISA_2_05, [test x$HWCAP_HAS_ISA_2_05 = xyes])
1352AM_CONDITIONAL(HAS_ISA_2_06, [test x$HWCAP_HAS_ISA_2_06 = xyes])
1353# compiler support for isa 2.07 level instructions
1354AC_MSG_CHECKING([that assembler knows ISA 2.07 instructions ])
1355AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1356]], [[
1357  __asm__ __volatile__("mtvsrd 1,2 ");
1358]])], [
1359ac_asm_have_isa_2_07=yes
1360AC_MSG_RESULT([yes])
1361], [
1362ac_asm_have_isa_2_07=no
1363AC_MSG_RESULT([no])
1364])
1365AM_CONDITIONAL(HAS_ISA_2_07, [test x$ac_asm_have_isa_2_07 = xyes \
1366                               -a x$HWCAP_HAS_ISA_2_07 = xyes])
1367
1368# altivec (vsx) support.
1369# does this compiler support -maltivec and does it have the include file
1370# <altivec.h> ?
1371AC_MSG_CHECKING([for Altivec support in the compiler ])
1372safe_CFLAGS=$CFLAGS
1373CFLAGS="-maltivec -Werror"
1374AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1375#include <altivec.h>
1376]], [[
1377  vector unsigned int v;
1378]])], [
1379ac_have_altivec=yes
1380AC_MSG_RESULT([yes])
1381], [
1382ac_have_altivec=no
1383AC_MSG_RESULT([no])
1384])
1385CFLAGS=$safe_CFLAGS
1386AM_CONDITIONAL([HAS_ALTIVEC], [test x$ac_have_altivec = xyes \
1387                                 -a x$HWCAP_HAS_ALTIVEC = xyes])
1388
1389# Check that both: the compiler supports -mvsx and that the assembler
1390# understands VSX instructions.  If either of those doesn't work,
1391# conclude that we can't do VSX.
1392AC_MSG_CHECKING([for VSX compiler flag support])
1393safe_CFLAGS=$CFLAGS
1394CFLAGS="-mvsx -Werror"
1395AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1396]], [[
1397]])], [
1398ac_compiler_supports_vsx_flag=yes
1399AC_MSG_RESULT([yes])
1400], [
1401ac_compiler_supports_vsx_flag=no
1402AC_MSG_RESULT([no])
1403])
1404CFLAGS=$safe_CFLAGS
1405
1406AC_MSG_CHECKING([for VSX support in the assembler ])
1407safe_CFLAGS=$CFLAGS
1408CFLAGS="-mvsx -Werror"
1409AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1410#include <altivec.h>
1411]], [[
1412  vector unsigned int v;
1413  __asm__ __volatile__("xsmaddadp 32, 32, 33" ::: "memory","cc");
1414]])], [
1415ac_compiler_supports_vsx=yes
1416AC_MSG_RESULT([yes])
1417], [
1418ac_compiler_supports_vsx=no
1419AC_MSG_RESULT([no])
1420])
1421CFLAGS=$safe_CFLAGS
1422AM_CONDITIONAL([HAS_VSX], [test x$ac_compiler_supports_vsx_flag = xyes \
1423                             -a x$ac_compiler_supports_vsx = xyes \
1424                             -a x$HWCAP_HAS_VSX = xyes ])
1425
1426# DFP (Decimal Float)
1427AC_MSG_CHECKING([that assembler knows DFP])
1428AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1429]], [[
1430  #ifdef __s390__
1431  __asm__ __volatile__("adtr 1, 2, 3")
1432  #else
1433  __asm__ __volatile__("dadd 1, 2, 3");
1434  __asm__ __volatile__("dcffix 1, 2");
1435  #endif
1436]])], [
1437ac_asm_have_dfp=yes
1438AC_MSG_RESULT([yes])
1439], [
1440ac_asm_have_dfp=no
1441AC_MSG_RESULT([no])
1442])
1443AC_MSG_CHECKING([that compiler knows -mhard-dfp switch])
1444safe_CFLAGS=$CFLAGS
1445CFLAGS="-mhard-dfp -Werror"
1446AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1447]], [[
1448  #ifdef __s390__
1449  __asm__ __volatile__("adtr 1, 2, 3")
1450  #else
1451  __asm__ __volatile__("dadd 1, 2, 3");
1452  __asm__ __volatile__("dcffix 1, 2");
1453  #endif
1454]])], [
1455ac_compiler_have_dfp=yes
1456AC_MSG_RESULT([yes])
1457], [
1458ac_compiler_have_dfp=no
1459AC_MSG_RESULT([no])
1460])
1461CFLAGS=$safe_CFLAGS
1462AM_CONDITIONAL(HAS_DFP, test x$ac_asm_have_dfp = xyes \
1463                          -a x$ac_compiler_have_dfp = xyes \
1464                          -a x$HWCAP_HAS_DFP = xyes )
1465
1466AC_MSG_CHECKING([that compiler knows DFP datatypes])
1467AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1468]], [[
1469  _Decimal64 x = 0.0DD;
1470]])], [
1471ac_compiler_have_dfp_type=yes
1472AC_MSG_RESULT([yes])
1473], [
1474ac_compiler_have_dfp_type=no
1475AC_MSG_RESULT([no])
1476])
1477AM_CONDITIONAL(BUILD_DFP_TESTS, test x$ac_compiler_have_dfp_type = xyes \
1478                                  -a x$HWCAP_HAS_DFP = xyes )
1479
1480
1481# HTM (Hardware Transactional Memory)
1482AC_MSG_CHECKING([if compiler accepts the -mhtm flag])
1483safe_CFLAGS=$CFLAGS
1484CFLAGS="-mhtm -Werror"
1485AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1486]], [[
1487  return 0;
1488]])], [
1489AC_MSG_RESULT([yes])
1490ac_compiler_supports_htm=yes
1491], [
1492AC_MSG_RESULT([no])
1493ac_compiler_supports_htm=no
1494])
1495CFLAGS=$safe_CFLAGS
1496
1497AC_MSG_CHECKING([if compiler can find the htm builtins])
1498safe_CFLAGS=$CFLAGS
1499CFLAGS="-mhtm -Werror"
1500 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1501 ]], [[
1502   if (__builtin_tbegin (0))
1503      __builtin_tend (0);
1504 ]])], [
1505 AC_MSG_RESULT([yes])
1506ac_compiler_sees_htm_builtins=yes
1507 ], [
1508 AC_MSG_RESULT([no])
1509ac_compiler_sees_htm_builtins=no
1510 ])
1511CFLAGS=$safe_CFLAGS
1512
1513AM_CONDITIONAL(SUPPORTS_HTM, test x$ac_compiler_supports_htm = xyes \
1514                               -a x$ac_compiler_sees_htm_builtins = xyes \
1515                               -a x$HWCAP_HAS_HTM = xyes )
1516
1517# isa 3.0 checking
1518AC_MSG_CHECKING([that assembler knows ISA 3.00 ])
1519
1520AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1521]], [[
1522  __asm__ __volatile__("cnttzw 1,2 ");
1523]])], [
1524ac_asm_have_isa_3_00=yes
1525AC_MSG_RESULT([yes])
1526], [
1527ac_asm_have_isa_3_00=no
1528AC_MSG_RESULT([no])
1529])
1530
1531AM_CONDITIONAL(HAS_ISA_3_00, [test x$ac_asm_have_isa_3_00 = xyes \
1532                             -a x$HWCAP_HAS_ISA_3_00 = xyes])
1533
1534# Check for pthread_create@GLIBC2.0
1535AC_MSG_CHECKING([for pthread_create@GLIBC2.0()])
1536
1537safe_CFLAGS=$CFLAGS
1538CFLAGS="-lpthread -Werror"
1539AC_LINK_IFELSE([AC_LANG_PROGRAM([[
1540extern int pthread_create_glibc_2_0(void*, const void*,
1541                                    void *(*)(void*), void*);
1542__asm__(".symver pthread_create_glibc_2_0, pthread_create@GLIBC_2.0");
1543]], [[
1544#ifdef __powerpc__
1545/*
1546 * Apparently on PowerPC linking this program succeeds and generates an
1547 * executable with the undefined symbol pthread_create@GLIBC_2.0.
1548 */
1549#error This test does not work properly on PowerPC.
1550#else
1551  pthread_create_glibc_2_0(0, 0, 0, 0);
1552#endif
1553  return 0;
1554]])], [
1555ac_have_pthread_create_glibc_2_0=yes
1556AC_MSG_RESULT([yes])
1557AC_DEFINE([HAVE_PTHREAD_CREATE_GLIBC_2_0], 1,
1558          [Define to 1 if you have the `pthread_create@glibc2.0' function.])
1559], [
1560ac_have_pthread_create_glibc_2_0=no
1561AC_MSG_RESULT([no])
1562])
1563CFLAGS=$safe_CFLAGS
1564
1565AM_CONDITIONAL(HAVE_PTHREAD_CREATE_GLIBC_2_0,
1566	       test x$ac_have_pthread_create_glibc_2_0 = xyes)
1567
1568
1569# Check for dlinfo RTLD_DI_TLS_MODID
1570AC_MSG_CHECKING([for dlinfo RTLD_DI_TLS_MODID])
1571
1572safe_LIBS="$LIBS"
1573LIBS="-ldl"
1574AC_LINK_IFELSE([AC_LANG_PROGRAM([[
1575#ifndef _GNU_SOURCE
1576#define _GNU_SOURCE
1577#endif
1578#include <link.h>
1579#include <dlfcn.h>
1580]], [[
1581  size_t sizes[10000];
1582  size_t modid_offset;
1583  (void) dlinfo ((void*)sizes, RTLD_DI_TLS_MODID, &modid_offset);
1584  return 0;
1585]])], [
1586ac_have_dlinfo_rtld_di_tls_modid=yes
1587AC_MSG_RESULT([yes])
1588AC_DEFINE([HAVE_DLINFO_RTLD_DI_TLS_MODID], 1,
1589          [Define to 1 if you have a dlinfo that can do RTLD_DI_TLS_MODID.])
1590], [
1591ac_have_dlinfo_rtld_di_tls_modid=no
1592AC_MSG_RESULT([no])
1593])
1594LIBS=$safe_LIBS
1595
1596AM_CONDITIONAL(HAVE_DLINFO_RTLD_DI_TLS_MODID,
1597	       test x$ac_have_dlinfo_rtld_di_tls_modid = xyes)
1598
1599
1600# Check for eventfd_t, eventfd() and eventfd_read()
1601AC_MSG_CHECKING([for eventfd()])
1602
1603AC_LINK_IFELSE([AC_LANG_PROGRAM([[
1604#include <sys/eventfd.h>
1605]], [[
1606  eventfd_t ev;
1607  int fd;
1608
1609  fd = eventfd(5, 0);
1610  eventfd_read(fd, &ev);
1611  return 0;
1612]])], [
1613AC_MSG_RESULT([yes])
1614AC_DEFINE([HAVE_EVENTFD], 1,
1615          [Define to 1 if you have the `eventfd' function.])
1616AC_DEFINE([HAVE_EVENTFD_READ], 1,
1617          [Define to 1 if you have the `eventfd_read' function.])
1618], [
1619AC_MSG_RESULT([no])
1620])
1621
1622# Check whether compiler can process #include <thread> without errors
1623# clang 3.3 cannot process <thread> from e.g.
1624# gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3
1625
1626AC_MSG_CHECKING([that C++ compiler can include <thread> header file])
1627AC_LANG(C++)
1628safe_CXXFLAGS=$CXXFLAGS
1629CXXFLAGS=-std=c++0x
1630
1631AC_COMPILE_IFELSE([AC_LANG_SOURCE([
1632#include <thread>
1633])],
1634[
1635ac_cxx_can_include_thread_header=yes
1636AC_MSG_RESULT([yes])
1637], [
1638ac_cxx_can_include_thread_header=no
1639AC_MSG_RESULT([no])
1640])
1641CXXFLAGS=$safe_CXXFLAGS
1642AC_LANG(C)
1643
1644AM_CONDITIONAL(CXX_CAN_INCLUDE_THREAD_HEADER, test x$ac_cxx_can_include_thread_header = xyes)
1645
1646
1647# On aarch64 before glibc 2.20 we would get the kernel user_pt_regs instead
1648# of the user_regs_struct from sys/user.h. They are structurally the same
1649# but we get either one or the other.
1650
1651AC_CHECK_TYPE([struct user_regs_struct],
1652              [sys_user_has_user_regs=yes], [sys_user_has_user_regs=no],
1653              [[#include <sys/ptrace.h>]
1654               [#include <sys/time.h>]
1655               [#include <sys/user.h>]])
1656if test "$sys_user_has_user_regs" = "yes"; then
1657  AC_DEFINE(HAVE_SYS_USER_REGS, 1,
1658            [Define to 1 if <sys/user.h> defines struct user_regs_struct])
1659fi
1660
1661
1662#----------------------------------------------------------------------------
1663# Checking for supported compiler flags.
1664#----------------------------------------------------------------------------
1665
1666# does this compiler support -m32 ?
1667AC_MSG_CHECKING([if gcc accepts -m32])
1668
1669safe_CFLAGS=$CFLAGS
1670CFLAGS="-m32 -Werror"
1671
1672AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
1673  return 0;
1674]])], [
1675FLAG_M32="-m32"
1676AC_MSG_RESULT([yes])
1677], [
1678FLAG_M32=""
1679AC_MSG_RESULT([no])
1680])
1681CFLAGS=$safe_CFLAGS
1682
1683AC_SUBST(FLAG_M32)
1684
1685
1686# does this compiler support -m64 ?
1687AC_MSG_CHECKING([if gcc accepts -m64])
1688
1689safe_CFLAGS=$CFLAGS
1690CFLAGS="-m64 -Werror"
1691
1692AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
1693  return 0;
1694]])], [
1695FLAG_M64="-m64"
1696AC_MSG_RESULT([yes])
1697], [
1698FLAG_M64=""
1699AC_MSG_RESULT([no])
1700])
1701CFLAGS=$safe_CFLAGS
1702
1703AC_SUBST(FLAG_M64)
1704
1705
1706# does this compiler support -march=mips32 (mips32 default) ?
1707AC_MSG_CHECKING([if gcc accepts -march=mips32])
1708
1709safe_CFLAGS=$CFLAGS
1710CFLAGS="$CFLAGS -march=mips32 -Werror"
1711
1712AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
1713  return 0;
1714]])], [
1715FLAG_MIPS32="-march=mips32"
1716AC_MSG_RESULT([yes])
1717], [
1718FLAG_MIPS32=""
1719AC_MSG_RESULT([no])
1720])
1721CFLAGS=$safe_CFLAGS
1722
1723AC_SUBST(FLAG_MIPS32)
1724
1725
1726# does this compiler support -march=mips64 (mips64 default) ?
1727AC_MSG_CHECKING([if gcc accepts -march=mips64])
1728
1729safe_CFLAGS=$CFLAGS
1730CFLAGS="$CFLAGS -march=mips64 -Werror"
1731
1732AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
1733  return 0;
1734]])], [
1735FLAG_MIPS64="-march=mips64"
1736AC_MSG_RESULT([yes])
1737], [
1738FLAG_MIPS64=""
1739AC_MSG_RESULT([no])
1740])
1741CFLAGS=$safe_CFLAGS
1742
1743AC_SUBST(FLAG_MIPS64)
1744
1745
1746# does this compiler support -march=octeon (Cavium OCTEON I Specific) ?
1747AC_MSG_CHECKING([if gcc accepts -march=octeon])
1748
1749safe_CFLAGS=$CFLAGS
1750CFLAGS="$CFLAGS -march=octeon -Werror"
1751
1752AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
1753  return 0;
1754]])], [
1755FLAG_OCTEON="-march=octeon"
1756AC_MSG_RESULT([yes])
1757], [
1758FLAG_OCTEON=""
1759AC_MSG_RESULT([no])
1760])
1761CFLAGS=$safe_CFLAGS
1762
1763AC_SUBST(FLAG_OCTEON)
1764
1765
1766# does this compiler support -march=octeon2 (Cavium OCTEON II Specific) ?
1767AC_MSG_CHECKING([if gcc accepts -march=octeon2])
1768
1769safe_CFLAGS=$CFLAGS
1770CFLAGS="$CFLAGS -march=octeon2 -Werror"
1771
1772AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
1773  return 0;
1774]])], [
1775FLAG_OCTEON2="-march=octeon2"
1776AC_MSG_RESULT([yes])
1777], [
1778FLAG_OCTEON2=""
1779AC_MSG_RESULT([no])
1780])
1781CFLAGS=$safe_CFLAGS
1782
1783AC_SUBST(FLAG_OCTEON2)
1784
1785
1786# does this compiler support -mmmx ?
1787AC_MSG_CHECKING([if gcc accepts -mmmx])
1788
1789safe_CFLAGS=$CFLAGS
1790CFLAGS="-mmmx -Werror"
1791
1792AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
1793  return 0;
1794]])], [
1795FLAG_MMMX="-mmmx"
1796AC_MSG_RESULT([yes])
1797], [
1798FLAG_MMMX=""
1799AC_MSG_RESULT([no])
1800])
1801CFLAGS=$safe_CFLAGS
1802
1803AC_SUBST(FLAG_MMMX)
1804
1805
1806# does this compiler support -msse ?
1807AC_MSG_CHECKING([if gcc accepts -msse])
1808
1809safe_CFLAGS=$CFLAGS
1810CFLAGS="-msse -Werror"
1811
1812AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
1813  return 0;
1814]])], [
1815FLAG_MSSE="-msse"
1816AC_MSG_RESULT([yes])
1817], [
1818FLAG_MSSE=""
1819AC_MSG_RESULT([no])
1820])
1821CFLAGS=$safe_CFLAGS
1822
1823AC_SUBST(FLAG_MSSE)
1824
1825
1826# does this compiler support -mpreferred-stack-boundary=2 when
1827# generating code for a 32-bit target?  Note that we only care about
1828# this when generating code for (32-bit) x86, so if the compiler
1829# doesn't recognise -m32 it's no big deal.  We'll just get code for
1830# the Memcheck and other helper functions, that is a bit slower than
1831# it could be, on x86; and no difference at all on any other platform.
1832AC_MSG_CHECKING([if gcc accepts -mpreferred-stack-boundary=2 -m32])
1833
1834safe_CFLAGS=$CFLAGS
1835CFLAGS="-mpreferred-stack-boundary=2 -m32 -Werror"
1836
1837AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
1838  return 0;
1839]])], [
1840PREFERRED_STACK_BOUNDARY_2="-mpreferred-stack-boundary=2"
1841AC_MSG_RESULT([yes])
1842], [
1843PREFERRED_STACK_BOUNDARY_2=""
1844AC_MSG_RESULT([no])
1845])
1846CFLAGS=$safe_CFLAGS
1847
1848AC_SUBST(PREFERRED_STACK_BOUNDARY_2)
1849
1850
1851# does this compiler support -mlong-double-128 ?
1852AC_MSG_CHECKING([if gcc accepts -mlong-double-128])
1853safe_CFLAGS=$CFLAGS
1854CFLAGS="-mlong-double-128 -Werror"
1855AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
1856  return 0;
1857]])], [
1858ac_compiler_supports_mlong_double_128=yes
1859AC_MSG_RESULT([yes])
1860], [
1861ac_compiler_supports_mlong_double_128=no
1862AC_MSG_RESULT([no])
1863])
1864CFLAGS=$safe_CFLAGS
1865AM_CONDITIONAL(HAS_MLONG_DOUBLE_128, test x$ac_compiler_supports_mlong_double_128 = xyes)
1866FLAG_MLONG_DOUBLE_128="-mlong-double-128"
1867AC_SUBST(FLAG_MLONG_DOUBLE_128)
1868
1869
1870# Convenience function to check whether GCC supports a particular
1871# warning option. Takes two arguments,
1872# first the warning flag name to check (without -W), then the
1873# substitution name to set with -Wno-warning-flag if the flag exists,
1874# or the empty string if the compiler doesn't accept the flag. Note
1875# that checking is done against the warning flag itself, but the
1876# substitution is then done to cancel the warning flag.
1877AC_DEFUN([AC_GCC_WARNING_SUBST_NO],[
1878  AC_MSG_CHECKING([if gcc accepts -W$1])
1879  safe_CFLAGS=$CFLAGS
1880  CFLAGS="-W$1 -Werror"
1881  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[;]])], [
1882  AC_SUBST([$2], [-Wno-$1])
1883  AC_MSG_RESULT([yes])], [
1884  AC_SUBST([$2], [])
1885  AC_MSG_RESULT([no])])
1886  CFLAGS=$safe_CFLAGS
1887])
1888
1889# Convenience function. Like AC_GCC_WARNING_SUBST_NO, except it substitutes
1890# -W$1  (instead of -Wno-$1).
1891AC_DEFUN([AC_GCC_WARNING_SUBST],[
1892  AC_MSG_CHECKING([if gcc accepts -W$1])
1893  safe_CFLAGS=$CFLAGS
1894  CFLAGS="-W$1 -Werror"
1895  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[;]])], [
1896  AC_SUBST([$2], [-W$1])
1897  AC_MSG_RESULT([yes])], [
1898  AC_SUBST([$2], [])
1899  AC_MSG_RESULT([no])])
1900  CFLAGS=$safe_CFLAGS
1901])
1902
1903AC_GCC_WARNING_SUBST_NO([memset-transposed-args], [FLAG_W_NO_MEMSET_TRANSPOSED_ARGS])
1904AC_GCC_WARNING_SUBST_NO([nonnull], [FLAG_W_NO_NONNULL])
1905AC_GCC_WARNING_SUBST_NO([overflow], [FLAG_W_NO_OVERFLOW])
1906AC_GCC_WARNING_SUBST_NO([pointer-sign], [FLAG_W_NO_POINTER_SIGN])
1907AC_GCC_WARNING_SUBST_NO([uninitialized], [FLAG_W_NO_UNINITIALIZED])
1908AC_GCC_WARNING_SUBST_NO([unused-function], [FLAG_W_NO_UNUSED_FUNCTION])
1909AC_GCC_WARNING_SUBST_NO([static-local-in-inline], [FLAG_W_NO_STATIC_LOCAL_IN_INLINE])
1910AC_GCC_WARNING_SUBST_NO([mismatched-new-delete], [FLAG_W_NO_MISMATCHED_NEW_DELETE])
1911AC_GCC_WARNING_SUBST_NO([infinite-recursion], [FLAG_W_NO_INFINITE_RECURSION])
1912AC_GCC_WARNING_SUBST([write-strings], [FLAG_W_WRITE_STRINGS])
1913AC_GCC_WARNING_SUBST([empty-body], [FLAG_W_EMPTY_BODY])
1914AC_GCC_WARNING_SUBST([format], [FLAG_W_FORMAT])
1915# Disabled for now until all platforms are clean
1916format_checking_enabled=no
1917#format_checking_enabled=yes
1918if test "$format_checking_enabled" = "yes"; then
1919   AC_GCC_WARNING_SUBST([format-signedness], [FLAG_W_FORMAT_SIGNEDNESS])
1920else
1921   dumy_assignment_to_avoid_syntax_errors=1
1922   AC_SUBST([FLAG_W_FORMAT_SIGNEDNESS], [])
1923fi
1924AC_GCC_WARNING_SUBST([cast-qual], [FLAG_W_CAST_QUAL])
1925AC_GCC_WARNING_SUBST([old-style-declaration], [FLAG_W_OLD_STYLE_DECLARATION])
1926AC_GCC_WARNING_SUBST([ignored-qualifiers], [FLAG_W_IGNORED_QUALIFIERS])
1927AC_GCC_WARNING_SUBST([missing-parameter-type], [FLAG_W_MISSING_PARAMETER_TYPE])
1928
1929# Does this compiler support -Wformat-security ?
1930# Special handling is needed, because certain GCC versions require -Wformat
1931# being present if -Wformat-security is given. Otherwise a warning is issued.
1932# However, AC_GCC_WARNING_SUBST will stick in -Werror (see r15323 for rationale).
1933# And with that the warning will be turned into an error with the result
1934# that -Wformat-security is believed to be unsupported when in fact it is.
1935AC_MSG_CHECKING([if gcc accepts -Wformat-security])
1936safe_CFLAGS=$CFLAGS
1937CFLAGS="-Wformat -Wformat-security -Werror"
1938AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[;]])], [
1939AC_SUBST([FLAG_W_FORMAT_SECURITY], [-Wformat-security])
1940AC_MSG_RESULT([yes])], [
1941AC_SUBST([FLAG_W_FORMAT_SECURITY], [])
1942AC_MSG_RESULT([no])])
1943CFLAGS=$safe_CFLAGS
1944
1945# does this compiler support -Wextra or the older -W ?
1946
1947AC_MSG_CHECKING([if gcc accepts -Wextra or -W])
1948
1949safe_CFLAGS=$CFLAGS
1950CFLAGS="-Wextra -Werror"
1951
1952AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ ]], [[
1953  return 0;
1954]])], [
1955AC_SUBST([FLAG_W_EXTRA], [-Wextra])
1956AC_MSG_RESULT([-Wextra])
1957], [
1958  CFLAGS="-W -Werror"
1959  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ ]], [[
1960    return 0;
1961  ]])], [
1962  AC_SUBST([FLAG_W_EXTRA], [-W])
1963  AC_MSG_RESULT([-W])
1964  ], [
1965  AC_SUBST([FLAG_W_EXTRA], [])
1966  AC_MSG_RESULT([not supported])
1967  ])
1968])
1969CFLAGS=$safe_CFLAGS
1970
1971# On ARM we do not want to pass -Wcast-align as that produces loads
1972# of warnings. GCC is just being conservative. See here:
1973# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65459#c4
1974if test "X$VGCONF_ARCH_PRI" = "Xarm"; then
1975  AC_SUBST([FLAG_W_CAST_ALIGN], [""])
1976else
1977  AC_SUBST([FLAG_W_CAST_ALIGN], [-Wcast-align])
1978fi
1979
1980# does this compiler support -fno-stack-protector ?
1981AC_MSG_CHECKING([if gcc accepts -fno-stack-protector])
1982
1983safe_CFLAGS=$CFLAGS
1984CFLAGS="-fno-stack-protector -Werror"
1985
1986AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
1987  return 0;
1988]])], [
1989no_stack_protector=yes
1990FLAG_FNO_STACK_PROTECTOR="-fno-stack-protector"
1991AC_MSG_RESULT([yes])
1992], [
1993no_stack_protector=no
1994FLAG_FNO_STACK_PROTECTOR=""
1995AC_MSG_RESULT([no])
1996])
1997CFLAGS=$safe_CFLAGS
1998
1999AC_SUBST(FLAG_FNO_STACK_PROTECTOR)
2000
2001# Does GCC support disabling Identical Code Folding?
2002# We want to disabled Identical Code Folding for the
2003# tools preload shared objects to get better backraces.
2004# For GCC 5.1+ -fipa-icf is enabled by default at -O2.
2005# "The optimization reduces code size and may disturb
2006#  unwind stacks by replacing a function by equivalent
2007#  one with a different name."
2008AC_MSG_CHECKING([if gcc accepts -fno-ipa-icf])
2009
2010safe_CFLAGS=$CFLAGS
2011CFLAGS="-fno-ipa-icf -Werror"
2012
2013AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
2014  return 0;
2015]])], [
2016no_ipa_icf=yes
2017FLAG_FNO_IPA_ICF="-fno-ipa-icf"
2018AC_MSG_RESULT([yes])
2019], [
2020no_ipa_icf=no
2021FLAG_FNO_IPA_ICF=""
2022AC_MSG_RESULT([no])
2023])
2024CFLAGS=$safe_CFLAGS
2025
2026AC_SUBST(FLAG_FNO_IPA_ICF)
2027
2028
2029# Does this compiler support -fsanitize=undefined. This is true for
2030# GCC 4.9 and newer. However, the undefined behaviour sanitiser in GCC 5.1
2031# also checks for alignment violations on memory accesses which the valgrind
2032# code base is sprinkled (if not littered) with. As those alignment issues
2033# don't pose a problem we want to suppress warnings about them.
2034# In GCC 5.1 this can be done by passing -fno-sanitize=alignment. Earlier
2035# GCCs do not support that.
2036#
2037# Only checked for if --enable-ubsan was given.
2038if test "x${vg_cv_ubsan}" = "xyes"; then
2039AC_MSG_CHECKING([if gcc accepts -fsanitize=undefined -fno-sanitize=alignment])
2040safe_CFLAGS=$CFLAGS
2041CFLAGS="-fsanitize=undefined -fno-sanitize=alignment -Werror"
2042AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
2043  return 0;
2044]])], [
2045FLAG_FSANITIZE="-fsanitize=undefined -fno-sanitize=alignment"
2046LIB_UBSAN="-static-libubsan"
2047AC_MSG_RESULT([yes])
2048], [
2049CFLAGS="-fsanitize=undefined -Werror"
2050AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
2051  return 0;
2052]])], [
2053FLAG_FSANITIZE="-fsanitize=undefined"
2054LIB_UBSAN="-static-libubsan"
2055AC_MSG_RESULT([yes])
2056], [
2057FLAG_FSANITIZE=""
2058LIB_UBSAN=""
2059AC_MSG_RESULT([no])
2060])
2061])
2062CFLAGS=$safe_CFLAGS
2063AC_SUBST(FLAG_FSANITIZE)
2064AC_SUBST(LIB_UBSAN)
2065fi
2066# does this compiler support --param inline-unit-growth=... ?
2067
2068AC_MSG_CHECKING([if gcc accepts --param inline-unit-growth])
2069
2070safe_CFLAGS=$CFLAGS
2071CFLAGS="--param inline-unit-growth=900 -Werror"
2072
2073AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ ]], [[
2074  return 0;
2075]])], [
2076AC_SUBST([FLAG_UNLIMITED_INLINE_UNIT_GROWTH],
2077         ["--param inline-unit-growth=900"])
2078AC_MSG_RESULT([yes])
2079], [
2080AC_SUBST([FLAG_UNLIMITED_INLINE_UNIT_GROWTH], [""])
2081AC_MSG_RESULT([no])
2082])
2083CFLAGS=$safe_CFLAGS
2084
2085
2086# does this compiler support -gdwarf-4 -fdebug-types-section ?
2087
2088AC_MSG_CHECKING([if gcc accepts -gdwarf-4 -fdebug-types-section])
2089
2090safe_CFLAGS=$CFLAGS
2091CFLAGS="-gdwarf-4 -fdebug-types-section -Werror"
2092
2093AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ ]], [[
2094  return 0;
2095]])], [
2096ac_have_dwarf4=yes
2097AC_MSG_RESULT([yes])
2098], [
2099ac_have_dwarf4=no
2100AC_MSG_RESULT([no])
2101])
2102AM_CONDITIONAL(DWARF4, test x$ac_have_dwarf4 = xyes)
2103CFLAGS=$safe_CFLAGS
2104
2105
2106# does this compiler support -g -gz=zlib ?
2107
2108AC_MSG_CHECKING([if gcc accepts -g -gz=zlib])
2109
2110safe_CFLAGS=$CFLAGS
2111CFLAGS="-g -gz=zlib"
2112
2113AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ ]], [[
2114  return 0;
2115]])], [
2116ac_have_gz_zlib=yes
2117AC_MSG_RESULT([yes])
2118], [
2119ac_have_gz_zlib=no
2120AC_MSG_RESULT([no])
2121])
2122AM_CONDITIONAL(GZ_ZLIB, test x$ac_have_gz_zlib = xyes)
2123CFLAGS=$safe_CFLAGS
2124
2125
2126# does this compiler support -g -gz=zlib-gnu ?
2127
2128AC_MSG_CHECKING([if gcc accepts -g -gz=zlib-gnu])
2129
2130safe_CFLAGS=$CFLAGS
2131CFLAGS="-g -gz=zlib-gnu"
2132
2133AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ ]], [[
2134  return 0;
2135]])], [
2136ac_have_gz_zlib_gnu=yes
2137AC_MSG_RESULT([yes])
2138], [
2139ac_have_gz_zlib_gnu=no
2140AC_MSG_RESULT([no])
2141])
2142AM_CONDITIONAL(GZ_ZLIB_GNU, test x$ac_have_gz_zlib_gnu = xyes)
2143CFLAGS=$safe_CFLAGS
2144
2145
2146# does this compiler support nested functions ?
2147
2148AC_MSG_CHECKING([if gcc accepts nested functions])
2149
2150AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
2151  int foo() { return 1; }
2152  return foo();
2153]])], [
2154ac_have_nested_functions=yes
2155AC_MSG_RESULT([yes])
2156], [
2157ac_have_nested_functions=no
2158AC_MSG_RESULT([no])
2159])
2160AM_CONDITIONAL([HAVE_NESTED_FUNCTIONS], [test x$ac_have_nested_functions = xyes])
2161
2162
2163# does this compiler support the 'p' constraint in ASM statements ?
2164
2165AC_MSG_CHECKING([if gcc accepts the 'p' constraint in asm statements])
2166
2167AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
2168   char *p;
2169   __asm__ __volatile__ ("movdqa (%0),%%xmm6\n" : "=p" (p));
2170]])], [
2171ac_have_asm_constraint_p=yes
2172AC_MSG_RESULT([yes])
2173], [
2174ac_have_asm_constraint_p=no
2175AC_MSG_RESULT([no])
2176])
2177AM_CONDITIONAL([HAVE_ASM_CONSTRAINT_P], [test x$ac_have_asm_constraint_p = xyes])
2178
2179
2180# Does this compiler support -no-pie?
2181# On Ubuntu 16.10+, gcc produces position independent executables (PIE) by
2182# default. However this gets in the way with some tests, we use -no-pie
2183# for these.
2184
2185AC_MSG_CHECKING([if gcc accepts -no-pie])
2186
2187safe_CFLAGS=$CFLAGS
2188CFLAGS="-no-pie"
2189
2190AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ ]], [[
2191  return 0;
2192]])], [
2193AC_SUBST([FLAG_NO_PIE], ["-no-pie"])
2194AC_MSG_RESULT([yes])
2195], [
2196AC_SUBST([FLAG_NO_PIE], [""])
2197AC_MSG_RESULT([no])
2198])
2199CFLAGS=$safe_CFLAGS
2200
2201
2202# We want to use use the -Ttext-segment option to the linker.
2203# GNU (bfd) ld supports this directly. Newer GNU gold linkers
2204# support it as an alias of -Ttext. Sadly GNU (bfd) ld's -Ttext
2205# semantics are NOT what we want (GNU gold -Ttext is fine).
2206#
2207# For GNU (bfd) ld -Ttext-segment chooses the base at which ELF headers
2208# will reside. -Ttext aligns just the .text section start (but not any
2209# other section).
2210#
2211# So test for -Ttext-segment which is supported by all bfd ld versions
2212# and use that if it exists. If it doesn't exist it must be an older
2213# version of gold and we can fall back to using -Ttext which has the
2214# right semantics.
2215
2216AC_MSG_CHECKING([if the linker accepts -Wl,-Ttext-segment])
2217
2218safe_CFLAGS=$CFLAGS
2219CFLAGS="-static -nodefaultlibs -nostartfiles -Wl,-Ttext-segment=$valt_load_address_pri_norml -Werror"
2220
2221AC_LINK_IFELSE(
2222[AC_LANG_SOURCE([int _start () { return 0; }])],
2223[
2224  linker_using_t_text="no"
2225  AC_SUBST([FLAG_T_TEXT], ["-Ttext-segment"])
2226  AC_MSG_RESULT([yes])
2227], [
2228  linker_using_t_text="yes"
2229  AC_SUBST([FLAG_T_TEXT], ["-Ttext"])
2230  AC_MSG_RESULT([no])
2231])
2232CFLAGS=$safe_CFLAGS
2233
2234# If the linker only supports -Ttext (not -Ttext-segment) then we will
2235# have to strip any build-id ELF NOTEs from the statically linked tools.
2236# Otherwise the build-id NOTE might end up at the default load address.
2237# (Pedantically if the linker is gold then -Ttext is fine, but newer
2238# gold versions also support -Ttext-segment. So just assume that unless
2239# we can use -Ttext-segment we need to strip the build-id NOTEs.
2240if test "x${linker_using_t_text}" = "xyes"; then
2241AC_MSG_NOTICE([ld -Ttext used, need to strip build-id NOTEs.])
2242# does the linker support -Wl,--build-id=none ?  Note, it's
2243# important that we test indirectly via whichever C compiler
2244# is selected, rather than testing /usr/bin/ld or whatever
2245# directly.
2246AC_MSG_CHECKING([if the linker accepts -Wl,--build-id=none])
2247safe_CFLAGS=$CFLAGS
2248CFLAGS="-Wl,--build-id=none -Werror"
2249
2250AC_LINK_IFELSE(
2251[AC_LANG_PROGRAM([ ], [return 0;])],
2252[
2253  AC_SUBST([FLAG_NO_BUILD_ID], ["-Wl,--build-id=none"])
2254  AC_MSG_RESULT([yes])
2255], [
2256  AC_SUBST([FLAG_NO_BUILD_ID], [""])
2257  AC_MSG_RESULT([no])
2258])
2259else
2260AC_MSG_NOTICE([ld -Ttext-segment used, no need to strip build-id NOTEs.])
2261AC_SUBST([FLAG_NO_BUILD_ID], [""])
2262fi
2263CFLAGS=$safe_CFLAGS
2264
2265# does the ppc assembler support "mtocrf" et al?
2266AC_MSG_CHECKING([if ppc32/64 as supports mtocrf/mfocrf])
2267
2268AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
2269__asm__ __volatile__("mtocrf 4,0");
2270__asm__ __volatile__("mfocrf 0,4");
2271]])], [
2272ac_have_as_ppc_mftocrf=yes
2273AC_MSG_RESULT([yes])
2274], [
2275ac_have_as_ppc_mftocrf=no
2276AC_MSG_RESULT([no])
2277])
2278if test x$ac_have_as_ppc_mftocrf = xyes ; then
2279  AC_DEFINE(HAVE_AS_PPC_MFTOCRF, 1, [Define to 1 if as supports mtocrf/mfocrf.])
2280fi
2281
2282
2283# does the ppc assembler support "lfdp" and other phased out floating point insns?
2284AC_MSG_CHECKING([if ppc32/64 asm supports phased out floating point instructions])
2285
2286AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
2287  do { typedef struct {
2288      double hi;
2289      double lo;
2290     } dbl_pair_t;
2291     dbl_pair_t dbl_pair[3];
2292     __asm__ volatile ("lfdp 10, %0"::"m" (dbl_pair[0]));
2293   } while (0)
2294]])], [
2295ac_have_as_ppc_fpPO=yes
2296AC_MSG_RESULT([yes])
2297], [
2298ac_have_as_ppc_fpPO=no
2299AC_MSG_RESULT([no])
2300])
2301if test x$ac_have_as_ppc_fpPO = xyes ; then
2302  AC_DEFINE(HAVE_AS_PPC_FPPO, 1, [Define to 1 if as supports floating point phased out category.])
2303fi
2304
2305
2306# does the amd64 assembler understand "fxsave64" and "fxrstor64"?
2307AC_MSG_CHECKING([if amd64 assembler supports fxsave64/fxrstor64])
2308
2309AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
2310void* p;
2311asm __volatile__("fxsave64 (%0)" : : "r" (p) : "memory" );
2312asm __volatile__("fxrstor64 (%0)" : : "r" (p) : "memory" );
2313]])], [
2314ac_have_as_amd64_fxsave64=yes
2315AC_MSG_RESULT([yes])
2316], [
2317ac_have_as_amd64_fxsave64=no
2318AC_MSG_RESULT([no])
2319])
2320if test x$ac_have_as_amd64_fxsave64 = xyes ; then
2321  AC_DEFINE(HAVE_AS_AMD64_FXSAVE64, 1, [Define to 1 if as supports fxsave64/fxrstor64.])
2322fi
2323
2324# does the x86/amd64 assembler understand SSE3 instructions?
2325# Note, this doesn't generate a C-level symbol.  It generates a
2326# automake-level symbol (BUILD_SSE3_TESTS), used in test Makefile.am's
2327AC_MSG_CHECKING([if x86/amd64 assembler speaks SSE3])
2328
2329AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
2330  do { long long int x;
2331     __asm__ __volatile__("fisttpq (%0)" : :"r"(&x) ); }
2332  while (0)
2333]])], [
2334ac_have_as_sse3=yes
2335AC_MSG_RESULT([yes])
2336], [
2337ac_have_as_sse3=no
2338AC_MSG_RESULT([no])
2339])
2340
2341AM_CONDITIONAL(BUILD_SSE3_TESTS, test x$ac_have_as_sse3 = xyes)
2342
2343
2344# Ditto for SSSE3 instructions (note extra S)
2345# Note, this doesn't generate a C-level symbol.  It generates a
2346# automake-level symbol (BUILD_SSSE3_TESTS), used in test Makefile.am's
2347AC_MSG_CHECKING([if x86/amd64 assembler speaks SSSE3])
2348
2349save_CFLAGS="$CFLAGS"
2350CFLAGS="$CFLAGS -msse -Werror"
2351AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
2352  do { long long int x;
2353   __asm__ __volatile__(
2354      "pabsb (%0),%%xmm7" : : "r"(&x) : "xmm7" ); }
2355  while (0)
2356]])], [
2357ac_have_as_ssse3=yes
2358AC_MSG_RESULT([yes])
2359], [
2360ac_have_as_ssse3=no
2361AC_MSG_RESULT([no])
2362])
2363CFLAGS="$save_CFLAGS"
2364
2365AM_CONDITIONAL(BUILD_SSSE3_TESTS, test x$ac_have_as_ssse3 = xyes)
2366
2367
2368# does the x86/amd64 assembler understand the PCLMULQDQ instruction?
2369# Note, this doesn't generate a C-level symbol.  It generates a
2370# automake-level symbol (BUILD_PCLMULQDQ_TESTS), used in test Makefile.am's
2371AC_MSG_CHECKING([if x86/amd64 assembler supports 'pclmulqdq'])
2372AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
2373  do {
2374   __asm__ __volatile__(
2375      "pclmulqdq \$17,%%xmm6,%%xmm7" : : : "xmm6", "xmm7" ); }
2376  while (0)
2377]])], [
2378ac_have_as_pclmulqdq=yes
2379AC_MSG_RESULT([yes])
2380], [
2381ac_have_as_pclmulqdq=no
2382AC_MSG_RESULT([no])
2383])
2384
2385AM_CONDITIONAL(BUILD_PCLMULQDQ_TESTS, test x$ac_have_as_pclmulqdq = xyes)
2386
2387
2388# does the x86/amd64 assembler understand the VPCLMULQDQ instruction?
2389# Note, this doesn't generate a C-level symbol.  It generates a
2390# automake-level symbol (BUILD_VPCLMULQDQ_TESTS), used in test Makefile.am's
2391AC_MSG_CHECKING([if x86/amd64 assembler supports 'vpclmulqdq'])
2392AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
2393  do {
2394      /*
2395       * Carry-less multiplication of xmm1 with xmm2 and store the result in
2396       * xmm3. The immediate is used to determine which quadwords of xmm1 and
2397       * xmm2 should be used.
2398       */
2399   __asm__ __volatile__(
2400      "vpclmulqdq \$0,%%xmm1,%%xmm2,%%xmm3" : : : );
2401  } while (0)
2402]])], [
2403ac_have_as_vpclmulqdq=yes
2404AC_MSG_RESULT([yes])
2405], [
2406ac_have_as_vpclmulqdq=no
2407AC_MSG_RESULT([no])
2408])
2409
2410AM_CONDITIONAL(BUILD_VPCLMULQDQ_TESTS, test x$ac_have_as_vpclmulqdq = xyes)
2411
2412
2413# does the x86/amd64 assembler understand FMA4 instructions?
2414# Note, this doesn't generate a C-level symbol.  It generates a
2415# automake-level symbol (BUILD_AFM4_TESTS), used in test Makefile.am's
2416AC_MSG_CHECKING([if x86/amd64 assembler supports FMA4 'vfmaddpd'])
2417AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
2418  do {
2419   __asm__ __volatile__(
2420      "vfmaddpd %%xmm7,%%xmm8,%%xmm6,%%xmm9" : : : );
2421  } while (0)
2422]])], [
2423ac_have_as_vfmaddpd=yes
2424AC_MSG_RESULT([yes])
2425], [
2426ac_have_as_vfmaddpd=no
2427AC_MSG_RESULT([no])
2428])
2429
2430AM_CONDITIONAL(BUILD_FMA4_TESTS, test x$ac_have_as_vfmaddpd = xyes)
2431
2432
2433# does the x86/amd64 assembler understand the LZCNT instruction?
2434# Note, this doesn't generate a C-level symbol.  It generates a
2435# automake-level symbol (BUILD_LZCNT_TESTS), used in test Makefile.am's
2436AC_MSG_CHECKING([if x86/amd64 assembler supports 'lzcnt'])
2437
2438AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
2439  do {
2440      __asm__ __volatile__("lzcnt %%rax,%%rax" : : : "rax");
2441  } while (0)
2442]])], [
2443  ac_have_as_lzcnt=yes
2444  AC_MSG_RESULT([yes])
2445], [
2446  ac_have_as_lzcnt=no
2447  AC_MSG_RESULT([no])
2448])
2449
2450AM_CONDITIONAL([BUILD_LZCNT_TESTS], [test x$ac_have_as_lzcnt = xyes])
2451
2452
2453# does the x86/amd64 assembler understand the LOOPNEL instruction?
2454# Note, this doesn't generate a C-level symbol.  It generates a
2455# automake-level symbol (BUILD_LOOPNEL_TESTS), used in test Makefile.am's
2456AC_MSG_CHECKING([if x86/amd64 assembler supports 'loopnel'])
2457
2458AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
2459  do {
2460      __asm__ __volatile__("1:  loopnel 1b\n");
2461  } while (0)
2462]])], [
2463  ac_have_as_loopnel=yes
2464  AC_MSG_RESULT([yes])
2465], [
2466  ac_have_as_loopnel=no
2467  AC_MSG_RESULT([no])
2468])
2469
2470AM_CONDITIONAL([BUILD_LOOPNEL_TESTS], [test x$ac_have_as_loopnel = xyes])
2471
2472
2473# does the x86/amd64 assembler understand ADDR32 ?
2474# Note, this doesn't generate a C-level symbol.  It generates a
2475# automake-level symbol (BUILD_ADDR32_TESTS), used in test Makefile.am's
2476AC_MSG_CHECKING([if x86/amd64 assembler supports 'addr32'])
2477
2478AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
2479  do {
2480      asm volatile ("addr32 rep movsb");
2481  } while (0)
2482]])], [
2483  ac_have_as_addr32=yes
2484  AC_MSG_RESULT([yes])
2485], [
2486  ac_have_as_addr32=no
2487  AC_MSG_RESULT([no])
2488])
2489
2490AM_CONDITIONAL([BUILD_ADDR32_TESTS], [test x$ac_have_as_addr32 = xyes])
2491
2492
2493# does the x86/amd64 assembler understand SSE 4.2 instructions?
2494# Note, this doesn't generate a C-level symbol.  It generates a
2495# automake-level symbol (BUILD_SSE42_TESTS), used in test Makefile.am's
2496AC_MSG_CHECKING([if x86/amd64 assembler speaks SSE4.2])
2497
2498AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
2499  do { long long int x;
2500   __asm__ __volatile__(
2501      "crc32q %%r15,%%r15" : : : "r15" );
2502   __asm__ __volatile__(
2503      "pblendvb (%%rcx), %%xmm11" : : : "memory", "xmm11");
2504   __asm__ __volatile__(
2505      "aesdec %%xmm2, %%xmm1" : : : "xmm2", "xmm1"); }
2506  while (0)
2507]])], [
2508ac_have_as_sse42=yes
2509AC_MSG_RESULT([yes])
2510], [
2511ac_have_as_sse42=no
2512AC_MSG_RESULT([no])
2513])
2514
2515AM_CONDITIONAL(BUILD_SSE42_TESTS, test x$ac_have_as_sse42 = xyes)
2516
2517
2518# does the x86/amd64 assembler understand AVX instructions?
2519# Note, this doesn't generate a C-level symbol.  It generates a
2520# automake-level symbol (BUILD_AVX_TESTS), used in test Makefile.am's
2521AC_MSG_CHECKING([if x86/amd64 assembler speaks AVX])
2522
2523AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
2524  do { long long int x;
2525   __asm__ __volatile__(
2526      "vmovupd (%%rsp), %%ymm7" : : : "xmm7" );
2527   __asm__ __volatile__(
2528      "vaddpd %%ymm6,%%ymm7,%%ymm8" : : : "xmm6","xmm7","xmm8"); }
2529  while (0)
2530]])], [
2531ac_have_as_avx=yes
2532AC_MSG_RESULT([yes])
2533], [
2534ac_have_as_avx=no
2535AC_MSG_RESULT([no])
2536])
2537
2538AM_CONDITIONAL(BUILD_AVX_TESTS, test x$ac_have_as_avx = xyes)
2539
2540
2541# does the x86/amd64 assembler understand AVX2 instructions?
2542# Note, this doesn't generate a C-level symbol.  It generates a
2543# automake-level symbol (BUILD_AVX2_TESTS), used in test Makefile.am's
2544AC_MSG_CHECKING([if x86/amd64 assembler speaks AVX2])
2545
2546AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
2547  do { long long int x;
2548   __asm__ __volatile__(
2549      "vpsravd (%%rsp), %%ymm8, %%ymm7" : : : "xmm7", "xmm8" );
2550   __asm__ __volatile__(
2551      "vpaddb %%ymm6,%%ymm7,%%ymm8" : : : "xmm6","xmm7","xmm8"); }
2552  while (0)
2553]])], [
2554ac_have_as_avx2=yes
2555AC_MSG_RESULT([yes])
2556], [
2557ac_have_as_avx2=no
2558AC_MSG_RESULT([no])
2559])
2560
2561AM_CONDITIONAL(BUILD_AVX2_TESTS, test x$ac_have_as_avx2 = xyes)
2562
2563
2564# does the x86/amd64 assembler understand TSX instructions and
2565# the XACQUIRE/XRELEASE prefixes?
2566# Note, this doesn't generate a C-level symbol.  It generates a
2567# automake-level symbol (BUILD_TSX_TESTS), used in test Makefile.am's
2568AC_MSG_CHECKING([if x86/amd64 assembler speaks TSX])
2569
2570AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
2571  do {
2572   __asm__ __volatile__(
2573      "       xbegin Lfoo  \n\t"
2574      "Lfoo:  xend         \n\t"
2575      "       xacquire lock incq 0(%rsp)     \n\t"
2576      "       xrelease lock incq 0(%rsp)     \n"
2577   );
2578  } while (0)
2579]])], [
2580ac_have_as_tsx=yes
2581AC_MSG_RESULT([yes])
2582], [
2583ac_have_as_tsx=no
2584AC_MSG_RESULT([no])
2585])
2586
2587AM_CONDITIONAL(BUILD_TSX_TESTS, test x$ac_have_as_tsx = xyes)
2588
2589
2590# does the x86/amd64 assembler understand BMI1 and BMI2 instructions?
2591# Note, this doesn't generate a C-level symbol.  It generates a
2592# automake-level symbol (BUILD_BMI_TESTS), used in test Makefile.am's
2593AC_MSG_CHECKING([if x86/amd64 assembler speaks BMI1 and BMI2])
2594
2595AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
2596  do { unsigned int h, l;
2597   __asm__ __volatile__( "mulx %rax,%rcx,%r8" );
2598   __asm__ __volatile__(
2599      "andn %2, %1, %0" : "=r" (h) : "r" (0x1234567), "r" (0x7654321) );
2600   __asm__ __volatile__(
2601      "movl %2, %%edx; mulx %3, %1, %0" : "=r" (h), "=r" (l) : "g" (0x1234567), "rm" (0x7654321) : "edx" ); }
2602  while (0)
2603]])], [
2604ac_have_as_bmi=yes
2605AC_MSG_RESULT([yes])
2606], [
2607ac_have_as_bmi=no
2608AC_MSG_RESULT([no])
2609])
2610
2611AM_CONDITIONAL(BUILD_BMI_TESTS, test x$ac_have_as_bmi = xyes)
2612
2613
2614# does the x86/amd64 assembler understand FMA instructions?
2615# Note, this doesn't generate a C-level symbol.  It generates a
2616# automake-level symbol (BUILD_FMA_TESTS), used in test Makefile.am's
2617AC_MSG_CHECKING([if x86/amd64 assembler speaks FMA])
2618
2619AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
2620  do { unsigned int h, l;
2621   __asm__ __volatile__(
2622      "vfmadd132ps (%%rsp), %%ymm8, %%ymm7" : : : "xmm7", "xmm8" );
2623   __asm__ __volatile__(
2624      "vfnmsub231sd (%%rsp), %%xmm8, %%xmm7" : : : "xmm7", "xmm8" );
2625   __asm__ __volatile__(
2626      "vfmsubadd213pd (%%rsp), %%xmm8, %%xmm7" : : : "xmm7", "xmm8" ); }
2627  while (0)
2628]])], [
2629ac_have_as_fma=yes
2630AC_MSG_RESULT([yes])
2631], [
2632ac_have_as_fma=no
2633AC_MSG_RESULT([no])
2634])
2635
2636AM_CONDITIONAL(BUILD_FMA_TESTS, test x$ac_have_as_fma = xyes)
2637
2638
2639# does the amd64 assembler understand MPX instructions?
2640# Note, this doesn't generate a C-level symbol.  It generates a
2641# automake-level symbol (BUILD_MPX_TESTS), used in test Makefile.am's
2642AC_MSG_CHECKING([if amd64 assembler knows the MPX instructions])
2643
2644AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
2645  do {
2646    asm ("bndmov %bnd0,(%rsp)");
2647    asm ("bndldx 3(%rbx,%rdx), %bnd2");
2648    asm ("bnd call foo\n"
2649          bnd jmp  end\n"
2650          foo: bnd ret\n"
2651          end: nop");
2652  } while (0)
2653]])], [
2654ac_have_as_mpx=yes
2655AC_MSG_RESULT([yes])
2656], [
2657ac_have_as_mpx=no
2658AC_MSG_RESULT([no])
2659])
2660
2661AM_CONDITIONAL(BUILD_MPX_TESTS, test x$ac_have_as_mpx = xyes)
2662
2663
2664# does the amd64 assembler understand ADX instructions?
2665# Note, this doesn't generate a C-level symbol.  It generates a
2666# automake-level symbol (BUILD_ADX_TESTS), used in test Makefile.am's
2667AC_MSG_CHECKING([if amd64 assembler knows the ADX instructions])
2668
2669AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
2670  do {
2671    asm ("adcxq %r14,%r8");
2672  } while (0)
2673]])], [
2674ac_have_as_adx=yes
2675AC_MSG_RESULT([yes])
2676], [
2677ac_have_as_adx=no
2678AC_MSG_RESULT([no])
2679])
2680
2681AM_CONDITIONAL(BUILD_ADX_TESTS, test x$ac_have_as_adx = xyes)
2682
2683
2684# Does the C compiler support the "ifunc" attribute
2685# Note, this doesn't generate a C-level symbol.  It generates a
2686# automake-level symbol (BUILD_IFUNC_TESTS), used in test Makefile.am's
2687# does the x86/amd64 assembler understand MOVBE?
2688# Note, this doesn't generate a C-level symbol.  It generates a
2689# automake-level symbol (BUILD_MOVBE_TESTS), used in test Makefile.am's
2690AC_MSG_CHECKING([if x86/amd64 assembler knows the MOVBE insn])
2691
2692AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
2693  do { long long int x;
2694   __asm__ __volatile__(
2695      "movbe (%%rsp), %%r15" : : : "memory", "r15" ); }
2696  while (0)
2697]])], [
2698ac_have_as_movbe=yes
2699AC_MSG_RESULT([yes])
2700], [
2701ac_have_as_movbe=no
2702AC_MSG_RESULT([no])
2703])
2704
2705AM_CONDITIONAL(BUILD_MOVBE_TESTS, test x$ac_have_as_movbe = xyes)
2706
2707
2708# Does the C compiler support the "ifunc" attribute
2709# Note, this doesn't generate a C-level symbol.  It generates a
2710# automake-level symbol (BUILD_IFUNC_TESTS), used in test Makefile.am's
2711AC_MSG_CHECKING([if gcc supports the ifunc attribute])
2712
2713AC_LINK_IFELSE([AC_LANG_SOURCE([[
2714static void mytest(void) {}
2715
2716static void (*resolve_test(void))(void)
2717{
2718    return (void (*)(void))&mytest;
2719}
2720
2721void test(void) __attribute__((ifunc("resolve_test")));
2722
2723int main()
2724{
2725    test();
2726    return 0;
2727}
2728]])], [
2729ac_have_ifunc_attr=yes
2730AC_MSG_RESULT([yes])
2731], [
2732ac_have_ifunc_attr=no
2733AC_MSG_RESULT([no])
2734])
2735
2736AM_CONDITIONAL(BUILD_IFUNC_TESTS, test x$ac_have_ifunc_attr = xyes)
2737
2738# Does the C compiler support the armv8 crc feature flag
2739# Note, this doesn't generate a C-level symbol.  It generates a
2740# automake-level symbol (BUILD_ARMV8_CRC_TESTS), used in test Makefile.am's
2741AC_MSG_CHECKING([if gcc supports the armv8 crc feature flag])
2742
2743save_CFLAGS="$CFLAGS"
2744CFLAGS="$CFLAGS -march=armv8-a+crc -Werror"
2745AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
2746int main()
2747{
2748    return 0;
2749}
2750]])], [
2751ac_have_armv8_crc_feature=yes
2752AC_MSG_RESULT([yes])
2753], [
2754ac_have_armv8_crc_feature=no
2755AC_MSG_RESULT([no])
2756])
2757CFLAGS="$save_CFLAGS"
2758
2759AM_CONDITIONAL(BUILD_ARMV8_CRC_TESTS, test x$ac_have_armv8_crc_feature = xyes)
2760
2761
2762# XXX JRS 2010 Oct 13: what is this for?  For sure, we don't need this
2763# when building the tool executables.  I think we should get rid of it.
2764#
2765# Check for TLS support in the compiler and linker
2766AC_LINK_IFELSE([AC_LANG_PROGRAM([[static __thread int foo;]],
2767                                [[return foo;]])],
2768                               [vg_cv_linktime_tls=yes],
2769                               [vg_cv_linktime_tls=no])
2770# Native compilation: check whether running a program using TLS succeeds.
2771# Linking only is not sufficient -- e.g. on Red Hat 7.3 linking TLS programs
2772# succeeds but running programs using TLS fails.
2773# Cross-compiling: check whether linking a program using TLS succeeds.
2774AC_CACHE_CHECK([for TLS support], vg_cv_tls,
2775	       [AC_ARG_ENABLE(tls, [  --enable-tls            platform supports TLS],
2776		[vg_cv_tls=$enableval],
2777               	[AC_RUN_IFELSE([AC_LANG_PROGRAM([[static __thread int foo;]],
2778                                                [[return foo;]])],
2779                               [vg_cv_tls=yes],
2780                               [vg_cv_tls=no],
2781                               [vg_cv_tls=$vg_cv_linktime_tls])])])
2782
2783if test "$vg_cv_tls" = yes -a $is_clang != applellvm; then
2784AC_DEFINE([HAVE_TLS], 1, [can use __thread to define thread-local variables])
2785fi
2786
2787
2788#----------------------------------------------------------------------------
2789# Solaris-specific checks.
2790#----------------------------------------------------------------------------
2791
2792if test "$VGCONF_OS" = "solaris" ; then
2793AC_CHECK_HEADERS([sys/lgrp_user_impl.h])
2794
2795# Solaris-specific check determining if the Sun Studio Assembler is used to
2796# build Valgrind.  The test checks if the x86/amd64 assembler understands the
2797# cmovl.l instruction, if yes then it's Sun Assembler.
2798#
2799# C-level symbol: none
2800# Automake-level symbol: SOLARIS_SUN_STUDIO_AS
2801#
2802AC_MSG_CHECKING([if x86/amd64 assembler speaks cmovl.l (Solaris-specific)])
2803AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
2804]], [[
2805  __asm__ __volatile__("cmovl.l %edx, %eax");
2806]])], [
2807solaris_have_sun_studio_as=yes
2808AC_MSG_RESULT([yes])
2809], [
2810solaris_have_sun_studio_as=no
2811AC_MSG_RESULT([no])
2812])
2813AM_CONDITIONAL(SOLARIS_SUN_STUDIO_AS, test x$solaris_have_sun_studio_as = xyes)
2814
2815# Solaris-specific check determining if symbols __xpg4 and __xpg6
2816# are present in linked shared libraries when gcc is invoked with -std=gnu99.
2817# See solaris/vgpreload-solaris.mapfile for details.
2818# gcc on older Solaris instructs linker to include these symbols,
2819# gcc on illumos and newer Solaris does not.
2820#
2821# C-level symbol: none
2822# Automake-level symbol: SOLARIS_XPG_SYMBOLS_PRESENT
2823#
2824save_CFLAGS="$CFLAGS"
2825CFLAGS="$CFLAGS -std=gnu99"
2826AC_MSG_CHECKING([if xpg symbols are present with -std=gnu99 (Solaris-specific)])
2827temp_dir=$( /usr/bin/mktemp -d )
2828cat <<_ACEOF >${temp_dir}/mylib.c
2829#include <stdio.h>
2830int myfunc(void) { printf("LaPutyka\n"); }
2831_ACEOF
2832${CC} ${CFLAGS} -fpic -shared -o ${temp_dir}/mylib.so ${temp_dir}/mylib.c
2833xpg_present=$( /usr/bin/nm ${temp_dir}/mylib.so | ${EGREP} '(__xpg4|__xpg6)' )
2834if test "x${xpg_present}" = "x" ; then
2835    solaris_xpg_symbols_present=no
2836    AC_MSG_RESULT([no])
2837else
2838    solaris_xpg_symbols_present=yes
2839    AC_MSG_RESULT([yes])
2840fi
2841rm -rf ${temp_dir}
2842AM_CONDITIONAL(SOLARIS_XPG_SYMBOLS_PRESENT, test x$solaris_xpg_symbols_present = xyes)
2843CFLAGS="$save_CFLAGS"
2844
2845
2846# Solaris-specific check determining if gcc enables largefile support by
2847# default for 32-bit executables. If it does, then set SOLARIS_UNDEF_LARGESOURCE
2848# variable with gcc flags which disable it.
2849#
2850AC_MSG_CHECKING([if gcc enables largefile support for 32-bit apps (Solaris-specific)])
2851save_CFLAGS="$CFLAGS"
2852CFLAGS="$CFLAGS -m32"
2853AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
2854  return _LARGEFILE_SOURCE;
2855]])], [
2856SOLARIS_UNDEF_LARGESOURCE="-U_LARGEFILE_SOURCE -U_LARGEFILE64_SOURCE -U_FILE_OFFSET_BITS"
2857AC_MSG_RESULT([yes])
2858], [
2859SOLARIS_UNDEF_LARGESOURCE=""
2860AC_MSG_RESULT([no])
2861])
2862CFLAGS=$safe_CFLAGS
2863AC_SUBST(SOLARIS_UNDEF_LARGESOURCE)
2864
2865
2866# Solaris-specific check determining if /proc/self/cmdline
2867# or /proc/<pid>/cmdline is supported.
2868#
2869# C-level symbol: SOLARIS_PROC_CMDLINE
2870# Automake-level symbol: SOLARIS_PROC_CMDLINE
2871#
2872AC_CHECK_FILE([/proc/self/cmdline],
2873[
2874solaris_proc_cmdline=yes
2875AC_DEFINE([SOLARIS_PROC_CMDLINE], 1,
2876          [Define to 1 if you have /proc/self/cmdline.])
2877], [
2878solaris_proc_cmdline=no
2879])
2880AM_CONDITIONAL(SOLARIS_PROC_CMDLINE, test x$solaris_proc_cmdline = xyes)
2881
2882
2883# Solaris-specific check determining default platform for the Valgrind launcher.
2884# Used in case the launcher cannot select platform by looking at the client
2885# image (for example because the executable is a shell script).
2886#
2887# C-level symbol: SOLARIS_LAUNCHER_DEFAULT_PLATFORM
2888# Automake-level symbol: none
2889#
2890AC_MSG_CHECKING([for default platform of Valgrind launcher (Solaris-specific)])
2891# Get the ELF class of /bin/sh first.
2892if ! test -f /bin/sh; then
2893  AC_MSG_ERROR([Shell interpreter `/bin/sh' not found.])
2894fi
2895elf_class=$( /usr/bin/file /bin/sh | sed -n 's/.*ELF \(..\)-bit.*/\1/p' )
2896case "$elf_class" in
2897  64)
2898    default_arch="$VGCONF_ARCH_PRI";
2899    ;;
2900  32)
2901    if test "x$VGCONF_ARCH_SEC" != "x"; then
2902      default_arch="$VGCONF_ARCH_SEC"
2903    else
2904      default_arch="$VGCONF_ARCH_PRI";
2905    fi
2906    ;;
2907  *)
2908    AC_MSG_ERROR([Cannot determine ELF class of `/bin/sh'.])
2909    ;;
2910esac
2911default_platform="$default_arch-$VGCONF_OS"
2912AC_MSG_RESULT([$default_platform])
2913AC_DEFINE_UNQUOTED([SOLARIS_LAUNCHER_DEFAULT_PLATFORM], ["$default_platform"],
2914                   [Default platform for Valgrind launcher.])
2915
2916
2917# Solaris-specific check determining if the old syscalls are available.
2918#
2919# C-level symbol: SOLARIS_OLD_SYSCALLS
2920# Automake-level symbol: SOLARIS_OLD_SYSCALLS
2921#
2922AC_MSG_CHECKING([for the old Solaris syscalls (Solaris-specific)])
2923AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
2924#include <sys/syscall.h>
2925]], [[
2926  return !SYS_open;
2927]])], [
2928solaris_old_syscalls=yes
2929AC_MSG_RESULT([yes])
2930AC_DEFINE([SOLARIS_OLD_SYSCALLS], 1,
2931          [Define to 1 if you have the old Solaris syscalls.])
2932], [
2933solaris_old_syscalls=no
2934AC_MSG_RESULT([no])
2935])
2936AM_CONDITIONAL(SOLARIS_OLD_SYSCALLS, test x$solaris_old_syscalls = xyes)
2937
2938
2939# Solaris-specific check determining if the new accept() syscall is available.
2940#
2941# Old syscall:
2942# int accept(int sock, struct sockaddr *name, socklen_t *namelenp,
2943#            int version);
2944#
2945# New syscall (available on illumos):
2946# int accept(int sock, struct sockaddr *name, socklen_t *namelenp,
2947#            int version, int flags);
2948#
2949# If the old syscall is present then the following syscall will fail with
2950# ENOTSOCK (because file descriptor 0 is not a socket), if the new syscall is
2951# available then it will fail with EINVAL (because the flags parameter is
2952# invalid).
2953#
2954# C-level symbol: SOLARIS_NEW_ACCEPT_SYSCALL
2955# Automake-level symbol: none
2956#
2957AC_MSG_CHECKING([for the new `accept' syscall (Solaris-specific)])
2958AC_RUN_IFELSE([AC_LANG_PROGRAM([[
2959#include <sys/syscall.h>
2960#include <errno.h>
2961]], [[
2962  errno = 0;
2963  syscall(SYS_accept, 0, 0, 0, 0, -1);
2964  return !(errno == EINVAL);
2965]])], [
2966AC_MSG_RESULT([yes])
2967AC_DEFINE([SOLARIS_NEW_ACCEPT_SYSCALL], 1,
2968          [Define to 1 if you have the new `accept' syscall.])
2969], [
2970AC_MSG_RESULT([no])
2971])
2972
2973
2974# Solaris-specific check determining if the new illumos pipe() syscall is
2975# available.
2976#
2977# Old syscall:
2978# longlong_t pipe();
2979#
2980# New syscall (available on illumos):
2981# int pipe(intptr_t arg, int flags);
2982#
2983# If the old syscall is present then the following call will succeed, if the
2984# new syscall is available then it will fail with EFAULT (because address 0
2985# cannot be accessed).
2986#
2987# C-level symbol: SOLARIS_NEW_PIPE_SYSCALL
2988# Automake-level symbol: none
2989#
2990AC_MSG_CHECKING([for the new `pipe' syscall (Solaris-specific)])
2991AC_RUN_IFELSE([AC_LANG_PROGRAM([[
2992#include <sys/syscall.h>
2993#include <errno.h>
2994]], [[
2995  errno = 0;
2996  syscall(SYS_pipe, 0, 0);
2997  return !(errno == EFAULT);
2998]])], [
2999AC_MSG_RESULT([yes])
3000AC_DEFINE([SOLARIS_NEW_PIPE_SYSCALL], 1,
3001          [Define to 1 if you have the new `pipe' syscall.])
3002], [
3003AC_MSG_RESULT([no])
3004])
3005
3006
3007# Solaris-specific check determining if the new lwp_sigqueue() syscall is
3008# available.
3009#
3010# Old syscall:
3011# int lwp_kill(id_t lwpid, int sig);
3012#
3013# New syscall (available on Solaris 11):
3014# int lwp_sigqueue(id_t lwpid, int sig, void *value,
3015#                  int si_code, timespec_t *timeout);
3016#
3017# C-level symbol: SOLARIS_LWP_SIGQUEUE_SYSCALL
3018# Automake-level symbol: SOLARIS_LWP_SIGQUEUE_SYSCALL
3019#
3020AC_MSG_CHECKING([for the new `lwp_sigqueue' syscall (Solaris-specific)])
3021AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
3022#include <sys/syscall.h>
3023]], [[
3024  return !SYS_lwp_sigqueue;
3025]])], [
3026solaris_lwp_sigqueue_syscall=yes
3027AC_MSG_RESULT([yes])
3028AC_DEFINE([SOLARIS_LWP_SIGQUEUE_SYSCALL], 1,
3029          [Define to 1 if you have the new `lwp_sigqueue' syscall.])
3030], [
3031solaris_lwp_sigqueue_syscall=no
3032AC_MSG_RESULT([no])
3033])
3034AM_CONDITIONAL(SOLARIS_LWP_SIGQUEUE_SYSCALL, test x$solaris_lwp_sigqueue_syscall = xyes)
3035
3036
3037# Solaris-specific check determining if the lwp_sigqueue() syscall
3038# takes both pid and thread id arguments or just thread id.
3039#
3040# Old syscall (available on Solaris 11.x):
3041# int lwp_sigqueue(id_t lwpid, int sig, void *value,
3042#                  int si_code, timespec_t *timeout);
3043#
3044# New syscall (available on Solaris 12):
3045# int lwp_sigqueue(pid_t pid, id_t lwpid, int sig, void *value,
3046#                  int si_code, timespec_t *timeout);
3047#
3048# If the old syscall is present then the following syscall will fail with
3049# EINVAL (because signal is out of range); if the new syscall is available
3050# then it will fail with ESRCH (because it would not find such thread in the
3051# current process).
3052#
3053# C-level symbol: SOLARIS_LWP_SIGQUEUE_SYSCALL_TAKES_PID
3054# Automake-level symbol: SOLARIS_LWP_SIGQUEUE_SYSCALL_TAKES_PID
3055#
3056AM_COND_IF(SOLARIS_LWP_SIGQUEUE_SYSCALL,
3057AC_MSG_CHECKING([if the `lwp_sigqueue' syscall accepts pid (Solaris-specific)])
3058AC_RUN_IFELSE([AC_LANG_PROGRAM([[
3059#include <sys/syscall.h>
3060#include <errno.h>
3061]], [[
3062  errno = 0;
3063  syscall(SYS_lwp_sigqueue, 0, 101, 0, 0, 0, 0);
3064  return !(errno == ESRCH);
3065]])], [
3066solaris_lwp_sigqueue_syscall_takes_pid=yes
3067AC_MSG_RESULT([yes])
3068AC_DEFINE([SOLARIS_LWP_SIGQUEUE_SYSCALL_TAKES_PID], 1,
3069          [Define to 1 if you have the new `lwp_sigqueue' syscall which accepts pid.])
3070], [
3071solaris_lwp_sigqueue_syscall_takes_pid=no
3072AC_MSG_RESULT([no])
3073])
3074AM_CONDITIONAL(SOLARIS_LWP_SIGQUEUE_SYSCALL_TAKES_PID,
3075               test x$solaris_lwp_sigqueue_syscall_takes_pid = xyes)
3076,
3077AM_CONDITIONAL(SOLARIS_LWP_SIGQUEUE_SYSCALL_TAKES_PID, test x = y)
3078)
3079
3080
3081# Solaris-specific check determining if the new lwp_name() syscall is
3082# available.
3083#
3084# New syscall (available on Solaris 11):
3085# int lwp_name(int opcode, id_t lwpid, char *name, size_t len);
3086#
3087# C-level symbol: SOLARIS_LWP_NAME_SYSCALL
3088# Automake-level symbol: SOLARIS_LWP_NAME_SYSCALL
3089#
3090AC_MSG_CHECKING([for the new `lwp_name' syscall (Solaris-specific)])
3091AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
3092#include <sys/syscall.h>
3093]], [[
3094  return !SYS_lwp_name;
3095]])], [
3096solaris_lwp_name_syscall=yes
3097AC_MSG_RESULT([yes])
3098AC_DEFINE([SOLARIS_LWP_NAME_SYSCALL], 1,
3099          [Define to 1 if you have the new `lwp_name' syscall.])
3100], [
3101solaris_lwp_name_syscall=no
3102AC_MSG_RESULT([no])
3103])
3104AM_CONDITIONAL(SOLARIS_LWP_NAME_SYSCALL, test x$solaris_lwp_name_syscall = xyes)
3105
3106
3107# Solaris-specific check determining if the new getrandom() syscall is
3108# available.
3109#
3110# New syscall (available on Solaris 11):
3111# int getrandom(void *buf, size_t buflen, uint_t flags);
3112#
3113# C-level symbol: SOLARIS_GETRANDOM_SYSCALL
3114# Automake-level symbol: SOLARIS_GETRANDOM_SYSCALL
3115#
3116AC_MSG_CHECKING([for the new `getrandom' syscall (Solaris-specific)])
3117AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
3118#include <sys/syscall.h>
3119]], [[
3120  return !SYS_getrandom;
3121]])], [
3122solaris_getrandom_syscall=yes
3123AC_MSG_RESULT([yes])
3124AC_DEFINE([SOLARIS_GETRANDOM_SYSCALL], 1,
3125          [Define to 1 if you have the new `getrandom' syscall.])
3126], [
3127solaris_getrandom_syscall=no
3128AC_MSG_RESULT([no])
3129])
3130AM_CONDITIONAL(SOLARIS_GETRANDOM_SYSCALL, test x$solaris_getrandom_syscall = xyes)
3131
3132
3133# Solaris-specific check determining if the new zone() syscall subcodes
3134# ZONE_LIST_DEFUNCT and ZONE_GETATTR_DEFUNCT are available.  These subcodes
3135# were added in Solaris 11 but are missing on illumos.
3136#
3137# C-level symbol: SOLARIS_ZONE_DEFUNCT
3138# Automake-level symbol: SOLARIS_ZONE_DEFUNCT
3139#
3140AC_MSG_CHECKING([for ZONE_LIST_DEFUNCT and ZONE_GETATTR_DEFUNCT (Solaris-specific)])
3141AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
3142#include <sys/zone.h>
3143]], [[
3144  return !(ZONE_LIST_DEFUNCT && ZONE_GETATTR_DEFUNCT);
3145]])], [
3146solaris_zone_defunct=yes
3147AC_MSG_RESULT([yes])
3148AC_DEFINE([SOLARIS_ZONE_DEFUNCT], 1,
3149          [Define to 1 if you have the `ZONE_LIST_DEFUNCT' and `ZONE_GETATTR_DEFUNC' constants.])
3150], [
3151solaris_zone_defunct=no
3152AC_MSG_RESULT([no])
3153])
3154AM_CONDITIONAL(SOLARIS_ZONE_DEFUNCT, test x$solaris_zone_defunct = xyes)
3155
3156
3157# Solaris-specific check determining if commands A_GETSTAT and A_SETSTAT
3158# for auditon(2) subcode of the auditsys() syscall are available.
3159# These commands are available in Solaris 11 and illumos but were removed
3160# in Solaris 12.
3161#
3162# C-level symbol: SOLARIS_AUDITON_STAT
3163# Automake-level symbol: SOLARIS_AUDITON_STAT
3164#
3165AC_MSG_CHECKING([for A_GETSTAT and A_SETSTAT auditon(2) commands (Solaris-specific)])
3166AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
3167#include <bsm/audit.h>
3168]], [[
3169  return !(A_GETSTAT && A_SETSTAT);
3170]])], [
3171solaris_auditon_stat=yes
3172AC_MSG_RESULT([yes])
3173AC_DEFINE([SOLARIS_AUDITON_STAT], 1,
3174          [Define to 1 if you have the `A_GETSTAT' and `A_SETSTAT' constants.])
3175], [
3176solaris_auditon_stat=no
3177AC_MSG_RESULT([no])
3178])
3179AM_CONDITIONAL(SOLARIS_AUDITON_STAT, test x$solaris_auditon_stat = xyes)
3180
3181
3182# Solaris-specific check determining if the new shmsys() syscall subcodes
3183# IPC_XSTAT64, SHMADV, SHM_ADV_GET, SHM_ADV_SET and SHMGET_OSM are available.
3184# These subcodes were added in Solaris 11 but are missing on illumos.
3185#
3186# C-level symbol: SOLARIS_SHM_NEW
3187# Automake-level symbol: SOLARIS_SHM_NEW
3188#
3189AC_MSG_CHECKING([for SHMADV, SHM_ADV_GET, SHM_ADV_SET and SHMGET_OSM (Solaris-specific)])
3190AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
3191#include <sys/ipc_impl.h>
3192#include <sys/shm.h>
3193#include <sys/shm_impl.h>
3194]], [[
3195  return !(IPC_XSTAT64 && SHMADV && SHM_ADV_GET && SHM_ADV_SET && SHMGET_OSM);
3196]])], [
3197solaris_shm_new=yes
3198AC_MSG_RESULT([yes])
3199AC_DEFINE([SOLARIS_SHM_NEW], 1,
3200          [Define to 1 if you have the `IPC_XSTAT64', `SHMADV', `SHM_ADV_GET', `SHM_ADV_SET' and `SHMGET_OSM' constants.])
3201], [
3202solaris_shm_new=no
3203AC_MSG_RESULT([no])
3204])
3205AM_CONDITIONAL(SOLARIS_SHM_NEW, test x$solaris_shm_new = xyes)
3206
3207
3208# Solaris-specific check determining if prxregset_t is available.  Illumos
3209# currently does not define it on the x86 platform.
3210#
3211# C-level symbol: SOLARIS_PRXREGSET_T
3212# Automake-level symbol: SOLARIS_PRXREGSET_T
3213#
3214AC_MSG_CHECKING([for the `prxregset_t' type (Solaris-specific)])
3215AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
3216#include <sys/procfs_isa.h>
3217]], [[
3218  return !sizeof(prxregset_t);
3219]])], [
3220solaris_prxregset_t=yes
3221AC_MSG_RESULT([yes])
3222AC_DEFINE([SOLARIS_PRXREGSET_T], 1,
3223          [Define to 1 if you have the `prxregset_t' type.])
3224], [
3225solaris_prxregset_t=no
3226AC_MSG_RESULT([no])
3227])
3228AM_CONDITIONAL(SOLARIS_PRXREGSET_T, test x$solaris_prxregset_t = xyes)
3229
3230
3231# Solaris-specific check determining if the new frealpathat() syscall is
3232# available.
3233#
3234# New syscall (available on Solaris 11.1):
3235# int frealpathat(int fd, char *path, char *buf, size_t buflen);
3236#
3237# C-level symbol: SOLARIS_FREALPATHAT_SYSCALL
3238# Automake-level symbol: SOLARIS_FREALPATHAT_SYSCALL
3239#
3240AC_MSG_CHECKING([for the new `frealpathat' syscall (Solaris-specific)])
3241AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
3242#include <sys/syscall.h>
3243]], [[
3244  return !SYS_frealpathat;
3245]])], [
3246solaris_frealpathat_syscall=yes
3247AC_MSG_RESULT([yes])
3248AC_DEFINE([SOLARIS_FREALPATHAT_SYSCALL], 1,
3249          [Define to 1 if you have the new `frealpathat' syscall.])
3250], [
3251solaris_frealpathat_syscall=no
3252AC_MSG_RESULT([no])
3253])
3254AM_CONDITIONAL(SOLARIS_FREALPATHAT_SYSCALL, test x$solaris_frealpathat_syscall = xyes)
3255
3256
3257# Solaris-specific check determining if the new uuidsys() syscall is
3258# available.
3259#
3260# New syscall (available on newer Solaris):
3261# int uuidsys(struct uuid *uuid);
3262#
3263# C-level symbol: SOLARIS_UUIDSYS_SYSCALL
3264# Automake-level symbol: SOLARIS_UUIDSYS_SYSCALL
3265#
3266AC_MSG_CHECKING([for the new `uuidsys' syscall (Solaris-specific)])
3267AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
3268#include <sys/syscall.h>
3269]], [[
3270  return !SYS_uuidsys;
3271]])], [
3272solaris_uuidsys_syscall=yes
3273AC_MSG_RESULT([yes])
3274AC_DEFINE([SOLARIS_UUIDSYS_SYSCALL], 1,
3275          [Define to 1 if you have the new `uuidsys' syscall.])
3276], [
3277solaris_uuidsys_syscall=no
3278AC_MSG_RESULT([no])
3279])
3280AM_CONDITIONAL(SOLARIS_UUIDSYS_SYSCALL, test x$solaris_uuidsys_syscall = xyes)
3281
3282
3283# Solaris-specific check determining if the new labelsys() syscall subcode
3284# TNDB_GET_TNIP is available.  This subcode was added in Solaris 11 but is
3285# missing on illumos.
3286#
3287# C-level symbol: SOLARIS_TNDB_GET_TNIP
3288# Automake-level symbol: SOLARIS_TNDB_GET_TNIP
3289#
3290AC_MSG_CHECKING([for TNDB_GET_TNIP (Solaris-specific)])
3291AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
3292#include <sys/tsol/tndb.h>
3293]], [[
3294  return !TNDB_GET_TNIP;
3295]])], [
3296solaris_tndb_get_tnip=yes
3297AC_MSG_RESULT([yes])
3298AC_DEFINE([SOLARIS_TNDB_GET_TNIP], 1,
3299          [Define to 1 if you have the `TNDB_GET_TNIP' constant.])
3300], [
3301solaris_tndb_get_tnip=no
3302AC_MSG_RESULT([no])
3303])
3304AM_CONDITIONAL(SOLARIS_TNDB_GET_TNIP, test x$solaris_tndb_get_tnip = xyes)
3305
3306
3307# Solaris-specific check determining if the new labelsys() syscall opcodes
3308# TSOL_GETCLEARANCE and TSOL_SETCLEARANCE are available. These opcodes were
3309# added in Solaris 11 but are missing on illumos.
3310#
3311# C-level symbol: SOLARIS_TSOL_CLEARANCE
3312# Automake-level symbol: SOLARIS_TSOL_CLEARANCE
3313#
3314AC_MSG_CHECKING([for TSOL_GETCLEARANCE and TSOL_SETCLEARANCE (Solaris-specific)])
3315AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
3316#include <sys/tsol/tsyscall.h>
3317]], [[
3318  return !(TSOL_GETCLEARANCE && TSOL_SETCLEARANCE);
3319]])], [
3320solaris_tsol_clearance=yes
3321AC_MSG_RESULT([yes])
3322AC_DEFINE([SOLARIS_TSOL_CLEARANCE], 1,
3323          [Define to 1 if you have the `TSOL_GETCLEARANCE' and `TSOL_SETCLEARANCE' constants.])
3324], [
3325solaris_tsol_clearance=no
3326AC_MSG_RESULT([no])
3327])
3328AM_CONDITIONAL(SOLARIS_TSOL_CLEARANCE, test x$solaris_tsol_clearance = xyes)
3329
3330
3331# Solaris-specific check determining if the new pset() syscall subcode
3332# PSET_GET_NAME is available. This subcode was added in Solaris 12 but
3333# is missing on illumos and Solaris 11.
3334#
3335# C-level symbol: SOLARIS_PSET_GET_NAME
3336# Automake-level symbol: SOLARIS_PSET_GET_NAME
3337#
3338AC_MSG_CHECKING([for PSET_GET_NAME (Solaris-specific)])
3339AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
3340#include <sys/pset.h>
3341]], [[
3342  return !(PSET_GET_NAME);
3343]])], [
3344solaris_pset_get_name=yes
3345AC_MSG_RESULT([yes])
3346AC_DEFINE([SOLARIS_PSET_GET_NAME], 1,
3347          [Define to 1 if you have the `PSET_GET_NAME' constants.])
3348], [
3349solaris_pset_get_name=no
3350AC_MSG_RESULT([no])
3351])
3352AM_CONDITIONAL(SOLARIS_PSET_GET_NAME, test x$solaris_pset_get_name = xyes)
3353
3354
3355# Solaris-specific check determining if the utimesys() syscall is
3356# available (on illumos and older Solaris).
3357#
3358# C-level symbol: SOLARIS_UTIMESYS_SYSCALL
3359# Automake-level symbol: SOLARIS_UTIMESYS_SYSCALL
3360#
3361AC_MSG_CHECKING([for the `utimesys' syscall (Solaris-specific)])
3362AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
3363#include <sys/syscall.h>
3364]], [[
3365  return !SYS_utimesys;
3366]])], [
3367solaris_utimesys_syscall=yes
3368AC_MSG_RESULT([yes])
3369AC_DEFINE([SOLARIS_UTIMESYS_SYSCALL], 1,
3370          [Define to 1 if you have the `utimesys' syscall.])
3371], [
3372solaris_utimesys_syscall=no
3373AC_MSG_RESULT([no])
3374])
3375AM_CONDITIONAL(SOLARIS_UTIMESYS_SYSCALL, test x$solaris_utimesys_syscall = xyes)
3376
3377
3378# Solaris-specific check determining if the utimensat() syscall is
3379# available (on newer Solaris).
3380#
3381# C-level symbol: SOLARIS_UTIMENSAT_SYSCALL
3382# Automake-level symbol: SOLARIS_UTIMENSAT_SYSCALL
3383#
3384AC_MSG_CHECKING([for the `utimensat' syscall (Solaris-specific)])
3385AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
3386#include <sys/syscall.h>
3387]], [[
3388  return !SYS_utimensat;
3389]])], [
3390solaris_utimensat_syscall=yes
3391AC_MSG_RESULT([yes])
3392AC_DEFINE([SOLARIS_UTIMENSAT_SYSCALL], 1,
3393          [Define to 1 if you have the `utimensat' syscall.])
3394], [
3395solaris_utimensat_syscall=no
3396AC_MSG_RESULT([no])
3397])
3398AM_CONDITIONAL(SOLARIS_UTIMENSAT_SYSCALL, test x$solaris_utimensat_syscall = xyes)
3399
3400
3401# Solaris-specific check determining if the spawn() syscall is available
3402# (on newer Solaris).
3403#
3404# C-level symbol: SOLARIS_SPAWN_SYSCALL
3405# Automake-level symbol: SOLARIS_SPAWN_SYSCALL
3406#
3407AC_MSG_CHECKING([for the `spawn' syscall (Solaris-specific)])
3408AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
3409#include <sys/syscall.h>
3410]], [[
3411  return !SYS_spawn;
3412]])], [
3413solaris_spawn_syscall=yes
3414AC_MSG_RESULT([yes])
3415AC_DEFINE([SOLARIS_SPAWN_SYSCALL], 1,
3416          [Define to 1 if you have the `spawn' syscall.])
3417], [
3418solaris_spawn_syscall=no
3419AC_MSG_RESULT([no])
3420])
3421AM_CONDITIONAL(SOLARIS_SPAWN_SYSCALL, test x$solaris_spawn_syscall = xyes)
3422
3423
3424# Solaris-specific check determining if commands MODNVL_CTRLMAP through
3425# MODDEVINFO_CACHE_TS for modctl() syscall are available (on newer Solaris).
3426#
3427# C-level symbol: SOLARIS_MODCTL_MODNVL
3428# Automake-level symbol: SOLARIS_MODCTL_MODNVL
3429#
3430AC_MSG_CHECKING([for MODNVL_CTRLMAP through MODDEVINFO_CACHE_TS modctl(2) commands (Solaris-specific)])
3431AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
3432#include <sys/modctl.h>
3433]], [[
3434  return !(MODNVL_CTRLMAP && MODDEVINFO_CACHE_TS);
3435]])], [
3436solaris_modctl_modnvl=yes
3437AC_MSG_RESULT([yes])
3438AC_DEFINE([SOLARIS_MODCTL_MODNVL], 1,
3439          [Define to 1 if you have the `MODNVL_CTRLMAP' through `MODDEVINFO_CACHE_TS' constants.])
3440], [
3441solaris_modctl_modnvl=no
3442AC_MSG_RESULT([no])
3443])
3444AM_CONDITIONAL(SOLARIS_MODCTL_MODNVL, test x$solaris_modctl_modnvl = xyes)
3445
3446
3447# Solaris-specific check determining whether nscd (name switch cache daemon)
3448# attaches its door at /system/volatile/name_service_door (Solaris)
3449# or at /var/run/name_service_door (illumos).
3450#
3451# Note that /var/run is a symlink to /system/volatile on Solaris
3452# but not vice versa on illumos.
3453#
3454# C-level symbol: SOLARIS_NSCD_DOOR_SYSTEM_VOLATILE
3455# Automake-level symbol: SOLARIS_NSCD_DOOR_SYSTEM_VOLATILE
3456#
3457AC_MSG_CHECKING([for nscd door location (Solaris-specific)])
3458if test -e /system/volatile/name_service_door; then
3459    solaris_nscd_door_system_volatile=yes
3460    AC_MSG_RESULT([/system/volatile/name_service_door])
3461    AC_DEFINE([SOLARIS_NSCD_DOOR_SYSTEM_VOLATILE], 1,
3462              [Define to 1 if nscd attaches to /system/volatile/name_service_door.])
3463else
3464    solaris_nscd_door_system_volatile=no
3465    AC_MSG_RESULT([/var/run/name_service_door])
3466fi
3467AM_CONDITIONAL(SOLARIS_NSCD_DOOR_SYSTEM_VOLATILE, test x$solaris_nscd_door_system_volatile = xyes)
3468
3469
3470# Solaris-specific check determining if the new gethrt() fasttrap is available.
3471#
3472# New fasttrap (available on Solaris 11):
3473# hrt_t *gethrt(void);
3474#
3475# C-level symbol: SOLARIS_GETHRT_FASTTRAP
3476# Automake-level symbol: SOLARIS_GETHRT_FASTTRAP
3477#
3478AC_MSG_CHECKING([for the new `gethrt' fasttrap (Solaris-specific)])
3479AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
3480#include <sys/trap.h>
3481]], [[
3482  return !T_GETHRT;
3483]])], [
3484solaris_gethrt_fasttrap=yes
3485AC_MSG_RESULT([yes])
3486AC_DEFINE([SOLARIS_GETHRT_FASTTRAP], 1,
3487          [Define to 1 if you have the new `gethrt' fasttrap.])
3488], [
3489solaris_gethrt_fasttrap=no
3490AC_MSG_RESULT([no])
3491])
3492AM_CONDITIONAL(SOLARIS_GETHRT_FASTTRAP, test x$solaris_gethrt_fasttrap = xyes)
3493
3494
3495# Solaris-specific check determining if the new get_zone_offset() fasttrap
3496# is available.
3497#
3498# New fasttrap (available on Solaris 11):
3499# zonehrtoffset_t *get_zone_offset(void);
3500#
3501# C-level symbol: SOLARIS_GETZONEOFFSET_FASTTRAP
3502# Automake-level symbol: SOLARIS_GETZONEOFFSET_FASTTRAP
3503#
3504AC_MSG_CHECKING([for the new `get_zone_offset' fasttrap (Solaris-specific)])
3505AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
3506#include <sys/trap.h>
3507]], [[
3508  return !T_GETZONEOFFSET;
3509]])], [
3510solaris_getzoneoffset_fasttrap=yes
3511AC_MSG_RESULT([yes])
3512AC_DEFINE([SOLARIS_GETZONEOFFSET_FASTTRAP], 1,
3513          [Define to 1 if you have the new `get_zone_offset' fasttrap.])
3514], [
3515solaris_getzoneoffset_fasttrap=no
3516AC_MSG_RESULT([no])
3517])
3518AM_CONDITIONAL(SOLARIS_GETZONEOFFSET_FASTTRAP, test x$solaris_getzoneoffset_fasttrap = xyes)
3519
3520
3521# Solaris-specific check determining if the execve() syscall
3522# takes fourth argument (flags) or not.
3523#
3524# Old syscall (available on illumos):
3525# int execve(const char *fname, const char **argv, const char **envp);
3526#
3527# New syscall (available on Solaris):
3528# int execve(uintptr_t file, const char **argv, const char **envp, int flags);
3529#
3530# If the new syscall is present then it will fail with EINVAL (because flags
3531# are invalid); if the old syscall is available then it will fail with ENOENT
3532# (because the file could not be found).
3533#
3534# C-level symbol: SOLARIS_EXECVE_SYSCALL_TAKES_FLAGS
3535# Automake-level symbol: SOLARIS_EXECVE_SYSCALL_TAKES_FLAGS
3536#
3537AC_MSG_CHECKING([if the `execve' syscall accepts flags (Solaris-specific)])
3538AC_RUN_IFELSE([AC_LANG_PROGRAM([[
3539#include <sys/syscall.h>
3540#include <errno.h>
3541]], [[
3542  errno = 0;
3543  syscall(SYS_execve, "/no/existing/path", 0, 0, 0xdeadbeef, 0, 0);
3544  return !(errno == EINVAL);
3545]])], [
3546solaris_execve_syscall_takes_flags=yes
3547AC_MSG_RESULT([yes])
3548AC_DEFINE([SOLARIS_EXECVE_SYSCALL_TAKES_FLAGS], 1,
3549          [Define to 1 if you have the new `execve' syscall which accepts flags.])
3550], [
3551solaris_execve_syscall_takes_flags=no
3552AC_MSG_RESULT([no])
3553])
3554AM_CONDITIONAL(SOLARIS_EXECVE_SYSCALL_TAKES_FLAGS,
3555               test x$solaris_execve_syscall_takes_flags = xyes)
3556
3557
3558# Solaris-specific check determining version of the repository cache protocol.
3559# Every Solaris version uses a different one, ranging from 21 to current 25.
3560# The check is very ugly, though.
3561#
3562# C-level symbol: SOLARIS_REPCACHE_PROTOCOL_VERSION vv
3563# Automake-level symbol: none
3564#
3565AC_PATH_PROG(DIS_PATH, dis, false)
3566if test "x$DIS_PATH" = "xfalse"; then
3567  AC_MSG_FAILURE([Object code disassembler (`dis') not found.])
3568fi
3569AC_CHECK_LIB(scf, scf_handle_bind, [], [
3570  AC_MSG_WARN([Function `scf_handle_bind' was not found in `libscf'.])
3571  AC_MSG_ERROR([Cannot determine version of the repository cache protocol.])
3572])
3573
3574AC_MSG_CHECKING([for version of the repository cache protocol (Solaris-specific)])
3575if test "X$VGCONF_ARCH_PRI" = "Xamd64"; then
3576  libscf=/usr/lib/64/libscf.so.1
3577else
3578  libscf=/usr/lib/libscf.so.1
3579fi
3580if ! $DIS_PATH -F scf_handle_bind $libscf  | grep -q 0x526570; then
3581  AC_MSG_WARN([Function `scf_handle_bind' does not contain repository cache protocol version.])
3582  AC_MSG_ERROR([Cannot determine version of the repository cache protocol.])
3583fi
3584hex=$( $DIS_PATH -F scf_handle_bind $libscf  | sed -n 's/.*0x526570\(..\).*/\1/p' )
3585if test -z "$hex"; then
3586  AC_MSG_WARN([Version of the repository cache protocol is empty?!])
3587  AC_MSG_ERROR([Cannot determine version of the repository cache protocol.])
3588fi
3589version=$( printf "%d\n" 0x$hex )
3590AC_MSG_RESULT([$version])
3591AC_DEFINE_UNQUOTED([SOLARIS_REPCACHE_PROTOCOL_VERSION], [$version],
3592                   [Version number of the repository door cache protocol.])
3593
3594
3595# Solaris-specific check determining if "sysstat" segment reservation type
3596# is available.
3597#
3598# New "sysstat" segment reservation (available on Solaris 12):
3599# - program header type:    PT_SUNW_SYSSTAT
3600# - auxiliary vector entry: AT_SUN_SYSSTAT_ADDR
3601#
3602# C-level symbol: SOLARIS_RESERVE_SYSSTAT_ADDR
3603# Automake-level symbol: SOLARIS_RESERVE_SYSSTAT_ADDR
3604#
3605AC_MSG_CHECKING([for the new `sysstat' segment reservation (Solaris-specific)])
3606AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
3607#include <sys/auxv.h>
3608]], [[
3609  return !AT_SUN_SYSSTAT_ADDR;
3610]])], [
3611solaris_reserve_sysstat_addr=yes
3612AC_MSG_RESULT([yes])
3613AC_DEFINE([SOLARIS_RESERVE_SYSSTAT_ADDR], 1,
3614          [Define to 1 if you have the new `sysstat' segment reservation.])
3615], [
3616solaris_reserve_sysstat_addr=no
3617AC_MSG_RESULT([no])
3618])
3619AM_CONDITIONAL(SOLARIS_RESERVE_SYSSTAT_ADDR, test x$solaris_reserve_sysstat_addr = xyes)
3620
3621
3622# Solaris-specific check determining if "sysstat_zone" segment reservation type
3623# is available.
3624#
3625# New "sysstat_zone" segment reservation (available on Solaris 12):
3626# - program header type:    PT_SUNW_SYSSTAT_ZONE
3627# - auxiliary vector entry: AT_SUN_SYSSTAT_ZONE_ADDR
3628#
3629# C-level symbol: SOLARIS_RESERVE_SYSSTAT_ZONE_ADDR
3630# Automake-level symbol: SOLARIS_RESERVE_SYSSTAT_ZONE_ADDR
3631#
3632AC_MSG_CHECKING([for the new `sysstat_zone' segment reservation (Solaris-specific)])
3633AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
3634#include <sys/auxv.h>
3635]], [[
3636  return !AT_SUN_SYSSTAT_ZONE_ADDR;
3637]])], [
3638solaris_reserve_sysstat_zone_addr=yes
3639AC_MSG_RESULT([yes])
3640AC_DEFINE([SOLARIS_RESERVE_SYSSTAT_ZONE_ADDR], 1,
3641          [Define to 1 if you have the new `sysstat_zone' segment reservation.])
3642], [
3643solaris_reserve_sysstat_zone_addr=no
3644AC_MSG_RESULT([no])
3645])
3646AM_CONDITIONAL(SOLARIS_RESERVE_SYSSTAT_ZONE_ADDR, test x$solaris_reserve_sysstat_zone_addr = xyes)
3647
3648
3649# Solaris-specific check determining if the system_stats() syscall is available
3650# (on newer Solaris).
3651#
3652# C-level symbol: SOLARIS_SYSTEM_STATS_SYSCALL
3653# Automake-level symbol: SOLARIS_SYSTEM_STATS_SYSCALL
3654#
3655AC_MSG_CHECKING([for the `system_stats' syscall (Solaris-specific)])
3656AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
3657#include <sys/syscall.h>
3658]], [[
3659  return !SYS_system_stats;
3660]])], [
3661solaris_system_stats_syscall=yes
3662AC_MSG_RESULT([yes])
3663AC_DEFINE([SOLARIS_SYSTEM_STATS_SYSCALL], 1,
3664          [Define to 1 if you have the `system_stats' syscall.])
3665], [
3666solaris_system_stats_syscall=no
3667AC_MSG_RESULT([no])
3668])
3669AM_CONDITIONAL(SOLARIS_SYSTEM_STATS_SYSCALL, test x$solaris_system_stats_syscall = xyes)
3670
3671
3672# Solaris-specific check determining if fpregset_t defines struct _fpchip_state
3673# (on newer illumos) or struct fpchip_state (Solaris, older illumos).
3674#
3675# C-level symbol: SOLARIS_FPCHIP_STATE_TAKES_UNDERSCORE
3676# Automake-level symbol: none
3677#
3678AC_CHECK_TYPE([struct _fpchip_state],
3679              [solaris_fpchip_state_takes_underscore=yes],
3680              [solaris_fpchip_state_takes_underscore=no],
3681              [[#include <sys/regset.h>]])
3682if test "$solaris_fpchip_state_takes_underscore" = "yes"; then
3683  AC_DEFINE(SOLARIS_FPCHIP_STATE_TAKES_UNDERSCORE, 1,
3684            [Define to 1 if fpregset_t defines struct _fpchip_state])
3685fi
3686
3687
3688# Solaris-specific check determining if schedctl page shared between kernel
3689# and userspace program is executable (illumos, older Solaris) or not (newer
3690# Solaris).
3691#
3692# C-level symbol: SOLARIS_SCHEDCTL_PAGE_EXEC
3693# Automake-level symbol: none
3694#
3695AC_MSG_CHECKING([if schedctl page is executable (Solaris-specific)])
3696AC_RUN_IFELSE([AC_LANG_PROGRAM([[
3697#include <assert.h>
3698#include <fcntl.h>
3699#include <procfs.h>
3700#include <schedctl.h>
3701#include <stdio.h>
3702#include <unistd.h>
3703]], [[
3704    schedctl_t *scp = schedctl_init();
3705    if (scp == NULL)
3706        return 1;
3707
3708    int fd = open("/proc/self/map", O_RDONLY);
3709    assert(fd >= 0);
3710
3711    prmap_t map;
3712    ssize_t rd;
3713    while ((rd = read(fd, &map, sizeof(map))) == sizeof(map)) {
3714        if (map.pr_vaddr == ((uintptr_t) scp & PAGEMASK)) {
3715            fprintf(stderr, "%#lx [%zu] %s\n", map.pr_vaddr, map.pr_size,
3716                    (map.pr_mflags & MA_EXEC) ? "x" : "no-x");
3717            return (map.pr_mflags & MA_EXEC);
3718        }
3719    }
3720
3721    return 1;
3722]])], [
3723solaris_schedctl_page_exec=no
3724AC_MSG_RESULT([no])
3725], [
3726solaris_schedctl_page_exec=yes
3727AC_MSG_RESULT([yes])
3728AC_DEFINE([SOLARIS_SCHEDCTL_PAGE_EXEC], 1,
3729          [Define to 1 if you have the schedctl page executable.])
3730])
3731
3732
3733# Solaris-specific check determining if PT_SUNWDTRACE program header provides
3734# scratch space for DTrace fasttrap provider (illumos, older Solaris) or just
3735# an initial thread pointer for libc (newer Solaris).
3736#
3737# C-level symbol: SOLARIS_PT_SUNDWTRACE_THRP
3738# Automake-level symbol: none
3739#
3740AC_MSG_CHECKING([if PT_SUNWDTRACE serves for initial thread pointer (Solaris-specific)])
3741AC_RUN_IFELSE([AC_LANG_PROGRAM([[
3742#include <sys/fasttrap_isa.h>
3743]], [[
3744    return !FT_SCRATCHSIZE;
3745]])], [
3746solaris_pt_sunwdtrace_thrp=yes
3747AC_MSG_RESULT([yes])
3748AC_DEFINE([SOLARIS_PT_SUNDWTRACE_THRP], 1,
3749          [Define to 1 if PT_SUNWDTRACE program header provides just an initial thread pointer for libc.])
3750], [
3751solaris_pt_sunwdtrace_thrp=no
3752AC_MSG_RESULT([no])
3753])
3754
3755else
3756AM_CONDITIONAL(SOLARIS_SUN_STUDIO_AS, false)
3757AM_CONDITIONAL(SOLARIS_XPG_SYMBOLS_PRESENT, false)
3758AM_CONDITIONAL(SOLARIS_PROC_CMDLINE, false)
3759AM_CONDITIONAL(SOLARIS_OLD_SYSCALLS, false)
3760AM_CONDITIONAL(SOLARIS_LWP_SIGQUEUE_SYSCALL, false)
3761AM_CONDITIONAL(SOLARIS_LWP_SIGQUEUE_SYSCALL_TAKES_PID, false)
3762AM_CONDITIONAL(SOLARIS_LWP_NAME_SYSCALL, false)
3763AM_CONDITIONAL(SOLARIS_GETRANDOM_SYSCALL, false)
3764AM_CONDITIONAL(SOLARIS_ZONE_DEFUNCT, false)
3765AM_CONDITIONAL(SOLARIS_AUDITON_STAT, false)
3766AM_CONDITIONAL(SOLARIS_SHM_NEW, false)
3767AM_CONDITIONAL(SOLARIS_PRXREGSET_T, false)
3768AM_CONDITIONAL(SOLARIS_FREALPATHAT_SYSCALL, false)
3769AM_CONDITIONAL(SOLARIS_UUIDSYS_SYSCALL, false)
3770AM_CONDITIONAL(SOLARIS_TNDB_GET_TNIP, false)
3771AM_CONDITIONAL(SOLARIS_TSOL_CLEARANCE, false)
3772AM_CONDITIONAL(SOLARIS_PSET_GET_NAME, false)
3773AM_CONDITIONAL(SOLARIS_UTIMESYS_SYSCALL, false)
3774AM_CONDITIONAL(SOLARIS_UTIMENSAT_SYSCALL, false)
3775AM_CONDITIONAL(SOLARIS_SPAWN_SYSCALL, false)
3776AM_CONDITIONAL(SOLARIS_MODCTL_MODNVL, false)
3777AM_CONDITIONAL(SOLARIS_NSCD_DOOR_SYSTEM_VOLATILE, false)
3778AM_CONDITIONAL(SOLARIS_GETHRT_FASTTRAP, false)
3779AM_CONDITIONAL(SOLARIS_GETZONEOFFSET_FASTTRAP, false)
3780AM_CONDITIONAL(SOLARIS_EXECVE_SYSCALL_TAKES_FLAGS, false)
3781AM_CONDITIONAL(SOLARIS_RESERVE_SYSSTAT_ADDR, false)
3782AM_CONDITIONAL(SOLARIS_RESERVE_SYSSTAT_ZONE_ADDR, false)
3783AM_CONDITIONAL(SOLARIS_SYSTEM_STATS_SYSCALL, false)
3784fi # test "$VGCONF_OS" = "solaris"
3785
3786
3787#----------------------------------------------------------------------------
3788# Checks for C header files.
3789#----------------------------------------------------------------------------
3790
3791AC_HEADER_STDC
3792AC_CHECK_HEADERS([       \
3793        asm/unistd.h     \
3794        endian.h         \
3795        mqueue.h         \
3796        sys/endian.h     \
3797        sys/epoll.h      \
3798        sys/eventfd.h    \
3799        sys/klog.h       \
3800        sys/poll.h       \
3801        sys/prctl.h      \
3802        sys/signal.h     \
3803        sys/signalfd.h   \
3804        sys/syscall.h    \
3805        sys/sysnvl.h     \
3806        sys/time.h       \
3807        sys/types.h      \
3808        ])
3809
3810# Verify whether the <linux/futex.h> header is usable.
3811AC_MSG_CHECKING([if <linux/futex.h> is usable])
3812
3813save_CFLAGS="$CFLAGS"
3814CFLAGS="$CFLAGS -D__user="
3815AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
3816#include <linux/futex.h>
3817]], [[
3818  return FUTEX_WAIT;
3819]])], [
3820ac_have_usable_linux_futex_h=yes
3821AC_DEFINE([HAVE_USABLE_LINUX_FUTEX_H], 1,
3822          [Define to 1 if you have a usable <linux/futex.h> header file.])
3823AC_MSG_RESULT([yes])
3824], [
3825ac_have_usable_linux_futex_h=no
3826AC_MSG_RESULT([no])
3827])
3828CFLAGS="$save_CFLAGS"
3829
3830
3831#----------------------------------------------------------------------------
3832# Checks for typedefs, structures, and compiler characteristics.
3833#----------------------------------------------------------------------------
3834AC_TYPE_UID_T
3835AC_TYPE_OFF_T
3836AC_TYPE_SIZE_T
3837AC_HEADER_TIME
3838
3839
3840#----------------------------------------------------------------------------
3841# Checks for library functions.
3842#----------------------------------------------------------------------------
3843AC_FUNC_MEMCMP
3844AC_FUNC_MMAP
3845
3846AC_CHECK_LIB([pthread], [pthread_create])
3847AC_CHECK_LIB([rt], [clock_gettime])
3848
3849AC_CHECK_FUNCS([     \
3850        clock_gettime\
3851        epoll_create \
3852        epoll_pwait  \
3853        klogctl      \
3854        mallinfo     \
3855        memchr       \
3856        memset       \
3857        mkdir        \
3858        mremap       \
3859        ppoll        \
3860        pthread_barrier_init       \
3861        pthread_condattr_setclock  \
3862        pthread_mutex_timedlock    \
3863        pthread_rwlock_timedrdlock \
3864        pthread_rwlock_timedwrlock \
3865        pthread_spin_lock          \
3866        pthread_yield              \
3867        pthread_setname_np         \
3868        readlinkat   \
3869        semtimedop   \
3870        signalfd     \
3871        sigwaitinfo  \
3872        strchr       \
3873        strdup       \
3874        strpbrk      \
3875        strrchr      \
3876        strstr       \
3877        syscall      \
3878        utimensat    \
3879        process_vm_readv  \
3880        process_vm_writev \
3881        ])
3882
3883# AC_CHECK_LIB adds any library found to the variable LIBS, and links these
3884# libraries with any shared object and/or executable. This is NOT what we
3885# want for e.g. vgpreload_core-x86-linux.so
3886LIBS=""
3887
3888AM_CONDITIONAL([HAVE_PTHREAD_BARRIER],
3889               [test x$ac_cv_func_pthread_barrier_init = xyes])
3890AM_CONDITIONAL([HAVE_PTHREAD_MUTEX_TIMEDLOCK],
3891               [test x$ac_cv_func_pthread_mutex_timedlock = xyes])
3892AM_CONDITIONAL([HAVE_PTHREAD_SPINLOCK],
3893               [test x$ac_cv_func_pthread_spin_lock = xyes])
3894AM_CONDITIONAL([HAVE_PTHREAD_SETNAME_NP],
3895               [test x$ac_cv_func_pthread_setname_np = xyes])
3896
3897if test x$VGCONF_PLATFORM_PRI_CAPS = xMIPS32_LINUX \
3898     -o x$VGCONF_PLATFORM_PRI_CAPS = xMIPS64_LINUX ; then
3899  AC_DEFINE([DISABLE_PTHREAD_SPINLOCK_INTERCEPT], 1,
3900            [Disable intercept pthread_spin_lock() on MIPS32 and MIPS64.])
3901fi
3902
3903#----------------------------------------------------------------------------
3904# MPI checks
3905#----------------------------------------------------------------------------
3906# Do we have a useable MPI setup on the primary and/or secondary targets?
3907# On Linux, by default, assumes mpicc and -m32/-m64
3908# Note: this is a kludge in that it assumes the specified mpicc
3909# understands -m32/-m64 regardless of what is specified using
3910# --with-mpicc=.
3911AC_PATH_PROG([MPI_CC], [mpicc], [mpicc],
3912             [$PATH:/usr/lib/openmpi/bin:/usr/lib64/openmpi/bin])
3913
3914mflag_primary=
3915if test x$VGCONF_PLATFORM_PRI_CAPS = xX86_LINUX \
3916     -o x$VGCONF_PLATFORM_PRI_CAPS = xPPC32_LINUX \
3917     -o x$VGCONF_PLATFORM_PRI_CAPS = xARM_LINUX \
3918     -o x$VGCONF_PLATFORM_PRI_CAPS = xMIPS32_LINUX \
3919     -o x$VGCONF_PLATFORM_PRI_CAPS = xMIPS64_LINUX \
3920     -o x$VGCONF_PLATFORM_PRI_CAPS = xX86_SOLARIS ; then
3921  mflag_primary=$FLAG_M32
3922elif test x$VGCONF_PLATFORM_PRI_CAPS = xAMD64_LINUX \
3923       -o x$VGCONF_PLATFORM_PRI_CAPS = xPPC64_LINUX \
3924       -o x$VGCONF_PLATFORM_PRI_CAPS = xARM64_LINUX \
3925       -o x$VGCONF_PLATFORM_PRI_CAPS = xS390X_LINUX ; then
3926  mflag_primary=$FLAG_M64
3927elif test x$VGCONF_PLATFORM_PRI_CAPS = xX86_DARWIN ; then
3928  mflag_primary="$FLAG_M32 -arch i386"
3929elif test x$VGCONF_PLATFORM_PRI_CAPS = xAMD64_DARWIN ; then
3930  mflag_primary="$FLAG_M64 -arch x86_64"
3931fi
3932
3933mflag_secondary=
3934if test x$VGCONF_PLATFORM_SEC_CAPS = xX86_LINUX \
3935     -o x$VGCONF_PLATFORM_SEC_CAPS = xPPC32_LINUX \
3936     -o x$VGCONF_PLATFORM_SEC_CAPS = xX86_SOLARIS ; then
3937  mflag_secondary=$FLAG_M32
3938elif test x$VGCONF_PLATFORM_SEC_CAPS = xX86_DARWIN ; then
3939  mflag_secondary="$FLAG_M32 -arch i386"
3940fi
3941
3942
3943AC_ARG_WITH(mpicc,
3944   [  --with-mpicc=           Specify name of MPI2-ised C compiler],
3945   MPI_CC=$withval
3946)
3947AC_SUBST(MPI_CC)
3948
3949## We AM_COND_IF here instead of automake "if" in mpi/Makefile.am so that we can
3950## use these values in the check for a functioning mpicc.
3951##
3952## We leave the MPI_FLAG_M3264_ logic in mpi/Makefile.am and assume that
3953## mflag_primary/mflag_secondary are sufficient approximations of that behavior
3954AM_COND_IF([VGCONF_OS_IS_LINUX],
3955           [CFLAGS_MPI="-g -O -fno-omit-frame-pointer -Wall -fpic"
3956            LDFLAGS_MPI="-fpic -shared"])
3957AM_COND_IF([VGCONF_OS_IS_DARWIN],
3958           [CFLAGS_MPI="-g -O -fno-omit-frame-pointer -Wall -dynamic"
3959            LDFLAGS_MPI="-dynamic -dynamiclib -all_load"])
3960AM_COND_IF([VGCONF_OS_IS_SOLARIS],
3961           [CFLAGS_MPI="-g -O -fno-omit-frame-pointer -Wall -fpic"
3962            LDFLAGS_MPI="-fpic -shared"])
3963
3964AC_SUBST([CFLAGS_MPI])
3965AC_SUBST([LDFLAGS_MPI])
3966
3967
3968## See if MPI_CC works for the primary target
3969##
3970AC_MSG_CHECKING([primary target for usable MPI2-compliant C compiler and mpi.h])
3971saved_CC=$CC
3972saved_CFLAGS=$CFLAGS
3973CC=$MPI_CC
3974CFLAGS="$CFLAGS_MPI $mflag_primary"
3975saved_LDFLAGS="$LDFLAGS"
3976LDFLAGS="$LDFLAGS_MPI $mflag_primary"
3977AC_LINK_IFELSE([AC_LANG_PROGRAM([[
3978#include <mpi.h>
3979#include <stdio.h>
3980]], [[
3981  int ni, na, nd, comb;
3982  int r = MPI_Init(NULL,NULL);
3983  r |= MPI_Type_get_envelope( MPI_INT, &ni, &na, &nd, &comb );
3984  r |= MPI_Finalize();
3985  return r;
3986]])], [
3987ac_have_mpi2_pri=yes
3988AC_MSG_RESULT([yes, $MPI_CC])
3989], [
3990ac_have_mpi2_pri=no
3991AC_MSG_RESULT([no])
3992])
3993CC=$saved_CC
3994CFLAGS=$saved_CFLAGS
3995LDFLAGS="$saved_LDFLAGS"
3996AM_CONDITIONAL(BUILD_MPIWRAP_PRI, test x$ac_have_mpi2_pri = xyes)
3997
3998## See if MPI_CC works for the secondary target.  Complication: what if
3999## there is no secondary target?  We need this to then fail.
4000## Kludge this by making MPI_CC something which will surely fail in
4001## such a case.
4002##
4003AC_MSG_CHECKING([secondary target for usable MPI2-compliant C compiler and mpi.h])
4004saved_CC=$CC
4005saved_CFLAGS=$CFLAGS
4006saved_LDFLAGS="$LDFLAGS"
4007LDFLAGS="$LDFLAGS_MPI $mflag_secondary"
4008if test x$VGCONF_PLATFORM_SEC_CAPS = x ; then
4009  CC="$MPI_CC this will surely fail"
4010else
4011  CC=$MPI_CC
4012fi
4013CFLAGS="$CFLAGS_MPI $mflag_secondary"
4014AC_LINK_IFELSE([AC_LANG_PROGRAM([[
4015#include <mpi.h>
4016#include <stdio.h>
4017]], [[
4018  int ni, na, nd, comb;
4019  int r = MPI_Init(NULL,NULL);
4020  r |= MPI_Type_get_envelope( MPI_INT, &ni, &na, &nd, &comb );
4021  r |= MPI_Finalize();
4022  return r;
4023]])], [
4024ac_have_mpi2_sec=yes
4025AC_MSG_RESULT([yes, $MPI_CC])
4026], [
4027ac_have_mpi2_sec=no
4028AC_MSG_RESULT([no])
4029])
4030CC=$saved_CC
4031CFLAGS=$saved_CFLAGS
4032LDFLAGS="$saved_LDFLAGS"
4033AM_CONDITIONAL(BUILD_MPIWRAP_SEC, test x$ac_have_mpi2_sec = xyes)
4034
4035
4036#----------------------------------------------------------------------------
4037# Other library checks
4038#----------------------------------------------------------------------------
4039# There now follow some tests for Boost, and OpenMP.  These
4040# tests are present because Drd has some regression tests that use
4041# these packages.  All regression test programs all compiled only
4042# for the primary target.  And so it is important that the configure
4043# checks that follow, use the correct -m32 or -m64 flag for the
4044# primary target (called $mflag_primary).  Otherwise, we can end up
4045# in a situation (eg) where, on amd64-linux, the test for Boost checks
4046# for usable 64-bit Boost facilities, but because we are doing a 32-bit
4047# only build (meaning, the primary target is x86-linux), the build
4048# of the regtest programs that use Boost fails, because they are
4049# build as 32-bit (IN THIS EXAMPLE).
4050#
4051# Hence: ALWAYS USE $mflag_primary FOR CONFIGURE TESTS FOR FACILITIES
4052# NEEDED BY THE REGRESSION TEST PROGRAMS.
4053
4054
4055# Check whether the boost library 1.35 or later has been installed.
4056# The Boost.Threads library has undergone a major rewrite in version 1.35.0.
4057
4058AC_MSG_CHECKING([for boost])
4059
4060AC_LANG(C++)
4061safe_CXXFLAGS=$CXXFLAGS
4062CXXFLAGS="$mflag_primary"
4063safe_LIBS="$LIBS"
4064LIBS="-lboost_thread-mt -lboost_system-mt $LIBS"
4065
4066AC_LINK_IFELSE([AC_LANG_SOURCE([
4067#include <boost/thread.hpp>
4068static void thread_func(void)
4069{ }
4070int main(int argc, char** argv)
4071{
4072  boost::thread t(thread_func);
4073  return 0;
4074}
4075])],
4076[
4077ac_have_boost_1_35=yes
4078AC_SUBST([BOOST_CFLAGS], [])
4079AC_SUBST([BOOST_LIBS], ["-lboost_thread-mt -lboost_system-mt"])
4080AC_MSG_RESULT([yes])
4081], [
4082ac_have_boost_1_35=no
4083AC_MSG_RESULT([no])
4084])
4085
4086LIBS="$safe_LIBS"
4087CXXFLAGS=$safe_CXXFLAGS
4088AC_LANG(C)
4089
4090AM_CONDITIONAL([HAVE_BOOST_1_35], [test x$ac_have_boost_1_35 = xyes])
4091
4092
4093# does this compiler support -fopenmp, does it have the include file
4094# <omp.h> and does it have libgomp ?
4095
4096AC_MSG_CHECKING([for OpenMP])
4097
4098safe_CFLAGS=$CFLAGS
4099CFLAGS="-fopenmp $mflag_primary -Werror"
4100
4101AC_LINK_IFELSE([AC_LANG_SOURCE([
4102#include <omp.h>
4103int main(int argc, char** argv)
4104{
4105  omp_set_dynamic(0);
4106  return 0;
4107}
4108])],
4109[
4110ac_have_openmp=yes
4111AC_MSG_RESULT([yes])
4112], [
4113ac_have_openmp=no
4114AC_MSG_RESULT([no])
4115])
4116CFLAGS=$safe_CFLAGS
4117
4118AM_CONDITIONAL([HAVE_OPENMP], [test x$ac_have_openmp = xyes])
4119
4120
4121# Check for __builtin_popcount
4122AC_MSG_CHECKING([for __builtin_popcount()])
4123AC_LINK_IFELSE([AC_LANG_PROGRAM([[
4124]], [[
4125  __builtin_popcount(2);
4126  return 0;
4127]])], [
4128AC_MSG_RESULT([yes])
4129AC_DEFINE([HAVE_BUILTIN_POPCOUT], 1,
4130          [Define to 1 if compiler provides __builtin_popcount().])
4131], [
4132AC_MSG_RESULT([no])
4133])
4134
4135# Check for __builtin_clz
4136AC_MSG_CHECKING([for __builtin_clz()])
4137AC_LINK_IFELSE([AC_LANG_PROGRAM([[
4138]], [[
4139  __builtin_clz(2);
4140  return 0;
4141]])], [
4142AC_MSG_RESULT([yes])
4143AC_DEFINE([HAVE_BUILTIN_CLZ], 1,
4144          [Define to 1 if compiler provides __builtin_clz().])
4145], [
4146AC_MSG_RESULT([no])
4147])
4148
4149# Check for __builtin_ctz
4150AC_MSG_CHECKING([for __builtin_ctz()])
4151AC_LINK_IFELSE([AC_LANG_PROGRAM([[
4152]], [[
4153  __builtin_ctz(2);
4154  return 0;
4155]])], [
4156AC_MSG_RESULT([yes])
4157AC_DEFINE([HAVE_BUILTIN_CTZ], 1,
4158          [Define to 1 if compiler provides __builtin_ctz().])
4159], [
4160AC_MSG_RESULT([no])
4161])
4162
4163# does this compiler have built-in functions for atomic memory access for the
4164# primary target ?
4165AC_MSG_CHECKING([if gcc supports __sync_add_and_fetch for the primary target])
4166
4167safe_CFLAGS=$CFLAGS
4168CFLAGS="$mflag_primary"
4169
4170AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[
4171  int variable = 1;
4172  return (__sync_bool_compare_and_swap(&variable, 1, 2)
4173          && __sync_add_and_fetch(&variable, 1) ? 1 : 0)
4174]])], [
4175  ac_have_builtin_atomic_primary=yes
4176  AC_MSG_RESULT([yes])
4177  AC_DEFINE(HAVE_BUILTIN_ATOMIC, 1, [Define to 1 if gcc supports __sync_bool_compare_and_swap() and __sync_add_and_fetch() for the primary target])
4178], [
4179  ac_have_builtin_atomic_primary=no
4180  AC_MSG_RESULT([no])
4181])
4182
4183CFLAGS=$safe_CFLAGS
4184
4185AM_CONDITIONAL([HAVE_BUILTIN_ATOMIC],
4186               [test x$ac_have_builtin_atomic_primary = xyes])
4187
4188
4189# does this compiler have built-in functions for atomic memory access for the
4190# secondary target ?
4191
4192if test x$VGCONF_PLATFORM_SEC_CAPS != x; then
4193
4194AC_MSG_CHECKING([if gcc supports __sync_add_and_fetch for the secondary target])
4195
4196safe_CFLAGS=$CFLAGS
4197CFLAGS="$mflag_secondary"
4198
4199AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[
4200  int variable = 1;
4201  return (__sync_add_and_fetch(&variable, 1) ? 1 : 0)
4202]])], [
4203  ac_have_builtin_atomic_secondary=yes
4204  AC_MSG_RESULT([yes])
4205], [
4206  ac_have_builtin_atomic_secondary=no
4207  AC_MSG_RESULT([no])
4208])
4209
4210CFLAGS=$safe_CFLAGS
4211
4212fi
4213
4214AM_CONDITIONAL([HAVE_BUILTIN_ATOMIC_SECONDARY],
4215               [test x$ac_have_builtin_atomic_secondary = xyes])
4216
4217# does this compiler have built-in functions for atomic memory access on
4218# 64-bit integers for all targets ?
4219
4220AC_MSG_CHECKING([if gcc supports __sync_add_and_fetch on uint64_t for all targets])
4221
4222AC_LINK_IFELSE([AC_LANG_PROGRAM([[
4223  #include <stdint.h>
4224]], [[
4225  uint64_t variable = 1;
4226  return __sync_add_and_fetch(&variable, 1)
4227]])], [
4228  ac_have_builtin_atomic64_primary=yes
4229], [
4230  ac_have_builtin_atomic64_primary=no
4231])
4232
4233if test x$VGCONF_PLATFORM_SEC_CAPS != x; then
4234
4235safe_CFLAGS=$CFLAGS
4236CFLAGS="$mflag_secondary"
4237
4238AC_LINK_IFELSE([AC_LANG_PROGRAM([[
4239  #include <stdint.h>
4240]], [[
4241  uint64_t variable = 1;
4242  return __sync_add_and_fetch(&variable, 1)
4243]])], [
4244  ac_have_builtin_atomic64_secondary=yes
4245], [
4246  ac_have_builtin_atomic64_secondary=no
4247])
4248
4249CFLAGS=$safe_CFLAGS
4250
4251fi
4252
4253if test x$ac_have_builtin_atomic64_primary = xyes && \
4254   test x$VGCONF_PLATFORM_SEC_CAPS = x \
4255     -o x$ac_have_builtin_atomic64_secondary = xyes; then
4256  AC_MSG_RESULT([yes])
4257  ac_have_builtin_atomic64=yes
4258else
4259  AC_MSG_RESULT([no])
4260  ac_have_builtin_atomic64=no
4261fi
4262
4263AM_CONDITIONAL([HAVE_BUILTIN_ATOMIC64],
4264               [test x$ac_have_builtin_atomic64 = xyes])
4265
4266
4267# does g++ have built-in functions for atomic memory access ?
4268AC_MSG_CHECKING([if g++ supports __sync_add_and_fetch])
4269
4270safe_CXXFLAGS=$CXXFLAGS
4271CXXFLAGS="$mflag_primary"
4272
4273AC_LANG_PUSH(C++)
4274AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[
4275  int variable = 1;
4276  return (__sync_bool_compare_and_swap(&variable, 1, 2)
4277          && __sync_add_and_fetch(&variable, 1) ? 1 : 0)
4278]])], [
4279  ac_have_builtin_atomic_cxx=yes
4280  AC_MSG_RESULT([yes])
4281  AC_DEFINE(HAVE_BUILTIN_ATOMIC_CXX, 1, [Define to 1 if g++ supports __sync_bool_compare_and_swap() and __sync_add_and_fetch()])
4282], [
4283  ac_have_builtin_atomic_cxx=no
4284  AC_MSG_RESULT([no])
4285])
4286AC_LANG_POP(C++)
4287
4288CXXFLAGS=$safe_CXXFLAGS
4289
4290AM_CONDITIONAL([HAVE_BUILTIN_ATOMIC_CXX], [test x$ac_have_builtin_atomic_cxx = xyes])
4291
4292
4293if test x$ac_have_usable_linux_futex_h = xyes \
4294        -a x$ac_have_builtin_atomic_primary = xyes; then
4295  ac_enable_linux_ticket_lock_primary=yes
4296fi
4297AM_CONDITIONAL([ENABLE_LINUX_TICKET_LOCK_PRIMARY],
4298               [test x$ac_enable_linux_ticket_lock_primary = xyes])
4299
4300if test x$VGCONF_PLATFORM_SEC_CAPS != x \
4301        -a x$ac_have_usable_linux_futex_h = xyes \
4302        -a x$ac_have_builtin_atomic_secondary = xyes; then
4303  ac_enable_linux_ticket_lock_secondary=yes
4304fi
4305AM_CONDITIONAL([ENABLE_LINUX_TICKET_LOCK_SECONDARY],
4306               [test x$ac_enable_linux_ticket_lock_secondary = xyes])
4307
4308
4309# does libstdc++ support annotating shared pointers ?
4310AC_MSG_CHECKING([if libstdc++ supports annotating shared pointers])
4311
4312safe_CXXFLAGS=$CXXFLAGS
4313CXXFLAGS="-std=c++0x"
4314
4315AC_LANG_PUSH(C++)
4316AC_LINK_IFELSE([AC_LANG_PROGRAM([[
4317  #include <memory>
4318]], [[
4319  std::shared_ptr<int> p
4320]])], [
4321  ac_have_shared_ptr=yes
4322], [
4323  ac_have_shared_ptr=no
4324])
4325if test x$ac_have_shared_ptr = xyes; then
4326  # If compilation of the program below fails because of a syntax error
4327  # triggered by substituting one of the annotation macros then that
4328  # means that libstdc++ supports these macros.
4329  AC_LINK_IFELSE([AC_LANG_PROGRAM([[
4330    #define _GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE(a) (a)----
4331    #define _GLIBCXX_SYNCHRONIZATION_HAPPENS_AFTER(a) (a)----
4332    #include <memory>
4333  ]], [[
4334    std::shared_ptr<int> p
4335  ]])], [
4336    ac_have_shared_pointer_annotation=no
4337    AC_MSG_RESULT([no])
4338  ], [
4339    ac_have_shared_pointer_annotation=yes
4340    AC_MSG_RESULT([yes])
4341    AC_DEFINE(HAVE_SHARED_POINTER_ANNOTATION, 1,
4342              [Define to 1 if libstd++ supports annotating shared pointers])
4343  ])
4344else
4345  ac_have_shared_pointer_annotation=no
4346  AC_MSG_RESULT([no])
4347fi
4348AC_LANG_POP(C++)
4349
4350CXXFLAGS=$safe_CXXFLAGS
4351
4352AM_CONDITIONAL([HAVE_SHARED_POINTER_ANNOTATION],
4353               [test x$ac_have_shared_pointer_annotation = xyes])
4354
4355
4356#----------------------------------------------------------------------------
4357# Ok.  We're done checking.
4358#----------------------------------------------------------------------------
4359
4360# Nb: VEX/Makefile is generated from Makefile.vex.in.
4361AC_CONFIG_FILES([
4362   Makefile
4363   VEX/Makefile:Makefile.vex.in
4364   valgrind.spec
4365   valgrind.pc
4366   glibc-2.X.supp
4367   docs/Makefile
4368   tests/Makefile
4369   tests/vg_regtest
4370   perf/Makefile
4371   perf/vg_perf
4372   gdbserver_tests/Makefile
4373   gdbserver_tests/solaris/Makefile
4374   include/Makefile
4375   auxprogs/Makefile
4376   mpi/Makefile
4377   coregrind/Makefile
4378   memcheck/Makefile
4379   memcheck/tests/Makefile
4380   memcheck/tests/common/Makefile
4381   memcheck/tests/amd64/Makefile
4382   memcheck/tests/x86/Makefile
4383   memcheck/tests/linux/Makefile
4384   memcheck/tests/darwin/Makefile
4385   memcheck/tests/solaris/Makefile
4386   memcheck/tests/amd64-linux/Makefile
4387   memcheck/tests/arm64-linux/Makefile
4388   memcheck/tests/x86-linux/Makefile
4389   memcheck/tests/amd64-solaris/Makefile
4390   memcheck/tests/x86-solaris/Makefile
4391   memcheck/tests/ppc32/Makefile
4392   memcheck/tests/ppc64/Makefile
4393   memcheck/tests/s390x/Makefile
4394   memcheck/tests/mips32/Makefile
4395   memcheck/tests/mips64/Makefile
4396   memcheck/tests/vbit-test/Makefile
4397   cachegrind/Makefile
4398   cachegrind/tests/Makefile
4399   cachegrind/tests/x86/Makefile
4400   cachegrind/cg_annotate
4401   cachegrind/cg_diff
4402   callgrind/Makefile
4403   callgrind/callgrind_annotate
4404   callgrind/callgrind_control
4405   callgrind/tests/Makefile
4406   helgrind/Makefile
4407   helgrind/tests/Makefile
4408   massif/Makefile
4409   massif/tests/Makefile
4410   massif/ms_print
4411   lackey/Makefile
4412   lackey/tests/Makefile
4413   none/Makefile
4414   none/tests/Makefile
4415   none/tests/scripts/Makefile
4416   none/tests/amd64/Makefile
4417   none/tests/ppc32/Makefile
4418   none/tests/ppc64/Makefile
4419   none/tests/x86/Makefile
4420   none/tests/arm/Makefile
4421   none/tests/arm64/Makefile
4422   none/tests/s390x/Makefile
4423   none/tests/mips32/Makefile
4424   none/tests/mips64/Makefile
4425   none/tests/linux/Makefile
4426   none/tests/darwin/Makefile
4427   none/tests/solaris/Makefile
4428   none/tests/amd64-linux/Makefile
4429   none/tests/x86-linux/Makefile
4430   none/tests/amd64-darwin/Makefile
4431   none/tests/x86-darwin/Makefile
4432   none/tests/amd64-solaris/Makefile
4433   none/tests/x86-solaris/Makefile
4434   exp-sgcheck/Makefile
4435   exp-sgcheck/tests/Makefile
4436   drd/Makefile
4437   drd/scripts/download-and-build-splash2
4438   drd/tests/Makefile
4439   exp-bbv/Makefile
4440   exp-bbv/tests/Makefile
4441   exp-bbv/tests/x86/Makefile
4442   exp-bbv/tests/x86-linux/Makefile
4443   exp-bbv/tests/amd64-linux/Makefile
4444   exp-bbv/tests/ppc32-linux/Makefile
4445   exp-bbv/tests/arm-linux/Makefile
4446   exp-dhat/Makefile
4447   exp-dhat/tests/Makefile
4448   shared/Makefile
4449   solaris/Makefile
4450])
4451AC_CONFIG_FILES([coregrind/link_tool_exe_linux],
4452                [chmod +x coregrind/link_tool_exe_linux])
4453AC_CONFIG_FILES([coregrind/link_tool_exe_darwin],
4454                [chmod +x coregrind/link_tool_exe_darwin])
4455AC_CONFIG_FILES([coregrind/link_tool_exe_solaris],
4456                [chmod +x coregrind/link_tool_exe_solaris])
4457AC_OUTPUT
4458
4459cat<<EOF
4460
4461         Maximum build arch: ${ARCH_MAX}
4462         Primary build arch: ${VGCONF_ARCH_PRI}
4463       Secondary build arch: ${VGCONF_ARCH_SEC}
4464                   Build OS: ${VGCONF_OS}
4465       Primary build target: ${VGCONF_PLATFORM_PRI_CAPS}
4466     Secondary build target: ${VGCONF_PLATFORM_SEC_CAPS}
4467           Platform variant: ${VGCONF_PLATVARIANT}
4468      Primary -DVGPV string: -DVGPV_${VGCONF_ARCH_PRI}_${VGCONF_OS}_${VGCONF_PLATVARIANT}=1
4469         Default supp files: ${DEFAULT_SUPP}
4470
4471EOF
4472