xref: /netbsd-src/external/apache2/llvm/dist/clang/include/clang/Driver/SanitizerArgs.h (revision e038c9c4676b0f19b1b7dd08a940c6ed64a6d5ae)
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> UserIgnorelistFiles;
29   std::vector<std::string> SystemIgnorelistFiles;
30   std::vector<std::string> CoverageAllowlistFiles;
31   std::vector<std::string> CoverageIgnorelistFiles;
32   int CoverageFeatures = 0;
33   int MsanTrackOrigins = 0;
34   bool MsanUseAfterDtor = true;
35   bool CfiCrossDso = false;
36   bool CfiICallGeneralizePointers = false;
37   bool CfiCanonicalJumpTables = false;
38   int AsanFieldPadding = 0;
39   bool SharedRuntime = false;
40   bool AsanUseAfterScope = true;
41   bool AsanPoisonCustomArrayCookie = false;
42   bool AsanGlobalsDeadStripping = false;
43   bool AsanUseOdrIndicator = false;
44   bool AsanInvalidPointerCmp = false;
45   bool AsanInvalidPointerSub = false;
46   llvm::AsanDtorKind AsanDtorKind = llvm::AsanDtorKind::Invalid;
47   std::string HwasanAbi;
48   bool LinkRuntimes = true;
49   bool LinkCXXRuntimes = false;
50   bool NeedPIE = false;
51   bool SafeStackRuntime = false;
52   bool Stats = false;
53   bool TsanMemoryAccess = true;
54   bool TsanFuncEntryExit = true;
55   bool TsanAtomics = true;
56   bool MinimalRuntime = false;
57   // True if cross-dso CFI support if provided by the system (i.e. Android).
58   bool ImplicitCfiRuntime = false;
59   bool NeedsMemProfRt = false;
60   bool HwasanUseAliases = false;
61 
62 public:
63   /// Parses the sanitizer arguments from an argument list.
64   SanitizerArgs(const ToolChain &TC, const llvm::opt::ArgList &Args);
65 
needsSharedRt()66   bool needsSharedRt() const { return SharedRuntime; }
67 
needsMemProfRt()68   bool needsMemProfRt() const { return NeedsMemProfRt; }
needsAsanRt()69   bool needsAsanRt() const { return Sanitizers.has(SanitizerKind::Address); }
needsHwasanRt()70   bool needsHwasanRt() const {
71     return Sanitizers.has(SanitizerKind::HWAddress);
72   }
needsHwasanAliasesRt()73   bool needsHwasanAliasesRt() const {
74     return needsHwasanRt() && HwasanUseAliases;
75   }
needsTsanRt()76   bool needsTsanRt() const { return Sanitizers.has(SanitizerKind::Thread); }
needsMsanRt()77   bool needsMsanRt() const { return Sanitizers.has(SanitizerKind::Memory); }
needsFuzzer()78   bool needsFuzzer() const { return Sanitizers.has(SanitizerKind::Fuzzer); }
needsLsanRt()79   bool needsLsanRt() const {
80     return Sanitizers.has(SanitizerKind::Leak) &&
81            !Sanitizers.has(SanitizerKind::Address) &&
82            !Sanitizers.has(SanitizerKind::HWAddress);
83   }
84   bool needsFuzzerInterceptors() const;
85   bool needsUbsanRt() const;
requiresMinimalRuntime()86   bool requiresMinimalRuntime() const { return MinimalRuntime; }
needsDfsanRt()87   bool needsDfsanRt() const { return Sanitizers.has(SanitizerKind::DataFlow); }
needsSafeStackRt()88   bool needsSafeStackRt() const { return SafeStackRuntime; }
89   bool needsCfiRt() const;
90   bool needsCfiDiagRt() const;
needsStatsRt()91   bool needsStatsRt() const { return Stats; }
needsScudoRt()92   bool needsScudoRt() const { return Sanitizers.has(SanitizerKind::Scudo); }
93 
94   bool requiresPIE() const;
95   bool needsUnwindTables() const;
96   bool needsLTO() const;
linkRuntimes()97   bool linkRuntimes() const { return LinkRuntimes; }
linkCXXRuntimes()98   bool linkCXXRuntimes() const { return LinkCXXRuntimes; }
hasCrossDsoCfi()99   bool hasCrossDsoCfi() const { return CfiCrossDso; }
hasAnySanitizer()100   bool hasAnySanitizer() const { return !Sanitizers.empty(); }
101   void addArgs(const ToolChain &TC, const llvm::opt::ArgList &Args,
102                llvm::opt::ArgStringList &CmdArgs, types::ID InputType) const;
103 };
104 
105 }  // namespace driver
106 }  // namespace clang
107 
108 #endif
109