diff options
author | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2021-09-07 12:24:25 +0300 |
---|---|---|
committer | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2021-09-07 12:25:26 +0300 |
commit | e2a52a91c687afc8f15b98a33ee6ed01a0a4a1ff (patch) | |
tree | 50e764864612cdc805511fb75d74bfc2e3d8cdd1 /configure.ac | |
parent | be630f9d6b2ebed570475c512dca7d986b95fc6d (diff) | |
download | libmicrohttpd-e2a52a91c687afc8f15b98a33ee6ed01a0a4a1ff.tar.gz libmicrohttpd-e2a52a91c687afc8f15b98a33ee6ed01a0a4a1ff.zip |
configure: improved test for undefined behavior sanitizer
Added workaround for clang bug
Diffstat (limited to 'configure.ac')
-rw-r--r-- | configure.ac | 106 |
1 files changed, 77 insertions, 29 deletions
diff --git a/configure.ac b/configure.ac index 92a6aaf8..b61e1d4a 100644 --- a/configure.ac +++ b/configure.ac | |||
@@ -2535,11 +2535,13 @@ AC_ARG_ENABLE([sanitizers], | |||
2535 | [], [enable_sanitizers=no]) | 2535 | [], [enable_sanitizers=no]) |
2536 | AS_VAR_IF([enable_sanitizers], ["yes"], | 2536 | AS_VAR_IF([enable_sanitizers], ["yes"], |
2537 | [ | 2537 | [ |
2538 | new_CFLAGS="$CFLAGS" | 2538 | AS_UNSET([san_FLAGS]) # the sanitizer flags to be added to both CFLAGS and LDFLAGS |
2539 | AS_UNSET([san_CFLAGS]) # the sanitizer flags to be added to CFLAGS | ||
2540 | saved_CFLAGS="$CFLAGS" | ||
2539 | AC_CACHE_CHECK([whether sanitizer parameter works for $CC], | 2541 | AC_CACHE_CHECK([whether sanitizer parameter works for $CC], |
2540 | [mhd_cv_cc_sanitizer_works], | 2542 | [mhd_cv_cc_sanitizer_works], |
2541 | [ | 2543 | [ |
2542 | CFLAGS="${new_CFLAGS} -fsanitize=wrongFeatureName" | 2544 | CFLAGS="${saved_CFLAGS} -fsanitize=wrongFeatureName" |
2543 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[])], | 2545 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[])], |
2544 | [mhd_cv_cc_sanitizer_works=no], [mhd_cv_cc_sanitizer_works=yes]) | 2546 | [mhd_cv_cc_sanitizer_works=no], [mhd_cv_cc_sanitizer_works=yes]) |
2545 | ] | 2547 | ] |
@@ -2548,66 +2550,100 @@ AS_VAR_IF([enable_sanitizers], ["yes"], | |||
2548 | [ | 2550 | [ |
2549 | AC_CACHE_CHECK([for address sanitizer], [mhd_cv_cc_sanitizer_address], | 2551 | AC_CACHE_CHECK([for address sanitizer], [mhd_cv_cc_sanitizer_address], |
2550 | [ | 2552 | [ |
2551 | CFLAGS="${saved_CFLAGS} -fsanitize=address" | 2553 | CFLAGS="${saved_CFLAGS} ${san_CFLAGS} ${san_FLAGS} -fsanitize=address" |
2552 | AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])], | 2554 | AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])], |
2553 | [mhd_cv_cc_sanitizer_address=yes], [mhd_cv_cc_sanitizer_address=no]) | 2555 | [mhd_cv_cc_sanitizer_address=yes], [mhd_cv_cc_sanitizer_address=no]) |
2554 | ] | 2556 | ] |
2555 | ) | 2557 | ) |
2556 | AS_VAR_IF([mhd_cv_cc_sanitizer_address],["yes"], | 2558 | AS_VAR_IF([mhd_cv_cc_sanitizer_address],["yes"], |
2557 | [ | 2559 | [ |
2558 | new_CFLAGS="${new_CFLAGS} -fsanitize=address" | 2560 | AX_APPEND_FLAG([-fsanitize=address], [san_FLAGS]) |
2559 | enabled_sanitizers="${enabled_sanitizers}${enabled_sanitizers:+, }address" | 2561 | enabled_sanitizers="${enabled_sanitizers}${enabled_sanitizers:+, }address" |
2560 | AC_CACHE_CHECK([for pointer compare sanitizer], [mhd_cv_cc_sanitizer_pointer_compare], | 2562 | AC_CACHE_CHECK([for pointer compare sanitizer], [mhd_cv_cc_sanitizer_pointer_compare], |
2561 | [ | 2563 | [ |
2562 | CFLAGS="${new_CFLAGS} -fsanitize=pointer-compare" | 2564 | CFLAGS="${saved_CFLAGS} ${san_CFLAGS} ${san_FLAGS} -fsanitize=pointer-compare" |
2563 | AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])], | 2565 | AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])], |
2564 | [mhd_cv_cc_sanitizer_pointer_compare=yes], [mhd_cv_cc_sanitizer_pointer_compare=no]) | 2566 | [mhd_cv_cc_sanitizer_pointer_compare=yes], [mhd_cv_cc_sanitizer_pointer_compare=no]) |
2565 | ] | 2567 | ] |
2566 | ) | 2568 | ) |
2567 | AS_VAR_IF([mhd_cv_cc_sanitizer_pointer_compare],["yes"], | 2569 | AS_VAR_IF([mhd_cv_cc_sanitizer_pointer_compare],["yes"], |
2568 | [ | 2570 | [ |
2569 | new_CFLAGS="${new_CFLAGS} -fsanitize=pointer-compare" | 2571 | AX_APPEND_FLAG([-fsanitize=pointer-compare], [san_FLAGS]) |
2570 | enabled_sanitizers="${enabled_sanitizers}${enabled_sanitizers:+, }pointer compare" | 2572 | enabled_sanitizers="${enabled_sanitizers}${enabled_sanitizers:+, }pointer compare" |
2571 | ] | 2573 | ] |
2572 | ) | 2574 | ) |
2573 | AC_CACHE_CHECK([for pointer subtract sanitizer], [mhd_cv_cc_sanitizer_pointer_subtract], | 2575 | AC_CACHE_CHECK([for pointer subtract sanitizer], [mhd_cv_cc_sanitizer_pointer_subtract], |
2574 | [ | 2576 | [ |
2575 | CFLAGS="${new_CFLAGS} -fsanitize=pointer-subtract" | 2577 | CFLAGS="${saved_CFLAGS} ${san_CFLAGS} ${san_FLAGS} -fsanitize=pointer-subtract" |
2576 | AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])], | 2578 | AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])], |
2577 | [mhd_cv_cc_sanitizer_pointer_subtract=yes], [mhd_cv_cc_sanitizer_pointer_subtract=no]) | 2579 | [mhd_cv_cc_sanitizer_pointer_subtract=yes], [mhd_cv_cc_sanitizer_pointer_subtract=no]) |
2578 | ] | 2580 | ] |
2579 | ) | 2581 | ) |
2580 | AS_VAR_IF([mhd_cv_cc_sanitizer_pointer_subtract],["yes"], | 2582 | AS_VAR_IF([mhd_cv_cc_sanitizer_pointer_subtract],["yes"], |
2581 | [ | 2583 | [ |
2582 | new_CFLAGS="${new_CFLAGS} -fsanitize=pointer-subtract" | 2584 | AX_APPEND_FLAG([-fsanitize=pointer-subtract], [san_FLAGS]) |
2583 | enabled_sanitizers="${enabled_sanitizers}${enabled_sanitizers:+, }pointer subtract" | 2585 | enabled_sanitizers="${enabled_sanitizers}${enabled_sanitizers:+, }pointer subtract" |
2584 | ] | 2586 | ] |
2585 | ) | 2587 | ) |
2586 | ] | 2588 | ] |
2587 | ) | 2589 | ) |
2590 | [dnl Ensure that '#' will be processed correctly | ||
2591 | test_undf_prog=' | ||
2592 | #include <stdio.h> | ||
2593 | |||
2594 | void func_out_b(char *arr) | ||
2595 | { | ||
2596 | arr[0] = 0; | ||
2597 | arr[16] = 2; | ||
2598 | } | ||
2599 | |||
2600 | unsigned int int_deref(void *ptr) | ||
2601 | { | ||
2602 | return (*((int*)ptr)) + 2; | ||
2603 | } | ||
2604 | |||
2605 | int func1(void) | ||
2606 | { | ||
2607 | char chr[16]; | ||
2608 | func_out_b (chr); | ||
2609 | return int_deref(chr + 1) + int_deref(chr + 2); | ||
2610 | } | ||
2611 | |||
2612 | int main(void) | ||
2613 | { | ||
2614 | unsigned long ulvar; | ||
2615 | signed char ch1; | ||
2616 | ulvar = -1 * func1(); | ||
2617 | ch1 = ulvar * 6UL; | ||
2618 | printf("%lu\n", ulvar + ch1); | ||
2619 | return 0; | ||
2620 | } | ||
2621 | ' | ||
2622 | ] | ||
2588 | AC_CACHE_CHECK([for undefined behavior sanitizer], [mhd_cv_cc_sanitizer_undefined], | 2623 | AC_CACHE_CHECK([for undefined behavior sanitizer], [mhd_cv_cc_sanitizer_undefined], |
2589 | [ | 2624 | [ |
2590 | CFLAGS="${new_CFLAGS} -fsanitize=undefined" | 2625 | CFLAGS="${saved_CFLAGS} ${san_FLAGS} ${san_CFLAGS} -fsanitize=undefined" |
2591 | AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])], | 2626 | AC_LINK_IFELSE([AC_LANG_SOURCE([${test_undf_prog}])], |
2592 | [mhd_cv_cc_sanitizer_undefined=yes], [mhd_cv_cc_sanitizer_undefined=no]) | 2627 | [mhd_cv_cc_sanitizer_undefined=yes], [mhd_cv_cc_sanitizer_undefined=no]) |
2593 | ] | 2628 | ] |
2594 | ) | 2629 | ) |
2595 | AS_VAR_IF([mhd_cv_cc_sanitizer_undefined],["yes"], | 2630 | AS_VAR_IF([mhd_cv_cc_sanitizer_undefined],["yes"], |
2596 | [ | 2631 | [ |
2597 | new_CFLAGS="${new_CFLAGS} -fsanitize=undefined" | 2632 | AX_APPEND_FLAG([-fsanitize=undefined], [san_FLAGS]) |
2598 | enabled_sanitizers="${enabled_sanitizers}${enabled_sanitizers:+, }undefined" | 2633 | enabled_sanitizers="${enabled_sanitizers}${enabled_sanitizers:+, }undefined" |
2599 | ], | 2634 | ], |
2600 | [ | 2635 | [ |
2601 | AC_CACHE_CHECK([for undefined behavior sanitizer with '-fsanitize-undefined-trap-on-error'], [mhd_cv_cc_sanitizer_undefined_trap], | 2636 | AC_CACHE_CHECK([for undefined behavior sanitizer with '-fsanitize-undefined-trap-on-error'], [mhd_cv_cc_sanitizer_undefined_trap], |
2602 | [ | 2637 | [ |
2603 | CFLAGS="${new_CFLAGS} -fsanitize=undefined -fsanitize-undefined-trap-on-error" | 2638 | CFLAGS="${saved_CFLAGS} ${san_FLAGS} ${san_CFLAGS} -fsanitize=undefined -fsanitize-undefined-trap-on-error" |
2604 | AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])], | 2639 | AC_LINK_IFELSE([AC_LANG_SOURCE([${test_undf_prog}])], |
2605 | [mhd_cv_cc_sanitizer_undefined_trap=yes], [mhd_cv_cc_sanitizer_undefined_trap=no]) | 2640 | [mhd_cv_cc_sanitizer_undefined_trap=yes], [mhd_cv_cc_sanitizer_undefined_trap=no]) |
2606 | ] | 2641 | ] |
2607 | ) | 2642 | ) |
2608 | AS_VAR_IF([mhd_cv_cc_sanitizer_undefined_trap], ["yes"], | 2643 | AS_VAR_IF([mhd_cv_cc_sanitizer_undefined_trap], ["yes"], |
2609 | [ | 2644 | [ |
2610 | new_CFLAGS="${new_CFLAGS} -fsanitize=undefined -fsanitize-undefined-trap-on-error" | 2645 | AX_APPEND_FLAG([-fsanitize=undefined], [san_FLAGS]) |
2646 | AX_APPEND_FLAG([-fsanitize-undefined-trap-on-error], [san_FLAGS]) | ||
2611 | enabled_sanitizers="${enabled_sanitizers}${enabled_sanitizers:+, }undefined" | 2647 | enabled_sanitizers="${enabled_sanitizers}${enabled_sanitizers:+, }undefined" |
2612 | AC_MSG_WARN([Enabled sanitizer without run-time library, error reporting will be limited]) | 2648 | AC_MSG_WARN([Enabled sanitizer without run-time library, error reporting will be limited]) |
2613 | ], | 2649 | ], |
@@ -2617,14 +2653,16 @@ AS_VAR_IF([enable_sanitizers], ["yes"], | |||
2617 | # Last resort | 2653 | # Last resort |
2618 | AC_CACHE_CHECK([for undefined behavior sanitizer with '-fsanitize-trap=all'], [mhd_cv_cc_sanitizer_undefined_trap_all], | 2654 | AC_CACHE_CHECK([for undefined behavior sanitizer with '-fsanitize-trap=all'], [mhd_cv_cc_sanitizer_undefined_trap_all], |
2619 | [ | 2655 | [ |
2620 | CFLAGS="${new_CFLAGS} -fsanitize=undefined -fsanitize-undefined-trap-on-error" | 2656 | CFLAGS="${saved_CFLAGS} ${san_FLAGS} ${san_CFLAGS} -fsanitize=undefined -fsanitize-trap=all" |
2621 | AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])], | 2657 | AC_LINK_IFELSE([AC_LANG_SOURCE([${test_undf_prog}])], |
2622 | [mhd_cv_cc_sanitizer_undefined_trap_all=yes], [mhd_cv_cc_sanitizer_undefined_trap_all=no]) | 2658 | [mhd_cv_cc_sanitizer_undefined_trap_all=yes], [mhd_cv_cc_sanitizer_undefined_trap_all=no]) |
2623 | ] | 2659 | ] |
2624 | ) | 2660 | ) |
2625 | AS_VAR_IF([mhd_cv_cc_sanitizer_undefined_trap_all],["yes"], | 2661 | AS_VAR_IF([mhd_cv_cc_sanitizer_undefined_trap_all],["yes"], |
2626 | [ | 2662 | [ |
2627 | new_CFLAGS="${new_CFLAGS} -fsanitize=undefined -fsanitize-undefined-trap-on-error" | 2663 | AX_APPEND_FLAG([-fsanitize=undefined], [san_FLAGS]) |
2664 | AX_APPEND_FLAG([-fsanitize-trap=all], [san_FLAGS]) | ||
2665 | CFLAGS="${saved_CFLAGS} ${san_FLAGS} ${san_CFLAGS} -fsanitize=undefined -fsanitize-trap=all" | ||
2628 | enabled_sanitizers="${enabled_sanitizers}${enabled_sanitizers:+, }undefined" | 2666 | enabled_sanitizers="${enabled_sanitizers}${enabled_sanitizers:+, }undefined" |
2629 | AC_MSG_WARN([Enabled sanitizer without run-time library, error reporting will be limited]) | 2667 | AC_MSG_WARN([Enabled sanitizer without run-time library, error reporting will be limited]) |
2630 | ] | 2668 | ] |
@@ -2637,21 +2675,31 @@ AS_VAR_IF([enable_sanitizers], ["yes"], | |||
2637 | ) | 2675 | ) |
2638 | AS_CASE(["$enabled_sanitizers"], [*undefined], | 2676 | AS_CASE(["$enabled_sanitizers"], [*undefined], |
2639 | [ | 2677 | [ |
2640 | CFLAGS="${new_CFLAGS}" | 2678 | AS_VAR_IF([mhd_cv_cc_sanitizer_undefined], ["yes"],[], |
2679 | [ | ||
2680 | # A workaround for broken clang which is trying to use UBSan lib | ||
2681 | # even when instructed to not use it | ||
2682 | CFLAGS="${saved_CFLAGS} ${san_FLAGS} ${san_CFLAGS}" | ||
2683 | AX_APPEND_LINK_FLAGS([-fsanitize-trap=implicit-conversion], | ||
2684 | [san_FLAGS], [], [AC_LANG_SOURCE([${test_undf_prog}])]) | ||
2685 | ] | ||
2686 | ) | ||
2687 | CFLAGS="${saved_CFLAGS} ${san_FLAGS} ${san_CFLAGS}" | ||
2641 | AX_APPEND_LINK_FLAGS([-fsanitize=bounds-strict -fsanitize=local-bounds -fsanitize=implicit-conversion -fsanitize=nullability-arg], | 2688 | AX_APPEND_LINK_FLAGS([-fsanitize=bounds-strict -fsanitize=local-bounds -fsanitize=implicit-conversion -fsanitize=nullability-arg], |
2642 | [new_CFLAGS], []) | 2689 | [san_CFLAGS], [], [AC_LANG_SOURCE([${test_undf_prog}])]) |
2643 | ] | 2690 | ] |
2644 | ) | 2691 | ) |
2692 | AS_UNSET([test_undf_prog]) | ||
2645 | AC_CACHE_CHECK([for leak sanitizer], [mhd_cv_cc_sanitizer_leak], | 2693 | AC_CACHE_CHECK([for leak sanitizer], [mhd_cv_cc_sanitizer_leak], |
2646 | [ | 2694 | [ |
2647 | CFLAGS="${new_CFLAGS} -fsanitize=leak" | 2695 | CFLAGS="${saved_CFLAGS} ${san_FLAGS} ${san_CFLAGS} -fsanitize=leak" |
2648 | AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])], | 2696 | AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])], |
2649 | [mhd_cv_cc_sanitizer_leak=yes], [mhd_cv_cc_sanitizer_leak=no]) | 2697 | [mhd_cv_cc_sanitizer_leak=yes], [mhd_cv_cc_sanitizer_leak=no]) |
2650 | ] | 2698 | ] |
2651 | ) | 2699 | ) |
2652 | AS_VAR_IF([mhd_cv_cc_sanitizer_leak],["yes"], | 2700 | AS_VAR_IF([mhd_cv_cc_sanitizer_leak],["yes"], |
2653 | [ | 2701 | [ |
2654 | new_CFLAGS="${new_CFLAGS} -fsanitize=leak" | 2702 | AX_APPEND_FLAG([-fsanitize=leak], [san_FLAGS]) |
2655 | enabled_sanitizers="${enabled_sanitizers}${enabled_sanitizers:+, }leak" | 2703 | enabled_sanitizers="${enabled_sanitizers}${enabled_sanitizers:+, }leak" |
2656 | ] | 2704 | ] |
2657 | ) | 2705 | ) |
@@ -2659,18 +2707,18 @@ AS_VAR_IF([enable_sanitizers], ["yes"], | |||
2659 | [AC_MSG_ERROR([cannot find any sanitizer supported by $CC])]) | 2707 | [AC_MSG_ERROR([cannot find any sanitizer supported by $CC])]) |
2660 | AS_VAR_IF([mhd_cv_cc_sanitizer_address],["yes"], | 2708 | AS_VAR_IF([mhd_cv_cc_sanitizer_address],["yes"], |
2661 | [ | 2709 | [ |
2662 | new_CFLAGS="${new_CFLAGS} -D_FORTIFY_SOURCE=0" | 2710 | AX_APPEND_FLAG([-D_FORTIFY_SOURCE=0], [san_CFLAGS]) |
2663 | CFLAGS="${new_CFLAGS}" | 2711 | CFLAGS="${saved_CFLAGS} ${san_FLAGS} ${san_CFLAGS}" |
2664 | AX_APPEND_COMPILE_FLAGS([-Wp,-U_FORTIFY_SOURCE], [new_CFLAGS]) | 2712 | AX_APPEND_COMPILE_FLAGS([-Wp,-U_FORTIFY_SOURCE], [san_CFLAGS]) |
2665 | ], | 2713 | ], |
2666 | [AC_MSG_WARN([$CC does not support address sanitizer])] | 2714 | [AC_MSG_WARN([$CC does not support address sanitizer])] |
2667 | ) | 2715 | ) |
2668 | # Always stop on error | 2716 | # Always stop on error |
2669 | CFLAGS="${new_CFLAGS}" | 2717 | CFLAGS="${saved_CFLAGS} ${san_FLAGS} ${san_CFLAGS}" |
2670 | AX_APPEND_COMPILE_FLAGS([-fno-sanitize-recover=all], [new_CFLAGS]) | 2718 | AX_APPEND_COMPILE_FLAGS([-fno-sanitize-recover=all], [san_CFLAGS]) |
2671 | # Get better output for sanitizers error reporting | 2719 | # Get better output for sanitizers error reporting |
2672 | AX_APPEND_COMPILE_FLAGS([-fno-omit-frame-pointer -fno-common -fno-optimize-sibling-calls], | 2720 | AX_APPEND_COMPILE_FLAGS([-fno-omit-frame-pointer -fno-common -fno-optimize-sibling-calls], |
2673 | [new_CFLAGS]) | 2721 | [san_CFLAGS]) |
2674 | AM_ASAN_OPTIONS="exitcode=88:detect_leaks=1:strict_string_checks=1:detect_stack_use_after_return=1" | 2722 | AM_ASAN_OPTIONS="exitcode=88:detect_leaks=1:strict_string_checks=1:detect_stack_use_after_return=1" |
2675 | AM_ASAN_OPTIONS="${AM_ASAN_OPTIONS}:check_initialization_order=1:strict_init_order=1:redzone=64" | 2723 | AM_ASAN_OPTIONS="${AM_ASAN_OPTIONS}:check_initialization_order=1:strict_init_order=1:redzone=64" |
2676 | AM_ASAN_OPTIONS="${AM_ASAN_OPTIONS}:max_free_fill_size=1024:detect_invalid_pointer_pairs=3" | 2724 | AM_ASAN_OPTIONS="${AM_ASAN_OPTIONS}:max_free_fill_size=1024:detect_invalid_pointer_pairs=3" |
@@ -2683,8 +2731,8 @@ UBSAN_OPTIONS="$(AM_UBSAN_OPTIONS)" ; export UBSAN_OPTIONS ; \ | |||
2683 | LSAN_OPTIONS="$(AM_LSAN_OPTIONS)" ; export LSAN_OPTIONS ;' | 2731 | LSAN_OPTIONS="$(AM_LSAN_OPTIONS)" ; export LSAN_OPTIONS ;' |
2684 | ] | 2732 | ] |
2685 | ) | 2733 | ) |
2686 | CFLAGS="$new_CFLAGS" | 2734 | CFLAGS="${saved_CFLAGS} ${san_FLAGS} ${san_CFLAGS}" |
2687 | AS_UNSET([new_CFLAGS]) | 2735 | AS_UNSET([saved_CFLAGS]) |
2688 | ] | 2736 | ] |
2689 | ) | 2737 | ) |
2690 | AM_CONDITIONAL([USE_SANITIZERS], | 2738 | AM_CONDITIONAL([USE_SANITIZERS], |