1 //===---- RuntimeDyldChecker.h - RuntimeDyld tester framework -----*- 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 #ifndef LLVM_EXECUTIONENGINE_RUNTIMEDYLDCHECKER_H 11 #define LLVM_EXECUTIONENGINE_RUNTIMEDYLDCHECKER_H 12 13 #include <cstdint> 14 #include <memory> 15 #include <string> 16 #include <utility> 17 18 namespace llvm { 19 20 class StringRef; 21 class MCDisassembler; 22 class MemoryBuffer; 23 class MCInstPrinter; 24 class RuntimeDyld; 25 class RuntimeDyldCheckerImpl; 26 class raw_ostream; 27 28 /// \brief RuntimeDyld invariant checker for verifying that RuntimeDyld has 29 /// correctly applied relocations. 30 /// 31 /// The RuntimeDyldChecker class evaluates expressions against an attached 32 /// RuntimeDyld instance to verify that relocations have been applied 33 /// correctly. 34 /// 35 /// The expression language supports basic pointer arithmetic and bit-masking, 36 /// and has limited disassembler integration for accessing instruction 37 /// operands and the next PC (program counter) address for each instruction. 38 /// 39 /// The language syntax is: 40 /// 41 /// check = expr '=' expr 42 /// 43 /// expr = binary_expr 44 /// | sliceable_expr 45 /// 46 /// sliceable_expr = '*{' number '}' load_addr_expr [slice] 47 /// | '(' expr ')' [slice] 48 /// | ident_expr [slice] 49 /// | number [slice] 50 /// 51 /// slice = '[' high-bit-index ':' low-bit-index ']' 52 /// 53 /// load_addr_expr = symbol 54 /// | '(' symbol '+' number ')' 55 /// | '(' symbol '-' number ')' 56 /// 57 /// ident_expr = 'decode_operand' '(' symbol ',' operand-index ')' 58 /// | 'next_pc' '(' symbol ')' 59 /// | 'stub_addr' '(' file-name ',' section-name ',' symbol ')' 60 /// | symbol 61 /// 62 /// binary_expr = expr '+' expr 63 /// | expr '-' expr 64 /// | expr '&' expr 65 /// | expr '|' expr 66 /// | expr '<<' expr 67 /// | expr '>>' expr 68 /// 69 class RuntimeDyldChecker { 70 public: 71 RuntimeDyldChecker(RuntimeDyld &RTDyld, MCDisassembler *Disassembler, 72 MCInstPrinter *InstPrinter, raw_ostream &ErrStream); 73 ~RuntimeDyldChecker(); 74 75 // \brief Get the associated RTDyld instance. 76 RuntimeDyld& getRTDyld(); 77 78 // \brief Get the associated RTDyld instance. 79 const RuntimeDyld& getRTDyld() const; 80 81 /// \brief Check a single expression against the attached RuntimeDyld 82 /// instance. 83 bool check(StringRef CheckExpr) const; 84 85 /// \brief Scan the given memory buffer for lines beginning with the string 86 /// in RulePrefix. The remainder of the line is passed to the check 87 /// method to be evaluated as an expression. 88 bool checkAllRulesInBuffer(StringRef RulePrefix, MemoryBuffer *MemBuf) const; 89 90 /// \brief Returns the address of the requested section (or an error message 91 /// in the second element of the pair if the address cannot be found). 92 /// 93 /// if 'LocalAddress' is true, this returns the address of the section 94 /// within the linker's memory. If 'LocalAddress' is false it returns the 95 /// address within the target process (i.e. the load address). 96 std::pair<uint64_t, std::string> getSectionAddr(StringRef FileName, 97 StringRef SectionName, 98 bool LocalAddress); 99 100 private: 101 std::unique_ptr<RuntimeDyldCheckerImpl> Impl; 102 }; 103 104 } // end namespace llvm 105 106 #endif 107