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