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 19 namespace clang { 20 namespace driver { 21 22 class ToolChain; 23 24 class 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 = true; 34 bool CfiCrossDso = false; 35 bool CfiICallGeneralizePointers = false; 36 int AsanFieldPadding = 0; 37 bool SharedRuntime = false; 38 bool AsanUseAfterScope = true; 39 bool AsanPoisonCustomArrayCookie = false; 40 bool AsanGlobalsDeadStripping = false; 41 bool AsanUseOdrIndicator = false; 42 std::string HwasanAbi; 43 bool LinkCXXRuntimes = false; 44 bool NeedPIE = false; 45 bool SafeStackRuntime = false; 46 bool Stats = false; 47 bool TsanMemoryAccess = true; 48 bool TsanFuncEntryExit = true; 49 bool TsanAtomics = true; 50 bool MinimalRuntime = false; 51 // True if cross-dso CFI support if provided by the system (i.e. Android). 52 bool ImplicitCfiRuntime = false; 53 54 public: 55 /// Parses the sanitizer arguments from an argument list. 56 SanitizerArgs(const ToolChain &TC, const llvm::opt::ArgList &Args); 57 needsSharedRt()58 bool needsSharedRt() const { return SharedRuntime; } 59 needsAsanRt()60 bool needsAsanRt() const { return Sanitizers.has(SanitizerKind::Address); } needsHwasanRt()61 bool needsHwasanRt() const { return Sanitizers.has(SanitizerKind::HWAddress); } needsTsanRt()62 bool needsTsanRt() const { return Sanitizers.has(SanitizerKind::Thread); } needsMsanRt()63 bool needsMsanRt() const { return Sanitizers.has(SanitizerKind::Memory); } needsFuzzer()64 bool needsFuzzer() const { return Sanitizers.has(SanitizerKind::Fuzzer); } needsLsanRt()65 bool needsLsanRt() const { 66 return Sanitizers.has(SanitizerKind::Leak) && 67 !Sanitizers.has(SanitizerKind::Address) && 68 !Sanitizers.has(SanitizerKind::HWAddress); 69 } 70 bool needsUbsanRt() const; requiresMinimalRuntime()71 bool requiresMinimalRuntime() const { return MinimalRuntime; } needsDfsanRt()72 bool needsDfsanRt() const { return Sanitizers.has(SanitizerKind::DataFlow); } needsSafeStackRt()73 bool needsSafeStackRt() const { return SafeStackRuntime; } 74 bool needsCfiRt() const; 75 bool needsCfiDiagRt() const; needsStatsRt()76 bool needsStatsRt() const { return Stats; } needsEsanRt()77 bool needsEsanRt() const { 78 return Sanitizers.hasOneOf(SanitizerKind::Efficiency); 79 } needsScudoRt()80 bool needsScudoRt() const { return Sanitizers.has(SanitizerKind::Scudo); } 81 82 bool requiresPIE() const; 83 bool needsUnwindTables() const; 84 bool needsLTO() const; linkCXXRuntimes()85 bool linkCXXRuntimes() const { return LinkCXXRuntimes; } hasCrossDsoCfi()86 bool hasCrossDsoCfi() const { return CfiCrossDso; } hasAnySanitizer()87 bool hasAnySanitizer() const { return !Sanitizers.empty(); } 88 void addArgs(const ToolChain &TC, const llvm::opt::ArgList &Args, 89 llvm::opt::ArgStringList &CmdArgs, types::ID InputType) const; 90 }; 91 92 } // namespace driver 93 } // namespace clang 94 95 #endif 96