Home | History | Annotate | Line # | Download | only in m4
      1  1.1  riastrad # SYNOPSIS
      2  1.1  riastrad #
      3  1.1  riastrad #   AX_CHECK_CATCHABLE_SEGV
      4  1.1  riastrad #
      5  1.1  riastrad # DESCRIPTION
      6  1.1  riastrad #
      7  1.1  riastrad #  Check whether segmentation violations can be caught using signal handlers.
      8  1.1  riastrad 
      9  1.1  riastrad #serial 1
     10  1.1  riastrad 
     11  1.1  riastrad AC_DEFUN([AX_CHECK_CATCHABLE_SEGV], [dnl
     12  1.1  riastrad     AC_PREREQ(2.64)
     13  1.1  riastrad     AS_VAR_PUSHDEF([CACHEVAR], [ax_cv_check_[]_AC_LANG_ABBREV[]CATCHABLE_SEGV])dnl
     14  1.1  riastrad     AC_CACHE_CHECK([whether segmentation violations can be caught when using the _AC_LANG compiler], CACHEVAR, [
     15  1.1  riastrad         AC_RUN_IFELSE([
     16  1.1  riastrad             AC_LANG_PROGRAM([[
     17  1.1  riastrad #include <signal.h>
     18  1.1  riastrad #include <stdlib.h>
     19  1.1  riastrad static void sig(int _) { exit(0); }
     20  1.1  riastrad             ]], [[
     21  1.1  riastrad volatile unsigned char * volatile x = (volatile unsigned char *) malloc(8);
     22  1.1  riastrad size_t i;
     23  1.1  riastrad 
     24  1.1  riastrad signal(SIGSEGV, sig);
     25  1.1  riastrad signal(SIGBUS, sig);
     26  1.1  riastrad #if !defined(__SANITIZE_ADDRESS__) && !defined(__EMSCRIPTEN__)
     27  1.1  riastrad for (i = 0; i < 10000000; i += 1024) { x[-i] = x[i] = (unsigned char) i; }
     28  1.1  riastrad #endif
     29  1.1  riastrad free((void *) x);
     30  1.1  riastrad exit(1)
     31  1.1  riastrad             ]])],
     32  1.1  riastrad             [AS_VAR_SET(CACHEVAR, [yes])],
     33  1.1  riastrad             [AS_VAR_SET(CACHEVAR, [no])],
     34  1.1  riastrad             [AS_VAR_SET(CACHEVAR, [unknown])]
     35  1.1  riastrad         )
     36  1.1  riastrad     ])
     37  1.1  riastrad     AS_VAR_IF(CACHEVAR, yes,
     38  1.1  riastrad         [AC_DEFINE([HAVE_CATCHABLE_SEGV], [1], [Define if segmentation violations can be caught using signal handlers])],
     39  1.1  riastrad         [AC_MSG_WARN([On this platform, segmentation violations cannot be caught using signal handlers. This is expected if you enabled a tool such as Address Sanitizer (-fsanitize=address), but be aware that using Address Sanitizer may also significantly reduce performance.])]
     40  1.1  riastrad     )
     41  1.1  riastrad     AS_VAR_POPDEF([CACHEVAR])dnl
     42  1.1  riastrad ])
     43