1 //===-- ObjectImageCommon.h - Format independent executuable object image -===// 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 // 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 17 #include "llvm/ExecutionEngine/ObjectBuffer.h" 18 #include "llvm/ExecutionEngine/ObjectImage.h" 19 #include "llvm/Object/ObjectFile.h" 20 21 #include <memory> 22 23 namespace llvm { 24 25 namespace object { 26 class ObjectFile; 27 } 28 29 class ObjectImageCommon : public ObjectImage { 30 ObjectImageCommon(); // = delete 31 ObjectImageCommon(const ObjectImageCommon &other); // = delete 32 void anchor() override; 33 34 protected: 35 std::unique_ptr<object::ObjectFile> ObjFile; 36 37 // This form of the constructor allows subclasses to use 38 // format-specific subclasses of ObjectFile directly ObjectImageCommon(ObjectBuffer * Input,std::unique_ptr<object::ObjectFile> Obj)39 ObjectImageCommon(ObjectBuffer *Input, std::unique_ptr<object::ObjectFile> Obj) 40 : ObjectImage(Input), // saves Input as Buffer and takes ownership 41 ObjFile(std::move(Obj)) 42 { 43 } 44 45 public: ObjectImageCommon(ObjectBuffer * Input)46 ObjectImageCommon(ObjectBuffer* Input) 47 : ObjectImage(Input) // saves Input as Buffer and takes ownership 48 { 49 // FIXME: error checking? createObjectFile returns an ErrorOr<ObjectFile*> 50 // and should probably be checked for failure. 51 std::unique_ptr<MemoryBuffer> Buf(Buffer->getMemBuffer()); 52 ObjFile.reset(object::ObjectFile::createObjectFile(Buf).get()); 53 } ObjectImageCommon(std::unique_ptr<object::ObjectFile> Input)54 ObjectImageCommon(std::unique_ptr<object::ObjectFile> Input) 55 : ObjectImage(nullptr), ObjFile(std::move(Input)) {} ~ObjectImageCommon()56 virtual ~ObjectImageCommon() { } 57 begin_symbols()58 object::symbol_iterator begin_symbols() const override 59 { return ObjFile->symbol_begin(); } end_symbols()60 object::symbol_iterator end_symbols() const override 61 { return ObjFile->symbol_end(); } 62 begin_sections()63 object::section_iterator begin_sections() const override 64 { return ObjFile->section_begin(); } end_sections()65 object::section_iterator end_sections() const override 66 { return ObjFile->section_end(); } 67 getArch()68 /* Triple::ArchType */ unsigned getArch() const override 69 { return ObjFile->getArch(); } 70 getData()71 StringRef getData() const override { return ObjFile->getData(); } 72 getObjectFile()73 object::ObjectFile* getObjectFile() const override { return ObjFile.get(); } 74 75 // Subclasses can override these methods to update the image with loaded 76 // addresses for sections and common symbols updateSectionAddress(const object::SectionRef & Sec,uint64_t Addr)77 void updateSectionAddress(const object::SectionRef &Sec, 78 uint64_t Addr) override {} updateSymbolAddress(const object::SymbolRef & Sym,uint64_t Addr)79 void updateSymbolAddress(const object::SymbolRef &Sym, 80 uint64_t Addr) override {} 81 82 // Subclasses can override these methods to provide JIT debugging support registerWithDebugger()83 void registerWithDebugger() override {} deregisterWithDebugger()84 void deregisterWithDebugger() override {} 85 }; 86 87 } // end namespace llvm 88 89 #endif // LLVM_RUNTIMEDYLD_OBJECT_IMAGE_H 90