1 //===---- RuntimeDyldChecker.h - RuntimeDyld tester framework -----*- C++ -*-=//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_EXECUTIONENGINE_RUNTIMEDYLDCHECKER_H
10 #define LLVM_EXECUTIONENGINE_RUNTIMEDYLDCHECKER_H
12 #include "llvm/ADT/Optional.h"
26 class RuntimeDyldCheckerImpl
;
29 /// RuntimeDyld invariant checker for verifying that RuntimeDyld has
30 /// correctly applied relocations.
32 /// The RuntimeDyldChecker class evaluates expressions against an attached
33 /// RuntimeDyld instance to verify that relocations have been applied
36 /// The expression language supports basic pointer arithmetic and bit-masking,
37 /// and has limited disassembler integration for accessing instruction
38 /// operands and the next PC (program counter) address for each instruction.
40 /// The language syntax is:
42 /// check = expr '=' expr
44 /// expr = binary_expr
47 /// sliceable_expr = '*{' number '}' load_addr_expr [slice]
48 /// | '(' expr ')' [slice]
49 /// | ident_expr [slice]
52 /// slice = '[' high-bit-index ':' low-bit-index ']'
54 /// load_addr_expr = symbol
55 /// | '(' symbol '+' number ')'
56 /// | '(' symbol '-' number ')'
58 /// ident_expr = 'decode_operand' '(' symbol ',' operand-index ')'
59 /// | 'next_pc' '(' symbol ')'
60 /// | 'stub_addr' '(' file-name ',' section-name ',' symbol ')'
63 /// binary_expr = expr '+' expr
70 class RuntimeDyldChecker
{
72 RuntimeDyldChecker(RuntimeDyld
&RTDyld
, MCDisassembler
*Disassembler
,
73 MCInstPrinter
*InstPrinter
, raw_ostream
&ErrStream
);
74 ~RuntimeDyldChecker();
76 // Get the associated RTDyld instance.
77 RuntimeDyld
& getRTDyld();
79 // Get the associated RTDyld instance.
80 const RuntimeDyld
& getRTDyld() const;
82 /// Check a single expression against the attached RuntimeDyld
84 bool check(StringRef CheckExpr
) const;
86 /// Scan the given memory buffer for lines beginning with the string
87 /// in RulePrefix. The remainder of the line is passed to the check
88 /// method to be evaluated as an expression.
89 bool checkAllRulesInBuffer(StringRef RulePrefix
, MemoryBuffer
*MemBuf
) const;
91 /// Returns the address of the requested section (or an error message
92 /// in the second element of the pair if the address cannot be found).
94 /// if 'LocalAddress' is true, this returns the address of the section
95 /// within the linker's memory. If 'LocalAddress' is false it returns the
96 /// address within the target process (i.e. the load address).
97 std::pair
<uint64_t, std::string
> getSectionAddr(StringRef FileName
,
98 StringRef SectionName
,
101 /// If there is a section at the given local address, return its load
102 /// address, otherwise return none.
103 Optional
<uint64_t> getSectionLoadAddress(void *LocalAddress
) const;
106 std::unique_ptr
<RuntimeDyldCheckerImpl
> Impl
;
109 } // end namespace llvm