From 444b5725b125e5154a571a1542cbb5a7ca58e29b Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sat, 4 Jul 2020 20:07:20 +0200 Subject: Fix sanitizers (and tests) by allowing to specify which sanitizer to use. Its not possible to use all of them at the same time --- src/CmakeModule.cpp | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) (limited to 'src/CmakeModule.cpp') diff --git a/src/CmakeModule.cpp b/src/CmakeModule.cpp index a690948..f57a8cf 100644 --- a/src/CmakeModule.cpp +++ b/src/CmakeModule.cpp @@ -74,6 +74,23 @@ namespace sibs string allLinkerFlags = ""; #endif + if(config.getCompiler() == Compiler::GCC || config.getCompiler() == Compiler::MINGW_W64) + { + switch(config.getSanitize()) { + case Sanitize::NONE: + break; + case Sanitize::ADDRESS: + allLinkerFlags += " -lasan"; + break; + case Sanitize::UNDEFINED: + allLinkerFlags += TINYDIR_STRING(" -lubsan"); + break; + case Sanitize::LEAK: + allLinkerFlags += TINYDIR_STRING(" -llsan"); + break; + } + } + #if 0 // TODO: Somehow check loading order, because it has to be correct to work.. Or does it for dynamic libraries? // Anyways it's required for static libraries (especially on Windows) @@ -180,9 +197,22 @@ namespace sibs FileString cflags = TINYDIR_STRING("-fPIC"); FileString cxxflags; - if(config.getCompiler() == Compiler::GCC && config.getSanitize()) + if(config.getCompiler() == Compiler::GCC || config.getCompiler() == Compiler::MINGW_W64) { - cflags += TINYDIR_STRING(" -fno-omit-frame-pointer -fsanitize=address -fsanitize=undefined -fsanitize=leak -lasan -lubsan -llsan"); + cflags += TINYDIR_STRING(" -fno-omit-frame-pointer"); + switch(config.getSanitize()) { + case Sanitize::NONE: + break; + case Sanitize::ADDRESS: + cflags += TINYDIR_STRING(" -fsanitize=address"); + break; + case Sanitize::UNDEFINED: + cflags += TINYDIR_STRING(" -fsanitize=undefined"); + break; + case Sanitize::LEAK: + cflags += TINYDIR_STRING(" -fsanitize=leak"); + break; + } } #if OS_FAMILY == OS_FAMILY_POSIX -- cgit v1.2.3