AddressSanitizer.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===--------- Definition of the AddressSanitizer class ---------*- 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. //
  14. // This file declares the AddressSanitizer class which is a port of the legacy
  15. // AddressSanitizer pass to use the new PassManager infrastructure.
  16. //
  17. //===----------------------------------------------------------------------===//
  18. #ifndef LLVM_TRANSFORMS_INSTRUMENTATION_ADDRESSSANITIZER_H
  19. #define LLVM_TRANSFORMS_INSTRUMENTATION_ADDRESSSANITIZER_H
  20. #include "llvm/IR/PassManager.h"
  21. #include "llvm/Transforms/Instrumentation/AddressSanitizerOptions.h"
  22. namespace llvm {
  23. class Module;
  24. class raw_ostream;
  25. struct AddressSanitizerOptions {
  26. bool CompileKernel = false;
  27. bool Recover = false;
  28. bool UseAfterScope = false;
  29. AsanDetectStackUseAfterReturnMode UseAfterReturn =
  30. AsanDetectStackUseAfterReturnMode::Runtime;
  31. };
  32. /// Public interface to the address sanitizer module pass for instrumenting code
  33. /// to check for various memory errors.
  34. ///
  35. /// This adds 'asan.module_ctor' to 'llvm.global_ctors'. This pass may also
  36. /// run intependently of the function address sanitizer.
  37. class AddressSanitizerPass : public PassInfoMixin<AddressSanitizerPass> {
  38. public:
  39. AddressSanitizerPass(const AddressSanitizerOptions &Options,
  40. bool UseGlobalGC = true, bool UseOdrIndicator = true,
  41. AsanDtorKind DestructorKind = AsanDtorKind::Global,
  42. AsanCtorKind ConstructorKind = AsanCtorKind::Global);
  43. PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
  44. void printPipeline(raw_ostream &OS,
  45. function_ref<StringRef(StringRef)> MapClassName2PassName);
  46. static bool isRequired() { return true; }
  47. private:
  48. AddressSanitizerOptions Options;
  49. bool UseGlobalGC;
  50. bool UseOdrIndicator;
  51. AsanDtorKind DestructorKind;
  52. AsanCtorKind ConstructorKind;
  53. };
  54. struct ASanAccessInfo {
  55. const int32_t Packed;
  56. const uint8_t AccessSizeIndex;
  57. const bool IsWrite;
  58. const bool CompileKernel;
  59. explicit ASanAccessInfo(int32_t Packed);
  60. ASanAccessInfo(bool IsWrite, bool CompileKernel, uint8_t AccessSizeIndex);
  61. };
  62. } // namespace llvm
  63. #endif
  64. #ifdef __GNUC__
  65. #pragma GCC diagnostic pop
  66. #endif