clang  6.0.0svn
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 = false;
34  bool CfiCrossDso = false;
35  bool CfiICallGeneralizePointers = false;
36  int AsanFieldPadding = 0;
37  bool SharedRuntime = false;
38  bool AsanUseAfterScope = true;
39  bool AsanGlobalsDeadStripping = false;
40  bool LinkCXXRuntimes = false;
41  bool NeedPIE = false;
42  bool SafeStackRuntime = false;
43  bool Stats = false;
44  bool TsanMemoryAccess = true;
45  bool TsanFuncEntryExit = true;
46  bool TsanAtomics = true;
47  bool MinimalRuntime = false;
48  // True if cross-dso CFI support if provided by the system (i.e. Android).
49  bool ImplicitCfiRuntime = false;
50 
51  public:
52  /// Parses the sanitizer arguments from an argument list.
53  SanitizerArgs(const ToolChain &TC, const llvm::opt::ArgList &Args);
54 
55  bool needsSharedRt() const { return SharedRuntime; }
56 
57  bool needsAsanRt() const { return Sanitizers.has(SanitizerKind::Address); }
58  bool needsHwasanRt() const { return Sanitizers.has(SanitizerKind::HWAddress); }
59  bool needsTsanRt() const { return Sanitizers.has(SanitizerKind::Thread); }
60  bool needsMsanRt() const { return Sanitizers.has(SanitizerKind::Memory); }
61  bool needsFuzzer() const { return Sanitizers.has(SanitizerKind::Fuzzer); }
62  bool needsLsanRt() const {
63  return Sanitizers.has(SanitizerKind::Leak) &&
64  !Sanitizers.has(SanitizerKind::Address) &&
65  !Sanitizers.has(SanitizerKind::HWAddress);
66  }
67  bool needsUbsanRt() const;
68  bool requiresMinimalRuntime() const { return MinimalRuntime; }
69  bool needsDfsanRt() const { return Sanitizers.has(SanitizerKind::DataFlow); }
70  bool needsSafeStackRt() const { return SafeStackRuntime; }
71  bool needsCfiRt() const;
72  bool needsCfiDiagRt() const;
73  bool needsStatsRt() const { return Stats; }
74  bool needsEsanRt() const {
75  return Sanitizers.hasOneOf(SanitizerKind::Efficiency);
76  }
77  bool needsScudoRt() const { return Sanitizers.has(SanitizerKind::Scudo); }
78 
79  bool requiresPIE() const;
80  bool needsUnwindTables() const;
81  bool linkCXXRuntimes() const { return LinkCXXRuntimes; }
82  bool hasCrossDsoCfi() const { return CfiCrossDso; }
83  void addArgs(const ToolChain &TC, const llvm::opt::ArgList &Args,
84  llvm::opt::ArgStringList &CmdArgs, types::ID InputType) const;
85 };
86 
87 } // namespace driver
88 } // namespace clang
89 
90 #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:56
bool requiresMinimalRuntime() const
Definition: SanitizerArgs.h:68
Dataflow Directional Tag Classes.
bool has(SanitizerMask K) const
Check if a certain (single) sanitizer is enabled.
Definition: Sanitizers.h:50
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:73