Avoid test failures with ASAN.
[libsigsegv.git] / configure.ac
blobd518f7373c88dbcc4e34daab96801aa0a6e8b3d1
1 dnl Autoconf configuration for libsigsegv.
2 dnl Process this file with autoconf to produce a configure script.
3 dnl
4 dnl Copyright (C) 2002-2023  Bruno Haible <bruno@clisp.org>
5 dnl
6 dnl This program is free software: you can redistribute it and/or modify
7 dnl it under the terms of the GNU General Public License as published by
8 dnl the Free Software Foundation; either version 2 of the License, or
9 dnl (at your option) any later version.
10 dnl
11 dnl This program is distributed in the hope that it will be useful,
12 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
13 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 dnl GNU General Public License for more details.
15 dnl
16 dnl You should have received a copy of the GNU General Public License
17 dnl along with this program.  If not, see <https://www.gnu.org/licenses/>.
19 AC_PREREQ([2.64])
20 AC_INIT([libsigsegv], [2.14])
21 AC_CONFIG_SRCDIR([src/sigsegv.h.in])
22 AC_CONFIG_AUX_DIR([build-aux])
23 AC_CONFIG_MACRO_DIRS([m4])
24 AC_CONFIG_HEADERS([config.h])
26 RSE_BOLD
28 { echo; echo "${term_bold}Build Tools:${term_norm}"; } >& AS_MESSAGE_FD
30 AM_INIT_AUTOMAKE
32 dnl Override automake's tar command used for creating distributions.
33 am__tar='${AMTAR} chf - --owner=root --group=root "$$tardir"'
35 AC_PROG_CC
36 AC_PROG_CPP
38 AC_CANONICAL_HOST
41 dnl ========================== Determine PLATFORM ==========================
42 dnl Requires AC_CANONICAL_HOST.
43 dnl PLATFORM is a modified config.guess triple that is supposed to contain
44 dnl the bits of information which influence the configuration or functioning
45 dnl of catching faults.
47 AC_MSG_CHECKING([host platform])
48 sv_cv_host="$host"
49 changequote(,)dnl Autoconf 2.52 brokenness
50 case "$host_os" in
51   linux | linux-*)
52     kernelversion=`uname -r | sed -e 's/^\([0-9.]*\).*/\1/'`
53     sv_cv_host=`echo $sv_cv_host | sed -e "s/linux/linux$kernelversion/"`
54     ;;
55 esac
56 changequote([,])dnl Autoconf 2.52 brokenness
57 cat > conftest.c << EOF
58 #include <features.h>
59 #ifdef __GNU_LIBRARY__
60 Version __GLIBC__ . __GLIBC_MINOR__
61 #endif
62 EOF
63 dnl We cannot simply use 'grep Version' on the output; see
64 dnl https://lists.gnu.org/archive/html/bug-autoconf/2017-02/msg00001.html
65 sed_extract_lines_after_version='/Version/{
71 glibcversion=`$CPP $CPPFLAGS conftest.c 2>/dev/null | sed -e '/^#/d' | sed -n -e "$sed_extract_lines_after_version" | tr -d '\n' | sed -e 's/Version//' -e 's/ //g'`
72 if test -n "$glibcversion"; then
73   sv_cv_host="$sv_cv_host-glibc$glibcversion"
75 AC_MSG_RESULT([$sv_cv_host])
76 PLATFORM="$sv_cv_host"
77 AC_SUBST([PLATFORM])
79 gl_MUSL_LIBC
81 dnl ========================== Done with PLATFORM ==========================
84 AC_PROG_INSTALL
86 LT_INIT([disable-shared])
88 # For testing cross-compilation behaviour.
89 #cross_compiling=yes
91 { echo; echo "${term_bold}Optional Platform Environment:${term_norm}"; } >& AS_MESSAGE_FD
93 dnl Headers to be included with <signal.h>. On MacOS X (Darwin) one also
94 dnl needs <sys/signal.h>.
95 AC_CHECK_HEADERS([sys/signal.h])
98 dnl ========================== Determine CFG_SIGNALS ==========================
99 dnl Requires AC_CANONICAL_HOST.
101 dnl List of signals that are sent when an invalid virtual memory address
102 dnl is accessed, or when the stack overflows.
103 case "$host_os" in
104   sunos4* | freebsd* | dragonfly* | openbsd* | netbsd* | midnightbsd* | \
105   kfreebsd* | knetbsd*)
106     CFG_SIGNALS=signals-bsd.h ;;
107   hpux*)
108     CFG_SIGNALS=signals-hpux.h ;;
109   macos* | darwin*)
110     CFG_SIGNALS=signals-macos.h ;;
111   gnu*)
112     CFG_SIGNALS=signals-hurd.h ;;
113   *)
114     CFG_SIGNALS=signals.h ;;
115 esac
116 AC_DEFINE_UNQUOTED([CFG_SIGNALS], ["$CFG_SIGNALS"],
117   [The name of the include file describing the fault signals.])
119 dnl ========================== Done with CFG_SIGNALS ==========================
122 # How to determine the memory page size.
123 SV_GETPAGESIZE
125 # How to allocate fresh memory using mmap.
126 # (We need mmap, because mprotect() doesn't work on malloc()ed memory on
127 # some systems.)
128 SV_MMAP_ANON
131 dnl ================== Determine CFG_HANDLER partially,     ==================
132 dnl ================== CFG_FAULT, CFG_MACHFAULT,            ==================
133 dnl ================== FAULT_CONTEXT, FAULT_CONTEXT_INCLUDE ==================
134 dnl Requires AC_CANONICAL_HOST, SV_MMAP_ANON.
136 # How to write a SIGSEGV handler with access to the fault address.
138 # Cygwin >= 2.1 supports sigaltstack().  For older versions of Cygwin,
139 # a Windows API based handler is needed, with complex code to make EFAULT work.
140 # Use the simpler approach by default.
141 AC_ARG_ENABLE([support-old-cygwin],
142   [AS_HELP_STRING([--enable-support-old-cygwin],
143                   [enable support of Cygwin older than 2.1 (2015)])])
145 # On MacOS X 10.2 to 10.12, we don't need these tests, because we'll end up
146 # using handler-macos.c anyway. If we were to perform the tests, 5 Crash Report
147 # dialog windows would pop up.
148 # Starting with MacOS X 10.13 (at least), handler-unix.c works fine too.
149 case "$host_os" in
150   macos* | darwin[[6-9]]* | darwin1[[0-6]]*) ;;
151   *)
153 dnl FIXME: Put in some more known values into the third argument.
154 SV_TRY_FAULT([POSIX], sv_cv_fault_posix,
155   [*-*-solaris2.[7-9] | i?86-*-linux2.[4-9]* | sparc*-*-linux2.6.* | i?86-*-freebsd[4-9]* | i?86-*-freebsd[1-9][0-9]* | i?86-*-kfreebsd[4-9]* | i?86-*-kfreebsd[1-9][0-9]* | x86_64-*-kfreebsd[4-9]* | x86_64-*-kfreebsd[1-9][0-9]* | i?86-*-mirbsd1[0-9] | alpha*-dec-osf[4-9]* | *-*-hpux11* | mips-sgi-irix6*],
156   [],
157   [int sig, siginfo_t *sip, void *ucp],
158   [sip->si_addr],
159   [action.sa_sigaction = &sigsegv_handler;
160    action.sa_flags = SA_SIGINFO;])
162 SV_TRY_FAULT([Linux/i386], sv_cv_fault_linux_i386, [i?86-*-linux2.[2-9]*],
163   [#include <asm/sigcontext.h>],
164   [int sig, struct sigcontext sc],
165   [sc.cr2])
167 SV_TRY_FAULT([old Linux/i386], sv_cv_fault_linux_i386_old,
168   [i?86-*-linux2.[2-9]*],
169   [],
170   [int sig, unsigned int more],
171   [((unsigned long *) &more) [21]])
173 dnl FIXME: Put in some more known values into the third argument.
174 SV_TRY_FAULT([Linux/m68k], sv_cv_fault_linux_m68k, [],
175   [#include <asm/sigcontext.h>
176 #include "$srcdir/src/fault-linux-m68k-old.c"],
177   [int sig, int code, struct sigcontext *scp],
178   [get_fault_addr (scp)])
180 dnl FIXME: Put in some more known values into the third argument.
181 SV_TRY_FAULT([Linux/PowerPC], sv_cv_fault_linux_powerpc, [],
182   [#include <asm/sigcontext.h>],
183   [int sig, struct sigcontext *scp],
184   [scp->regs->dar])
186 dnl FIXME: Put in some more known values into the third argument.
187 SV_TRY_FAULT([Linux/HPPA], sv_cv_fault_linux_hppa, [],
188   [],
189   [int sig, siginfo_t *sip, void *ucp],
190   [sip->si_ptr],
191   [action.sa_sigaction = &sigsegv_handler;
192    action.sa_flags = SA_SIGINFO;])
194 dnl FIXME: Put in some more known values into the third argument.
195 SV_TRY_FAULT([BSD], sv_cv_fault_bsd, [i?86-*-freebsd[4-9]* | i?86-*-freebsd[1-9][0-9]* | x86_64-*-kfreebsd[4-9]* | x86_64-*-kfreebsd[1-9][0-9]*],
196   [],
197   [int sig, int code, struct sigcontext *scp, void *addr],
198   [addr])
200 dnl FIXME: Put in some more known values into the third argument.
201 SV_TRY_FAULT([IRIX], sv_cv_fault_irix, [mips-sgi-irix6*],
202   [],
203   [int sig, int code, struct sigcontext *scp],
204   [(unsigned long) scp->sc_badvaddr])
206 dnl FIXME: Put in some more known values into the third argument.
207 SV_TRY_FAULT([HP-UX HPPA], sv_cv_fault_hpux_hppa, [hppa*-*-hpux11*],
208   [
209 #define USE_64BIT_REGS(mc) \
210   (((mc).ss_flags & SS_WIDEREGS) && ((mc).ss_flags & SS_NARROWISINVALID))
211 #define GET_CR21(mc) \
212   (USE_64BIT_REGS(mc) ? (mc).ss_wide.ss_64.ss_cr21 : (mc).ss_narrow.ss_cr21)
214   [int sig, int code, struct sigcontext *scp],
215   [GET_CR21 (scp->sc_sl.sl_ss)])
217 dnl FIXME: Put in some more known values into the third argument.
218 SV_TRY_FAULT([OSF/1 Alpha], sv_cv_fault_osf_alpha,
219   [alpha*-*-osf[4-9]* | alpha*-*-linux2.[4-9]*],
220   [],
221   [int sig, int code, struct sigcontext *scp],
222   [scp->sc_traparg_a0])
224 dnl FIXME: Put in some more known values into the third argument.
225 SV_TRY_FAULT([NetBSD Alpha], sv_cv_fault_netbsd_alpha,
226   [alpha*-*-osf[4-9]* | alpha-*-*bsd*],
227   [#include "$srcdir/src/fault-netbsd-alpha.c"],
228   [int sig, int code, struct sigcontext *scp],
229   [get_fault_addr (scp)])
231 dnl FIXME: Put in some more known values into the third argument.
232 SV_TRY_FAULT([AIX], sv_cv_fault_aix, [*-*-aix[34]*],
233   [],
234   [int sig, int code, struct sigcontext *scp],
235   [scp->sc_jmpbuf.jmp_context.o_vaddr])
237 SV_TRY_FAULT([MacOSX/Darwin7 PowerPC], sv_cv_fault_macosdarwin7_ppc,
238   [powerpc-*-darwin7*],
239   [#include "$srcdir/src/fault-macosdarwin7-powerpc.c"],
240   [int sig, siginfo_t *sip, ucontext_t *ucp],
241   [get_fault_addr (sip, ucp)],
242   [action.sa_sigaction = (void (*) (int, siginfo_t *, void *)) &sigsegv_handler;
243    action.sa_flags = SA_SIGINFO;])
245 if test "$sv_cv_fault_macosdarwin7_ppc" != yes; then
246 SV_TRY_FAULT([MacOSX/Darwin5 PowerPC], sv_cv_fault_macosdarwin5_ppc,
247   [powerpc-*-darwin5*],
248   [#include "$srcdir/src/fault-macosdarwin5-powerpc.c"],
249   [int sig, int code, struct sigcontext *scp],
250   [get_fault_addr (scp)])
253 dnl FIXME: Put in some more known values into the third argument.
254 SV_TRY_FAULT([Hurd], sv_cv_fault_hurd, [],
255   [],
256   [int sig, int code, struct sigcontext *scp],
257   [code])
259 # End of MacOS X special casing.
260     ;;
261 esac
263 dnl Now determine the fault handler include file.
264 dnl We prefer the platform specific include files to the generic fault-posix.h
265 dnl because the former often defines SIGSEGV_FAULT_STACKPOINTER.
266 dnl Also we put the BSD test second-to-last, because the test may produce
267 dnl false positives.
268 CFG_HANDLER=
269 CFG_FAULT=
270 CFG_MACHFAULT=
271 FAULT_CONTEXT=void
272 FAULT_CONTEXT_INCLUDE=
274 dnl First the cases where the OS provides the fault address.
276 if test -z "$CFG_FAULT" && test "$sv_cv_fault_aix" = yes; then
277   case "$host_cpu" in
278     powerpc* | rs6000) CFG_FAULT=fault-aix3-powerpc.h ;;
279     *) CFG_FAULT=fault-aix3.h ;;
280   esac
281   FAULT_CONTEXT='struct sigcontext'
283 if test -z "$CFG_FAULT" && test "$sv_cv_fault_irix" = yes; then
284   case "$host_cpu" in
285     mips*) CFG_FAULT=fault-irix-mips.h ;;
286     *) CFG_FAULT=fault-irix.h ;;
287   esac
288   FAULT_CONTEXT='struct sigcontext'
290 if test -z "$CFG_FAULT" && test "$sv_cv_fault_hpux_hppa" = yes; then
291   case "$host_cpu" in
292     hppa* | parisc*) CFG_FAULT=fault-hpux-hppa.h ;;
293     *) CFG_FAULT=fault-hpux.h ;;
294   esac
295   FAULT_CONTEXT='struct sigcontext'
297 if test -z "$CFG_FAULT" && test "$sv_cv_fault_osf_alpha" = yes; then
298   case "$host_cpu" in
299     alpha*) CFG_FAULT=fault-osf-alpha.h ;;
300     *) CFG_FAULT=fault-osf.h ;;
301   esac
302   FAULT_CONTEXT='struct sigcontext'
304 if test -z "$CFG_FAULT" && test "$sv_cv_fault_netbsd_alpha" = yes; then
305   case "$host_cpu" in
306     alpha*) CFG_FAULT=fault-netbsd-alpha.h ;;
307   esac
308   FAULT_CONTEXT='struct sigcontext'
310 if test -z "$CFG_FAULT" && test "$sv_cv_fault_hurd" = yes; then
311   case "$host_os" in
312     gnu*)
313       # Test $sv_cv_fault_hurd before testing $sv_cv_fault_posix, because
314       # support for SA_SIGINFO in Hurd is present only in upstream glibc ≥ 2.33
315       # or in Debian glibc ≥ 2.19.
316       case "$host_cpu" in
317         i?86 | x86_64)
318           CFG_FAULT=fault-hurd-i386-old.h
319           ;;
320         *)
321           CFG_FAULT=fault-hurd.h
322           ;;
323       esac
324       FAULT_CONTEXT='struct sigcontext'
325       ;;
326   esac
328 if test -z "$CFG_FAULT" && test "$sv_cv_fault_bsd" = yes; then
329   case "$host_os" in
330     freebsd* | dragonfly* | kfreebsd*)
331       case "$host_cpu" in
332         i?86 | x86_64)
333           CFG_FAULT=fault-freebsd-i386.h
334           FAULT_CONTEXT='struct sigcontext'
335           ;;
336         *)
337           CFG_FAULT=fault-bsd.h
338           FAULT_CONTEXT='void'
339           ;;
340       esac
341       ;;
342     *)
343       CFG_FAULT=fault-bsd.h
344       FAULT_CONTEXT='void'
345       ;;
346   esac
348 if test -z "$CFG_FAULT" && test "$sv_cv_fault_posix" = yes; then
349   case "$host_os" in
350     openbsd*)
351       case "$host_cpu" in
352         alpha*) CFG_FAULT=fault-openbsd-alpha.h ;;
353         arm* | strongarm* | xscale*) CFG_FAULT=fault-openbsd-arm.h ;;
354         hppa* | parisc*) CFG_FAULT=fault-openbsd-hppa.h ;;
355         i?86 | x86_64) CFG_FAULT=fault-openbsd-i386.h ;;
356         m68*) CFG_FAULT=fault-openbsd-m68k.h ;;
357         m88k*) CFG_FAULT=fault-openbsd-m88k.h ;;
358         mips*) CFG_FAULT=fault-openbsd-mips.h ;;
359         powerpc* | rs6000) CFG_FAULT=fault-openbsd-powerpc.h ;;
360         sh*) CFG_FAULT=fault-openbsd-sh.h ;;
361         sparc*) CFG_FAULT=fault-openbsd-sparc.h ;;
362         vax*) CFG_FAULT=fault-openbsd-vax.h ;;
363         *) CFG_FAULT=fault-openbsd.h ;;
364       esac
365       FAULT_CONTEXT='struct sigcontext'
366       ;;
367     mirbsd*)
368       case "$host_cpu" in
369         i?86 | x86_64)
370           CFG_FAULT=fault-openbsd-i386.h
371           FAULT_CONTEXT='struct sigcontext'
372           ;;
373       esac
374       ;;
375     linux*)
376       case "$host_cpu" in
377         ia64)
378           CFG_FAULT=fault-linux-ia64-old.h
379           FAULT_CONTEXT='struct sigcontext'
380           ;;
381       esac
382       ;;
383     darwin*)
384       case "$host_cpu" in
385         aarch64*) CFG_FAULT=fault-macos-arm64.h ;;
386         i?86 | x86_64) CFG_FAULT=fault-macos-i386.h ;;
387         powerpc* | rs6000) CFG_FAULT=fault-macos-powerpc.h ;;
388         *) CFG_FAULT=fault-macos.h ;;
389       esac
390       FAULT_CONTEXT='ucontext_t'
391       FAULT_CONTEXT_INCLUDE='#include <sys/ucontext.h>'
392       ;;
393     haiku*)
394       case "$host_cpu" in
395         i?86 | x86_64) CFG_FAULT=fault-haiku-i386.h ;;
396         *) CFG_FAULT=fault-haiku.h ;;
397       esac
398       FAULT_CONTEXT='ucontext_t'
399       FAULT_CONTEXT_INCLUDE='#include <signal.h>'
400       ;;
401   esac
402   if test -z "$CFG_FAULT"; then
403     dnl <ucontext.h> was required by POSIX:2001, and many systems have it. But
404     dnl POSIX:2008 does not require it any more, and MirBSD does not have it.
405     AC_CHECK_HEADERS([ucontext.h])
406     if test $ac_cv_header_ucontext_h = yes; then
407       case "$host_os" in
408         solaris*)
409           case "$host_cpu" in
410             i?86 | x86_64) CFG_FAULT=fault-solaris-i386.h ;;
411             sparc*)
412               case "$host_os" in
413                 solaris2.11)
414                   CFG_FAULT=fault-solaris11-sparc.h
415                   ;;
416                 *)
417                   CFG_FAULT=fault-solaris-sparc.h
418                   ;;
419               esac
420               ;;
421             *) CFG_FAULT=fault-solaris.h ;;
422           esac
423           ;;
424         aix*)
425           case "$host_cpu" in
426             powerpc* | rs6000) CFG_FAULT=fault-aix5-powerpc.h ;;
427             *) CFG_FAULT=fault-aix5.h ;;
428           esac
429           ;;
430         freebsd* | dragonfly* | kfreebsd*)
431           case "$host_cpu" in
432             arm* | strongarm* | xscale* | aarch64*)
433               CFG_FAULT=fault-freebsd-arm.h
434               ;;
435             *)
436               CFG_FAULT=fault-posix-ucontext.h
437               ;;
438           esac
439           ;;
440         netbsd*)
441           CFG_FAULT=fault-netbsd.h
442           ;;
443         linux*)
444           case "$host_cpu" in
445             alpha*)
446               CFG_FAULT=fault-linux-alpha.h
447               ;;
448             arm* | strongarm* | xscale* | aarch64*)
449               CFG_FAULT=fault-linux-arm.h
450               ;;
451             cris)
452               CFG_FAULT=fault-linux-cris.h
453               ;;
454             hppa* | parisc*)
455               CFG_FAULT=fault-linux-hppa.h
456               ;;
457             i?86 | x86_64)
458               CFG_FAULT=fault-linux-i386.h
459               ;;
460             ia64)
461               CFG_FAULT=fault-linux-ia64.h
462               ;;
463             loongarch64)
464               CFG_FAULT=fault-linux-loongarch.h
465               ;;
466             m68*)
467               CFG_FAULT=fault-linux-m68k.h
468               ;;
469             mips*)
470               CFG_FAULT=fault-linux-mips.h
471               ;;
472             nds32*)
473               CFG_FAULT=fault-linux-nds32.h
474               ;;
475             powerpc* | rs6000)
476               CFG_FAULT=fault-linux-powerpc.h
477               ;;
478             riscv64)
479               CFG_FAULT=fault-linux-riscv64.h
480               ;;
481             s390*)
482               CFG_FAULT=fault-linux-s390.h
483               ;;
484             sh*)
485               CFG_FAULT=fault-linux-sh.h
486               ;;
487             sparc*)
488               CFG_FAULT=fault-linux-sparc.h
489               ;;
490             *)
491               CFG_FAULT=fault-posix-ucontext.h
492               ;;
493           esac
494           ;;
495         cygwin*)
496           case "$host_cpu" in
497             i?86* | x86_64*)
498               CFG_FAULT=fault-cygwin-i386.h
499               ;;
500             *)
501               CFG_FAULT=fault-cygwin.h
502               ;;
503           esac
504           ;;
505         gnu*)
506           case "$host_cpu" in
507             i?86 | x86_64)
508               CFG_FAULT=fault-hurd-i386.h
509               ;;
510             *)
511               CFG_FAULT=fault-posix-ucontext.h
512               ;;
513           esac
514           ;;
515         *)
516           CFG_FAULT=fault-posix-ucontext.h
517           ;;
518       esac
519       FAULT_CONTEXT='ucontext_t'
520       FAULT_CONTEXT_INCLUDE='#include <ucontext.h>'
521     else
522       CFG_FAULT=fault-posix.h
523       FAULT_CONTEXT='void'
524     fi
525   fi
527 if test -z "$CFG_FAULT" && test "$sv_cv_fault_linux_i386" = yes; then
528   case "$host_cpu" in
529     i?86 | x86_64) CFG_FAULT=fault-linux-i386-old.h ;;
530   esac
531   FAULT_CONTEXT='struct sigcontext'
533 if test -z "$CFG_FAULT" && test "$sv_cv_fault_linux_i386_old" = yes; then
534   case "$host_cpu" in
535     i?86 | x86_64) CFG_FAULT=fault-linux-i386-oldold.h ;;
536   esac
537   FAULT_CONTEXT='struct sigcontext'
539 if test -z "$CFG_FAULT" && test "$sv_cv_fault_linux_powerpc" = yes; then
540   case "$host_cpu" in
541     powerpc* | rs6000) CFG_FAULT=fault-linux-powerpc-old.h ;;
542   esac
543   FAULT_CONTEXT='struct sigcontext'
545 if test -z "$CFG_FAULT" && test "$sv_cv_fault_linux_hppa" = yes; then
546   case "$host_cpu" in
547     hppa* | parisc*) CFG_FAULT=fault-linux-hppa-old.h ;;
548   esac
550 if test -z "$CFG_FAULT"; then
551   case "$host_os" in
552     macos* | darwin[[6-9]]* | darwin[[1-9]][[0-9]]*)
553       case "$host_cpu" in
554         powerpc* | rs6000 | i?86 | x86_64 | aarch64)
555           CFG_MACHFAULT=machfault-macos.h
556           FAULT_CONTEXT_INCLUDE='#include <signal.h>
557 #include <mach/thread_status.h>
558 #if defined __aarch64__
559 #define sigsegv_thread_state_t arm_thread_state64_t
560 #endif
561 #if defined __ppc64__
562 #define sigsegv_thread_state_t ppc_thread_state64_t
563 #elif defined __ppc__
564 #define sigsegv_thread_state_t ppc_thread_state_t
565 #endif
566 #if defined __x86_64__
567 #define sigsegv_thread_state_t x86_thread_state64_t
568 #elif defined __i386__
569 #if defined x86_THREAD_STATE32
570 #define sigsegv_thread_state_t x86_thread_state32_t
571 #else
572 #define sigsegv_thread_state_t i386_thread_state_t
573 #endif
574 #endif'
575           FAULT_CONTEXT='sigsegv_thread_state_t'
576           ;;
577       esac
578       if test -n "$CFG_MACHFAULT"; then
579         CFG_HANDLER=handler-macos.c
580         CFG_FAULT=fault-macos.h # nonexistent, just a dummy
581       fi
582       ;;
583   esac
586 dnl Next, the cases where there is a hairy CPU dependent way to get the
587 dnl fault address.
589 if test -z "$CFG_FAULT" && test "$sv_cv_fault_linux_m68k" = yes; then
590   case "$host_cpu" in
591     m68*)
592       CFG_FAULT=fault-linux-m68k-old.h
593       FAULT_CONTEXT='struct sigcontext'
594       ;;
595   esac
597 if test -z "$CFG_FAULT" && test "$sv_cv_fault_macosdarwin7_ppc" = yes; then
598   case "$host_cpu" in
599     powerpc* | rs6000)
600       CFG_FAULT=fault-macosdarwin7-powerpc.h
601       FAULT_CONTEXT='ucontext_t'
602       FAULT_CONTEXT_INCLUDE='#include <signal.h>
603 #include <ucontext.h>'
604       ;;
605   esac
607 if test -z "$CFG_FAULT" && test "$sv_cv_fault_macosdarwin5_ppc" = yes; then
608   case "$host_cpu" in
609     powerpc* | rs6000)
610       CFG_FAULT=fault-macosdarwin5-powerpc.h
611       FAULT_CONTEXT='struct sigcontext'
612       ;;
613   esac
615 case "$host_os" in
616   mingw* | windows*)
617     FAULT_CONTEXT='CONTEXT'
618     FAULT_CONTEXT_INCLUDE='#include <windows.h>'
619     CFG_FAULT=fault-win32.h # nonexistent, just a dummy
620     ;;
621   cygwin*)
622     if test "$enable_support_old_cygwin" = yes; then
623       FAULT_CONTEXT='struct _CONTEXT'
624       # CONTEXT is defined in <windows.h>, but cygwin programs should not
625       # normally inspect the contents of CONTEXT, and the outright inclusion
626       # of <windows.h> pollutes the namespace.
627       FAULT_CONTEXT_INCLUDE='struct _CONTEXT;'
628       # Cygwin 1.7 uses fault-posix.h. Cygwin 1.5.x needs a hacky workaround.
629       if test -z "$CFG_FAULT"; then
630         CFG_FAULT=fault-cygwin-old.h
631         AC_DEFINE([OLD_CYGWIN_WORKAROUND], [1],
632           [Define to 1 on Cygwin versions older than 1.7.])
633       fi
634     fi
635     ;;
636 esac
637 if test -n "$CFG_FAULT"; then
638   sv_cv_have_sigsegv_recovery=yes
639 else
640   sv_cv_have_sigsegv_recovery=no
641   dnl
642   dnl No way to get the fault address. But other information is available.
643   dnl
644   case "$host_os" in
645     linux*)
646       case "$host_cpu" in
647         alpha*)
648           CFG_FAULT=fault-linux-alpha-old.h
649           FAULT_CONTEXT='struct sigcontext'
650           ;;
651         arm* | strongarm* | xscale*)
652           CFG_FAULT=fault-linux-arm-old.h
653           FAULT_CONTEXT='struct sigcontext'
654           ;;
655         cris)
656           CFG_FAULT=fault-linux-cris-old.h
657           FAULT_CONTEXT='struct sigcontext'
658           ;;
659         mips*)
660           CFG_FAULT=fault-linux-mips-old.h
661           FAULT_CONTEXT='struct sigcontext'
662           ;;
663         s390*)
664           CFG_FAULT=fault-linux-s390-old.h
665           FAULT_CONTEXT='struct sigcontext'
666           ;;
667         sh*)
668           CFG_FAULT=fault-linux-sh-old.h
669           FAULT_CONTEXT='struct sigcontext'
670           ;;
671         sparc*)
672           CFG_FAULT=fault-linux-sparc-old.h
673           FAULT_CONTEXT='struct sigcontext'
674           ;;
675         x86_64)
676           CFG_FAULT=fault-linux-x86_64-old.h
677           FAULT_CONTEXT='struct sigcontext'
678           ;;
679       esac
680       ;;
681     beos*)
682       case "$host_cpu" in
683         i?86 | x86_64) CFG_FAULT=fault-beos-i386.h ;;
684         *) CFG_FAULT=fault-beos.h ;;
685       esac
686       FAULT_CONTEXT='struct vregs'
687       ;;
688     macos* | darwin*)
689       case "$host_cpu" in
690         i?86 | x86_64) CFG_FAULT=fault-macos-i386-old.h ;;
691       esac
692       FAULT_CONTEXT='struct sigcontext'
693       ;;
694   esac
696 AC_MSG_CHECKING([for the fault handler specifics])
697 if test -n "$CFG_FAULT"; then
698   sv_cv_fault_include=$CFG_FAULT
699 else
700   if test -n "$CFG_MACHFAULT"; then
701     sv_cv_fault_include=$CFG_MACHFAULT
702   else
703     sv_cv_fault_include=none
704   fi
706 AC_MSG_RESULT([$sv_cv_fault_include])
707 if test -z "$CFG_FAULT"; then
708   CFG_FAULT=fault-none.h
710 AC_DEFINE_UNQUOTED([CFG_FAULT], ["$CFG_FAULT"],
711   [The name of the include file describing the fault handler.])
712 if test -z "$CFG_MACHFAULT"; then
713   CFG_MACHFAULT=fault-none.h
715 AC_DEFINE_UNQUOTED([CFG_MACHFAULT], ["$CFG_MACHFAULT"],
716   [The name of the include file describing the Mach fault handler.])
717 AC_SUBST([FAULT_CONTEXT])
718 AC_SUBST([FAULT_CONTEXT_INCLUDE])
719 dnl AM_SUBST_NOTMAKE, because FAULT_CONTEXT_INCLUDE may have a multiline value.
720 AM_SUBST_NOTMAKE([FAULT_CONTEXT_INCLUDE])
722 dnl ================== Done with CFG_HANDLER partially,     ==================
723 dnl ================== CFG_FAULT, CFG_MACHFAULT,            ==================
724 dnl ================== FAULT_CONTEXT, FAULT_CONTEXT_INCLUDE ==================
727 dnl ===================== Determine HAVE_SIGSEGV_RECOVERY =====================
728 dnl Requires CFG_HANDLER / CFG_FAULT / etc.
730 AC_MSG_CHECKING([if the system supports catching SIGSEGV])
731 AC_MSG_RESULT([$sv_cv_have_sigsegv_recovery])
732 if test $sv_cv_have_sigsegv_recovery != no; then
733   HAVE_SIGSEGV_RECOVERY=1
734 else
735   HAVE_SIGSEGV_RECOVERY=0
737 AC_SUBST([HAVE_SIGSEGV_RECOVERY])
739 dnl ===================== Done with HAVE_SIGSEGV_RECOVERY =====================
742 dnl The stackoverflow_context_t type depends on the CFG_FAULT include file.
744 dnl Stack direction.
745 SV_STACK_DIRECTION
748 dnl ========================= Determine CFG_STACKVMA =========================
749 dnl Requires AC_CANONICAL_HOST.
751 AC_ARG_ENABLE([stackvma],
752   AS_HELP_STRING([--disable-stackvma],
753     [detect stack overflow without stack VMA heuristic]),
754   [use_stackvma=$enableval], [use_stackvma=yes])
755 if test "$use_stackvma" != no; then
756   dnl Determination of the stack's virtual memory area.
757   AC_CACHE_CHECK([for prmap_t in sys/procfs.h], [sv_cv_procfsvma], [
758     AC_LINK_IFELSE(
759       [AC_LANG_PROGRAM([[
760          /* Persuade Solaris OpenIndiana <signal.h> to declare 'struct sigaltstack'.  */
761          #define __EXTENSIONS__ 1
762          #include <sys/procfs.h>
763          ]], [[prmap_t x;]])],
764       [sv_cv_procfsvma=yes], [sv_cv_procfsvma=no])
765   ])
766   AC_CHECK_FUNCS([mquery mincore])
767   CFG_STACKVMA=
768   if test $sv_cv_procfsvma = yes; then
769     case "$host_os" in
770       aix*) CFG_STACKVMA=stackvma-aix.c ;;
771       *) CFG_STACKVMA=stackvma-procfs.c ;;
772     esac
773   fi
774   if test -z "$CFG_STACKVMA"; then
775     case "$host_os" in
776       linux*)                CFG_STACKVMA=stackvma-linux.c ;;
777       freebsd* | kfreebsd*-gnu* | dragonfly*)
778                              CFG_STACKVMA=stackvma-freebsd.c ;;
779       netbsd*)               CFG_STACKVMA=stackvma-netbsd.c ;;
780       cygwin*)               if test "$enable_support_old_cygwin" != yes; then
781                                CFG_STACKVMA=stackvma-cygwin.c
782                              fi
783                              ;;
784       beos* | haiku*)        CFG_STACKVMA=stackvma-beos.c ;;
785       macos* | darwin*)      CFG_STACKVMA=stackvma-mach.c ;;
786       dnl About gnu*): GNU/Hurd provides a /proc/self/maps file that is similar
787       dnl to one on Linux, and the vma_iterate (from gnulib) that reads this file
788       dnl works fine on GNU/Hurd under normal conditions. But in the context of
789       dnl libsigsegv, that is, during a SIGSEGV handler, it just hangs.
790     esac
791   fi
792   dnl We prefer the mquery based approach over the mincore based approach,
793   dnl because stackvma-mincore.c:is_unmapped() has a bad worst-case runtime.
794   if test -z "$CFG_STACKVMA" && test $ac_cv_func_mquery = yes; then
795     CFG_STACKVMA=stackvma-mquery.c
796   fi
797   if test -z "$CFG_STACKVMA" && test $ac_cv_func_mincore = yes; then
798     CFG_STACKVMA=stackvma-aix.c
799   fi
800   if test -n "$CFG_STACKVMA"; then
801     AC_DEFINE([HAVE_STACKVMA], [1],
802       [Define if CFG_STACKVMA is set to a nontrivial source file.])
803   else
804     CFG_STACKVMA=stackvma-none.c
805   fi
806 else
807   CFG_STACKVMA=stackvma-none.c
809 AC_DEFINE_UNQUOTED([CFG_STACKVMA], ["$CFG_STACKVMA"],
810   [The name of the file determining the stack virtual memory area.])
811 AC_SUBST([CFG_STACKVMA])
813 dnl ========================= Done with CFG_STACKVMA =========================
816 AC_CHECK_FUNCS([getrlimit setrlimit])
818 dnl Catching stack overflow requires an alternate signal stack.
819 dnl The old "install a guard page" trick would be unreliable, because
820 dnl we don't know where exactly to place the guard page.
821 SV_SIGALTSTACK
824 dnl =========================== Determine CFG_LEAVE ===========================
825 dnl Requires AC_CANONICAL_HOST.
827 # How to longjmp out of a signal handler, in such a way that the
828 # alternate signal stack remains functional.
830 # On MacOS X 10.2 or newer, we don't need these tests, because we'll end up
831 # using handler-macos.c anyway. If we were to perform the tests, 2 Crash Report
832 # dialog windows would pop up.
833 case "$host_os" in
834   macos* | darwin[[6-9]]* | darwin[[1-9]][[0-9]]*) ;;
835   *)
837 dnl FIXME: Put in some more known values into the third argument.
838 SV_TRY_LEAVE_HANDLER_LONGJMP([], sv_cv_leave_handler_longjmp,
839   [*-*-kfreebsd* | *-*-osf[4-9]* | *-*-hpux11* | *-*-linux2.[2-9]*],
840   [], [])
842 dnl FIXME: Put in some more known values into the third argument.
843 SV_TRY_LEAVE_HANDLER_LONGJMP([ and sigaltstack],
844   sv_cv_leave_handler_longjmp_sigaltstack,
845   [*-*-freebsd* | *-*-kfreebsd*],
846   [
847 #ifndef SS_ONSTACK
848 #define SS_ONSTACK SA_ONSTACK
849 #endif
850   ],
851   [stack_t ss;
852    if (sigaltstack (NULL, &ss) >= 0)
853      {
854        ss.ss_flags &= ~SS_ONSTACK;
855        sigaltstack (&ss, NULL);
856      }
857   ])
859 dnl FIXME: Put in some more known values into the third argument.
860 SV_TRY_LEAVE_HANDLER_LONGJMP([ and setcontext],
861   sv_cv_leave_handler_longjmp_setcontext,
862   [*-*-kfreebsd* | *-*-irix* | *-*-solaris*],
863   [#include <ucontext.h>
864 #ifndef SS_ONSTACK
865 #define SS_ONSTACK SA_ONSTACK
866 #endif
867   ],
868   [static int fl;
869    static ucontext_t uc;
870    fl = 0;
871    if (getcontext (&uc) >= 0)
872      if (fl == 0)
873        if (uc.uc_stack.ss_flags & SS_ONSTACK)
874          {
875            uc.uc_stack.ss_flags &= ~SS_ONSTACK;
876            fl = 1;
877            setcontext (&uc);
878          }
879   ])
881 # End of MacOS X special casing.
882     ;;
883 esac
885 # How to siglongjmp out of a signal handler, in such a way that the
886 # alternate signal stack remains functional.
888 # On MacOS X 10.2 or newer, we don't need these tests, because we'll end up
889 # using handler-macos.c anyway. If we were to perform the tests, 2 Crash Report
890 # dialog windows would pop up.
891 case "$host_os" in
892   macos* | darwin[[6-9]]* | darwin[[1-9]][[0-9]]*) ;;
893   *)
895 dnl FIXME: Put in some more known values into the third argument.
896 SV_TRY_LEAVE_HANDLER_SIGLONGJMP([], sv_cv_leave_handler_siglongjmp,
897   [*-*-kfreebsd* | *-*-osf[4-9]* | *-*-hpux11* | *-*-linux2.[2-9]* | *-*-irix* | *-*-solaris*],
898   [], [])
900 dnl FIXME: Put in some more known values into the third argument.
901 SV_TRY_LEAVE_HANDLER_SIGLONGJMP([ and sigaltstack],
902   sv_cv_leave_handler_siglongjmp_sigaltstack,
903   [*-*-freebsd* | *-*-kfreebsd*],
904   [
905 #ifndef SS_ONSTACK
906 #define SS_ONSTACK SA_ONSTACK
907 #endif
908   ],
909   [stack_t ss;
910    if (sigaltstack (NULL, &ss) >= 0)
911      {
912        ss.ss_flags &= ~SS_ONSTACK;
913        sigaltstack (&ss, NULL);
914      }
915   ])
917 dnl FIXME: Put in some more known values into the third argument.
918 SV_TRY_LEAVE_HANDLER_SIGLONGJMP([ and setcontext],
919   sv_cv_leave_handler_siglongjmp_setcontext,
920   [*-*-kfreebsd*],
921   [#include <ucontext.h>
922 #ifndef SS_ONSTACK
923 #define SS_ONSTACK SA_ONSTACK
924 #endif
925   ],
926   [static int fl;
927    static ucontext_t uc;
928    fl = 0;
929    if (getcontext(&uc) >= 0)
930      if (fl == 0)
931        if (uc.uc_stack.ss_flags & SS_ONSTACK)
932          {
933            uc.uc_stack.ss_flags &= ~SS_ONSTACK;
934            fl = 1;
935            setcontext(&uc);
936          }
937   ])
939 # End of MacOS X special casing.
940     ;;
941 esac
943 CFG_LEAVE=
944 if test "$sv_cv_leave_handler_longjmp" != no; then
945   CFG_LEAVE=leave-nop.c
946 else
947   if test "$sv_cv_leave_handler_longjmp_sigaltstack" != no; then
948     CFG_LEAVE=leave-sigaltstack.c
949   else
950     if test "$sv_cv_leave_handler_longjmp_setcontext" != no; then
951       CFG_LEAVE=leave-setcontext.c
952     fi
953   fi
955 case "$host_os" in
956   # On BeOS, the 6 tests fail because sigaltstack() doesn't exist.
957   # If one uses set_signal_stack() instead of sigaltstack(), the first
958   # test actually works. i.e. sv_cv_leave_handler_longjmp would be 'yes'.
959   beos*) CFG_LEAVE=leave-nop.c ;;
960 esac
961 if test -z "$CFG_LEAVE"; then
962   CFG_LEAVE=leave-none.c
964 AC_DEFINE_UNQUOTED([CFG_LEAVE], ["$CFG_LEAVE"],
965   [The name of the file implementing sigsegv_reset_onstack_flag.])
966 AC_SUBST([CFG_LEAVE])
968 dnl =========================== Done with CFG_LEAVE ===========================
971 dnl ================= Determine HAVE_STACK_OVERFLOW_RECOVERY =================
972 dnl Requires AC_CANONICAL_HOST, CFG_HANDLER / CFG_FAULT / etc., CFG_STACKVMA,
973 dnl CFG_LEAVE.
975 AC_CACHE_CHECK([if the system supports catching stack overflow],
976                [sv_cv_have_stack_overflow_recovery],
978   dnl On Mach, it requires a machfault-*.h (see src/handler-macos.c).
979   dnl On Unix, it requires either sigaltstack() or the BeOS set_signal_stack()
980   dnl function, and the ability to longjmp out of the signal handler, and on
981   dnl Unix it also requires a fault-*.h or a stackvma-*.c with certain
982   dnl properties (see src/handler-unix.c).
983   if test "$CFG_MACHFAULT" != fault-none.h; then
984     sv_cv_have_stack_overflow_recovery=yes
985   else
986     case "$host_os" in
987       mingw* | windows* | cygwin*) sv_cv_have_stack_overflow_recovery=yes ;;
988       *)
989         if test "$CFG_LEAVE" != 'leave-none.c'; then
990           if test "$sv_cv_sigaltstack" != no; then
991             sv_cv_have_stack_overflow_recovery=maybe
992           else
993             case "$host_os" in
994               beos*) sv_cv_have_stack_overflow_recovery=maybe ;;
995               *) sv_cv_have_stack_overflow_recovery=no ;;
996             esac
997           fi
998         else
999           sv_cv_have_stack_overflow_recovery=no
1000         fi
1001         ;;
1002     esac
1003   fi
1004   if test $sv_cv_have_stack_overflow_recovery = maybe; then
1005     if test -n "$CFG_FAULT"; then
1006       AC_EGREP_CPP([xyzzy], [
1007 #include "$srcdir/src/$CFG_FAULT"
1008 #ifdef SIGSEGV_FAULT_HANDLER_ARGLIST
1009 #ifdef SIGSEGV_FAULT_ADDRESS
1010 xyzzy
1011 #endif
1012 #endif
1013 ], [condA=true], [condA=false])
1014     else
1015       condA=false
1016     fi
1017     if test -n "$CFG_FAULT"; then
1018       AC_EGREP_CPP([xyzzy], [
1019 #include "$srcdir/src/$CFG_FAULT"
1020 #ifdef SIGSEGV_FAULT_HANDLER_ARGLIST
1021 #ifdef SIGSEGV_FAULT_STACKPOINTER
1022 xyzzy
1023 #endif
1024 #endif
1025 ], [condB=true], [condB=false])
1026     else
1027       condB=false
1028     fi
1029     if test "$CFG_STACKVMA" != "stackvma-none.c"; then
1030       condC=true
1031     else
1032       condC=false
1033     fi
1034     if { $condA && $condB; } || { $condA && $condC; } || { $condB && $condC; }; then
1035       sv_cv_have_stack_overflow_recovery=yes
1036     else
1037       sv_cv_have_stack_overflow_recovery=no
1038     fi
1039   fi
1041 if test $sv_cv_have_stack_overflow_recovery != no; then
1042   HAVE_STACK_OVERFLOW_RECOVERY=1
1043 else
1044   HAVE_STACK_OVERFLOW_RECOVERY=0
1046 AC_SUBST([HAVE_STACK_OVERFLOW_RECOVERY])
1048 dnl ================= Done with HAVE_STACK_OVERFLOW_RECOVERY =================
1051 dnl ======================= Determine CFG_HANDLER fully =======================
1052 dnl Requires AC_CANONICAL_HOST, CFG_HANDLER / CFG_FAULT / etc.,
1053 dnl HAVE_SIGSEGV_RECOVERY, HAVE_STACK_OVERFLOW_RECOVERY.
1055 case "$host_os" in
1056   mingw* | windows*) CFG_HANDLER=handler-win32.c ;;
1057   cygwin*)
1058     if test "$enable_support_old_cygwin" = yes; then
1059       CFG_HANDLER=handler-win32.c
1060     fi
1061     ;;
1062 esac
1063 if test -z "$CFG_HANDLER"; then
1064   if test $sv_cv_have_sigsegv_recovery = no \
1065      && test $sv_cv_have_stack_overflow_recovery = no; then
1066     CFG_HANDLER=handler-none.c
1067   else
1068     CFG_HANDLER=handler-unix.c
1069   fi
1071 AC_DEFINE_UNQUOTED([CFG_HANDLER], ["$CFG_HANDLER"],
1072   [The name of the file implementing the handler functionality.])
1073 AC_SUBST([CFG_HANDLER])
1075 dnl ======================= Done with CFG_HANDLER fully =======================
1077 dnl Test whether to enable Cygwin specific tests.
1078 AM_CONDITIONAL([CYGWIN],
1079   [case "$host_os" in
1080      cygwin*) true;;
1081      *)       false;;
1082    esac])
1084 dnl Test whether to make system calls fail with error EFAULT.
1085 dnl More precisely: whether passing invalid memory accesses to system calls
1086 dnl should make the system call fail with error EFAULT, rather than invoking
1087 dnl the signal handler.
1088 dnl It is necessary on Cygwin: otherwise the cygwin1 test fails.
1089 case "$host_os" in
1090   cygwin*) enable_EFAULT=yes ;;
1091   *)       enable_EFAULT=no ;;
1092 esac
1093 if test $enable_EFAULT = yes; then
1094   AC_DEFINE([ENABLE_EFAULT], [1],
1095     [Define to 1 if attempting to make system calls fail with error EFAULT])
1097 AM_CONDITIONAL([ENABLE_EFAULT], [test $enable_EFAULT = yes])
1099 if test $enable_EFAULT = yes; then
1100   SV_SYSCALLS_EFAULT
1104 dnl Test for features used in tests.
1105 AC_TYPE_UINTPTR_T
1108 { echo; echo "${term_bold}Build Parameters:${term_norm}"; } >& AS_MESSAGE_FD
1110 dnl Relocatability is a nop for this package.
1111 gl_RELOCATABLE_NOP
1113 { echo; echo "${term_bold}Output Substitution:${term_norm}"; } >& AS_MESSAGE_FD
1115 dnl AC_CONFIG_FILES([Makefile])
1116 AC_CONFIG_FILES([Makefile
1117                  src/Makefile src/sigsegv.h
1118                  tests/Makefile])
1120 { echo; echo "Now please type '${term_bold}make${term_norm}' to compile. Good luck."; echo; } >& AS_MESSAGE_FD
1122 AC_OUTPUT