2014-06-27 20:20:57 +00:00
|
|
|
//===---- RuntimeDyldChecker.h - RuntimeDyld tester framework -----*- C++ -*-=//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-08-13 16:26:38 +00:00
|
|
|
#ifndef LLVM_EXECUTIONENGINE_RUNTIMEDYLDCHECKER_H
|
|
|
|
#define LLVM_EXECUTIONENGINE_RUNTIMEDYLDCHECKER_H
|
2014-06-27 20:20:57 +00:00
|
|
|
|
[MCJIT] Refactor and add stub inspection to the RuntimeDyldChecker framework.
This patch introduces a 'stub_addr' builtin that can be used to find the address
of the stub for a given (<file>, <section>, <symbol>) tuple. This address can be
used both to verify the contents of stubs (by loading from the returned address)
and to verify references to stubs (by comparing against the returned address).
Example (1) - Verifying stub contents:
Load 8 bytes (assuming a 64-bit target) from the stub for 'x' in the __text
section of f.o, and compare that value against the addres of 'x'.
# rtdyld-check: *{8}(stub_addr(f.o, __text, x) = x
Example (2) - Verifying references to stubs:
Decode the immediate of the instruction at label 'l', and verify that it's
equal to the offset from the next instruction's PC to the stub for 'y' in the
__text section of f.o (i.e. it's the correct PC-rel difference).
# rtdyld-check: decode_operand(l, 4) = stub_addr(f.o, __text, y) - next_pc(l)
l:
movq y@GOTPCREL(%rip), %rax
Since stub inspection requires cooperation with RuntimeDyldImpl this patch
pimpl-ifies RuntimeDyldChecker. Its implementation is moved in to a new class,
RuntimeDyldCheckerImpl, that has access to the definition of RuntimeDyldImpl.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@213698 91177308-0d34-0410-b5e6-96231b3b80d8
2014-07-22 22:47:39 +00:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
2014-06-27 20:20:57 +00:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
|
|
|
class MCDisassembler;
|
[MCJIT] Refactor and add stub inspection to the RuntimeDyldChecker framework.
This patch introduces a 'stub_addr' builtin that can be used to find the address
of the stub for a given (<file>, <section>, <symbol>) tuple. This address can be
used both to verify the contents of stubs (by loading from the returned address)
and to verify references to stubs (by comparing against the returned address).
Example (1) - Verifying stub contents:
Load 8 bytes (assuming a 64-bit target) from the stub for 'x' in the __text
section of f.o, and compare that value against the addres of 'x'.
# rtdyld-check: *{8}(stub_addr(f.o, __text, x) = x
Example (2) - Verifying references to stubs:
Decode the immediate of the instruction at label 'l', and verify that it's
equal to the offset from the next instruction's PC to the stub for 'y' in the
__text section of f.o (i.e. it's the correct PC-rel difference).
# rtdyld-check: decode_operand(l, 4) = stub_addr(f.o, __text, y) - next_pc(l)
l:
movq y@GOTPCREL(%rip), %rax
Since stub inspection requires cooperation with RuntimeDyldImpl this patch
pimpl-ifies RuntimeDyldChecker. Its implementation is moved in to a new class,
RuntimeDyldCheckerImpl, that has access to the definition of RuntimeDyldImpl.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@213698 91177308-0d34-0410-b5e6-96231b3b80d8
2014-07-22 22:47:39 +00:00
|
|
|
class MemoryBuffer;
|
2014-06-27 20:20:57 +00:00
|
|
|
class MCInstPrinter;
|
[MCJIT] Refactor and add stub inspection to the RuntimeDyldChecker framework.
This patch introduces a 'stub_addr' builtin that can be used to find the address
of the stub for a given (<file>, <section>, <symbol>) tuple. This address can be
used both to verify the contents of stubs (by loading from the returned address)
and to verify references to stubs (by comparing against the returned address).
Example (1) - Verifying stub contents:
Load 8 bytes (assuming a 64-bit target) from the stub for 'x' in the __text
section of f.o, and compare that value against the addres of 'x'.
# rtdyld-check: *{8}(stub_addr(f.o, __text, x) = x
Example (2) - Verifying references to stubs:
Decode the immediate of the instruction at label 'l', and verify that it's
equal to the offset from the next instruction's PC to the stub for 'y' in the
__text section of f.o (i.e. it's the correct PC-rel difference).
# rtdyld-check: decode_operand(l, 4) = stub_addr(f.o, __text, y) - next_pc(l)
l:
movq y@GOTPCREL(%rip), %rax
Since stub inspection requires cooperation with RuntimeDyldImpl this patch
pimpl-ifies RuntimeDyldChecker. Its implementation is moved in to a new class,
RuntimeDyldCheckerImpl, that has access to the definition of RuntimeDyldImpl.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@213698 91177308-0d34-0410-b5e6-96231b3b80d8
2014-07-22 22:47:39 +00:00
|
|
|
class RuntimeDyld;
|
|
|
|
class RuntimeDyldCheckerImpl;
|
|
|
|
class raw_ostream;
|
2014-06-27 20:20:57 +00:00
|
|
|
|
|
|
|
/// \brief RuntimeDyld invariant checker for verifying that RuntimeDyld has
|
|
|
|
/// correctly applied relocations.
|
|
|
|
///
|
|
|
|
/// The RuntimeDyldChecker class evaluates expressions against an attached
|
|
|
|
/// RuntimeDyld instance to verify that relocations have been applied
|
|
|
|
/// correctly.
|
|
|
|
///
|
|
|
|
/// The expression language supports basic pointer arithmetic and bit-masking,
|
|
|
|
/// and has limited disassembler integration for accessing instruction
|
|
|
|
/// operands and the next PC (program counter) address for each instruction.
|
|
|
|
///
|
|
|
|
/// The language syntax is:
|
|
|
|
///
|
|
|
|
/// check = expr '=' expr
|
|
|
|
///
|
|
|
|
/// expr = binary_expr
|
|
|
|
/// | sliceable_expr
|
|
|
|
///
|
|
|
|
/// sliceable_expr = '*{' number '}' load_addr_expr [slice]
|
|
|
|
/// | '(' expr ')' [slice]
|
|
|
|
/// | ident_expr [slice]
|
|
|
|
/// | number [slice]
|
|
|
|
///
|
|
|
|
/// slice = '[' high-bit-index ':' low-bit-index ']'
|
|
|
|
///
|
|
|
|
/// load_addr_expr = symbol
|
|
|
|
/// | '(' symbol '+' number ')'
|
|
|
|
/// | '(' symbol '-' number ')'
|
|
|
|
///
|
|
|
|
/// ident_expr = 'decode_operand' '(' symbol ',' operand-index ')'
|
|
|
|
/// | 'next_pc' '(' symbol ')'
|
|
|
|
/// | symbol
|
|
|
|
///
|
|
|
|
/// binary_expr = expr '+' expr
|
|
|
|
/// | expr '-' expr
|
|
|
|
/// | expr '&' expr
|
|
|
|
/// | expr '|' expr
|
|
|
|
/// | expr '<<' expr
|
|
|
|
/// | expr '>>' expr
|
|
|
|
///
|
|
|
|
class RuntimeDyldChecker {
|
|
|
|
public:
|
[MCJIT] Refactor and add stub inspection to the RuntimeDyldChecker framework.
This patch introduces a 'stub_addr' builtin that can be used to find the address
of the stub for a given (<file>, <section>, <symbol>) tuple. This address can be
used both to verify the contents of stubs (by loading from the returned address)
and to verify references to stubs (by comparing against the returned address).
Example (1) - Verifying stub contents:
Load 8 bytes (assuming a 64-bit target) from the stub for 'x' in the __text
section of f.o, and compare that value against the addres of 'x'.
# rtdyld-check: *{8}(stub_addr(f.o, __text, x) = x
Example (2) - Verifying references to stubs:
Decode the immediate of the instruction at label 'l', and verify that it's
equal to the offset from the next instruction's PC to the stub for 'y' in the
__text section of f.o (i.e. it's the correct PC-rel difference).
# rtdyld-check: decode_operand(l, 4) = stub_addr(f.o, __text, y) - next_pc(l)
l:
movq y@GOTPCREL(%rip), %rax
Since stub inspection requires cooperation with RuntimeDyldImpl this patch
pimpl-ifies RuntimeDyldChecker. Its implementation is moved in to a new class,
RuntimeDyldCheckerImpl, that has access to the definition of RuntimeDyldImpl.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@213698 91177308-0d34-0410-b5e6-96231b3b80d8
2014-07-22 22:47:39 +00:00
|
|
|
RuntimeDyldChecker(RuntimeDyld &RTDyld, MCDisassembler *Disassembler,
|
|
|
|
MCInstPrinter *InstPrinter, raw_ostream &ErrStream);
|
|
|
|
~RuntimeDyldChecker();
|
2014-06-27 20:20:57 +00:00
|
|
|
|
2014-09-04 04:19:54 +00:00
|
|
|
// \brief Get the associated RTDyld instance.
|
|
|
|
RuntimeDyld& getRTDyld();
|
|
|
|
|
|
|
|
// \brief Get the associated RTDyld instance.
|
|
|
|
const RuntimeDyld& getRTDyld() const;
|
|
|
|
|
2014-06-27 20:20:57 +00:00
|
|
|
/// \brief Check a single expression against the attached RuntimeDyld
|
|
|
|
/// instance.
|
|
|
|
bool check(StringRef CheckExpr) const;
|
|
|
|
|
|
|
|
/// \brief Scan the given memory buffer for lines beginning with the string
|
|
|
|
/// in RulePrefix. The remainder of the line is passed to the check
|
|
|
|
/// method to be evaluated as an expression.
|
|
|
|
bool checkAllRulesInBuffer(StringRef RulePrefix, MemoryBuffer *MemBuf) const;
|
|
|
|
|
2014-09-04 04:19:54 +00:00
|
|
|
/// \brief Returns the address of the requested section (or an error message
|
|
|
|
/// in the second element of the pair if the address cannot be found).
|
|
|
|
///
|
|
|
|
/// if 'LinkerAddress' is true, this returns the address of the section
|
|
|
|
/// within the linker's memory. If 'LinkerAddress' is false it returns the
|
|
|
|
/// address within the target process (i.e. the load address).
|
|
|
|
std::pair<uint64_t, std::string> getSectionAddr(StringRef FileName,
|
|
|
|
StringRef SectionName,
|
|
|
|
bool LinkerAddress);
|
|
|
|
|
2014-06-27 20:20:57 +00:00
|
|
|
private:
|
[MCJIT] Refactor and add stub inspection to the RuntimeDyldChecker framework.
This patch introduces a 'stub_addr' builtin that can be used to find the address
of the stub for a given (<file>, <section>, <symbol>) tuple. This address can be
used both to verify the contents of stubs (by loading from the returned address)
and to verify references to stubs (by comparing against the returned address).
Example (1) - Verifying stub contents:
Load 8 bytes (assuming a 64-bit target) from the stub for 'x' in the __text
section of f.o, and compare that value against the addres of 'x'.
# rtdyld-check: *{8}(stub_addr(f.o, __text, x) = x
Example (2) - Verifying references to stubs:
Decode the immediate of the instruction at label 'l', and verify that it's
equal to the offset from the next instruction's PC to the stub for 'y' in the
__text section of f.o (i.e. it's the correct PC-rel difference).
# rtdyld-check: decode_operand(l, 4) = stub_addr(f.o, __text, y) - next_pc(l)
l:
movq y@GOTPCREL(%rip), %rax
Since stub inspection requires cooperation with RuntimeDyldImpl this patch
pimpl-ifies RuntimeDyldChecker. Its implementation is moved in to a new class,
RuntimeDyldCheckerImpl, that has access to the definition of RuntimeDyldImpl.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@213698 91177308-0d34-0410-b5e6-96231b3b80d8
2014-07-22 22:47:39 +00:00
|
|
|
std::unique_ptr<RuntimeDyldCheckerImpl> Impl;
|
2014-06-27 20:20:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // end namespace llvm
|
|
|
|
|
2014-08-13 16:26:38 +00:00
|
|
|
#endif
|