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 bool TysanOutlineInstrumentation = true;
71 // True if cross-dso CFI support if provided by the system (i.e. Android).
72 bool ImplicitCfiRuntime = false;
73 bool NeedsMemProfRt = false;
74 bool HwasanUseAliases = false;
75 llvm::AsanDetectStackUseAfterReturnMode AsanUseAfterReturn =
76 llvm::AsanDetectStackUseAfterReturnMode::Invalid;
77
78 std::string MemtagMode;
79 bool AllocTokenFastABI = false;
80 bool AllocTokenExtended = false;
81
82public:
83 /// Parses the sanitizer arguments from an argument list.
84 SanitizerArgs(const ToolChain &TC, const llvm::opt::ArgList &Args,
85 bool DiagnoseErrors = true);
86
87 bool needsSharedRt() const { return SharedRuntime; }
88 bool needsStableAbi() const { return StableABI; }
89
90 bool needsMemProfRt() const { return NeedsMemProfRt; }
91 bool needsAsanRt() const { return Sanitizers.has(SanitizerKind::Address); }
92 bool needsHwasanRt() const {
93 return Sanitizers.has(SanitizerKind::HWAddress);
94 }
95 bool needsHwasanAliasesRt() const {
96 return needsHwasanRt() && HwasanUseAliases;
97 }
98 bool needsTysanRt() const { return Sanitizers.has(SanitizerKind::Type); }
99 bool needsTsanRt() const { return Sanitizers.has(SanitizerKind::Thread); }
100 bool needsMsanRt() const { return Sanitizers.has(SanitizerKind::Memory); }
101 bool needsFuzzer() const { return Sanitizers.has(SanitizerKind::Fuzzer); }
102 bool needsLsanRt() const {
103 return Sanitizers.has(SanitizerKind::Leak) &&
104 !Sanitizers.has(SanitizerKind::Address) &&
105 !Sanitizers.has(SanitizerKind::HWAddress);
106 }
107 bool needsFuzzerInterceptors() const;
108 bool needsUbsanRt() const;
109 bool needsUbsanCXXRt() const;
110 bool requiresMinimalRuntime() const { return MinimalRuntime; }
111 bool needsDfsanRt() const { return Sanitizers.has(SanitizerKind::DataFlow); }
112 bool needsSafeStackRt() const { return SafeStackRuntime; }
113 bool needsCfiCrossDsoRt() const;
114 bool needsCfiCrossDsoDiagRt() const;
115 bool needsStatsRt() const { return Stats; }
116 bool needsScudoRt() const { return Sanitizers.has(SanitizerKind::Scudo); }
117 bool needsNsanRt() const {
118 return Sanitizers.has(SanitizerKind::NumericalStability);
119 }
120 bool needsRtsanRt() const { return Sanitizers.has(SanitizerKind::Realtime); }
121
122 bool hasMemTag() const {
124 }
125 bool hasMemtagHeap() const {
126 return Sanitizers.has(SanitizerKind::MemtagHeap);
127 }
128 bool hasMemtagStack() const {
129 return Sanitizers.has(SanitizerKind::MemtagStack);
130 }
131 bool hasMemtagGlobals() const {
132 return Sanitizers.has(SanitizerKind::MemtagGlobals);
133 }
134 const std::string &getMemtagMode() const {
135 assert(!MemtagMode.empty());
136 return MemtagMode;
137 }
138
139 bool hasShadowCallStack() const {
140 return Sanitizers.has(SanitizerKind::ShadowCallStack);
141 }
142
143 bool requiresPIE() const;
144 bool needsUnwindTables() const;
145 bool needsLTO() const;
146 bool linkRuntimes() const { return LinkRuntimes; }
147 bool linkCXXRuntimes() const { return LinkCXXRuntimes; }
148 bool hasCrossDsoCfi() const { return CfiCrossDso; }
149 bool hasAnySanitizer() const { return !Sanitizers.empty(); }
150 void addArgs(const ToolChain &TC, const llvm::opt::ArgList &Args,
151 llvm::opt::ArgStringList &CmdArgs, types::ID InputType) const;
152};
153
154} // namespace driver
155} // namespace clang
156
157#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.