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