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