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