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