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 | |
23 | class SanitizerArgs { |
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 = 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 () 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 needsScudoRt() const { return Sanitizers.has(SanitizerKind::Scudo); } |
77 | |
78 | bool requiresPIE() const; |
79 | bool needsUnwindTables() const; |
80 | bool needsLTO() const; |
81 | bool linkCXXRuntimes() const { return LinkCXXRuntimes; } |
82 | bool hasCrossDsoCfi() const { return CfiCrossDso; } |
83 | bool hasAnySanitizer() const { return !Sanitizers.empty(); } |
84 | void addArgs(const ToolChain &TC, const llvm::opt::ArgList &Args, |
85 | llvm::opt::ArgStringList &CmdArgs, types::ID InputType) const; |
86 | }; |
87 | |
88 | } // namespace driver |
89 | } // namespace clang |
90 | |
91 | #endif |
92 |