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 
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
void addArgs(const ToolChain &TC, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs, types::ID InputType) const
Defines the clang::SanitizerKind enum.
bool hasOneOf(SanitizerMask K) const
Check if one or more sanitizers are enabled.
Definition: Sanitizers.h:58
bool requiresMinimalRuntime() const
Definition: SanitizerArgs.h:71
Dataflow Directional Tag Classes.
bool empty() const
Returns true if no sanitizers are enabled.
Definition: Sanitizers.h:70
bool has(SanitizerMask K) const
Check if a certain (single) sanitizer is enabled.
Definition: Sanitizers.h:52
SanitizerArgs(const ToolChain &TC, const llvm::opt::ArgList &Args)
Parses the sanitizer arguments from an argument list.
ToolChain - Access to tools for a single platform.
Definition: ToolChain.h:89