RuntimeDyld.h revision 36b56886974eae4f9c5ebc96befd3e7bfe5de338
1//===-- RuntimeDyld.h - Run-time dynamic linker for MC-JIT ------*- 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// Interface for the runtime dynamic linker facilities of the MC-JIT.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_EXECUTIONENGINE_RUNTIMEDYLD_H
15#define LLVM_EXECUTIONENGINE_RUNTIMEDYLD_H
16
17#include "llvm/ADT/StringRef.h"
18#include "llvm/ExecutionEngine/ObjectBuffer.h"
19#include "llvm/ExecutionEngine/RTDyldMemoryManager.h"
20#include "llvm/Support/Memory.h"
21
22namespace llvm {
23
24namespace object {
25  class ObjectFile;
26}
27
28class RuntimeDyldImpl;
29class ObjectImage;
30
31class RuntimeDyld {
32  RuntimeDyld(const RuntimeDyld &) LLVM_DELETED_FUNCTION;
33  void operator=(const RuntimeDyld &) LLVM_DELETED_FUNCTION;
34
35  // RuntimeDyldImpl is the actual class. RuntimeDyld is just the public
36  // interface.
37  RuntimeDyldImpl *Dyld;
38  RTDyldMemoryManager *MM;
39  bool ProcessAllSections;
40protected:
41  // Change the address associated with a section when resolving relocations.
42  // Any relocations already associated with the symbol will be re-resolved.
43  void reassignSectionAddress(unsigned SectionID, uint64_t Addr);
44public:
45  RuntimeDyld(RTDyldMemoryManager *);
46  ~RuntimeDyld();
47
48  /// Prepare the object contained in the input buffer for execution.
49  /// Ownership of the input buffer is transferred to the ObjectImage
50  /// instance returned from this function if successful. In the case of load
51  /// failure, the input buffer will be deleted.
52  ObjectImage *loadObject(ObjectBuffer *InputBuffer);
53
54  /// Prepare the referenced object file for execution.
55  /// Ownership of the input object is transferred to the ObjectImage
56  /// instance returned from this function if successful. In the case of load
57  /// failure, the input object will be deleted.
58  ObjectImage *loadObject(object::ObjectFile *InputObject);
59
60  /// Get the address of our local copy of the symbol. This may or may not
61  /// be the address used for relocation (clients can copy the data around
62  /// and resolve relocatons based on where they put it).
63  void *getSymbolAddress(StringRef Name);
64
65  /// Get the address of the target copy of the symbol. This is the address
66  /// used for relocation.
67  uint64_t getSymbolLoadAddress(StringRef Name);
68
69  /// Resolve the relocations for all symbols we currently know about.
70  void resolveRelocations();
71
72  /// Map a section to its target address space value.
73  /// Map the address of a JIT section as returned from the memory manager
74  /// to the address in the target process as the running code will see it.
75  /// This is the address which will be used for relocation resolution.
76  void mapSectionAddress(const void *LocalAddress, uint64_t TargetAddress);
77
78  /// Register any EH frame sections that have been loaded but not previously
79  /// registered with the memory manager.  Note, RuntimeDyld is responsible
80  /// for identifying the EH frame and calling the memory manager with the
81  /// EH frame section data.  However, the memory manager itself will handle
82  /// the actual target-specific EH frame registration.
83  void registerEHFrames();
84
85  void deregisterEHFrames();
86
87  bool hasError();
88  StringRef getErrorString();
89
90  /// By default, only sections that are "required for execution" are passed to
91  /// the RTDyldMemoryManager, and other sections are discarded. Passing 'true'
92  /// to this method will cause RuntimeDyld to pass all sections to its
93  /// memory manager regardless of whether they are "required to execute" in the
94  /// usual sense. This is useful for inspecting metadata sections that may not
95  /// contain relocations, E.g. Debug info, stackmaps.
96  ///
97  /// Must be called before the first object file is loaded.
98  void setProcessAllSections(bool ProcessAllSections) {
99    assert(!Dyld && "setProcessAllSections must be called before loadObject.");
100    this->ProcessAllSections = ProcessAllSections;
101  }
102};
103
104} // end namespace llvm
105
106#endif
107