From: Claudio André <claudioandre.br@xxxxxxxxx> Sanitizers are based on compile-time instrumentation. They are available in gcc and clang for a range of supported operation systems and platforms. More info at: https://github.com/google/sanitizers The address sanitizer finds bugs related to addressing memory: use after free, heap buffer overflow, stack buffer overflow, memory leaks, ... The undefined behavior sanitizer detects situations not prescribed by the language specification: bound violations, data overflows, ... The llvm.org states that Sanitizers have found thousands of bugs everywhere. Sanitizers running during CI can prevent bugs from taking up residence. They are helper tools to maintain bugs out. --- * Harmless (the new flags are disabled by default) * Real example of it working: Direct leak of 1432 byte(s) in 1 object(s) allocated from: #0 0x4cea00 in calloc /home/ben/development/llvm/3.5/final/llvm.src/projects/compiler-rt/lib/asan/asan_malloc_linux.cc:56:3 #1 0x2b0459e834a6 in virAlloc /home/travis/build/claudioandre/libvirt/src/util/viralloc.c:144:24 #2 0x2b045a010af4 in virDomainDefNew /home/travis/build/claudioandre/libvirt/src/conf/domain_conf.c:2923:9 #3 0x2b045a010af4 in virDomainDefParseXML /home/travis/build/claudioandre/libvirt/src/conf/domain_conf.c:16923 #4 0x2b045a0106a1 in virDomainDefParseNode /home/travis/build/claudioandre/libvirt/src/conf/domain_conf.c:18764:11 #5 0x2b045a0105ba in virDomainDefParse /home/travis/build/claudioandre/libvirt/src/conf/domain_conf.c:18708:15 #6 0x4ec396 in testCompareMemLock /home/travis/build/claudioandre/libvirt/tests/qemumemlocktest.c:45:17 #7 0x4ede56 in virTestRun /home/travis/build/claudioandre/libvirt/tests/testutils.c:180:11 #8 0x4ec194 in mymain /home/travis/build/claudioandre/libvirt/tests/qemumemlocktest.c:119:5 #9 0x4f0f9c in virTestMain /home/travis/build/claudioandre/libvirt/tests/testutils.c:1019:11 #10 0x2b045b221f44 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21f44) m4/virt-compile-warnings.m4 | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/m4/virt-compile-warnings.m4 b/m4/virt-compile-warnings.m4 index 768a5c8..269f14d 100644 --- a/m4/virt-compile-warnings.m4 +++ b/m4/virt-compile-warnings.m4 @@ -166,12 +166,6 @@ AC_DEFUN([LIBVIRT_COMPILE_WARNINGS],[ wantwarn="$wantwarn -Wno-format" fi - # This should be < 256 really. Currently we're down to 4096, - # but using 1024 bytes sized buffers (mostly for virStrerror) - # stops us from going down further - gl_WARN_ADD(["-Wframe-larger-than=4096"], [STRICT_FRAME_LIMIT_CFLAGS]) - gl_WARN_ADD(["-Wframe-larger-than=25600"], [RELAXED_FRAME_LIMIT_CFLAGS]) - # Extra special flags dnl -fstack-protector stuff passes gl_WARN_ADD with gcc dnl on Mingw32, but fails when actually used @@ -259,4 +253,33 @@ AC_DEFUN([LIBVIRT_COMPILE_WARNINGS],[ AC_DEFINE_UNQUOTED([BROKEN_GCC_WLOGICALOP_EQUAL_EXPR], 1, [Define to 1 if gcc -Wlogical-op reports false positive 'or' equal expr]) fi + + dnl Check for support for Sanitizers + dnl Check for -fsanitize=address and -fsanitize=undefined support + LIBVIRT_ARG_ENABLE([ASAN], [build with address sanitizer support], [no]) + SAN_CFLAGS= + + AS_IF([test "x$enable_asan" = "xyes"], [ + gl_COMPILER_OPTION_IF([-fsanitize=address -fno-omit-frame-pointer], [ + SAN_CFLAGS="-fsanitize=address" + ]) + ]) + + LIBVIRT_ARG_ENABLE([UBSAN], [build with undefined behavior sanitizer support], [no]) + AS_IF([test "x$enable_ubsan" = "xyes"], [ + gl_COMPILER_OPTION_IF([-fsanitize=undefined -fno-omit-frame-pointer], [ + SAN_CFLAGS="$SAN_CFLAGS -fsanitize=undefined" + ]) + ]) + + AS_IF([ test -n "${SAN_CFLAGS}"], [ + gl_AS_VAR_APPEND([WARN_CFLAGS], [" $SAN_CFLAGS -fno-omit-frame-pointer"]) + gl_AS_VAR_APPEND([LDFLAGS], [" $SAN_CFLAGS -ldl"]) + ],[ + # This should be < 256 really. Currently we're down to 4096, + # but using 1024 bytes sized buffers (mostly for virStrerror) + # stops us from going down further + gl_WARN_ADD(["-Wframe-larger-than=4096"], [STRICT_FRAME_LIMIT_CFLAGS]) + gl_WARN_ADD(["-Wframe-larger-than=25600"], [RELAXED_FRAME_LIMIT_CFLAGS]) + ]) ]) -- 2.11.0 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list