clang 8.0.0

SanitizerArgs.h
Go to the documentation of this file.
1 //===--- SanitizerArgs.h - Arguments for sanitizer tools -------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_CLANG_DRIVER_SANITIZERARGS_H
10 #define LLVM_CLANG_DRIVER_SANITIZERARGS_H
11
12 #include "clang/Basic/Sanitizers.h"
13 #include "clang/Driver/Types.h"
14 #include "llvm/Option/Arg.h"
15 #include "llvm/Option/ArgList.h"
16 #include <string>
17 #include <vector>
18
19 namespace clang {
20 namespace driver {
21
22 class ToolChain;
23
24 class SanitizerArgs {
25 SanitizerSet Sanitizers;
26 SanitizerSet RecoverableSanitizers;
27 SanitizerSet TrapSanitizers;
28
29 std::vector<std::string> BlacklistFiles;
30 std::vector<std::string> ExtraDeps;
31 int CoverageFeatures = 0;
32 int MsanTrackOrigins = 0;
33 bool MsanUseAfterDtor = true;
34 bool CfiCrossDso = false;
35 bool CfiICallGeneralizePointers = 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 std::string HwasanAbi;
43 bool LinkCXXRuntimes = false;
44 bool NeedPIE = false;
45 bool SafeStackRuntime = false;
46 bool Stats = false;
47 bool TsanMemoryAccess = true;
48 bool TsanFuncEntryExit = true;
49 bool TsanAtomics = true;
50 bool MinimalRuntime = false;
51 // True if cross-dso CFI support if provided by the system (i.e. Android).
52 bool ImplicitCfiRuntime = false;
53
54 public:
55 /// Parses the sanitizer arguments from an argument list.
56 SanitizerArgs(const ToolChain &TC, const llvm::opt::ArgList &Args);
57
58 bool needsSharedRt() const { return SharedRuntime; }
59
60 bool needsAsanRt() const { return Sanitizers.has(SanitizerKind::Address); }
61 bool needsHwasanRt() const { return Sanitizers.has(SanitizerKind::HWAddress); }
62 bool needsTsanRt() const { return Sanitizers.has(SanitizerKind::Thread); }
63 bool needsMsanRt() const { return Sanitizers.has(SanitizerKind::Memory); }
64 bool needsFuzzer() const { return Sanitizers.has(SanitizerKind::Fuzzer); }
65 bool needsLsanRt() const {
66 return Sanitizers.has(SanitizerKind::Leak) &&
67 !Sanitizers.has(SanitizerKind::Address) &&
68 !Sanitizers.has(SanitizerKind::HWAddress);
69 }
70 bool needsUbsanRt() const;
71 bool requiresMinimalRuntime() const { return MinimalRuntime; }
72 bool needsDfsanRt() const { return Sanitizers.has(SanitizerKind::DataFlow); }
73 bool needsSafeStackRt() const { return SafeStackRuntime; }
74 bool needsCfiRt() const;
75 bool needsCfiDiagRt() const;
76 bool needsStatsRt() const { return Stats; }
77 bool needsEsanRt() const {
78 return Sanitizers.hasOneOf(SanitizerKind::Efficiency);
79 }
80 bool needsScudoRt() const { return Sanitizers.has(SanitizerKind::Scudo); }
81
82 bool requiresPIE() const;
83 bool needsUnwindTables() const;
84 bool needsLTO() const;
85 bool linkCXXRuntimes() const { return LinkCXXRuntimes; }
86 bool hasCrossDsoCfi() const { return CfiCrossDso; }
87 bool hasAnySanitizer() const { return !Sanitizers.empty(); }
88 void addArgs(const ToolChain &TC, const llvm::opt::ArgList &Args,
89 llvm::opt::ArgStringList &CmdArgs, types::ID InputType) const;
90 };
91
92 } // namespace driver
93 } // namespace clang
94
95 #endif
clang::driver::SanitizerArgs::needsStatsRt
bool needsStatsRt() const
Definition: SanitizerArgs.h:76
Types.h
clang::driver::SanitizerArgs::needsHwasanRt
bool needsHwasanRt() const
Definition: SanitizerArgs.h:61
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:801
clang::driver::SanitizerArgs::needsFuzzer
bool needsFuzzer() const
Definition: SanitizerArgs.h:64
clang::driver::types::ID
ID
Definition: Types.h:22
Sanitizers.h
Defines the clang::SanitizerKind enum.
clang::SanitizerSet::hasOneOf
bool hasOneOf(SanitizerMask K) const
Check if one or more sanitizers are enabled.
Definition: Sanitizers.h:58
clang::driver::SanitizerArgs::needsUbsanRt
bool needsUbsanRt() const
Definition: SanitizerArgs.cpp:181
clang::driver::SanitizerArgs::needsLsanRt
bool needsLsanRt() const
Definition: SanitizerArgs.h:65
clang::driver::SanitizerArgs::needsEsanRt
bool needsEsanRt() const
Definition: SanitizerArgs.h:77
clang::driver::SanitizerArgs
Definition: SanitizerArgs.h:24
clang::driver::SanitizerArgs::hasAnySanitizer
bool hasAnySanitizer() const
Definition: SanitizerArgs.h:87
clang::SanitizerSet
Definition: Sanitizers.h:50
clang::driver::SanitizerArgs::hasCrossDsoCfi
bool hasCrossDsoCfi() const
Definition: SanitizerArgs.h:86
clang::driver::SanitizerArgs::needsCfiDiagRt
bool needsCfiDiagRt() const
Definition: SanitizerArgs.cpp:197
clang::driver::SanitizerArgs::needsUnwindTables
bool needsUnwindTables() const
Definition: SanitizerArgs.cpp:206
clang::driver::SanitizerArgs::requiresMinimalRuntime
bool requiresMinimalRuntime() const
Definition: SanitizerArgs.h:71
clang::driver::SanitizerArgs::needsTsanRt
bool needsTsanRt() const
Definition: SanitizerArgs.h:62
clang::driver::SanitizerArgs::needsSafeStackRt
bool needsSafeStackRt() const
Definition: SanitizerArgs.h:73
clang::driver::SanitizerArgs::needsDfsanRt
bool needsDfsanRt() const
Definition: SanitizerArgs.h:72
clang::driver::SanitizerArgs::needsScudoRt
bool needsScudoRt() const
Definition: SanitizerArgs.h:80
clang::driver::SanitizerArgs::needsMsanRt
bool needsMsanRt() const
Definition: SanitizerArgs.h:63
clang
Dataflow Directional Tag Classes.
Definition: CFGReachabilityAnalysis.h:22
clang::SanitizerSet::empty
bool empty() const
Returns true if no sanitizers are enabled.
Definition: Sanitizers.h:70
clang::driver::SanitizerArgs::needsCfiRt
bool needsCfiRt() const
Definition: SanitizerArgs.cpp:192
clang::driver::SanitizerArgs::requiresPIE
bool requiresPIE() const
Definition: SanitizerArgs.cpp:202
clang::driver::SanitizerArgs::needsAsanRt
bool needsAsanRt() const
Definition: SanitizerArgs.h:60
clang::SanitizerSet::has
bool has(SanitizerMask K) const
Check if a certain (single) sanitizer is enabled.
Definition: Sanitizers.h:52
clang::driver::SanitizerArgs::needsSharedRt
bool needsSharedRt() const
Definition: SanitizerArgs.h:58
clang::driver::SanitizerArgs::SanitizerArgs
SanitizerArgs(const ToolChain &TC, const llvm::opt::ArgList &Args)
Parses the sanitizer arguments from an argument list.
Definition: SanitizerArgs.cpp:212
clang::driver::SanitizerArgs::needsLTO
bool needsLTO() const
Definition: SanitizerArgs.cpp:210
clang::driver::SanitizerArgs::linkCXXRuntimes
bool linkCXXRuntimes() const
Definition: SanitizerArgs.h:85
clang::driver::ToolChain
ToolChain - Access to tools for a single platform.
Definition: ToolChain.h:89