]>
Commit | Line | Data |
---|---|---|
223e47cc LB |
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 | ||
970d7e83 LB |
14 | #ifndef LLVM_EXECUTIONENGINE_RUNTIMEDYLD_H |
15 | #define LLVM_EXECUTIONENGINE_RUNTIMEDYLD_H | |
223e47cc LB |
16 | |
17 | #include "llvm/ADT/StringRef.h" | |
1a4d82fc | 18 | #include "llvm/ExecutionEngine/RTDyldMemoryManager.h" |
223e47cc | 19 | #include "llvm/Support/Memory.h" |
85aaf69f | 20 | #include <memory> |
223e47cc LB |
21 | |
22 | namespace llvm { | |
23 | ||
1a4d82fc JJ |
24 | namespace object { |
25 | class ObjectFile; | |
85aaf69f | 26 | template <typename T> class OwningBinary; |
1a4d82fc JJ |
27 | } |
28 | ||
223e47cc | 29 | class RuntimeDyldImpl; |
1a4d82fc | 30 | class RuntimeDyldCheckerImpl; |
223e47cc | 31 | |
223e47cc | 32 | class RuntimeDyld { |
1a4d82fc JJ |
33 | friend class RuntimeDyldCheckerImpl; |
34 | ||
223e47cc LB |
35 | RuntimeDyld(const RuntimeDyld &) LLVM_DELETED_FUNCTION; |
36 | void operator=(const RuntimeDyld &) LLVM_DELETED_FUNCTION; | |
37 | ||
38 | // RuntimeDyldImpl is the actual class. RuntimeDyld is just the public | |
39 | // interface. | |
1a4d82fc | 40 | std::unique_ptr<RuntimeDyldImpl> Dyld; |
223e47cc | 41 | RTDyldMemoryManager *MM; |
1a4d82fc JJ |
42 | bool ProcessAllSections; |
43 | RuntimeDyldCheckerImpl *Checker; | |
223e47cc LB |
44 | protected: |
45 | // Change the address associated with a section when resolving relocations. | |
46 | // Any relocations already associated with the symbol will be re-resolved. | |
47 | void reassignSectionAddress(unsigned SectionID, uint64_t Addr); | |
48 | public: | |
85aaf69f SL |
49 | |
50 | /// \brief Information about the loaded object. | |
51 | class LoadedObjectInfo { | |
52 | friend class RuntimeDyldImpl; | |
53 | public: | |
54 | LoadedObjectInfo(RuntimeDyldImpl &RTDyld, unsigned BeginIdx, | |
55 | unsigned EndIdx) | |
56 | : RTDyld(RTDyld), BeginIdx(BeginIdx), EndIdx(EndIdx) { } | |
57 | ||
58 | virtual ~LoadedObjectInfo() {} | |
59 | ||
60 | virtual object::OwningBinary<object::ObjectFile> | |
61 | getObjectForDebug(const object::ObjectFile &Obj) const = 0; | |
62 | ||
63 | uint64_t getSectionLoadAddress(StringRef Name) const; | |
64 | ||
65 | protected: | |
66 | virtual void anchor(); | |
67 | ||
68 | RuntimeDyldImpl &RTDyld; | |
69 | unsigned BeginIdx, EndIdx; | |
70 | }; | |
71 | ||
970d7e83 | 72 | RuntimeDyld(RTDyldMemoryManager *); |
223e47cc LB |
73 | ~RuntimeDyld(); |
74 | ||
85aaf69f SL |
75 | /// Add the referenced object file to the list of objects to be loaded and |
76 | /// relocated. | |
77 | std::unique_ptr<LoadedObjectInfo> loadObject(const object::ObjectFile &O); | |
223e47cc LB |
78 | |
79 | /// Get the address of our local copy of the symbol. This may or may not | |
80 | /// be the address used for relocation (clients can copy the data around | |
81 | /// and resolve relocatons based on where they put it). | |
1a4d82fc | 82 | void *getSymbolAddress(StringRef Name) const; |
223e47cc LB |
83 | |
84 | /// Get the address of the target copy of the symbol. This is the address | |
85 | /// used for relocation. | |
1a4d82fc | 86 | uint64_t getSymbolLoadAddress(StringRef Name) const; |
223e47cc LB |
87 | |
88 | /// Resolve the relocations for all symbols we currently know about. | |
89 | void resolveRelocations(); | |
90 | ||
970d7e83 | 91 | /// Map a section to its target address space value. |
223e47cc LB |
92 | /// Map the address of a JIT section as returned from the memory manager |
93 | /// to the address in the target process as the running code will see it. | |
94 | /// This is the address which will be used for relocation resolution. | |
95 | void mapSectionAddress(const void *LocalAddress, uint64_t TargetAddress); | |
96 | ||
1a4d82fc JJ |
97 | /// Register any EH frame sections that have been loaded but not previously |
98 | /// registered with the memory manager. Note, RuntimeDyld is responsible | |
99 | /// for identifying the EH frame and calling the memory manager with the | |
100 | /// EH frame section data. However, the memory manager itself will handle | |
101 | /// the actual target-specific EH frame registration. | |
102 | void registerEHFrames(); | |
103 | ||
104 | void deregisterEHFrames(); | |
105 | ||
106 | bool hasError(); | |
223e47cc | 107 | StringRef getErrorString(); |
1a4d82fc JJ |
108 | |
109 | /// By default, only sections that are "required for execution" are passed to | |
110 | /// the RTDyldMemoryManager, and other sections are discarded. Passing 'true' | |
111 | /// to this method will cause RuntimeDyld to pass all sections to its | |
112 | /// memory manager regardless of whether they are "required to execute" in the | |
113 | /// usual sense. This is useful for inspecting metadata sections that may not | |
114 | /// contain relocations, E.g. Debug info, stackmaps. | |
115 | /// | |
116 | /// Must be called before the first object file is loaded. | |
117 | void setProcessAllSections(bool ProcessAllSections) { | |
118 | assert(!Dyld && "setProcessAllSections must be called before loadObject."); | |
119 | this->ProcessAllSections = ProcessAllSections; | |
120 | } | |
223e47cc LB |
121 | }; |
122 | ||
123 | } // end namespace llvm | |
124 | ||
125 | #endif |