1 //===--- SanitizerArgs.h - Arguments for sanitizer tools -------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
8 #ifndef LLVM_CLANG_DRIVER_SANITIZERARGS_H
9 #define LLVM_CLANG_DRIVER_SANITIZERARGS_H
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 "llvm/Transforms/Instrumentation/AddressSanitizerOptions.h"
25 SanitizerSet Sanitizers;
26 SanitizerSet RecoverableSanitizers;
27 SanitizerSet TrapSanitizers;
29 std::vector<std::string> UserIgnorelistFiles;
30 std::vector<std::string> SystemIgnorelistFiles;
31 std::vector<std::string> CoverageAllowlistFiles;
32 std::vector<std::string> CoverageIgnorelistFiles;
33 std::vector<std::string> BinaryMetadataIgnorelistFiles;
34 int CoverageFeatures = 0;
35 int BinaryMetadataFeatures = 0;
36 int MsanTrackOrigins = 0;
37 bool MsanUseAfterDtor = true;
38 bool MsanParamRetval = true;
39 bool CfiCrossDso = false;
40 bool CfiICallGeneralizePointers = false;
41 bool CfiICallNormalizeIntegers = false;
42 bool CfiCanonicalJumpTables = false;
43 int AsanFieldPadding = 0;
44 bool SharedRuntime = false;
45 bool StableABI = false;
46 bool AsanUseAfterScope = true;
47 bool AsanPoisonCustomArrayCookie = false;
48 bool AsanGlobalsDeadStripping = false;
49 bool AsanUseOdrIndicator = false;
50 bool AsanInvalidPointerCmp = false;
51 bool AsanInvalidPointerSub = false;
52 bool AsanOutlineInstrumentation = false;
53 llvm::AsanDtorKind AsanDtorKind = llvm::AsanDtorKind::Invalid;
54 std::string HwasanAbi;
55 bool LinkRuntimes = true;
56 bool LinkCXXRuntimes = false;
58 bool SafeStackRuntime = false;
60 bool TsanMemoryAccess = true;
61 bool TsanFuncEntryExit = true;
62 bool TsanAtomics = true;
63 bool MinimalRuntime = false;
64 // True if cross-dso CFI support if provided by the system (i.e. Android).
65 bool ImplicitCfiRuntime = false;
66 bool NeedsMemProfRt = false;
67 bool HwasanUseAliases = false;
68 llvm::AsanDetectStackUseAfterReturnMode AsanUseAfterReturn =
69 llvm::AsanDetectStackUseAfterReturnMode::Invalid;
71 std::string MemtagMode;
74 /// Parses the sanitizer arguments from an argument list.
75 SanitizerArgs(const ToolChain &TC, const llvm::opt::ArgList &Args,
76 bool DiagnoseErrors = true);
78 bool needsSharedRt() const { return SharedRuntime; }
80 bool needsMemProfRt() const { return NeedsMemProfRt; }
81 bool needsAsanRt() const { return Sanitizers.has(SanitizerKind::Address); }
82 bool needsHwasanRt() const {
83 return Sanitizers.has(SanitizerKind::HWAddress);
85 bool needsHwasanAliasesRt() const {
86 return needsHwasanRt() && HwasanUseAliases;
88 bool needsTsanRt() const { return Sanitizers.has(SanitizerKind::Thread); }
89 bool needsMsanRt() const { return Sanitizers.has(SanitizerKind::Memory); }
90 bool needsFuzzer() const { return Sanitizers.has(SanitizerKind::Fuzzer); }
91 bool needsLsanRt() const {
92 return Sanitizers.has(SanitizerKind::Leak) &&
93 !Sanitizers.has(SanitizerKind::Address) &&
94 !Sanitizers.has(SanitizerKind::HWAddress);
96 bool needsFuzzerInterceptors() const;
97 bool needsUbsanRt() const;
98 bool requiresMinimalRuntime() const { return MinimalRuntime; }
99 bool needsDfsanRt() const { return Sanitizers.has(SanitizerKind::DataFlow); }
100 bool needsSafeStackRt() const { return SafeStackRuntime; }
101 bool needsCfiRt() const;
102 bool needsCfiDiagRt() const;
103 bool needsStatsRt() const { return Stats; }
104 bool needsScudoRt() const { return Sanitizers.has(SanitizerKind::Scudo); }
106 bool hasMemTag() const {
107 return hasMemtagHeap() || hasMemtagStack() || hasMemtagGlobals();
109 bool hasMemtagHeap() const {
110 return Sanitizers.has(SanitizerKind::MemtagHeap);
112 bool hasMemtagStack() const {
113 return Sanitizers.has(SanitizerKind::MemtagStack);
115 bool hasMemtagGlobals() const {
116 return Sanitizers.has(SanitizerKind::MemtagGlobals);
118 const std::string &getMemtagMode() const {
119 assert(!MemtagMode.empty());
123 bool hasShadowCallStack() const {
124 return Sanitizers.has(SanitizerKind::ShadowCallStack);
127 bool requiresPIE() const;
128 bool needsUnwindTables() const;
129 bool needsLTO() const;
130 bool linkRuntimes() const { return LinkRuntimes; }
131 bool linkCXXRuntimes() const { return LinkCXXRuntimes; }
132 bool hasCrossDsoCfi() const { return CfiCrossDso; }
133 bool hasAnySanitizer() const { return !Sanitizers.empty(); }
134 void addArgs(const ToolChain &TC, const llvm::opt::ArgList &Args,
135 llvm::opt::ArgStringList &CmdArgs, types::ID InputType) const;
138 } // namespace driver