aboutsummaryrefslogtreecommitdiff
path: root/backend/ninja
diff options
context:
space:
mode:
Diffstat (limited to 'backend/ninja')
-rw-r--r--backend/ninja/Ninja.cpp65
1 files changed, 39 insertions, 26 deletions
diff --git a/backend/ninja/Ninja.cpp b/backend/ninja/Ninja.cpp
index bacbd4c..48595bb 100644
--- a/backend/ninja/Ninja.cpp
+++ b/backend/ninja/Ninja.cpp
@@ -399,15 +399,34 @@ namespace backend
return Result<bool>::Ok(true);
}
- static vector<ninja::NinjaArg> getCompilerSanitizerFlags(const SibsConfig &config)
+ static ninja::NinjaArg getCompilerSanitizerFlag(const SibsConfig &config)
{
if(config.getCompiler() == Compiler::GCC || config.getCompiler() == Compiler::MINGW_W64)
{
- return {
- ninja::NinjaArg::createRaw("-fsanitize=address"),
- ninja::NinjaArg::createRaw("-fsanitize=undefined"),
- ninja::NinjaArg::createRaw("-fsanitize=leak")
- };
+ switch(config.getSanitize()) {
+ case Sanitize::NONE:
+ return {};
+ case Sanitize::ADDRESS:
+ return ninja::NinjaArg::createRaw("-fsanitize=address");
+ case Sanitize::UNDEFINED:
+ return ninja::NinjaArg::createRaw("-fsanitize=undefined");
+ case Sanitize::LEAK:
+ return ninja::NinjaArg::createRaw("-fsanitize=leak");
+ }
+ }
+ return {};
+ }
+
+ static ninja::NinjaArg getlinkerSanitizerFlags(const SibsConfig &config) {
+ switch(config.getSanitize()) {
+ case Sanitize::NONE:
+ return {};
+ case Sanitize::ADDRESS:
+ return ninja::NinjaArg::createRaw("-lasan");
+ case Sanitize::UNDEFINED:
+ return ninja::NinjaArg::createRaw("-lubsan");
+ case Sanitize::LEAK:
+ return ninja::NinjaArg::createRaw("-llsan");
}
return {};
}
@@ -749,9 +768,9 @@ namespace backend
if(compilerType == RuntimeCompilerType::NONE)
compilerType = cppCompilerType;
- bool sanitize = config.getSanitize();
+ Sanitize sanitize = config.getSanitize();
if(compilerType == RuntimeCompilerType::EMSCRIPTEN)
- sanitize = false;
+ sanitize = Sanitize::NONE;
Result<bool> createBuildDirResult = createDirectoryRecursive(savePath);
if (!createBuildDirResult)
@@ -1028,11 +1047,9 @@ namespace backend
vector<ninja::NinjaArg> optimizationFlags = getCompilerOptimizationFlags(config);
compileCCommand.insert(compileCCommand.end(), optimizationFlags.begin(), optimizationFlags.end());
- if(sanitize)
- {
- vector<ninja::NinjaArg> sanitizerFlags = getCompilerSanitizerFlags(config);
- compileCCommand.insert(compileCCommand.end(), sanitizerFlags.begin(), sanitizerFlags.end());
- }
+ ninja::NinjaArg sanitizerFlag = getCompilerSanitizerFlag(config);
+ if(sanitizerFlag.type != ninja::NinjaArg::Type::NONE)
+ compileCCommand.push_back(std::move(sanitizerFlag));
compileCppCommand = compileCCommand;
compileCppCommand[0] = ninja::NinjaArg::createRaw(cppCompilerName);
@@ -1082,11 +1099,9 @@ namespace backend
vector<ninja::NinjaArg> optimizationFlags = getCompilerOptimizationFlags(config);
compileCCommand.insert(compileCCommand.end(), optimizationFlags.begin(), optimizationFlags.end());
- if(sanitize)
- {
- vector<ninja::NinjaArg> sanitizerFlags = getCompilerSanitizerFlags(config);
- compileCCommand.insert(compileCCommand.end(), sanitizerFlags.begin(), sanitizerFlags.end());
- }
+ ninja::NinjaArg sanitizerFlag = getCompilerSanitizerFlag(config);
+ if(sanitizerFlag.type != ninja::NinjaArg::Type::NONE)
+ compileCCommand.push_back(std::move(sanitizerFlag));
compileCppCommand = compileCCommand;
compileCppCommand.push_back(ninja::NinjaArg("/EHs"));
@@ -1378,10 +1393,9 @@ namespace backend
if(!rpath.empty())
buildExeArgs.push_back(ninja::NinjaArg("-Wl,-rpath," + rpath));
- if(sanitize)
- {
- buildExeArgs.push_back(ninja::NinjaArg::createRaw("-lasan -lubsan -llsan"));
- }
+ ninja::NinjaArg sanitizeFlag = getlinkerSanitizerFlags(config);
+ if(sanitizeFlag.type != ninja::NinjaArg::Type::NONE)
+ buildExeArgs.push_back(std::move(sanitizeFlag));
else if(config.getOptimizationLevel() == OPT_LEV_RELEASE)
{
// Strip binary
@@ -1612,10 +1626,9 @@ namespace backend
buildDynamicArgs.push_back(ninja::NinjaArg::createRaw("-s SIDE_MODULE=1"));
}
- if(sanitize)
- {
- buildDynamicArgs.push_back(ninja::NinjaArg::createRaw("-lasan -lubsan -llsan"));
- }
+ ninja::NinjaArg sanitizeFlag = getlinkerSanitizerFlags(config);
+ if(sanitizeFlag.type != ninja::NinjaArg::Type::NONE)
+ buildDynamicArgs.push_back(std::move(sanitizeFlag));
if(config.getOptimizationLevel() == OPT_LEV_RELEASE)
{