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