SanitizerArgs.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===--- SanitizerArgs.h - Arguments for sanitizer tools -------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_CLANG_DRIVER_SANITIZERARGS_H
  14. #define LLVM_CLANG_DRIVER_SANITIZERARGS_H
  15. #include "clang/Basic/Sanitizers.h"
  16. #include "clang/Driver/Types.h"
  17. #include "llvm/Option/Arg.h"
  18. #include "llvm/Option/ArgList.h"
  19. #include "llvm/Transforms/Instrumentation/AddressSanitizerOptions.h"
  20. #include <string>
  21. #include <vector>
  22. namespace clang {
  23. namespace driver {
  24. class ToolChain;
  25. class SanitizerArgs {
  26. SanitizerSet Sanitizers;
  27. SanitizerSet RecoverableSanitizers;
  28. 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. int CoverageFeatures = 0;
  34. int MsanTrackOrigins = 0;
  35. bool MsanUseAfterDtor = true;
  36. bool MsanParamRetval = false;
  37. bool CfiCrossDso = false;
  38. bool CfiICallGeneralizePointers = false;
  39. bool CfiCanonicalJumpTables = false;
  40. int AsanFieldPadding = 0;
  41. bool SharedRuntime = false;
  42. bool AsanUseAfterScope = true;
  43. bool AsanPoisonCustomArrayCookie = false;
  44. bool AsanGlobalsDeadStripping = false;
  45. bool AsanUseOdrIndicator = false;
  46. bool AsanInvalidPointerCmp = false;
  47. bool AsanInvalidPointerSub = false;
  48. bool AsanOutlineInstrumentation = false;
  49. llvm::AsanDtorKind AsanDtorKind = llvm::AsanDtorKind::Invalid;
  50. std::string HwasanAbi;
  51. bool LinkRuntimes = true;
  52. bool LinkCXXRuntimes = false;
  53. bool NeedPIE = false;
  54. bool SafeStackRuntime = false;
  55. bool Stats = false;
  56. bool TsanMemoryAccess = true;
  57. bool TsanFuncEntryExit = true;
  58. bool TsanAtomics = true;
  59. bool MinimalRuntime = false;
  60. // True if cross-dso CFI support if provided by the system (i.e. Android).
  61. bool ImplicitCfiRuntime = false;
  62. bool NeedsMemProfRt = false;
  63. bool HwasanUseAliases = false;
  64. llvm::AsanDetectStackUseAfterReturnMode AsanUseAfterReturn =
  65. llvm::AsanDetectStackUseAfterReturnMode::Invalid;
  66. public:
  67. /// Parses the sanitizer arguments from an argument list.
  68. SanitizerArgs(const ToolChain &TC, const llvm::opt::ArgList &Args,
  69. bool DiagnoseErrors = true);
  70. bool needsSharedRt() const { return SharedRuntime; }
  71. bool needsMemProfRt() const { return NeedsMemProfRt; }
  72. bool needsAsanRt() const { return Sanitizers.has(SanitizerKind::Address); }
  73. bool needsHwasanRt() const {
  74. return Sanitizers.has(SanitizerKind::HWAddress);
  75. }
  76. bool needsHwasanAliasesRt() const {
  77. return needsHwasanRt() && HwasanUseAliases;
  78. }
  79. bool needsTsanRt() const { return Sanitizers.has(SanitizerKind::Thread); }
  80. bool needsMsanRt() const { return Sanitizers.has(SanitizerKind::Memory); }
  81. bool needsFuzzer() const { return Sanitizers.has(SanitizerKind::Fuzzer); }
  82. bool needsLsanRt() const {
  83. return Sanitizers.has(SanitizerKind::Leak) &&
  84. !Sanitizers.has(SanitizerKind::Address) &&
  85. !Sanitizers.has(SanitizerKind::HWAddress);
  86. }
  87. bool needsFuzzerInterceptors() const;
  88. bool needsUbsanRt() const;
  89. bool requiresMinimalRuntime() const { return MinimalRuntime; }
  90. bool needsDfsanRt() const { return Sanitizers.has(SanitizerKind::DataFlow); }
  91. bool needsSafeStackRt() const { return SafeStackRuntime; }
  92. bool needsCfiRt() const;
  93. bool needsCfiDiagRt() const;
  94. bool needsStatsRt() const { return Stats; }
  95. bool needsScudoRt() const { return Sanitizers.has(SanitizerKind::Scudo); }
  96. bool requiresPIE() const;
  97. bool needsUnwindTables() const;
  98. bool needsLTO() const;
  99. bool linkRuntimes() const { return LinkRuntimes; }
  100. bool linkCXXRuntimes() const { return LinkCXXRuntimes; }
  101. bool hasCrossDsoCfi() const { return CfiCrossDso; }
  102. bool hasAnySanitizer() const { return !Sanitizers.empty(); }
  103. void addArgs(const ToolChain &TC, const llvm::opt::ArgList &Args,
  104. llvm::opt::ArgStringList &CmdArgs, types::ID InputType) const;
  105. };
  106. } // namespace driver
  107. } // namespace clang
  108. #endif
  109. #ifdef __GNUC__
  110. #pragma GCC diagnostic pop
  111. #endif