clang 10.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
11 #include "clang/Basic/Sanitizers.h"
12 #include "clang/Driver/Types.h"
13 #include "llvm/Option/Arg.h"
14 #include "llvm/Option/ArgList.h"
15 #include <string>
16 #include <vector>
17
18 namespace clang {
19 namespace driver {
20
21 class ToolChain;
22
23 class SanitizerArgs {
24 SanitizerSet Sanitizers;
25 SanitizerSet RecoverableSanitizers;
26 SanitizerSet TrapSanitizers;
27
28 std::vector<std::string> UserBlacklistFiles;
29 std::vector<std::string> SystemBlacklistFiles;
30 int CoverageFeatures = 0;
31 int MsanTrackOrigins = 0;
32 bool MsanUseAfterDtor = true;
33 bool CfiCrossDso = false;
34 bool CfiICallGeneralizePointers = false;
35 bool CfiCanonicalJumpTables = false;
36 int AsanFieldPadding = 0;
37 bool SharedRuntime = false;
38 bool AsanUseAfterScope = true;
39 bool AsanPoisonCustomArrayCookie = false;
40 bool AsanGlobalsDeadStripping = false;
41 bool AsanUseOdrIndicator = false;
42 bool AsanInvalidPointerCmp = false;
43 bool AsanInvalidPointerSub = false;
44 std::string HwasanAbi;
45 bool LinkRuntimes = true;
46 bool LinkCXXRuntimes = false;
47 bool NeedPIE = false;
48 bool SafeStackRuntime = false;
49 bool Stats = false;
50 bool TsanMemoryAccess = true;
51 bool TsanFuncEntryExit = true;
52 bool TsanAtomics = true;
53 bool MinimalRuntime = false;
54 // True if cross-dso CFI support if provided by the system (i.e. Android).
55 bool ImplicitCfiRuntime = false;
56
57 public:
58 /// Parses the sanitizer arguments from an argument list.
59 SanitizerArgs(const ToolChain &TC, const llvm::opt::ArgList &Args);
60
61 bool needsSharedRt() const { return SharedRuntime; }
62
63 bool needsAsanRt() const { return Sanitizers.has(SanitizerKind::Address); }
64 bool needsHwasanRt() const {
65 return Sanitizers.has(SanitizerKind::HWAddress);
66 }
67 bool needsTsanRt() const { return Sanitizers.has(SanitizerKind::Thread); }
68 bool needsMsanRt() const { return Sanitizers.has(SanitizerKind::Memory); }
69 bool needsFuzzer() const { return Sanitizers.has(SanitizerKind::Fuzzer); }
70 bool needsLsanRt() const {
71 return Sanitizers.has(SanitizerKind::Leak) &&
72 !Sanitizers.has(SanitizerKind::Address) &&
73 !Sanitizers.has(SanitizerKind::HWAddress);
74 }
75 bool needsUbsanRt() const;
76 bool requiresMinimalRuntime() const { return MinimalRuntime; }
77 bool needsDfsanRt() const { return Sanitizers.has(SanitizerKind::DataFlow); }
78 bool needsSafeStackRt() const { return SafeStackRuntime; }
79 bool needsCfiRt() const;
80 bool needsCfiDiagRt() const;
81 bool needsStatsRt() const { return Stats; }
82 bool needsScudoRt() const { return Sanitizers.has(SanitizerKind::Scudo); }
83
84 bool requiresPIE() const;
85 bool needsUnwindTables() const;
86 bool needsLTO() const;
87 bool linkRuntimes() const { return LinkRuntimes; }
88 bool linkCXXRuntimes() const { return LinkCXXRuntimes; }
89 bool hasCrossDsoCfi() const { return CfiCrossDso; }
90 bool hasAnySanitizer() const { return !Sanitizers.empty(); }
91 void addArgs(const ToolChain &TC, const llvm::opt::ArgList &Args,
92 llvm::opt::ArgStringList &CmdArgs, types::ID InputType) const;
93 };
94
95 } // namespace driver
96 } // namespace clang
97
98 #endif
clang::driver::SanitizerArgs::needsStatsRt
bool needsStatsRt() const
Definition: SanitizerArgs.h:81
Types.h
clang::driver::SanitizerArgs::needsHwasanRt
bool needsHwasanRt() const
Definition: SanitizerArgs.h:64
clang::driver::SanitizerArgs::addArgs
void addArgs(const ToolChain &TC, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs, types::ID InputType) const
Definition: SanitizerArgs.cpp:894
clang::driver::SanitizerArgs::needsFuzzer
bool needsFuzzer() const
Definition: SanitizerArgs.h:69
clang::driver::types::ID
ID
Definition: Types.h:23
Sanitizers.h
Defines the clang::SanitizerKind enum.
clang::driver::SanitizerArgs::needsUbsanRt
bool needsUbsanRt() const
Definition: SanitizerArgs.cpp:208
clang::driver::SanitizerArgs::linkRuntimes
bool linkRuntimes() const
Definition: SanitizerArgs.h:87
clang::driver::SanitizerArgs::needsLsanRt
bool needsLsanRt() const
Definition: SanitizerArgs.h:70
clang::driver::SanitizerArgs
Definition: SanitizerArgs.h:23
clang::driver::SanitizerArgs::hasAnySanitizer
bool hasAnySanitizer() const
Definition: SanitizerArgs.h:90
clang::SanitizerSet
Definition: Sanitizers.h:151
clang::driver::SanitizerArgs::hasCrossDsoCfi
bool hasCrossDsoCfi() const
Definition: SanitizerArgs.h:89
clang::driver::SanitizerArgs::needsCfiDiagRt
bool needsCfiDiagRt() const
Definition: SanitizerArgs.cpp:224
clang::driver::SanitizerArgs::needsUnwindTables
bool needsUnwindTables() const
Definition: SanitizerArgs.cpp:233
clang::driver::SanitizerArgs::requiresMinimalRuntime
bool requiresMinimalRuntime() const
Definition: SanitizerArgs.h:76
clang::driver::SanitizerArgs::needsTsanRt
bool needsTsanRt() const
Definition: SanitizerArgs.h:67
clang::driver::SanitizerArgs::needsSafeStackRt
bool needsSafeStackRt() const
Definition: SanitizerArgs.h:78
clang::driver::SanitizerArgs::needsDfsanRt
bool needsDfsanRt() const
Definition: SanitizerArgs.h:77
clang::driver::SanitizerArgs::needsScudoRt
bool needsScudoRt() const
Definition: SanitizerArgs.h:82
clang::driver::SanitizerArgs::needsMsanRt
bool needsMsanRt() const
Definition: SanitizerArgs.h:68
clang
Dataflow Directional Tag Classes.
Definition: CFGReachabilityAnalysis.h:21
clang::SanitizerSet::empty
bool empty() const
Returns true if no sanitizers are enabled.
Definition: Sanitizers.h:171
clang::driver::SanitizerArgs::needsCfiRt
bool needsCfiRt() const
Definition: SanitizerArgs.cpp:219
clang::driver::SanitizerArgs::requiresPIE
bool requiresPIE() const
Definition: SanitizerArgs.cpp:229
clang::driver::SanitizerArgs::needsAsanRt
bool needsAsanRt() const
Definition: SanitizerArgs.h:63
clang::SanitizerSet::has
bool has(SanitizerMask K) const
Check if a certain (single) sanitizer is enabled.
Definition: Sanitizers.h:153
clang::driver::SanitizerArgs::needsSharedRt
bool needsSharedRt() const
Definition: SanitizerArgs.h:61
clang::driver::SanitizerArgs::SanitizerArgs
SanitizerArgs(const ToolChain &TC, const llvm::opt::ArgList &Args)
Parses the sanitizer arguments from an argument list.
Definition: SanitizerArgs.cpp:241
clang::driver::SanitizerArgs::needsLTO
bool needsLTO() const
Definition: SanitizerArgs.cpp:237
clang::driver::SanitizerArgs::linkCXXRuntimes
bool linkCXXRuntimes() const
Definition: SanitizerArgs.h:88
clang::driver::ToolChain
ToolChain - Access to tools for a single platform.
Definition: ToolChain.h:88