From b0d53af7698567706c23b17b13d0e233472f33ea Mon Sep 17 00:00:00 2001 From: Ivan Kochin Date: Wed, 6 Dec 2023 12:07:59 +0200 Subject: [PATCH] BUILD/CONFIG: Introduce Address Sanitizer flag option --- config/m4/compiler.m4 | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/config/m4/compiler.m4 b/config/m4/compiler.m4 index 83db0271f4e..6aa3360e76a 100644 --- a/config/m4/compiler.m4 +++ b/config/m4/compiler.m4 @@ -411,6 +411,31 @@ ADD_COMPILER_FLAG_IF_SUPPORTED([-funwind-tables], [AS_MESSAGE([compiling without unwind tables])]) +# +# ASAN support +# +AC_ARG_ENABLE([asan], + AS_HELP_STRING([--enable-asan], [Enable address sanitized check]), + [], + [enable_asan=no]) + +AS_IF([test "x$enable_asan" = xyes], + [ADD_COMPILER_FLAG_IF_SUPPORTED([-fsanitize=address -fno-omit-frame-pointer], + [-fsanitize=address -fno-omit-frame-pointer], + [AC_LANG_SOURCE([[int main(int argc, char** argv){return 0;}]])], + [AS_MESSAGE([compiling with sanitizer]) + BASE_CXXFLAGS="-fsanitize=address -fno-omit-frame-pointer $BASE_CXXFLAGS" + LDFLAGS="-fsanitize=address -fno-omit-frame-pointer $LDFLAGS"], + [AC_MSG_ERROR([ASAN check is requested but not supported. Check libasan package existance])]) + + AC_RUN_IFELSE([AC_LANG_PROGRAM([[#include ]], + [[void *p = malloc(7); return 0;]])], + [AC_MSG_ERROR([ASAN cannot detect simple memory leak, consider installing newer compiler version])], + [AS_MESSAGE([sanitizer runtime leak detection check passed])] + )], + []) + + AS_IF([test "x$enable_gcov" = xyes], [ADD_COMPILER_FLAGS_IF_SUPPORTED([[-ftest-coverage], [-fprofile-arcs]],