1//===--- SanitizerArgs.h - Arguments for sanitizer tools -------*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9#ifndef LLVM_CLANG_DRIVER_SANITIZERARGS_H 10#define LLVM_CLANG_DRIVER_SANITIZERARGS_H 11 12#include "clang/Basic/Sanitizers.h" 13#include "clang/Driver/Types.h" 14#include "llvm/Option/Arg.h" 15#include "llvm/Option/ArgList.h" 16#include <string> 17#include <vector> 18 19namespace clang { 20namespace driver { 21 22class ToolChain; 23 24class SanitizerArgs { 25 SanitizerSet Sanitizers; 26 SanitizerSet RecoverableSanitizers; 27 SanitizerSet TrapSanitizers; 28 29 std::vector<std::string> BlacklistFiles; 30 std::vector<std::string> ExtraDeps; 31 int CoverageFeatures = 0; 32 int MsanTrackOrigins = 0; 33 bool MsanUseAfterDtor = false; 34 bool CfiCrossDso = false; 35 int AsanFieldPadding = 0; 36 bool SharedRuntime = false; 37 bool AsanUseAfterScope = true; 38 bool AsanGlobalsDeadStripping = false; 39 bool LinkCXXRuntimes = false; 40 bool NeedPIE = false; 41 bool SafeStackRuntime = false; 42 bool Stats = false; 43 bool TsanMemoryAccess = true; 44 bool TsanFuncEntryExit = true; 45 bool TsanAtomics = true; 46 bool MinimalRuntime = false; 47 // True if cross-dso CFI support if provided by the system (i.e. Android). 48 bool ImplicitCfiRuntime = false; 49 50 public: 51 /// Parses the sanitizer arguments from an argument list. 52 SanitizerArgs(const ToolChain &TC, const llvm::opt::ArgList &Args); 53 54 bool needsSharedRt() const { return SharedRuntime; } 55 56 bool needsAsanRt() const { return Sanitizers.has(SanitizerKind::Address); } 57 bool needsTsanRt() const { return Sanitizers.has(SanitizerKind::Thread); } 58 bool needsMsanRt() const { return Sanitizers.has(SanitizerKind::Memory); } 59 bool needsFuzzer() const { return Sanitizers.has(SanitizerKind::Fuzzer); } 60 bool needsLsanRt() const { 61 return Sanitizers.has(SanitizerKind::Leak) && 62 !Sanitizers.has(SanitizerKind::Address); 63 } 64 bool needsUbsanRt() const; 65 bool requiresMinimalRuntime() const { return MinimalRuntime; } 66 bool needsDfsanRt() const { return Sanitizers.has(SanitizerKind::DataFlow); } 67 bool needsSafeStackRt() const { return SafeStackRuntime; } 68 bool needsCfiRt() const; 69 bool needsCfiDiagRt() const; 70 bool needsStatsRt() const { return Stats; } 71 bool needsEsanRt() const { 72 return Sanitizers.hasOneOf(SanitizerKind::Efficiency); 73 } 74 75 bool requiresPIE() const; 76 bool needsUnwindTables() const; 77 bool linkCXXRuntimes() const { return LinkCXXRuntimes; } 78 bool hasCrossDsoCfi() const { return CfiCrossDso; } 79 void addArgs(const ToolChain &TC, const llvm::opt::ArgList &Args, 80 llvm::opt::ArgStringList &CmdArgs, types::ID InputType) const; 81}; 82 83} // namespace driver 84} // namespace clang 85 86#endif 87