Jakub Staszak | de7c853 | 2012-11-14 20:18:34 +0000 | [diff] [blame] | 1 | //===-- ObjectImageCommon.h - Format independent executuable object image -===// |
| 2 | // |
Stephen Hines | 36b5688 | 2014-04-23 16:57:46 -0700 | [diff] [blame^] | 3 | // The LLVM Compiler Infrastructure |
Jakub Staszak | de7c853 | 2012-11-14 20:18:34 +0000 | [diff] [blame] | 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file declares a file format independent ObjectImage class. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #ifndef LLVM_RUNTIMEDYLD_OBJECTIMAGECOMMON_H |
| 15 | #define LLVM_RUNTIMEDYLD_OBJECTIMAGECOMMON_H |
| 16 | |
Jakub Staszak | de7c853 | 2012-11-14 20:18:34 +0000 | [diff] [blame] | 17 | #include "llvm/ExecutionEngine/ObjectBuffer.h" |
Chandler Carruth | a1514e2 | 2012-12-04 07:12:27 +0000 | [diff] [blame] | 18 | #include "llvm/ExecutionEngine/ObjectImage.h" |
| 19 | #include "llvm/Object/ObjectFile.h" |
Jakub Staszak | de7c853 | 2012-11-14 20:18:34 +0000 | [diff] [blame] | 20 | |
| 21 | namespace llvm { |
| 22 | |
Stephen Hines | 36b5688 | 2014-04-23 16:57:46 -0700 | [diff] [blame^] | 23 | namespace object { |
| 24 | class ObjectFile; |
| 25 | } |
| 26 | |
Jakub Staszak | de7c853 | 2012-11-14 20:18:34 +0000 | [diff] [blame] | 27 | class ObjectImageCommon : public ObjectImage { |
| 28 | ObjectImageCommon(); // = delete |
| 29 | ObjectImageCommon(const ObjectImageCommon &other); // = delete |
Stephen Hines | 36b5688 | 2014-04-23 16:57:46 -0700 | [diff] [blame^] | 30 | void anchor() override; |
Jakub Staszak | de7c853 | 2012-11-14 20:18:34 +0000 | [diff] [blame] | 31 | |
| 32 | protected: |
| 33 | object::ObjectFile *ObjFile; |
| 34 | |
| 35 | // This form of the constructor allows subclasses to use |
| 36 | // format-specific subclasses of ObjectFile directly |
| 37 | ObjectImageCommon(ObjectBuffer *Input, object::ObjectFile *Obj) |
| 38 | : ObjectImage(Input), // saves Input as Buffer and takes ownership |
| 39 | ObjFile(Obj) |
| 40 | { |
| 41 | } |
| 42 | |
| 43 | public: |
| 44 | ObjectImageCommon(ObjectBuffer* Input) |
| 45 | : ObjectImage(Input) // saves Input as Buffer and takes ownership |
| 46 | { |
Stephen Hines | 36b5688 | 2014-04-23 16:57:46 -0700 | [diff] [blame^] | 47 | ObjFile = |
| 48 | object::ObjectFile::createObjectFile(Buffer->getMemBuffer()).get(); |
Jakub Staszak | de7c853 | 2012-11-14 20:18:34 +0000 | [diff] [blame] | 49 | } |
Stephen Hines | 36b5688 | 2014-04-23 16:57:46 -0700 | [diff] [blame^] | 50 | ObjectImageCommon(object::ObjectFile* Input) |
| 51 | : ObjectImage(NULL), ObjFile(Input) {} |
Jakub Staszak | de7c853 | 2012-11-14 20:18:34 +0000 | [diff] [blame] | 52 | virtual ~ObjectImageCommon() { delete ObjFile; } |
| 53 | |
Stephen Hines | 36b5688 | 2014-04-23 16:57:46 -0700 | [diff] [blame^] | 54 | object::symbol_iterator begin_symbols() const override |
| 55 | { return ObjFile->symbol_begin(); } |
| 56 | object::symbol_iterator end_symbols() const override |
| 57 | { return ObjFile->symbol_end(); } |
Jakub Staszak | de7c853 | 2012-11-14 20:18:34 +0000 | [diff] [blame] | 58 | |
Stephen Hines | 36b5688 | 2014-04-23 16:57:46 -0700 | [diff] [blame^] | 59 | object::section_iterator begin_sections() const override |
| 60 | { return ObjFile->section_begin(); } |
| 61 | object::section_iterator end_sections() const override |
| 62 | { return ObjFile->section_end(); } |
Jakub Staszak | de7c853 | 2012-11-14 20:18:34 +0000 | [diff] [blame] | 63 | |
Stephen Hines | 36b5688 | 2014-04-23 16:57:46 -0700 | [diff] [blame^] | 64 | /* Triple::ArchType */ unsigned getArch() const override |
| 65 | { return ObjFile->getArch(); } |
Jakub Staszak | de7c853 | 2012-11-14 20:18:34 +0000 | [diff] [blame] | 66 | |
Stephen Hines | 36b5688 | 2014-04-23 16:57:46 -0700 | [diff] [blame^] | 67 | StringRef getData() const override { return ObjFile->getData(); } |
Jakub Staszak | de7c853 | 2012-11-14 20:18:34 +0000 | [diff] [blame] | 68 | |
Stephen Hines | 36b5688 | 2014-04-23 16:57:46 -0700 | [diff] [blame^] | 69 | object::ObjectFile* getObjectFile() const override { return ObjFile; } |
Andrew Kaylor | ee7c0d2 | 2013-01-25 22:50:58 +0000 | [diff] [blame] | 70 | |
Jakub Staszak | de7c853 | 2012-11-14 20:18:34 +0000 | [diff] [blame] | 71 | // Subclasses can override these methods to update the image with loaded |
| 72 | // addresses for sections and common symbols |
Stephen Hines | 36b5688 | 2014-04-23 16:57:46 -0700 | [diff] [blame^] | 73 | void updateSectionAddress(const object::SectionRef &Sec, |
| 74 | uint64_t Addr) override {} |
| 75 | void updateSymbolAddress(const object::SymbolRef &Sym, |
| 76 | uint64_t Addr) override {} |
Jakub Staszak | de7c853 | 2012-11-14 20:18:34 +0000 | [diff] [blame] | 77 | |
| 78 | // Subclasses can override these methods to provide JIT debugging support |
Stephen Hines | 36b5688 | 2014-04-23 16:57:46 -0700 | [diff] [blame^] | 79 | void registerWithDebugger() override {} |
| 80 | void deregisterWithDebugger() override {} |
Jakub Staszak | de7c853 | 2012-11-14 20:18:34 +0000 | [diff] [blame] | 81 | }; |
| 82 | |
| 83 | } // end namespace llvm |
| 84 | |
| 85 | #endif // LLVM_RUNTIMEDYLD_OBJECT_IMAGE_H |