clang 24.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
13#include "clang/Driver/Action.h"
14#include "clang/Driver/Types.h"
15#include "llvm/Option/Arg.h"
16#include "llvm/Option/ArgList.h"
17#include "llvm/Transforms/Instrumentation/AddressSanitizerOptions.h"
18#include <optional>
19#include <string>
20#include <vector>
21
22namespace clang {
23namespace driver {
24
25class ToolChain;
26
28 SanitizerSet Sanitizers;
29 SanitizerSet RecoverableSanitizers;
30 SanitizerSet TrapSanitizers;
31 SanitizerSet MergeHandlers;
32 SanitizerMaskCutoffs SkipHotCutoffs;
33 SanitizerSet AnnotateDebugInfo;
34 SanitizerSet SuppressUBSanFeature;
35
36 std::vector<std::string> UserIgnorelistFiles;
37 std::vector<std::string> SystemIgnorelistFiles;
38 std::vector<std::string> CoverageAllowlistFiles;
39 std::vector<std::string> CoverageIgnorelistFiles;
40 std::vector<std::string> BinaryMetadataIgnorelistFiles;
41 int CoverageFeatures = 0;
42 int CoverageStackDepthCallbackMin = 0;
43 int BinaryMetadataFeatures = 0;
44 int OverflowPatternExclusions = 0;
45 int MsanTrackOrigins = 0;
46 bool MsanUseAfterDtor = true;
47 bool MsanParamRetval = true;
48 bool CfiCrossDso = false;
49 bool CfiICallGeneralizePointers = false;
50 bool CfiICallNormalizeIntegers = false;
51 bool CfiCanonicalJumpTables = false;
52 bool KcfiArity = false;
53 std::optional<std::string> KcfiHash;
54 int AsanFieldPadding = 0;
55 bool SharedRuntime = false;
56 bool StableABI = false;
57 bool AsanUseAfterScope = true;
58 bool AsanPoisonCustomArrayCookie = false;
59 bool AsanGlobalsDeadStripping = false;
60 bool AsanUseOdrIndicator = false;
61 bool AsanInvalidPointerCmp = false;
62 bool AsanInvalidPointerSub = false;
63 bool AsanOutlineInstrumentation = false;
64 llvm::AsanDtorKind AsanDtorKind = llvm::AsanDtorKind::Invalid;
65 std::string HwasanAbi;
66 bool LinkRuntimes = true;
67 bool LinkCXXRuntimes = false;
68 bool NeedPIE = false;
69 bool SafeStackRuntime = false;
70 bool Stats = false;
71 bool TsanMemoryAccess = true;
72 bool TsanFuncEntryExit = true;
73 bool TsanAtomics = true;
74 bool MinimalRuntime = false;
75 bool TrapLoop = false;
76 bool TysanOutlineInstrumentation = true;
77 bool HandlerPreserveAllRegs = false;
78 // True if cross-dso CFI support if provided by the system (i.e. Android).
79 bool ImplicitCfiRuntime = false;
80 bool NeedsMemProfRt = false;
81 bool NeedsCopyProfRt = false;
82 bool HwasanUseAliases = false;
83 llvm::AsanDetectStackUseAfterReturnMode AsanUseAfterReturn =
84 llvm::AsanDetectStackUseAfterReturnMode::Invalid;
85
86 std::string MemtagMode;
87 bool AllocTokenFastABI = false;
88 bool AllocTokenExtended = false;
89
90public:
91 /// Parses the sanitizer arguments from an argument list.
92 SanitizerArgs(const ToolChain &TC, const llvm::opt::ArgList &Args,
93 bool DiagnoseErrors = true, bool DiagnoseBoundArchErrors = true,
94 BoundArch BA = {},
95 Action::OffloadKind DeviceOffloadKind = Action::OFK_None);
96
97 bool needsSharedRt() const { return SharedRuntime; }
98 bool needsStableAbi() const { return StableABI; }
99
100 bool needsMemProfRt() const { return NeedsMemProfRt; }
101 bool needsAsanRt() const { return Sanitizers.has(SanitizerKind::Address); }
102 bool needsHwasanRt() const {
103 return Sanitizers.has(SanitizerKind::HWAddress);
104 }
105 bool needsHwasanAliasesRt() const {
106 return needsHwasanRt() && HwasanUseAliases;
107 }
108 bool needsTysanRt() const { return Sanitizers.has(SanitizerKind::Type); }
109 bool needsTsanRt() const { return Sanitizers.has(SanitizerKind::Thread); }
110 bool needsCsanRt() const {
111 return Sanitizers.has(SanitizerKind::Concurrency);
112 }
113 bool needsMsanRt() const { return Sanitizers.has(SanitizerKind::Memory); }
114 bool needsFuzzer() const { return Sanitizers.has(SanitizerKind::Fuzzer); }
115 bool needsLsanRt() const {
116 return Sanitizers.has(SanitizerKind::Leak) &&
117 !Sanitizers.has(SanitizerKind::Address) &&
118 !Sanitizers.has(SanitizerKind::HWAddress);
119 }
120 bool needsCopyProfRt() const { return NeedsCopyProfRt; }
121 bool needsFuzzerInterceptors() const;
122 bool needsUbsanRt() const;
123 bool needsUbsanCXXRt() const;
124 bool requiresMinimalRuntime() const { return MinimalRuntime; }
125 bool needsUbsanLoopDetectRt() const { return TrapLoop; }
126 bool needsDfsanRt() const { return Sanitizers.has(SanitizerKind::DataFlow); }
127 bool needsSafeStackRt() const { return SafeStackRuntime; }
128 bool needsCfiCrossDsoRt() const;
129 bool needsCfiCrossDsoDiagRt() const;
130 bool needsStatsRt() const { return Stats; }
131 bool needsScudoRt() const { return Sanitizers.has(SanitizerKind::Scudo); }
132 bool needsNsanRt() const {
133 return Sanitizers.has(SanitizerKind::NumericalStability);
134 }
135 bool needsRtsanRt() const { return Sanitizers.has(SanitizerKind::Realtime); }
136
137 bool hasMemTag() const {
139 }
140 bool hasMemtagHeap() const {
141 return Sanitizers.has(SanitizerKind::MemtagHeap);
142 }
143 bool hasMemtagStack() const {
144 return Sanitizers.has(SanitizerKind::MemtagStack);
145 }
146 bool hasMemtagGlobals() const {
147 return Sanitizers.has(SanitizerKind::MemtagGlobals);
148 }
149 const std::string &getMemtagMode() const {
150 assert(!MemtagMode.empty());
151 return MemtagMode;
152 }
153
154 bool hasShadowCallStack() const {
155 return Sanitizers.has(SanitizerKind::ShadowCallStack);
156 }
157
158 bool requiresPIE() const;
159 bool needsUnwindTables() const;
160 bool needsLTO() const;
161 bool linkRuntimes() const { return LinkRuntimes; }
162 bool linkCXXRuntimes() const { return LinkCXXRuntimes; }
163 bool hasCrossDsoCfi() const { return CfiCrossDso; }
164 bool hasAnySanitizer() const { return !Sanitizers.empty(); }
165 void addArgs(const ToolChain &TC, const llvm::opt::ArgList &Args,
166 llvm::opt::ArgStringList &CmdArgs, types::ID InputType) const;
167};
168
169} // namespace driver
170} // namespace clang
171
172#endif
Defines the clang::SanitizerKind enum.
SanitizerArgs(const ToolChain &TC, const llvm::opt::ArgList &Args, bool DiagnoseErrors=true, bool DiagnoseBoundArchErrors=true, BoundArch BA={}, Action::OffloadKind DeviceOffloadKind=Action::OFK_None)
Parses the sanitizer arguments from an argument list.
const std::string & getMemtagMode() const
void addArgs(const ToolChain &TC, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs, types::ID InputType) const
ToolChain - Access to tools for a single platform.
Definition ToolChain.h:92
Top level wrappers for InstallAPI frontend operations.
Represents a bound architecture for offload / multiple architecture compilation.