Instrumentation.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. //===- Transforms/Instrumentation.h - Instrumentation passes ----*- C++ -*-===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This file defines constructor functions for instrumentation passes.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_TRANSFORMS_INSTRUMENTATION_H
  14. #define LLVM_TRANSFORMS_INSTRUMENTATION_H
  15. #include "llvm/ADT/StringRef.h"
  16. #include <vector>
  17. #if defined(__GNUC__) && defined(__linux__) && !defined(ANDROID)
  18. inline void *getDFSanArgTLSPtrForJIT() {
  19. extern __thread __attribute__((tls_model("initial-exec")))
  20. void *__dfsan_arg_tls;
  21. return (void *)&__dfsan_arg_tls;
  22. }
  23. inline void *getDFSanRetValTLSPtrForJIT() {
  24. extern __thread __attribute__((tls_model("initial-exec")))
  25. void *__dfsan_retval_tls;
  26. return (void *)&__dfsan_retval_tls;
  27. }
  28. #endif
  29. namespace llvm {
  30. class ModulePass;
  31. class FunctionPass;
  32. // Insert GCOV profiling instrumentation
  33. struct GCOVOptions {
  34. static GCOVOptions getDefault();
  35. // Specify whether to emit .gcno files.
  36. bool EmitNotes;
  37. // Specify whether to modify the program to emit .gcda files when run.
  38. bool EmitData;
  39. // A four-byte version string. The meaning of a version string is described in
  40. // gcc's gcov-io.h
  41. char Version[4];
  42. // Emit a "cfg checksum" that follows the "line number checksum" of a
  43. // function. This affects both .gcno and .gcda files.
  44. bool UseCfgChecksum;
  45. // Add the 'noredzone' attribute to added runtime library calls.
  46. bool NoRedZone;
  47. // Emit the name of the function in the .gcda files. This is redundant, as
  48. // the function identifier can be used to find the name from the .gcno file.
  49. bool FunctionNamesInData;
  50. // Emit the exit block immediately after the start block, rather than after
  51. // all of the function body's blocks.
  52. bool ExitBlockBeforeBody;
  53. };
  54. ModulePass *createGCOVProfilerPass(const GCOVOptions &Options =
  55. GCOVOptions::getDefault());
  56. /// Options for the frontend instrumentation based profiling pass.
  57. struct InstrProfOptions {
  58. InstrProfOptions() : NoRedZone(false) {}
  59. // Add the 'noredzone' attribute to added runtime library calls.
  60. bool NoRedZone;
  61. // Name of the profile file to use as output
  62. std::string InstrProfileOutput;
  63. };
  64. /// Insert frontend instrumentation based profiling.
  65. ModulePass *createInstrProfilingPass(
  66. const InstrProfOptions &Options = InstrProfOptions());
  67. // Insert AddressSanitizer (address sanity checking) instrumentation
  68. FunctionPass *createAddressSanitizerFunctionPass(bool CompileKernel = false);
  69. ModulePass *createAddressSanitizerModulePass(bool CompileKernel = false);
  70. // Insert MemorySanitizer instrumentation (detection of uninitialized reads)
  71. FunctionPass *createMemorySanitizerPass(int TrackOrigins = 0);
  72. // Insert ThreadSanitizer (race detection) instrumentation
  73. FunctionPass *createThreadSanitizerPass();
  74. // Insert DataFlowSanitizer (dynamic data flow analysis) instrumentation
  75. ModulePass *createDataFlowSanitizerPass(
  76. const std::vector<std::string> &ABIListFiles = std::vector<std::string>(),
  77. void *(*getArgTLS)() = nullptr, void *(*getRetValTLS)() = nullptr);
  78. // Options for sanitizer coverage instrumentation.
  79. struct SanitizerCoverageOptions {
  80. SanitizerCoverageOptions()
  81. : CoverageType(SCK_None), IndirectCalls(false), TraceBB(false),
  82. TraceCmp(false), Use8bitCounters(false) {}
  83. enum Type {
  84. SCK_None = 0,
  85. SCK_Function,
  86. SCK_BB,
  87. SCK_Edge
  88. } CoverageType;
  89. bool IndirectCalls;
  90. bool TraceBB;
  91. bool TraceCmp;
  92. bool Use8bitCounters;
  93. };
  94. // Insert SanitizerCoverage instrumentation.
  95. ModulePass *createSanitizerCoverageModulePass(
  96. const SanitizerCoverageOptions &Options = SanitizerCoverageOptions());
  97. #if defined(__GNUC__) && defined(__linux__) && !defined(ANDROID)
  98. inline ModulePass *createDataFlowSanitizerPassForJIT(
  99. const std::vector<std::string> &ABIListFiles = std::vector<std::string>()) {
  100. return createDataFlowSanitizerPass(ABIListFiles, getDFSanArgTLSPtrForJIT,
  101. getDFSanRetValTLSPtrForJIT);
  102. }
  103. #endif
  104. // BoundsChecking - This pass instruments the code to perform run-time bounds
  105. // checking on loads, stores, and other memory intrinsics.
  106. FunctionPass *createBoundsCheckingPass();
  107. /// \brief This pass splits the stack into a safe stack and an unsafe stack to
  108. /// protect against stack-based overflow vulnerabilities.
  109. FunctionPass *createSafeStackPass();
  110. } // End llvm namespace
  111. #endif