Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:36:53

0001 //===--- SanitizerArgs.h - Arguments for sanitizer tools  -------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 #ifndef LLVM_CLANG_DRIVER_SANITIZERARGS_H
0009 #define LLVM_CLANG_DRIVER_SANITIZERARGS_H
0010 
0011 #include "clang/Basic/Sanitizers.h"
0012 #include "clang/Driver/Types.h"
0013 #include "llvm/Option/Arg.h"
0014 #include "llvm/Option/ArgList.h"
0015 #include "llvm/Transforms/Instrumentation/AddressSanitizerOptions.h"
0016 #include <string>
0017 #include <vector>
0018 
0019 namespace clang {
0020 namespace driver {
0021 
0022 class ToolChain;
0023 
0024 class SanitizerArgs {
0025   SanitizerSet Sanitizers;
0026   SanitizerSet RecoverableSanitizers;
0027   SanitizerSet TrapSanitizers;
0028   SanitizerSet MergeHandlers;
0029   SanitizerMaskCutoffs SkipHotCutoffs;
0030 
0031   std::vector<std::string> UserIgnorelistFiles;
0032   std::vector<std::string> SystemIgnorelistFiles;
0033   std::vector<std::string> CoverageAllowlistFiles;
0034   std::vector<std::string> CoverageIgnorelistFiles;
0035   std::vector<std::string> BinaryMetadataIgnorelistFiles;
0036   int CoverageFeatures = 0;
0037   int BinaryMetadataFeatures = 0;
0038   int OverflowPatternExclusions = 0;
0039   int MsanTrackOrigins = 0;
0040   bool MsanUseAfterDtor = true;
0041   bool MsanParamRetval = true;
0042   bool CfiCrossDso = false;
0043   bool CfiICallGeneralizePointers = false;
0044   bool CfiICallNormalizeIntegers = false;
0045   bool CfiCanonicalJumpTables = false;
0046   int AsanFieldPadding = 0;
0047   bool SharedRuntime = false;
0048   bool StableABI = false;
0049   bool AsanUseAfterScope = true;
0050   bool AsanPoisonCustomArrayCookie = false;
0051   bool AsanGlobalsDeadStripping = false;
0052   bool AsanUseOdrIndicator = false;
0053   bool AsanInvalidPointerCmp = false;
0054   bool AsanInvalidPointerSub = false;
0055   bool AsanOutlineInstrumentation = false;
0056   llvm::AsanDtorKind AsanDtorKind = llvm::AsanDtorKind::Invalid;
0057   std::string HwasanAbi;
0058   bool LinkRuntimes = true;
0059   bool LinkCXXRuntimes = false;
0060   bool NeedPIE = false;
0061   bool SafeStackRuntime = false;
0062   bool Stats = false;
0063   bool TsanMemoryAccess = true;
0064   bool TsanFuncEntryExit = true;
0065   bool TsanAtomics = true;
0066   bool MinimalRuntime = false;
0067   // True if cross-dso CFI support if provided by the system (i.e. Android).
0068   bool ImplicitCfiRuntime = false;
0069   bool NeedsMemProfRt = false;
0070   bool HwasanUseAliases = false;
0071   llvm::AsanDetectStackUseAfterReturnMode AsanUseAfterReturn =
0072       llvm::AsanDetectStackUseAfterReturnMode::Invalid;
0073 
0074   std::string MemtagMode;
0075 
0076 public:
0077   /// Parses the sanitizer arguments from an argument list.
0078   SanitizerArgs(const ToolChain &TC, const llvm::opt::ArgList &Args,
0079                 bool DiagnoseErrors = true);
0080 
0081   bool needsSharedRt() const { return SharedRuntime; }
0082   bool needsStableAbi() const { return StableABI; }
0083 
0084   bool needsMemProfRt() const { return NeedsMemProfRt; }
0085   bool needsAsanRt() const { return Sanitizers.has(SanitizerKind::Address); }
0086   bool needsHwasanRt() const {
0087     return Sanitizers.has(SanitizerKind::HWAddress);
0088   }
0089   bool needsHwasanAliasesRt() const {
0090     return needsHwasanRt() && HwasanUseAliases;
0091   }
0092   bool needsTysanRt() const { return Sanitizers.has(SanitizerKind::Type); }
0093   bool needsTsanRt() const { return Sanitizers.has(SanitizerKind::Thread); }
0094   bool needsMsanRt() const { return Sanitizers.has(SanitizerKind::Memory); }
0095   bool needsFuzzer() const { return Sanitizers.has(SanitizerKind::Fuzzer); }
0096   bool needsLsanRt() const {
0097     return Sanitizers.has(SanitizerKind::Leak) &&
0098            !Sanitizers.has(SanitizerKind::Address) &&
0099            !Sanitizers.has(SanitizerKind::HWAddress);
0100   }
0101   bool needsFuzzerInterceptors() const;
0102   bool needsUbsanRt() const;
0103   bool needsUbsanCXXRt() const;
0104   bool requiresMinimalRuntime() const { return MinimalRuntime; }
0105   bool needsDfsanRt() const { return Sanitizers.has(SanitizerKind::DataFlow); }
0106   bool needsSafeStackRt() const { return SafeStackRuntime; }
0107   bool needsCfiRt() const;
0108   bool needsCfiDiagRt() const;
0109   bool needsStatsRt() const { return Stats; }
0110   bool needsScudoRt() const { return Sanitizers.has(SanitizerKind::Scudo); }
0111   bool needsNsanRt() const {
0112     return Sanitizers.has(SanitizerKind::NumericalStability);
0113   }
0114   bool needsRtsanRt() const { return Sanitizers.has(SanitizerKind::Realtime); }
0115 
0116   bool hasMemTag() const {
0117     return hasMemtagHeap() || hasMemtagStack() || hasMemtagGlobals();
0118   }
0119   bool hasMemtagHeap() const {
0120     return Sanitizers.has(SanitizerKind::MemtagHeap);
0121   }
0122   bool hasMemtagStack() const {
0123     return Sanitizers.has(SanitizerKind::MemtagStack);
0124   }
0125   bool hasMemtagGlobals() const {
0126     return Sanitizers.has(SanitizerKind::MemtagGlobals);
0127   }
0128   const std::string &getMemtagMode() const {
0129     assert(!MemtagMode.empty());
0130     return MemtagMode;
0131   }
0132 
0133   bool hasShadowCallStack() const {
0134     return Sanitizers.has(SanitizerKind::ShadowCallStack);
0135   }
0136 
0137   bool requiresPIE() const;
0138   bool needsUnwindTables() const;
0139   bool needsLTO() const;
0140   bool linkRuntimes() const { return LinkRuntimes; }
0141   bool linkCXXRuntimes() const { return LinkCXXRuntimes; }
0142   bool hasCrossDsoCfi() const { return CfiCrossDso; }
0143   bool hasAnySanitizer() const { return !Sanitizers.empty(); }
0144   void addArgs(const ToolChain &TC, const llvm::opt::ArgList &Args,
0145                llvm::opt::ArgStringList &CmdArgs, types::ID InputType) const;
0146 };
0147 
0148 }  // namespace driver
0149 }  // namespace clang
0150 
0151 #endif