LLVM API Documentation

ObjectImageCommon.h
Go to the documentation of this file.
00001 //===-- ObjectImageCommon.h - Format independent executuable object image -===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file declares a file format independent ObjectImage class.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #ifndef LLVM_LIB_EXECUTIONENGINE_RUNTIMEDYLD_OBJECTIMAGECOMMON_H
00015 #define LLVM_LIB_EXECUTIONENGINE_RUNTIMEDYLD_OBJECTIMAGECOMMON_H
00016 
00017 #include "llvm/ExecutionEngine/ObjectBuffer.h"
00018 #include "llvm/ExecutionEngine/ObjectImage.h"
00019 #include "llvm/Object/ObjectFile.h"
00020 
00021 #include <memory>
00022 
00023 namespace llvm {
00024 
00025 namespace object {
00026   class ObjectFile;
00027 }
00028 
00029 class ObjectImageCommon : public ObjectImage {
00030   ObjectImageCommon(); // = delete
00031   ObjectImageCommon(const ObjectImageCommon &other); // = delete
00032   void anchor() override;
00033 
00034 protected:
00035   std::unique_ptr<object::ObjectFile> ObjFile;
00036 
00037   // This form of the constructor allows subclasses to use
00038   // format-specific subclasses of ObjectFile directly
00039   ObjectImageCommon(std::unique_ptr<ObjectBuffer> Input,
00040                     std::unique_ptr<object::ObjectFile> Obj)
00041       : ObjectImage(std::move(Input)), ObjFile(std::move(Obj)) {}
00042 
00043 public:
00044   ObjectImageCommon(std::unique_ptr<ObjectBuffer> Input)
00045       : ObjectImage(std::move(Input)) {
00046     // FIXME: error checking? createObjectFile returns an ErrorOr<ObjectFile*>
00047     // and should probably be checked for failure.
00048     MemoryBufferRef Buf = Buffer->getMemBuffer();
00049     ObjFile = std::move(object::ObjectFile::createObjectFile(Buf).get());
00050   }
00051   ObjectImageCommon(std::unique_ptr<object::ObjectFile> Input)
00052   : ObjectImage(nullptr), ObjFile(std::move(Input))  {}
00053   virtual ~ObjectImageCommon() { }
00054 
00055   object::symbol_iterator begin_symbols() const override
00056       { return ObjFile->symbol_begin(); }
00057   object::symbol_iterator end_symbols() const override
00058       { return ObjFile->symbol_end(); }
00059 
00060   object::section_iterator begin_sections() const override
00061       { return ObjFile->section_begin(); }
00062   object::section_iterator end_sections() const override
00063       { return ObjFile->section_end(); }
00064 
00065   /* Triple::ArchType */ unsigned getArch() const override
00066       { return ObjFile->getArch(); }
00067 
00068   StringRef getData() const override { return ObjFile->getData(); }
00069 
00070   object::ObjectFile* getObjectFile() const override { return ObjFile.get(); }
00071 
00072   // Subclasses can override these methods to update the image with loaded
00073   // addresses for sections and common symbols
00074   void updateSectionAddress(const object::SectionRef &Sec,
00075                             uint64_t Addr) override {}
00076   void updateSymbolAddress(const object::SymbolRef &Sym,
00077                            uint64_t Addr) override {}
00078 
00079   // Subclasses can override these methods to provide JIT debugging support
00080   void registerWithDebugger() override {}
00081   void deregisterWithDebugger() override {}
00082 };
00083 
00084 } // end namespace llvm
00085 
00086 #endif