LLVM  9.0.0svn
RuntimeDyldChecker.h
Go to the documentation of this file.
1 //===---- RuntimeDyldChecker.h - RuntimeDyld tester framework -----*- C++ -*-=//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLVM_EXECUTIONENGINE_RUNTIMEDYLDCHECKER_H
10 #define LLVM_EXECUTIONENGINE_RUNTIMEDYLDCHECKER_H
11 
12 #include "llvm/ADT/DenseMap.h"
13 #include "llvm/ADT/Optional.h"
15 #include "llvm/Support/Endian.h"
16 
17 #include <cstdint>
18 #include <memory>
19 #include <string>
20 #include <utility>
21 
22 namespace llvm {
23 
24 class StringRef;
25 class MCDisassembler;
26 class MemoryBuffer;
27 class MCInstPrinter;
28 class RuntimeDyld;
29 class RuntimeDyldCheckerImpl;
30 class raw_ostream;
31 
32 /// RuntimeDyld invariant checker for verifying that RuntimeDyld has
33 /// correctly applied relocations.
34 ///
35 /// The RuntimeDyldChecker class evaluates expressions against an attached
36 /// RuntimeDyld instance to verify that relocations have been applied
37 /// correctly.
38 ///
39 /// The expression language supports basic pointer arithmetic and bit-masking,
40 /// and has limited disassembler integration for accessing instruction
41 /// operands and the next PC (program counter) address for each instruction.
42 ///
43 /// The language syntax is:
44 ///
45 /// check = expr '=' expr
46 ///
47 /// expr = binary_expr
48 /// | sliceable_expr
49 ///
50 /// sliceable_expr = '*{' number '}' load_addr_expr [slice]
51 /// | '(' expr ')' [slice]
52 /// | ident_expr [slice]
53 /// | number [slice]
54 ///
55 /// slice = '[' high-bit-index ':' low-bit-index ']'
56 ///
57 /// load_addr_expr = symbol
58 /// | '(' symbol '+' number ')'
59 /// | '(' symbol '-' number ')'
60 ///
61 /// ident_expr = 'decode_operand' '(' symbol ',' operand-index ')'
62 /// | 'next_pc' '(' symbol ')'
63 /// | 'stub_addr' '(' stub-container-name ',' symbol ')'
64 /// | 'got_addr' '(' stub-container-name ',' symbol ')'
65 /// | symbol
66 ///
67 /// binary_expr = expr '+' expr
68 /// | expr '-' expr
69 /// | expr '&' expr
70 /// | expr '|' expr
71 /// | expr '<<' expr
72 /// | expr '>>' expr
73 ///
75 public:
79  };
80 
81  using IsSymbolValidFunction = std::function<bool(StringRef Symbol)>;
82  using GetSymbolInfoFunction =
83  std::function<Expected<MemoryRegionInfo>(StringRef SymbolName)>;
84  using GetSectionInfoFunction = std::function<Expected<MemoryRegionInfo>(
86  using GetStubInfoFunction = std::function<Expected<MemoryRegionInfo>(
87  StringRef StubContainer, StringRef TargetName)>;
88  using GetGOTInfoFunction = std::function<Expected<MemoryRegionInfo>(
89  StringRef GOTContainer, StringRef TargetName)>;
90 
92  GetSymbolInfoFunction GetSymbolInfo,
93  GetSectionInfoFunction GetSectionInfo,
94  GetStubInfoFunction GetStubInfo,
95  GetGOTInfoFunction GetGOTInfo,
97  MCDisassembler *Disassembler, MCInstPrinter *InstPrinter,
98  raw_ostream &ErrStream);
100 
101  /// Check a single expression against the attached RuntimeDyld
102  /// instance.
103  bool check(StringRef CheckExpr) const;
104 
105  /// Scan the given memory buffer for lines beginning with the string
106  /// in RulePrefix. The remainder of the line is passed to the check
107  /// method to be evaluated as an expression.
108  bool checkAllRulesInBuffer(StringRef RulePrefix, MemoryBuffer *MemBuf) const;
109 
110  /// Returns the address of the requested section (or an error message
111  /// in the second element of the pair if the address cannot be found).
112  ///
113  /// if 'LocalAddress' is true, this returns the address of the section
114  /// within the linker's memory. If 'LocalAddress' is false it returns the
115  /// address within the target process (i.e. the load address).
116  std::pair<uint64_t, std::string> getSectionAddr(StringRef FileName,
118  bool LocalAddress);
119 
120  /// If there is a section at the given local address, return its load
121  /// address, otherwise return none.
122  Optional<uint64_t> getSectionLoadAddress(void *LocalAddress) const;
123 
124 private:
125  std::unique_ptr<RuntimeDyldCheckerImpl> Impl;
126 };
127 
128 } // end namespace llvm
129 
130 #endif
bool checkAllRulesInBuffer(StringRef RulePrefix, MemoryBuffer *MemBuf) const
Scan the given memory buffer for lines beginning with the string in RulePrefix.
This class represents lattice values for constants.
Definition: AllocatorList.h:23
Superclass for all disassemblers.
constexpr support::endianness Endianness
The endianness of all multi-byte encoded values in MessagePack.
Definition: MsgPack.h:24
constexpr char SymbolName[]
Key for Kernel::Metadata::mSymbolName.
Optional< uint64_t > getSectionLoadAddress(void *LocalAddress) const
If there is a section at the given local address, return its load address, otherwise return none...
std::function< Expected< MemoryRegionInfo >(StringRef GOTContainer, StringRef TargetName)> GetGOTInfoFunction
uint64_t JITTargetAddress
Represents an address in the target process&#39;s address space.
Definition: JITSymbol.h:40
std::function< bool(StringRef Symbol)> IsSymbolValidFunction
std::function< Expected< MemoryRegionInfo >(StringRef SymbolName)> GetSymbolInfoFunction
std::pair< uint64_t, std::string > getSectionAddr(StringRef FileName, StringRef SectionName, bool LocalAddress)
Returns the address of the requested section (or an error message in the second element of the pair i...
RuntimeDyld invariant checker for verifying that RuntimeDyld has correctly applied relocations...
std::function< Expected< MemoryRegionInfo >(StringRef StubContainer, StringRef TargetName)> GetStubInfoFunction
bool check(StringRef CheckExpr) const
Check a single expression against the attached RuntimeDyld instance.
This interface provides simple read-only access to a block of memory, and provides simple methods for...
Definition: MemoryBuffer.h:41
RuntimeDyldChecker(IsSymbolValidFunction IsSymbolValid, GetSymbolInfoFunction GetSymbolInfo, GetSectionInfoFunction GetSectionInfo, GetStubInfoFunction GetStubInfo, GetGOTInfoFunction GetGOTInfo, support::endianness Endianness, MCDisassembler *Disassembler, MCInstPrinter *InstPrinter, raw_ostream &ErrStream)
This is an instance of a target assembly language printer that converts an MCInst to valid target ass...
Definition: MCInstPrinter.h:39
std::function< Expected< MemoryRegionInfo >(StringRef FileName, StringRef SectionName)> GetSectionInfoFunction
const char SectionName[]
Definition: AMDGPUPTNote.h:23
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:45
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48