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