Daniel Dunbar | 7e5d8a7 | 2010-11-17 16:06:43 +0000 | [diff] [blame] | 1 | //===-- MCJIT.h - Class definition for the MCJIT ----------------*- 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_LIB_EXECUTIONENGINE_MCJIT_H |
| 11 | #define LLVM_LIB_EXECUTIONENGINE_MCJIT_H |
| 12 | |
Andrew Kaylor | ea39592 | 2013-10-01 01:47:35 +0000 | [diff] [blame] | 13 | #include "llvm/ADT/DenseMap.h" |
Andrew Kaylor | c89fc82 | 2013-10-24 00:19:14 +0000 | [diff] [blame] | 14 | #include "llvm/ADT/SmallPtrSet.h" |
Andrew Kaylor | d8ffd9c | 2012-11-06 18:51:59 +0000 | [diff] [blame] | 15 | #include "llvm/ADT/SmallVector.h" |
Daniel Dunbar | 7e5d8a7 | 2010-11-17 16:06:43 +0000 | [diff] [blame] | 16 | #include "llvm/ExecutionEngine/ExecutionEngine.h" |
Andrew Kaylor | ced4e8f | 2013-04-25 21:02:36 +0000 | [diff] [blame] | 17 | #include "llvm/ExecutionEngine/ObjectCache.h" |
Andrew Kaylor | ea39592 | 2013-10-01 01:47:35 +0000 | [diff] [blame] | 18 | #include "llvm/ExecutionEngine/ObjectImage.h" |
Jim Grosbach | 348a548 | 2011-03-22 01:06:42 +0000 | [diff] [blame] | 19 | #include "llvm/ExecutionEngine/RuntimeDyld.h" |
Andrew Kaylor | c89fc82 | 2013-10-24 00:19:14 +0000 | [diff] [blame] | 20 | #include "llvm/IR/Module.h" |
Daniel Dunbar | 7e5d8a7 | 2010-11-17 16:06:43 +0000 | [diff] [blame] | 21 | |
| 22 | namespace llvm { |
Andrew Kaylor | ea39592 | 2013-10-01 01:47:35 +0000 | [diff] [blame] | 23 | class MCJIT; |
| 24 | |
| 25 | // This is a helper class that the MCJIT execution engine uses for linking |
| 26 | // functions across modules that it owns. It aggregates the memory manager |
| 27 | // that is passed in to the MCJIT constructor and defers most functionality |
| 28 | // to that object. |
| 29 | class LinkingMemoryManager : public RTDyldMemoryManager { |
| 30 | public: |
| 31 | LinkingMemoryManager(MCJIT *Parent, RTDyldMemoryManager *MM) |
| 32 | : ParentEngine(Parent), ClientMM(MM) {} |
| 33 | |
Craig Topper | b51ff60 | 2014-03-08 07:51:20 +0000 | [diff] [blame] | 34 | uint64_t getSymbolAddress(const std::string &Name) override; |
Andrew Kaylor | ea39592 | 2013-10-01 01:47:35 +0000 | [diff] [blame] | 35 | |
| 36 | // Functions deferred to client memory manager |
Craig Topper | b51ff60 | 2014-03-08 07:51:20 +0000 | [diff] [blame] | 37 | uint8_t *allocateCodeSection(uintptr_t Size, unsigned Alignment, |
| 38 | unsigned SectionID, |
| 39 | StringRef SectionName) override { |
Filip Pizlo | 7aa695e0 | 2013-10-02 00:59:25 +0000 | [diff] [blame] | 40 | return ClientMM->allocateCodeSection(Size, Alignment, SectionID, SectionName); |
Andrew Kaylor | ea39592 | 2013-10-01 01:47:35 +0000 | [diff] [blame] | 41 | } |
| 42 | |
Craig Topper | b51ff60 | 2014-03-08 07:51:20 +0000 | [diff] [blame] | 43 | uint8_t *allocateDataSection(uintptr_t Size, unsigned Alignment, |
| 44 | unsigned SectionID, StringRef SectionName, |
| 45 | bool IsReadOnly) override { |
Andrew Kaylor | ea39592 | 2013-10-01 01:47:35 +0000 | [diff] [blame] | 46 | return ClientMM->allocateDataSection(Size, Alignment, |
Filip Pizlo | 7aa695e0 | 2013-10-02 00:59:25 +0000 | [diff] [blame] | 47 | SectionID, SectionName, IsReadOnly); |
Andrew Kaylor | ea39592 | 2013-10-01 01:47:35 +0000 | [diff] [blame] | 48 | } |
Craig Topper | b51ff60 | 2014-03-08 07:51:20 +0000 | [diff] [blame] | 49 | |
| 50 | void reserveAllocationSpace(uintptr_t CodeSize, uintptr_t DataSizeRO, |
| 51 | uintptr_t DataSizeRW) override { |
Lang Hames | 937ec54 | 2014-02-12 21:30:07 +0000 | [diff] [blame] | 52 | return ClientMM->reserveAllocationSpace(CodeSize, DataSizeRO, DataSizeRW); |
| 53 | } |
Craig Topper | b51ff60 | 2014-03-08 07:51:20 +0000 | [diff] [blame] | 54 | |
| 55 | bool needsToReserveAllocationSpace() override { |
Lang Hames | 937ec54 | 2014-02-12 21:30:07 +0000 | [diff] [blame] | 56 | return ClientMM->needsToReserveAllocationSpace(); |
| 57 | } |
Andrew Kaylor | ea39592 | 2013-10-01 01:47:35 +0000 | [diff] [blame] | 58 | |
Craig Topper | b51ff60 | 2014-03-08 07:51:20 +0000 | [diff] [blame] | 59 | void notifyObjectLoaded(ExecutionEngine *EE, |
| 60 | const ObjectImage *Obj) override { |
Andrew Kaylor | 1b2cfb6 | 2013-10-04 00:49:38 +0000 | [diff] [blame] | 61 | ClientMM->notifyObjectLoaded(EE, Obj); |
| 62 | } |
| 63 | |
Craig Topper | b51ff60 | 2014-03-08 07:51:20 +0000 | [diff] [blame] | 64 | void registerEHFrames(uint8_t *Addr, uint64_t LoadAddr, |
| 65 | size_t Size) override { |
Andrew Kaylor | 7bb1344 | 2013-10-11 21:25:48 +0000 | [diff] [blame] | 66 | ClientMM->registerEHFrames(Addr, LoadAddr, Size); |
Andrew Kaylor | ea39592 | 2013-10-01 01:47:35 +0000 | [diff] [blame] | 67 | } |
| 68 | |
Craig Topper | b51ff60 | 2014-03-08 07:51:20 +0000 | [diff] [blame] | 69 | void deregisterEHFrames(uint8_t *Addr, uint64_t LoadAddr, |
| 70 | size_t Size) override { |
Andrew Kaylor | c442a76 | 2013-10-16 00:14:21 +0000 | [diff] [blame] | 71 | ClientMM->deregisterEHFrames(Addr, LoadAddr, Size); |
| 72 | } |
| 73 | |
Craig Topper | b51ff60 | 2014-03-08 07:51:20 +0000 | [diff] [blame] | 74 | bool finalizeMemory(std::string *ErrMsg = 0) override { |
Andrew Kaylor | ea39592 | 2013-10-01 01:47:35 +0000 | [diff] [blame] | 75 | return ClientMM->finalizeMemory(ErrMsg); |
| 76 | } |
| 77 | |
| 78 | private: |
| 79 | MCJIT *ParentEngine; |
Ahmed Charles | 56440fd | 2014-03-06 05:51:42 +0000 | [diff] [blame] | 80 | std::unique_ptr<RTDyldMemoryManager> ClientMM; |
Andrew Kaylor | ea39592 | 2013-10-01 01:47:35 +0000 | [diff] [blame] | 81 | }; |
Andrew Kaylor | adc7056 | 2012-10-02 21:18:39 +0000 | [diff] [blame] | 82 | |
Andrew Kaylor | c89fc82 | 2013-10-24 00:19:14 +0000 | [diff] [blame] | 83 | // About Module states: added->loaded->finalized. |
Yaron Keren | fb95582 | 2013-10-19 09:03:20 +0000 | [diff] [blame] | 84 | // |
| 85 | // The purpose of the "added" state is having modules in standby. (added=known |
| 86 | // but not compiled). The idea is that you can add a module to provide function |
| 87 | // definitions but if nothing in that module is referenced by a module in which |
Yaron Keren | 1ec9df3 | 2013-10-24 10:04:47 +0000 | [diff] [blame] | 88 | // a function is executed (note the wording here because it's not exactly the |
Yaron Keren | fb95582 | 2013-10-19 09:03:20 +0000 | [diff] [blame] | 89 | // ideal case) then the module never gets compiled. This is sort of lazy |
| 90 | // compilation. |
| 91 | // |
| 92 | // The purpose of the "loaded" state (loaded=compiled and required sections |
| 93 | // copied into local memory but not yet ready for execution) is to have an |
| 94 | // intermediate state wherein clients can remap the addresses of sections, using |
| 95 | // MCJIT::mapSectionAddress, (in preparation for later copying to a new location |
| 96 | // or an external process) before relocations and page permissions are applied. |
| 97 | // |
| 98 | // It might not be obvious at first glance, but the "remote-mcjit" case in the |
| 99 | // lli tool does this. In that case, the intermediate action is taken by the |
| 100 | // RemoteMemoryManager in response to the notifyObjectLoaded function being |
| 101 | // called. |
| 102 | |
Daniel Dunbar | 7e5d8a7 | 2010-11-17 16:06:43 +0000 | [diff] [blame] | 103 | class MCJIT : public ExecutionEngine { |
Jim Grosbach | bea6753 | 2012-08-21 15:42:49 +0000 | [diff] [blame] | 104 | MCJIT(Module *M, TargetMachine *tm, RTDyldMemoryManager *MemMgr, |
| 105 | bool AllocateGVsWithCode); |
Jim Grosbach | 7b16249 | 2011-03-18 22:48:41 +0000 | [diff] [blame] | 106 | |
Andrew Kaylor | c89fc82 | 2013-10-24 00:19:14 +0000 | [diff] [blame] | 107 | typedef llvm::SmallPtrSet<Module *, 4> ModulePtrSet; |
Andrew Kaylor | ea39592 | 2013-10-01 01:47:35 +0000 | [diff] [blame] | 108 | |
Andrew Kaylor | c89fc82 | 2013-10-24 00:19:14 +0000 | [diff] [blame] | 109 | class OwningModuleContainer { |
Andrew Kaylor | ea39592 | 2013-10-01 01:47:35 +0000 | [diff] [blame] | 110 | public: |
Andrew Kaylor | c89fc82 | 2013-10-24 00:19:14 +0000 | [diff] [blame] | 111 | OwningModuleContainer() { |
| 112 | } |
| 113 | ~OwningModuleContainer() { |
| 114 | freeModulePtrSet(AddedModules); |
| 115 | freeModulePtrSet(LoadedModules); |
| 116 | freeModulePtrSet(FinalizedModules); |
| 117 | } |
Andrew Kaylor | ea39592 | 2013-10-01 01:47:35 +0000 | [diff] [blame] | 118 | |
Andrew Kaylor | c89fc82 | 2013-10-24 00:19:14 +0000 | [diff] [blame] | 119 | ModulePtrSet::iterator begin_added() { return AddedModules.begin(); } |
| 120 | ModulePtrSet::iterator end_added() { return AddedModules.end(); } |
| 121 | |
| 122 | ModulePtrSet::iterator begin_loaded() { return LoadedModules.begin(); } |
| 123 | ModulePtrSet::iterator end_loaded() { return LoadedModules.end(); } |
| 124 | |
| 125 | ModulePtrSet::iterator begin_finalized() { return FinalizedModules.begin(); } |
| 126 | ModulePtrSet::iterator end_finalized() { return FinalizedModules.end(); } |
| 127 | |
| 128 | void addModule(Module *M) { |
| 129 | AddedModules.insert(M); |
| 130 | } |
| 131 | |
| 132 | bool removeModule(Module *M) { |
| 133 | return AddedModules.erase(M) || LoadedModules.erase(M) || |
| 134 | FinalizedModules.erase(M); |
| 135 | } |
| 136 | |
| 137 | bool hasModuleBeenAddedButNotLoaded(Module *M) { |
| 138 | return AddedModules.count(M) != 0; |
| 139 | } |
| 140 | |
| 141 | bool hasModuleBeenLoaded(Module *M) { |
| 142 | // If the module is in either the "loaded" or "finalized" sections it |
| 143 | // has been loaded. |
| 144 | return (LoadedModules.count(M) != 0 ) || (FinalizedModules.count(M) != 0); |
| 145 | } |
| 146 | |
| 147 | bool hasModuleBeenFinalized(Module *M) { |
| 148 | return FinalizedModules.count(M) != 0; |
| 149 | } |
| 150 | |
| 151 | bool ownsModule(Module* M) { |
| 152 | return (AddedModules.count(M) != 0) || (LoadedModules.count(M) != 0) || |
| 153 | (FinalizedModules.count(M) != 0); |
| 154 | } |
| 155 | |
| 156 | void markModuleAsLoaded(Module *M) { |
| 157 | // This checks against logic errors in the MCJIT implementation. |
| 158 | // This function should never be called with either a Module that MCJIT |
| 159 | // does not own or a Module that has already been loaded and/or finalized. |
| 160 | assert(AddedModules.count(M) && |
| 161 | "markModuleAsLoaded: Module not found in AddedModules"); |
| 162 | |
| 163 | // Remove the module from the "Added" set. |
| 164 | AddedModules.erase(M); |
| 165 | |
| 166 | // Add the Module to the "Loaded" set. |
| 167 | LoadedModules.insert(M); |
| 168 | } |
| 169 | |
| 170 | void markModuleAsFinalized(Module *M) { |
| 171 | // This checks against logic errors in the MCJIT implementation. |
| 172 | // This function should never be called with either a Module that MCJIT |
| 173 | // does not own, a Module that has not been loaded or a Module that has |
| 174 | // already been finalized. |
| 175 | assert(LoadedModules.count(M) && |
| 176 | "markModuleAsFinalized: Module not found in LoadedModules"); |
| 177 | |
| 178 | // Remove the module from the "Loaded" section of the list. |
| 179 | LoadedModules.erase(M); |
| 180 | |
| 181 | // Add the Module to the "Finalized" section of the list by inserting it |
| 182 | // before the 'end' iterator. |
| 183 | FinalizedModules.insert(M); |
| 184 | } |
| 185 | |
| 186 | void markAllLoadedModulesAsFinalized() { |
| 187 | for (ModulePtrSet::iterator I = LoadedModules.begin(), |
| 188 | E = LoadedModules.end(); |
| 189 | I != E; ++I) { |
| 190 | Module *M = *I; |
| 191 | FinalizedModules.insert(M); |
| 192 | } |
| 193 | LoadedModules.clear(); |
| 194 | } |
Andrew Kaylor | ea39592 | 2013-10-01 01:47:35 +0000 | [diff] [blame] | 195 | |
| 196 | private: |
Andrew Kaylor | c89fc82 | 2013-10-24 00:19:14 +0000 | [diff] [blame] | 197 | ModulePtrSet AddedModules; |
| 198 | ModulePtrSet LoadedModules; |
| 199 | ModulePtrSet FinalizedModules; |
| 200 | |
| 201 | void freeModulePtrSet(ModulePtrSet& MPS) { |
| 202 | // Go through the module set and delete everything. |
| 203 | for (ModulePtrSet::iterator I = MPS.begin(), E = MPS.end(); I != E; ++I) { |
| 204 | Module *M = *I; |
| 205 | delete M; |
| 206 | } |
| 207 | MPS.clear(); |
| 208 | } |
Andrew Kaylor | ea39592 | 2013-10-01 01:47:35 +0000 | [diff] [blame] | 209 | }; |
| 210 | |
Jim Grosbach | 7b16249 | 2011-03-18 22:48:41 +0000 | [diff] [blame] | 211 | TargetMachine *TM; |
| 212 | MCContext *Ctx; |
Andrew Kaylor | ea39592 | 2013-10-01 01:47:35 +0000 | [diff] [blame] | 213 | LinkingMemoryManager MemMgr; |
Andrew Kaylor | 1a568c3 | 2012-08-07 18:33:00 +0000 | [diff] [blame] | 214 | RuntimeDyld Dyld; |
Andrew Kaylor | d8ffd9c | 2012-11-06 18:51:59 +0000 | [diff] [blame] | 215 | SmallVector<JITEventListener*, 2> EventListeners; |
Jim Grosbach | 7b16249 | 2011-03-18 22:48:41 +0000 | [diff] [blame] | 216 | |
Andrew Kaylor | c89fc82 | 2013-10-24 00:19:14 +0000 | [diff] [blame] | 217 | OwningModuleContainer OwnedModules; |
Andrew Kaylor | ea39592 | 2013-10-01 01:47:35 +0000 | [diff] [blame] | 218 | |
Lang Hames | 173c69f | 2014-01-08 04:09:09 +0000 | [diff] [blame] | 219 | SmallVector<object::Archive*, 2> Archives; |
| 220 | |
| 221 | typedef SmallVector<ObjectImage *, 2> LoadedObjectList; |
| 222 | LoadedObjectList LoadedObjects; |
Jim Grosbach | 7b16249 | 2011-03-18 22:48:41 +0000 | [diff] [blame] | 223 | |
Andrew Kaylor | ced4e8f | 2013-04-25 21:02:36 +0000 | [diff] [blame] | 224 | // An optional ObjectCache to be notified of compiled objects and used to |
| 225 | // perform lookup of pre-compiled code to avoid re-compilation. |
| 226 | ObjectCache *ObjCache; |
| 227 | |
Andrew Kaylor | c89fc82 | 2013-10-24 00:19:14 +0000 | [diff] [blame] | 228 | Function *FindFunctionNamedInModulePtrSet(const char *FnName, |
| 229 | ModulePtrSet::iterator I, |
| 230 | ModulePtrSet::iterator E); |
| 231 | |
| 232 | void runStaticConstructorsDestructorsInModulePtrSet(bool isDtors, |
| 233 | ModulePtrSet::iterator I, |
| 234 | ModulePtrSet::iterator E); |
| 235 | |
Daniel Dunbar | 7e5d8a7 | 2010-11-17 16:06:43 +0000 | [diff] [blame] | 236 | public: |
| 237 | ~MCJIT(); |
| 238 | |
| 239 | /// @name ExecutionEngine interface implementation |
| 240 | /// @{ |
Craig Topper | b51ff60 | 2014-03-08 07:51:20 +0000 | [diff] [blame] | 241 | void addModule(Module *M) override; |
| 242 | void addObjectFile(object::ObjectFile *O) override; |
| 243 | void addArchive(object::Archive *O) override; |
| 244 | bool removeModule(Module *M) override; |
Andrew Kaylor | c89fc82 | 2013-10-24 00:19:14 +0000 | [diff] [blame] | 245 | |
| 246 | /// FindFunctionNamed - Search all of the active modules to find the one that |
| 247 | /// defines FnName. This is very slow operation and shouldn't be used for |
| 248 | /// general code. |
Craig Topper | b51ff60 | 2014-03-08 07:51:20 +0000 | [diff] [blame] | 249 | Function *FindFunctionNamed(const char *FnName) override; |
Daniel Dunbar | 7e5d8a7 | 2010-11-17 16:06:43 +0000 | [diff] [blame] | 250 | |
Andrew Kaylor | ced4e8f | 2013-04-25 21:02:36 +0000 | [diff] [blame] | 251 | /// Sets the object manager that MCJIT should use to avoid compilation. |
Craig Topper | b51ff60 | 2014-03-08 07:51:20 +0000 | [diff] [blame] | 252 | void setObjectCache(ObjectCache *manager) override; |
Andrew Kaylor | ced4e8f | 2013-04-25 21:02:36 +0000 | [diff] [blame] | 253 | |
Craig Topper | b51ff60 | 2014-03-08 07:51:20 +0000 | [diff] [blame] | 254 | void generateCodeForModule(Module *M) override; |
Andrew Kaylor | ea39592 | 2013-10-01 01:47:35 +0000 | [diff] [blame] | 255 | |
David Tweed | 2e7efed | 2013-05-17 10:01:46 +0000 | [diff] [blame] | 256 | /// finalizeObject - ensure the module is fully processed and is usable. |
| 257 | /// |
| 258 | /// It is the user-level function for completing the process of making the |
| 259 | /// object usable for execution. It should be called after sections within an |
| 260 | /// object have been relocated using mapSectionAddress. When this method is |
| 261 | /// called the MCJIT execution engine will reapply relocations for a loaded |
| 262 | /// object. |
Yaron Keren | fb95582 | 2013-10-19 09:03:20 +0000 | [diff] [blame] | 263 | /// Is it OK to finalize a set of modules, add modules and finalize again. |
Andrew Kaylor | 2fb40ce | 2013-10-21 23:27:02 +0000 | [diff] [blame] | 264 | // FIXME: Do we really need both of these? |
Craig Topper | b51ff60 | 2014-03-08 07:51:20 +0000 | [diff] [blame] | 265 | void finalizeObject() override; |
Andrew Kaylor | ea39592 | 2013-10-01 01:47:35 +0000 | [diff] [blame] | 266 | virtual void finalizeModule(Module *); |
| 267 | void finalizeLoadedModules(); |
Andrew Kaylor | a714efc | 2012-11-05 20:57:16 +0000 | [diff] [blame] | 268 | |
Andrew Kaylor | c89fc82 | 2013-10-24 00:19:14 +0000 | [diff] [blame] | 269 | /// runStaticConstructorsDestructors - This method is used to execute all of |
| 270 | /// the static constructors or destructors for a program. |
| 271 | /// |
| 272 | /// \param isDtors - Run the destructors instead of constructors. |
Craig Topper | b51ff60 | 2014-03-08 07:51:20 +0000 | [diff] [blame] | 273 | void runStaticConstructorsDestructors(bool isDtors) override; |
Andrew Kaylor | c89fc82 | 2013-10-24 00:19:14 +0000 | [diff] [blame] | 274 | |
Craig Topper | b51ff60 | 2014-03-08 07:51:20 +0000 | [diff] [blame] | 275 | void *getPointerToBasicBlock(BasicBlock *BB) override; |
Daniel Dunbar | 7e5d8a7 | 2010-11-17 16:06:43 +0000 | [diff] [blame] | 276 | |
Craig Topper | b51ff60 | 2014-03-08 07:51:20 +0000 | [diff] [blame] | 277 | void *getPointerToFunction(Function *F) override; |
Daniel Dunbar | 7e5d8a7 | 2010-11-17 16:06:43 +0000 | [diff] [blame] | 278 | |
Craig Topper | b51ff60 | 2014-03-08 07:51:20 +0000 | [diff] [blame] | 279 | void *recompileAndRelinkFunction(Function *F) override; |
Daniel Dunbar | 7e5d8a7 | 2010-11-17 16:06:43 +0000 | [diff] [blame] | 280 | |
Craig Topper | b51ff60 | 2014-03-08 07:51:20 +0000 | [diff] [blame] | 281 | void freeMachineCodeForFunction(Function *F) override; |
Daniel Dunbar | 7e5d8a7 | 2010-11-17 16:06:43 +0000 | [diff] [blame] | 282 | |
Craig Topper | b51ff60 | 2014-03-08 07:51:20 +0000 | [diff] [blame] | 283 | GenericValue runFunction(Function *F, |
| 284 | const std::vector<GenericValue> &ArgValues) override; |
Daniel Dunbar | 7e5d8a7 | 2010-11-17 16:06:43 +0000 | [diff] [blame] | 285 | |
Jim Grosbach | d527440 | 2011-03-22 18:05:27 +0000 | [diff] [blame] | 286 | /// getPointerToNamedFunction - This method returns the address of the |
| 287 | /// specified function by using the dlsym function call. As such it is only |
| 288 | /// useful for resolving library symbols, not code generated symbols. |
| 289 | /// |
| 290 | /// If AbortOnFailure is false and no function with the given name is |
| 291 | /// found, this function silently returns a null pointer. Otherwise, |
| 292 | /// it prints a message to stderr and aborts. |
| 293 | /// |
Craig Topper | b51ff60 | 2014-03-08 07:51:20 +0000 | [diff] [blame] | 294 | void *getPointerToNamedFunction(const std::string &Name, |
| 295 | bool AbortOnFailure = true) override; |
Danil Malyshev | bfee542 | 2012-03-28 21:46:36 +0000 | [diff] [blame] | 296 | |
Jim Grosbach | 0ddb3a4 | 2012-01-16 23:50:55 +0000 | [diff] [blame] | 297 | /// mapSectionAddress - map a section to its target address space value. |
| 298 | /// Map the address of a JIT section as returned from the memory manager |
| 299 | /// to the address in the target process as the running code will see it. |
| 300 | /// This is the address which will be used for relocation resolution. |
Craig Topper | b51ff60 | 2014-03-08 07:51:20 +0000 | [diff] [blame] | 301 | void mapSectionAddress(const void *LocalAddress, |
| 302 | uint64_t TargetAddress) override { |
Jim Grosbach | 0ddb3a4 | 2012-01-16 23:50:55 +0000 | [diff] [blame] | 303 | Dyld.mapSectionAddress(LocalAddress, TargetAddress); |
| 304 | } |
Craig Topper | b51ff60 | 2014-03-08 07:51:20 +0000 | [diff] [blame] | 305 | void RegisterJITEventListener(JITEventListener *L) override; |
| 306 | void UnregisterJITEventListener(JITEventListener *L) override; |
Andrew Kaylor | d8ffd9c | 2012-11-06 18:51:59 +0000 | [diff] [blame] | 307 | |
Andrew Kaylor | ea39592 | 2013-10-01 01:47:35 +0000 | [diff] [blame] | 308 | // If successful, these function will implicitly finalize all loaded objects. |
| 309 | // To get a function address within MCJIT without causing a finalize, use |
| 310 | // getSymbolAddress. |
Craig Topper | b51ff60 | 2014-03-08 07:51:20 +0000 | [diff] [blame] | 311 | uint64_t getGlobalValueAddress(const std::string &Name) override; |
| 312 | uint64_t getFunctionAddress(const std::string &Name) override; |
Andrew Kaylor | ea39592 | 2013-10-01 01:47:35 +0000 | [diff] [blame] | 313 | |
Craig Topper | b51ff60 | 2014-03-08 07:51:20 +0000 | [diff] [blame] | 314 | TargetMachine *getTargetMachine() override { return TM; } |
Juergen Ributzka | 5fe955c | 2014-01-23 19:23:28 +0000 | [diff] [blame] | 315 | |
Daniel Dunbar | 7e5d8a7 | 2010-11-17 16:06:43 +0000 | [diff] [blame] | 316 | /// @} |
| 317 | /// @name (Private) Registration Interfaces |
| 318 | /// @{ |
| 319 | |
| 320 | static void Register() { |
| 321 | MCJITCtor = createJIT; |
| 322 | } |
| 323 | |
Daniel Dunbar | 7e5d8a7 | 2010-11-17 16:06:43 +0000 | [diff] [blame] | 324 | static ExecutionEngine *createJIT(Module *M, |
| 325 | std::string *ErrorStr, |
Filip Pizlo | 9bc53e8 | 2013-05-14 19:29:00 +0000 | [diff] [blame] | 326 | RTDyldMemoryManager *MemMgr, |
Daniel Dunbar | 7e5d8a7 | 2010-11-17 16:06:43 +0000 | [diff] [blame] | 327 | bool GVsWithCode, |
Dylan Noblesmith | 8418fdc | 2011-05-13 21:51:29 +0000 | [diff] [blame] | 328 | TargetMachine *TM); |
Daniel Dunbar | 7e5d8a7 | 2010-11-17 16:06:43 +0000 | [diff] [blame] | 329 | |
| 330 | // @} |
Andrew Kaylor | 1a568c3 | 2012-08-07 18:33:00 +0000 | [diff] [blame] | 331 | |
Andrew Kaylor | ea39592 | 2013-10-01 01:47:35 +0000 | [diff] [blame] | 332 | // This is not directly exposed via the ExecutionEngine API, but it is |
| 333 | // used by the LinkingMemoryManager. |
| 334 | uint64_t getSymbolAddress(const std::string &Name, |
| 335 | bool CheckFunctionsOnly); |
| 336 | |
Andrew Kaylor | 1a568c3 | 2012-08-07 18:33:00 +0000 | [diff] [blame] | 337 | protected: |
| 338 | /// emitObject -- Generate a JITed object in memory from the specified module |
| 339 | /// Currently, MCJIT only supports a single module and the module passed to |
| 340 | /// this function call is expected to be the contained module. The module |
NAKAMURA Takumi | 87e0880 | 2013-12-07 11:21:42 +0000 | [diff] [blame] | 341 | /// is passed as a parameter here to prepare for multiple module support in |
Andrew Kaylor | 1a568c3 | 2012-08-07 18:33:00 +0000 | [diff] [blame] | 342 | /// the future. |
Andrew Kaylor | ced4e8f | 2013-04-25 21:02:36 +0000 | [diff] [blame] | 343 | ObjectBufferStream* emitObject(Module *M); |
| 344 | |
Andrew Kaylor | d8ffd9c | 2012-11-06 18:51:59 +0000 | [diff] [blame] | 345 | void NotifyObjectEmitted(const ObjectImage& Obj); |
| 346 | void NotifyFreeingObject(const ObjectImage& Obj); |
Andrew Kaylor | ea39592 | 2013-10-01 01:47:35 +0000 | [diff] [blame] | 347 | |
| 348 | uint64_t getExistingSymbolAddress(const std::string &Name); |
| 349 | Module *findModuleForSymbol(const std::string &Name, |
| 350 | bool CheckFunctionsOnly); |
Daniel Dunbar | 7e5d8a7 | 2010-11-17 16:06:43 +0000 | [diff] [blame] | 351 | }; |
| 352 | |
| 353 | } // End llvm namespace |
| 354 | |
| 355 | #endif |