ax_check_catchable_segv.m4 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # SYNOPSIS
  2. #
  3. # AX_CHECK_CATCHABLE_SEGV
  4. #
  5. # DESCRIPTION
  6. #
  7. # Check whether segmentation violations can be caught using signal handlers.
  8. #serial 1
  9. AC_DEFUN([AX_CHECK_CATCHABLE_SEGV], [dnl
  10. AC_PREREQ(2.64)
  11. AS_VAR_PUSHDEF([CACHEVAR], [ax_cv_check_[]_AC_LANG_ABBREV[]CATCHABLE_SEGV])dnl
  12. AC_CACHE_CHECK([whether segmentation violations can be caught when using the _AC_LANG compiler], CACHEVAR, [
  13. AC_RUN_IFELSE([
  14. AC_LANG_PROGRAM([[
  15. #include <signal.h>
  16. #include <stdlib.h>
  17. static void sig(int _) { exit(0); }
  18. ]], [[
  19. volatile unsigned char * volatile x = (volatile unsigned char *) malloc(8);
  20. size_t i;
  21. signal(SIGSEGV, sig);
  22. signal(SIGBUS, sig);
  23. #if !defined(__SANITIZE_ADDRESS__) && !defined(__EMSCRIPTEN__)
  24. for (i = 0; i < 10000000; i += 1024) { x[-i] = x[i] = (unsigned char) i; }
  25. #endif
  26. free((void *) x);
  27. exit(1)
  28. ]])],
  29. [AS_VAR_SET(CACHEVAR, [yes])],
  30. [AS_VAR_SET(CACHEVAR, [no])],
  31. [AS_VAR_SET(CACHEVAR, [unknown])]
  32. )
  33. ])
  34. AS_VAR_IF(CACHEVAR, yes,
  35. [AC_DEFINE([HAVE_CATCHABLE_SEGV], [1], [Define if segmentation violations can be caught using signal handlers])],
  36. [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.])]
  37. )
  38. AS_VAR_POPDEF([CACHEVAR])dnl
  39. ])