/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/include/clang/Driver/SanitizerArgs.h
Line | Count | Source (jump to first uncovered line) |
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 | | |
24 | | class SanitizerArgs { |
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 = |
65 | | llvm::AsanDetectStackUseAfterReturnMode::Invalid; |
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 | 14.6k | bool needsSharedRt() const { return SharedRuntime; } |
75 | | |
76 | 1.82k | bool needsMemProfRt() const { return NeedsMemProfRt; } |
77 | 23.0k | bool needsAsanRt() const { return Sanitizers.has(SanitizerKind::Address); } |
78 | 16.3k | bool needsHwasanRt() const { |
79 | 16.3k | return Sanitizers.has(SanitizerKind::HWAddress); |
80 | 16.3k | } |
81 | 25 | bool needsHwasanAliasesRt() const { |
82 | 25 | return needsHwasanRt() && HwasanUseAliases; |
83 | 25 | } |
84 | 65.1k | bool needsTsanRt() const { return Sanitizers.has(SanitizerKind::Thread); } |
85 | 16.2k | bool needsMsanRt() const { return Sanitizers.has(SanitizerKind::Memory); } |
86 | 6.02k | bool needsFuzzer() const { return Sanitizers.has(SanitizerKind::Fuzzer); } |
87 | 19.8k | bool needsLsanRt() const { |
88 | 19.8k | return Sanitizers.has(SanitizerKind::Leak) && |
89 | 19.8k | !Sanitizers.has(SanitizerKind::Address)78 && |
90 | 19.8k | !Sanitizers.has(SanitizerKind::HWAddress)73 ; |
91 | 19.8k | } |
92 | | bool needsFuzzerInterceptors() const; |
93 | | bool needsUbsanRt() const; |
94 | 208 | bool requiresMinimalRuntime() const { return MinimalRuntime; } |
95 | 16.0k | bool needsDfsanRt() const { return Sanitizers.has(SanitizerKind::DataFlow); } |
96 | 1.79k | bool needsSafeStackRt() const { return SafeStackRuntime; } |
97 | | bool needsCfiRt() const; |
98 | | bool needsCfiDiagRt() const; |
99 | 15.8k | bool needsStatsRt() const { return Stats; } |
100 | 16.0k | bool needsScudoRt() const { return Sanitizers.has(SanitizerKind::Scudo); } |
101 | | |
102 | 1.84k | bool hasMemTag() const { |
103 | 1.84k | return hasMemtagHeap() || hasMemtagStack()1.83k || hasMemtagGlobals()1.83k ; |
104 | 1.84k | } |
105 | 1.85k | bool hasMemtagHeap() const { |
106 | 1.85k | return Sanitizers.has(SanitizerKind::MemtagHeap); |
107 | 1.85k | } |
108 | 1.84k | bool hasMemtagStack() const { |
109 | 1.84k | return Sanitizers.has(SanitizerKind::MemtagStack); |
110 | 1.84k | } |
111 | 1.83k | bool hasMemtagGlobals() const { |
112 | 1.83k | return Sanitizers.has(SanitizerKind::MemtagGlobals); |
113 | 1.83k | } |
114 | 13 | const std::string &getMemtagMode() const { |
115 | 13 | assert(!MemtagMode.empty()); |
116 | 0 | return MemtagMode; |
117 | 13 | } |
118 | | |
119 | | bool requiresPIE() const; |
120 | | bool needsUnwindTables() const; |
121 | | bool needsLTO() const; |
122 | 384 | bool linkRuntimes() const { return LinkRuntimes; } |
123 | 271 | bool linkCXXRuntimes() const { return LinkCXXRuntimes; } |
124 | 1.84k | bool hasCrossDsoCfi() const { return CfiCrossDso; } |
125 | 196 | 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 |