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