Subversion Repositories QNX 8.QNX8 LLVM/Clang compiler suite

Rev

Blame | Last modification | View Log | Download | RSS feed

  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 "llvm/Transforms/Instrumentation/AddressSanitizerOptions.h"
  16. #include <string>
  17. #include <vector>
  18.  
  19. namespace clang {
  20. namespace driver {
  21.  
  22. class ToolChain;
  23.  
  24. class SanitizerArgs {
  25.   SanitizerSet Sanitizers;
  26.   SanitizerSet RecoverableSanitizers;
  27.   SanitizerSet TrapSanitizers;
  28.  
  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.   int CoverageFeatures = 0;
  34.   int BinaryMetadataFeatures = 0;
  35.   int MsanTrackOrigins = 0;
  36.   bool MsanUseAfterDtor = true;
  37.   bool MsanParamRetval = true;
  38.   bool CfiCrossDso = false;
  39.   bool CfiICallGeneralizePointers = false;
  40.   bool CfiCanonicalJumpTables = false;
  41.   int AsanFieldPadding = 0;
  42.   bool SharedRuntime = false;
  43.   bool AsanUseAfterScope = true;
  44.   bool AsanPoisonCustomArrayCookie = false;
  45.   bool AsanGlobalsDeadStripping = false;
  46.   bool AsanUseOdrIndicator = false;
  47.   bool AsanInvalidPointerCmp = false;
  48.   bool AsanInvalidPointerSub = false;
  49.   bool AsanOutlineInstrumentation = false;
  50.   llvm::AsanDtorKind AsanDtorKind = llvm::AsanDtorKind::Invalid;
  51.   std::string HwasanAbi;
  52.   bool LinkRuntimes = true;
  53.   bool LinkCXXRuntimes = false;
  54.   bool NeedPIE = false;
  55.   bool SafeStackRuntime = false;
  56.   bool Stats = false;
  57.   bool TsanMemoryAccess = true;
  58.   bool TsanFuncEntryExit = true;
  59.   bool TsanAtomics = true;
  60.   bool MinimalRuntime = false;
  61.   // True if cross-dso CFI support if provided by the system (i.e. Android).
  62.   bool ImplicitCfiRuntime = false;
  63.   bool NeedsMemProfRt = false;
  64.   bool HwasanUseAliases = false;
  65.   llvm::AsanDetectStackUseAfterReturnMode AsanUseAfterReturn =
  66.       llvm::AsanDetectStackUseAfterReturnMode::Invalid;
  67.  
  68.   std::string MemtagMode;
  69.  
  70. public:
  71.   /// Parses the sanitizer arguments from an argument list.
  72.   SanitizerArgs(const ToolChain &TC, const llvm::opt::ArgList &Args,
  73.                 bool DiagnoseErrors = true);
  74.  
  75.   bool needsSharedRt() const { return SharedRuntime; }
  76.  
  77.   bool needsMemProfRt() const { return NeedsMemProfRt; }
  78.   bool needsAsanRt() const { return Sanitizers.has(SanitizerKind::Address); }
  79.   bool needsHwasanRt() const {
  80.     return Sanitizers.has(SanitizerKind::HWAddress);
  81.   }
  82.   bool needsHwasanAliasesRt() const {
  83.     return needsHwasanRt() && HwasanUseAliases;
  84.   }
  85.   bool needsTsanRt() const { return Sanitizers.has(SanitizerKind::Thread); }
  86.   bool needsMsanRt() const { return Sanitizers.has(SanitizerKind::Memory); }
  87.   bool needsFuzzer() const { return Sanitizers.has(SanitizerKind::Fuzzer); }
  88.   bool needsLsanRt() const {
  89.     return Sanitizers.has(SanitizerKind::Leak) &&
  90.            !Sanitizers.has(SanitizerKind::Address) &&
  91.            !Sanitizers.has(SanitizerKind::HWAddress);
  92.   }
  93.   bool needsFuzzerInterceptors() const;
  94.   bool needsUbsanRt() const;
  95.   bool requiresMinimalRuntime() const { return MinimalRuntime; }
  96.   bool needsDfsanRt() const { return Sanitizers.has(SanitizerKind::DataFlow); }
  97.   bool needsSafeStackRt() const { return SafeStackRuntime; }
  98.   bool needsCfiRt() const;
  99.   bool needsCfiDiagRt() const;
  100.   bool needsStatsRt() const { return Stats; }
  101.   bool needsScudoRt() const { return Sanitizers.has(SanitizerKind::Scudo); }
  102.  
  103.   bool hasMemTag() const {
  104.     return hasMemtagHeap() || hasMemtagStack() || hasMemtagGlobals();
  105.   }
  106.   bool hasMemtagHeap() const {
  107.     return Sanitizers.has(SanitizerKind::MemtagHeap);
  108.   }
  109.   bool hasMemtagStack() const {
  110.     return Sanitizers.has(SanitizerKind::MemtagStack);
  111.   }
  112.   bool hasMemtagGlobals() const {
  113.     return Sanitizers.has(SanitizerKind::MemtagGlobals);
  114.   }
  115.   const std::string &getMemtagMode() const {
  116.     assert(!MemtagMode.empty());
  117.     return MemtagMode;
  118.   }
  119.  
  120.   bool requiresPIE() const;
  121.   bool needsUnwindTables() const;
  122.   bool needsLTO() const;
  123.   bool linkRuntimes() const { return LinkRuntimes; }
  124.   bool linkCXXRuntimes() const { return LinkCXXRuntimes; }
  125.   bool hasCrossDsoCfi() const { return CfiCrossDso; }
  126.   bool hasAnySanitizer() const { return !Sanitizers.empty(); }
  127.   void addArgs(const ToolChain &TC, const llvm::opt::ArgList &Args,
  128.                llvm::opt::ArgStringList &CmdArgs, types::ID InputType) const;
  129. };
  130.  
  131. }  // namespace driver
  132. }  // namespace clang
  133.  
  134. #endif
  135.