]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Satanize the build to find sus behavior
authorIgor Putovny <igor.putovny@nic.cz>
Fri, 21 Feb 2025 10:58:53 +0000 (11:58 +0100)
committerMaria Matejka <mq@ucw.cz>
Fri, 21 Feb 2025 10:58:53 +0000 (11:58 +0100)
aclocal.m4
configure.ac

index 3fdc446f9de92ee5a0d973a94f92dac8691e9046..564084ee218dff3f7e3ffcb367f8075262c50c91 100644 (file)
@@ -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],
index 43349102a68e53cf24dd9ae8484b65afa5c2b5e7..3e8f853570f1a735916ab714c58f905dc8ecf3a5 100644 (file)
@@ -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