LLVM  3.7.0
Instrumentation.h
Go to the documentation of this file.
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 
14 #ifndef LLVM_TRANSFORMS_INSTRUMENTATION_H
15 #define LLVM_TRANSFORMS_INSTRUMENTATION_H
16 
17 #include "llvm/ADT/StringRef.h"
18 #include <vector>
19 
20 #if defined(__GNUC__) && defined(__linux__) && !defined(ANDROID)
21 inline void *getDFSanArgTLSPtrForJIT() {
22  extern __thread __attribute__((tls_model("initial-exec")))
23  void *__dfsan_arg_tls;
24  return (void *)&__dfsan_arg_tls;
25 }
26 
27 inline void *getDFSanRetValTLSPtrForJIT() {
28  extern __thread __attribute__((tls_model("initial-exec")))
29  void *__dfsan_retval_tls;
30  return (void *)&__dfsan_retval_tls;
31 }
32 #endif
33 
34 namespace llvm {
35 
36 class ModulePass;
37 class FunctionPass;
38 
39 // Insert GCOV profiling instrumentation
40 struct GCOVOptions {
41  static GCOVOptions getDefault();
42 
43  // Specify whether to emit .gcno files.
44  bool EmitNotes;
45 
46  // Specify whether to modify the program to emit .gcda files when run.
47  bool EmitData;
48 
49  // A four-byte version string. The meaning of a version string is described in
50  // gcc's gcov-io.h
51  char Version[4];
52 
53  // Emit a "cfg checksum" that follows the "line number checksum" of a
54  // function. This affects both .gcno and .gcda files.
56 
57  // Add the 'noredzone' attribute to added runtime library calls.
58  bool NoRedZone;
59 
60  // Emit the name of the function in the .gcda files. This is redundant, as
61  // the function identifier can be used to find the name from the .gcno file.
63 
64  // Emit the exit block immediately after the start block, rather than after
65  // all of the function body's blocks.
67 };
70 
71 /// Options for the frontend instrumentation based profiling pass.
74 
75  // Add the 'noredzone' attribute to added runtime library calls.
76  bool NoRedZone;
77 
78  // Name of the profile file to use as output
79  std::string InstrProfileOutput;
80 };
81 
82 /// Insert frontend instrumentation based profiling.
84  const InstrProfOptions &Options = InstrProfOptions());
85 
86 // Insert AddressSanitizer (address sanity checking) instrumentation
87 FunctionPass *createAddressSanitizerFunctionPass(bool CompileKernel = false);
88 ModulePass *createAddressSanitizerModulePass(bool CompileKernel = false);
89 
90 // Insert MemorySanitizer instrumentation (detection of uninitialized reads)
91 FunctionPass *createMemorySanitizerPass(int TrackOrigins = 0);
92 
93 // Insert ThreadSanitizer (race detection) instrumentation
95 
96 // Insert DataFlowSanitizer (dynamic data flow analysis) instrumentation
98  const std::vector<std::string> &ABIListFiles = std::vector<std::string>(),
99  void *(*getArgTLS)() = nullptr, void *(*getRetValTLS)() = nullptr);
100 
101 // Options for sanitizer coverage instrumentation.
106 
107  enum Type {
108  SCK_None = 0,
112  } CoverageType;
114  bool TraceBB;
115  bool TraceCmp;
117 };
118 
119 // Insert SanitizerCoverage instrumentation.
122 
123 #if defined(__GNUC__) && defined(__linux__) && !defined(ANDROID)
124 inline ModulePass *createDataFlowSanitizerPassForJIT(
125  const std::vector<std::string> &ABIListFiles = std::vector<std::string>()) {
126  return createDataFlowSanitizerPass(ABIListFiles, getDFSanArgTLSPtrForJIT,
127  getDFSanRetValTLSPtrForJIT);
128 }
129 #endif
130 
131 // BoundsChecking - This pass instruments the code to perform run-time bounds
132 // checking on loads, stores, and other memory intrinsics.
133 FunctionPass *createBoundsCheckingPass();
134 
135 /// \brief This pass splits the stack into a safe stack and an unsafe stack to
136 /// protect against stack-based overflow vulnerabilities.
137 FunctionPass *createSafeStackPass();
138 
139 } // End llvm namespace
140 
141 #endif
GCOVOptions - A struct for passing gcov options between functions.
Definition: GCOV.h:37
FunctionPass * createBoundsCheckingPass()
static GCOVOptions getDefault()
FunctionPass * createSafeStackPass()
This pass splits the stack into a safe stack and an unsafe stack to protect against stack-based overf...
Definition: SafeStack.cpp:609
ModulePass * createGCOVProfilerPass(const GCOVOptions &Options=GCOVOptions::getDefault())
#define false
Definition: ConvertUTF.c:65
FunctionPass * createThreadSanitizerPass()
FunctionPass * createMemorySanitizerPass(int TrackOrigins=0)
always inline
ModulePass * createInstrProfilingPass(const InstrProfOptions &Options=InstrProfOptions())
Insert frontend instrumentation based profiling.
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:294
std::string InstrProfileOutput
enum llvm::SanitizerCoverageOptions::Type CoverageType
Options for the frontend instrumentation based profiling pass.
GCOVOptions(bool A, bool B, bool C, bool F, bool P, bool U, bool L, bool N)
Definition: GCOV.h:38
FunctionPass * createAddressSanitizerFunctionPass(bool CompileKernel=false)
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
Definition: Pass.h:236
__attribute__((weak)) dfsan_label dfsan_create_label(const char *desc
ModulePass * createDataFlowSanitizerPass(const std::vector< std::string > &ABIListFiles=std::vector< std::string >(), void *(*getArgTLS)()=nullptr, void *(*getRetValTLS)()=nullptr)
ModulePass * createSanitizerCoverageModulePass(const SanitizerCoverageOptions &Options=SanitizerCoverageOptions())
ModulePass * createAddressSanitizerModulePass(bool CompileKernel=false)