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