From 25601fbac722b9af61ebaf69014e4b73517aaf94 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Thu, 24 May 2018 03:23:50 +0200 Subject: Add sanitize build/test option, currently ignored if gcc is not used --- backend/ninja/Ninja.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'backend') diff --git a/backend/ninja/Ninja.cpp b/backend/ninja/Ninja.cpp index 35922ee..c72c99f 100644 --- a/backend/ninja/Ninja.cpp +++ b/backend/ninja/Ninja.cpp @@ -722,12 +722,17 @@ namespace backend switch (config.getOptimizationLevel()) { case OPT_LEV_DEBUG: - result += " -g3 -D_FORTIFY_SOURCE=2 -D_GLIBCXX_ASSERTIONS -fasynchronous-unwind-tables -fsanitize=address -fsanitize=undefined "; + result += " -g3 -D_FORTIFY_SOURCE=2 -D_GLIBCXX_ASSERTIONS -fasynchronous-unwind-tables"; break; case OPT_LEV_RELEASE: result += " -g0"; break; } + + if(config.getSanitize()) + { + result += " -fno-omit-frame-pointer -fsanitize=address -fsanitize=undefined"; + } break; } case Compiler::MSVC: @@ -782,7 +787,10 @@ namespace backend case Compiler::GCC: { // TODO: Add flag to disable -ldl and -lm (dlopen, dlclose, floor, max, ...) - result += " LINK_ARGS = '-Wl,--no-undefined,--as-needed' -ldl -lm "; + result += " LINK_ARGS = '-Wl,--no-undefined,--as-needed'"; + if(config.getSanitize()) + result += " -lasan -lubsan"; + result += " -ldl -lm "; break; } case Compiler::MSVC: @@ -848,7 +856,10 @@ namespace backend result += ".so: " + buildJob + " "; result += join(objectNames, " "); result += "\n"; - result += " LINK_ARGS = '-Wl,--no-undefined,--as-needed' -ldl -lm "; + result += " LINK_ARGS = '-Wl,--no-undefined,--as-needed'"; + if(config.getSanitize()) + result += " -lasan -lubsan"; + result += " -ldl -lm "; projectGeneratedBinary += "lib" + config.getPackageName() + ".so"; break; } @@ -946,6 +957,7 @@ namespace backend FileType projectConfFileType = getFileType(projectConfFilePath.c_str()); SibsTestConfig sibsTestConfig(config.getCompiler(), testSourceDirNative, config.getOptimizationLevel()); + sibsTestConfig.setSanitize(config.getSanitize()); if(projectConfFileType == FileType::REGULAR) { Result result = Config::readFromFile(projectConfFilePath.c_str(), sibsTestConfig); -- cgit v1.2.3