diff options
author | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2021-12-11 12:34:56 +0300 |
---|---|---|
committer | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2021-12-11 13:53:11 +0300 |
commit | c8e2acd48856e1e41d0fb028c08c06774a2a8520 (patch) | |
tree | 7b99f8c23df96651630891a0f9a0833a31f8613a /configure.ac | |
parent | 6fc74f24da0e1c1a92f5f238b254882004eeace8 (diff) | |
download | libmicrohttpd-c8e2acd48856e1e41d0fb028c08c06774a2a8520.tar.gz libmicrohttpd-c8e2acd48856e1e41d0fb028c08c06774a2a8520.zip |
configure: added selective sanitizers enable
Diffstat (limited to 'configure.ac')
-rw-r--r-- | configure.ac | 474 |
1 files changed, 293 insertions, 181 deletions
diff --git a/configure.ac b/configure.ac index 9011654d..af0c95f5 100644 --- a/configure.ac +++ b/configure.ac | |||
@@ -2857,15 +2857,64 @@ AM_LSAN_OPTIONS="" | |||
2857 | AS_UNSET([ASAN_OPTIONS]) | 2857 | AS_UNSET([ASAN_OPTIONS]) |
2858 | AS_UNSET([UBSAN_OPTIONS]) | 2858 | AS_UNSET([UBSAN_OPTIONS]) |
2859 | AS_UNSET([LSAN_OPTIONS]) | 2859 | AS_UNSET([LSAN_OPTIONS]) |
2860 | |||
2861 | AC_MSG_CHECKING([whether to enable run-time sanitizers]) | ||
2860 | AC_ARG_ENABLE([sanitizers], | 2862 | AC_ARG_ENABLE([sanitizers], |
2861 | [AS_HELP_STRING([--enable-sanitizers], [enable run-time sanitizers])], | 2863 | [AS_HELP_STRING([[--enable-sanitizers[=address,undefined,leak,user-poison]]], |
2864 | [enable run-time sanitizers, specify the list of types of sanitizers to enable or ] | ||
2865 | [leave the list empty to enable all suppoted and availabe sanitizers])], | ||
2862 | [], [enable_sanitizers=no]) | 2866 | [], [enable_sanitizers=no]) |
2863 | AS_VAR_IF([enable_sanitizers], ["yes"], | 2867 | AS_IF([test "x${enable_sanitizers}" = "x"], [enable_sanitizers="auto"]) |
2868 | AS_VAR_IF([enable_sanitizers], ["yes"], [enable_sanitizers="auto"]) | ||
2869 | AS_IF([test "x${enable_sanitizers}" = "xno"], | ||
2870 | [ | ||
2871 | enable_sanitizers="no" | ||
2872 | enable_san_address="no" | ||
2873 | enable_san_undef="no" | ||
2874 | enable_san_leak="no" | ||
2875 | enable_san_upoison="no" | ||
2876 | ], | ||
2877 | [test "x${enable_sanitizers}" = "xauto"], | ||
2878 | [ | ||
2879 | enable_san_address="auto" | ||
2880 | enable_san_undef="auto" | ||
2881 | enable_san_leak="auto" | ||
2882 | enable_san_upoison="auto" | ||
2883 | ], | ||
2884 | [ | ||
2885 | AS_UNSET([san]) | ||
2886 | enable_san_address="no" | ||
2887 | enable_san_undef="no" | ||
2888 | enable_san_leak="no" | ||
2889 | enable_san_upoison="no" | ||
2890 | for san in `AS_ECHO([${enable_sanitizers}]) | tr ',' ' '` | ||
2891 | do | ||
2892 | AS_CASE([$san], | ||
2893 | [address], [enable_san_address="yes"], | ||
2894 | [undefined], [enable_san_undef="yes"], | ||
2895 | [leak], [enable_san_leak="yes"], | ||
2896 | [user-poison|user_poison], [enable_san_upoison="yes"], | ||
2897 | [no|yes|auto], [AC_MSG_ERROR(["$san" cannot be used with other options for --enable-sanitizers=])], | ||
2898 | [AC_MSG_ERROR([Unknown parameter "$san" for --enable-sanitizers=])] | ||
2899 | ) | ||
2900 | done | ||
2901 | AS_IF([test "x${enable_san_upoison}" = "xyes" && test "x${enable_san_address}" = "xno"], | ||
2902 | [AC_MSG_ERROR([User memory poisoning cannot be used without address sanitizer])] | ||
2903 | ) | ||
2904 | enable_sanitizers="selected" | ||
2905 | ] | ||
2906 | ) | ||
2907 | AS_CASE([${enable_sanitizers}], | ||
2908 | [selected], [AC_MSG_RESULT([selected])], | ||
2909 | [auto], [AC_MSG_RESULT([yes, detect and use supported sanitizers])], | ||
2910 | [AC_MSG_RESULT([no])] | ||
2911 | ) | ||
2912 | AS_VAR_IF([enable_sanitizers], ["no"], [:], | ||
2864 | [ | 2913 | [ |
2865 | AS_UNSET([san_FLAGS]) # the sanitizer flags to be added to both CFLAGS and LDFLAGS | 2914 | AS_UNSET([san_FLAGS]) # the sanitizer flags to be added to both CFLAGS and LDFLAGS |
2866 | AS_UNSET([san_CFLAGS]) # the sanitizer flags to be added to CFLAGS | 2915 | AS_UNSET([san_CFLAGS]) # the sanitizer flags to be added to CFLAGS |
2867 | saved_CFLAGS="$CFLAGS" | 2916 | saved_CFLAGS="$CFLAGS" |
2868 | AC_CACHE_CHECK([whether sanitizer parameter works for $CC], | 2917 | AC_CACHE_CHECK([whether '-fsanitize=' works for $CC], |
2869 | [mhd_cv_cc_sanitizer_works], | 2918 | [mhd_cv_cc_sanitizer_works], |
2870 | [ | 2919 | [ |
2871 | CFLAGS="${saved_CFLAGS} -fsanitize=wrongFeatureName" | 2920 | CFLAGS="${saved_CFLAGS} -fsanitize=wrongFeatureName" |
@@ -2875,71 +2924,79 @@ AS_VAR_IF([enable_sanitizers], ["yes"], | |||
2875 | ) | 2924 | ) |
2876 | AS_VAR_IF([mhd_cv_cc_sanitizer_works], ["yes"], | 2925 | AS_VAR_IF([mhd_cv_cc_sanitizer_works], ["yes"], |
2877 | [ | 2926 | [ |
2878 | AC_CACHE_CHECK([for address sanitizer], [mhd_cv_cc_sanitizer_address], | 2927 | AS_VAR_IF([enable_san_address], ["no"], [:], |
2879 | [ | 2928 | [ |
2880 | CFLAGS="${saved_CFLAGS} ${san_CFLAGS} ${san_FLAGS} -fsanitize=address" | 2929 | AC_CACHE_CHECK([for address sanitizer], [mhd_cv_cc_sanitizer_address], |
2881 | AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])], | ||
2882 | [mhd_cv_cc_sanitizer_address=yes], [mhd_cv_cc_sanitizer_address=no]) | ||
2883 | ] | ||
2884 | ) | ||
2885 | AS_VAR_IF([mhd_cv_cc_sanitizer_address],["yes"], | ||
2886 | [ | ||
2887 | AC_DEFINE([MHD_ASAN_ACTIVE], [1], [Define to '1' if you have address sanitizer enabled]) | ||
2888 | AC_CHECK_HEADERS([sanitizer/asan_interface.h], [], [], [AC_INCLUDES_DEFAULT]) | ||
2889 | AX_APPEND_FLAG([-fsanitize=address], [san_FLAGS]) | ||
2890 | enabled_sanitizers="${enabled_sanitizers}${enabled_sanitizers:+, }address" | ||
2891 | AC_CACHE_CHECK([whether leak detect is supported], [mhd_cv_cc_sanitizer_address_leak], | ||
2892 | [ | ||
2893 | CFLAGS="${saved_CFLAGS} ${san_CFLAGS} ${san_FLAGS}" | ||
2894 | ASAN_OPTIONS="exitcode=88:detect_leaks=1:halt_on_error=1" | ||
2895 | export ASAN_OPTIONS | ||
2896 | AC_RUN_IFELSE([AC_LANG_PROGRAM([],[])], | ||
2897 | [mhd_cv_cc_sanitizer_address_leak=yes], [mhd_cv_cc_sanitizer_address_leak=no], | ||
2898 | [ | ||
2899 | # Cross-compiling with sanitizers? | ||
2900 | mhd_cv_cc_sanitizer_address_leak='assuming no' | ||
2901 | ] | ||
2902 | ) | ||
2903 | AS_UNSET([ASAN_OPTIONS]) | ||
2904 | ] | ||
2905 | ) | ||
2906 | AC_CACHE_CHECK([for pointer compare sanitizer], [mhd_cv_cc_sanitizer_pointer_compare], | ||
2907 | [ | 2930 | [ |
2908 | CFLAGS="${saved_CFLAGS} ${san_CFLAGS} ${san_FLAGS} -fsanitize=pointer-compare" | 2931 | CFLAGS="${saved_CFLAGS} ${san_CFLAGS} ${san_FLAGS} -fsanitize=address" |
2909 | AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])], | 2932 | AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])], |
2910 | [mhd_cv_cc_sanitizer_pointer_compare=yes], [mhd_cv_cc_sanitizer_pointer_compare=no]) | 2933 | [mhd_cv_cc_sanitizer_address=yes], [mhd_cv_cc_sanitizer_address=no]) |
2911 | ] | 2934 | ] |
2912 | ) | 2935 | ) |
2913 | AS_VAR_IF([mhd_cv_cc_sanitizer_pointer_compare],["yes"], | 2936 | AS_VAR_IF([mhd_cv_cc_sanitizer_address],["yes"], |
2914 | [ | 2937 | [ |
2915 | AX_APPEND_FLAG([-fsanitize=pointer-compare], [san_FLAGS]) | 2938 | AC_DEFINE([MHD_ASAN_ACTIVE], [1], [Define to '1' if you have address sanitizer enabled]) |
2916 | enabled_sanitizers="${enabled_sanitizers}${enabled_sanitizers:+, }pointer compare" | 2939 | AX_APPEND_FLAG([-fsanitize=address], [san_FLAGS]) |
2917 | ] | 2940 | enabled_sanitizers="${enabled_sanitizers}${enabled_sanitizers:+, }address" |
2918 | ) | 2941 | AS_VAR_IF([enable_san_leak], ["no"], [:], |
2919 | AC_CACHE_CHECK([for pointer subtract sanitizer], [mhd_cv_cc_sanitizer_pointer_subtract], | ||
2920 | [ | ||
2921 | CFLAGS="${saved_CFLAGS} ${san_CFLAGS} ${san_FLAGS} -fsanitize=pointer-subtract" | ||
2922 | AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])], | ||
2923 | [mhd_cv_cc_sanitizer_pointer_subtract=yes], [mhd_cv_cc_sanitizer_pointer_subtract=no]) | ||
2924 | ] | ||
2925 | ) | ||
2926 | AS_VAR_IF([mhd_cv_cc_sanitizer_pointer_subtract],["yes"], | ||
2927 | [ | ||
2928 | AX_APPEND_FLAG([-fsanitize=pointer-subtract], [san_FLAGS]) | ||
2929 | enabled_sanitizers="${enabled_sanitizers}${enabled_sanitizers:+, }pointer subtract" | ||
2930 | ] | ||
2931 | ) | ||
2932 | AS_IF([test "x${mhd_cv_cc_sanitizer_pointer_compare}" = "xyes" && test "x${ac_cv_header_sanitizer_asan_interface_h}" = "xyes"], | ||
2933 | [ | ||
2934 | AC_CACHE_CHECK([whether '__attribute__((no_sanitize("pointer-compare","pointer-subtract")))' works], [mhd_cv_func_attribute_nosanitize_ptr], | ||
2935 | [ | 2942 | [ |
2936 | ASAN_OPTIONS="exitcode=88:detect_invalid_pointer_pairs=3:halt_on_error=1" | 2943 | AC_CACHE_CHECK([whether leak detect is supported by address sanitizer], [mhd_cv_cc_sanitizer_address_leak], |
2937 | export ASAN_OPTIONS | ||
2938 | CFLAGS="${saved_CFLAGS} ${san_CFLAGS} ${san_FLAGS} ${errattr_CFLAGS}" | ||
2939 | AC_RUN_IFELSE( | ||
2940 | [ | 2944 | [ |
2941 | AC_LANG_PROGRAM( | 2945 | CFLAGS="${saved_CFLAGS} ${san_CFLAGS} ${san_FLAGS}" |
2942 | [[ | 2946 | ASAN_OPTIONS="exitcode=88:detect_leaks=1:halt_on_error=1" |
2947 | export ASAN_OPTIONS | ||
2948 | AC_RUN_IFELSE([AC_LANG_PROGRAM([],[])], | ||
2949 | [mhd_cv_cc_sanitizer_address_leak=yes], [mhd_cv_cc_sanitizer_address_leak=no], | ||
2950 | [ | ||
2951 | # Cross-compiling with sanitizers? | ||
2952 | mhd_cv_cc_sanitizer_address_leak='assuming no' | ||
2953 | ] | ||
2954 | ) | ||
2955 | AS_UNSET([ASAN_OPTIONS]) | ||
2956 | ] | ||
2957 | ) | ||
2958 | ] | ||
2959 | ) | ||
2960 | AC_CACHE_CHECK([for pointer compare sanitizer], [mhd_cv_cc_sanitizer_pointer_compare], | ||
2961 | [ | ||
2962 | CFLAGS="${saved_CFLAGS} ${san_CFLAGS} ${san_FLAGS} -fsanitize=pointer-compare" | ||
2963 | AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])], | ||
2964 | [mhd_cv_cc_sanitizer_pointer_compare=yes], [mhd_cv_cc_sanitizer_pointer_compare=no]) | ||
2965 | ] | ||
2966 | ) | ||
2967 | AS_VAR_IF([mhd_cv_cc_sanitizer_pointer_compare],["yes"], | ||
2968 | [ | ||
2969 | AX_APPEND_FLAG([-fsanitize=pointer-compare], [san_FLAGS]) | ||
2970 | enabled_sanitizers="${enabled_sanitizers}${enabled_sanitizers:+, }pointer compare" | ||
2971 | ] | ||
2972 | ) | ||
2973 | AC_CACHE_CHECK([for pointer subtract sanitizer], [mhd_cv_cc_sanitizer_pointer_subtract], | ||
2974 | [ | ||
2975 | CFLAGS="${saved_CFLAGS} ${san_CFLAGS} ${san_FLAGS} -fsanitize=pointer-subtract" | ||
2976 | AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])], | ||
2977 | [mhd_cv_cc_sanitizer_pointer_subtract=yes], [mhd_cv_cc_sanitizer_pointer_subtract=no]) | ||
2978 | ] | ||
2979 | ) | ||
2980 | AS_VAR_IF([mhd_cv_cc_sanitizer_pointer_subtract],["yes"], | ||
2981 | [ | ||
2982 | AX_APPEND_FLAG([-fsanitize=pointer-subtract], [san_FLAGS]) | ||
2983 | enabled_sanitizers="${enabled_sanitizers}${enabled_sanitizers:+, }pointer subtract" | ||
2984 | ] | ||
2985 | ) | ||
2986 | AS_VAR_IF([enable_san_upoison], ["no"], [:], | ||
2987 | [ | ||
2988 | AC_CHECK_HEADERS([sanitizer/asan_interface.h], [], [], [AC_INCLUDES_DEFAULT]) | ||
2989 | AS_IF([test "x${mhd_cv_cc_sanitizer_pointer_compare}" = "xyes" && test "x${ac_cv_header_sanitizer_asan_interface_h}" = "xyes"], | ||
2990 | [ | ||
2991 | AC_CACHE_CHECK([whether '__attribute__((no_sanitize("pointer-compare","pointer-subtract")))' works], [mhd_cv_func_attribute_nosanitize_ptr], | ||
2992 | [ | ||
2993 | ASAN_OPTIONS="exitcode=88:detect_invalid_pointer_pairs=3:halt_on_error=1" | ||
2994 | export ASAN_OPTIONS | ||
2995 | CFLAGS="${saved_CFLAGS} ${san_CFLAGS} ${san_FLAGS} ${errattr_CFLAGS}" | ||
2996 | AC_RUN_IFELSE( | ||
2997 | [ | ||
2998 | AC_LANG_PROGRAM( | ||
2999 | [[ | ||
2943 | #include <stdlib.h> | 3000 | #include <stdlib.h> |
2944 | 3001 | ||
2945 | __attribute__((no_sanitize("pointer-compare","pointer-subtract"))) | 3002 | __attribute__((no_sanitize("pointer-compare","pointer-subtract"))) |
@@ -2949,8 +3006,8 @@ int ptr_process(void *ptr1, void *ptr2) | |||
2949 | return (int) ((char*)ptr2 - (char*)ptr1); | 3006 | return (int) ((char*)ptr2 - (char*)ptr1); |
2950 | return (int) ((char*)ptr1 - (char*)ptr2); | 3007 | return (int) ((char*)ptr1 - (char*)ptr2); |
2951 | } | 3008 | } |
2952 | ]], | 3009 | ]], |
2953 | [[ | 3010 | [[ |
2954 | int *a = (int*) malloc (sizeof(int)*4); | 3011 | int *a = (int*) malloc (sizeof(int)*4); |
2955 | int *b = (int*) malloc (sizeof(long)*6); | 3012 | int *b = (int*) malloc (sizeof(long)*6); |
2956 | int c = ptr_process(a, b); | 3013 | int c = ptr_process(a, b); |
@@ -2962,30 +3019,30 @@ int ptr_process(void *ptr1, void *ptr2) | |||
2962 | } | 3019 | } |
2963 | free (a); | 3020 | free (a); |
2964 | free (b); | 3021 | free (b); |
2965 | ]] | 3022 | ]] |
3023 | ) | ||
3024 | ], | ||
3025 | [mhd_cv_func_attribute_nosanitize_ptr=yes], [mhd_cv_func_attribute_nosanitize_ptr=no], | ||
3026 | [ | ||
3027 | # Cross-compiling with sanitizers?? | ||
3028 | mhd_cv_func_attribute_nosanitize_ptr='assuming no' | ||
3029 | ] | ||
3030 | ) | ||
3031 | AS_UNSET([ASAN_OPTIONS]) | ||
3032 | ] | ||
2966 | ) | 3033 | ) |
2967 | ], | 3034 | AS_VAR_IF([mhd_cv_func_attribute_nosanitize_ptr], ["yes"], |
2968 | [mhd_cv_func_attribute_nosanitize_ptr=yes], [mhd_cv_func_attribute_nosanitize_ptr=no], | 3035 | [AC_DEFINE([FUNC_ATTR_PTRCOMPARE_WOKRS],[1],[Define to '1' if '__attribute__((no_sanitize("pointer-compare","pointer-subtract")))' works])], |
2969 | [ | ||
2970 | # Cross-compiling with sanitizers?? | ||
2971 | mhd_cv_func_attribute_nosanitize_ptr='assuming no' | ||
2972 | ] | ||
2973 | ) | ||
2974 | AS_UNSET([ASAN_OPTIONS]) | ||
2975 | ] | ||
2976 | ) | ||
2977 | AS_VAR_IF([mhd_cv_func_attribute_nosanitize_ptr], ["yes"], | ||
2978 | [AC_DEFINE([FUNC_ATTR_PTRCOMPARE_WOKRS],[1],[Define to '1' if '__attribute__((no_sanitize("pointer-compare","pointer-subtract")))' works])], | ||
2979 | [ | ||
2980 | AC_CACHE_CHECK([whether '__attribute__((no_sanitize("address")))' works for pointers compare], [mhd_cv_func_attribute_nosanitize_addr], | ||
2981 | [ | ||
2982 | ASAN_OPTIONS="exitcode=88:detect_invalid_pointer_pairs=3:halt_on_error=1" | ||
2983 | export ASAN_OPTIONS | ||
2984 | CFLAGS="${saved_CFLAGS} ${san_CFLAGS} ${san_FLAGS} ${errattr_CFLAGS}" | ||
2985 | AC_RUN_IFELSE( | ||
2986 | [ | 3036 | [ |
2987 | AC_LANG_PROGRAM( | 3037 | AC_CACHE_CHECK([whether '__attribute__((no_sanitize("address")))' works for pointers compare], [mhd_cv_func_attribute_nosanitize_addr], |
2988 | [[ | 3038 | [ |
3039 | ASAN_OPTIONS="exitcode=88:detect_invalid_pointer_pairs=3:halt_on_error=1" | ||
3040 | export ASAN_OPTIONS | ||
3041 | CFLAGS="${saved_CFLAGS} ${san_CFLAGS} ${san_FLAGS} ${errattr_CFLAGS}" | ||
3042 | AC_RUN_IFELSE( | ||
3043 | [ | ||
3044 | AC_LANG_PROGRAM( | ||
3045 | [[ | ||
2989 | #include <stdlib.h> | 3046 | #include <stdlib.h> |
2990 | 3047 | ||
2991 | __attribute__((no_sanitize("address"))) | 3048 | __attribute__((no_sanitize("address"))) |
@@ -2995,8 +3052,8 @@ int ptr_process(void *ptr1, void *ptr2) | |||
2995 | return (int) ((char*)ptr2 - (char*)ptr1); | 3052 | return (int) ((char*)ptr2 - (char*)ptr1); |
2996 | return (int) ((char*)ptr1 - (char*)ptr2); | 3053 | return (int) ((char*)ptr1 - (char*)ptr2); |
2997 | } | 3054 | } |
2998 | ]], | 3055 | ]], |
2999 | [[ | 3056 | [[ |
3000 | int *a = (int*) malloc (sizeof(int)*4); | 3057 | int *a = (int*) malloc (sizeof(int)*4); |
3001 | int *b = (int*) malloc (sizeof(long)*6); | 3058 | int *b = (int*) malloc (sizeof(long)*6); |
3002 | int c = ptr_process(a, b); | 3059 | int c = ptr_process(a, b); |
@@ -3008,30 +3065,40 @@ int ptr_process(void *ptr1, void *ptr2) | |||
3008 | } | 3065 | } |
3009 | free (a); | 3066 | free (a); |
3010 | free (b); | 3067 | free (b); |
3011 | ]] | 3068 | ]] |
3069 | ) | ||
3070 | ], | ||
3071 | [mhd_cv_func_attribute_nosanitize_addr=yes], [mhd_cv_func_attribute_nosanitize_addr=no], | ||
3072 | [ | ||
3073 | # Cross-compiling with sanitizers?? | ||
3074 | mhd_cv_func_attribute_nosanitize_addr='assuming no' | ||
3075 | ] | ||
3076 | ) | ||
3077 | AS_UNSET([ASAN_OPTIONS]) | ||
3078 | ] | ||
3079 | ) | ||
3080 | AS_VAR_IF([mhd_cv_func_attribute_nosanitize_addr], ["yes"], | ||
3081 | [AC_DEFINE([FUNC_ATTR_NOSANITIZE_WORKS],[1],[Define to '1' if '__attribute__((no_sanitize("address")))' works for pointers compare])] | ||
3012 | ) | 3082 | ) |
3013 | ], | ||
3014 | [mhd_cv_func_attribute_nosanitize_addr=yes], [mhd_cv_func_attribute_nosanitize_addr=no], | ||
3015 | [ | ||
3016 | # Cross-compiling with sanitizers?? | ||
3017 | mhd_cv_func_attribute_nosanitize_addr='assuming no' | ||
3018 | ] | 3083 | ] |
3019 | ) | 3084 | ) |
3020 | AS_UNSET([ASAN_OPTIONS]) | ||
3021 | ] | 3085 | ] |
3022 | ) | 3086 | ) |
3023 | AS_VAR_IF([mhd_cv_func_attribute_nosanitize_addr], ["yes"], | ||
3024 | [AC_DEFINE([FUNC_ATTR_NOSANITIZE_WORKS],[1],[Define to '1' if '__attribute__((no_sanitize("address")))' works for pointers compare])] | ||
3025 | ) | ||
3026 | ] | 3087 | ] |
3027 | ) | 3088 | ) |
3028 | ] | 3089 | ] |
3029 | ) | 3090 | ) |
3091 | AS_IF([test "x${enable_san_address}" = "xyes" && test "x${mhd_cv_cc_sanitizer_address}" != "xyes"], | ||
3092 | [AC_MSG_ERROR([Address sanitizer cannot be enabled])] | ||
3093 | ) | ||
3094 | enable_san_address="${mhd_cv_cc_sanitizer_address}" | ||
3030 | ] | 3095 | ] |
3031 | ) | 3096 | ) |
3032 | dnl Ensure that '#' will be processed correctly | 3097 | AS_VAR_IF([enable_san_undef], ["no"], [:], |
3033 | [ | 3098 | [ |
3034 | test_undf_prog=' | 3099 | dnl Ensure that '#' will be processed correctly |
3100 | [ | ||
3101 | test_undf_prog=' | ||
3035 | #include <stdio.h> | 3102 | #include <stdio.h> |
3036 | 3103 | ||
3037 | void func_out_b(char *arr) | 3104 | void func_out_b(char *arr) |
@@ -3061,125 +3128,170 @@ int main(void) | |||
3061 | printf("%lu\n", ulvar + ch1); | 3128 | printf("%lu\n", ulvar + ch1); |
3062 | return 0; | 3129 | return 0; |
3063 | } | 3130 | } |
3064 | ' | 3131 | ' |
3065 | ] | 3132 | ] |
3066 | AC_CACHE_CHECK([for undefined behavior sanitizer], [mhd_cv_cc_sanitizer_undefined], | 3133 | AC_CACHE_CHECK([for undefined behavior sanitizer], [mhd_cv_cc_sanitizer_undefined], |
3067 | [ | ||
3068 | CFLAGS="${saved_CFLAGS} ${san_FLAGS} ${san_CFLAGS} -fsanitize=undefined" | ||
3069 | AC_LINK_IFELSE([AC_LANG_SOURCE([${test_undf_prog}])], | ||
3070 | [mhd_cv_cc_sanitizer_undefined=yes], [mhd_cv_cc_sanitizer_undefined=no]) | ||
3071 | ] | ||
3072 | ) | ||
3073 | AS_VAR_IF([mhd_cv_cc_sanitizer_undefined],["yes"], | ||
3074 | [ | ||
3075 | AX_APPEND_FLAG([-fsanitize=undefined], [san_FLAGS]) | ||
3076 | enabled_sanitizers="${enabled_sanitizers}${enabled_sanitizers:+, }undefined" | ||
3077 | ], | ||
3078 | [ | ||
3079 | AC_CACHE_CHECK([for undefined behavior sanitizer with '-fsanitize-undefined-trap-on-error'], [mhd_cv_cc_sanitizer_undefined_trap], | ||
3080 | [ | 3134 | [ |
3081 | CFLAGS="${saved_CFLAGS} ${san_FLAGS} ${san_CFLAGS} -fsanitize=undefined -fsanitize-undefined-trap-on-error" | 3135 | CFLAGS="${saved_CFLAGS} ${san_FLAGS} ${san_CFLAGS} -fsanitize=undefined" |
3082 | AC_LINK_IFELSE([AC_LANG_SOURCE([${test_undf_prog}])], | 3136 | AC_LINK_IFELSE([AC_LANG_SOURCE([${test_undf_prog}])], |
3083 | [mhd_cv_cc_sanitizer_undefined_trap=yes], [mhd_cv_cc_sanitizer_undefined_trap=no]) | 3137 | [mhd_cv_cc_sanitizer_undefined=yes], [mhd_cv_cc_sanitizer_undefined=no]) |
3084 | ] | 3138 | ] |
3085 | ) | 3139 | ) |
3086 | AS_VAR_IF([mhd_cv_cc_sanitizer_undefined_trap], ["yes"], | 3140 | AS_VAR_IF([mhd_cv_cc_sanitizer_undefined],["yes"], |
3087 | [ | 3141 | [ |
3088 | AX_APPEND_FLAG([-fsanitize=undefined], [san_FLAGS]) | 3142 | AX_APPEND_FLAG([-fsanitize=undefined], [san_FLAGS]) |
3089 | AX_APPEND_FLAG([-fsanitize-undefined-trap-on-error], [san_FLAGS]) | ||
3090 | enabled_sanitizers="${enabled_sanitizers}${enabled_sanitizers:+, }undefined" | 3143 | enabled_sanitizers="${enabled_sanitizers}${enabled_sanitizers:+, }undefined" |
3091 | AC_MSG_WARN([Enabled sanitizer without run-time library, error reporting will be limited]) | ||
3092 | ], | 3144 | ], |
3093 | [ | 3145 | [ |
3094 | AS_IF([test -z "${enabled_sanitizers}"], | 3146 | AC_CACHE_CHECK([for undefined behavior sanitizer with '-fsanitize-undefined-trap-on-error'], [mhd_cv_cc_sanitizer_undefined_trap], |
3095 | [ | 3147 | [ |
3096 | # Last resort | 3148 | CFLAGS="${saved_CFLAGS} ${san_FLAGS} ${san_CFLAGS} -fsanitize=undefined -fsanitize-undefined-trap-on-error" |
3097 | AC_CACHE_CHECK([for undefined behavior sanitizer with '-fsanitize-trap=all'], [mhd_cv_cc_sanitizer_undefined_trap_all], | 3149 | AC_LINK_IFELSE([AC_LANG_SOURCE([${test_undf_prog}])], |
3098 | [ | 3150 | [mhd_cv_cc_sanitizer_undefined_trap=yes], [mhd_cv_cc_sanitizer_undefined_trap=no]) |
3099 | CFLAGS="${saved_CFLAGS} ${san_FLAGS} ${san_CFLAGS} -fsanitize=undefined -fsanitize-trap=all" | 3151 | ] |
3100 | AC_LINK_IFELSE([AC_LANG_SOURCE([${test_undf_prog}])], | 3152 | ) |
3101 | [mhd_cv_cc_sanitizer_undefined_trap_all=yes], [mhd_cv_cc_sanitizer_undefined_trap_all=no]) | 3153 | AS_VAR_IF([mhd_cv_cc_sanitizer_undefined_trap], ["yes"], |
3102 | ] | 3154 | [ |
3103 | ) | 3155 | AX_APPEND_FLAG([-fsanitize=undefined], [san_FLAGS]) |
3104 | AS_VAR_IF([mhd_cv_cc_sanitizer_undefined_trap_all],["yes"], | 3156 | AX_APPEND_FLAG([-fsanitize-undefined-trap-on-error], [san_FLAGS]) |
3157 | enabled_sanitizers="${enabled_sanitizers}${enabled_sanitizers:+, }undefined" | ||
3158 | AC_MSG_WARN([Enabled sanitizer without run-time library, error reporting will be limited]) | ||
3159 | ], | ||
3160 | [ | ||
3161 | AS_IF([test -z "${enabled_sanitizers}"], | ||
3105 | [ | 3162 | [ |
3106 | AX_APPEND_FLAG([-fsanitize=undefined], [san_FLAGS]) | 3163 | # Last resort |
3107 | AX_APPEND_FLAG([-fsanitize-trap=all], [san_FLAGS]) | 3164 | AC_CACHE_CHECK([for undefined behavior sanitizer with '-fsanitize-trap=all'], [mhd_cv_cc_sanitizer_undefined_trap_all], |
3108 | CFLAGS="${saved_CFLAGS} ${san_FLAGS} ${san_CFLAGS} -fsanitize=undefined -fsanitize-trap=all" | 3165 | [ |
3109 | enabled_sanitizers="${enabled_sanitizers}${enabled_sanitizers:+, }undefined" | 3166 | CFLAGS="${saved_CFLAGS} ${san_FLAGS} ${san_CFLAGS} -fsanitize=undefined -fsanitize-trap=all" |
3110 | AC_MSG_WARN([Enabled sanitizer without run-time library, error reporting will be limited]) | 3167 | AC_LINK_IFELSE([AC_LANG_SOURCE([${test_undf_prog}])], |
3168 | [mhd_cv_cc_sanitizer_undefined_trap_all=yes], [mhd_cv_cc_sanitizer_undefined_trap_all=no]) | ||
3169 | ] | ||
3170 | ) | ||
3171 | AS_VAR_IF([mhd_cv_cc_sanitizer_undefined_trap_all],["yes"], | ||
3172 | [ | ||
3173 | AX_APPEND_FLAG([-fsanitize=undefined], [san_FLAGS]) | ||
3174 | AX_APPEND_FLAG([-fsanitize-trap=all], [san_FLAGS]) | ||
3175 | CFLAGS="${saved_CFLAGS} ${san_FLAGS} ${san_CFLAGS} -fsanitize=undefined -fsanitize-trap=all" | ||
3176 | enabled_sanitizers="${enabled_sanitizers}${enabled_sanitizers:+, }undefined" | ||
3177 | AC_MSG_WARN([Enabled sanitizer without run-time library, error reporting will be limited]) | ||
3178 | ] | ||
3179 | ) | ||
3111 | ] | 3180 | ] |
3112 | ) | 3181 | ) |
3113 | ] | 3182 | ] |
3114 | ) | 3183 | ) |
3115 | ] | 3184 | ] |
3116 | ) | 3185 | ) |
3117 | ] | 3186 | AS_CASE(["$enabled_sanitizers"], [*undefined], |
3118 | ) | ||
3119 | AS_CASE(["$enabled_sanitizers"], [*undefined], | ||
3120 | [ | ||
3121 | AS_VAR_IF([mhd_cv_cc_sanitizer_undefined], ["yes"],[], | ||
3122 | [ | 3187 | [ |
3123 | # A workaround for broken clang which is trying to use UBSan lib | 3188 | AS_VAR_IF([mhd_cv_cc_sanitizer_undefined], ["yes"],[], |
3124 | # even when instructed to not use it | 3189 | [ |
3190 | # A workaround for broken clang which is trying to use UBSan lib | ||
3191 | # even when instructed to not use it | ||
3192 | CFLAGS="${saved_CFLAGS} ${san_FLAGS} ${san_CFLAGS}" | ||
3193 | AX_APPEND_LINK_FLAGS([-fsanitize-trap=implicit-conversion], | ||
3194 | [san_FLAGS], [], [AC_LANG_SOURCE([${test_undf_prog}])]) | ||
3195 | ] | ||
3196 | ) | ||
3125 | CFLAGS="${saved_CFLAGS} ${san_FLAGS} ${san_CFLAGS}" | 3197 | CFLAGS="${saved_CFLAGS} ${san_FLAGS} ${san_CFLAGS}" |
3126 | AX_APPEND_LINK_FLAGS([-fsanitize-trap=implicit-conversion], | 3198 | AX_APPEND_LINK_FLAGS([-fsanitize=bounds-strict -fsanitize=local-bounds -fsanitize=implicit-conversion -fsanitize=nullability-arg], |
3127 | [san_FLAGS], [], [AC_LANG_SOURCE([${test_undf_prog}])]) | 3199 | [san_CFLAGS], [], [AC_LANG_SOURCE([${test_undf_prog}])]) |
3200 | ] | ||
3201 | ) | ||
3202 | AS_UNSET([test_undf_prog]) | ||
3203 | AS_CASE(["$enabled_sanitizers"], | ||
3204 | [*undefined], [enable_san_undef="yes"], | ||
3205 | [ | ||
3206 | AS_VAR_IF([enable_san_undef], [yes], [AC_MSG_ERROR([Undefined behavior sanitizer cannot be enabled])]) | ||
3207 | enable_san_undef="no" | ||
3128 | ] | 3208 | ] |
3129 | ) | 3209 | ) |
3130 | CFLAGS="${saved_CFLAGS} ${san_FLAGS} ${san_CFLAGS}" | ||
3131 | AX_APPEND_LINK_FLAGS([-fsanitize=bounds-strict -fsanitize=local-bounds -fsanitize=implicit-conversion -fsanitize=nullability-arg], | ||
3132 | [san_CFLAGS], [], [AC_LANG_SOURCE([${test_undf_prog}])]) | ||
3133 | ] | ||
3134 | ) | ||
3135 | AS_UNSET([test_undf_prog]) | ||
3136 | AC_CACHE_CHECK([for leak sanitizer], [mhd_cv_cc_sanitizer_leak], | ||
3137 | [ | ||
3138 | CFLAGS="${saved_CFLAGS} ${san_FLAGS} ${san_CFLAGS} -fsanitize=leak" | ||
3139 | AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])], | ||
3140 | [mhd_cv_cc_sanitizer_leak=yes], [mhd_cv_cc_sanitizer_leak=no]) | ||
3141 | ] | 3210 | ] |
3142 | ) | 3211 | ) |
3143 | AS_VAR_IF([mhd_cv_cc_sanitizer_leak],["yes"], | 3212 | AS_VAR_IF([enable_san_leak], ["no"], [:], |
3144 | [ | 3213 | [ |
3145 | AX_APPEND_FLAG([-fsanitize=leak], [san_FLAGS]) | 3214 | AC_CACHE_CHECK([for leak sanitizer], [mhd_cv_cc_sanitizer_leak], |
3146 | enabled_sanitizers="${enabled_sanitizers}${enabled_sanitizers:+, }leak" | 3215 | [ |
3216 | CFLAGS="${saved_CFLAGS} ${san_FLAGS} ${san_CFLAGS} -fsanitize=leak" | ||
3217 | AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])], | ||
3218 | [mhd_cv_cc_sanitizer_leak=yes], [mhd_cv_cc_sanitizer_leak=no]) | ||
3219 | ] | ||
3220 | ) | ||
3221 | AS_VAR_IF([mhd_cv_cc_sanitizer_leak],["yes"], | ||
3222 | [ | ||
3223 | AX_APPEND_FLAG([-fsanitize=leak], [san_FLAGS]) | ||
3224 | enabled_sanitizers="${enabled_sanitizers}${enabled_sanitizers:+, }leak" | ||
3225 | ] | ||
3226 | ) | ||
3227 | AS_IF([test "x${enable_san_leak}" = "xyes" && test "x${mhd_cv_cc_sanitizer_leak}" != "xyes"], | ||
3228 | [AC_MSG_ERROR([User poison cannot be enabled])] | ||
3229 | ) | ||
3230 | enable_san_leak="${mhd_cv_cc_sanitizer_leak}" | ||
3147 | ] | 3231 | ] |
3148 | ) | 3232 | ) |
3149 | AS_IF([test -z "${enabled_sanitizers}"], | 3233 | AS_IF([test -z "${enabled_sanitizers}"], |
3150 | [AC_MSG_ERROR([cannot find any sanitizer supported by $CC])]) | 3234 | [AC_MSG_ERROR([cannot find any sanitizer supported by $CC])]) |
3151 | AC_MSG_CHECKING([whether to enable user memory poisoning]) | 3235 | AS_VAR_IF([enable_san_upoison], ["no"], [:], |
3152 | AS_IF([test "x${mhd_cv_cc_sanitizer_address}" = "xyes" && test "x${mhd_cv_cc_sanitizer_pointer_compare}" = "xyes" && \ | ||
3153 | test "x${ac_cv_header_sanitizer_asan_interface_h}" = "xyes" && \ | ||
3154 | (test "x${mhd_cv_func_attribute_nosanitize_ptr}" = "xyes" || test "x${mhd_cv_func_attribute_nosanitize_addr}" = "xyes")], | ||
3155 | [ | 3236 | [ |
3156 | AC_DEFINE([MHD_ASAN_POISON_ACTIVE], [1], [Define to '1' if user memory poison is used]) | 3237 | AC_MSG_CHECKING([whether to enable user memory poisoning]) |
3157 | enabled_sanitizers="${enabled_sanitizers}${enabled_sanitizers:+, }user-poison" | 3238 | AS_IF([test "x${mhd_cv_cc_sanitizer_address}" = "xyes" && test "x${mhd_cv_cc_sanitizer_pointer_compare}" = "xyes" && \ |
3158 | AC_MSG_RESULT([yes]) | 3239 | test "x${ac_cv_header_sanitizer_asan_interface_h}" = "xyes" && \ |
3159 | ], [AC_MSG_RESULT([no])] | 3240 | (test "x${mhd_cv_func_attribute_nosanitize_ptr}" = "xyes" || test "x${mhd_cv_func_attribute_nosanitize_addr}" = "xyes")], |
3241 | [ | ||
3242 | AC_DEFINE([MHD_ASAN_POISON_ACTIVE], [1], [Define to '1' if user memory poison is used]) | ||
3243 | enabled_sanitizers="${enabled_sanitizers}${enabled_sanitizers:+, }user-poison" | ||
3244 | enable_san_upoison="yes" | ||
3245 | AC_MSG_RESULT([yes]) | ||
3246 | ], | ||
3247 | [ | ||
3248 | AC_MSG_RESULT([no]) | ||
3249 | AS_VAR_IF([enable_san_upoison], ["yes"], | ||
3250 | [AC_MSG_ERROR([User memory poisoning cannot be enabled])]) | ||
3251 | enable_san_upoison="no" | ||
3252 | ] | ||
3253 | ) | ||
3254 | ] | ||
3160 | ) | 3255 | ) |
3161 | AS_VAR_IF([mhd_cv_cc_sanitizer_address],["yes"], | 3256 | AS_VAR_IF([enable_san_address], ["yes"], |
3162 | [ | 3257 | [ |
3163 | AX_APPEND_FLAG([-D_FORTIFY_SOURCE=0], [san_CFLAGS]) | 3258 | AS_VAR_IF([mhd_cv_cc_sanitizer_address],["yes"], |
3164 | CFLAGS="${saved_CFLAGS} ${san_FLAGS} ${san_CFLAGS}" | 3259 | [ |
3165 | AX_APPEND_COMPILE_FLAGS([-Wp,-U_FORTIFY_SOURCE], [san_CFLAGS]) | 3260 | AX_APPEND_FLAG([-D_FORTIFY_SOURCE=0], [san_CFLAGS]) |
3166 | ], | 3261 | CFLAGS="${saved_CFLAGS} ${san_FLAGS} ${san_CFLAGS}" |
3167 | [AC_MSG_WARN([$CC does not support address sanitizer])] | 3262 | AX_APPEND_COMPILE_FLAGS([-Wp,-U_FORTIFY_SOURCE], [san_CFLAGS]) |
3263 | ], | ||
3264 | [AC_MSG_WARN([$CC does not support address sanitizer])] | ||
3265 | ) | ||
3266 | ] | ||
3168 | ) | 3267 | ) |
3169 | CFLAGS="${saved_CFLAGS} ${san_FLAGS} ${san_CFLAGS}" | 3268 | CFLAGS="${saved_CFLAGS} ${san_FLAGS} ${san_CFLAGS}" |
3170 | # Always stop on sanitizer error | 3269 | # Always stop on sanitizer error |
3171 | AX_APPEND_COMPILE_FLAGS([-fno-sanitize-recover=all], [san_CFLAGS]) | 3270 | AX_APPEND_COMPILE_FLAGS([-fno-sanitize-recover=all], [san_CFLAGS]) |
3172 | # Get better output for sanitizers error reporting | 3271 | # Get a better output for sanitizers error reporting |
3173 | AX_APPEND_COMPILE_FLAGS([-fno-omit-frame-pointer -fno-optimize-sibling-calls], | 3272 | AX_APPEND_COMPILE_FLAGS([-fno-omit-frame-pointer -fno-optimize-sibling-calls], |
3174 | [san_CFLAGS]) | 3273 | [san_CFLAGS]) |
3175 | AM_ASAN_OPTIONS="exitcode=88:strict_string_checks=1:detect_stack_use_after_return=1" | 3274 | AS_VAR_IF([enable_san_address], ["yes"], |
3176 | AM_ASAN_OPTIONS="${AM_ASAN_OPTIONS}:check_initialization_order=1:strict_init_order=1:redzone=64" | 3275 | [ |
3177 | AM_ASAN_OPTIONS="${AM_ASAN_OPTIONS}:max_free_fill_size=1024:detect_invalid_pointer_pairs=3" | 3276 | AM_ASAN_OPTIONS="exitcode=88:strict_string_checks=1:detect_stack_use_after_return=1" |
3178 | AM_ASAN_OPTIONS="${AM_ASAN_OPTIONS}:handle_ioctl=1:allow_user_poisoning=1:halt_on_error=1" | 3277 | AM_ASAN_OPTIONS="${AM_ASAN_OPTIONS}:check_initialization_order=1:strict_init_order=1:redzone=64" |
3179 | AS_VAR_IF([mhd_cv_cc_sanitizer_address_leak], ["yes"], | 3278 | AM_ASAN_OPTIONS="${AM_ASAN_OPTIONS}:max_free_fill_size=1024:detect_invalid_pointer_pairs=3" |
3180 | [AM_ASAN_OPTIONS="${AM_ASAN_OPTIONS}:detect_leaks=1"]) | 3279 | AM_ASAN_OPTIONS="${AM_ASAN_OPTIONS}:handle_ioctl=1:halt_on_error=1" |
3181 | AM_UBSAN_OPTIONS="exitcode=87:print_stacktrace=1:halt_on_error=1" | 3280 | AS_VAR_IF([enable_san_upoison], ["yes"], [AM_ASAN_OPTIONS="${AM_ASAN_OPTIONS}:allow_user_poisoning=1"]) |
3182 | AM_LSAN_OPTIONS="use_unaligned=1" | 3281 | ] |
3282 | ) | ||
3283 | AS_VAR_IF([enable_san_undef], [yes], | ||
3284 | [AM_UBSAN_OPTIONS="exitcode=87:print_stacktrace=1:halt_on_error=1"]) | ||
3285 | AS_VAR_IF([enable_san_leak], ["yes"], | ||
3286 | [ | ||
3287 | AS_VAR_IF([enable_san_address], ["yes"], | ||
3288 | [AS_VAR_IF([mhd_cv_cc_sanitizer_address_leak], ["yes"], | ||
3289 | [AM_ASAN_OPTIONS="${AM_ASAN_OPTIONS}:detect_leaks=1"]) | ||
3290 | ] | ||
3291 | ) | ||
3292 | AM_LSAN_OPTIONS="use_unaligned=1" | ||
3293 | ] | ||
3294 | ) | ||
3183 | AM_TESTS_ENVIRONMENT='\ | 3295 | AM_TESTS_ENVIRONMENT='\ |
3184 | ASAN_OPTIONS="$(AM_ASAN_OPTIONS)" ; export ASAN_OPTIONS ; \ | 3296 | ASAN_OPTIONS="$(AM_ASAN_OPTIONS)" ; export ASAN_OPTIONS ; \ |
3185 | UBSAN_OPTIONS="$(AM_UBSAN_OPTIONS)" ; export UBSAN_OPTIONS ; \ | 3297 | UBSAN_OPTIONS="$(AM_UBSAN_OPTIONS)" ; export UBSAN_OPTIONS ; \ |