From: Igor Putovny Date: Fri, 21 Feb 2025 10:58:53 +0000 (+0100) Subject: Satanize the build to find sus behavior X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=963185bd34f9e53673a3b440d487eac22312dc26;p=thirdparty%2Fbird.git Satanize the build to find sus behavior --- diff --git a/aclocal.m4 b/aclocal.m4 index 3fdc446f9..564084ee2 100644 --- a/aclocal.m4 +++ b/aclocal.m4 @@ -173,7 +173,6 @@ AC_DEFUN([BIRD_CHECK_LTO], LDFLAGS="$bird_tmp_ldflags" ]) - AC_DEFUN([BIRD_CHECK_GCC_OPTION], [ bird_tmp_cflags="$CFLAGS" @@ -207,6 +206,40 @@ AC_DEFUN([BIRD_CHECK_AND_ADD_GCC_OPTION], BIRD_ADD_GCC_OPTION($1,$2) ]) +AC_DEFUN([BIRD_CHECK_GCC_OPTION_LINK], +[ + bird_tmp_cflags="$CFLAGS" + CFLAGS="$3 $2" + + AC_CACHE_CHECK( + [whether CC supports $2], + [$1], + [ + AC_LINK_IFELSE( + [AC_LANG_PROGRAM()], + [$1=yes], + [$1=no] + ) + ] + ) + + CFLAGS="$bird_tmp_cflags" +]) + +AC_DEFUN([BIRD_ADD_GCC_OPTION_LINK], +[ + if test "$$1" = yes ; then + CFLAGS="$CFLAGS $2" + LDFLAGS="$LDFLAGS $2" + fi +]) + +AC_DEFUN([BIRD_CHECK_AND_ADD_GCC_OPTION_LINK], +[ + BIRD_CHECK_GCC_OPTION_LINK($@) + BIRD_ADD_GCC_OPTION_LINK($1,$2) +]) + # BIRD_CHECK_PROG_FLAVOR_GNU(PROGRAM-PATH, IF-SUCCESS, [IF-FAILURE]) # copied from autoconf internal _AC_PATH_PROG_FLAVOR_GNU AC_DEFUN([BIRD_CHECK_PROG_FLAVOR_GNU], diff --git a/configure.ac b/configure.ac index 43349102a..3e8f85357 100644 --- a/configure.ac +++ b/configure.ac @@ -36,6 +36,12 @@ AC_ARG_ENABLE([memcheck], [enable_memcheck=yes] ) +AC_ARG_ENABLE([satan], + [AS_HELP_STRING([--enable-satan], [enable memory and undefined bahaviour sanitization @<:@no@:>@])], + [], + [enable_satan=no] +) + AC_ARG_ENABLE([compact-tries], [AS_HELP_STRING([--enable-compact-tries], [use 4-way tries instead of 16-way ones @<:@no@:>@])], [], @@ -424,6 +430,13 @@ if test "$enable_debug" = yes ; then fi fi +if test "$enable_satan" = yes; then + BIRD_CHECK_AND_ADD_GCC_OPTION_LINK([bird_cv_c_option_satan_address], [-fsanitize=address], []) + BIRD_CHECK_AND_ADD_GCC_OPTION_LINK([bird_cv_c_option_satan_undefined], [-fsanitize=undefined], []) + BIRD_CHECK_AND_ADD_GCC_OPTION_LINK([bird_cv_c_option_satan_memory], [-fsanitize=memory], []) +fi + + if test "$enable_compact_tries" = yes ; then AC_DEFINE([ENABLE_COMPACT_TRIES], [1], [Define to 1 if you want 4-way tries instead of 16-way ones.]) fi