Refactor: reorder a few structs to make them more compact
[valgrind.git] / configure.ac
blob92fb33c4a51895ee8b23e53c590db0c2e19c4dcc
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.
8 ##------------------------------------------------------------##
10 # Process this file with autoconf to produce a configure script.
12 # Define major, minor, micro and suffix here once, then reuse them
13 # for version number in valgrind.h and vg-entities (documentation).
14 # suffix must be empty for a release, otherwise it is GIT or RC1, etc.
15 # Also set the (expected/last) release date here.
16 # Do not forget to rerun ./autogen.sh
17 m4_define([v_major_ver], [3])
18 m4_define([v_minor_ver], [21])
19 m4_define([v_micro_ver], [0])
20 m4_define([v_suffix_ver], [GIT])
21 m4_define([v_rel_date], ["?? Apr 2023"])
22 m4_define([v_version],
23           m4_if(v_suffix_ver, [],
24                 [v_major_ver.v_minor_ver.v_micro_ver],
25                 [v_major_ver.v_minor_ver.v_micro_ver.v_suffix_ver]))
26 AC_INIT([Valgrind],[v_version],[valgrind-users@lists.sourceforge.net])
28 # For valgrind.h
29 AC_SUBST(VG_VER_MAJOR, v_major_ver)
30 AC_SUBST(VG_VER_MINOR, v_minor_ver)
32 # For docs/xml/vg-entities.xml
33 AC_SUBST(VG_DATE, v_rel_date)
35 AC_CONFIG_SRCDIR(coregrind/m_main.c)
36 AC_CONFIG_HEADERS([config.h])
37 AM_INIT_AUTOMAKE([foreign dist-bzip2 subdir-objects])
39 AM_MAINTAINER_MODE
41 #----------------------------------------------------------------------------
42 # Do NOT modify these flags here. Except in feature tests in which case
43 # the original values must be properly restored.
44 #----------------------------------------------------------------------------
45 CFLAGS="$CFLAGS"
46 CXXFLAGS="$CXXFLAGS"
48 #----------------------------------------------------------------------------
49 # Checks for various programs.
50 #----------------------------------------------------------------------------
52 AC_PROG_LN_S
53 m4_version_prereq([2.70], [AC_PROG_CC], [AC_PROG_CC_C99])
54 # Make sure we can compile in C99 mode.
55 if test "$ac_cv_prog_cc_c99" = "no"; then
56     AC_MSG_ERROR([Valgrind relies on a C compiler supporting C99])
58 AC_PROG_CPP
59 AC_PROG_CXX
60 # AC_PROG_OBJC apparently causes problems on older Linux distros (eg. with
61 # autoconf 2.59).  If we ever have any Objective-C code in the Valgrind code
62 # base (eg. most likely as Darwin-specific tests) we'll need one of the
63 # following:
64 # - put AC_PROG_OBJC in a Darwin-specific part of this file
65 # - Use AC_PROG_OBJC here and up the minimum autoconf version
66 # - Use the following, which is apparently equivalent:
67 #     m4_ifdef([AC_PROG_OBJC],
68 #        [AC_PROG_OBJC],
69 #        [AC_CHECK_TOOL([OBJC], [gcc])
70 #         AC_SUBST([OBJC])
71 #         AC_SUBST([OBJCFLAGS])
72 #        ])
73 AC_PROG_RANLIB
74 # Set LTO_RANLIB variable to an lto enabled ranlib
75 if test "x$LTO_RANLIB" = "x"; then
76   AC_PATH_PROGS([LTO_RANLIB], [gcc-ranlib])
78 AC_ARG_VAR([LTO_RANLIB],[Library indexer command for link time optimisation])
80 # provide a very basic definition for AC_PROG_SED if it's not provided by
81 # autoconf (as e.g. in autoconf 2.59).
82 m4_ifndef([AC_PROG_SED],
83           [AC_DEFUN([AC_PROG_SED],
84                     [AC_ARG_VAR([SED])
85                      AC_CHECK_PROGS([SED],[gsed sed])])])
86 AC_PROG_SED
88 AC_DEFUN([AC_PROG_SHA256SUM],
89           [AC_ARG_VAR([SHA256SUM])
90           AC_CHECK_PROGS([SHA256SUM],[gsha256sum sha256sum])])
91 AC_PROG_SHA256SUM
93 # If no AR variable was specified, look up the name of the archiver. Otherwise
94 # do not touch the AR variable.
95 if test "x$AR" = "x"; then
96   AC_PATH_PROGS([AR], [`echo $LD | $SED 's/ld$/ar/'` "ar"], [ar])
98 AC_ARG_VAR([AR],[Archiver command])
100 # same for LTO_AR variable for lto enabled archiver
101 if test "x$LTO_AR" = "x"; then
102   AC_PATH_PROGS([LTO_AR], [gcc-ar])
104 AC_ARG_VAR([LTO_AR],[Archiver command for link time optimisation])
107 # Check for the compiler support
108 if test "${GCC}" != "yes" ; then
109    AC_MSG_ERROR([Valgrind relies on GCC to be compiled])
112 # figure out where perl lives
113 AC_PATH_PROG(PERL, perl)
115 # figure out where gdb lives
116 AC_PATH_PROG(GDB, gdb, "/no/gdb/was/found/at/configure/time")
117 AC_DEFINE_UNQUOTED(GDB_PATH, "$GDB", [path to GDB])
119 # some older automake's don't have it so try something on our own
120 ifdef([AM_PROG_AS],[AM_PROG_AS],
122 AS="${CC}"
123 AC_SUBST(AS)
125 ASFLAGS=""
126 AC_SUBST(ASFLAGS)
130 # Check if 'diff' supports -u (universal diffs) and use it if possible.
132 AC_MSG_CHECKING([for diff -u])
133 AC_SUBST(DIFF)
135 # Comparing two identical files results in 0.
136 tmpfile="tmp-xxx-yyy-zzz"
137 touch $tmpfile;
138 if diff -u $tmpfile $tmpfile ; then
139     AC_MSG_RESULT([yes])
140     DIFF="diff -u"
141 else
142     AC_MSG_RESULT([no])
143     DIFF="diff"
145 rm $tmpfile
147 # We don't want gcc < 3.0
148 AC_MSG_CHECKING([for a supported version of gcc])
150 # Obtain the compiler version.
152 # A few examples of how the ${CC} --version output looks like:
154 # ######## gcc variants ########
155 # Arch Linux: i686-pc-linux-gnu-gcc (GCC) 4.6.2
156 # Debian Linux: gcc (Debian 4.3.2-1.1) 4.3.2
157 # openSUSE: gcc (SUSE Linux) 4.5.1 20101208 [gcc-4_5-branch revision 167585]
158 # Exherbo Linux: x86_64-pc-linux-gnu-gcc (Exherbo gcc-4.6.2) 4.6.2
159 # MontaVista Linux for ARM: arm-none-linux-gnueabi-gcc (Sourcery G++ Lite 2009q1-203) 4.3.3
160 # OS/X 10.6: i686-apple-darwin10-gcc-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5666) (dot 3)
161 # 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)
163 # ######## clang variants ########
164 # Clang: clang version 2.9 (tags/RELEASE_29/final)
165 # Apple clang: Apple clang version 3.1 (tags/Apple/clang-318.0.58) (based on LLVM 3.1svn)
166 # FreeBSD clang: FreeBSD clang version 3.1 (branches/release_31 156863) 20120523
168 # ######## Apple LLVM variants ########
169 # Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
170 # Apple LLVM version 6.0 (clang-600.0.51) (based on LLVM 3.5svn)
173 if test "x`${CC} --version | $SED -n -e 's/.*\Apple \(LLVM\) version.*clang.*/\1/p'`" = "xLLVM" ;
174 then
175     is_clang="applellvm"
176     gcc_version=`${CC} --version | $SED -n -e 's/.*LLVM version \([0-9.]*\).*$/\1/p'`
177 elif test "x`${CC} --version | $SED -n -e 's/.*\(clang\) version.*/\1/p'`" = "xclang" ;
178 then
179     is_clang="clang"
180     # Don't use -dumpversion with clang: it will always produce "4.2.1".
181     gcc_version=`${CC} --version | $SED -n -e 's/.*clang version \([0-9.]*\).*$/\1/p'`
182 elif test "x`${CC} --version | $SED -n -e 's/icc.*\(ICC\).*/\1/p'`" = "xICC" ; 
183 then
184     is_clang="icc"
185     gcc_version=`${CC} -dumpversion 2>/dev/null`
186 else
187     is_clang="notclang"
188     gcc_version=`${CC} -dumpversion 2>/dev/null`
189     if test "x$gcc_version" = x; then
190         gcc_version=`${CC} --version | $SED -n -e 's/[^ ]*gcc[^ ]* ([^)]*) \([0-9.]*\).*$/\1/p'`
191     fi
194 AM_CONDITIONAL(COMPILER_IS_CLANG, test $is_clang = clang -o $is_clang = applellvm)
195 AM_CONDITIONAL(COMPILER_IS_ICC, test $is_clang = icc)
197 # Note: m4 arguments are quoted with [ and ] so square brackets in shell
198 # statements have to be quoted.
199 case "${is_clang}-${gcc_version}" in
200      applellvm-5.1|applellvm-[[6-9]].*|applellvm-[[1-9][0-9]]*)
201         AC_MSG_RESULT([ok (Apple LLVM version ${gcc_version})])
202         ;;
203      icc-1[[3-9]].*|icc-202[[0-9]].*)
204         AC_MSG_RESULT([ok (ICC version ${gcc_version})])
205         ;;
206      notclang-[[3-9]]|notclang-[[3-9]].*|notclang-[[1-9][0-9]]*)
207         AC_MSG_RESULT([ok (${gcc_version})])
208         ;;
209      clang-2.9|clang-[[3-9]].*|clang-[[1-9][0-9]]*)
210         AC_MSG_RESULT([ok (clang-${gcc_version})])
211         ;;
212      *)
213         AC_MSG_RESULT([no (${is_clang}-${gcc_version})])
214         AC_MSG_ERROR([please use gcc >= 3.0 or clang >= 2.9 or icc >= 13.0 or Apple LLVM >= 5.1])
215         ;;
216 esac
218 #----------------------------------------------------------------------------
219 # Arch/OS/platform tests.
220 #----------------------------------------------------------------------------
221 # We create a number of arch/OS/platform-related variables.  We prefix them
222 # all with "VGCONF_" which indicates that they are defined at
223 # configure-time, and distinguishes them from the VGA_*/VGO_*/VGP_*
224 # variables used when compiling C files.
226 AC_CANONICAL_HOST
228 AC_MSG_CHECKING([for a supported CPU])
230 # ARCH_MAX reflects the most that this CPU can do: for example if it
231 # is a 64-bit capable PowerPC, then it must be set to ppc64 and not ppc32.
232 # Ditto for amd64.  It is used for more configuration below, but is not used
233 # outside this file.
235 # Power PC returns powerpc for Big Endian.  This was not changed when Little
236 # Endian support was added to the 64-bit architecture.  The 64-bit Little
237 # Endian systems explicitly state le in the host_cpu.  For clarity in the
238 # Valgrind code, the ARCH_MAX name will state LE or BE for the endianness of
239 # the 64-bit system.  Big Endian is the only mode supported on 32-bit Power PC.
240 # The abreviation PPC or ppc refers to 32-bit and 64-bit systems with either
241 # Endianness.  The name PPC64 or ppc64 to 64-bit systems of either Endianness.
242 # The names ppc64be or PPC64BE refer to only 64-bit systems that are Big
243 # Endian.  Similarly, ppc64le or PPC64LE refer to only 64-bit systems that are
244 # Little Endian.
246 case "${host_cpu}" in
247      i?86) 
248         AC_MSG_RESULT([ok (${host_cpu})])
249         ARCH_MAX="x86"
250         ;;
252      x86_64|amd64) 
253         AC_MSG_RESULT([ok (${host_cpu})])
254         ARCH_MAX="amd64"
255         ;;
257      powerpc64)
258      # this only referrs to 64-bit Big Endian
259         AC_MSG_RESULT([ok (${host_cpu})])
260         ARCH_MAX="ppc64be"
261         ;;
263      powerpc64le)
264      # this only referrs to 64-bit Little Endian
265         AC_MSG_RESULT([ok (${host_cpu})])
266         ARCH_MAX="ppc64le"
267         ;;
269      powerpc)
270         # On Linux this means only a 32-bit capable CPU.
271         AC_MSG_RESULT([ok (${host_cpu})])
272         ARCH_MAX="ppc32"
273         ;;
275      s390x)
276         AC_MSG_RESULT([ok (${host_cpu})])
277         ARCH_MAX="s390x"
278         ;;
280      armv7*)
281         AC_MSG_RESULT([ok (${host_cpu})])
282         ARCH_MAX="arm"
283         ;;
285      aarch64*)
286        AC_MSG_RESULT([ok (${host_cpu})])
287        ARCH_MAX="arm64"
288        ;;
290      mips)
291         AC_MSG_RESULT([ok (${host_cpu})])
292         ARCH_MAX="mips32"
293         ;;
295      mipsel)
296         AC_MSG_RESULT([ok (${host_cpu})])
297         ARCH_MAX="mips32"
298         ;;
300      mipsisa32r2)
301         AC_MSG_RESULT([ok (${host_cpu})])
302         ARCH_MAX="mips32"
303         ;;
305      mips64*)
306         AC_MSG_RESULT([ok (${host_cpu})])
307         ARCH_MAX="mips64"
308         ;;
310      mipsisa64*)
311         AC_MSG_RESULT([ok (${host_cpu})])
312         ARCH_MAX="mips64"
313         ;;
314      nanomips)
315         AC_MSG_RESULT([ok (${host_cpu})])
316         ARCH_MAX="nanomips"
317         ;;
319      *) 
320         AC_MSG_RESULT([no (${host_cpu})])
321         AC_MSG_ERROR([Unsupported host architecture. Sorry])
322         ;;
323 esac
325 #----------------------------------------------------------------------------
327 # Sometimes it's convenient to subvert the bi-arch build system and
328 # just have a single build even though the underlying platform is
329 # capable of both.  Hence handle --enable-only64bit and
330 # --enable-only32bit.  Complain if both are issued :-)
331 # [Actually, if either of these options are used, I think both get built,
332 # but only one gets installed.  So if you use an in-place build, both can be
333 # used. --njn]
335 # Check if a 64-bit only build has been requested
336 AC_CACHE_CHECK([for a 64-bit only build], vg_cv_only64bit,
337    [AC_ARG_ENABLE(only64bit, 
338       [  --enable-only64bit      do a 64-bit only build],
339       [vg_cv_only64bit=$enableval],
340       [vg_cv_only64bit=no])])
342 # Check if a 32-bit only build has been requested
343 AC_CACHE_CHECK([for a 32-bit only build], vg_cv_only32bit,
344    [AC_ARG_ENABLE(only32bit, 
345       [  --enable-only32bit      do a 32-bit only build],
346       [vg_cv_only32bit=$enableval],
347       [vg_cv_only32bit=no])])
349 # Stay sane
350 if test x$vg_cv_only64bit = xyes -a x$vg_cv_only32bit = xyes; then
351    AC_MSG_ERROR(
352       [Nonsensical: both --enable-only64bit and --enable-only32bit.])
355 #----------------------------------------------------------------------------
357 # VGCONF_OS is the primary build OS, eg. "linux".  It is passed in to
358 # compilation of many C files via -VGO_$(VGCONF_OS) and
359 # -VGP_$(VGCONF_ARCH_PRI)_$(VGCONF_OS).
360 AC_MSG_CHECKING([for a supported OS])
361 AC_SUBST(VGCONF_OS)
363 DEFAULT_SUPP=""
365 case "${host_os}" in
366      *linux*)
367         AC_MSG_RESULT([ok (${host_os})])
368         VGCONF_OS="linux"
370         # Ok, this is linux. Check the kernel version
371         AC_MSG_CHECKING([for the kernel version])
373         kernel=`uname -r`
375         case "${kernel}" in
376              0.*|1.*|2.0.*|2.1.*|2.2.*|2.3.*|2.4.*|2.5.*) 
377                     AC_MSG_RESULT([unsupported (${kernel})])
378                     AC_MSG_ERROR([Valgrind needs a Linux kernel >= 2.6])
379                     ;;
381              *)
382                     AC_MSG_RESULT([2.6 or later (${kernel})])
383                     ;;
384         esac
386         ;;
388      *freebsd*)
389         AC_MSG_RESULT([ok (${host_os})])
390         VGCONF_OS="freebsd"
391         AC_DEFINE([FREEBSD_10], 1000, [FREEBSD_VERS value for FreeBSD 10.x])
392         freebsd_10=1000
393         AC_DEFINE([FREEBSD_11], 1100, [FREEBSD_VERS value for FreeBSD 11.x])
394         freebsd_11=1100
395         AC_DEFINE([FREEBSD_12], 1200, [FREEBSD_VERS value for FreeBSD 12.0 to 12.1])
396         freebsd_12=1200
397         AC_DEFINE([FREEBSD_12_2], 1220, [FREEBSD_VERS value for FreeBSD 12.2])
398         freebsd_12_2=1220
399         AC_DEFINE([FREEBSD_13_0], 1300, [FREEBSD_VERS value for FreeBSD 13.0])
400         freebsd_13_0=1300
401         AC_DEFINE([FREEBSD_13_1], 1310, [FREEBSD_VERS value for FreeBSD 13.1+])
402         freebsd_13_1=1310
403         AC_DEFINE([FREEBSD_14], 1400, [FREEBSD_VERS value for FreeBSD 14.x])
404         freebsd_14=1400
406         AC_MSG_CHECKING([for the kernel version])
407         kernel=`uname -r`
409         case "${kernel}" in
410         10.*)
411            AC_MSG_RESULT([FreeBSD 10.x (${kernel})])
412            AC_DEFINE([FREEBSD_VERS], FREEBSD_10, [FreeBSD version])
413            freebsd_vers=$freebsd_10
414            ;;
415         11.*)
416            AC_MSG_RESULT([FreeBSD 11.x (${kernel})])
417            AC_DEFINE([FREEBSD_VERS], FREEBSD_11, [FreeBSD version])
418            freebsd_vers=$freebsd_11
419            ;;
420         12.*)
421            case "${kernel}" in
422            12.[[0-1]]-*)
423               AC_MSG_RESULT([FreeBSD 12.x (${kernel})])
424               AC_DEFINE([FREEBSD_VERS], FREEBSD_12, [FreeBSD version])
425               freebsd_vers=$freebsd_12
426               ;;
427            *)
428               AC_MSG_RESULT([FreeBSD 12.x (${kernel})])
429               AC_DEFINE([FREEBSD_VERS], FREEBSD_12_2, [FreeBSD version])
430               freebsd_vers=$freebsd_12_2
431               ;;
432            esac
433            ;;
434         13.*)
435            case "${kernel}" in
436            13.0-*)
437               AC_MSG_RESULT([FreeBSD 13.0 (${kernel})])
438               AC_DEFINE([FREEBSD_VERS], FREEBSD_13_0, [FreeBSD version])
439               freebsd_vers=$freebsd_13_0
440               ;;
441            *)
442               AC_MSG_RESULT([FreeBSD 13.1+ (${kernel})])
443               AC_DEFINE([FREEBSD_VERS], FREEBSD_13_1, [FreeBSD version])
444               freebsd_vers=$freebsd_13_1
445               ;;
446            esac
447            ;;
448         14.*)
449            AC_MSG_RESULT([FreeBSD 14.x (${kernel})])
450            AC_DEFINE([FREEBSD_VERS], FREEBSD_14, [FreeBSD version])
451            freebsd_vers=$freebsd_14
452            ;;
453         *)
454            AC_MSG_RESULT([unsupported (${kernel})])
455            AC_MSG_ERROR([Valgrind works on FreeBSD 10.x to 14.x])
456            ;;
457         esac
459         DEFAULT_SUPP="$srcdir/freebsd.supp $srcdir/freebsd-helgrind.supp $srcdir/freebsd-drd.supp ${DEFAULT_SUPP}"
460         ;;
462      *darwin*)
463         AC_MSG_RESULT([ok (${host_os})])
464         VGCONF_OS="darwin"
465         AC_DEFINE([DARWIN_10_5], 100500, [DARWIN_VERS value for Mac OS X 10.5])
466         AC_DEFINE([DARWIN_10_6], 100600, [DARWIN_VERS value for Mac OS X 10.6])
467         AC_DEFINE([DARWIN_10_7], 100700, [DARWIN_VERS value for Mac OS X 10.7])
468         AC_DEFINE([DARWIN_10_8], 100800, [DARWIN_VERS value for Mac OS X 10.8])
469         AC_DEFINE([DARWIN_10_9], 100900, [DARWIN_VERS value for Mac OS X 10.9])
470         AC_DEFINE([DARWIN_10_10], 101000, [DARWIN_VERS value for Mac OS X 10.10])
471         AC_DEFINE([DARWIN_10_11], 101100, [DARWIN_VERS value for Mac OS X 10.11])
472         AC_DEFINE([DARWIN_10_12], 101200, [DARWIN_VERS value for macOS 10.12])
473         AC_DEFINE([DARWIN_10_13], 101300, [DARWIN_VERS value for macOS 10.13])
475         AC_MSG_CHECKING([for the kernel version])
476         kernel=`uname -r`
478         # Nb: for Darwin we set DEFAULT_SUPP here.  That's because Darwin
479         # has only one relevant version, the OS version. The `uname` check
480         # is a good way to get that version (i.e. "Darwin 9.6.0" is Mac OS
481         # X 10.5.6, and "Darwin 10.x" is Mac OS X 10.6.x Snow Leopard,
482         # and possibly "Darwin 11.x" is Mac OS X 10.7.x Lion), 
483         # and we don't know of an macros similar to __GLIBC__ to get that info.
484         #
485         # XXX: `uname -r` won't do the right thing for cross-compiles, but
486         # that's not a problem yet.
487         #
488         # jseward 21 Sept 2011: I seriously doubt whether V 3.7.0 will work
489         # on OS X 10.5.x; I haven't tested yet, and only plan to test 3.7.0
490         # on 10.6.8 and 10.7.1.  Although tempted to delete the configure
491         # time support for 10.5 (the 9.* pattern just below), I'll leave it
492         # in for now, just in case anybody wants to give it a try.  But I'm
493         # assuming that 3.7.0 is a Snow Leopard and Lion-only release.
494         case "${kernel}" in
495              9.*)
496                   AC_MSG_RESULT([Darwin 9.x (${kernel}) / Mac OS X 10.5 Leopard])
497                   AC_DEFINE([DARWIN_VERS], DARWIN_10_5, [Darwin / Mac OS X version])
498                   DEFAULT_SUPP="$srcdir/darwin9.supp ${DEFAULT_SUPP}"
499                   DEFAULT_SUPP="$srcdir/darwin9-drd.supp ${DEFAULT_SUPP}"
500                   ;;
501              10.*)
502                   AC_MSG_RESULT([Darwin 10.x (${kernel}) / Mac OS X 10.6 Snow Leopard])
503                   AC_DEFINE([DARWIN_VERS], DARWIN_10_6, [Darwin / Mac OS X version])
504                   DEFAULT_SUPP="$srcdir/darwin10.supp ${DEFAULT_SUPP}"
505                   DEFAULT_SUPP="$srcdir/darwin10-drd.supp ${DEFAULT_SUPP}"
506                   ;;
507              11.*)
508                   AC_MSG_RESULT([Darwin 11.x (${kernel}) / Mac OS X 10.7 Lion])
509                   AC_DEFINE([DARWIN_VERS], DARWIN_10_7, [Darwin / Mac OS X version])
510                   DEFAULT_SUPP="$srcdir/darwin11.supp ${DEFAULT_SUPP}"
511                   DEFAULT_SUPP="$srcdir/darwin10-drd.supp ${DEFAULT_SUPP}"
512                   ;;
513              12.*)
514                   AC_MSG_RESULT([Darwin 12.x (${kernel}) / Mac OS X 10.8 Mountain Lion])
515                   AC_DEFINE([DARWIN_VERS], DARWIN_10_8, [Darwin / Mac OS X version])
516                   DEFAULT_SUPP="$srcdir/darwin12.supp ${DEFAULT_SUPP}"
517                   DEFAULT_SUPP="$srcdir/darwin10-drd.supp ${DEFAULT_SUPP}"
518                   ;;
519              13.*)
520                   AC_MSG_RESULT([Darwin 13.x (${kernel}) / Mac OS X 10.9 Mavericks])
521                   AC_DEFINE([DARWIN_VERS], DARWIN_10_9, [Darwin / Mac OS X version])
522                   DEFAULT_SUPP="$srcdir/darwin13.supp ${DEFAULT_SUPP}"
523                   DEFAULT_SUPP="$srcdir/darwin10-drd.supp ${DEFAULT_SUPP}"
524                   ;;
525              14.*)
526                   AC_MSG_RESULT([Darwin 14.x (${kernel}) / Mac OS X 10.10 Yosemite])
527                   AC_DEFINE([DARWIN_VERS], DARWIN_10_10, [Darwin / Mac OS X version])
528                   DEFAULT_SUPP="$srcdir/darwin14.supp ${DEFAULT_SUPP}"
529                   DEFAULT_SUPP="$srcdir/darwin10-drd.supp ${DEFAULT_SUPP}"
530                   ;;
531              15.*)
532                   AC_MSG_RESULT([Darwin 15.x (${kernel}) / Mac OS X 10.11 El Capitan])
533                   AC_DEFINE([DARWIN_VERS], DARWIN_10_11, [Darwin / Mac OS X version])
534                   DEFAULT_SUPP="$srcdir/darwin15.supp ${DEFAULT_SUPP}"
535                   DEFAULT_SUPP="$srcdir/darwin10-drd.supp ${DEFAULT_SUPP}"
536                   ;;
537              16.*)
538                   AC_MSG_RESULT([Darwin 16.x (${kernel}) / macOS 10.12 Sierra])
539                   AC_DEFINE([DARWIN_VERS], DARWIN_10_12, [Darwin / Mac OS X version])
540                   DEFAULT_SUPP="$srcdir/darwin16.supp ${DEFAULT_SUPP}"
541                   DEFAULT_SUPP="$srcdir/darwin10-drd.supp ${DEFAULT_SUPP}"
542                   ;;
543              17.*)
544                   AC_MSG_RESULT([Darwin 17.x (${kernel}) / macOS 10.13 High Sierra])
545                   AC_DEFINE([DARWIN_VERS], DARWIN_10_13, [Darwin / Mac OS X version])
546                   DEFAULT_SUPP="$srcdir/darwin17.supp ${DEFAULT_SUPP}"
547                   DEFAULT_SUPP="$srcdir/darwin10-drd.supp ${DEFAULT_SUPP}"
548                   ;;
549              *) 
550                   AC_MSG_RESULT([unsupported (${kernel})])
551                   AC_MSG_ERROR([Valgrind works on Darwin 10.x, 11.x, 12.x, 13.x, 14.x, 15.x, 16.x and 17.x (Mac OS X 10.6/7/8/9/10/11 and macOS 10.12/13)])
552                   ;;
553         esac
554         ;;
556      solaris2.11*)
557         AC_MSG_RESULT([ok (${host_os})])
558         VGCONF_OS="solaris"
560         uname_v=$( uname -v )
561         case "$uname_v" in
562              11.4.*)
563                  DEFAULT_SUPP="$srcdir/solaris12.supp ${DEFAULT_SUPP}"
564                  ;;
565              *)
566                  DEFAULT_SUPP="$srcdir/solaris11.supp ${DEFAULT_SUPP}"
567                  ;;
568         esac
569         ;;
571      solaris2.12*)
572         AC_MSG_RESULT([ok (${host_os})])
573         VGCONF_OS="solaris"
574         DEFAULT_SUPP="$srcdir/solaris12.supp ${DEFAULT_SUPP}"
575         ;;
577      *) 
578         AC_MSG_RESULT([no (${host_os})])
579         AC_MSG_ERROR([Valgrind is operating system specific. Sorry.])
580         ;;
581 esac
583 #----------------------------------------------------------------------------
585 # If we are building on a 64 bit platform test to see if the system
586 # supports building 32 bit programs and disable 32 bit support if it
587 # does not support building 32 bit programs
589 case "$ARCH_MAX-$VGCONF_OS" in
590      amd64-linux|ppc64be-linux|arm64-linux|amd64-solaris)
591         AC_MSG_CHECKING([for 32 bit build support])
592         safe_CFLAGS=$CFLAGS
593         CFLAGS="-m32"
594         AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[
595           return 0;
596         ]])], [
597         AC_MSG_RESULT([yes])
598         ], [
599         vg_cv_only64bit="yes"
600         AC_MSG_RESULT([no])
601         ])
602         CFLAGS=$safe_CFLAGS;;
603     mips64-linux)
604         AC_MSG_CHECKING([for 32 bit build support])
605         safe_CFLAGS=$CFLAGS
606         CFLAGS="$CFLAGS -mips32 -mabi=32"
607         AC_LINK_IFELSE([AC_LANG_PROGRAM([[
608           #include <sys/prctl.h>
609         ]], [[]])], [
610         AC_MSG_RESULT([yes])
611         ], [
612         vg_cv_only64bit="yes"
613         AC_MSG_RESULT([no])
614         ])
615         CFLAGS=$safe_CFLAGS;;
616 esac
618 if test x$vg_cv_only64bit = xyes -a x$vg_cv_only32bit = xyes; then
619    AC_MSG_ERROR(
620       [--enable-only32bit was specified but system does not support 32 bit builds])
623 #----------------------------------------------------------------------------
625 # VGCONF_ARCH_PRI is the arch for the primary build target, eg. "amd64".  By
626 # default it's the same as ARCH_MAX.  But if, say, we do a build on an amd64
627 # machine, but --enable-only32bit has been requested, then ARCH_MAX (see
628 # above) will be "amd64" since that reflects the most that this cpu can do,
629 # but VGCONF_ARCH_PRI will be downgraded to "x86", since that reflects the
630 # arch corresponding to the primary build (VGCONF_PLATFORM_PRI_CAPS).  It is
631 # passed in to compilation of many C files via -VGA_$(VGCONF_ARCH_PRI) and
632 # -VGP_$(VGCONF_ARCH_PRI)_$(VGCONF_OS).
633 AC_SUBST(VGCONF_ARCH_PRI)
635 # VGCONF_ARCH_SEC is the arch for the secondary build target, eg. "x86".
636 # It is passed in to compilation of many C files via -VGA_$(VGCONF_ARCH_SEC)
637 # and -VGP_$(VGCONF_ARCH_SEC)_$(VGCONF_OS), if there is a secondary target.
638 # It is empty if there is no secondary target.
639 AC_SUBST(VGCONF_ARCH_SEC)
641 # VGCONF_PLATFORM_PRI_CAPS is the primary build target, eg. "AMD64_LINUX".
642 # The entire system, including regression and performance tests, will be
643 # built for this target.  The "_CAPS" indicates that the name is in capital
644 # letters, and it also uses '_' rather than '-' as a separator, because it's
645 # used to create various Makefile variables, which are all in caps by
646 # convention and cannot contain '-' characters.  This is in contrast to
647 # VGCONF_ARCH_PRI and VGCONF_OS which are not in caps.
648 AC_SUBST(VGCONF_PLATFORM_PRI_CAPS)
650 # VGCONF_PLATFORM_SEC_CAPS is the secondary build target, if there is one.
651 # Valgrind and tools will also be built for this target, but not the
652 # regression or performance tests.
654 # By default, the primary arch is the same as the "max" arch, as commented
655 # above (at the definition of ARCH_MAX).  We may choose to downgrade it in
656 # the big case statement just below here, in the case where we're building
657 # on a 64 bit machine but have been requested only to do a 32 bit build.
658 AC_SUBST(VGCONF_PLATFORM_SEC_CAPS)
660 AC_MSG_CHECKING([for a supported CPU/OS combination])
662 # NB.  The load address for a given platform may be specified in more 
663 # than one place, in some cases, depending on whether we're doing a biarch,
664 # 32-bit only or 64-bit only build.  eg see case for amd64-linux below.
665 # Be careful to give consistent values in all subcases.  Also, all four
666 # valt_load_addres_{pri,sec}_{norml,inner} values must always be set,
667 # even if it is to "0xUNSET".
669 case "$ARCH_MAX-$VGCONF_OS" in
670      x86-linux)
671         VGCONF_ARCH_PRI="x86"
672         VGCONF_ARCH_SEC=""
673         VGCONF_PLATFORM_PRI_CAPS="X86_LINUX"
674         VGCONF_PLATFORM_SEC_CAPS=""
675         valt_load_address_pri_norml="0x58000000"
676         valt_load_address_pri_inner="0x38000000"
677         valt_load_address_sec_norml="0xUNSET"
678         valt_load_address_sec_inner="0xUNSET"
679         AC_MSG_RESULT([ok (${ARCH_MAX}-${VGCONF_OS})])
680         ;;
681      amd64-linux)
682         valt_load_address_sec_norml="0xUNSET"
683         valt_load_address_sec_inner="0xUNSET"
684         if test x$vg_cv_only64bit = xyes; then
685            VGCONF_ARCH_PRI="amd64"
686            VGCONF_ARCH_SEC=""
687            VGCONF_PLATFORM_PRI_CAPS="AMD64_LINUX"
688            VGCONF_PLATFORM_SEC_CAPS=""
689            valt_load_address_pri_norml="0x58000000"
690            valt_load_address_pri_inner="0x38000000"
691         elif test x$vg_cv_only32bit = xyes; then
692            VGCONF_ARCH_PRI="x86"
693            VGCONF_ARCH_SEC=""
694            VGCONF_PLATFORM_PRI_CAPS="X86_LINUX"
695            VGCONF_PLATFORM_SEC_CAPS=""
696            valt_load_address_pri_norml="0x58000000"
697            valt_load_address_pri_inner="0x38000000"
698         else
699            VGCONF_ARCH_PRI="amd64"
700            VGCONF_ARCH_SEC="x86"
701            VGCONF_PLATFORM_PRI_CAPS="AMD64_LINUX"
702            VGCONF_PLATFORM_SEC_CAPS="X86_LINUX"
703            valt_load_address_pri_norml="0x58000000"
704            valt_load_address_pri_inner="0x38000000"
705            valt_load_address_sec_norml="0x58000000"
706            valt_load_address_sec_inner="0x38000000"
707         fi
708         AC_MSG_RESULT([ok (${ARCH_MAX}-${VGCONF_OS})])
709         ;;
710      ppc32-linux)
711         VGCONF_ARCH_PRI="ppc32"
712         VGCONF_ARCH_SEC=""
713         VGCONF_PLATFORM_PRI_CAPS="PPC32_LINUX"
714         VGCONF_PLATFORM_SEC_CAPS=""
715         valt_load_address_pri_norml="0x58000000"
716         valt_load_address_pri_inner="0x38000000"
717         valt_load_address_sec_norml="0xUNSET"
718         valt_load_address_sec_inner="0xUNSET"
719         AC_MSG_RESULT([ok (${ARCH_MAX}-${VGCONF_OS})])
720         ;;
721      ppc64be-linux)
722         valt_load_address_sec_norml="0xUNSET"
723         valt_load_address_sec_inner="0xUNSET"
724         if test x$vg_cv_only64bit = xyes; then
725            VGCONF_ARCH_PRI="ppc64be"
726            VGCONF_ARCH_SEC=""
727            VGCONF_PLATFORM_PRI_CAPS="PPC64BE_LINUX"
728            VGCONF_PLATFORM_SEC_CAPS=""
729            valt_load_address_pri_norml="0x58000000"
730            valt_load_address_pri_inner="0x38000000"
731         elif test x$vg_cv_only32bit = xyes; then
732            VGCONF_ARCH_PRI="ppc32"
733            VGCONF_ARCH_SEC=""
734            VGCONF_PLATFORM_PRI_CAPS="PPC32_LINUX"
735            VGCONF_PLATFORM_SEC_CAPS=""
736            valt_load_address_pri_norml="0x58000000"
737            valt_load_address_pri_inner="0x38000000"
738         else
739            VGCONF_ARCH_PRI="ppc64be"
740            VGCONF_ARCH_SEC="ppc32"
741            VGCONF_PLATFORM_PRI_CAPS="PPC64BE_LINUX"
742            VGCONF_PLATFORM_SEC_CAPS="PPC32_LINUX"
743            valt_load_address_pri_norml="0x58000000"
744            valt_load_address_pri_inner="0x38000000"
745            valt_load_address_sec_norml="0x58000000"
746            valt_load_address_sec_inner="0x38000000"
747         fi
748         AC_MSG_RESULT([ok (${ARCH_MAX}-${VGCONF_OS})])
749         ;;
750      ppc64le-linux)
751         # Little Endian is only supported on PPC64
752         valt_load_address_sec_norml="0xUNSET"
753         valt_load_address_sec_inner="0xUNSET"
754         VGCONF_ARCH_PRI="ppc64le"
755         VGCONF_ARCH_SEC=""
756         VGCONF_PLATFORM_PRI_CAPS="PPC64LE_LINUX"
757         VGCONF_PLATFORM_SEC_CAPS=""
758         valt_load_address_pri_norml="0x58000000"
759         valt_load_address_pri_inner="0x38000000"
760         AC_MSG_RESULT([ok (${ARCH_MAX}-${VGCONF_OS})])
761        ;;
762      x86-freebsd)
763         VGCONF_ARCH_PRI="x86"
764         VGCONF_ARCH_SEC=""
765         VGCONF_PLATFORM_PRI_CAPS="X86_FREEBSD"
766         VGCONF_PLATFORM_SEC_CAPS=""
767         valt_load_address_pri_norml="0x38000000"
768         valt_load_address_pri_inner="0x28000000"
769         valt_load_address_sec_norml="0xUNSET"
770         valt_load_address_sec_inner="0xUNSET"
771         AC_MSG_RESULT([ok (${ARCH_MAX}-${VGCONF_OS})])
772         ;;
773      amd64-freebsd)
774         if test x$vg_cv_only64bit = xyes; then
775            VGCONF_ARCH_PRI="amd64"
776            VGCONF_ARCH_SEC=""
777            VGCONF_PLATFORM_PRI_CAPS="AMD64_FREEBSD"
778            VGCONF_PLATFORM_SEC_CAPS=""
779         elif test x$vg_cv_only32bit = xyes; then
780            VGCONF_ARCH_PRI="x86"
781            VGCONF_ARCH_SEC=""
782            VGCONF_PLATFORM_PRI_CAPS="X86_FREEBSD"
783            VGCONF_PLATFORM_SEC_CAPS=""
784         else
785            VGCONF_ARCH_PRI="amd64"
786            VGCONF_ARCH_SEC="x86"
787            VGCONF_PLATFORM_PRI_CAPS="AMD64_FREEBSD"
788            VGCONF_PLATFORM_SEC_CAPS="X86_FREEBSD"
789         fi
790         # These work with either base clang or ports installed gcc
791         # Hand rolled compilers probably need INSTALL_DIR/lib (at least for gcc)
792         if test x$is_clang = xclang ; then
793            FLAG_32ON64="-B/usr/lib32"
794         else
795            GCC_MAJOR_VERSION=`${CC} -dumpversion | $SED 's/\..*//' 2>/dev/null`
796            FLAG_32ON64="-B/usr/local/lib32/gcc${GCC_MAJOR_VERSION} -Wl,-rpath,/usr/local/lib32/gcc${GCC_MAJOR_VERSION}/"
797         fi
798         valt_load_address_pri_norml="0x38000000"
799         valt_load_address_pri_inner="0x28000000"
800         valt_load_address_sec_norml="0x38000000"
801         valt_load_address_sec_inner="0x28000000"
802         AC_MSG_RESULT([ok (${ARCH_MAX}-${VGCONF_OS})])
803         ;;
804      # Darwin gets identified as 32-bit even when it supports 64-bit.
805      # (Not sure why, possibly because 'uname' returns "i386"?)  Just about
806      # all Macs support both 32-bit and 64-bit, so we just build both.  If
807      # someone has a really old 32-bit only machine they can (hopefully?)
808      # build with --enable-only32bit.  See bug 243362.
809      x86-darwin|amd64-darwin)
810         ARCH_MAX="amd64"
811         valt_load_address_sec_norml="0xUNSET"
812         valt_load_address_sec_inner="0xUNSET"
813         if test x$vg_cv_only64bit = xyes; then
814            VGCONF_ARCH_PRI="amd64"
815            VGCONF_ARCH_SEC=""
816            VGCONF_PLATFORM_PRI_CAPS="AMD64_DARWIN"
817            VGCONF_PLATFORM_SEC_CAPS=""
818            valt_load_address_pri_norml="0x158000000"
819            valt_load_address_pri_inner="0x138000000"
820         elif test x$vg_cv_only32bit = xyes; then
821            VGCONF_ARCH_PRI="x86"
822            VGCONF_ARCH_SEC=""
823            VGCONF_PLATFORM_PRI_CAPS="X86_DARWIN"
824            VGCONF_PLATFORM_SEC_CAPS=""
825            VGCONF_ARCH_PRI_CAPS="x86"
826            valt_load_address_pri_norml="0x58000000"
827            valt_load_address_pri_inner="0x38000000"
828         else
829            VGCONF_ARCH_PRI="amd64"
830            VGCONF_ARCH_SEC="x86"
831            VGCONF_PLATFORM_PRI_CAPS="AMD64_DARWIN"
832            VGCONF_PLATFORM_SEC_CAPS="X86_DARWIN"
833            valt_load_address_pri_norml="0x158000000"
834            valt_load_address_pri_inner="0x138000000"
835            valt_load_address_sec_norml="0x58000000"
836            valt_load_address_sec_inner="0x38000000"
837         fi
838         AC_MSG_RESULT([ok (${ARCH_MAX}-${VGCONF_OS})])
839         ;;
840      arm-linux) 
841         VGCONF_ARCH_PRI="arm"
842         VGCONF_PLATFORM_PRI_CAPS="ARM_LINUX"
843         VGCONF_PLATFORM_SEC_CAPS=""
844         valt_load_address_pri_norml="0x58000000"
845         valt_load_address_pri_inner="0x38000000"
846         valt_load_address_sec_norml="0xUNSET"
847         valt_load_address_sec_inner="0xUNSET"
848         AC_MSG_RESULT([ok (${host_cpu}-${host_os})])
849         ;;
850      arm64-linux)
851         valt_load_address_sec_norml="0xUNSET"
852         valt_load_address_sec_inner="0xUNSET"
853         if test x$vg_cv_only64bit = xyes; then
854            VGCONF_ARCH_PRI="arm64"
855            VGCONF_ARCH_SEC=""
856            VGCONF_PLATFORM_PRI_CAPS="ARM64_LINUX"
857            VGCONF_PLATFORM_SEC_CAPS=""
858            valt_load_address_pri_norml="0x58000000"
859            valt_load_address_pri_inner="0x38000000"
860         elif test x$vg_cv_only32bit = xyes; then
861            VGCONF_ARCH_PRI="arm"
862            VGCONF_ARCH_SEC=""
863            VGCONF_PLATFORM_PRI_CAPS="ARM_LINUX"
864            VGCONF_PLATFORM_SEC_CAPS=""
865            valt_load_address_pri_norml="0x58000000"
866            valt_load_address_pri_inner="0x38000000"
867         else
868            VGCONF_ARCH_PRI="arm64"
869            VGCONF_ARCH_SEC="arm"
870            VGCONF_PLATFORM_PRI_CAPS="ARM64_LINUX"
871            VGCONF_PLATFORM_SEC_CAPS="ARM_LINUX"
872            valt_load_address_pri_norml="0x58000000"
873            valt_load_address_pri_inner="0x38000000"
874            valt_load_address_sec_norml="0x58000000"
875            valt_load_address_sec_inner="0x38000000"
876         fi
877         AC_MSG_RESULT([ok (${ARCH_MAX}-${VGCONF_OS})])
878         ;;
879      s390x-linux)
880         VGCONF_ARCH_PRI="s390x"
881         VGCONF_ARCH_SEC=""
882         VGCONF_PLATFORM_PRI_CAPS="S390X_LINUX"
883         VGCONF_PLATFORM_SEC_CAPS=""
884         # To improve branch prediction hit rate we want to have
885         # the generated code close to valgrind (host) code
886         valt_load_address_pri_norml="0x800000000"
887         valt_load_address_pri_inner="0x810000000"
888         valt_load_address_sec_norml="0xUNSET"
889         valt_load_address_sec_inner="0xUNSET"
890         AC_MSG_RESULT([ok (${ARCH_MAX}-${VGCONF_OS})])
891         ;;
892      mips32-linux) 
893         VGCONF_ARCH_PRI="mips32"
894         VGCONF_ARCH_SEC=""
895         VGCONF_PLATFORM_PRI_CAPS="MIPS32_LINUX"
896         VGCONF_PLATFORM_SEC_CAPS=""
897         valt_load_address_pri_norml="0x58000000"
898         valt_load_address_pri_inner="0x38000000"
899         valt_load_address_sec_norml="0xUNSET"
900         valt_load_address_sec_inner="0xUNSET"
901         AC_MSG_RESULT([ok (${ARCH_MAX}-${VGCONF_OS})])
902         ;;
903      mips64-linux)
904         valt_load_address_sec_norml="0xUNSET"
905         valt_load_address_sec_inner="0xUNSET"
906         if test x$vg_cv_only64bit = xyes; then
907             VGCONF_ARCH_PRI="mips64"
908             VGCONF_PLATFORM_SEC_CAPS=""
909             VGCONF_PLATFORM_PRI_CAPS="MIPS64_LINUX"
910             VGCONF_PLATFORM_SEC_CAPS=""
911             valt_load_address_pri_norml="0x58000000"
912             valt_load_address_pri_inner="0x38000000"
913         elif test x$vg_cv_only32bit = xyes; then
914             VGCONF_ARCH_PRI="mips32"
915             VGCONF_ARCH_SEC=""
916             VGCONF_PLATFORM_PRI_CAPS="MIPS32_LINUX"
917             VGCONF_PLATFORM_SEC_CAPS=""
918             valt_load_address_pri_norml="0x58000000"
919             valt_load_address_pri_inner="0x38000000"
920         else
921             VGCONF_ARCH_PRI="mips64"
922             VGCONF_ARCH_SEC="mips32"
923             VGCONF_PLATFORM_PRI_CAPS="MIPS64_LINUX"
924             VGCONF_PLATFORM_SEC_CAPS="MIPS32_LINUX"
925             valt_load_address_pri_norml="0x58000000"
926             valt_load_address_pri_inner="0x38000000"
927             valt_load_address_sec_norml="0x58000000"
928             valt_load_address_sec_inner="0x38000000"
929         fi
930         AC_MSG_RESULT([ok (${ARCH_MAX}-${VGCONF_OS})])
931         ;;
932      nanomips-linux)
933         VGCONF_ARCH_PRI="nanomips"
934         VGCONF_ARCH_SEC=""
935         VGCONF_PLATFORM_PRI_CAPS="NANOMIPS_LINUX"
936         VGCONF_PLATFORM_SEC_CAPS=""
937         valt_load_address_pri_norml="0x58000000"
938         valt_load_address_pri_inner="0x38000000"
939         valt_load_address_sec_norml="0xUNSET"
940         valt_load_address_sec_inner="0xUNSET"
941         AC_MSG_RESULT([ok (${ARCH_MAX}-${VGCONF_OS})])
942         ;;
943      x86-solaris)
944         VGCONF_ARCH_PRI="x86"
945         VGCONF_ARCH_SEC=""
946         VGCONF_PLATFORM_PRI_CAPS="X86_SOLARIS"
947         VGCONF_PLATFORM_SEC_CAPS=""
948         valt_load_address_pri_norml="0x58000000"
949         valt_load_address_pri_inner="0x38000000"
950         valt_load_address_sec_norml="0xUNSET"
951         valt_load_address_sec_inner="0xUNSET"
952         AC_MSG_RESULT([ok (${ARCH_MAX}-${VGCONF_OS})])
953         ;;
954      amd64-solaris)
955         valt_load_address_sec_norml="0xUNSET"
956         valt_load_address_sec_inner="0xUNSET"
957         if test x$vg_cv_only64bit = xyes; then
958            VGCONF_ARCH_PRI="amd64"
959            VGCONF_ARCH_SEC=""
960            VGCONF_PLATFORM_PRI_CAPS="AMD64_SOLARIS"
961            VGCONF_PLATFORM_SEC_CAPS=""
962            valt_load_address_pri_norml="0x58000000"
963            valt_load_address_pri_inner="0x38000000"
964         elif test x$vg_cv_only32bit = xyes; then
965            VGCONF_ARCH_PRI="x86"
966            VGCONF_ARCH_SEC=""
967            VGCONF_PLATFORM_PRI_CAPS="X86_SOLARIS"
968            VGCONF_PLATFORM_SEC_CAPS=""
969            valt_load_address_pri_norml="0x58000000"
970            valt_load_address_pri_inner="0x38000000"
971         else
972            VGCONF_ARCH_PRI="amd64"
973            VGCONF_ARCH_SEC="x86"
974            VGCONF_PLATFORM_PRI_CAPS="AMD64_SOLARIS"
975            VGCONF_PLATFORM_SEC_CAPS="X86_SOLARIS"
976            valt_load_address_pri_norml="0x58000000"
977            valt_load_address_pri_inner="0x38000000"
978            valt_load_address_sec_norml="0x58000000"
979            valt_load_address_sec_inner="0x38000000"
980         fi
981         AC_MSG_RESULT([ok (${ARCH_MAX}-${VGCONF_OS})])
982         ;;
983     *)
984         VGCONF_ARCH_PRI="unknown"
985         VGCONF_ARCH_SEC="unknown"
986         VGCONF_PLATFORM_PRI_CAPS="UNKNOWN"
987         VGCONF_PLATFORM_SEC_CAPS="UNKNOWN"
988         valt_load_address_pri_norml="0xUNSET"
989         valt_load_address_pri_inner="0xUNSET"
990         valt_load_address_sec_norml="0xUNSET"
991         valt_load_address_sec_inner="0xUNSET"
992         AC_MSG_RESULT([no (${ARCH_MAX}-${VGCONF_OS})])
993         AC_MSG_ERROR([Valgrind is platform specific. Sorry. Please consider doing a port.])
994         ;;
995 esac
997 #----------------------------------------------------------------------------
999 # Set up VGCONF_ARCHS_INCLUDE_<arch>.  Either one or two of these become
1000 # defined.
1001 AM_CONDITIONAL(VGCONF_ARCHS_INCLUDE_X86,   
1002                test x$VGCONF_PLATFORM_PRI_CAPS = xX86_LINUX \
1003                  -o x$VGCONF_PLATFORM_SEC_CAPS = xX86_LINUX \
1004                  -o x$VGCONF_PLATFORM_PRI_CAPS = xX86_FREEBSD \
1005                  -o x$VGCONF_PLATFORM_SEC_CAPS = xX86_FREEBSD \
1006                  -o x$VGCONF_PLATFORM_PRI_CAPS = xX86_DARWIN \
1007                  -o x$VGCONF_PLATFORM_SEC_CAPS = xX86_DARWIN \
1008                  -o x$VGCONF_PLATFORM_PRI_CAPS = xX86_SOLARIS \
1009                  -o x$VGCONF_PLATFORM_SEC_CAPS = xX86_SOLARIS )
1010 AM_CONDITIONAL(VGCONF_ARCHS_INCLUDE_AMD64, 
1011                test x$VGCONF_PLATFORM_PRI_CAPS = xAMD64_LINUX \
1012                  -o x$VGCONF_PLATFORM_PRI_CAPS = xAMD64_FREEBSD \
1013                  -o x$VGCONF_PLATFORM_PRI_CAPS = xAMD64_DARWIN \
1014                  -o x$VGCONF_PLATFORM_PRI_CAPS = xAMD64_SOLARIS )
1015 AM_CONDITIONAL(VGCONF_ARCHS_INCLUDE_PPC32, 
1016                test x$VGCONF_PLATFORM_PRI_CAPS = xPPC32_LINUX \ 
1017                  -o x$VGCONF_PLATFORM_SEC_CAPS = xPPC32_LINUX )
1018 AM_CONDITIONAL(VGCONF_ARCHS_INCLUDE_PPC64, 
1019                test x$VGCONF_PLATFORM_PRI_CAPS = xPPC64BE_LINUX \
1020                  -o x$VGCONF_PLATFORM_PRI_CAPS = xPPC64LE_LINUX )
1021 AM_CONDITIONAL(VGCONF_ARCHS_INCLUDE_ARM,   
1022                test x$VGCONF_PLATFORM_PRI_CAPS = xARM_LINUX \
1023                  -o x$VGCONF_PLATFORM_SEC_CAPS = xARM_LINUX )
1024 AM_CONDITIONAL(VGCONF_ARCHS_INCLUDE_ARM64, 
1025                test x$VGCONF_PLATFORM_PRI_CAPS = xARM64_LINUX )
1026 AM_CONDITIONAL(VGCONF_ARCHS_INCLUDE_S390X,
1027                test x$VGCONF_PLATFORM_PRI_CAPS = xS390X_LINUX )
1028 AM_CONDITIONAL(VGCONF_ARCHS_INCLUDE_MIPS32,
1029                test x$VGCONF_PLATFORM_PRI_CAPS = xMIPS32_LINUX \
1030                  -o x$VGCONF_PLATFORM_SEC_CAPS = xMIPS32_LINUX )
1031 AM_CONDITIONAL(VGCONF_ARCHS_INCLUDE_MIPS64,
1032                test x$VGCONF_PLATFORM_PRI_CAPS = xMIPS64_LINUX ) 
1033 AM_CONDITIONAL(VGCONF_ARCHS_INCLUDE_NANOMIPS,
1034                test x$VGCONF_PLATFORM_PRI_CAPS = xNANOMIPS_LINUX )
1036 # Set up VGCONF_PLATFORMS_INCLUDE_<platform>.  Either one or two of these
1037 # become defined.
1038 AM_CONDITIONAL(VGCONF_PLATFORMS_INCLUDE_X86_LINUX,   
1039                test x$VGCONF_PLATFORM_PRI_CAPS = xX86_LINUX \
1040                  -o x$VGCONF_PLATFORM_SEC_CAPS = xX86_LINUX)
1041 AM_CONDITIONAL(VGCONF_PLATFORMS_INCLUDE_AMD64_LINUX, 
1042                test x$VGCONF_PLATFORM_PRI_CAPS = xAMD64_LINUX)
1043 AM_CONDITIONAL(VGCONF_PLATFORMS_INCLUDE_PPC32_LINUX, 
1044                test x$VGCONF_PLATFORM_PRI_CAPS = xPPC32_LINUX \ 
1045                  -o x$VGCONF_PLATFORM_SEC_CAPS = xPPC32_LINUX)
1046 AM_CONDITIONAL(VGCONF_PLATFORMS_INCLUDE_PPC64BE_LINUX,
1047                test x$VGCONF_PLATFORM_PRI_CAPS = xPPC64BE_LINUX)
1048 AM_CONDITIONAL(VGCONF_PLATFORMS_INCLUDE_PPC64LE_LINUX,
1049                test x$VGCONF_PLATFORM_PRI_CAPS = xPPC64LE_LINUX)
1050 AM_CONDITIONAL(VGCONF_PLATFORMS_INCLUDE_ARM_LINUX, 
1051                test x$VGCONF_PLATFORM_PRI_CAPS = xARM_LINUX \
1052                  -o x$VGCONF_PLATFORM_SEC_CAPS = xARM_LINUX)
1053 AM_CONDITIONAL(VGCONF_PLATFORMS_INCLUDE_ARM64_LINUX, 
1054                test x$VGCONF_PLATFORM_PRI_CAPS = xARM64_LINUX)
1055 AM_CONDITIONAL(VGCONF_PLATFORMS_INCLUDE_S390X_LINUX,
1056                test x$VGCONF_PLATFORM_PRI_CAPS = xS390X_LINUX \
1057                  -o x$VGCONF_PLATFORM_SEC_CAPS = xS390X_LINUX)
1058 AM_CONDITIONAL(VGCONF_PLATFORMS_INCLUDE_MIPS32_LINUX,
1059                test x$VGCONF_PLATFORM_PRI_CAPS = xMIPS32_LINUX \
1060                  -o x$VGCONF_PLATFORM_SEC_CAPS = xMIPS32_LINUX)
1061 AM_CONDITIONAL(VGCONF_PLATFORMS_INCLUDE_MIPS64_LINUX,
1062                test x$VGCONF_PLATFORM_PRI_CAPS = xMIPS64_LINUX)
1063 AM_CONDITIONAL(VGCONF_PLATFORMS_INCLUDE_NANOMIPS_LINUX,
1064                test x$VGCONF_PLATFORM_PRI_CAPS = xNANOMIPS_LINUX)
1065 AM_CONDITIONAL(VGCONF_PLATFORMS_INCLUDE_X86_FREEBSD,
1066                test x$VGCONF_PLATFORM_PRI_CAPS = xX86_FREEBSD \
1067                  -o x$VGCONF_PLATFORM_SEC_CAPS = xX86_FREEBSD)
1068 AM_CONDITIONAL(VGCONF_PLATFORMS_INCLUDE_AMD64_FREEBSD, 
1069                test x$VGCONF_PLATFORM_PRI_CAPS = xAMD64_FREEBSD)
1070 AM_CONDITIONAL(VGCONF_PLATFORMS_INCLUDE_X86_DARWIN,
1071                test x$VGCONF_PLATFORM_PRI_CAPS = xX86_DARWIN \
1072                  -o x$VGCONF_PLATFORM_SEC_CAPS = xX86_DARWIN)
1073 AM_CONDITIONAL(VGCONF_PLATFORMS_INCLUDE_AMD64_DARWIN, 
1074                test x$VGCONF_PLATFORM_PRI_CAPS = xAMD64_DARWIN)
1075 AM_CONDITIONAL(VGCONF_PLATFORMS_INCLUDE_X86_SOLARIS,
1076                test x$VGCONF_PLATFORM_PRI_CAPS = xX86_SOLARIS \
1077                  -o x$VGCONF_PLATFORM_SEC_CAPS = xX86_SOLARIS)
1078 AM_CONDITIONAL(VGCONF_PLATFORMS_INCLUDE_AMD64_SOLARIS,
1079                test x$VGCONF_PLATFORM_PRI_CAPS = xAMD64_SOLARIS)
1082 # Similarly, set up VGCONF_OS_IS_<os>.  Exactly one of these becomes defined.
1083 # Relies on the assumption that the primary and secondary targets are 
1084 # for the same OS, so therefore only necessary to test the primary.
1085 AM_CONDITIONAL(VGCONF_OS_IS_LINUX,
1086                test x$VGCONF_PLATFORM_PRI_CAPS = xX86_LINUX \
1087                  -o x$VGCONF_PLATFORM_PRI_CAPS = xAMD64_LINUX \
1088                  -o x$VGCONF_PLATFORM_PRI_CAPS = xPPC32_LINUX \
1089                  -o x$VGCONF_PLATFORM_PRI_CAPS = xPPC64BE_LINUX \
1090                  -o x$VGCONF_PLATFORM_PRI_CAPS = xPPC64LE_LINUX \
1091                  -o x$VGCONF_PLATFORM_PRI_CAPS = xARM_LINUX \
1092                  -o x$VGCONF_PLATFORM_PRI_CAPS = xARM64_LINUX \
1093                  -o x$VGCONF_PLATFORM_PRI_CAPS = xS390X_LINUX \
1094                  -o x$VGCONF_PLATFORM_PRI_CAPS = xMIPS32_LINUX \
1095                  -o x$VGCONF_PLATFORM_PRI_CAPS = xMIPS64_LINUX \
1096                  -o x$VGCONF_PLATFORM_PRI_CAPS = xNANOMIPS_LINUX)
1097 AM_CONDITIONAL(VGCONF_OS_IS_FREEBSD,
1098                test x$VGCONF_PLATFORM_PRI_CAPS = xX86_FREEBSD \
1099                  -o x$VGCONF_PLATFORM_PRI_CAPS = xAMD64_FREEBSD)
1100 AM_CONDITIONAL(VGCONF_OS_IS_DARWIN,
1101                test x$VGCONF_PLATFORM_PRI_CAPS = xX86_DARWIN \
1102                  -o x$VGCONF_PLATFORM_PRI_CAPS = xAMD64_DARWIN)
1103 AM_CONDITIONAL(VGCONF_OS_IS_SOLARIS,
1104                test x$VGCONF_PLATFORM_PRI_CAPS = xX86_SOLARIS \
1105                  -o x$VGCONF_PLATFORM_PRI_CAPS = xAMD64_SOLARIS)
1106 AM_CONDITIONAL(VGCONF_OS_IS_DARWIN_OR_FREEBSD,
1107                test x$VGCONF_PLATFORM_PRI_CAPS = xX86_FREEBSD \
1108                  -o x$VGCONF_PLATFORM_PRI_CAPS = xAMD64_FREEBSD \
1109                  -o x$VGCONF_PLATFORM_PRI_CAPS = xX86_DARWIN \
1110                  -o x$VGCONF_PLATFORM_PRI_CAPS = xAMD64_DARWIN)
1113 # Sometimes, in the Makefile.am files, it's useful to know whether or not
1114 # there is a secondary target.
1115 AM_CONDITIONAL(VGCONF_HAVE_PLATFORM_SEC,
1116                test x$VGCONF_PLATFORM_SEC_CAPS != x)
1118 dnl automake-1.10 does not have AM_COND_IF (added in 1.11), so we supply a
1119 dnl fallback definition
1120 dnl The macro is courtesy of Dave Hart:
1121 dnl   https://lists.gnu.org/archive/html/automake/2010-12/msg00045.html
1122 m4_ifndef([AM_COND_IF], [AC_DEFUN([AM_COND_IF], [
1123 if test -z "$$1_TRUE"; then :
1124   m4_n([$2])[]dnl
1125 m4_ifval([$3],
1126 [else
1127   $3
1128 ])dnl
1129 fi[]dnl
1130 ])])
1132 #----------------------------------------------------------------------------
1133 # Inner Valgrind?
1134 #----------------------------------------------------------------------------
1136 # Check if this should be built as an inner Valgrind, to be run within
1137 # another Valgrind.  Choose the load address accordingly.
1138 AC_SUBST(VALT_LOAD_ADDRESS_PRI)
1139 AC_SUBST(VALT_LOAD_ADDRESS_SEC)
1140 AC_CACHE_CHECK([for use as an inner Valgrind], vg_cv_inner,
1141    [AC_ARG_ENABLE(inner, 
1142       [  --enable-inner          enables self-hosting],
1143       [vg_cv_inner=$enableval],
1144       [vg_cv_inner=no])])
1145 if test "$vg_cv_inner" = yes; then
1146     AC_DEFINE([ENABLE_INNER], 1, [configured to run as an inner Valgrind])
1147     VALT_LOAD_ADDRESS_PRI=$valt_load_address_pri_inner
1148     VALT_LOAD_ADDRESS_SEC=$valt_load_address_sec_inner
1149 else
1150     VALT_LOAD_ADDRESS_PRI=$valt_load_address_pri_norml
1151     VALT_LOAD_ADDRESS_SEC=$valt_load_address_sec_norml
1154 #----------------------------------------------------------------------------
1155 # Undefined behaviour sanitiser
1156 #----------------------------------------------------------------------------
1157 # Check whether we should build with the undefined beahviour sanitiser.
1159 AC_CACHE_CHECK([for using the undefined behaviour sanitiser], vg_cv_ubsan,
1160    [AC_ARG_ENABLE(ubsan, 
1161       [  --enable-ubsan          enables the undefined behaviour sanitiser],
1162       [vg_cv_ubsan=$enableval],
1163       [vg_cv_ubsan=no])])
1165 #----------------------------------------------------------------------------
1166 # Extra fine-tuning of installation directories
1167 #----------------------------------------------------------------------------
1168 AC_ARG_WITH(tmpdir,
1169    [  --with-tmpdir=PATH      Specify path for temporary files],
1170    tmpdir="$withval",
1171    tmpdir="/tmp")
1172 AC_DEFINE_UNQUOTED(VG_TMPDIR, "$tmpdir", [Temporary files directory])
1173 AC_SUBST(VG_TMPDIR, [$tmpdir])
1175 #----------------------------------------------------------------------------
1176 # Detect xcode path
1177 #----------------------------------------------------------------------------
1178 AM_COND_IF([VGCONF_OS_IS_DARWIN],
1179 [AC_CHECK_PROG([XCRUN], [xcrun], [yes], [no])
1180 AC_MSG_CHECKING([for xcode sdk include path])
1181 AC_ARG_WITH(xcodedir,
1182    [  --with-xcode-path=PATH      Specify path for xcode sdk includes],
1183    [xcodedir="$withval"],
1184    [
1185       if test "x$XCRUN" != "xno" -a ! -d /usr/include; then
1186          xcrundir=`xcrun --sdk macosx --show-sdk-path`
1187          if test -z "$xcrundir"; then
1188             xcodedir="/usr/include"
1189          else
1190             xcodedir="$xcrundir/usr/include"
1191          fi
1192       else
1193          xcodedir="/usr/include"
1194       fi
1195    ])
1196 AC_MSG_RESULT([$xcodedir])
1197 AC_DEFINE_UNQUOTED(XCODE_DIR, "$xcodedir", [xcode sdk include directory])
1198 AC_SUBST(XCODE_DIR, [$xcodedir])])
1200 #----------------------------------------------------------------------------
1201 # Libc and suppressions
1202 #----------------------------------------------------------------------------
1203 # This variable will collect the suppression files to be used.
1204 AC_SUBST(DEFAULT_SUPP)
1206 AC_CHECK_HEADER([features.h])
1208 if test x$ac_cv_header_features_h = xyes; then
1209   AC_DEFINE([HAVE_HEADER_FEATURES_H], 1,
1210           [Define to 1 if you have the `features.h' header.])
1211   rm -f conftest.$ac_ext
1212   cat <<_ACEOF >conftest.$ac_ext
1213 #include <features.h>
1214 #if defined(__GNU_LIBRARY__) && defined(__GLIBC__) && defined(__GLIBC_MINOR__)
1215 glibc version is: __GLIBC__ __GLIBC_MINOR__
1216 #endif
1217 _ACEOF
1218   GLIBC_VERSION="`$CPP -P conftest.$ac_ext | $SED -n 's/^glibc version is: //p' | $SED 's/ /./g'`"
1221 # not really a version check
1222 AC_EGREP_CPP([DARWIN_LIBC], [
1223 #include <sys/cdefs.h>
1224 #if defined(__DARWIN_VERS_1050)
1225   DARWIN_LIBC
1226 #endif
1228 GLIBC_VERSION="darwin")
1230 AC_EGREP_CPP([FREEBSD_LIBC], [
1231 #include <sys/cdefs.h>
1232 #if defined(__FreeBSD__)
1233   FREEBSD_LIBC
1234 #endif
1236 GLIBC_VERSION="freebsd")
1238 # not really a version check
1239 AC_EGREP_CPP([BIONIC_LIBC], [
1240 #if defined(__ANDROID__)
1241   BIONIC_LIBC
1242 #endif
1244 GLIBC_VERSION="bionic")
1246 # there is only one version of libc on Solaris
1247 if test x$VGCONF_PLATFORM_PRI_CAPS = xX86_SOLARIS \
1248      -o x$VGCONF_PLATFORM_PRI_CAPS = xAMD64_SOLARIS; then
1249     GLIBC_VERSION="solaris"
1252 # GLIBC_VERSION is empty if a musl libc is used, so use the toolchain tuple
1253 # in this case.
1254 if test x$GLIBC_VERSION = x; then
1255     if $CC -dumpmachine | grep -q musl; then
1256         GLIBC_VERSION=musl
1257     fi
1260 # If this is glibc then figure out the generic (in file) libc.so and
1261 # libpthread.so file paths to use in suppressions. Before 2.34 libpthread
1262 # was a separate library, afterwards it was merged into libc.so and
1263 # the library is called libc.so.6 (before it was libc-2.[0-9]+.so).
1264 # Use this fact to set GLIBC_LIBC_PATH and GLIBC_LIBPTHREAD_PATH.
1265 case ${GLIBC_VERSION} in
1267   AC_MSG_CHECKING([whether pthread_create needs libpthread])
1268   AC_LINK_IFELSE([AC_LANG_CALL([], [pthread_create])],
1269   [
1270     AC_MSG_RESULT([no])
1271     GLIBC_LIBC_PATH="*/lib*/libc.so.6"
1272     GLIBC_LIBPTHREAD_PATH="$GLIBC_LIBC_PATH"
1273   ], [
1274     AC_MSG_RESULT([yes])
1275     GLIBC_LIBC_PATH="*/lib*/libc-2.*so*"
1276     GLIBC_LIBPTHREAD_PATH="*/lib*/libpthread-2.*so*"
1277   ])
1278   ;;
1280   AC_MSG_CHECKING([not glibc...])
1281   AC_MSG_RESULT([${GLIBC_VERSION}])
1282   ;;
1283 esac
1285 AC_MSG_CHECKING([the glibc version])
1287 case "${GLIBC_VERSION}" in
1288      2.2)
1289         AC_MSG_RESULT(${GLIBC_VERSION} family)
1290         DEFAULT_SUPP="$srcdir/glibc-2.2.supp ${DEFAULT_SUPP}"
1291         DEFAULT_SUPP="$srcdir/glibc-2.2-LinuxThreads-helgrind.supp ${DEFAULT_SUPP}"
1292         DEFAULT_SUPP="glibc-2.X-drd.supp ${DEFAULT_SUPP}"
1293         ;;
1294      2.[[3-6]])
1295         AC_MSG_RESULT(${GLIBC_VERSION} family)
1296         DEFAULT_SUPP="$srcdir/glibc-${GLIBC_VERSION}.supp ${DEFAULT_SUPP}"
1297         DEFAULT_SUPP="glibc-2.X-helgrind.supp ${DEFAULT_SUPP}"
1298         DEFAULT_SUPP="glibc-2.X-drd.supp ${DEFAULT_SUPP}"
1299         ;;
1300      2.[[7-9]])
1301         AC_MSG_RESULT(${GLIBC_VERSION} family)
1302         DEFAULT_SUPP="glibc-2.X.supp ${DEFAULT_SUPP}"
1303         DEFAULT_SUPP="glibc-2.X-helgrind.supp ${DEFAULT_SUPP}"
1304         DEFAULT_SUPP="glibc-2.X-drd.supp ${DEFAULT_SUPP}"
1305         ;;
1306      2.10|2.11)
1307         AC_MSG_RESULT(${GLIBC_VERSION} family)
1308         AC_DEFINE([GLIBC_MANDATORY_STRLEN_REDIRECT], 1,
1309                   [Define to 1 if strlen() has been optimized heavily (amd64 glibc >= 2.10)])
1310         DEFAULT_SUPP="glibc-2.X.supp ${DEFAULT_SUPP}"
1311         DEFAULT_SUPP="glibc-2.X-helgrind.supp ${DEFAULT_SUPP}"
1312         DEFAULT_SUPP="glibc-2.X-drd.supp ${DEFAULT_SUPP}"
1313         ;;
1314      2.*)
1315         AC_MSG_RESULT(${GLIBC_VERSION} family)
1316         AC_DEFINE([GLIBC_MANDATORY_STRLEN_REDIRECT], 1,
1317                   [Define to 1 if strlen() has been optimized heavily (amd64 glibc >= 2.10)])
1318         AC_DEFINE([GLIBC_MANDATORY_INDEX_AND_STRLEN_REDIRECT], 1,
1319                   [Define to 1 if index() and strlen() have been optimized heavily (x86 glibc >= 2.12)])
1320         DEFAULT_SUPP="glibc-2.X.supp ${DEFAULT_SUPP}"
1321         DEFAULT_SUPP="glibc-2.X-helgrind.supp ${DEFAULT_SUPP}"
1322         DEFAULT_SUPP="glibc-2.X-drd.supp ${DEFAULT_SUPP}"
1323         ;;
1324      darwin)
1325         AC_MSG_RESULT(Darwin)
1326         AC_DEFINE([DARWIN_LIBC], 1, [Define to 1 if you're using Darwin])
1327         # DEFAULT_SUPP set by kernel version check above.
1328         ;;
1329      freebsd)
1330         AC_MSG_RESULT(FreeBSD)
1331         AC_DEFINE([FREEBSD_LIBC], 1, [Define to 1 if you're using FreeBSD])
1332         # DEFAULT_SUPP set by kernel version check above.
1333         ;;
1334      bionic)
1335         AC_MSG_RESULT(Bionic)
1336         AC_DEFINE([BIONIC_LIBC], 1, [Define to 1 if you're using Bionic])
1337         DEFAULT_SUPP="$srcdir/bionic.supp ${DEFAULT_SUPP}"
1338         ;;
1339      solaris)
1340         AC_MSG_RESULT(Solaris)
1341         # DEFAULT_SUPP set in host_os switch-case above.
1342         # No other suppression file is used.
1343         ;;
1344      musl)
1345         AC_MSG_RESULT(Musl)
1346         AC_DEFINE([MUSL_LIBC], 1, [Define to 1 if you're using Musl libc])
1347         DEFAULT_SUPP="$srcdir/musl.supp ${DEFAULT_SUPP}"
1348         ;;
1349      2.0|2.1|*)
1350         AC_MSG_RESULT([unsupported version ${GLIBC_VERSION}])
1351         AC_MSG_ERROR([Valgrind requires glibc version 2.2 or later, uClibc,])
1352         AC_MSG_ERROR([musl libc, Darwin libc, Bionic libc or Solaris libc])
1353         ;;
1354 esac
1356 AC_SUBST(GLIBC_VERSION)
1357 AC_SUBST(GLIBC_LIBC_PATH)
1358 AC_SUBST(GLIBC_LIBPTHREAD_PATH)
1361 if test "$VGCONF_OS" != "solaris"; then
1362     # Add default suppressions for the X client libraries.  Make no
1363     # attempt to detect whether such libraries are installed on the
1364     # build machine (or even if any X facilities are present); just
1365     # add the suppressions antidisirregardless.
1366     DEFAULT_SUPP="$srcdir/xfree-4.supp ${DEFAULT_SUPP}"
1367     DEFAULT_SUPP="$srcdir/xfree-3.supp ${DEFAULT_SUPP}"
1371 #----------------------------------------------------------------------------
1372 # Platform variants?
1373 #----------------------------------------------------------------------------
1375 # Normally the PLAT = (ARCH, OS) characterisation of the platform is enough.
1376 # But there are times where we need a bit more control.  The motivating
1377 # and currently only case is Android: this is almost identical to
1378 # {x86,arm,mips}-linux, but not quite.  So this introduces the concept of
1379 # platform variant tags, which get passed in the compile as
1380 # -DVGPV_<arch>_<os>_<variant> along with the main -DVGP_<arch>_<os> definition.
1382 # In almost all cases, the <variant> bit is "vanilla".  But for Android
1383 # it is "android" instead.
1385 # Consequently (eg), plain arm-linux would build with
1387 #   -DVGP_arm_linux -DVGPV_arm_linux_vanilla
1389 # whilst an Android build would have
1391 #   -DVGP_arm_linux -DVGPV_arm_linux_android
1393 # Same for x86. The setup of the platform variant is pushed relatively far
1394 # down this file in order that we can inspect any of the variables set above.
1396 # In the normal case ..
1397 VGCONF_PLATVARIANT="vanilla"
1399 # Android ?
1400 if test "$GLIBC_VERSION" = "bionic";
1401 then
1402    VGCONF_PLATVARIANT="android"
1405 AC_SUBST(VGCONF_PLATVARIANT)
1408 # FIXME: do we also want to define automake variables
1409 # VGCONF_PLATVARIANT_IS_<WHATEVER>, where WHATEVER is (currently)
1410 # VANILLA or ANDROID ?  This would be in the style of VGCONF_ARCHS_INCLUDE,
1411 # VGCONF_PLATFORMS_INCLUDE and VGCONF_OS_IS above?  Could easily enough
1412 # do that.  Problem is that we can't do and-ing in Makefile.am's, but
1413 # that's what we'd need to do to use this, since what we'd want to write
1414 # is something like
1416 # VGCONF_PLATFORMS_INCLUDE_ARM_LINUX && VGCONF_PLATVARIANT_IS_ANDROID
1418 # Hmm.  Can't think of a nice clean solution to this.
1420 AM_CONDITIONAL(VGCONF_PLATVARIANT_IS_VANILLA,
1421                test x$VGCONF_PLATVARIANT = xvanilla)
1422 AM_CONDITIONAL(VGCONF_PLATVARIANT_IS_ANDROID,
1423                test x$VGCONF_PLATVARIANT = xandroid)
1426 #----------------------------------------------------------------------------
1427 # Checking for various library functions and other definitions
1428 #----------------------------------------------------------------------------
1430 # Check for AT_FDCWD
1432 AC_MSG_CHECKING([for AT_FDCWD])
1433 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1434 #define _GNU_SOURCE
1435 #include <fcntl.h>
1436 #include <unistd.h>
1437 ]], [[
1438   int a = AT_FDCWD;
1439 ]])], [
1440 ac_have_at_fdcwd=yes
1441 AC_MSG_RESULT([yes])
1442 ], [
1443 ac_have_at_fdcwd=no
1444 AC_MSG_RESULT([no])
1447 AM_CONDITIONAL([HAVE_AT_FDCWD], [test x$ac_have_at_fdcwd = xyes])
1449 # Check for stpncpy function definition in string.h
1450 # This explicitly checks with _GNU_SOURCE defined since that is also
1451 # used in the test case (some systems might define it without anyway
1452 # since stpncpy is part of The Open Group Base Specifications Issue 7
1453 # IEEE Std 1003.1-2008.
1454 AC_MSG_CHECKING([for stpncpy])
1455 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
1456 #define _GNU_SOURCE
1457 #include <string.h>
1458 ]], [[
1459   char *d;
1460   char *s;
1461   size_t n = 0;
1462   char *r = stpncpy(d, s, n);
1463 ]])], [
1464 ac_have_gnu_stpncpy=yes
1465 AC_MSG_RESULT([yes])
1466 ], [
1467 ac_have_gnu_stpncpy=no
1468 AC_MSG_RESULT([no])
1471 AM_CONDITIONAL([HAVE_GNU_STPNCPY], [test x$ac_have_gnu_stpncpy = xyes])
1473 # Check for PTRACE_GETREGS
1475 AC_MSG_CHECKING([for PTRACE_GETREGS])
1476 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1477 #include <stdlib.h>
1478 #include <stddef.h>
1479 #include <sys/ptrace.h>
1480 #include <sys/user.h>
1481 ]], [[
1482   void *p;
1483   long res = ptrace (PTRACE_GETREGS, 0, p, p);
1484 ]])], [
1485 AC_MSG_RESULT([yes])
1486 AC_DEFINE([HAVE_PTRACE_GETREGS], 1,
1487           [Define to 1 if you have the `PTRACE_GETREGS' ptrace request.])
1488 ], [
1489 AC_MSG_RESULT([no])
1493 # Check for CLOCK_MONOTONIC
1495 AC_MSG_CHECKING([for CLOCK_MONOTONIC])
1497 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1498 #include <time.h>
1499 ]], [[
1500   struct timespec t;
1501   clock_gettime(CLOCK_MONOTONIC, &t);
1502   return 0;
1503 ]])], [
1504 AC_MSG_RESULT([yes])
1505 AC_DEFINE([HAVE_CLOCK_MONOTONIC], 1,
1506           [Define to 1 if you have the `CLOCK_MONOTONIC' constant.])
1507 ], [
1508 AC_MSG_RESULT([no])
1512 # Check for ELF32/64_CHDR
1514 AC_CHECK_TYPES([Elf32_Chdr, Elf64_Chdr], [], [], [[#include <elf.h>]])
1517 # Check for PTHREAD_RWLOCK_T
1519 AC_MSG_CHECKING([for pthread_rwlock_t])
1521 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1522 #define _GNU_SOURCE
1523 #include <pthread.h>
1524 ]], [[
1525   pthread_rwlock_t rwl;
1526 ]])], [
1527 AC_MSG_RESULT([yes])
1528 AC_DEFINE([HAVE_PTHREAD_RWLOCK_T], 1,
1529           [Define to 1 if you have the `pthread_rwlock_t' type.])
1530 ], [
1531 AC_MSG_RESULT([no])
1534 # Check for CLOCKID_T
1536 AC_MSG_CHECKING([for clockid_t])
1538 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1539 #include <time.h>
1540 ]], [[
1541   clockid_t c;
1542 ]])], [
1543 AC_MSG_RESULT([yes])
1544 AC_DEFINE([HAVE_CLOCKID_T], 1,
1545           [Define to 1 if you have the `clockid_t' type.])
1546 ], [
1547 AC_MSG_RESULT([no])
1550 # Check for PTHREAD_MUTEX_ADAPTIVE_NP
1552 AC_MSG_CHECKING([for PTHREAD_MUTEX_ADAPTIVE_NP])
1554 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1555 #define _GNU_SOURCE
1556 #include <pthread.h>
1557 ]], [[
1558   return (PTHREAD_MUTEX_ADAPTIVE_NP);
1559 ]])], [
1560 AC_MSG_RESULT([yes])
1561 AC_DEFINE([HAVE_PTHREAD_MUTEX_ADAPTIVE_NP], 1,
1562           [Define to 1 if you have the `PTHREAD_MUTEX_ADAPTIVE_NP' constant.])
1563 ], [
1564 AC_MSG_RESULT([no])
1568 # Check for PTHREAD_MUTEX_ERRORCHECK_NP
1570 AC_MSG_CHECKING([for PTHREAD_MUTEX_ERRORCHECK_NP])
1572 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1573 #define _GNU_SOURCE
1574 #include <pthread.h>
1575 ]], [[
1576   return (PTHREAD_MUTEX_ERRORCHECK_NP);
1577 ]])], [
1578 AC_MSG_RESULT([yes])
1579 AC_DEFINE([HAVE_PTHREAD_MUTEX_ERRORCHECK_NP], 1,
1580           [Define to 1 if you have the `PTHREAD_MUTEX_ERRORCHECK_NP' constant.])
1581 ], [
1582 AC_MSG_RESULT([no])
1586 # Check for PTHREAD_MUTEX_RECURSIVE_NP
1588 AC_MSG_CHECKING([for PTHREAD_MUTEX_RECURSIVE_NP])
1590 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1591 #define _GNU_SOURCE
1592 #include <pthread.h>
1593 ]], [[
1594   return (PTHREAD_MUTEX_RECURSIVE_NP);
1595 ]])], [
1596 AC_MSG_RESULT([yes])
1597 AC_DEFINE([HAVE_PTHREAD_MUTEX_RECURSIVE_NP], 1,
1598           [Define to 1 if you have the `PTHREAD_MUTEX_RECURSIVE_NP' constant.])
1599 ], [
1600 AC_MSG_RESULT([no])
1604 # Check for PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
1606 AC_MSG_CHECKING([for PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP])
1608 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1609 #define _GNU_SOURCE
1610 #include <pthread.h>
1611 ]], [[
1612   pthread_mutex_t m = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
1613   return 0;
1614 ]])], [
1615 AC_MSG_RESULT([yes])
1616 AC_DEFINE([HAVE_PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP], 1,
1617           [Define to 1 if you have the `PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP' constant.])
1618 ], [
1619 AC_MSG_RESULT([no])
1623 # Check whether pthread_mutex_t has a member called __m_kind.
1625 AC_CHECK_MEMBER([pthread_mutex_t.__m_kind],
1626                 [AC_DEFINE([HAVE_PTHREAD_MUTEX_T__M_KIND],
1627                            1,                                   
1628                            [Define to 1 if pthread_mutex_t has a member called __m_kind.])
1629                 ],
1630                 [],
1631                 [#include <pthread.h>])
1634 # Check whether pthread_mutex_t has a member called __data.__kind.
1636 AC_CHECK_MEMBER([pthread_mutex_t.__data.__kind],
1637                 [AC_DEFINE([HAVE_PTHREAD_MUTEX_T__DATA__KIND],
1638                           1,
1639                           [Define to 1 if pthread_mutex_t has a member __data.__kind.])
1640                 ],
1641                 [],
1642                 [#include <pthread.h>])
1644 # Convenience function.  Set flags based on the existing HWCAP entries.
1645 # The AT_HWCAP entries are generated by glibc, and are based on
1646 # functions supported by the hardware/system/libc.
1647 # Subsequent support for whether the capability will actually be utilized
1648 # will also be checked against the compiler capabilities.
1649 # called as
1650 #      AC_HWCAP_CONTAINS_FLAG[hwcap_string_to_match],[VARIABLE_TO_SET]
1651 AC_DEFUN([AC_HWCAP_CONTAINS_FLAG],[
1652   AUXV_CHECK_FOR=$1
1653   AC_MSG_CHECKING([if AT_HWCAP contains the $AUXV_CHECK_FOR indicator])
1654   if env LD_SHOW_AUXV=1 true | grep ^AT_HWCAP | grep -q -w ${AUXV_CHECK_FOR}
1655   then
1656     AC_MSG_RESULT([yes])
1657     AC_SUBST([$2],[yes])
1658   else
1659     AC_MSG_RESULT([no])
1660     AC_SUBST([$2],[])
1661   fi
1664 # gather hardware capabilities. (hardware/kernel/libc)
1665 AC_HWCAP_CONTAINS_FLAG([altivec],[HWCAP_HAS_ALTIVEC])
1666 AC_HWCAP_CONTAINS_FLAG([vsx],[HWCAP_HAS_VSX])
1667 AC_HWCAP_CONTAINS_FLAG([dfp],[HWCAP_HAS_DFP])
1668 AC_HWCAP_CONTAINS_FLAG([arch_2_05],[HWCAP_HAS_ISA_2_05])
1669 AC_HWCAP_CONTAINS_FLAG([arch_2_06],[HWCAP_HAS_ISA_2_06])
1670 AC_HWCAP_CONTAINS_FLAG([arch_2_07],[HWCAP_HAS_ISA_2_07])
1671 AC_HWCAP_CONTAINS_FLAG([arch_3_00],[HWCAP_HAS_ISA_3_00])
1672 AC_HWCAP_CONTAINS_FLAG([arch_3_1],[HWCAP_HAS_ISA_3_1])
1673 AC_HWCAP_CONTAINS_FLAG([htm],[HWCAP_HAS_HTM])
1674 AC_HWCAP_CONTAINS_FLAG([mma],[HWCAP_HAS_MMA])
1676 # ISA Levels
1677 AM_CONDITIONAL(HAS_ISA_2_05, [test x$HWCAP_HAS_ISA_2_05 = xyes])
1678 AM_CONDITIONAL(HAS_ISA_2_06, [test x$HWCAP_HAS_ISA_2_06 = xyes])
1679 # compiler support for isa 2.07 level instructions
1680 AC_MSG_CHECKING([that assembler knows ISA 2.07 instructions ])
1681 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1682 ]], [[
1683   __asm__ __volatile__("mtvsrd 1,2 ");
1684 ]])], [
1685 ac_asm_have_isa_2_07=yes
1686 AC_MSG_RESULT([yes])
1687 ], [
1688 ac_asm_have_isa_2_07=no
1689 AC_MSG_RESULT([no])
1691 AM_CONDITIONAL(HAS_ISA_2_07, [test x$ac_asm_have_isa_2_07 = xyes \
1692                                -a x$HWCAP_HAS_ISA_2_07 = xyes])
1694 # altivec (vsx) support.
1695 # does this compiler support -maltivec and does it have the include file
1696 # <altivec.h> ?
1697 AC_MSG_CHECKING([for Altivec support in the compiler ])
1698 safe_CFLAGS=$CFLAGS
1699 CFLAGS="-maltivec -Werror"
1700 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1701 #include <altivec.h>
1702 ]], [[
1703   vector unsigned int v;
1704 ]])], [
1705 ac_have_altivec=yes
1706 AC_MSG_RESULT([yes])
1707 ], [
1708 ac_have_altivec=no
1709 AC_MSG_RESULT([no])
1711 CFLAGS=$safe_CFLAGS
1712 AM_CONDITIONAL([HAS_ALTIVEC], [test x$ac_have_altivec = xyes \
1713                                  -a x$HWCAP_HAS_ALTIVEC = xyes])
1715 # Check that both: the compiler supports -mvsx and that the assembler
1716 # understands VSX instructions.  If either of those doesn't work,
1717 # conclude that we can't do VSX.
1718 AC_MSG_CHECKING([for VSX compiler flag support])
1719 safe_CFLAGS=$CFLAGS
1720 CFLAGS="-mvsx -Werror"
1721 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1722 ]], [[
1723 ]])], [
1724 ac_compiler_supports_vsx_flag=yes
1725 AC_MSG_RESULT([yes])
1726 ], [
1727 ac_compiler_supports_vsx_flag=no
1728 AC_MSG_RESULT([no])
1730 CFLAGS=$safe_CFLAGS
1732 AC_MSG_CHECKING([for VSX support in the assembler ])
1733 safe_CFLAGS=$CFLAGS
1734 CFLAGS="-mvsx -Werror"
1735 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1736 #include <altivec.h>
1737 ]], [[
1738   vector unsigned int v;
1739   __asm__ __volatile__("xsmaddadp 32, 32, 33" ::: "memory","cc");
1740 ]])], [
1741 ac_compiler_supports_vsx=yes
1742 AC_MSG_RESULT([yes])
1743 ], [
1744 ac_compiler_supports_vsx=no
1745 AC_MSG_RESULT([no])
1747 CFLAGS=$safe_CFLAGS
1748 AM_CONDITIONAL([HAS_VSX], [test x$ac_compiler_supports_vsx_flag = xyes \
1749                              -a x$ac_compiler_supports_vsx = xyes \
1750                              -a x$HWCAP_HAS_VSX = xyes ])
1752 # DFP (Decimal Float)
1753 # The initial DFP support was added in Power 6.  The dcffix instruction
1754 # support was added in Power 7.
1755 AC_MSG_CHECKING([that assembler knows DFP])
1756 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1757 ]], [[
1758   #ifdef __s390__
1759   __asm__ __volatile__("adtr 1, 2, 3")
1760   #else
1761 __asm__ __volatile__(".machine power7;\n" \
1762   "dadd 1, 2, 3;\n" \
1763   "dcffix 1, 2");
1764   #endif
1765 ]])], [
1766 ac_asm_have_dfp=yes
1767 AC_MSG_RESULT([yes])
1768 ], [
1769 ac_asm_have_dfp=no
1770 AC_MSG_RESULT([no])
1772 AC_MSG_CHECKING([that compiler knows -mhard-dfp switch])
1773 safe_CFLAGS=$CFLAGS
1774 CFLAGS="-mhard-dfp -Werror"
1776 # The dcffix instruction is Power 7
1777 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1778 ]], [[
1779   #ifdef __s390__
1780   __asm__ __volatile__("adtr 1, 2, 3")
1781   #else
1782   __asm__ __volatile__(".machine power7;\n" \
1783   "dadd 1, 2, 3;\n" \
1784   "dcffix 1, 2");
1785   #endif
1786 ]])], [
1787 ac_compiler_have_dfp=yes
1788 AC_MSG_RESULT([yes])
1789 ], [
1790 ac_compiler_have_dfp=no
1791 AC_MSG_RESULT([no])
1793 CFLAGS=$safe_CFLAGS
1794 AM_CONDITIONAL(HAS_DFP, test x$ac_asm_have_dfp = xyes \
1795                           -a x$ac_compiler_have_dfp = xyes \
1796                           -a x$HWCAP_HAS_DFP = xyes )
1798 AC_MSG_CHECKING([that compiler knows DFP datatypes])
1799 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1800 ]], [[
1801   _Decimal64 x = 0.0DD;
1802 ]])], [
1803 ac_compiler_have_dfp_type=yes
1804 AC_MSG_RESULT([yes])
1805 ], [
1806 ac_compiler_have_dfp_type=no
1807 AC_MSG_RESULT([no])
1809 AM_CONDITIONAL(BUILD_DFP_TESTS, test x$ac_compiler_have_dfp_type = xyes \
1810                                   -a x$HWCAP_HAS_DFP = xyes )
1813 # HTM (Hardware Transactional Memory)
1814 AC_MSG_CHECKING([if compiler accepts the -mhtm flag])
1815 safe_CFLAGS=$CFLAGS
1816 CFLAGS="-mhtm -Werror"
1817 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1818 ]], [[
1819   return 0;
1820 ]])], [
1821 AC_MSG_RESULT([yes])
1822 ac_compiler_supports_htm=yes
1823 ], [
1824 AC_MSG_RESULT([no])
1825 ac_compiler_supports_htm=no
1827 CFLAGS=$safe_CFLAGS
1829 AC_MSG_CHECKING([if compiler can find the htm builtins])
1830 safe_CFLAGS=$CFLAGS
1831 CFLAGS="-mhtm -Werror"
1832  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1833  ]], [[
1834    if (__builtin_tbegin (0))
1835       __builtin_tend (0);
1836  ]])], [
1837  AC_MSG_RESULT([yes])
1838 ac_compiler_sees_htm_builtins=yes
1839  ], [
1840  AC_MSG_RESULT([no])
1841 ac_compiler_sees_htm_builtins=no
1842  ])
1843 CFLAGS=$safe_CFLAGS
1845 AM_CONDITIONAL(SUPPORTS_HTM, test x$ac_compiler_supports_htm = xyes \
1846                                -a x$ac_compiler_sees_htm_builtins = xyes \
1847                                -a x$HWCAP_HAS_HTM = xyes )
1849 # isa 3.0 checking. (actually 3.0 or newer)
1850 AC_MSG_CHECKING([that assembler knows ISA 3.00 ])
1852 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1853 ]], [[
1854 __asm__ __volatile__ (".machine power9;\n" \
1855         "cnttzw   1,3; \n" );
1856 ]])], [
1857 # guest_ppc_helpers.c needs the HAS_ISA_3_OO to enable copy, paste,
1858 # cpabort support
1859 safe_CFLAGS=$CFLAGS
1860 CFLAGS="-DHAS_ISA_3_00"
1861 ac_asm_have_isa_3_00=yes
1862 AC_MSG_RESULT([yes])
1863 ], [
1864 ac_asm_have_isa_3_00=no
1865 AC_MSG_RESULT([no])
1867 CFLAGS=$safe_CFLAGS
1869 # xscvhpdp checking
1870 AC_MSG_CHECKING([that assembler knows xscvhpdp ])
1872 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1873 ]], [[
1874 __asm__ __volatile__ (".machine power9;\n" \
1875         "xscvhpdp 1,2;\n" );
1876 ]])], [
1877 ac_asm_have_xscvhpdp=yes
1878 AC_MSG_RESULT([yes])
1879 ], [
1880 ac_asm_have_xscvhpdp=no
1881 AC_MSG_RESULT([no])
1884 # darn instruction checking
1885 AC_MSG_CHECKING([that assembler knows darn instruction ])
1887 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1888 ]], [[
1889   __asm__ __volatile__(".machine power9; darn 1,0 ");
1890 ]])], [
1891 ac_asm_have_darn_inst=yes
1892 AC_MSG_RESULT([yes])
1893 ], [
1894 ac_asm_have_darn_inst=no
1895 AC_MSG_RESULT([no])
1898 # isa 3.01 checking
1899 AC_MSG_CHECKING([that assembler knows ISA 3.1 ])
1900 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1901 ]], [[
1902 __asm__ __volatile__ (".machine power10;\n" \
1903         "brh 1,2;\n ");
1904 ]])], [
1905 ac_asm_have_isa_3_1=yes
1906 AC_MSG_RESULT([yes])
1907 ], [
1908 ac_asm_have_isa_3_1=no
1909 AC_MSG_RESULT([no])
1913 AM_CONDITIONAL(HAS_ISA_3_00, [test x$ac_asm_have_isa_3_00 = xyes \
1914                              -a x$HWCAP_HAS_ISA_3_00 = xyes])
1916 AM_CONDITIONAL(HAS_XSCVHPDP, [test x$ac_asm_have_xscvhpdp = xyes])
1917 AM_CONDITIONAL(HAS_DARN, [test x$ac_asm_have_darn_inst = xyes])
1919 AM_CONDITIONAL(HAS_ISA_3_1, [test x$ac_asm_have_isa_3_1 = xyes \
1920                              -a x$HWCAP_HAS_ISA_3_1 = xyes])
1922 # Check for pthread_create@GLIBC2.0
1923 AC_MSG_CHECKING([for pthread_create@GLIBC2.0()])
1925 safe_CFLAGS=$CFLAGS
1926 CFLAGS="-lpthread -Werror"
1927 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
1928 extern int pthread_create_glibc_2_0(void*, const void*,
1929                                     void *(*)(void*), void*);
1930 __asm__(".symver pthread_create_glibc_2_0, pthread_create@GLIBC_2.0");
1931 ]], [[
1932 #ifdef __powerpc__
1934  * Apparently on PowerPC linking this program succeeds and generates an
1935  * executable with the undefined symbol pthread_create@GLIBC_2.0.
1936  */
1937 #error This test does not work properly on PowerPC.
1938 #else
1939   pthread_create_glibc_2_0(0, 0, 0, 0);
1940 #endif
1941   return 0;
1942 ]])], [
1943 ac_have_pthread_create_glibc_2_0=yes
1944 AC_MSG_RESULT([yes])
1945 AC_DEFINE([HAVE_PTHREAD_CREATE_GLIBC_2_0], 1,
1946           [Define to 1 if you have the `pthread_create@glibc2.0' function.])
1947 ], [
1948 ac_have_pthread_create_glibc_2_0=no
1949 AC_MSG_RESULT([no])
1951 CFLAGS=$safe_CFLAGS
1953 AM_CONDITIONAL(HAVE_PTHREAD_CREATE_GLIBC_2_0,
1954                test x$ac_have_pthread_create_glibc_2_0 = xyes)
1957 # Check for dlinfo RTLD_DI_TLS_MODID
1958 AC_MSG_CHECKING([for dlinfo RTLD_DI_TLS_MODID])
1960 safe_LIBS="$LIBS"
1961 LIBS="-ldl"
1962 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
1963 #ifndef _GNU_SOURCE
1964 #define _GNU_SOURCE
1965 #endif
1966 #include <link.h>
1967 #include <dlfcn.h>
1968 ]], [[
1969   size_t sizes[10000];
1970   size_t modid_offset;
1971   (void) dlinfo ((void*)sizes, RTLD_DI_TLS_MODID, &modid_offset);
1972   return 0;
1973 ]])], [
1974 ac_have_dlinfo_rtld_di_tls_modid=yes
1975 AC_MSG_RESULT([yes])
1976 AC_DEFINE([HAVE_DLINFO_RTLD_DI_TLS_MODID], 1,
1977           [Define to 1 if you have a dlinfo that can do RTLD_DI_TLS_MODID.])
1978 ], [
1979 ac_have_dlinfo_rtld_di_tls_modid=no
1980 AC_MSG_RESULT([no])
1982 LIBS=$safe_LIBS
1984 AM_CONDITIONAL(HAVE_DLINFO_RTLD_DI_TLS_MODID,
1985                test x$ac_have_dlinfo_rtld_di_tls_modid = xyes)
1988 # Check for eventfd_t, eventfd() and eventfd_read()
1989 AC_MSG_CHECKING([for eventfd()])
1991 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
1992 #include <sys/eventfd.h>
1993 ]], [[
1994   eventfd_t ev;
1995   int fd;
1997   fd = eventfd(5, 0);
1998   eventfd_read(fd, &ev);
1999   return 0;
2000 ]])], [
2001 AC_MSG_RESULT([yes])
2002 AC_DEFINE([HAVE_EVENTFD], 1,
2003           [Define to 1 if you have the `eventfd' function.])
2004 AC_DEFINE([HAVE_EVENTFD_READ], 1,
2005           [Define to 1 if you have the `eventfd_read' function.])
2006 ], [
2007 AC_MSG_RESULT([no])
2010 # Check whether compiler can process #include <thread> without errors
2011 # clang 3.3 cannot process <thread> from e.g.
2012 # gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3
2014 AC_MSG_CHECKING([that C++ compiler can compile C++17 code])
2015 AC_LANG(C++)
2016 safe_CXXFLAGS=$CXXFLAGS
2017 CXXFLAGS=-std=c++17
2019 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
2020 int x;
2021 ])],
2023 ac_have_cxx_17=yes
2024 AC_MSG_RESULT([yes])
2025 ], [
2026 ac_have_cxx_17=no
2027 AC_MSG_RESULT([no])
2029 CXXFLAGS=$safe_CXXFLAGS
2030 AC_LANG(C)
2032 AM_CONDITIONAL(HAVE_CXX17, test x$ac_have_cxx_17 = xyes)
2034 AC_MSG_CHECKING([that C++ compiler can include <thread> header file])
2035 AC_LANG(C++)
2036 safe_CXXFLAGS=$CXXFLAGS
2037 CXXFLAGS=-std=c++0x
2039 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
2040 #include <thread> 
2041 ])],
2043 ac_cxx_can_include_thread_header=yes
2044 AC_MSG_RESULT([yes])
2045 ], [
2046 ac_cxx_can_include_thread_header=no
2047 AC_MSG_RESULT([no])
2049 CXXFLAGS=$safe_CXXFLAGS
2050 AC_LANG(C)
2052 AM_CONDITIONAL(CXX_CAN_INCLUDE_THREAD_HEADER, test x$ac_cxx_can_include_thread_header = xyes)
2054 # Check whether compiler can process #include <condition_variable> without errors
2056 AC_MSG_CHECKING([that C++ compiler can include <condition_variable> header file])
2057 AC_LANG(C++)
2058 safe_CXXFLAGS=$CXXFLAGS
2059 CXXFLAGS=-std=c++0x
2061 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
2062 #include <condition_variable> 
2063 ])],
2065 ac_cxx_can_include_condition_variable_header=yes
2066 AC_MSG_RESULT([yes])
2067 ], [
2068 ac_cxx_can_include_condition_variable_header=no
2069 AC_MSG_RESULT([no])
2071 CXXFLAGS=$safe_CXXFLAGS
2072 AC_LANG(C)
2074 AM_CONDITIONAL(CXX_CAN_INCLUDE_CONDITION_VARIABLE_HEADER, test x$ac_cxx_can_include_condition_variable_header = xyes)
2076 # check for std::shared_timed_mutex, this is a C++ 14 feature
2078 AC_MSG_CHECKING([that C++ compiler can use std::shared_timed_mutex])
2079 AC_LANG(C++)
2080 safe_CXXFLAGS=$CXXFLAGS
2081 CXXFLAGS="-std=c++1y -pthread"
2083 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
2084 #include <shared_mutex>
2085 std::shared_timed_mutex test_mutex;
2086 ])],
2088 ac_cxx_can_use_shared_timed_mutex=yes
2089 AC_MSG_RESULT([yes])
2090 ], [
2091 ac_cxx_can_use_shared_timed_mutex=no
2092 AC_MSG_RESULT([no])
2094 CXXFLAGS=$safe_CXXFLAGS
2095 AC_LANG(C)
2097 AM_CONDITIONAL(CXX_CAN_USE_SHARED_TIMED_MUTEX, test x$ac_cxx_can_use_shared_timed_mutex = xyes)
2099 # check for std::shared_mutex, this is a C++ 11 feature
2101 AC_MSG_CHECKING([that C++ compiler can use std::timed_mutex])
2102 AC_LANG(C++)
2103 safe_CXXFLAGS=$CXXFLAGS
2104 CXXFLAGS="-std=c++0x -pthread"
2106 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
2107 #include <mutex>
2108 std::timed_mutex test_mutex;
2109 ])],
2111 ac_cxx_can_use_timed_mutex=yes
2112 AC_MSG_RESULT([yes])
2113 ], [
2114 ac_cxx_can_use_timed_mutex=no
2115 AC_MSG_RESULT([no])
2117 CXXFLAGS=$safe_CXXFLAGS
2118 AC_LANG(C)
2120 AM_CONDITIONAL(CXX_CAN_USE_TIMED_MUTEX, test x$ac_cxx_can_use_timed_mutex = xyes)
2122 # On aarch64 before glibc 2.20 we would get the kernel user_pt_regs instead
2123 # of the user_regs_struct from sys/user.h. They are structurally the same
2124 # but we get either one or the other.
2126 AC_CHECK_TYPE([struct user_regs_struct],
2127               [sys_user_has_user_regs=yes], [sys_user_has_user_regs=no],
2128               [[#include <sys/ptrace.h>]
2129                [#include <sys/time.h>]
2130                [#include <sys/user.h>]])
2131 if test "$sys_user_has_user_regs" = "yes"; then
2132   AC_DEFINE(HAVE_SYS_USER_REGS, 1,
2133             [Define to 1 if <sys/user.h> defines struct user_regs_struct])
2136 AC_MSG_CHECKING([for __NR_membarrier])
2137 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
2138 #include <linux/unistd.h>
2139 ]], [[
2140 return __NR_membarrier
2141 ]])], [
2142 ac_have_nr_membarrier=yes
2143 AC_MSG_RESULT([yes])
2144 ], [
2145 ac_have_nr_membarrier=no
2146 AC_MSG_RESULT([no])
2149 AM_CONDITIONAL(HAVE_NR_MEMBARRIER, [test x$ac_have_nr_membarrier = xyes])
2151 #----------------------------------------------------------------------------
2152 # Checking for supported compiler flags.
2153 #----------------------------------------------------------------------------
2155 case "${host_cpu}" in
2156     mips*)
2157         ARCH=$(echo "$CFLAGS" | grep -E -e '-march=@<:@^ @:>@+' -e '\B-mips@<:@^ +@:>@')
2158         if test -z "$ARCH"; then
2159           # does this compiler support -march=mips32 (mips32 default) ?
2160           AC_MSG_CHECKING([if gcc accepts -march=mips32 -mabi=32])
2162           safe_CFLAGS=$CFLAGS
2163           CFLAGS="$CFLAGS -mips32 -mabi=32 -Werror"
2165           AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
2166             return 0;
2167           ]])], [
2168           FLAG_M32="-mips32 -mabi=32"
2169           AC_MSG_RESULT([yes])
2170           ], [
2171           FLAG_M32=""
2172           AC_MSG_RESULT([no])
2173           ])
2174           CFLAGS=$safe_CFLAGS
2176           AC_SUBST(FLAG_M32)
2179           # does this compiler support -march=mips64r2 (mips64r2 default) ?
2180           AC_MSG_CHECKING([if gcc accepts -march=mips64r2 -mabi=64])
2182           safe_CFLAGS=$CFLAGS
2183           CFLAGS="$CFLAGS -march=mips64r2 -mabi=64 -Werror"
2185           AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
2186             return 0;
2187           ]])], [
2188           FLAG_M64="-march=mips64r2 -mabi=64"
2189           AC_MSG_RESULT([yes])
2190           ], [
2191           FLAG_M64=""
2192           AC_MSG_RESULT([no])
2193           ])
2194           CFLAGS=$safe_CFLAGS
2196           AC_SUBST(FLAG_M64)
2197         fi
2198         ;;
2199     nanomips*)
2200         ;;
2201     *)
2202         # does this compiler support -m32 ?
2203         AC_MSG_CHECKING([if gcc accepts -m32])
2205         safe_CFLAGS=$CFLAGS
2206         CFLAGS="${FLAG_32ON64} -m32 -Werror"
2208         AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
2209           return 0;
2210         ]])], [
2211         FLAG_M32="${FLAG_32ON64} -m32"
2212         AC_MSG_RESULT([yes])
2213         ], [
2214         FLAG_M32=""
2215         AC_MSG_RESULT([no])
2216         ])
2217         CFLAGS=$safe_CFLAGS
2219         AC_SUBST(FLAG_M32)
2222         # does this compiler support -m64 ?
2223         AC_MSG_CHECKING([if gcc accepts -m64])
2225         safe_CFLAGS=$CFLAGS
2226         CFLAGS="-m64 -Werror"
2228         AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
2229           return 0;
2230         ]])], [
2231         FLAG_M64="-m64"
2232         AC_MSG_RESULT([yes])
2233         ], [
2234         FLAG_M64=""
2235         AC_MSG_RESULT([no])
2236         ])
2237         CFLAGS=$safe_CFLAGS
2239         AC_SUBST(FLAG_M64)
2240         ;;
2241 esac
2244 ARCH=$(echo "$CFLAGS" | grep -E -e '-march=@<:@^ @:>@+' -e '\B-mips@<:@^ +@:>@')
2245 if test -z "$ARCH"; then
2246   # does this compiler support -march=octeon (Cavium OCTEON I Specific) ?
2247   AC_MSG_CHECKING([if gcc accepts -march=octeon])
2249   safe_CFLAGS=$CFLAGS
2250   CFLAGS="$CFLAGS $FLAG_M64 -march=octeon -Werror"
2252   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
2253     return 0;
2254   ]])], [
2255   FLAG_OCTEON="-march=octeon"
2256   AC_MSG_RESULT([yes])
2257   ], [
2258   FLAG_OCTEON=""
2259   AC_MSG_RESULT([no])
2260   ])
2261   CFLAGS=$safe_CFLAGS
2263   AC_SUBST(FLAG_OCTEON)
2266   # does this compiler support -march=octeon2 (Cavium OCTEON II Specific) ?
2267   AC_MSG_CHECKING([if gcc accepts -march=octeon2])
2269   safe_CFLAGS=$CFLAGS
2270   CFLAGS="$CFLAGS $FLAG_M64 -march=octeon2 -Werror"
2272   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
2273     return 0;
2274   ]])], [
2275   FLAG_OCTEON2="-march=octeon2"
2276   AC_MSG_RESULT([yes])
2277   ], [
2278   FLAG_OCTEON2=""
2279   AC_MSG_RESULT([no])
2280   ])
2281   CFLAGS=$safe_CFLAGS
2283   AC_SUBST(FLAG_OCTEON2)
2287 # does this compiler support -mmsa (MIPS MSA ASE) ?
2288 AC_MSG_CHECKING([if gcc accepts -mmsa])
2290 safe_CFLAGS=$CFLAGS
2291 CFLAGS="$CFLAGS -mmsa -Werror"
2293 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
2294     return 0;
2295 ]])], [
2296 FLAG_MSA="-mmsa"
2297 AC_MSG_RESULT([yes])
2298 ], [
2299 FLAG_MSA=""
2300 AC_MSG_RESULT([no])
2302 CFLAGS=$safe_CFLAGS
2304 AC_SUBST(FLAG_MSA)
2306 # Are we compiling for the MIPS64 n32 ABI?
2307 AC_MSG_CHECKING([if gcc is producing mips n32 binaries])
2308 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
2309 #if !defined(_MIPS_SIM) || (defined(_MIPS_SIM) && (_MIPS_SIM != _ABIN32))
2310 #error NO
2311 #endif
2312 ]])], [
2313 VGCONF_ABI=N32
2314 FLAG_M64="-march=mips64r2 -mabi=n32"
2315 AC_MSG_RESULT([yes])
2316 ], [
2317 AC_MSG_RESULT([no])
2320 # Are we compiling for the MIPS64 n64 ABI?
2321 AC_MSG_CHECKING([if gcc is producing mips n64 binaries])
2322 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
2323 #if !defined(_MIPS_SIM) || (defined(_MIPS_SIM) && (_MIPS_SIM != _ABI64))
2324 #error NO
2325 #endif
2326 ]])], [
2327 VGCONF_ABI=64
2328 AC_MSG_RESULT([yes])
2329 ], [
2330 AC_MSG_RESULT([no])
2333 # We enter the code block below in the following case:
2334 # Target architecture is set to mips64, the desired abi
2335 # was not specified and the compiler's default abi setting
2336 # is neither n32 nor n64.
2337 # Probe for and set the abi to either n64 or n32, in that order,
2338 # which is required for a mips64 build of valgrind.
2339 if test "$ARCH_MAX" = "mips64" -a "x$VGCONF_ABI" = "x"; then
2340   safe_CFLAGS=$CFLAGS
2341   CFLAGS="$CFLAGS -mabi=64 -Werror"
2342   AC_MSG_CHECKING([if gcc is n64 capable])
2343   AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[
2344       return 0;
2345   ]])], [
2346   VGCONF_ABI=64
2347   AC_MSG_RESULT([yes])
2348   ], [
2349   AC_MSG_RESULT([no])
2350   ])
2351   CFLAGS=$safe_CFLAGS
2353   if test "x$VGCONF_ABI" = "x"; then
2354     safe_CFLAGS=$CFLAGS
2355     CFLAGS="$CFLAGS -mabi=n32 -Werror"
2356     AC_MSG_CHECKING([if gcc is n32 capable])
2357     AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[
2358         return 0;
2359     ]])], [
2360     VGCONF_ABI=N32
2361     FLAG_M64="-march=mips64r2 -mabi=n32"
2362     AC_MSG_RESULT([yes])
2363     ], [
2364     AC_MSG_RESULT([no])
2365     ])
2366     CFLAGS=$safe_CFLAGS
2367   fi
2370 AM_CONDITIONAL([VGCONF_HAVE_ABI],
2371                [test x$VGCONF_ABI != x])
2372 AC_SUBST(VGCONF_ABI)
2375 # does this compiler support -mmmx ?
2376 AC_MSG_CHECKING([if gcc accepts -mmmx])
2378 safe_CFLAGS=$CFLAGS
2379 CFLAGS="-mmmx -Werror"
2381 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
2382   return 0;
2383 ]])], [
2384 FLAG_MMMX="-mmmx"
2385 AC_MSG_RESULT([yes])
2386 ], [
2387 FLAG_MMMX=""
2388 AC_MSG_RESULT([no])
2390 CFLAGS=$safe_CFLAGS
2392 AC_SUBST(FLAG_MMMX)
2395 # does this compiler support -msse ?
2396 AC_MSG_CHECKING([if gcc accepts -msse])
2398 safe_CFLAGS=$CFLAGS
2399 CFLAGS="-msse -Werror"
2401 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
2402   return 0;
2403 ]])], [
2404 FLAG_MSSE="-msse"
2405 AC_MSG_RESULT([yes])
2406 ], [
2407 FLAG_MSSE=""
2408 AC_MSG_RESULT([no])
2410 CFLAGS=$safe_CFLAGS
2412 AC_SUBST(FLAG_MSSE)
2415 # does this compiler support -mpreferred-stack-boundary=2 when
2416 # generating code for a 32-bit target?  Note that we only care about
2417 # this when generating code for (32-bit) x86, so if the compiler
2418 # doesn't recognise -m32 it's no big deal.  We'll just get code for
2419 # the Memcheck and other helper functions, that is a bit slower than
2420 # it could be, on x86; and no difference at all on any other platform.
2421 AC_MSG_CHECKING([if gcc accepts -mpreferred-stack-boundary=2 -m32])
2423 safe_CFLAGS=$CFLAGS
2424 CFLAGS="-mpreferred-stack-boundary=2 -m32 -Werror"
2426 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
2427   return 0;
2428 ]])], [
2429 PREFERRED_STACK_BOUNDARY_2="-mpreferred-stack-boundary=2"
2430 AC_MSG_RESULT([yes])
2431 ], [
2432 PREFERRED_STACK_BOUNDARY_2=""
2433 AC_MSG_RESULT([no])
2435 CFLAGS=$safe_CFLAGS
2437 AC_SUBST(PREFERRED_STACK_BOUNDARY_2)
2440 # does this compiler support -mlong-double-128 ?
2441 AC_MSG_CHECKING([if gcc accepts -mlong-double-128])
2442 safe_CFLAGS=$CFLAGS
2443 CFLAGS="-mlong-double-128 -Werror"
2444 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
2445   return 0;
2446 ]])], [
2447 ac_compiler_supports_mlong_double_128=yes
2448 AC_MSG_RESULT([yes])
2449 ], [
2450 ac_compiler_supports_mlong_double_128=no
2451 AC_MSG_RESULT([no])
2453 CFLAGS=$safe_CFLAGS
2454 AM_CONDITIONAL(HAS_MLONG_DOUBLE_128, test x$ac_compiler_supports_mlong_double_128 = xyes)
2455 FLAG_MLONG_DOUBLE_128="-mlong-double-128"
2456 AC_SUBST(FLAG_MLONG_DOUBLE_128)
2458 # does this toolchain support lto ?
2459 # Not checked for if --enable-lto=no was given, or if LTO_AR or LTO_RANLIG
2460 # are not defined
2461 # If not enable-lto=* arg is provided, default to no, as  lto builds are
2462 # a lot slower, and so not appropriate for Valgrind developments.
2463 # --enable-lto=yes should be used by distro packagers.
2464 AC_CACHE_CHECK([for using the link time optimisation], vg_cv_lto,
2465    [AC_ARG_ENABLE(lto,
2466       [  --enable-lto          enables building with link time optimisation],
2467       [vg_cv_lto=$enableval],
2468       [vg_cv_lto=no])])
2470 if test "x${vg_cv_lto}" != "xno" -a "x${LTO_AR}" != "x" -a "x${LTO_RANLIB}" != "x"; then
2471 AC_MSG_CHECKING([if toolchain accepts lto])
2472 safe_CFLAGS=$CFLAGS
2473 TEST_LTO_CFLAGS="-flto -flto-partition=one -fuse-linker-plugin"
2474 # Note : using 'one' partition is giving a slightly smaller/faster memcheck
2475 # and ld/lto-trans1 still needs a reasonable memory (about 0.5GB) when linking.
2476 CFLAGS="$TEST_LTO_CFLAGS -Werror"
2478 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
2479   extern void somefun(void);
2480   somefun();
2481   return 0;
2482 ]])], [
2483 LTO_CFLAGS=$TEST_LTO_CFLAGS
2484 AC_MSG_RESULT([yes])
2485 ], [
2486 LTO_CFLAGS=""
2487 AC_MSG_RESULT([no])
2489 CFLAGS=$safe_CFLAGS
2492 AC_SUBST(LTO_CFLAGS)
2494 # if we could not compile with lto args, or lto was disabled,
2495 # then set LTO_AR/LTO_RANLIB to the non lto values
2496 # define in config.h ENABLE_LTO (not needed by the code currently, but
2497 # this guarantees we recompile everything if we re-configure and rebuild
2498 # in a build dir previously build with another value of --enable-lto
2499 if test "x${LTO_CFLAGS}" = "x"; then
2500    LTO_AR=${AR}
2501    LTO_RANLIB=${RANLIB}
2502    vg_cv_lto=no
2503 else
2504    vg_cv_lto=yes
2505    AC_DEFINE([ENABLE_LTO], 1, [configured to build with lto link time optimisation])
2508 # Convenience function to check whether GCC supports a particular
2509 # warning option. Takes two arguments,
2510 # first the warning flag name to check (without -W), then the
2511 # substitution name to set with -Wno-warning-flag if the flag exists,
2512 # or the empty string if the compiler doesn't accept the flag. Note
2513 # that checking is done against the warning flag itself, but the
2514 # substitution is then done to cancel the warning flag.
2515 AC_DEFUN([AC_GCC_WARNING_SUBST_NO],[
2516   AC_MSG_CHECKING([if gcc accepts -W$1])
2517   safe_CFLAGS=$CFLAGS
2518   CFLAGS="-W$1 -Werror"
2519   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[;]])], [
2520   AC_SUBST([$2], [-Wno-$1])
2521   AC_MSG_RESULT([yes])], [
2522   AC_SUBST([$2], [])
2523   AC_MSG_RESULT([no])])
2524   CFLAGS=$safe_CFLAGS
2527 # A variation of the above for arguments that
2528 # take a value
2529 AC_DEFUN([AC_GCC_WARNING_SUBST_NO_VAL],[
2530   AC_MSG_CHECKING([if gcc accepts -W$1=$2])
2531   safe_CFLAGS=$CFLAGS
2532   CFLAGS="-W$1=$2 -Werror"
2533   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[;]])], [
2534   AC_SUBST([$3], [-Wno-$1])
2535   AC_MSG_RESULT([yes])], [
2536   AC_SUBST([$3], [])
2537   AC_MSG_RESULT([no])])
2538   CFLAGS=$safe_CFLAGS
2541 # Convenience function. Like AC_GCC_WARNING_SUBST_NO, except it substitutes
2542 # -W$1  (instead of -Wno-$1).
2543 AC_DEFUN([AC_GCC_WARNING_SUBST],[
2544   AC_MSG_CHECKING([if gcc accepts -W$1])
2545   safe_CFLAGS=$CFLAGS
2546   CFLAGS="-W$1 -Werror"
2547   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[;]])], [
2548   AC_SUBST([$2], [-W$1])
2549   AC_MSG_RESULT([yes])], [
2550   AC_SUBST([$2], [])
2551   AC_MSG_RESULT([no])])
2552   CFLAGS=$safe_CFLAGS
2555 AC_GCC_WARNING_SUBST_NO([memset-transposed-args], [FLAG_W_NO_MEMSET_TRANSPOSED_ARGS])
2556 AC_GCC_WARNING_SUBST_NO([nonnull], [FLAG_W_NO_NONNULL])
2557 AC_GCC_WARNING_SUBST_NO([overflow], [FLAG_W_NO_OVERFLOW])
2558 AC_GCC_WARNING_SUBST_NO([pointer-sign], [FLAG_W_NO_POINTER_SIGN])
2559 AC_GCC_WARNING_SUBST_NO([uninitialized], [FLAG_W_NO_UNINITIALIZED])
2560 AC_GCC_WARNING_SUBST_NO([maybe-uninitialized], [FLAG_W_NO_MAYBE_UNINITIALIZED])
2561 AC_GCC_WARNING_SUBST_NO([unused-function], [FLAG_W_NO_UNUSED_FUNCTION])
2562 AC_GCC_WARNING_SUBST_NO([static-local-in-inline], [FLAG_W_NO_STATIC_LOCAL_IN_INLINE])
2563 AC_GCC_WARNING_SUBST_NO([mismatched-new-delete], [FLAG_W_NO_MISMATCHED_NEW_DELETE])
2564 AC_GCC_WARNING_SUBST_NO([infinite-recursion], [FLAG_W_NO_INFINITE_RECURSION])
2565 AC_GCC_WARNING_SUBST_NO([expansion-to-defined], [FLAG_W_NO_EXPANSION_TO_DEFINED])
2566 AC_GCC_WARNING_SUBST_NO([unused-but-set-variable], [FLAG_W_NO_UNUSED_BUT_SET_VARIABLE])
2567 AC_GCC_WARNING_SUBST_NO([non-power-of-two-alignment], [FLAG_W_NO_NON_POWER_OF_TWO_ALIGNMENT])
2568 AC_GCC_WARNING_SUBST_NO([sign-compare], [FLAG_W_NO_SIGN_COMPARE])
2569 AC_GCC_WARNING_SUBST_NO([stringop-overflow], [FLAG_W_NO_STRINGOP_OVERFLOW])
2570 AC_GCC_WARNING_SUBST_NO([stringop-overread], [FLAG_W_NO_STRINGOP_OVERREAD])
2571 AC_GCC_WARNING_SUBST_NO([stringop-truncation], [FLAG_W_NO_STRINGOP_TRUNCATION])
2572 AC_GCC_WARNING_SUBST_NO([format-overflow], [FLAG_W_NO_FORMAT_OVERFLOW])
2573 AC_GCC_WARNING_SUBST_NO([use-after-free], [FLAG_W_NO_USE_AFTER_FREE])
2574 AC_GCC_WARNING_SUBST_NO([free-nonheap-object], [FLAG_W_NO_FREE_NONHEAP_OBJECT])
2576 AC_GCC_WARNING_SUBST_NO_VAL([alloc-size-larger-than], [1677216], [FLAG_W_NO_ALLOC_SIZE_LARGER_THAN])
2578 AC_GCC_WARNING_SUBST([write-strings], [FLAG_W_WRITE_STRINGS])
2579 AC_GCC_WARNING_SUBST([empty-body], [FLAG_W_EMPTY_BODY])
2580 AC_GCC_WARNING_SUBST([format], [FLAG_W_FORMAT])
2581 AC_GCC_WARNING_SUBST([format-signedness], [FLAG_W_FORMAT_SIGNEDNESS])
2582 AC_GCC_WARNING_SUBST([cast-qual], [FLAG_W_CAST_QUAL])
2583 AC_GCC_WARNING_SUBST([old-style-declaration], [FLAG_W_OLD_STYLE_DECLARATION])
2584 AC_GCC_WARNING_SUBST([ignored-qualifiers], [FLAG_W_IGNORED_QUALIFIERS])
2585 AC_GCC_WARNING_SUBST([missing-parameter-type], [FLAG_W_MISSING_PARAMETER_TYPE])
2586 AC_GCC_WARNING_SUBST([logical-op], [FLAG_W_LOGICAL_OP])
2587 AC_GCC_WARNING_SUBST([enum-conversion], [FLAG_W_ENUM_CONVERSION])
2588 AC_GCC_WARNING_SUBST([implicit-fallthrough=2], [FLAG_W_IMPLICIT_FALLTHROUGH])
2590 # Does this compiler support -Wformat-security ?
2591 # Special handling is needed, because certain GCC versions require -Wformat
2592 # being present if -Wformat-security is given. Otherwise a warning is issued.
2593 # However, AC_GCC_WARNING_SUBST will stick in -Werror (see r15323 for rationale).
2594 # And with that the warning will be turned into an error with the result
2595 # that -Wformat-security is believed to be unsupported when in fact it is.
2596 AC_MSG_CHECKING([if gcc accepts -Wformat-security])
2597 safe_CFLAGS=$CFLAGS
2598 CFLAGS="-Wformat -Wformat-security -Werror"
2599 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[;]])], [
2600 AC_SUBST([FLAG_W_FORMAT_SECURITY], [-Wformat-security])
2601 AC_MSG_RESULT([yes])], [
2602 AC_SUBST([FLAG_W_FORMAT_SECURITY], [])
2603 AC_MSG_RESULT([no])])
2604 CFLAGS=$safe_CFLAGS
2606 # does this compiler support -Wextra or the older -W ?
2608 AC_MSG_CHECKING([if gcc accepts -Wextra or -W])
2610 safe_CFLAGS=$CFLAGS
2611 CFLAGS="-Wextra -Werror"
2613 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ ]], [[
2614   return 0;
2615 ]])], [
2616 AC_SUBST([FLAG_W_EXTRA], [-Wextra])
2617 AC_MSG_RESULT([-Wextra])
2618 ], [
2619   CFLAGS="-W -Werror"
2620   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ ]], [[
2621     return 0;
2622   ]])], [
2623   AC_SUBST([FLAG_W_EXTRA], [-W])
2624   AC_MSG_RESULT([-W])
2625   ], [
2626   AC_SUBST([FLAG_W_EXTRA], [])
2627   AC_MSG_RESULT([not supported])
2628   ])
2630 CFLAGS=$safe_CFLAGS
2632 # On ARM we do not want to pass -Wcast-align as that produces loads
2633 # of warnings. GCC is just being conservative. See here:
2634 # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65459#c4
2635 if test "X$VGCONF_ARCH_PRI" = "Xarm"; then
2636   AC_SUBST([FLAG_W_CAST_ALIGN], [""])
2637 else
2638   AC_SUBST([FLAG_W_CAST_ALIGN], [-Wcast-align])
2641 # does this compiler support -faligned-new ?
2642 AC_MSG_CHECKING([if g++ accepts -faligned-new])
2644 safe_CXXFLAGS=$CXXFLAGS
2645 CXXFLAGS="-faligned-new -Werror"
2647 AC_LANG(C++)
2648 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
2649   return 0;
2650 ]])], [
2651 FLAG_FALIGNED_NEW="-faligned-new"
2652 AC_MSG_RESULT([yes])
2653 ], [
2654 FLAG_FALIGNED_NEW=""
2655 AC_MSG_RESULT([no])
2657 CXXFLAGS=$safe_CXXFLAGS
2658 AC_LANG(C)
2660 AC_SUBST(FLAG_FALIGNED_NEW)
2662 # does this compiler support -fsized-deallocation ?
2663 AC_MSG_CHECKING([if g++ accepts -fsized-deallocation])
2665 safe_CXXFLAGS=$CXXFLAGS
2666 CXXFLAGS="-fsized-deallocation -Werror"
2668 AC_LANG(C++)
2669 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
2670   return 0;
2671 ]])], [
2672 FLAG_FSIZED_DEALLOCATION="-fsized-deallocation"
2673 ac_have_sized_deallocation=yes
2674 AC_MSG_RESULT([yes])
2675 ], [
2676 FLAG_FSIZED_DEALLOCATION=""
2677 ac_have_sized_deallocation=no
2678 AC_MSG_RESULT([no])
2680 CXXFLAGS=$safe_CXXFLAGS
2681 AC_LANG(C)
2683 AC_SUBST(FLAG_FSIZED_DEALLOCATION)
2684 AM_CONDITIONAL([HAVE_FSIZED_DEALLOCATION], [test x$ac_have_sized_deallocation = xyes])
2686 # does this compiler support C++17 aligned new/delete?
2687 AC_MSG_CHECKING([if g++ supports aligned new and delete])
2689 safe_CXXFLAGS=$CXXFLAGS
2690 CXXFLAGS="-std=c++17"
2692 AC_LANG(C++)
2693 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
2694 #include <cstdlib>
2695 #include <new>
2696 ]], [[
2697   operator delete(nullptr, std::align_val_t(64U));
2698 ]])], [
2699 ac_have_aligned_cxx_alloc=yes
2700 AC_MSG_RESULT([yes])
2701 ], [
2702 ac_have_aligned_cxx_alloc=no
2703 AC_MSG_RESULT([no])
2705 CXXFLAGS=$safe_CXXFLAGS
2706 AC_LANG(C)
2708 AM_CONDITIONAL([HAVE_ALIGNED_CXX_ALLOC], [test x$ac_have_aligned_cxx_alloc = xyes])
2710 # does this compiler support -fno-stack-protector ?
2711 AC_MSG_CHECKING([if gcc accepts -fno-stack-protector])
2713 safe_CFLAGS=$CFLAGS
2714 CFLAGS="-fno-stack-protector -Werror"
2716 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
2717   return 0;
2718 ]])], [
2719 no_stack_protector=yes
2720 FLAG_FNO_STACK_PROTECTOR="-fno-stack-protector"
2721 AC_MSG_RESULT([yes])
2722 ], [
2723 no_stack_protector=no
2724 FLAG_FNO_STACK_PROTECTOR=""
2725 AC_MSG_RESULT([no])
2727 CFLAGS=$safe_CFLAGS
2729 AC_SUBST(FLAG_FNO_STACK_PROTECTOR)
2731 # does this compiler support -finline-functions ?
2732 AC_MSG_CHECKING([if gcc accepts -finline-functions])
2734 safe_CFLAGS=$CFLAGS
2735 CFLAGS="-finline-functions -Werror"
2737 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
2738   return 0;
2739 ]])], [
2740 inline_functions=yes
2741 FLAG_FINLINE_FUNCTIONS="-finline-functions"
2742 AC_MSG_RESULT([yes])
2743 ], [
2744 inline_functions=no
2745 FLAG_FINLINE_FUNCTIONS=""
2746 AC_MSG_RESULT([no])
2748 CFLAGS=$safe_CFLAGS
2750 AC_SUBST(FLAG_FINLINE_FUNCTIONS)
2752 # Does GCC support disabling Identical Code Folding?
2753 # We want to disabled Identical Code Folding for the
2754 # tools preload shared objects to get better backraces.
2755 # For GCC 5.1+ -fipa-icf is enabled by default at -O2.
2756 # "The optimization reduces code size and may disturb
2757 #  unwind stacks by replacing a function by equivalent
2758 #  one with a different name."
2759 AC_MSG_CHECKING([if gcc accepts -fno-ipa-icf])
2761 safe_CFLAGS=$CFLAGS
2762 CFLAGS="-fno-ipa-icf -Werror"
2764 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
2765   return 0;
2766 ]])], [
2767 no_ipa_icf=yes
2768 FLAG_FNO_IPA_ICF="-fno-ipa-icf"
2769 AC_MSG_RESULT([yes])
2770 ], [
2771 no_ipa_icf=no
2772 FLAG_FNO_IPA_ICF=""
2773 AC_MSG_RESULT([no])
2775 CFLAGS=$safe_CFLAGS
2777 AC_SUBST(FLAG_FNO_IPA_ICF)
2780 # Does this compiler support -fsanitize=undefined. This is true for
2781 # GCC 4.9 and newer. However, the undefined behaviour sanitiser in GCC 5.1
2782 # also checks for alignment violations on memory accesses which the valgrind
2783 # code base is sprinkled (if not littered) with. As those alignment issues
2784 # don't pose a problem we want to suppress warnings about them.
2785 # In GCC 5.1 this can be done by passing -fno-sanitize=alignment. Earlier
2786 # GCCs do not support that.
2788 # Only checked for if --enable-ubsan was given.
2789 if test "x${vg_cv_ubsan}" = "xyes"; then
2790 AC_MSG_CHECKING([if gcc accepts -fsanitize=undefined -fno-sanitize=alignment])
2791 safe_CFLAGS=$CFLAGS
2792 CFLAGS="-fsanitize=undefined -fno-sanitize=alignment -Werror"
2793 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
2794   return 0;
2795 ]])], [
2796 FLAG_FSANITIZE="-fsanitize=undefined -fno-sanitize=alignment"
2797 LIB_UBSAN="-static-libubsan"
2798 AC_MSG_RESULT([yes])
2799 ], [
2800 CFLAGS="-fsanitize=undefined -Werror"
2801 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
2802   return 0;
2803 ]])], [
2804 FLAG_FSANITIZE="-fsanitize=undefined"
2805 LIB_UBSAN="-static-libubsan"
2806 AC_MSG_RESULT([yes])
2807 ], [
2808 FLAG_FSANITIZE=""
2809 LIB_UBSAN=""
2810 AC_MSG_RESULT([no])
2813 CFLAGS=$safe_CFLAGS
2814 AC_SUBST(FLAG_FSANITIZE)
2815 AC_SUBST(LIB_UBSAN)
2817 # does this compiler support --param inline-unit-growth=... ?
2819 AC_MSG_CHECKING([if gcc accepts --param inline-unit-growth])
2821 safe_CFLAGS=$CFLAGS
2822 CFLAGS="--param inline-unit-growth=900 -Werror"
2824 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ ]], [[
2825   return 0;
2826 ]])], [
2827 AC_SUBST([FLAG_UNLIMITED_INLINE_UNIT_GROWTH],
2828          ["--param inline-unit-growth=900"])
2829 AC_MSG_RESULT([yes])
2830 ], [
2831 AC_SUBST([FLAG_UNLIMITED_INLINE_UNIT_GROWTH], [""])
2832 AC_MSG_RESULT([no])
2834 CFLAGS=$safe_CFLAGS
2837 # does this compiler support -gdwarf-4 -fdebug-types-section ?
2839 AC_MSG_CHECKING([if gcc accepts -gdwarf-4 -fdebug-types-section])
2841 safe_CFLAGS=$CFLAGS
2842 CFLAGS="-gdwarf-4 -fdebug-types-section -Werror"
2844 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ ]], [[
2845   return 0;
2846 ]])], [
2847 ac_have_dwarf4=yes
2848 AC_MSG_RESULT([yes])
2849 ], [
2850 ac_have_dwarf4=no
2851 AC_MSG_RESULT([no])
2853 AM_CONDITIONAL(DWARF4, test x$ac_have_dwarf4 = xyes)
2854 CFLAGS=$safe_CFLAGS
2857 # does this compiler support -g -gz=zlib ?
2859 AC_MSG_CHECKING([if gcc accepts -g -gz=zlib])
2861 safe_CFLAGS=$CFLAGS
2862 CFLAGS="-g -gz=zlib"
2864 AC_LINK_IFELSE([AC_LANG_PROGRAM([[ ]], [[
2865   return 0;
2866 ]])], [
2867 ac_have_gz_zlib=yes
2868 AC_MSG_RESULT([yes])
2869 ], [
2870 ac_have_gz_zlib=no
2871 AC_MSG_RESULT([no])
2873 AM_CONDITIONAL(GZ_ZLIB, test x$ac_have_gz_zlib = xyes)
2874 CFLAGS=$safe_CFLAGS
2877 # does this compiler support -g -gz=zlib-gnu ?
2879 AC_MSG_CHECKING([if gcc accepts -g -gz=zlib-gnu])
2881 safe_CFLAGS=$CFLAGS
2882 CFLAGS="-g -gz=zlib-gnu"
2884 AC_LINK_IFELSE([AC_LANG_PROGRAM([[ ]], [[
2885   return 0;
2886 ]])], [
2887 ac_have_gz_zlib_gnu=yes
2888 AC_MSG_RESULT([yes])
2889 ], [
2890 ac_have_gz_zlib_gnu=no
2891 AC_MSG_RESULT([no])
2893 AM_CONDITIONAL(GZ_ZLIB_GNU, test x$ac_have_gz_zlib_gnu = xyes)
2894 CFLAGS=$safe_CFLAGS
2897 # does this compiler support nested functions ?
2899 AC_MSG_CHECKING([if gcc accepts nested functions])
2901 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
2902   int foo() { return 1; }
2903   return foo();
2904 ]])], [
2905 ac_have_nested_functions=yes
2906 AC_MSG_RESULT([yes])
2907 ], [
2908 ac_have_nested_functions=no
2909 AC_MSG_RESULT([no])
2911 AM_CONDITIONAL([HAVE_NESTED_FUNCTIONS], [test x$ac_have_nested_functions = xyes])
2914 # does this compiler support the 'p' constraint in ASM statements ?
2916 AC_MSG_CHECKING([if gcc accepts the 'p' constraint in asm statements])
2918 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
2919    char *p;
2920    __asm__ __volatile__ ("movdqa (%0),%%xmm6\n" : "=p" (p));
2921 ]])], [
2922 ac_have_asm_constraint_p=yes
2923 AC_MSG_RESULT([yes])
2924 ], [
2925 ac_have_asm_constraint_p=no
2926 AC_MSG_RESULT([no])
2928 AM_CONDITIONAL([HAVE_ASM_CONSTRAINT_P], [test x$ac_have_asm_constraint_p = xyes])
2931 # Does this compiler and linker support -pie?
2932 # Some compilers actually do not support -pie and report its usage
2933 # as an error. We need to check if it is safe to use it first.
2935 AC_MSG_CHECKING([if gcc accepts -pie])
2937 safe_CFLAGS=$CFLAGS
2938 CFLAGS="-pie"
2940 AC_LINK_IFELSE([AC_LANG_PROGRAM([[ ]], [[
2941   return 0;
2942 ]])], [
2943 AC_SUBST([FLAG_PIE], ["-pie"])
2944 AC_MSG_RESULT([yes])
2945 ], [
2946 AC_SUBST([FLAG_PIE], [""])
2947 AC_MSG_RESULT([no])
2949 CFLAGS=$safe_CFLAGS
2951 AC_MSG_CHECKING([if gcc accepts -ansi])
2953 safe_CFLAGS=$CFLAGS
2954 CFLAGS="-ansi"
2956 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
2957    return 0;
2958 ]])], [
2959 ac_have_ansi=yes
2960 AC_MSG_RESULT([yes])
2961 ], [
2962 ac_have_ansi=no
2963 AC_MSG_RESULT([no])
2965 AM_CONDITIONAL([HAVE_ANSI], [test x$ac_have_ansi = xyes])
2967 CFLAGS=$safe_CFLAGS
2970 # Does this compiler support -no-pie?
2971 # On Ubuntu 16.10+, gcc produces position independent executables (PIE) by
2972 # default. However this gets in the way with some tests, we use -no-pie
2973 # for these.
2975 AC_MSG_CHECKING([if gcc accepts -no-pie])
2977 safe_CFLAGS=$CFLAGS
2978 CFLAGS="-no-pie -Werror"
2980 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ ]], [[
2981   return 0;
2982 ]])], [
2983 AC_SUBST([FLAG_NO_PIE], ["-no-pie"])
2984 AC_MSG_RESULT([yes])
2985 ], [
2986 AC_SUBST([FLAG_NO_PIE], [""])
2987 AC_MSG_RESULT([no])
2989 CFLAGS=$safe_CFLAGS
2992 # We want to use use the -Ttext-segment option to the linker.
2993 # GNU (bfd) ld supports this directly. Newer GNU gold linkers
2994 # support it as an alias of -Ttext. Sadly GNU (bfd) ld's -Ttext
2995 # semantics are NOT what we want (GNU gold -Ttext is fine).
2997 # For GNU (bfd) ld -Ttext-segment chooses the base at which ELF headers
2998 # will reside. -Ttext aligns just the .text section start (but not any
2999 # other section).
3001 # LLVM ld.lld 10.0 changed the semantics of its -Ttext. See "Breaking changes"
3002 # in https://releases.llvm.org/10.0.0/tools/lld/docs/ReleaseNotes.html
3003 # The --image-base option (since version 6.0?) provides the semantics needed.
3004 # -Ttext-segment generates an error, but -Ttext now more closely
3005 # follows the GNU (bfd) ld's -Ttext.
3007 # So test first for --image-base support, and if that fails then
3008 # for -Ttext-segment which is supported by all bfd ld versions
3009 # and use that if it exists. If it doesn't exist it must be an older
3010 # version of gold and we can fall back to using -Ttext which has the
3011 # right semantics.
3013 safe_CFLAGS=$CFLAGS
3014 AC_MSG_CHECKING([if the linker accepts -Wl,--image-base])
3016 CFLAGS="-static -nodefaultlibs -nostartfiles -Wl,--image-base=$valt_load_address_pri_norml -Werror"
3018 AC_LINK_IFELSE(
3019 [AC_LANG_SOURCE([int _start () { return 0; }])],
3021   linker_using_t_text="no"
3022   AC_SUBST([FLAG_T_TEXT], ["--image-base"])
3023   AC_MSG_RESULT([yes])
3024 ], [
3025   AC_MSG_RESULT([no])
3027   AC_MSG_CHECKING([if the linker accepts -Wl,-Ttext-segment])
3029   CFLAGS="-static -nodefaultlibs -nostartfiles -Wl,-Ttext-segment=$valt_load_address_pri_norml -Werror"
3031   AC_LINK_IFELSE(
3032   [AC_LANG_SOURCE([int _start () { return 0; }])],
3033   [
3034     linker_using_t_text="no"
3035     AC_SUBST([FLAG_T_TEXT], ["-Ttext-segment"])
3036     AC_MSG_RESULT([yes])
3037   ], [
3038     linker_using_t_text="yes"
3039     AC_SUBST([FLAG_T_TEXT], ["-Ttext"])
3040     AC_MSG_RESULT([no])
3041   ])
3044 CFLAGS=$safe_CFLAGS
3046 # If the linker only supports -Ttext (not -Ttext-segment or --image-base) then we will
3047 # have to strip any build-id ELF NOTEs from the statically linked tools.
3048 # Otherwise the build-id NOTE might end up at the default load address.
3049 # (Pedantically if the linker is gold then -Ttext is fine, but newer
3050 # gold versions also support -Ttext-segment. So just assume that unless
3051 # we can use -Ttext-segment we need to strip the build-id NOTEs.
3052 if test "x${linker_using_t_text}" = "xyes"; then
3053 AC_MSG_NOTICE([ld -Ttext used, need to strip build-id NOTEs.])
3054 # does the linker support -Wl,--build-id=none ?  Note, it's
3055 # important that we test indirectly via whichever C compiler
3056 # is selected, rather than testing /usr/bin/ld or whatever
3057 # directly.
3058 AC_MSG_CHECKING([if the linker accepts -Wl,--build-id=none])
3059 safe_CFLAGS=$CFLAGS
3060 CFLAGS="-Wl,--build-id=none -Werror"
3062 AC_LINK_IFELSE(
3063 [AC_LANG_PROGRAM([ ], [return 0;])],
3065   AC_SUBST([FLAG_NO_BUILD_ID], ["-Wl,--build-id=none"])
3066   AC_MSG_RESULT([yes])
3067 ], [
3068   AC_SUBST([FLAG_NO_BUILD_ID], [""])
3069   AC_MSG_RESULT([no])
3071 else
3072 AC_MSG_NOTICE([ld --image-base or -Ttext-segment used, no need to strip build-id NOTEs.])
3073 AC_SUBST([FLAG_NO_BUILD_ID], [""])
3075 CFLAGS=$safe_CFLAGS
3077 # does the ppc assembler support "mtocrf" et al?
3078 AC_MSG_CHECKING([if ppc32/64 as supports mtocrf/mfocrf])
3080 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
3081 __asm__ __volatile__("mtocrf 4,0");
3082 __asm__ __volatile__("mfocrf 0,4");
3083 ]])], [
3084 ac_have_as_ppc_mftocrf=yes
3085 AC_MSG_RESULT([yes])
3086 ], [
3087 ac_have_as_ppc_mftocrf=no
3088 AC_MSG_RESULT([no])
3090 if test x$ac_have_as_ppc_mftocrf = xyes ; then
3091   AC_DEFINE(HAVE_AS_PPC_MFTOCRF, 1, [Define to 1 if as supports mtocrf/mfocrf.])
3095 # does the ppc assembler support "lfdp" and other phased out floating point insns?
3096 AC_MSG_CHECKING([if ppc32/64 asm supports phased out floating point instructions])
3098 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
3099   do { typedef struct {
3100       double hi;
3101       double lo;
3102      } dbl_pair_t;
3103      dbl_pair_t dbl_pair[3];
3104      __asm__ volatile ("lfdp 10, %0"::"m" (dbl_pair[0]));
3105    } while (0)
3106 ]])], [
3107 ac_have_as_ppc_fpPO=yes
3108 AC_MSG_RESULT([yes])
3109 ], [
3110 ac_have_as_ppc_fpPO=no
3111 AC_MSG_RESULT([no])
3113 if test x$ac_have_as_ppc_fpPO = xyes ; then
3114   AC_DEFINE(HAVE_AS_PPC_FPPO, 1, [Define to 1 if as supports floating point phased out category.])
3118 # does the amd64 assembler understand "fxsave64" and "fxrstor64"?
3119 AC_MSG_CHECKING([if amd64 assembler supports fxsave64/fxrstor64])
3121 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
3122 void* p;
3123 asm __volatile__("fxsave64 (%0)" : : "r" (p) : "memory" );
3124 asm __volatile__("fxrstor64 (%0)" : : "r" (p) : "memory" );
3125 ]])], [
3126 ac_have_as_amd64_fxsave64=yes
3127 AC_MSG_RESULT([yes])
3128 ], [
3129 ac_have_as_amd64_fxsave64=no
3130 AC_MSG_RESULT([no])
3132 if test x$ac_have_as_amd64_fxsave64 = xyes ; then
3133   AC_DEFINE(HAVE_AS_AMD64_FXSAVE64, 1, [Define to 1 if as supports fxsave64/fxrstor64.])
3136 # does the x86/amd64 assembler understand SSE3 instructions?
3137 # Note, this doesn't generate a C-level symbol.  It generates a
3138 # automake-level symbol (BUILD_SSE3_TESTS), used in test Makefile.am's
3139 AC_MSG_CHECKING([if x86/amd64 assembler speaks SSE3])
3141 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
3142   do { long long int x; 
3143      __asm__ __volatile__("fisttpq (%0)" : :"r"(&x) ); } 
3144   while (0)
3145 ]])], [
3146 ac_have_as_sse3=yes
3147 AC_MSG_RESULT([yes])
3148 ], [
3149 ac_have_as_sse3=no
3150 AC_MSG_RESULT([no])
3153 AM_CONDITIONAL(BUILD_SSE3_TESTS, test x$ac_have_as_sse3 = xyes)
3156 # Ditto for SSSE3 instructions (note extra S)
3157 # Note, this doesn't generate a C-level symbol.  It generates a
3158 # automake-level symbol (BUILD_SSSE3_TESTS), used in test Makefile.am's
3159 AC_MSG_CHECKING([if x86/amd64 assembler speaks SSSE3])
3161 save_CFLAGS="$CFLAGS"
3162 CFLAGS="$CFLAGS -msse -Werror"
3163 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
3164   do { long long int x; 
3165    __asm__ __volatile__(
3166       "pabsb (%0),%%xmm7" : : "r"(&x) : "xmm7" ); }
3167   while (0)
3168 ]])], [
3169 ac_have_as_ssse3=yes
3170 AC_MSG_RESULT([yes])
3171 ], [
3172 ac_have_as_ssse3=no
3173 AC_MSG_RESULT([no])
3175 CFLAGS="$save_CFLAGS"
3177 AM_CONDITIONAL(BUILD_SSSE3_TESTS, test x$ac_have_as_ssse3 = xyes)
3180 # does the x86/amd64 assembler understand the PCLMULQDQ instruction?
3181 # Note, this doesn't generate a C-level symbol.  It generates a
3182 # automake-level symbol (BUILD_PCLMULQDQ_TESTS), used in test Makefile.am's
3183 AC_MSG_CHECKING([if x86/amd64 assembler supports 'pclmulqdq'])
3184 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
3185   do {
3186    __asm__ __volatile__(
3187       "pclmulqdq \$17,%%xmm6,%%xmm7" : : : "xmm6", "xmm7" ); }
3188   while (0)
3189 ]])], [
3190 ac_have_as_pclmulqdq=yes
3191 AC_MSG_RESULT([yes])
3192 ], [
3193 ac_have_as_pclmulqdq=no
3194 AC_MSG_RESULT([no])
3197 AM_CONDITIONAL(BUILD_PCLMULQDQ_TESTS, test x$ac_have_as_pclmulqdq = xyes)
3200 # does the x86/amd64 assembler understand the VPCLMULQDQ instruction?
3201 # Note, this doesn't generate a C-level symbol.  It generates a
3202 # automake-level symbol (BUILD_VPCLMULQDQ_TESTS), used in test Makefile.am's
3203 AC_MSG_CHECKING([if x86/amd64 assembler supports 'vpclmulqdq'])
3204 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
3205   do {
3206       /*
3207        * Carry-less multiplication of xmm1 with xmm2 and store the result in
3208        * xmm3. The immediate is used to determine which quadwords of xmm1 and
3209        * xmm2 should be used.
3210        */
3211    __asm__ __volatile__(
3212       "vpclmulqdq \$0,%%xmm1,%%xmm2,%%xmm3" : : : );
3213   } while (0)
3214 ]])], [
3215 ac_have_as_vpclmulqdq=yes
3216 AC_MSG_RESULT([yes])
3217 ], [
3218 ac_have_as_vpclmulqdq=no
3219 AC_MSG_RESULT([no])
3222 AM_CONDITIONAL(BUILD_VPCLMULQDQ_TESTS, test x$ac_have_as_vpclmulqdq = xyes)
3225 # does the x86/amd64 assembler understand FMA4 instructions?
3226 # Note, this doesn't generate a C-level symbol.  It generates a
3227 # automake-level symbol (BUILD_AFM4_TESTS), used in test Makefile.am's
3228 AC_MSG_CHECKING([if x86/amd64 assembler supports FMA4 'vfmaddpd'])
3229 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
3230   do {
3231    __asm__ __volatile__(
3232       "vfmaddpd %%xmm7,%%xmm8,%%xmm6,%%xmm9" : : : );
3233   } while (0)
3234 ]])], [
3235 ac_have_as_vfmaddpd=yes
3236 AC_MSG_RESULT([yes])
3237 ], [
3238 ac_have_as_vfmaddpd=no
3239 AC_MSG_RESULT([no])
3242 AM_CONDITIONAL(BUILD_FMA4_TESTS, test x$ac_have_as_vfmaddpd = xyes)
3245 # does the x86/amd64 assembler understand the LZCNT instruction?
3246 # Note, this doesn't generate a C-level symbol.  It generates a
3247 # automake-level symbol (BUILD_LZCNT_TESTS), used in test Makefile.am's
3248 AC_MSG_CHECKING([if x86/amd64 assembler supports 'lzcnt'])
3250 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
3251   do {           
3252       __asm__ __volatile__("lzcnt %%rax,%%rax" : : : "rax");
3253   } while (0)
3254 ]])], [
3255   ac_have_as_lzcnt=yes
3256   AC_MSG_RESULT([yes])
3257 ], [
3258   ac_have_as_lzcnt=no
3259   AC_MSG_RESULT([no])
3262 AM_CONDITIONAL([BUILD_LZCNT_TESTS], [test x$ac_have_as_lzcnt = xyes])
3265 # does the x86/amd64 assembler understand the LOOPNEL instruction?
3266 # Note, this doesn't generate a C-level symbol.  It generates a
3267 # automake-level symbol (BUILD_LOOPNEL_TESTS), used in test Makefile.am's
3268 AC_MSG_CHECKING([if x86/amd64 assembler supports 'loopnel'])
3270 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
3271   do {           
3272       __asm__ __volatile__("1:  loopnel 1b\n");
3273   } while (0)
3274 ]])], [
3275   ac_have_as_loopnel=yes
3276   AC_MSG_RESULT([yes])
3277 ], [
3278   ac_have_as_loopnel=no
3279   AC_MSG_RESULT([no])
3282 AM_CONDITIONAL([BUILD_LOOPNEL_TESTS], [test x$ac_have_as_loopnel = xyes])
3285 # does the x86/amd64 assembler understand ADDR32 ?
3286 # Note, this doesn't generate a C-level symbol.  It generates a
3287 # automake-level symbol (BUILD_ADDR32_TESTS), used in test Makefile.am's
3288 AC_MSG_CHECKING([if x86/amd64 assembler supports 'addr32'])
3290 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
3291   do {           
3292       asm volatile ("addr32 rep movsb");
3293   } while (0)
3294 ]])], [
3295   ac_have_as_addr32=yes
3296   AC_MSG_RESULT([yes])
3297 ], [
3298   ac_have_as_addr32=no
3299   AC_MSG_RESULT([no])
3302 AM_CONDITIONAL([BUILD_ADDR32_TESTS], [test x$ac_have_as_addr32 = xyes])
3305 # does the x86/amd64 assembler understand SSE 4.2 instructions?
3306 # Note, this doesn't generate a C-level symbol.  It generates a
3307 # automake-level symbol (BUILD_SSE42_TESTS), used in test Makefile.am's
3308 AC_MSG_CHECKING([if x86/amd64 assembler speaks SSE4.2])
3310 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
3311   do { long long int x; 
3312    __asm__ __volatile__(
3313       "crc32q %%r15,%%r15" : : : "r15" );
3314    __asm__ __volatile__(
3315       "pblendvb (%%rcx), %%xmm11" : : : "memory", "xmm11"); 
3316    __asm__ __volatile__(
3317       "aesdec %%xmm2, %%xmm1" : : : "xmm2", "xmm1"); }
3318   while (0)
3319 ]])], [
3320 ac_have_as_sse42=yes
3321 AC_MSG_RESULT([yes])
3322 ], [
3323 ac_have_as_sse42=no
3324 AC_MSG_RESULT([no])
3327 AM_CONDITIONAL(BUILD_SSE42_TESTS, test x$ac_have_as_sse42 = xyes)
3330 # does the x86/amd64 assembler understand AVX instructions?
3331 # Note, this doesn't generate a C-level symbol.  It generates a
3332 # automake-level symbol (BUILD_AVX_TESTS), used in test Makefile.am's
3333 AC_MSG_CHECKING([if x86/amd64 assembler speaks AVX])
3335 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
3336   do { long long int x; 
3337    __asm__ __volatile__(
3338       "vmovupd (%%rsp), %%ymm7" : : : "xmm7" );
3339    __asm__ __volatile__(
3340       "vaddpd %%ymm6,%%ymm7,%%ymm8" : : : "xmm6","xmm7","xmm8"); }
3341   while (0)
3342 ]])], [
3343 ac_have_as_avx=yes
3344 AC_MSG_RESULT([yes])
3345 ], [
3346 ac_have_as_avx=no
3347 AC_MSG_RESULT([no])
3350 AM_CONDITIONAL(BUILD_AVX_TESTS, test x$ac_have_as_avx = xyes)
3353 # does the x86/amd64 assembler understand AVX2 instructions?
3354 # Note, this doesn't generate a C-level symbol.  It generates a
3355 # automake-level symbol (BUILD_AVX2_TESTS), used in test Makefile.am's
3356 AC_MSG_CHECKING([if x86/amd64 assembler speaks AVX2])
3358 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
3359   do { long long int x; 
3360    __asm__ __volatile__(
3361       "vpsravd (%%rsp), %%ymm8, %%ymm7" : : : "xmm7", "xmm8" );
3362    __asm__ __volatile__(
3363       "vpaddb %%ymm6,%%ymm7,%%ymm8" : : : "xmm6","xmm7","xmm8"); }
3364   while (0)
3365 ]])], [
3366 ac_have_as_avx2=yes
3367 AC_MSG_RESULT([yes])
3368 ], [
3369 ac_have_as_avx2=no
3370 AC_MSG_RESULT([no])
3373 AM_CONDITIONAL(BUILD_AVX2_TESTS, test x$ac_have_as_avx2 = xyes)
3376 # does the x86/amd64 assembler understand TSX instructions and
3377 # the XACQUIRE/XRELEASE prefixes?
3378 # Note, this doesn't generate a C-level symbol.  It generates a
3379 # automake-level symbol (BUILD_TSX_TESTS), used in test Makefile.am's
3380 AC_MSG_CHECKING([if x86/amd64 assembler speaks TSX])
3382 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
3383   do {
3384    __asm__ __volatile__(
3385       "       xbegin Lfoo  \n\t"
3386       "Lfoo:  xend         \n\t"
3387       "       xacquire lock incq 0(%rsp)     \n\t"
3388       "       xrelease lock incq 0(%rsp)     \n"
3389    );
3390   } while (0)
3391 ]])], [
3392 ac_have_as_tsx=yes
3393 AC_MSG_RESULT([yes])
3394 ], [
3395 ac_have_as_tsx=no
3396 AC_MSG_RESULT([no])
3399 AM_CONDITIONAL(BUILD_TSX_TESTS, test x$ac_have_as_tsx = xyes)
3402 # does the x86/amd64 assembler understand BMI1 and BMI2 instructions?
3403 # Note, this doesn't generate a C-level symbol.  It generates a
3404 # automake-level symbol (BUILD_BMI_TESTS), used in test Makefile.am's
3405 AC_MSG_CHECKING([if x86/amd64 assembler speaks BMI1 and BMI2])
3407 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
3408   do { unsigned int h, l;
3409    __asm__ __volatile__( "mulx %rax,%rcx,%r8" );
3410    __asm__ __volatile__(
3411       "andn %2, %1, %0" : "=r" (h) : "r" (0x1234567), "r" (0x7654321) );
3412    __asm__ __volatile__(
3413       "movl %2, %%edx; mulx %3, %1, %0" : "=r" (h), "=r" (l) : "g" (0x1234567), "rm" (0x7654321) : "edx" ); }
3414   while (0)
3415 ]])], [
3416 ac_have_as_bmi=yes
3417 AC_MSG_RESULT([yes])
3418 ], [
3419 ac_have_as_bmi=no
3420 AC_MSG_RESULT([no])
3423 AM_CONDITIONAL(BUILD_BMI_TESTS, test x$ac_have_as_bmi = xyes)
3426 # does the x86/amd64 assembler understand FMA instructions?
3427 # Note, this doesn't generate a C-level symbol.  It generates a
3428 # automake-level symbol (BUILD_FMA_TESTS), used in test Makefile.am's
3429 AC_MSG_CHECKING([if x86/amd64 assembler speaks FMA])
3431 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
3432   do { unsigned int h, l;
3433    __asm__ __volatile__(
3434       "vfmadd132ps (%%rsp), %%ymm8, %%ymm7" : : : "xmm7", "xmm8" );
3435    __asm__ __volatile__(
3436       "vfnmsub231sd (%%rsp), %%xmm8, %%xmm7" : : : "xmm7", "xmm8" );
3437    __asm__ __volatile__(
3438       "vfmsubadd213pd (%%rsp), %%xmm8, %%xmm7" : : : "xmm7", "xmm8" ); }
3439   while (0)
3440 ]])], [
3441 ac_have_as_fma=yes
3442 AC_MSG_RESULT([yes])
3443 ], [
3444 ac_have_as_fma=no
3445 AC_MSG_RESULT([no])
3448 AM_CONDITIONAL(BUILD_FMA_TESTS, test x$ac_have_as_fma = xyes)
3451 # does the amd64 assembler understand MPX instructions?
3452 # Note, this doesn't generate a C-level symbol.  It generates a
3453 # automake-level symbol (BUILD_MPX_TESTS), used in test Makefile.am's
3454 AC_MSG_CHECKING([if amd64 assembler knows the MPX instructions])
3456 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
3457   do {
3458     asm ("bndmov %bnd0,(%rsp)");
3459     asm ("bndldx 3(%rbx,%rdx), %bnd2");
3460     asm ("bnd call foo\n"
3461          "bnd jmp  end\n"
3462          "foo: bnd ret\n"
3463          "end: nop");
3464   } while (0)
3465 ]])], [
3466 ac_have_as_mpx=yes
3467 AC_MSG_RESULT([yes])
3468 ], [
3469 ac_have_as_mpx=no
3470 AC_MSG_RESULT([no])
3473 AM_CONDITIONAL(BUILD_MPX_TESTS, test x$ac_have_as_mpx = xyes)
3476 # does the amd64 assembler understand ADX instructions?
3477 # Note, this doesn't generate a C-level symbol.  It generates a
3478 # automake-level symbol (BUILD_ADX_TESTS), used in test Makefile.am's
3479 AC_MSG_CHECKING([if amd64 assembler knows the ADX instructions])
3481 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
3482   do {
3483     asm ("adcxq %r14,%r8");
3484   } while (0)
3485 ]])], [
3486 ac_have_as_adx=yes
3487 AC_MSG_RESULT([yes])
3488 ], [
3489 ac_have_as_adx=no
3490 AC_MSG_RESULT([no])
3493 AM_CONDITIONAL(BUILD_ADX_TESTS, test x$ac_have_as_adx = xyes)
3496 # does the amd64 assembler understand the RDRAND instruction?
3497 # Note, this doesn't generate a C-level symbol.  It generates a
3498 # automake-level symbol (BUILD_RDRAND_TESTS), used in test Makefile.am's
3499 AC_MSG_CHECKING([if amd64 assembler knows the RDRAND instruction])
3501 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
3502   do {
3503     asm ("rdrand %r14");
3504     asm ("rdrand %r14d");
3505     asm ("rdrand %r14w");
3506   } while (0)
3507 ]])], [
3508 ac_have_as_rdrand=yes
3509 AC_MSG_RESULT([yes])
3510 ], [
3511 ac_have_as_rdrand=no
3512 AC_MSG_RESULT([no])
3515 AM_CONDITIONAL(BUILD_RDRAND_TESTS, test x$ac_have_as_rdrand = xyes)
3517 # does the amd64 assembler understand the RDSEED instruction?
3518 # Note, this doesn't generate a C-level symbol.  It generates a
3519 # automake-level symbol (BUILD_RDSEED_TESTS), used in test Makefile.am's
3520 AC_MSG_CHECKING([if amd64 assembler knows the RDSEED instruction])
3522 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
3523   do {
3524     asm ("rdseed %r14");
3525     asm ("rdseed %r14d");
3526     asm ("rdseed %r14w");
3527   } while (0)
3528 ]])], [
3529 ac_have_as_rdseed=yes
3530 AC_MSG_RESULT([yes])
3531 ], [
3532 ac_have_as_rdseed=no
3533 AC_MSG_RESULT([no])
3536 AM_CONDITIONAL(BUILD_RDSEED_TESTS, test x$ac_have_as_rdseed = xyes)
3538 # does the amd64 assembler understand the F16C instructions (VCVTPH2PS and
3539 # VCVTPS2PH) ?
3540 # Note, this doesn't generate a C-level symbol.  It generates a
3541 # automake-level symbol (BUILD_F16C_TESTS), used in test Makefile.am's
3542 AC_MSG_CHECKING([if amd64 assembler knows the F16C instructions])
3544 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
3545   do {
3546     asm ("vcvtph2ps %xmm5, %ymm10");
3547     // If we put the dollar sign and zero together, the shell processing
3548     // this configure.ac script substitutes the command name in.  Sigh.
3549     asm ("vcvtps2ph $" "0, %ymm10, %xmm5");
3550   } while (0)
3551 ]])], [
3552 ac_have_as_f16c=yes
3553 AC_MSG_RESULT([yes])
3554 ], [
3555 ac_have_as_f16c=no
3556 AC_MSG_RESULT([no])
3559 AM_CONDITIONAL(BUILD_F16C_TESTS, test x$ac_have_as_f16c = xyes)
3562 # does the x86/amd64 assembler understand MOVBE?
3563 # Note, this doesn't generate a C-level symbol.  It generates a
3564 # automake-level symbol (BUILD_MOVBE_TESTS), used in test Makefile.am's
3565 AC_MSG_CHECKING([if x86/amd64 assembler knows the MOVBE insn])
3567 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
3568   do { long long int x; 
3569    __asm__ __volatile__(
3570       "movbe (%%rsp), %%r15" : : : "memory", "r15" ); }
3571   while (0)
3572 ]])], [
3573 ac_have_as_movbe=yes
3574 AC_MSG_RESULT([yes])
3575 ], [
3576 ac_have_as_movbe=no
3577 AC_MSG_RESULT([no])
3580 AM_CONDITIONAL(BUILD_MOVBE_TESTS, test x$ac_have_as_movbe = xyes)
3583 # Does the C compiler support the "ifunc" attribute
3584 # Note, this doesn't generate a C-level symbol.  It generates a
3585 # automake-level symbol (BUILD_IFUNC_TESTS), used in test Makefile.am's
3586 AC_MSG_CHECKING([if gcc supports the ifunc attribute])
3588 AC_LINK_IFELSE([AC_LANG_SOURCE([[
3589 static void mytest(void) {}
3591 static void (*resolve_test(void))(void)
3593     return (void (*)(void))&mytest;
3596 void test(void) __attribute__((ifunc("resolve_test")));
3598 int main()
3600     test();
3601     return 0;
3603 ]])], [
3604 ac_have_ifunc_attr=yes
3605 AC_MSG_RESULT([yes])
3606 ], [
3607 ac_have_ifunc_attr=no
3608 AC_MSG_RESULT([no])
3611 AM_CONDITIONAL(BUILD_IFUNC_TESTS, test x$ac_have_ifunc_attr = xyes)
3613 # Does the C compiler support the armv8 crc feature flag
3614 # Note, this doesn't generate a C-level symbol.  It generates a
3615 # automake-level symbol (BUILD_ARMV8_CRC_TESTS), used in test Makefile.am's
3616 AC_MSG_CHECKING([if gcc supports the armv8 crc feature flag])
3618 save_CFLAGS="$CFLAGS"
3619 CFLAGS="$CFLAGS -march=armv8-a+crc -Werror"
3620 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
3621 int main()
3623     return 0;
3625 ]])], [
3626 ac_have_armv8_crc_feature=yes
3627 AC_MSG_RESULT([yes])
3628 ], [
3629 ac_have_armv8_crc_feature=no
3630 AC_MSG_RESULT([no])
3632 CFLAGS="$save_CFLAGS"
3634 AM_CONDITIONAL(BUILD_ARMV8_CRC_TESTS, test x$ac_have_armv8_crc_feature = xyes)
3637 # Does the C compiler support the armv81 flag and the assembler v8.1 instructions
3638 # Note, this doesn't generate a C-level symbol.  It generates a
3639 # automake-level symbol (BUILD_ARMV81_TESTS), used in test Makefile.am's
3640 AC_MSG_CHECKING([if gcc supports the armv81 feature flag and assembler supports v8.1 instructions])
3642 save_CFLAGS="$CFLAGS"
3643 CFLAGS="$CFLAGS -march=armv8.1-a -Werror"
3644 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
3645 int main()
3647     __asm__ __volatile__("ldadd x0, x1, [x2]" ::: "memory");
3648     return 0;
3650 ]])], [
3651 ac_have_armv81_feature=yes
3652 AC_MSG_RESULT([yes])
3653 ], [
3654 ac_have_armv81_feature=no
3655 AC_MSG_RESULT([no])
3657 CFLAGS="$save_CFLAGS"
3659 AM_CONDITIONAL(BUILD_ARMV81_TESTS, test x$ac_have_armv81_feature = xyes)
3662 # Does the C compiler support the armv82 flag and the assembler v8.2 instructions
3663 # Note, this doesn't generate a C-level symbol.  It generates a
3664 # automake-level symbol (BUILD_ARMV82_TESTS), used in test Makefile.am's
3665 AC_MSG_CHECKING([if gcc supports the armv82 feature flag and assembler supports v8.2 instructions])
3667 save_CFLAGS="$CFLAGS"
3668 CFLAGS="$CFLAGS -march=armv8.2-a+fp16 -Werror"
3669 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
3670 int main()
3672     __asm__ __volatile__("faddp h0, v1.2h");
3673     return 0;
3675 ]])], [
3676 ac_have_armv82_feature=yes
3677 AC_MSG_RESULT([yes])
3678 ], [
3679 ac_have_armv82_feature=no
3680 AC_MSG_RESULT([no])
3682 CFLAGS="$save_CFLAGS"
3684 AM_CONDITIONAL(BUILD_ARMV82_TESTS, test x$ac_have_armv82_feature = xyes)
3687 # XXX JRS 2010 Oct 13: what is this for?  For sure, we don't need this
3688 # when building the tool executables.  I think we should get rid of it.
3690 # Check for TLS support in the compiler and linker
3691 AC_LINK_IFELSE([AC_LANG_PROGRAM([[static __thread int foo;]],
3692                                 [[return foo;]])],
3693                                [vg_cv_linktime_tls=yes],
3694                                [vg_cv_linktime_tls=no])
3695 # Native compilation: check whether running a program using TLS succeeds.
3696 # Linking only is not sufficient -- e.g. on Red Hat 7.3 linking TLS programs
3697 # succeeds but running programs using TLS fails.
3698 # Cross-compiling: check whether linking a program using TLS succeeds.
3699 AC_CACHE_CHECK([for TLS support], vg_cv_tls,
3700                [AC_ARG_ENABLE(tls, [  --enable-tls            platform supports TLS],
3701                 [vg_cv_tls=$enableval],
3702                 [AC_RUN_IFELSE([AC_LANG_PROGRAM([[static __thread int foo;]],
3703                                                 [[return foo;]])],
3704                                [vg_cv_tls=yes],
3705                                [vg_cv_tls=no],
3706                                [vg_cv_tls=$vg_cv_linktime_tls])])])
3708 if test "$vg_cv_tls" = yes -a $is_clang != applellvm; then
3709 AC_DEFINE([HAVE_TLS], 1, [can use __thread to define thread-local variables])
3713 #----------------------------------------------------------------------------
3714 # Solaris-specific checks.
3715 #----------------------------------------------------------------------------
3717 if test "$VGCONF_OS" = "solaris" ; then
3718 AC_CHECK_HEADERS([sys/lgrp_user_impl.h])
3720 # Solaris-specific check determining if the Sun Studio Assembler is used to
3721 # build Valgrind.  The test checks if the x86/amd64 assembler understands the
3722 # cmovl.l instruction, if yes then it's Sun Assembler.
3724 # C-level symbol: none
3725 # Automake-level symbol: SOLARIS_SUN_STUDIO_AS
3727 AC_MSG_CHECKING([if x86/amd64 assembler speaks cmovl.l (Solaris-specific)])
3728 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
3729 ]], [[
3730   __asm__ __volatile__("cmovl.l %edx, %eax");
3731 ]])], [
3732 solaris_have_sun_studio_as=yes
3733 AC_MSG_RESULT([yes])
3734 ], [
3735 solaris_have_sun_studio_as=no
3736 AC_MSG_RESULT([no])
3738 AM_CONDITIONAL(SOLARIS_SUN_STUDIO_AS, test x$solaris_have_sun_studio_as = xyes)
3740 # Solaris-specific check determining if symbols __xpg4 and __xpg6
3741 # are present in linked shared libraries when gcc is invoked with -std=gnu99.
3742 # See solaris/vgpreload-solaris.mapfile for details.
3743 # gcc on older Solaris instructs linker to include these symbols,
3744 # gcc on illumos and newer Solaris does not.
3746 # C-level symbol: none
3747 # Automake-level symbol: SOLARIS_XPG_SYMBOLS_PRESENT
3749 save_CFLAGS="$CFLAGS"
3750 CFLAGS="$CFLAGS -std=gnu99"
3751 AC_MSG_CHECKING([if xpg symbols are present with -std=gnu99 (Solaris-specific)])
3752 temp_dir=$( /usr/bin/mktemp -d )
3753 cat <<_ACEOF >${temp_dir}/mylib.c
3754 #include <stdio.h>
3755 int myfunc(void) { printf("LaPutyka\n"); }
3756 _ACEOF
3757 ${CC} ${CFLAGS} -fpic -shared -o ${temp_dir}/mylib.so ${temp_dir}/mylib.c
3758 xpg_present=$( /usr/bin/nm ${temp_dir}/mylib.so | ${EGREP} '(__xpg4|__xpg6)' )
3759 if test "x${xpg_present}" = "x" ; then
3760     solaris_xpg_symbols_present=no
3761     AC_MSG_RESULT([no])
3762 else
3763     solaris_xpg_symbols_present=yes
3764     AC_MSG_RESULT([yes])
3766 rm -rf ${temp_dir}
3767 AM_CONDITIONAL(SOLARIS_XPG_SYMBOLS_PRESENT, test x$solaris_xpg_symbols_present = xyes)
3768 CFLAGS="$save_CFLAGS"
3771 # Solaris-specific check determining if gcc enables largefile support by
3772 # default for 32-bit executables. If it does, then set SOLARIS_UNDEF_LARGESOURCE
3773 # variable with gcc flags which disable it.
3775 AC_MSG_CHECKING([if gcc enables largefile support for 32-bit apps (Solaris-specific)])
3776 save_CFLAGS="$CFLAGS"
3777 CFLAGS="$CFLAGS -m32"
3778 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
3779   return _LARGEFILE_SOURCE;
3780 ]])], [
3781 SOLARIS_UNDEF_LARGESOURCE="-U_LARGEFILE_SOURCE -U_LARGEFILE64_SOURCE -U_FILE_OFFSET_BITS"
3782 AC_MSG_RESULT([yes])
3783 ], [
3784 SOLARIS_UNDEF_LARGESOURCE=""
3785 AC_MSG_RESULT([no])
3787 CFLAGS=$safe_CFLAGS
3788 AC_SUBST(SOLARIS_UNDEF_LARGESOURCE)
3791 # Solaris-specific check determining if /proc/self/cmdline
3792 # or /proc/<pid>/cmdline is supported.
3794 # C-level symbol: SOLARIS_PROC_CMDLINE
3795 # Automake-level symbol: SOLARIS_PROC_CMDLINE
3797 AC_CHECK_FILE([/proc/self/cmdline],
3799 solaris_proc_cmdline=yes
3800 AC_DEFINE([SOLARIS_PROC_CMDLINE], 1,
3801           [Define to 1 if you have /proc/self/cmdline.])
3802 ], [
3803 solaris_proc_cmdline=no
3805 AM_CONDITIONAL(SOLARIS_PROC_CMDLINE, test x$solaris_proc_cmdline = xyes)
3808 # Solaris-specific check determining default platform for the Valgrind launcher.
3809 # Used in case the launcher cannot select platform by looking at the client
3810 # image (for example because the executable is a shell script).
3812 # C-level symbol: SOLARIS_LAUNCHER_DEFAULT_PLATFORM
3813 # Automake-level symbol: none
3815 AC_MSG_CHECKING([for default platform of Valgrind launcher (Solaris-specific)])
3816 # Get the ELF class of /bin/sh first.
3817 if ! test -f /bin/sh; then
3818   AC_MSG_ERROR([Shell interpreter `/bin/sh' not found.])
3820 elf_class=$( /usr/bin/file /bin/sh | sed -n 's/.*ELF \(..\)-bit.*/\1/p' )
3821 case "$elf_class" in
3822   64)
3823     default_arch="$VGCONF_ARCH_PRI";
3824     ;;
3825   32)
3826     if test "x$VGCONF_ARCH_SEC" != "x"; then
3827       default_arch="$VGCONF_ARCH_SEC"
3828     else
3829       default_arch="$VGCONF_ARCH_PRI";
3830     fi
3831     ;;
3832   *)
3833     AC_MSG_ERROR([Cannot determine ELF class of `/bin/sh'.])
3834     ;;
3835 esac
3836 default_platform="$default_arch-$VGCONF_OS"
3837 AC_MSG_RESULT([$default_platform])
3838 AC_DEFINE_UNQUOTED([SOLARIS_LAUNCHER_DEFAULT_PLATFORM], ["$default_platform"],
3839                    [Default platform for Valgrind launcher.])
3842 # Solaris-specific check determining if the old syscalls are available.
3844 # C-level symbol: SOLARIS_OLD_SYSCALLS
3845 # Automake-level symbol: SOLARIS_OLD_SYSCALLS
3847 AC_MSG_CHECKING([for the old Solaris syscalls (Solaris-specific)])
3848 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
3849 #include <sys/syscall.h>
3850 ]], [[
3851   return !SYS_open;
3852 ]])], [
3853 solaris_old_syscalls=yes
3854 AC_MSG_RESULT([yes])
3855 AC_DEFINE([SOLARIS_OLD_SYSCALLS], 1,
3856           [Define to 1 if you have the old Solaris syscalls.])
3857 ], [
3858 solaris_old_syscalls=no
3859 AC_MSG_RESULT([no])
3861 AM_CONDITIONAL(SOLARIS_OLD_SYSCALLS, test x$solaris_old_syscalls = xyes)
3864 # Solaris-specific check determining if the new accept() syscall is available.
3866 # Old syscall:
3867 # int accept(int sock, struct sockaddr *name, socklen_t *namelenp,
3868 #            int version);
3870 # New syscall (available on illumos):
3871 # int accept(int sock, struct sockaddr *name, socklen_t *namelenp,
3872 #            int version, int flags);
3874 # If the old syscall is present then the following syscall will fail with
3875 # ENOTSOCK (because file descriptor 0 is not a socket), if the new syscall is
3876 # available then it will fail with EINVAL (because the flags parameter is
3877 # invalid).
3879 # C-level symbol: SOLARIS_NEW_ACCEPT_SYSCALL
3880 # Automake-level symbol: none
3882 AC_MSG_CHECKING([for the new `accept' syscall (Solaris-specific)])
3883 AC_RUN_IFELSE([AC_LANG_PROGRAM([[
3884 #include <sys/syscall.h>
3885 #include <errno.h>
3886 ]], [[
3887   errno = 0;
3888   syscall(SYS_accept, 0, 0, 0, 0, -1);
3889   return !(errno == EINVAL);
3890 ]])], [
3891 AC_MSG_RESULT([yes])
3892 AC_DEFINE([SOLARIS_NEW_ACCEPT_SYSCALL], 1,
3893           [Define to 1 if you have the new `accept' syscall.])
3894 ], [
3895 AC_MSG_RESULT([no])
3899 # Solaris-specific check determining if the new illumos pipe() syscall is
3900 # available.
3902 # Old syscall:
3903 # longlong_t pipe();
3905 # New syscall (available on illumos):
3906 # int pipe(intptr_t arg, int flags);
3908 # If the old syscall is present then the following call will succeed, if the
3909 # new syscall is available then it will fail with EFAULT (because address 0
3910 # cannot be accessed).
3912 # C-level symbol: SOLARIS_NEW_PIPE_SYSCALL
3913 # Automake-level symbol: none
3915 AC_MSG_CHECKING([for the new `pipe' syscall (Solaris-specific)])
3916 AC_RUN_IFELSE([AC_LANG_PROGRAM([[
3917 #include <sys/syscall.h>
3918 #include <errno.h>
3919 ]], [[
3920   errno = 0;
3921   syscall(SYS_pipe, 0, 0);
3922   return !(errno == EFAULT);
3923 ]])], [
3924 AC_MSG_RESULT([yes])
3925 AC_DEFINE([SOLARIS_NEW_PIPE_SYSCALL], 1,
3926           [Define to 1 if you have the new `pipe' syscall.])
3927 ], [
3928 AC_MSG_RESULT([no])
3932 # Solaris-specific check determining if the new lwp_sigqueue() syscall is
3933 # available.
3935 # Old syscall:
3936 # int lwp_kill(id_t lwpid, int sig);
3938 # New syscall (available on Solaris 11):
3939 # int lwp_sigqueue(id_t lwpid, int sig, void *value,
3940 #                  int si_code, timespec_t *timeout);
3942 # C-level symbol: SOLARIS_LWP_SIGQUEUE_SYSCALL
3943 # Automake-level symbol: SOLARIS_LWP_SIGQUEUE_SYSCALL
3945 AC_MSG_CHECKING([for the new `lwp_sigqueue' syscall (Solaris-specific)])
3946 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
3947 #include <sys/syscall.h> 
3948 ]], [[
3949   return !SYS_lwp_sigqueue;
3950 ]])], [
3951 solaris_lwp_sigqueue_syscall=yes
3952 AC_MSG_RESULT([yes])
3953 AC_DEFINE([SOLARIS_LWP_SIGQUEUE_SYSCALL], 1,
3954           [Define to 1 if you have the new `lwp_sigqueue' syscall.])
3955 ], [
3956 solaris_lwp_sigqueue_syscall=no
3957 AC_MSG_RESULT([no])
3959 AM_CONDITIONAL(SOLARIS_LWP_SIGQUEUE_SYSCALL, test x$solaris_lwp_sigqueue_syscall = xyes)
3962 # Solaris-specific check determining if the lwp_sigqueue() syscall
3963 # takes both pid and thread id arguments or just thread id.
3965 # Old syscall (available up to Solaris 11.3):
3966 # int lwp_sigqueue(id_t lwpid, int sig, void *value,
3967 #                  int si_code, timespec_t *timeout);
3969 # New syscall (available since Solaris 11.4):
3970 # int lwp_sigqueue(pid_t pid, id_t lwpid, int sig, void *value,
3971 #                  int si_code, timespec_t *timeout);
3973 # If the old syscall is present then the following syscall will fail with
3974 # EINVAL (because signal is out of range); if the new syscall is available
3975 # then it will fail with ESRCH (because it would not find such thread in the
3976 # current process).
3978 # C-level symbol: SOLARIS_LWP_SIGQUEUE_SYSCALL_TAKES_PID
3979 # Automake-level symbol: SOLARIS_LWP_SIGQUEUE_SYSCALL_TAKES_PID
3981 AM_COND_IF(SOLARIS_LWP_SIGQUEUE_SYSCALL,
3982 AC_MSG_CHECKING([if the `lwp_sigqueue' syscall accepts pid (Solaris-specific)])
3983 AC_RUN_IFELSE([AC_LANG_PROGRAM([[
3984 #include <sys/syscall.h>
3985 #include <errno.h>
3986 ]], [[
3987   errno = 0;
3988   syscall(SYS_lwp_sigqueue, 0, 101, 0, 0, 0, 0);
3989   return !(errno == ESRCH);
3990 ]])], [
3991 solaris_lwp_sigqueue_syscall_takes_pid=yes
3992 AC_MSG_RESULT([yes])
3993 AC_DEFINE([SOLARIS_LWP_SIGQUEUE_SYSCALL_TAKES_PID], 1,
3994           [Define to 1 if you have the new `lwp_sigqueue' syscall which accepts pid.])
3995 ], [
3996 solaris_lwp_sigqueue_syscall_takes_pid=no
3997 AC_MSG_RESULT([no])
3999 AM_CONDITIONAL(SOLARIS_LWP_SIGQUEUE_SYSCALL_TAKES_PID,
4000                test x$solaris_lwp_sigqueue_syscall_takes_pid = xyes)
4002 AM_CONDITIONAL(SOLARIS_LWP_SIGQUEUE_SYSCALL_TAKES_PID, test x = y)
4006 # Solaris-specific check determining if the new lwp_name() syscall is
4007 # available.
4009 # New syscall (available on Solaris 11):
4010 # int lwp_name(int opcode, id_t lwpid, char *name, size_t len);
4012 # C-level symbol: SOLARIS_LWP_NAME_SYSCALL
4013 # Automake-level symbol: SOLARIS_LWP_NAME_SYSCALL
4015 AC_MSG_CHECKING([for the new `lwp_name' syscall (Solaris-specific)])
4016 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
4017 #include <sys/syscall.h>
4018 ]], [[
4019   return !SYS_lwp_name;
4020 ]])], [
4021 solaris_lwp_name_syscall=yes
4022 AC_MSG_RESULT([yes])
4023 AC_DEFINE([SOLARIS_LWP_NAME_SYSCALL], 1,
4024           [Define to 1 if you have the new `lwp_name' syscall.])
4025 ], [
4026 solaris_lwp_name_syscall=no
4027 AC_MSG_RESULT([no])
4029 AM_CONDITIONAL(SOLARIS_LWP_NAME_SYSCALL, test x$solaris_lwp_name_syscall = xyes)
4032 # Solaris-specific check determining if the new getrandom() syscall is
4033 # available.
4035 # New syscall (available on Solaris 11):
4036 # int getrandom(void *buf, size_t buflen, uint_t flags);
4038 # C-level symbol: SOLARIS_GETRANDOM_SYSCALL
4039 # Automake-level symbol: SOLARIS_GETRANDOM_SYSCALL
4041 AC_MSG_CHECKING([for the new `getrandom' syscall (Solaris-specific)])
4042 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
4043 #include <sys/syscall.h>
4044 ]], [[
4045   return !SYS_getrandom;
4046 ]])], [
4047 solaris_getrandom_syscall=yes
4048 AC_MSG_RESULT([yes])
4049 AC_DEFINE([SOLARIS_GETRANDOM_SYSCALL], 1,
4050           [Define to 1 if you have the new `getrandom' syscall.])
4051 ], [
4052 solaris_getrandom_syscall=no
4053 AC_MSG_RESULT([no])
4055 AM_CONDITIONAL(SOLARIS_GETRANDOM_SYSCALL, test x$solaris_getrandom_syscall = xyes)
4058 # Solaris-specific check determining if the new zone() syscall subcodes
4059 # ZONE_LIST_DEFUNCT and ZONE_GETATTR_DEFUNCT are available.  These subcodes
4060 # were added in Solaris 11 but are missing on illumos.
4062 # C-level symbol: SOLARIS_ZONE_DEFUNCT
4063 # Automake-level symbol: SOLARIS_ZONE_DEFUNCT
4065 AC_MSG_CHECKING([for ZONE_LIST_DEFUNCT and ZONE_GETATTR_DEFUNCT (Solaris-specific)])
4066 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
4067 #include <sys/zone.h>
4068 ]], [[
4069   return !(ZONE_LIST_DEFUNCT && ZONE_GETATTR_DEFUNCT);
4070 ]])], [
4071 solaris_zone_defunct=yes
4072 AC_MSG_RESULT([yes])
4073 AC_DEFINE([SOLARIS_ZONE_DEFUNCT], 1,
4074           [Define to 1 if you have the `ZONE_LIST_DEFUNCT' and `ZONE_GETATTR_DEFUNC' constants.])
4075 ], [
4076 solaris_zone_defunct=no
4077 AC_MSG_RESULT([no])
4079 AM_CONDITIONAL(SOLARIS_ZONE_DEFUNCT, test x$solaris_zone_defunct = xyes)
4082 # Solaris-specific check determining if commands A_GETSTAT and A_SETSTAT
4083 # for auditon(2) subcode of the auditsys() syscall are available.
4084 # These commands are available in Solaris 11 and illumos but were removed
4085 # in Solaris 11.4.
4087 # C-level symbol: SOLARIS_AUDITON_STAT
4088 # Automake-level symbol: SOLARIS_AUDITON_STAT
4090 AC_MSG_CHECKING([for A_GETSTAT and A_SETSTAT auditon(2) commands (Solaris-specific)])
4091 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
4092 #include <bsm/audit.h>
4093 ]], [[
4094   return !(A_GETSTAT && A_SETSTAT);
4095 ]])], [
4096 solaris_auditon_stat=yes
4097 AC_MSG_RESULT([yes])
4098 AC_DEFINE([SOLARIS_AUDITON_STAT], 1,
4099           [Define to 1 if you have the `A_GETSTAT' and `A_SETSTAT' constants.])
4100 ], [
4101 solaris_auditon_stat=no
4102 AC_MSG_RESULT([no])
4104 AM_CONDITIONAL(SOLARIS_AUDITON_STAT, test x$solaris_auditon_stat = xyes)
4107 # Solaris-specific check determining if the new shmsys() syscall subcodes
4108 # IPC_XSTAT64, SHMADV, SHM_ADV_GET, SHM_ADV_SET and SHMGET_OSM are available.
4109 # These subcodes were added in Solaris 11 but are missing on illumos.
4111 # C-level symbol: SOLARIS_SHM_NEW
4112 # Automake-level symbol: SOLARIS_SHM_NEW
4114 AC_MSG_CHECKING([for SHMADV, SHM_ADV_GET, SHM_ADV_SET and SHMGET_OSM (Solaris-specific)])
4115 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
4116 #include <sys/ipc_impl.h>
4117 #include <sys/shm.h>
4118 #include <sys/shm_impl.h>
4119 ]], [[
4120   return !(IPC_XSTAT64 && SHMADV && SHM_ADV_GET && SHM_ADV_SET && SHMGET_OSM);
4121 ]])], [
4122 solaris_shm_new=yes
4123 AC_MSG_RESULT([yes])
4124 AC_DEFINE([SOLARIS_SHM_NEW], 1,
4125           [Define to 1 if you have the `IPC_XSTAT64', `SHMADV', `SHM_ADV_GET', `SHM_ADV_SET' and `SHMGET_OSM' constants.])
4126 ], [
4127 solaris_shm_new=no
4128 AC_MSG_RESULT([no])
4130 AM_CONDITIONAL(SOLARIS_SHM_NEW, test x$solaris_shm_new = xyes)
4133 # Solaris-specific check determining if prxregset_t is available.  Illumos
4134 # currently does not define it on the x86 platform.
4136 # C-level symbol: SOLARIS_PRXREGSET_T
4137 # Automake-level symbol: SOLARIS_PRXREGSET_T
4139 AC_MSG_CHECKING([for the `prxregset_t' type (Solaris-specific)])
4140 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
4141 #include <sys/procfs_isa.h>
4142 ]], [[
4143   return !sizeof(prxregset_t);
4144 ]])], [
4145 solaris_prxregset_t=yes
4146 AC_MSG_RESULT([yes])
4147 AC_DEFINE([SOLARIS_PRXREGSET_T], 1,
4148           [Define to 1 if you have the `prxregset_t' type.])
4149 ], [
4150 solaris_prxregset_t=no
4151 AC_MSG_RESULT([no])
4153 AM_CONDITIONAL(SOLARIS_PRXREGSET_T, test x$solaris_prxregset_t = xyes)
4156 # Solaris-specific check determining if the new frealpathat() syscall is
4157 # available.
4159 # New syscall (available on Solaris 11.1):
4160 # int frealpathat(int fd, char *path, char *buf, size_t buflen);
4162 # C-level symbol: SOLARIS_FREALPATHAT_SYSCALL
4163 # Automake-level symbol: SOLARIS_FREALPATHAT_SYSCALL
4165 AC_MSG_CHECKING([for the new `frealpathat' syscall (Solaris-specific)])
4166 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
4167 #include <sys/syscall.h>
4168 ]], [[
4169   return !SYS_frealpathat;
4170 ]])], [
4171 solaris_frealpathat_syscall=yes
4172 AC_MSG_RESULT([yes])
4173 AC_DEFINE([SOLARIS_FREALPATHAT_SYSCALL], 1,
4174           [Define to 1 if you have the new `frealpathat' syscall.])
4175 ], [
4176 solaris_frealpathat_syscall=no
4177 AC_MSG_RESULT([no])
4179 AM_CONDITIONAL(SOLARIS_FREALPATHAT_SYSCALL, test x$solaris_frealpathat_syscall = xyes)
4182 # Solaris-specific check determining if the new uuidsys() syscall is
4183 # available.
4185 # New syscall (available on newer Solaris):
4186 # int uuidsys(struct uuid *uuid);
4188 # C-level symbol: SOLARIS_UUIDSYS_SYSCALL
4189 # Automake-level symbol: SOLARIS_UUIDSYS_SYSCALL
4191 AC_MSG_CHECKING([for the new `uuidsys' syscall (Solaris-specific)])
4192 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
4193 #include <sys/syscall.h>
4194 ]], [[
4195   return !SYS_uuidsys;
4196 ]])], [
4197 solaris_uuidsys_syscall=yes
4198 AC_MSG_RESULT([yes])
4199 AC_DEFINE([SOLARIS_UUIDSYS_SYSCALL], 1,
4200           [Define to 1 if you have the new `uuidsys' syscall.])
4201 ], [
4202 solaris_uuidsys_syscall=no
4203 AC_MSG_RESULT([no])
4205 AM_CONDITIONAL(SOLARIS_UUIDSYS_SYSCALL, test x$solaris_uuidsys_syscall = xyes)
4208 # Solaris-specific check determining if the new labelsys() syscall subcode
4209 # TNDB_GET_TNIP is available.  This subcode was added in Solaris 11 but is
4210 # missing on illumos.
4212 # C-level symbol: SOLARIS_TNDB_GET_TNIP
4213 # Automake-level symbol: SOLARIS_TNDB_GET_TNIP
4215 AC_MSG_CHECKING([for TNDB_GET_TNIP (Solaris-specific)])
4216 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
4217 #include <sys/tsol/tndb.h>
4218 ]], [[
4219   return !TNDB_GET_TNIP;
4220 ]])], [
4221 solaris_tndb_get_tnip=yes
4222 AC_MSG_RESULT([yes])
4223 AC_DEFINE([SOLARIS_TNDB_GET_TNIP], 1,
4224           [Define to 1 if you have the `TNDB_GET_TNIP' constant.])
4225 ], [
4226 solaris_tndb_get_tnip=no
4227 AC_MSG_RESULT([no])
4229 AM_CONDITIONAL(SOLARIS_TNDB_GET_TNIP, test x$solaris_tndb_get_tnip = xyes)
4232 # Solaris-specific check determining if the new labelsys() syscall opcodes
4233 # TSOL_GETCLEARANCE and TSOL_SETCLEARANCE are available. These opcodes were
4234 # added in Solaris 11 but are missing on illumos.
4236 # C-level symbol: SOLARIS_TSOL_CLEARANCE
4237 # Automake-level symbol: SOLARIS_TSOL_CLEARANCE
4239 AC_MSG_CHECKING([for TSOL_GETCLEARANCE and TSOL_SETCLEARANCE (Solaris-specific)])
4240 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
4241 #include <sys/tsol/tsyscall.h>
4242 ]], [[
4243   return !(TSOL_GETCLEARANCE && TSOL_SETCLEARANCE);
4244 ]])], [
4245 solaris_tsol_clearance=yes
4246 AC_MSG_RESULT([yes])
4247 AC_DEFINE([SOLARIS_TSOL_CLEARANCE], 1,
4248           [Define to 1 if you have the `TSOL_GETCLEARANCE' and `TSOL_SETCLEARANCE' constants.])
4249 ], [
4250 solaris_tsol_clearance=no
4251 AC_MSG_RESULT([no])
4253 AM_CONDITIONAL(SOLARIS_TSOL_CLEARANCE, test x$solaris_tsol_clearance = xyes)
4256 # Solaris-specific check determining if the new pset() syscall subcode
4257 # PSET_GET_NAME is available. This subcode was added in Solaris 11.4 but
4258 # is missing on illumos and Solaris 11.3.
4260 # C-level symbol: SOLARIS_PSET_GET_NAME
4261 # Automake-level symbol: SOLARIS_PSET_GET_NAME
4263 AC_MSG_CHECKING([for PSET_GET_NAME (Solaris-specific)])
4264 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
4265 #include <sys/pset.h>
4266 ]], [[
4267   return !(PSET_GET_NAME);
4268 ]])], [
4269 solaris_pset_get_name=yes
4270 AC_MSG_RESULT([yes])
4271 AC_DEFINE([SOLARIS_PSET_GET_NAME], 1,
4272           [Define to 1 if you have the `PSET_GET_NAME' constants.])
4273 ], [
4274 solaris_pset_get_name=no
4275 AC_MSG_RESULT([no])
4277 AM_CONDITIONAL(SOLARIS_PSET_GET_NAME, test x$solaris_pset_get_name = xyes)
4280 # Solaris-specific check determining if the utimesys() syscall is
4281 # available (on illumos and older Solaris).
4283 # C-level symbol: SOLARIS_UTIMESYS_SYSCALL
4284 # Automake-level symbol: SOLARIS_UTIMESYS_SYSCALL
4286 AC_MSG_CHECKING([for the `utimesys' syscall (Solaris-specific)])
4287 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
4288 #include <sys/syscall.h>
4289 ]], [[
4290   return !SYS_utimesys;
4291 ]])], [
4292 solaris_utimesys_syscall=yes
4293 AC_MSG_RESULT([yes])
4294 AC_DEFINE([SOLARIS_UTIMESYS_SYSCALL], 1,
4295           [Define to 1 if you have the `utimesys' syscall.])
4296 ], [
4297 solaris_utimesys_syscall=no
4298 AC_MSG_RESULT([no])
4300 AM_CONDITIONAL(SOLARIS_UTIMESYS_SYSCALL, test x$solaris_utimesys_syscall = xyes)
4303 # Solaris-specific check determining if the utimensat() syscall is
4304 # available (on newer Solaris).
4306 # C-level symbol: SOLARIS_UTIMENSAT_SYSCALL
4307 # Automake-level symbol: SOLARIS_UTIMENSAT_SYSCALL
4309 AC_MSG_CHECKING([for the `utimensat' syscall (Solaris-specific)])
4310 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
4311 #include <sys/syscall.h>
4312 ]], [[
4313   return !SYS_utimensat;
4314 ]])], [
4315 solaris_utimensat_syscall=yes
4316 AC_MSG_RESULT([yes])
4317 AC_DEFINE([SOLARIS_UTIMENSAT_SYSCALL], 1,
4318           [Define to 1 if you have the `utimensat' syscall.])
4319 ], [
4320 solaris_utimensat_syscall=no
4321 AC_MSG_RESULT([no])
4323 AM_CONDITIONAL(SOLARIS_UTIMENSAT_SYSCALL, test x$solaris_utimensat_syscall = xyes)
4326 # Solaris-specific check determining if the spawn() syscall is available
4327 # (on newer Solaris).
4329 # C-level symbol: SOLARIS_SPAWN_SYSCALL
4330 # Automake-level symbol: SOLARIS_SPAWN_SYSCALL
4332 AC_MSG_CHECKING([for the `spawn' syscall (Solaris-specific)])
4333 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
4334 #include <sys/syscall.h>
4335 ]], [[
4336   return !SYS_spawn;
4337 ]])], [
4338 solaris_spawn_syscall=yes
4339 AC_MSG_RESULT([yes])
4340 AC_DEFINE([SOLARIS_SPAWN_SYSCALL], 1,
4341           [Define to 1 if you have the `spawn' syscall.])
4342 ], [
4343 solaris_spawn_syscall=no
4344 AC_MSG_RESULT([no])
4346 AM_CONDITIONAL(SOLARIS_SPAWN_SYSCALL, test x$solaris_spawn_syscall = xyes)
4349 # Solaris-specific check determining if commands MODNVL_CTRLMAP through
4350 # MODDEVINFO_CACHE_TS for modctl() syscall are available (on newer Solaris).
4352 # C-level symbol: SOLARIS_MODCTL_MODNVL
4353 # Automake-level symbol: SOLARIS_MODCTL_MODNVL
4355 AC_MSG_CHECKING([for MODNVL_CTRLMAP through MODDEVINFO_CACHE_TS modctl(2) commands (Solaris-specific)])
4356 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
4357 #include <sys/modctl.h>
4358 ]], [[
4359   return !(MODNVL_CTRLMAP && MODDEVINFO_CACHE_TS);
4360 ]])], [
4361 solaris_modctl_modnvl=yes
4362 AC_MSG_RESULT([yes])
4363 AC_DEFINE([SOLARIS_MODCTL_MODNVL], 1,
4364           [Define to 1 if you have the `MODNVL_CTRLMAP' through `MODDEVINFO_CACHE_TS' constants.])
4365 ], [
4366 solaris_modctl_modnvl=no
4367 AC_MSG_RESULT([no])
4369 AM_CONDITIONAL(SOLARIS_MODCTL_MODNVL, test x$solaris_modctl_modnvl = xyes)
4372 # Solaris-specific check determining whether nscd (name switch cache daemon)
4373 # attaches its door at /system/volatile/name_service_door (Solaris)
4374 # or at /var/run/name_service_door (illumos).
4376 # Note that /var/run is a symlink to /system/volatile on Solaris
4377 # but not vice versa on illumos.
4379 # C-level symbol: SOLARIS_NSCD_DOOR_SYSTEM_VOLATILE
4380 # Automake-level symbol: SOLARIS_NSCD_DOOR_SYSTEM_VOLATILE
4382 AC_MSG_CHECKING([for nscd door location (Solaris-specific)])
4383 if test -e /system/volatile/name_service_door; then
4384     solaris_nscd_door_system_volatile=yes
4385     AC_MSG_RESULT([/system/volatile/name_service_door])
4386     AC_DEFINE([SOLARIS_NSCD_DOOR_SYSTEM_VOLATILE], 1,
4387               [Define to 1 if nscd attaches to /system/volatile/name_service_door.])
4388 else
4389     solaris_nscd_door_system_volatile=no
4390     AC_MSG_RESULT([/var/run/name_service_door])
4392 AM_CONDITIONAL(SOLARIS_NSCD_DOOR_SYSTEM_VOLATILE, test x$solaris_nscd_door_system_volatile = xyes)
4395 # Solaris-specific check determining if the new gethrt() fasttrap is available.
4397 # New fasttrap (available on Solaris 11):
4398 # hrt_t *gethrt(void);
4400 # C-level symbol: SOLARIS_GETHRT_FASTTRAP
4401 # Automake-level symbol: SOLARIS_GETHRT_FASTTRAP
4403 AC_MSG_CHECKING([for the new `gethrt' fasttrap (Solaris-specific)])
4404 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
4405 #include <sys/trap.h>
4406 ]], [[
4407   return !T_GETHRT;
4408 ]])], [
4409 solaris_gethrt_fasttrap=yes
4410 AC_MSG_RESULT([yes])
4411 AC_DEFINE([SOLARIS_GETHRT_FASTTRAP], 1,
4412           [Define to 1 if you have the new `gethrt' fasttrap.])
4413 ], [
4414 solaris_gethrt_fasttrap=no
4415 AC_MSG_RESULT([no])
4417 AM_CONDITIONAL(SOLARIS_GETHRT_FASTTRAP, test x$solaris_gethrt_fasttrap = xyes)
4420 # Solaris-specific check determining if the new get_zone_offset() fasttrap
4421 # is available.
4423 # New fasttrap (available on Solaris 11):
4424 # zonehrtoffset_t *get_zone_offset(void);
4426 # C-level symbol: SOLARIS_GETZONEOFFSET_FASTTRAP
4427 # Automake-level symbol: SOLARIS_GETZONEOFFSET_FASTTRAP
4429 AC_MSG_CHECKING([for the new `get_zone_offset' fasttrap (Solaris-specific)])
4430 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
4431 #include <sys/trap.h>
4432 ]], [[
4433   return !T_GETZONEOFFSET;
4434 ]])], [
4435 solaris_getzoneoffset_fasttrap=yes
4436 AC_MSG_RESULT([yes])
4437 AC_DEFINE([SOLARIS_GETZONEOFFSET_FASTTRAP], 1,
4438           [Define to 1 if you have the new `get_zone_offset' fasttrap.])
4439 ], [
4440 solaris_getzoneoffset_fasttrap=no
4441 AC_MSG_RESULT([no])
4443 AM_CONDITIONAL(SOLARIS_GETZONEOFFSET_FASTTRAP, test x$solaris_getzoneoffset_fasttrap = xyes)
4446 # Solaris-specific check determining if the execve() syscall
4447 # takes fourth argument (flags) or not.
4449 # Old syscall (available on illumos):
4450 # int execve(const char *fname, const char **argv, const char **envp);
4452 # New syscall (available on Solaris):
4453 # int execve(uintptr_t file, const char **argv, const char **envp, int flags);
4455 # If the new syscall is present then it will fail with EINVAL (because flags
4456 # are invalid); if the old syscall is available then it will fail with ENOENT
4457 # (because the file could not be found).
4459 # C-level symbol: SOLARIS_EXECVE_SYSCALL_TAKES_FLAGS
4460 # Automake-level symbol: SOLARIS_EXECVE_SYSCALL_TAKES_FLAGS
4462 AC_MSG_CHECKING([if the `execve' syscall accepts flags (Solaris-specific)])
4463 AC_RUN_IFELSE([AC_LANG_PROGRAM([[
4464 #include <sys/syscall.h>
4465 #include <errno.h>
4466 ]], [[
4467   errno = 0;
4468   syscall(SYS_execve, "/no/existing/path", 0, 0, 0xdeadbeef, 0, 0);
4469   return !(errno == EINVAL);
4470 ]])], [
4471 solaris_execve_syscall_takes_flags=yes
4472 AC_MSG_RESULT([yes])
4473 AC_DEFINE([SOLARIS_EXECVE_SYSCALL_TAKES_FLAGS], 1,
4474           [Define to 1 if you have the new `execve' syscall which accepts flags.])
4475 ], [
4476 solaris_execve_syscall_takes_flags=no
4477 AC_MSG_RESULT([no])
4479 AM_CONDITIONAL(SOLARIS_EXECVE_SYSCALL_TAKES_FLAGS,
4480                test x$solaris_execve_syscall_takes_flags = xyes)
4483 # Solaris-specific check determining version of the repository cache protocol.
4484 # Every Solaris version uses a different one, ranging from 21 to current 25.
4485 # The check is very ugly, though.
4487 # C-level symbol: SOLARIS_REPCACHE_PROTOCOL_VERSION vv
4488 # Automake-level symbol: none
4490 AC_PATH_PROG(DIS_PATH, dis, false)
4491 if test "x$DIS_PATH" = "xfalse"; then
4492   AC_MSG_FAILURE([Object code disassembler (`dis') not found.])
4494 AC_CHECK_LIB(scf, scf_handle_bind, [], [
4495   AC_MSG_WARN([Function `scf_handle_bind' was not found in `libscf'.])
4496   AC_MSG_ERROR([Cannot determine version of the repository cache protocol.])
4499 AC_MSG_CHECKING([for version of the repository cache protocol (Solaris-specific)])
4500 if test "X$VGCONF_ARCH_PRI" = "Xamd64"; then
4501   libscf=/usr/lib/64/libscf.so.1
4502 else
4503   libscf=/usr/lib/libscf.so.1
4505 if ! $DIS_PATH -F scf_handle_bind $libscf  | grep -q 0x526570; then
4506   AC_MSG_WARN([Function `scf_handle_bind' does not contain repository cache protocol version.])
4507   AC_MSG_ERROR([Cannot determine version of the repository cache protocol.])
4509 hex=$( $DIS_PATH -F scf_handle_bind $libscf  | sed -n 's/.*0x526570\(..\).*/\1/p' )
4510 if test -z "$hex"; then
4511   AC_MSG_WARN([Version of the repository cache protocol is empty?!])
4512   AC_MSG_ERROR([Cannot determine version of the repository cache protocol.])
4514 version=$( printf "%d\n" 0x$hex )
4515 AC_MSG_RESULT([$version])
4516 AC_DEFINE_UNQUOTED([SOLARIS_REPCACHE_PROTOCOL_VERSION], [$version],
4517                    [Version number of the repository door cache protocol.])
4520 # Solaris-specific check determining if "sysstat" segment reservation type
4521 # is available.
4523 # New "sysstat" segment reservation (available on Solaris 11.4):
4524 # - program header type:    PT_SUNW_SYSSTAT
4525 # - auxiliary vector entry: AT_SUN_SYSSTAT_ADDR
4527 # C-level symbol: SOLARIS_RESERVE_SYSSTAT_ADDR
4528 # Automake-level symbol: SOLARIS_RESERVE_SYSSTAT_ADDR
4530 AC_MSG_CHECKING([for the new `sysstat' segment reservation (Solaris-specific)])
4531 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
4532 #include <sys/auxv.h>
4533 ]], [[
4534   return !AT_SUN_SYSSTAT_ADDR;
4535 ]])], [
4536 solaris_reserve_sysstat_addr=yes
4537 AC_MSG_RESULT([yes])
4538 AC_DEFINE([SOLARIS_RESERVE_SYSSTAT_ADDR], 1,
4539           [Define to 1 if you have the new `sysstat' segment reservation.])
4540 ], [
4541 solaris_reserve_sysstat_addr=no
4542 AC_MSG_RESULT([no])
4544 AM_CONDITIONAL(SOLARIS_RESERVE_SYSSTAT_ADDR, test x$solaris_reserve_sysstat_addr = xyes)
4547 # Solaris-specific check determining if "sysstat_zone" segment reservation type
4548 # is available.
4550 # New "sysstat_zone" segment reservation (available on Solaris 11.4):
4551 # - program header type:    PT_SUNW_SYSSTAT_ZONE
4552 # - auxiliary vector entry: AT_SUN_SYSSTAT_ZONE_ADDR
4554 # C-level symbol: SOLARIS_RESERVE_SYSSTAT_ZONE_ADDR
4555 # Automake-level symbol: SOLARIS_RESERVE_SYSSTAT_ZONE_ADDR
4557 AC_MSG_CHECKING([for the new `sysstat_zone' segment reservation (Solaris-specific)])
4558 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
4559 #include <sys/auxv.h>
4560 ]], [[
4561   return !AT_SUN_SYSSTAT_ZONE_ADDR;
4562 ]])], [
4563 solaris_reserve_sysstat_zone_addr=yes
4564 AC_MSG_RESULT([yes])
4565 AC_DEFINE([SOLARIS_RESERVE_SYSSTAT_ZONE_ADDR], 1,
4566           [Define to 1 if you have the new `sysstat_zone' segment reservation.])
4567 ], [
4568 solaris_reserve_sysstat_zone_addr=no
4569 AC_MSG_RESULT([no])
4571 AM_CONDITIONAL(SOLARIS_RESERVE_SYSSTAT_ZONE_ADDR, test x$solaris_reserve_sysstat_zone_addr = xyes)
4574 # Solaris-specific check determining if the system_stats() syscall is available
4575 # (on newer Solaris).
4577 # C-level symbol: SOLARIS_SYSTEM_STATS_SYSCALL
4578 # Automake-level symbol: SOLARIS_SYSTEM_STATS_SYSCALL
4580 AC_MSG_CHECKING([for the `system_stats' syscall (Solaris-specific)])
4581 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
4582 #include <sys/syscall.h>
4583 ]], [[
4584   return !SYS_system_stats;
4585 ]])], [
4586 solaris_system_stats_syscall=yes
4587 AC_MSG_RESULT([yes])
4588 AC_DEFINE([SOLARIS_SYSTEM_STATS_SYSCALL], 1,
4589           [Define to 1 if you have the `system_stats' syscall.])
4590 ], [
4591 solaris_system_stats_syscall=no
4592 AC_MSG_RESULT([no])
4594 AM_CONDITIONAL(SOLARIS_SYSTEM_STATS_SYSCALL, test x$solaris_system_stats_syscall = xyes)
4597 # Solaris-specific check determining if fpregset_t defines struct _fpchip_state
4598 # (on newer illumos) or struct fpchip_state (Solaris, older illumos).
4600 # C-level symbol: SOLARIS_FPCHIP_STATE_TAKES_UNDERSCORE
4601 # Automake-level symbol: none
4603 AC_CHECK_TYPE([struct _fpchip_state],
4604               [solaris_fpchip_state_takes_underscore=yes],
4605               [solaris_fpchip_state_takes_underscore=no],
4606               [[#include <sys/regset.h>]])
4607 if test "$solaris_fpchip_state_takes_underscore" = "yes"; then
4608   AC_DEFINE(SOLARIS_FPCHIP_STATE_TAKES_UNDERSCORE, 1,
4609             [Define to 1 if fpregset_t defines struct _fpchip_state])
4613 # Solaris-specific check determining if schedctl page shared between kernel
4614 # and userspace program is executable (illumos, older Solaris) or not (newer
4615 # Solaris).
4617 # C-level symbol: SOLARIS_SCHEDCTL_PAGE_EXEC
4618 # Automake-level symbol: none
4620 AC_MSG_CHECKING([if schedctl page is executable (Solaris-specific)])
4621 AC_RUN_IFELSE([AC_LANG_PROGRAM([[
4622 #include <assert.h>
4623 #include <fcntl.h>
4624 #include <procfs.h>
4625 #include <schedctl.h>
4626 #include <stdio.h>
4627 #include <unistd.h>
4628 ]], [[
4629     schedctl_t *scp = schedctl_init();
4630     if (scp == NULL)
4631         return 1;
4633     int fd = open("/proc/self/map", O_RDONLY);
4634     assert(fd >= 0);
4636     prmap_t map;
4637     ssize_t rd;
4638     while ((rd = read(fd, &map, sizeof(map))) == sizeof(map)) {
4639         if (map.pr_vaddr == ((uintptr_t) scp & PAGEMASK)) {
4640             fprintf(stderr, "%#lx [%zu] %s\n", map.pr_vaddr, map.pr_size,
4641                     (map.pr_mflags & MA_EXEC) ? "x" : "no-x");
4642             return (map.pr_mflags & MA_EXEC);
4643         }
4644     }
4646     return 1;
4647 ]])], [
4648 solaris_schedctl_page_exec=no
4649 AC_MSG_RESULT([no])
4650 ], [
4651 solaris_schedctl_page_exec=yes
4652 AC_MSG_RESULT([yes])
4653 AC_DEFINE([SOLARIS_SCHEDCTL_PAGE_EXEC], 1,
4654           [Define to 1 if you have the schedctl page executable.])
4658 # Solaris-specific check determining if PT_SUNWDTRACE program header provides
4659 # scratch space for DTrace fasttrap provider (illumos, older Solaris) or just
4660 # an initial thread pointer for libc (newer Solaris).
4662 # C-level symbol: SOLARIS_PT_SUNDWTRACE_THRP
4663 # Automake-level symbol: none
4665 AC_MSG_CHECKING([if PT_SUNWDTRACE serves for initial thread pointer (Solaris-specific)])
4666 AC_RUN_IFELSE([AC_LANG_PROGRAM([[
4667 #include <sys/fasttrap_isa.h>
4668 ]], [[
4669     return !FT_SCRATCHSIZE;
4670 ]])], [
4671 solaris_pt_sunwdtrace_thrp=yes
4672 AC_MSG_RESULT([yes])
4673 AC_DEFINE([SOLARIS_PT_SUNDWTRACE_THRP], 1,
4674           [Define to 1 if PT_SUNWDTRACE program header provides just an initial thread pointer for libc.])
4675 ], [
4676 solaris_pt_sunwdtrace_thrp=no
4677 AC_MSG_RESULT([no])
4680 else
4681 AM_CONDITIONAL(SOLARIS_SUN_STUDIO_AS, false)
4682 AM_CONDITIONAL(SOLARIS_XPG_SYMBOLS_PRESENT, false)
4683 AM_CONDITIONAL(SOLARIS_PROC_CMDLINE, false)
4684 AM_CONDITIONAL(SOLARIS_OLD_SYSCALLS, false)
4685 AM_CONDITIONAL(SOLARIS_LWP_SIGQUEUE_SYSCALL, false)
4686 AM_CONDITIONAL(SOLARIS_LWP_SIGQUEUE_SYSCALL_TAKES_PID, false)
4687 AM_CONDITIONAL(SOLARIS_LWP_NAME_SYSCALL, false)
4688 AM_CONDITIONAL(SOLARIS_GETRANDOM_SYSCALL, false)
4689 AM_CONDITIONAL(SOLARIS_ZONE_DEFUNCT, false)
4690 AM_CONDITIONAL(SOLARIS_AUDITON_STAT, false)
4691 AM_CONDITIONAL(SOLARIS_SHM_NEW, false)
4692 AM_CONDITIONAL(SOLARIS_PRXREGSET_T, false)
4693 AM_CONDITIONAL(SOLARIS_FREALPATHAT_SYSCALL, false)
4694 AM_CONDITIONAL(SOLARIS_UUIDSYS_SYSCALL, false)
4695 AM_CONDITIONAL(SOLARIS_TNDB_GET_TNIP, false)
4696 AM_CONDITIONAL(SOLARIS_TSOL_CLEARANCE, false)
4697 AM_CONDITIONAL(SOLARIS_PSET_GET_NAME, false)
4698 AM_CONDITIONAL(SOLARIS_UTIMESYS_SYSCALL, false)
4699 AM_CONDITIONAL(SOLARIS_UTIMENSAT_SYSCALL, false)
4700 AM_CONDITIONAL(SOLARIS_SPAWN_SYSCALL, false)
4701 AM_CONDITIONAL(SOLARIS_MODCTL_MODNVL, false)
4702 AM_CONDITIONAL(SOLARIS_NSCD_DOOR_SYSTEM_VOLATILE, false)
4703 AM_CONDITIONAL(SOLARIS_GETHRT_FASTTRAP, false)
4704 AM_CONDITIONAL(SOLARIS_GETZONEOFFSET_FASTTRAP, false)
4705 AM_CONDITIONAL(SOLARIS_EXECVE_SYSCALL_TAKES_FLAGS, false)
4706 AM_CONDITIONAL(SOLARIS_RESERVE_SYSSTAT_ADDR, false)
4707 AM_CONDITIONAL(SOLARIS_RESERVE_SYSSTAT_ZONE_ADDR, false)
4708 AM_CONDITIONAL(SOLARIS_SYSTEM_STATS_SYSCALL, false)
4709 fi # test "$VGCONF_OS" = "solaris"
4711 #----------------------------------------------------------------------------
4712 # FreeBSD-specific checks.
4713 #----------------------------------------------------------------------------
4715 # Rather than having a large number of feature test as above with Solaris
4716 # these tests are per-version. This may not be entirely relialable for
4717 # FreeBSD development branches (XX.Y-CURRENT) or pre-release branches
4718 # (XX.Y-STABLE) but it should work for XX-Y-RELEASE
4720 if test "$VGCONF_OS" = "freebsd" ; then
4722 AM_CONDITIONAL(FREEBSD_VERS_13_PLUS, test $freebsd_vers -ge $freebsd_13_0)
4724 else
4726 AM_CONDITIONAL(FREEBSD_VERS_13_PLUS, false)
4728 fi # test "$VGCONF_OS" = "freebsd"
4731 #----------------------------------------------------------------------------
4732 # Checks for C header files.
4733 #----------------------------------------------------------------------------
4735 AC_CHECK_HEADERS([       \
4736         asm/unistd.h     \
4737         endian.h         \
4738         mqueue.h         \
4739         sys/endian.h     \
4740         sys/epoll.h      \
4741         sys/eventfd.h    \
4742         sys/klog.h       \
4743         sys/poll.h       \
4744         sys/prctl.h      \
4745         sys/signal.h     \
4746         sys/signalfd.h   \
4747         sys/syscall.h    \
4748         sys/sysnvl.h     \
4749         sys/time.h       \
4750         sys/types.h      \
4751         ])
4753 # Verify whether the <linux/futex.h> header is usable.
4754 AC_MSG_CHECKING([if <linux/futex.h> is usable])
4756 save_CFLAGS="$CFLAGS"
4757 CFLAGS="$CFLAGS -D__user="
4758 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
4759 #include <linux/futex.h>
4760 ]], [[
4761   return FUTEX_WAIT;
4762 ]])], [
4763 ac_have_usable_linux_futex_h=yes
4764 AC_DEFINE([HAVE_USABLE_LINUX_FUTEX_H], 1,
4765           [Define to 1 if you have a usable <linux/futex.h> header file.])
4766 AC_MSG_RESULT([yes])
4767 ], [
4768 ac_have_usable_linux_futex_h=no
4769 AC_MSG_RESULT([no])
4771 CFLAGS="$save_CFLAGS"
4774 #----------------------------------------------------------------------------
4775 # Checks for typedefs, structures, and compiler characteristics.
4776 #----------------------------------------------------------------------------
4777 AC_TYPE_UID_T
4778 AC_TYPE_OFF_T
4779 AC_TYPE_SIZE_T
4780 AC_CHECK_HEADERS_ONCE([sys/time.h])
4782 AC_CHECK_TYPE([struct statx], [
4783   AC_DEFINE([HAVE_STRUCT_STATX_IN_SYS_STAT_H], 1,
4784             [Define to 1 if <sys/stat.h> declares struct statx.])
4785 ], [], [
4786   #define _GNU_SOURCE
4787   #include <sys/stat.h>
4791 #----------------------------------------------------------------------------
4792 # Checks for library functions.
4793 #----------------------------------------------------------------------------
4794 AC_FUNC_MEMCMP
4795 AC_FUNC_MMAP
4797 AC_CHECK_LIB([pthread], [pthread_create])
4798 AC_CHECK_LIB([rt], [clock_gettime])
4800 AC_CHECK_FUNCS([     \
4801         clock_gettime\
4802         copy_file_range \
4803         epoll_create \
4804         epoll_pwait  \
4805         klogctl      \
4806         mallinfo     \
4807         memchr       \
4808         memfd_create \
4809         memset       \
4810         mkdir        \
4811         mremap       \
4812         ppoll        \
4813         preadv       \
4814         preadv2      \
4815         process_vm_readv  \
4816         process_vm_writev \
4817         pthread_barrier_init       \
4818         pthread_condattr_setclock  \
4819         pthread_mutex_timedlock    \
4820         pthread_rwlock_timedrdlock \
4821         pthread_rwlock_timedwrlock \
4822         pthread_setname_np         \
4823         pthread_spin_lock          \
4824         pthread_yield              \
4825         pwritev      \
4826         pwritev2     \
4827         rawmemchr    \
4828         readlinkat   \
4829         semtimedop   \
4830         setcontext   \
4831         signalfd     \
4832         sigwaitinfo  \
4833         strchr       \
4834         strdup       \
4835         strpbrk      \
4836         strrchr      \
4837         strstr       \
4838         swapcontext  \
4839         syscall      \
4840         utimensat    \
4841         mempcpy      \
4842         stpncpy      \
4843         strchrnul    \
4844         memrchr      \
4845         strndup      \
4846         ])
4848 # AC_CHECK_LIB adds any library found to the variable LIBS, and links these
4849 # libraries with any shared object and/or executable. This is NOT what we
4850 # want for e.g. vgpreload_core-x86-linux.so
4851 LIBS=""
4853 AM_CONDITIONAL([HAVE_PTHREAD_BARRIER],
4854                [test x$ac_cv_func_pthread_barrier_init = xyes])
4855 AM_CONDITIONAL([HAVE_PTHREAD_MUTEX_TIMEDLOCK],
4856                [test x$ac_cv_func_pthread_mutex_timedlock = xyes])
4857 AM_CONDITIONAL([HAVE_PTHREAD_SPINLOCK],
4858                [test x$ac_cv_func_pthread_spin_lock = xyes])
4859 AM_CONDITIONAL([HAVE_PTHREAD_SETNAME_NP],
4860                [test x$ac_cv_func_pthread_setname_np = xyes])
4861 AM_CONDITIONAL([HAVE_COPY_FILE_RANGE],
4862                [test x$ac_cv_func_copy_file_range = xyes])
4863 AM_CONDITIONAL([HAVE_PREADV_PWRITEV],
4864                [test x$ac_cv_func_preadv = xyes && test x$ac_cv_func_pwritev = xyes])
4865 AM_CONDITIONAL([HAVE_PREADV2_PWRITEV2],
4866                [test x$ac_cv_func_preadv2 = xyes && test x$ac_cv_func_pwritev2 = xyes])
4867 AM_CONDITIONAL([HAVE_SETCONTEXT], [test x$ac_cv_func_setcontext = xyes])
4868 AM_CONDITIONAL([HAVE_SWAPCONTEXT], [test x$ac_cv_func_swapcontext = xyes])
4869 AM_CONDITIONAL([HAVE_MEMFD_CREATE],
4870                [test x$ac_cv_func_memfd_create = xyes])
4872 if test x$VGCONF_PLATFORM_PRI_CAPS = xMIPS32_LINUX \
4873      -o x$VGCONF_PLATFORM_PRI_CAPS = xMIPS64_LINUX \
4874      -o x$VGCONF_PLATFORM_PRI_CAPS = xNANOMIPS_LINUX; then
4875   AC_DEFINE([DISABLE_PTHREAD_SPINLOCK_INTERCEPT], 1,
4876             [Disable intercept pthread_spin_lock() on MIPS32, MIPS64 and nanoMIPS.])
4879 #----------------------------------------------------------------------------
4880 # MPI checks
4881 #----------------------------------------------------------------------------
4882 # Do we have a useable MPI setup on the primary and/or secondary targets?
4883 # On Linux, by default, assumes mpicc and -m32/-m64
4884 # Note: this is a kludge in that it assumes the specified mpicc 
4885 # understands -m32/-m64 regardless of what is specified using
4886 # --with-mpicc=.
4887 AC_PATH_PROG([MPI_CC], [mpicc], [mpicc],
4888              [$PATH:/usr/lib/openmpi/bin:/usr/lib64/openmpi/bin])
4890 mflag_primary=
4891 if test x$VGCONF_PLATFORM_PRI_CAPS = xX86_LINUX \
4892      -o x$VGCONF_PLATFORM_PRI_CAPS = xX86_FREEBSD \
4893      -o x$VGCONF_PLATFORM_PRI_CAPS = xPPC32_LINUX \
4894      -o x$VGCONF_PLATFORM_PRI_CAPS = xARM_LINUX \
4895      -o x$VGCONF_PLATFORM_PRI_CAPS = xMIPS32_LINUX \
4896      -o x$VGCONF_PLATFORM_PRI_CAPS = xNANOMIPS_LINUX \
4897      -o x$VGCONF_PLATFORM_PRI_CAPS = xX86_SOLARIS ; then
4898   mflag_primary=$FLAG_M32
4899 elif test x$VGCONF_PLATFORM_PRI_CAPS = xAMD64_LINUX \
4900        -o x$VGCONF_PLATFORM_PRI_CAPS = xAMD64_FREEBSD \
4901        -o x$VGCONF_PLATFORM_PRI_CAPS = xPPC64_LINUX \
4902        -o x$VGCONF_PLATFORM_PRI_CAPS = xARM64_LINUX \
4903        -o x$VGCONF_PLATFORM_PRI_CAPS = xMIPS64_LINUX \
4904        -o x$VGCONF_PLATFORM_PRI_CAPS = xS390X_LINUX ; then
4905   mflag_primary=$FLAG_M64
4906 elif test x$VGCONF_PLATFORM_PRI_CAPS = xX86_DARWIN ; then
4907   mflag_primary="$FLAG_M32 -arch i386"
4908 elif test x$VGCONF_PLATFORM_PRI_CAPS = xAMD64_DARWIN ; then
4909   mflag_primary="$FLAG_M64 -arch x86_64"
4912 mflag_secondary=
4913 if test x$VGCONF_PLATFORM_SEC_CAPS = xX86_LINUX \
4914      -o x$VGCONF_PLATFORM_SEC_CAPS = xPPC32_LINUX \
4915      -o x$VGCONF_PLATFORM_SEC_CAPS = xX86_SOLARIS \
4916      -o x$VGCONF_PLATFORM_SEC_CAPS = xMIPS32_LINUX \
4917      -o x$VGCONF_PLATFORM_SEC_CAPS = xX86_FREEBSD ; then
4918   mflag_secondary=$FLAG_M32
4919 elif test x$VGCONF_PLATFORM_SEC_CAPS = xX86_DARWIN ; then
4920   mflag_secondary="$FLAG_M32 -arch i386"
4924 AC_ARG_WITH(mpicc,
4925    [  --with-mpicc=           Specify name of MPI2-ised C compiler],
4926    MPI_CC=$withval
4928 AC_SUBST(MPI_CC)
4930 ## We AM_COND_IF here instead of automake "if" in mpi/Makefile.am so that we can
4931 ## use these values in the check for a functioning mpicc.
4933 ## We leave the MPI_FLAG_M3264_ logic in mpi/Makefile.am and assume that
4934 ## mflag_primary/mflag_secondary are sufficient approximations of that behavior
4935 AM_COND_IF([VGCONF_OS_IS_LINUX],
4936            [CFLAGS_MPI="-g -O -fno-omit-frame-pointer -Wall -fpic"
4937             LDFLAGS_MPI="-fpic -shared"])
4938 AM_COND_IF([VGCONF_OS_IS_FREEBSD],
4939            [CFLAGS_MPI="-g -O -fno-omit-frame-pointer -Wall -fpic"
4940             LDFLAGS_MPI="-fpic -shared"])
4941 AM_COND_IF([VGCONF_OS_IS_DARWIN],
4942            [CFLAGS_MPI="-g -O -fno-omit-frame-pointer -Wall -dynamic"
4943             LDFLAGS_MPI="-dynamic -dynamiclib -all_load"])
4944 AM_COND_IF([VGCONF_OS_IS_SOLARIS],
4945            [CFLAGS_MPI="-g -O -fno-omit-frame-pointer -Wall -fpic"
4946             LDFLAGS_MPI="-fpic -shared"])
4948 AC_SUBST([CFLAGS_MPI])
4949 AC_SUBST([LDFLAGS_MPI])
4952 ## See if MPI_CC works for the primary target
4954 AC_MSG_CHECKING([primary target for usable MPI2-compliant C compiler and mpi.h])
4955 saved_CC=$CC
4956 saved_CFLAGS=$CFLAGS
4957 CC=$MPI_CC
4958 CFLAGS="$CFLAGS_MPI $mflag_primary"
4959 saved_LDFLAGS="$LDFLAGS"
4960 LDFLAGS="$LDFLAGS_MPI $mflag_primary"
4961 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
4962 #include <mpi.h>
4963 #include <stdio.h>
4964 ]], [[
4965   int ni, na, nd, comb;
4966   int r = MPI_Init(NULL,NULL);
4967   r |= MPI_Type_get_envelope( MPI_INT, &ni, &na, &nd, &comb );
4968   r |= MPI_Finalize();
4969   return r; 
4970 ]])], [
4971 ac_have_mpi2_pri=yes
4972 AC_MSG_RESULT([yes, $MPI_CC])
4973 ], [
4974 ac_have_mpi2_pri=no
4975 AC_MSG_RESULT([no])
4977 CC=$saved_CC
4978 CFLAGS=$saved_CFLAGS
4979 LDFLAGS="$saved_LDFLAGS"
4980 AM_CONDITIONAL(BUILD_MPIWRAP_PRI, test x$ac_have_mpi2_pri = xyes)
4982 ## See if MPI_CC works for the secondary target.  Complication: what if
4983 ## there is no secondary target?  We need this to then fail.
4984 ## Kludge this by making MPI_CC something which will surely fail in
4985 ## such a case.
4987 AC_MSG_CHECKING([secondary target for usable MPI2-compliant C compiler and mpi.h])
4988 saved_CC=$CC
4989 saved_CFLAGS=$CFLAGS
4990 saved_LDFLAGS="$LDFLAGS"
4991 LDFLAGS="$LDFLAGS_MPI $mflag_secondary"
4992 if test x$VGCONF_PLATFORM_SEC_CAPS = x ; then
4993   CC="$MPI_CC this will surely fail"
4994 else
4995   CC=$MPI_CC
4997 CFLAGS="$CFLAGS_MPI $mflag_secondary"
4998 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
4999 #include <mpi.h>
5000 #include <stdio.h>
5001 ]], [[
5002   int ni, na, nd, comb;
5003   int r = MPI_Init(NULL,NULL);
5004   r |= MPI_Type_get_envelope( MPI_INT, &ni, &na, &nd, &comb );
5005   r |= MPI_Finalize();
5006   return r; 
5007 ]])], [
5008 ac_have_mpi2_sec=yes
5009 AC_MSG_RESULT([yes, $MPI_CC])
5010 ], [
5011 ac_have_mpi2_sec=no
5012 AC_MSG_RESULT([no])
5014 CC=$saved_CC
5015 CFLAGS=$saved_CFLAGS
5016 LDFLAGS="$saved_LDFLAGS"
5017 AM_CONDITIONAL(BUILD_MPIWRAP_SEC, test x$ac_have_mpi2_sec = xyes)
5020 #----------------------------------------------------------------------------
5021 # Other library checks
5022 #----------------------------------------------------------------------------
5023 # There now follow some tests for Boost, and OpenMP.  These
5024 # tests are present because Drd has some regression tests that use
5025 # these packages.  All regression test programs all compiled only
5026 # for the primary target.  And so it is important that the configure
5027 # checks that follow, use the correct -m32 or -m64 flag for the
5028 # primary target (called $mflag_primary).  Otherwise, we can end up
5029 # in a situation (eg) where, on amd64-linux, the test for Boost checks
5030 # for usable 64-bit Boost facilities, but because we are doing a 32-bit
5031 # only build (meaning, the primary target is x86-linux), the build
5032 # of the regtest programs that use Boost fails, because they are 
5033 # build as 32-bit (IN THIS EXAMPLE).
5035 # Hence: ALWAYS USE $mflag_primary FOR CONFIGURE TESTS FOR FACILITIES
5036 # NEEDED BY THE REGRESSION TEST PROGRAMS.
5039 # Check whether the boost library 1.35 or later has been installed.
5040 # The Boost.Threads library has undergone a major rewrite in version 1.35.0.
5042 AC_MSG_CHECKING([for boost])
5044 AC_LANG(C++)
5045 safe_CXXFLAGS=$CXXFLAGS
5046 CXXFLAGS="$mflag_primary"
5047 safe_LIBS="$LIBS"
5048 LIBS="-lboost_thread-mt -lboost_system-mt $LIBS"
5050 AC_LINK_IFELSE([AC_LANG_SOURCE([
5051 #include <boost/thread.hpp>
5052 static void thread_func(void)
5053 { }
5054 int main(int argc, char** argv)
5056   boost::thread t(thread_func);
5057   return 0;
5059 ])],
5061 ac_have_boost_1_35=yes
5062 AC_SUBST([BOOST_CFLAGS], [])
5063 AC_SUBST([BOOST_LIBS], ["-lboost_thread-mt -lboost_system-mt"])
5064 AC_MSG_RESULT([yes])
5065 ], [
5066 ac_have_boost_1_35=no
5067 AC_MSG_RESULT([no])
5070 LIBS="$safe_LIBS"
5071 CXXFLAGS=$safe_CXXFLAGS
5072 AC_LANG(C)
5074 AM_CONDITIONAL([HAVE_BOOST_1_35], [test x$ac_have_boost_1_35 = xyes])
5077 # does this compiler support -fopenmp, does it have the include file
5078 # <omp.h> and does it have libgomp ?
5080 AC_MSG_CHECKING([for OpenMP])
5082 safe_CFLAGS=$CFLAGS
5083 CFLAGS="-fopenmp $mflag_primary -Werror"
5085 AC_LINK_IFELSE([AC_LANG_SOURCE([
5086 #include <omp.h> 
5087 int main(int argc, char** argv)
5089   omp_set_dynamic(0);
5090   return 0;
5092 ])],
5094 ac_have_openmp=yes
5095 AC_MSG_RESULT([yes])
5096 ], [
5097 ac_have_openmp=no
5098 AC_MSG_RESULT([no])
5100 CFLAGS=$safe_CFLAGS
5102 AM_CONDITIONAL([HAVE_OPENMP], [test x$ac_have_openmp = xyes])
5105 # Check for __builtin_popcount
5106 AC_MSG_CHECKING([for __builtin_popcount()])
5107 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
5108 ]], [[
5109   __builtin_popcount(2);
5110   return 0;
5111 ]])], [
5112 AC_MSG_RESULT([yes])
5113 AC_DEFINE([HAVE_BUILTIN_POPCOUT], 1,
5114           [Define to 1 if compiler provides __builtin_popcount().])
5115 ], [
5116 AC_MSG_RESULT([no])
5119 # Check for __builtin_clz
5120 AC_MSG_CHECKING([for __builtin_clz()])
5121 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
5122 ]], [[
5123   __builtin_clz(2);
5124   return 0;
5125 ]])], [
5126 AC_MSG_RESULT([yes])
5127 AC_DEFINE([HAVE_BUILTIN_CLZ], 1,
5128           [Define to 1 if compiler provides __builtin_clz().])
5129 ], [
5130 AC_MSG_RESULT([no])
5133 # Check for __builtin_ctz
5134 AC_MSG_CHECKING([for __builtin_ctz()])
5135 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
5136 ]], [[
5137   __builtin_ctz(2);
5138   return 0;
5139 ]])], [
5140 AC_MSG_RESULT([yes])
5141 AC_DEFINE([HAVE_BUILTIN_CTZ], 1,
5142           [Define to 1 if compiler provides __builtin_ctz().])
5143 ], [
5144 AC_MSG_RESULT([no])
5147 # does this compiler have built-in functions for atomic memory access for the
5148 # primary target ?
5149 AC_MSG_CHECKING([if gcc supports __sync_add_and_fetch for the primary target])
5151 safe_CFLAGS=$CFLAGS
5152 CFLAGS="$mflag_primary"
5154 AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[
5155   int variable = 1;
5156   return (__sync_bool_compare_and_swap(&variable, 1, 2)
5157           && __sync_add_and_fetch(&variable, 1) ? 1 : 0)
5158 ]])], [
5159   ac_have_builtin_atomic_primary=yes
5160   AC_MSG_RESULT([yes])
5161   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])
5162 ], [
5163   ac_have_builtin_atomic_primary=no
5164   AC_MSG_RESULT([no])
5167 CFLAGS=$safe_CFLAGS
5169 AM_CONDITIONAL([HAVE_BUILTIN_ATOMIC],
5170                [test x$ac_have_builtin_atomic_primary = xyes])
5173 # does this compiler have built-in functions for atomic memory access for the
5174 # secondary target ?
5176 if test x$VGCONF_PLATFORM_SEC_CAPS != x; then
5178 AC_MSG_CHECKING([if gcc supports __sync_add_and_fetch for the secondary target])
5180 safe_CFLAGS=$CFLAGS
5181 CFLAGS="$mflag_secondary"
5183 AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[
5184   int variable = 1;
5185   return (__sync_add_and_fetch(&variable, 1) ? 1 : 0)
5186 ]])], [
5187   ac_have_builtin_atomic_secondary=yes
5188   AC_MSG_RESULT([yes])
5189 ], [
5190   ac_have_builtin_atomic_secondary=no
5191   AC_MSG_RESULT([no])
5194 CFLAGS=$safe_CFLAGS
5198 AM_CONDITIONAL([HAVE_BUILTIN_ATOMIC_SECONDARY],
5199                [test x$ac_have_builtin_atomic_secondary = xyes])
5201 # does this compiler have built-in functions for atomic memory access on
5202 # 64-bit integers for all targets ?
5204 AC_MSG_CHECKING([if gcc supports __sync_add_and_fetch on uint64_t for all targets])
5206 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
5207   #include <stdint.h>
5208 ]], [[
5209   uint64_t variable = 1;
5210   return __sync_add_and_fetch(&variable, 1)
5211 ]])], [
5212   ac_have_builtin_atomic64_primary=yes
5213 ], [
5214   ac_have_builtin_atomic64_primary=no
5217 if test x$VGCONF_PLATFORM_SEC_CAPS != x; then
5219 safe_CFLAGS=$CFLAGS
5220 CFLAGS="$mflag_secondary"
5222 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
5223   #include <stdint.h>
5224 ]], [[
5225   uint64_t variable = 1;
5226   return __sync_add_and_fetch(&variable, 1)
5227 ]])], [
5228   ac_have_builtin_atomic64_secondary=yes
5229 ], [
5230   ac_have_builtin_atomic64_secondary=no
5233 CFLAGS=$safe_CFLAGS
5237 if test x$ac_have_builtin_atomic64_primary = xyes && \
5238    test x$VGCONF_PLATFORM_SEC_CAPS = x \
5239      -o x$ac_have_builtin_atomic64_secondary = xyes; then
5240   AC_MSG_RESULT([yes])
5241   ac_have_builtin_atomic64=yes
5242 else
5243   AC_MSG_RESULT([no])
5244   ac_have_builtin_atomic64=no
5247 AM_CONDITIONAL([HAVE_BUILTIN_ATOMIC64],
5248                [test x$ac_have_builtin_atomic64 = xyes])
5250                
5251 AC_MSG_CHECKING([if platform has openat2 syscall])
5253 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
5254   #include <sys/syscall.h>
5255 ]], [[
5256   return __NR_openat2
5257 ]])], [
5258   ac_have_openat2=yes
5259 ], [
5260   ac_have_openat2=no
5263 AM_CONDITIONAL([HAVE_OPENAT2],
5264                [test x$ac_have_openat2 = xyes])
5266 # does g++ have built-in functions for atomic memory access ?
5267 AC_MSG_CHECKING([if g++ supports __sync_add_and_fetch])
5269 safe_CXXFLAGS=$CXXFLAGS
5270 CXXFLAGS="$mflag_primary"
5272 AC_LANG_PUSH(C++)
5273 AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[
5274   int variable = 1;
5275   return (__sync_bool_compare_and_swap(&variable, 1, 2)
5276           && __sync_add_and_fetch(&variable, 1) ? 1 : 0)
5277 ]])], [
5278   ac_have_builtin_atomic_cxx=yes
5279   AC_MSG_RESULT([yes])
5280   AC_DEFINE(HAVE_BUILTIN_ATOMIC_CXX, 1, [Define to 1 if g++ supports __sync_bool_compare_and_swap() and __sync_add_and_fetch()])
5281 ], [
5282   ac_have_builtin_atomic_cxx=no
5283   AC_MSG_RESULT([no])
5285 AC_LANG_POP(C++)
5287 CXXFLAGS=$safe_CXXFLAGS
5289 AM_CONDITIONAL([HAVE_BUILTIN_ATOMIC_CXX], [test x$ac_have_builtin_atomic_cxx = xyes])
5292 if test x$ac_have_usable_linux_futex_h = xyes \
5293         -a x$ac_have_builtin_atomic_primary = xyes; then
5294   ac_enable_linux_ticket_lock_primary=yes
5296 AM_CONDITIONAL([ENABLE_LINUX_TICKET_LOCK_PRIMARY],
5297                [test x$ac_enable_linux_ticket_lock_primary = xyes])
5299 if test x$VGCONF_PLATFORM_SEC_CAPS != x \
5300         -a x$ac_have_usable_linux_futex_h = xyes \
5301         -a x$ac_have_builtin_atomic_secondary = xyes; then
5302   ac_enable_linux_ticket_lock_secondary=yes
5304 AM_CONDITIONAL([ENABLE_LINUX_TICKET_LOCK_SECONDARY],
5305                [test x$ac_enable_linux_ticket_lock_secondary = xyes])
5308 # does libstdc++ support annotating shared pointers ?
5309 AC_MSG_CHECKING([if libstdc++ supports annotating shared pointers])
5311 safe_CXXFLAGS=$CXXFLAGS
5312 CXXFLAGS="-std=c++0x"
5314 AC_LANG_PUSH(C++)
5315 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
5316   #include <memory>
5317 ]], [[
5318   std::shared_ptr<int> p
5319 ]])], [
5320   ac_have_shared_ptr=yes
5321 ], [
5322   ac_have_shared_ptr=no
5324 if test x$ac_have_shared_ptr = xyes; then
5325   # If compilation of the program below fails because of a syntax error
5326   # triggered by substituting one of the annotation macros then that
5327   # means that libstdc++ supports these macros.
5328   AC_LINK_IFELSE([AC_LANG_PROGRAM([[
5329     #define _GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE(a) (a)----
5330     #define _GLIBCXX_SYNCHRONIZATION_HAPPENS_AFTER(a) (a)----
5331     #include <memory>
5332   ]], [[
5333     std::shared_ptr<int> p
5334   ]])], [
5335     ac_have_shared_pointer_annotation=no
5336     AC_MSG_RESULT([no])
5337   ], [
5338     ac_have_shared_pointer_annotation=yes
5339     AC_MSG_RESULT([yes])
5340     AC_DEFINE(HAVE_SHARED_POINTER_ANNOTATION, 1,
5341               [Define to 1 if libstd++ supports annotating shared pointers])
5342   ])
5343 else
5344   ac_have_shared_pointer_annotation=no
5345   AC_MSG_RESULT([no])
5347 AC_LANG_POP(C++)
5349 CXXFLAGS=$safe_CXXFLAGS
5351 AM_CONDITIONAL([HAVE_SHARED_POINTER_ANNOTATION],
5352                [test x$ac_have_shared_pointer_annotation = xyes])
5355 #----------------------------------------------------------------------------
5356 # Ok.  We're done checking.
5357 #----------------------------------------------------------------------------
5359 # Nb: VEX/Makefile is generated from Makefile.vex.in.
5360 AC_CONFIG_FILES([
5361    Makefile 
5362    VEX/Makefile:Makefile.vex.in
5363    valgrind.spec
5364    valgrind.pc
5365    glibc-2.X.supp
5366    glibc-2.X-helgrind.supp
5367    glibc-2.X-drd.supp
5368    include/valgrind.h
5369    docs/Makefile 
5370    docs/xml/vg-entities.xml
5371    tests/Makefile 
5372    tests/vg_regtest 
5373    perf/Makefile 
5374    perf/vg_perf
5375    gdbserver_tests/Makefile
5376    gdbserver_tests/solaris/Makefile
5377    include/Makefile 
5378    auxprogs/Makefile
5379    mpi/Makefile
5380    coregrind/Makefile 
5381    memcheck/Makefile
5382    memcheck/tests/Makefile
5383    memcheck/tests/common/Makefile
5384    memcheck/tests/amd64/Makefile
5385    memcheck/tests/x86/Makefile
5386    memcheck/tests/linux/Makefile
5387    memcheck/tests/linux/debuginfod-check.vgtest
5388    memcheck/tests/darwin/Makefile
5389    memcheck/tests/solaris/Makefile
5390    memcheck/tests/freebsd/Makefile
5391    memcheck/tests/amd64-linux/Makefile
5392    memcheck/tests/arm64-linux/Makefile
5393    memcheck/tests/x86-linux/Makefile
5394    memcheck/tests/amd64-solaris/Makefile
5395    memcheck/tests/x86-solaris/Makefile
5396    memcheck/tests/amd64-freebsd/Makefile
5397    memcheck/tests/x86-freebsd/Makefile
5398    memcheck/tests/ppc32/Makefile
5399    memcheck/tests/ppc64/Makefile
5400    memcheck/tests/s390x/Makefile
5401    memcheck/tests/mips32/Makefile
5402    memcheck/tests/mips64/Makefile
5403    memcheck/tests/vbit-test/Makefile
5404    cachegrind/Makefile
5405    cachegrind/tests/Makefile
5406    cachegrind/tests/x86/Makefile
5407    cachegrind/cg_annotate
5408    cachegrind/cg_diff
5409    callgrind/Makefile
5410    callgrind/callgrind_annotate
5411    callgrind/callgrind_control
5412    callgrind/tests/Makefile
5413    helgrind/Makefile
5414    helgrind/tests/Makefile
5415    drd/Makefile
5416    drd/scripts/download-and-build-splash2
5417    drd/tests/Makefile
5418    massif/Makefile
5419    massif/tests/Makefile
5420    massif/ms_print
5421    dhat/Makefile
5422    dhat/tests/Makefile
5423    lackey/Makefile
5424    lackey/tests/Makefile
5425    none/Makefile
5426    none/tests/Makefile
5427    none/tests/scripts/Makefile
5428    none/tests/amd64/Makefile
5429    none/tests/ppc32/Makefile
5430    none/tests/ppc64/Makefile
5431    none/tests/x86/Makefile
5432    none/tests/arm/Makefile
5433    none/tests/arm64/Makefile
5434    none/tests/s390x/Makefile
5435    none/tests/mips32/Makefile
5436    none/tests/mips64/Makefile
5437    none/tests/nanomips/Makefile
5438    none/tests/linux/Makefile
5439    none/tests/darwin/Makefile
5440    none/tests/solaris/Makefile
5441    none/tests/freebsd/Makefile
5442    none/tests/amd64-linux/Makefile
5443    none/tests/x86-linux/Makefile
5444    none/tests/amd64-darwin/Makefile
5445    none/tests/x86-darwin/Makefile
5446    none/tests/amd64-solaris/Makefile
5447    none/tests/x86-solaris/Makefile
5448    none/tests/x86-freebsd/Makefile
5449    exp-bbv/Makefile
5450    exp-bbv/tests/Makefile
5451    exp-bbv/tests/x86/Makefile
5452    exp-bbv/tests/x86-linux/Makefile
5453    exp-bbv/tests/amd64-linux/Makefile
5454    exp-bbv/tests/ppc32-linux/Makefile
5455    exp-bbv/tests/arm-linux/Makefile
5456    shared/Makefile
5457    solaris/Makefile
5459 AC_CONFIG_FILES([coregrind/link_tool_exe_linux],
5460                 [chmod +x coregrind/link_tool_exe_linux])
5461 AC_CONFIG_FILES([coregrind/link_tool_exe_freebsd],
5462                 [chmod +x coregrind/link_tool_exe_freebsd])
5463 AC_CONFIG_FILES([coregrind/link_tool_exe_darwin],
5464                 [chmod +x coregrind/link_tool_exe_darwin])
5465 AC_CONFIG_FILES([coregrind/link_tool_exe_solaris],
5466                 [chmod +x coregrind/link_tool_exe_solaris])
5467 AC_CONFIG_FILES([tests/filter_stderr_basic],
5468                 [chmod +x tests/filter_stderr_basic])
5469 AC_CONFIG_FILES([tests/filter_discards],
5470                 [chmod +x tests/filter_discards])
5471 AC_CONFIG_FILES([memcheck/tests/filter_stderr],
5472                 [chmod +x memcheck/tests/filter_stderr])
5473 AC_CONFIG_FILES([memcheck/tests/filter_dw4],
5474                 [chmod +x memcheck/tests/filter_dw4])
5475 AC_CONFIG_FILES([memcheck/tests/filter_overlaperror],
5476                 [chmod +x memcheck/tests/filter_overlaperror])
5477 AC_CONFIG_FILES([memcheck/tests/x86/filter_pushfpopf],
5478                 [chmod +x memcheck/tests/x86/filter_pushfpopf])
5479 AC_CONFIG_FILES([gdbserver_tests/filter_gdb],
5480                 [chmod +x gdbserver_tests/filter_gdb])
5481 AC_CONFIG_FILES([gdbserver_tests/filter_memcheck_monitor],
5482                 [chmod +x gdbserver_tests/filter_memcheck_monitor])
5483 AC_CONFIG_FILES([gdbserver_tests/filter_stderr],
5484                 [chmod +x gdbserver_tests/filter_stderr])
5485 AC_CONFIG_FILES([gdbserver_tests/filter_vgdb],
5486                 [chmod +x gdbserver_tests/filter_vgdb])
5487 AC_CONFIG_FILES([drd/tests/filter_stderr],
5488                 [chmod +x drd/tests/filter_stderr])
5489 AC_CONFIG_FILES([drd/tests/filter_error_count],
5490                 [chmod +x drd/tests/filter_error_count])
5491 AC_CONFIG_FILES([drd/tests/filter_error_summary],
5492                 [chmod +x drd/tests/filter_error_summary])
5493 AC_CONFIG_FILES([drd/tests/filter_stderr_and_thread_no_and_offset],
5494                 [chmod +x drd/tests/filter_stderr_and_thread_no_and_offset])
5495 AC_CONFIG_FILES([drd/tests/filter_thread_no],
5496                 [chmod +x drd/tests/filter_thread_no])
5497 AC_CONFIG_FILES([drd/tests/filter_xml_and_thread_no],
5498                 [chmod +x drd/tests/filter_xml_and_thread_no])
5499 AC_CONFIG_FILES([helgrind/tests/filter_stderr],
5500                 [chmod +x helgrind/tests/filter_stderr])
5501 AC_OUTPUT
5503 cat<<EOF
5505                     Version: ${VERSION}
5506          Maximum build arch: ${ARCH_MAX}
5507          Primary build arch: ${VGCONF_ARCH_PRI}
5508        Secondary build arch: ${VGCONF_ARCH_SEC}
5509                    Build OS: ${VGCONF_OS}
5510      Link Time Optimisation: ${vg_cv_lto}
5511        Primary build target: ${VGCONF_PLATFORM_PRI_CAPS}
5512      Secondary build target: ${VGCONF_PLATFORM_SEC_CAPS}
5513            Platform variant: ${VGCONF_PLATVARIANT}
5514       Primary -DVGPV string: -DVGPV_${VGCONF_ARCH_PRI}_${VGCONF_OS}_${VGCONF_PLATVARIANT}=1
5515          Default supp files: ${DEFAULT_SUPP}