1 //===--- SanitizerArgs.h - Arguments for sanitizer tools -------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 #ifndef LLVM_CLANG_DRIVER_SANITIZERARGS_H 9 #define LLVM_CLANG_DRIVER_SANITIZERARGS_H 10 11 #include "clang/Basic/Sanitizers.h" 12 #include "clang/Driver/Types.h" 13 #include "llvm/Option/Arg.h" 14 #include "llvm/Option/ArgList.h" 15 #include <string> 16 #include <vector> 17 18 namespace clang { 19 namespace driver { 20 21 class ToolChain; 22 23 class SanitizerArgs { 24 SanitizerSet Sanitizers; 25 SanitizerSet RecoverableSanitizers; 26 SanitizerSet TrapSanitizers; 27 28 std::vector<std::string> UserBlacklistFiles; 29 std::vector<std::string> SystemBlacklistFiles; 30 std::vector<std::string> CoverageAllowlistFiles; 31 std::vector<std::string> CoverageBlocklistFiles; 32 int CoverageFeatures = 0; 33 int MsanTrackOrigins = 0; 34 bool MsanUseAfterDtor = true; 35 bool CfiCrossDso = false; 36 bool CfiICallGeneralizePointers = false; 37 bool CfiCanonicalJumpTables = false; 38 int AsanFieldPadding = 0; 39 bool SharedRuntime = false; 40 bool AsanUseAfterScope = true; 41 bool AsanPoisonCustomArrayCookie = false; 42 bool AsanGlobalsDeadStripping = false; 43 bool AsanUseOdrIndicator = false; 44 bool AsanInvalidPointerCmp = false; 45 bool AsanInvalidPointerSub = false; 46 std::string HwasanAbi; 47 bool LinkRuntimes = true; 48 bool LinkCXXRuntimes = false; 49 bool NeedPIE = false; 50 bool SafeStackRuntime = false; 51 bool Stats = false; 52 bool TsanMemoryAccess = true; 53 bool TsanFuncEntryExit = true; 54 bool TsanAtomics = true; 55 bool MinimalRuntime = false; 56 // True if cross-dso CFI support if provided by the system (i.e. Android). 57 bool ImplicitCfiRuntime = false; 58 59 public: 60 /// Parses the sanitizer arguments from an argument list. 61 SanitizerArgs(const ToolChain &TC, const llvm::opt::ArgList &Args); 62 63 bool needsSharedRt() const { return SharedRuntime; } 64 65 bool needsAsanRt() const { return Sanitizers.has(SanitizerKind::Address); } 66 bool needsHwasanRt() const { 67 return Sanitizers.has(SanitizerKind::HWAddress); 68 } 69 bool needsTsanRt() const { return Sanitizers.has(SanitizerKind::Thread); } 70 bool needsMsanRt() const { return Sanitizers.has(SanitizerKind::Memory); } 71 bool needsFuzzer() const { return Sanitizers.has(SanitizerKind::Fuzzer); } 72 bool needsLsanRt() const { 73 return Sanitizers.has(SanitizerKind::Leak) && 74 !Sanitizers.has(SanitizerKind::Address) && 75 !Sanitizers.has(SanitizerKind::HWAddress); 76 } 77 bool needsUbsanRt() const; 78 bool requiresMinimalRuntime() const { return MinimalRuntime; } 79 bool needsDfsanRt() const { return Sanitizers.has(SanitizerKind::DataFlow); } 80 bool needsSafeStackRt() const { return SafeStackRuntime; } 81 bool needsCfiRt() const; 82 bool needsCfiDiagRt() const; 83 bool needsStatsRt() const { return Stats; } 84 bool needsScudoRt() const { return Sanitizers.has(SanitizerKind::Scudo); } 85 86 bool requiresPIE() const; 87 bool needsUnwindTables() const; 88 bool needsLTO() const; 89 bool linkRuntimes() const { return LinkRuntimes; } 90 bool linkCXXRuntimes() const { return LinkCXXRuntimes; } 91 bool hasCrossDsoCfi() const { return CfiCrossDso; } 92 bool hasAnySanitizer() const { return !Sanitizers.empty(); } 93 void addArgs(const ToolChain &TC, const llvm::opt::ArgList &Args, 94 llvm::opt::ArgStringList &CmdArgs, types::ID InputType) const; 95 }; 96 97 } // namespace driver 98 } // namespace clang 99 100 #endif 101