clang  9.0.0svn
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 
24  SanitizerSet Sanitizers;
25  SanitizerSet RecoverableSanitizers;
26  SanitizerSet TrapSanitizers;
27 
28  std::vector<std::string> BlacklistFiles;
29  std::vector<std::string> ExtraDeps;
30  int CoverageFeatures = 0;
31  int MsanTrackOrigins = 0;
32  bool MsanUseAfterDtor = true;
33  bool CfiCrossDso = false;
34  bool CfiICallGeneralizePointers = false;
35  int AsanFieldPadding = 0;
36  bool SharedRuntime = false;
37  bool AsanUseAfterScope = true;
38  bool AsanPoisonCustomArrayCookie = false;
39  bool AsanGlobalsDeadStripping = false;
40  bool AsanUseOdrIndicator = false;
41  std::string HwasanAbi;
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 needsLTO() const;
84  bool linkCXXRuntimes() const { return LinkCXXRuntimes; }
85  bool hasCrossDsoCfi() const { return CfiCrossDso; }
86  bool hasAnySanitizer() const { return !Sanitizers.empty(); }
87  void addArgs(const ToolChain &TC, const llvm::opt::ArgList &Args,
88  llvm::opt::ArgStringList &CmdArgs, types::ID InputType) const;
89 };
90 
91 } // namespace driver
92 } // namespace clang
93 
94 #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:57
bool requiresMinimalRuntime() const
Definition: SanitizerArgs.h:70
Dataflow Directional Tag Classes.
bool empty() const
Returns true if no sanitizers are enabled.
Definition: Sanitizers.h:69
bool has(SanitizerMask K) const
Check if a certain (single) sanitizer is enabled.
Definition: Sanitizers.h:51
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