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 needsMsanRt() const { return Sanitizers.has(SanitizerKind::Memory); }
111 bool needsFuzzer() const { return Sanitizers.has(SanitizerKind::Fuzzer); }
112 bool needsLsanRt() const {
113 return Sanitizers.has(SanitizerKind::Leak) &&
114 !Sanitizers.has(SanitizerKind::Address) &&
115 !Sanitizers.has(SanitizerKind::HWAddress);
116 }
117 bool needsCopyProfRt() const { return NeedsCopyProfRt; }
118 bool needsFuzzerInterceptors() const;
119 bool needsUbsanRt() const;
120 bool needsUbsanCXXRt() const;
121 bool requiresMinimalRuntime() const { return MinimalRuntime; }
122 bool needsUbsanLoopDetectRt() const { return TrapLoop; }
123 bool needsDfsanRt() const { return Sanitizers.has(SanitizerKind::DataFlow); }
124 bool needsSafeStackRt() const { return SafeStackRuntime; }
125 bool needsCfiCrossDsoRt() const;
126 bool needsCfiCrossDsoDiagRt() const;
127 bool needsStatsRt() const { return Stats; }
128 bool needsScudoRt() const { return Sanitizers.has(SanitizerKind::Scudo); }
129 bool needsNsanRt() const {
130 return Sanitizers.has(SanitizerKind::NumericalStability);
131 }
132 bool needsRtsanRt() const { return Sanitizers.has(SanitizerKind::Realtime); }
133
134 bool hasMemTag() const {
136 }
137 bool hasMemtagHeap() const {
138 return Sanitizers.has(SanitizerKind::MemtagHeap);
139 }
140 bool hasMemtagStack() const {
141 return Sanitizers.has(SanitizerKind::MemtagStack);
142 }
143 bool hasMemtagGlobals() const {
144 return Sanitizers.has(SanitizerKind::MemtagGlobals);
145 }
146 const std::string &getMemtagMode() const {
147 assert(!MemtagMode.empty());
148 return MemtagMode;
149 }
150
151 bool hasShadowCallStack() const {
152 return Sanitizers.has(SanitizerKind::ShadowCallStack);
153 }
154
155 bool requiresPIE() const;
156 bool needsUnwindTables() const;
157 bool needsLTO() const;
158 bool linkRuntimes() const { return LinkRuntimes; }
159 bool linkCXXRuntimes() const { return LinkCXXRuntimes; }
160 bool hasCrossDsoCfi() const { return CfiCrossDso; }
161 bool hasAnySanitizer() const { return !Sanitizers.empty(); }
162 void addArgs(const ToolChain &TC, const llvm::opt::ArgList &Args,
163 llvm::opt::ArgStringList &CmdArgs, types::ID InputType) const;
164};
165
166} // namespace driver
167} // namespace clang
168
169#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.