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"
24 SanitizerSet Sanitizers;
25 SanitizerSet RecoverableSanitizers;
26 SanitizerSet TrapSanitizers;
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 bool AsanInvalidPointerCmp = false;
42 bool AsanInvalidPointerSub = false;
43 std::string HwasanAbi;
44 bool LinkCXXRuntimes = false;
46 bool SafeStackRuntime = false;
48 bool TsanMemoryAccess = true;
49 bool TsanFuncEntryExit = true;
50 bool TsanAtomics = true;
51 bool MinimalRuntime = false;
52 // True if cross-dso CFI support if provided by the system (i.e. Android).
53 bool ImplicitCfiRuntime = false;
56 /// Parses the sanitizer arguments from an argument list.
57 SanitizerArgs(const ToolChain &TC, const llvm::opt::ArgList &Args);
59 bool needsSharedRt() const { return SharedRuntime; }
61 bool needsAsanRt() const { return Sanitizers.has(SanitizerKind::Address); }
62 bool needsHwasanRt() const { return Sanitizers.has(SanitizerKind::HWAddress); }
63 bool needsTsanRt() const { return Sanitizers.has(SanitizerKind::Thread); }
64 bool needsMsanRt() const { return Sanitizers.has(SanitizerKind::Memory); }
65 bool needsFuzzer() const { return Sanitizers.has(SanitizerKind::Fuzzer); }
66 bool needsLsanRt() const {
67 return Sanitizers.has(SanitizerKind::Leak) &&
68 !Sanitizers.has(SanitizerKind::Address) &&
69 !Sanitizers.has(SanitizerKind::HWAddress);
71 bool needsUbsanRt() const;
72 bool requiresMinimalRuntime() const { return MinimalRuntime; }
73 bool needsDfsanRt() const { return Sanitizers.has(SanitizerKind::DataFlow); }
74 bool needsSafeStackRt() const { return SafeStackRuntime; }
75 bool needsCfiRt() const;
76 bool needsCfiDiagRt() const;
77 bool needsStatsRt() const { return Stats; }
78 bool needsScudoRt() const { return Sanitizers.has(SanitizerKind::Scudo); }
80 bool requiresPIE() const;
81 bool needsUnwindTables() const;
82 bool needsLTO() const;
83 bool linkCXXRuntimes() const { return LinkCXXRuntimes; }
84 bool hasCrossDsoCfi() const { return CfiCrossDso; }
85 bool hasAnySanitizer() const { return !Sanitizers.empty(); }
86 void addArgs(const ToolChain &TC, const llvm::opt::ArgList &Args,
87 llvm::opt::ArgStringList &CmdArgs, types::ID InputType) const;