clang  15.0.0git
SanitizerArgs.h
Go to the documentation of this file.
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 "llvm/Transforms/Instrumentation/AddressSanitizerOptions.h"
16 #include <string>
17 #include <vector>
18 
19 namespace clang {
20 namespace driver {
21 
22 class ToolChain;
23 
25  SanitizerSet Sanitizers;
26  SanitizerSet RecoverableSanitizers;
27  SanitizerSet TrapSanitizers;
28 
29  std::vector<std::string> UserIgnorelistFiles;
30  std::vector<std::string> SystemIgnorelistFiles;
31  std::vector<std::string> CoverageAllowlistFiles;
32  std::vector<std::string> CoverageIgnorelistFiles;
33  int CoverageFeatures = 0;
34  int MsanTrackOrigins = 0;
35  bool MsanUseAfterDtor = true;
36  bool MsanParamRetval = false;
37  bool CfiCrossDso = false;
38  bool CfiICallGeneralizePointers = false;
39  bool CfiCanonicalJumpTables = false;
40  int AsanFieldPadding = 0;
41  bool SharedRuntime = false;
42  bool AsanUseAfterScope = true;
43  bool AsanPoisonCustomArrayCookie = false;
44  bool AsanGlobalsDeadStripping = false;
45  bool AsanUseOdrIndicator = false;
46  bool AsanInvalidPointerCmp = false;
47  bool AsanInvalidPointerSub = false;
48  bool AsanOutlineInstrumentation = false;
49  llvm::AsanDtorKind AsanDtorKind = llvm::AsanDtorKind::Invalid;
50  std::string HwasanAbi;
51  bool LinkRuntimes = true;
52  bool LinkCXXRuntimes = false;
53  bool NeedPIE = false;
54  bool SafeStackRuntime = false;
55  bool Stats = false;
56  bool TsanMemoryAccess = true;
57  bool TsanFuncEntryExit = true;
58  bool TsanAtomics = true;
59  bool MinimalRuntime = false;
60  // True if cross-dso CFI support if provided by the system (i.e. Android).
61  bool ImplicitCfiRuntime = false;
62  bool NeedsMemProfRt = false;
63  bool HwasanUseAliases = false;
64  llvm::AsanDetectStackUseAfterReturnMode AsanUseAfterReturn =
66 
67  std::string MemtagMode;
68 
69 public:
70  /// Parses the sanitizer arguments from an argument list.
71  SanitizerArgs(const ToolChain &TC, const llvm::opt::ArgList &Args,
72  bool DiagnoseErrors = true);
73 
74  bool needsSharedRt() const { return SharedRuntime; }
75 
76  bool needsMemProfRt() const { return NeedsMemProfRt; }
77  bool needsAsanRt() const { return Sanitizers.has(SanitizerKind::Address); }
78  bool needsHwasanRt() const {
79  return Sanitizers.has(SanitizerKind::HWAddress);
80  }
81  bool needsHwasanAliasesRt() const {
82  return needsHwasanRt() && HwasanUseAliases;
83  }
84  bool needsTsanRt() const { return Sanitizers.has(SanitizerKind::Thread); }
85  bool needsMsanRt() const { return Sanitizers.has(SanitizerKind::Memory); }
86  bool needsFuzzer() const { return Sanitizers.has(SanitizerKind::Fuzzer); }
87  bool needsLsanRt() const {
88  return Sanitizers.has(SanitizerKind::Leak) &&
89  !Sanitizers.has(SanitizerKind::Address) &&
90  !Sanitizers.has(SanitizerKind::HWAddress);
91  }
92  bool needsFuzzerInterceptors() const;
93  bool needsUbsanRt() const;
94  bool requiresMinimalRuntime() const { return MinimalRuntime; }
95  bool needsDfsanRt() const { return Sanitizers.has(SanitizerKind::DataFlow); }
96  bool needsSafeStackRt() const { return SafeStackRuntime; }
97  bool needsCfiRt() const;
98  bool needsCfiDiagRt() const;
99  bool needsStatsRt() const { return Stats; }
100  bool needsScudoRt() const { return Sanitizers.has(SanitizerKind::Scudo); }
101 
102  bool hasMemTag() const {
103  return hasMemtagHeap() || hasMemtagStack() || hasMemtagGlobals();
104  }
105  bool hasMemtagHeap() const {
106  return Sanitizers.has(SanitizerKind::MemtagHeap);
107  }
108  bool hasMemtagStack() const {
109  return Sanitizers.has(SanitizerKind::MemtagStack);
110  }
111  bool hasMemtagGlobals() const {
112  return Sanitizers.has(SanitizerKind::MemtagGlobals);
113  }
114  const std::string &getMemtagMode() const {
115  assert(!MemtagMode.empty());
116  return MemtagMode;
117  }
118 
119  bool requiresPIE() const;
120  bool needsUnwindTables() const;
121  bool needsLTO() const;
122  bool linkRuntimes() const { return LinkRuntimes; }
123  bool linkCXXRuntimes() const { return LinkCXXRuntimes; }
124  bool hasCrossDsoCfi() const { return CfiCrossDso; }
125  bool hasAnySanitizer() const { return !Sanitizers.empty(); }
126  void addArgs(const ToolChain &TC, const llvm::opt::ArgList &Args,
127  llvm::opt::ArgStringList &CmdArgs, types::ID InputType) const;
128 };
129 
130 } // namespace driver
131 } // namespace clang
132 
133 #endif
clang::driver::SanitizerArgs::getMemtagMode
const std::string & getMemtagMode() const
Definition: SanitizerArgs.h:114
clang::driver::SanitizerArgs::needsUnwindTables
bool needsUnwindTables() const
Definition: SanitizerArgs.cpp:284
clang::driver::SanitizerArgs::hasCrossDsoCfi
bool hasCrossDsoCfi() const
Definition: SanitizerArgs.h:124
clang::driver::SanitizerArgs::SanitizerArgs
SanitizerArgs(const ToolChain &TC, const llvm::opt::ArgList &Args, bool DiagnoseErrors=true)
Parses the sanitizer arguments from an argument list.
Definition: SanitizerArgs.cpp:292
string
string(SUBSTRING ${CMAKE_CURRENT_BINARY_DIR} 0 ${PATH_LIB_START} PATH_HEAD) string(SUBSTRING $
Definition: CMakeLists.txt:22
clang::driver::SanitizerArgs::hasMemtagStack
bool hasMemtagStack() const
Definition: SanitizerArgs.h:108
clang::driver::SanitizerArgs::needsSafeStackRt
bool needsSafeStackRt() const
Definition: SanitizerArgs.h:96
clang::SanitizerSet::has
bool has(SanitizerMask K) const
Check if a certain (single) sanitizer is enabled.
Definition: Sanitizers.h:155
clang::driver::SanitizerArgs::needsTsanRt
bool needsTsanRt() const
Definition: SanitizerArgs.h:84
clang::driver::SanitizerArgs::needsHwasanRt
bool needsHwasanRt() const
Definition: SanitizerArgs.h:78
clang::driver::SanitizerArgs::requiresMinimalRuntime
bool requiresMinimalRuntime() const
Definition: SanitizerArgs.h:94
clang::driver::SanitizerArgs::requiresPIE
bool requiresPIE() const
Definition: SanitizerArgs.cpp:280
clang::driver::SanitizerArgs::linkRuntimes
bool linkRuntimes() const
Definition: SanitizerArgs.h:122
clang::SanitizerSet
Definition: Sanitizers.h:153
clang::driver::SanitizerArgs::addArgs
void addArgs(const ToolChain &TC, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs, types::ID InputType) const
Definition: SanitizerArgs.cpp:1028
clang::driver::SanitizerArgs::needsFuzzer
bool needsFuzzer() const
Definition: SanitizerArgs.h:86
clang::driver::SanitizerArgs::hasAnySanitizer
bool hasAnySanitizer() const
Definition: SanitizerArgs.h:125
clang::driver::SanitizerArgs::hasMemtagGlobals
bool hasMemtagGlobals() const
Definition: SanitizerArgs.h:111
clang::driver::SanitizerArgs::hasMemTag
bool hasMemTag() const
Definition: SanitizerArgs.h:102
clang::driver::SanitizerArgs::needsAsanRt
bool needsAsanRt() const
Definition: SanitizerArgs.h:77
clang::driver::SanitizerArgs::hasMemtagHeap
bool hasMemtagHeap() const
Definition: SanitizerArgs.h:105
clang::driver::SanitizerArgs::needsScudoRt
bool needsScudoRt() const
Definition: SanitizerArgs.h:100
clang::driver::SanitizerArgs::needsFuzzerInterceptors
bool needsFuzzerInterceptors() const
Definition: SanitizerArgs.cpp:255
clang::driver::SanitizerArgs
Definition: SanitizerArgs.h:24
clang::driver::SanitizerArgs::needsLTO
bool needsLTO() const
Definition: SanitizerArgs.cpp:288
clang::driver::SanitizerArgs::needsLsanRt
bool needsLsanRt() const
Definition: SanitizerArgs.h:87
clang::driver::SanitizerArgs::needsHwasanAliasesRt
bool needsHwasanAliasesRt() const
Definition: SanitizerArgs.h:81
clang::driver::ToolChain
ToolChain - Access to tools for a single platform.
Definition: ToolChain.h:91
clang::driver::SanitizerArgs::needsCfiRt
bool needsCfiRt() const
Definition: SanitizerArgs.cpp:270
clang::driver::SanitizerArgs::needsMemProfRt
bool needsMemProfRt() const
Definition: SanitizerArgs.h:76
clang::driver::SanitizerArgs::needsCfiDiagRt
bool needsCfiDiagRt() const
Definition: SanitizerArgs.cpp:275
clang::driver::types::ID
ID
Definition: Types.h:23
clang::SanitizerSet::empty
bool empty() const
Returns true if no sanitizers are enabled.
Definition: Sanitizers.h:173
Sanitizers.h
clang
Definition: CalledOnceCheck.h:17
clang::driver::SanitizerArgs::linkCXXRuntimes
bool linkCXXRuntimes() const
Definition: SanitizerArgs.h:123
clang::driver::SanitizerArgs::needsUbsanRt
bool needsUbsanRt() const
Definition: SanitizerArgs.cpp:259
Types.h
clang::driver::SanitizerArgs::needsDfsanRt
bool needsDfsanRt() const
Definition: SanitizerArgs.h:95
clang::driver::SanitizerArgs::needsSharedRt
bool needsSharedRt() const
Definition: SanitizerArgs.h:74
clang::driver::SanitizerArgs::needsStatsRt
bool needsStatsRt() const
Definition: SanitizerArgs.h:99
clang::RISCV::Invalid
@ Invalid
Definition: RISCVVIntrinsicUtils.h:148
clang::driver::SanitizerArgs::needsMsanRt
bool needsMsanRt() const
Definition: SanitizerArgs.h:85