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 HwasanUseAliases = false;
82 llvm::AsanDetectStackUseAfterReturnMode AsanUseAfterReturn =
83 llvm::AsanDetectStackUseAfterReturnMode::Invalid;
84
85 std::string MemtagMode;
86 bool AllocTokenFastABI = false;
87 bool AllocTokenExtended = false;
88
89public:
90 /// Parses the sanitizer arguments from an argument list.
91 SanitizerArgs(const ToolChain &TC, const llvm::opt::ArgList &Args,
92 bool DiagnoseErrors = true, bool DiagnoseBoundArchErrors = true,
93 BoundArch BA = {},
94 Action::OffloadKind DeviceOffloadKind = Action::OFK_None);
95
96 bool needsSharedRt() const { return SharedRuntime; }
97 bool needsStableAbi() const { return StableABI; }
98
99 bool needsMemProfRt() const { return NeedsMemProfRt; }
100 bool needsAsanRt() const { return Sanitizers.has(SanitizerKind::Address); }
101 bool needsHwasanRt() const {
102 return Sanitizers.has(SanitizerKind::HWAddress);
103 }
104 bool needsHwasanAliasesRt() const {
105 return needsHwasanRt() && HwasanUseAliases;
106 }
107 bool needsTysanRt() const { return Sanitizers.has(SanitizerKind::Type); }
108 bool needsTsanRt() const { return Sanitizers.has(SanitizerKind::Thread); }
109 bool needsMsanRt() const { return Sanitizers.has(SanitizerKind::Memory); }
110 bool needsFuzzer() const { return Sanitizers.has(SanitizerKind::Fuzzer); }
111 bool needsLsanRt() const {
112 return Sanitizers.has(SanitizerKind::Leak) &&
113 !Sanitizers.has(SanitizerKind::Address) &&
114 !Sanitizers.has(SanitizerKind::HWAddress);
115 }
116 bool needsFuzzerInterceptors() const;
117 bool needsUbsanRt() const;
118 bool needsUbsanCXXRt() const;
119 bool requiresMinimalRuntime() const { return MinimalRuntime; }
120 bool needsUbsanLoopDetectRt() const { return TrapLoop; }
121 bool needsDfsanRt() const { return Sanitizers.has(SanitizerKind::DataFlow); }
122 bool needsSafeStackRt() const { return SafeStackRuntime; }
123 bool needsCfiCrossDsoRt() const;
124 bool needsCfiCrossDsoDiagRt() const;
125 bool needsStatsRt() const { return Stats; }
126 bool needsScudoRt() const { return Sanitizers.has(SanitizerKind::Scudo); }
127 bool needsNsanRt() const {
128 return Sanitizers.has(SanitizerKind::NumericalStability);
129 }
130 bool needsRtsanRt() const { return Sanitizers.has(SanitizerKind::Realtime); }
131
132 bool hasMemTag() const {
134 }
135 bool hasMemtagHeap() const {
136 return Sanitizers.has(SanitizerKind::MemtagHeap);
137 }
138 bool hasMemtagStack() const {
139 return Sanitizers.has(SanitizerKind::MemtagStack);
140 }
141 bool hasMemtagGlobals() const {
142 return Sanitizers.has(SanitizerKind::MemtagGlobals);
143 }
144 const std::string &getMemtagMode() const {
145 assert(!MemtagMode.empty());
146 return MemtagMode;
147 }
148
149 bool hasShadowCallStack() const {
150 return Sanitizers.has(SanitizerKind::ShadowCallStack);
151 }
152
153 bool requiresPIE() const;
154 bool needsUnwindTables() const;
155 bool needsLTO() const;
156 bool linkRuntimes() const { return LinkRuntimes; }
157 bool linkCXXRuntimes() const { return LinkCXXRuntimes; }
158 bool hasCrossDsoCfi() const { return CfiCrossDso; }
159 bool hasAnySanitizer() const { return !Sanitizers.empty(); }
160 void addArgs(const ToolChain &TC, const llvm::opt::ArgList &Args,
161 llvm::opt::ArgStringList &CmdArgs, types::ID InputType) const;
162};
163
164} // namespace driver
165} // namespace clang
166
167#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:96
Top level wrappers for InstallAPI frontend operations.
Represents a bound architecture for offload / multiple architecture compilation.