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 bool NeedsMemProfRt = false; 59 60 public: 61 /// Parses the sanitizer arguments from an argument list. 62 SanitizerArgs(const ToolChain &TC, const llvm::opt::ArgList &Args); 63 needsSharedRt()64 bool needsSharedRt() const { return SharedRuntime; } 65 needsMemProfRt()66 bool needsMemProfRt() const { return NeedsMemProfRt; } needsAsanRt()67 bool needsAsanRt() const { return Sanitizers.has(SanitizerKind::Address); } needsHwasanRt()68 bool needsHwasanRt() const { 69 return Sanitizers.has(SanitizerKind::HWAddress); 70 } needsTsanRt()71 bool needsTsanRt() const { return Sanitizers.has(SanitizerKind::Thread); } needsMsanRt()72 bool needsMsanRt() const { return Sanitizers.has(SanitizerKind::Memory); } needsFuzzer()73 bool needsFuzzer() const { return Sanitizers.has(SanitizerKind::Fuzzer); } needsLsanRt()74 bool needsLsanRt() const { 75 return Sanitizers.has(SanitizerKind::Leak) && 76 !Sanitizers.has(SanitizerKind::Address) && 77 !Sanitizers.has(SanitizerKind::HWAddress); 78 } 79 bool needsFuzzerInterceptors() const; 80 bool needsUbsanRt() const; requiresMinimalRuntime()81 bool requiresMinimalRuntime() const { return MinimalRuntime; } needsDfsanRt()82 bool needsDfsanRt() const { return Sanitizers.has(SanitizerKind::DataFlow); } needsSafeStackRt()83 bool needsSafeStackRt() const { return SafeStackRuntime; } 84 bool needsCfiRt() const; 85 bool needsCfiDiagRt() const; needsStatsRt()86 bool needsStatsRt() const { return Stats; } needsScudoRt()87 bool needsScudoRt() const { return Sanitizers.has(SanitizerKind::Scudo); } 88 89 bool requiresPIE() const; 90 bool needsUnwindTables() const; 91 bool needsLTO() const; linkRuntimes()92 bool linkRuntimes() const { return LinkRuntimes; } linkCXXRuntimes()93 bool linkCXXRuntimes() const { return LinkCXXRuntimes; } hasCrossDsoCfi()94 bool hasCrossDsoCfi() const { return CfiCrossDso; } hasAnySanitizer()95 bool hasAnySanitizer() const { return !Sanitizers.empty(); } 96 void addArgs(const ToolChain &TC, const llvm::opt::ArgList &Args, 97 llvm::opt::ArgStringList &CmdArgs, types::ID InputType) const; 98 }; 99 100 } // namespace driver 101 } // namespace clang 102 103 #endif 104