1 //===- Transforms/Instrumentation.h - Instrumentation passes ----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines constructor functions for instrumentation passes.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_TRANSFORMS_INSTRUMENTATION_H
15 #define LLVM_TRANSFORMS_INSTRUMENTATION_H
17 #include "llvm/ADT/StringRef.h"
18 #include "llvm/IR/BasicBlock.h"
21 #if defined(__GNUC__) && defined(__linux__) && !defined(ANDROID)
22 inline void *getDFSanArgTLSPtrForJIT() {
23 extern __thread __attribute__((tls_model("initial-exec")))
24 void *__dfsan_arg_tls;
25 return (void *)&__dfsan_arg_tls;
28 inline void *getDFSanRetValTLSPtrForJIT() {
29 extern __thread __attribute__((tls_model("initial-exec")))
30 void *__dfsan_retval_tls;
31 return (void *)&__dfsan_retval_tls;
37 /// Instrumentation passes often insert conditional checks into entry blocks.
38 /// Call this function before splitting the entry block to move instructions
39 /// that must remain in the entry block up before the split point. Static
40 /// allocas and llvm.localescape calls, for example, must remain in the entry
42 BasicBlock::iterator PrepareToSplitEntryBlock(BasicBlock &BB,
43 BasicBlock::iterator IP);
48 // Insert GCOV profiling instrumentation
50 static GCOVOptions getDefault();
52 // Specify whether to emit .gcno files.
55 // Specify whether to modify the program to emit .gcda files when run.
58 // A four-byte version string. The meaning of a version string is described in
62 // Emit a "cfg checksum" that follows the "line number checksum" of a
63 // function. This affects both .gcno and .gcda files.
66 // Add the 'noredzone' attribute to added runtime library calls.
69 // Emit the name of the function in the .gcda files. This is redundant, as
70 // the function identifier can be used to find the name from the .gcno file.
71 bool FunctionNamesInData;
73 // Emit the exit block immediately after the start block, rather than after
74 // all of the function body's blocks.
75 bool ExitBlockBeforeBody;
77 ModulePass *createGCOVProfilerPass(const GCOVOptions &Options =
78 GCOVOptions::getDefault());
80 /// Options for the frontend instrumentation based profiling pass.
81 struct InstrProfOptions {
82 InstrProfOptions() : NoRedZone(false) {}
84 // Add the 'noredzone' attribute to added runtime library calls.
87 // Name of the profile file to use as output
88 std::string InstrProfileOutput;
91 /// Insert frontend instrumentation based profiling.
92 ModulePass *createInstrProfilingPass(
93 const InstrProfOptions &Options = InstrProfOptions());
95 // Insert AddressSanitizer (address sanity checking) instrumentation
96 FunctionPass *createAddressSanitizerFunctionPass(bool CompileKernel = false);
97 ModulePass *createAddressSanitizerModulePass(bool CompileKernel = false);
99 // Insert MemorySanitizer instrumentation (detection of uninitialized reads)
100 FunctionPass *createMemorySanitizerPass(int TrackOrigins = 0);
102 // Insert ThreadSanitizer (race detection) instrumentation
103 FunctionPass *createThreadSanitizerPass();
105 // Insert DataFlowSanitizer (dynamic data flow analysis) instrumentation
106 ModulePass *createDataFlowSanitizerPass(
107 const std::vector<std::string> &ABIListFiles = std::vector<std::string>(),
108 void *(*getArgTLS)() = nullptr, void *(*getRetValTLS)() = nullptr);
110 // Options for sanitizer coverage instrumentation.
111 struct SanitizerCoverageOptions {
112 SanitizerCoverageOptions()
113 : CoverageType(SCK_None), IndirectCalls(false), TraceBB(false),
114 TraceCmp(false), Use8bitCounters(false) {}
125 bool Use8bitCounters;
128 // Insert SanitizerCoverage instrumentation.
129 ModulePass *createSanitizerCoverageModulePass(
130 const SanitizerCoverageOptions &Options = SanitizerCoverageOptions());
132 #if defined(__GNUC__) && defined(__linux__) && !defined(ANDROID)
133 inline ModulePass *createDataFlowSanitizerPassForJIT(
134 const std::vector<std::string> &ABIListFiles = std::vector<std::string>()) {
135 return createDataFlowSanitizerPass(ABIListFiles, getDFSanArgTLSPtrForJIT,
136 getDFSanRetValTLSPtrForJIT);
140 // BoundsChecking - This pass instruments the code to perform run-time bounds
141 // checking on loads, stores, and other memory intrinsics.
142 FunctionPass *createBoundsCheckingPass();
144 /// \brief This pass splits the stack into a safe stack and an unsafe stack to
145 /// protect against stack-based overflow vulnerabilities.
146 FunctionPass *createSafeStackPass();
148 } // End llvm namespace