1 //===-- ObjectImageCommon.h - Format independent executuable object image -===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file declares a file format independent ObjectImage class.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_LIB_EXECUTIONENGINE_RUNTIMEDYLD_OBJECTIMAGECOMMON_H
15 #define LLVM_LIB_EXECUTIONENGINE_RUNTIMEDYLD_OBJECTIMAGECOMMON_H
17 #include "llvm/ExecutionEngine/ObjectBuffer.h"
18 #include "llvm/ExecutionEngine/ObjectImage.h"
19 #include "llvm/Object/ObjectFile.h"
29 class ObjectImageCommon : public ObjectImage {
30 ObjectImageCommon(); // = delete
31 ObjectImageCommon(const ObjectImageCommon &other); // = delete
32 void anchor() override;
35 std::unique_ptr<object::ObjectFile> ObjFile;
37 // This form of the constructor allows subclasses to use
38 // format-specific subclasses of ObjectFile directly
39 ObjectImageCommon(std::unique_ptr<ObjectBuffer> Input,
40 std::unique_ptr<object::ObjectFile> Obj)
41 : ObjectImage(std::move(Input)), ObjFile(std::move(Obj)) {}
44 ObjectImageCommon(std::unique_ptr<ObjectBuffer> Input)
45 : ObjectImage(std::move(Input)) {
46 // FIXME: error checking? createObjectFile returns an ErrorOr<ObjectFile*>
47 // and should probably be checked for failure.
48 MemoryBufferRef Buf = Buffer->getMemBuffer();
49 ObjFile = std::move(object::ObjectFile::createObjectFile(Buf).get());
51 ObjectImageCommon(std::unique_ptr<object::ObjectFile> Input)
52 : ObjectImage(nullptr), ObjFile(std::move(Input)) {}
53 virtual ~ObjectImageCommon() { }
55 object::symbol_iterator begin_symbols() const override
56 { return ObjFile->symbol_begin(); }
57 object::symbol_iterator end_symbols() const override
58 { return ObjFile->symbol_end(); }
60 object::section_iterator begin_sections() const override
61 { return ObjFile->section_begin(); }
62 object::section_iterator end_sections() const override
63 { return ObjFile->section_end(); }
65 /* Triple::ArchType */ unsigned getArch() const override
66 { return ObjFile->getArch(); }
68 StringRef getData() const override { return ObjFile->getData(); }
70 object::ObjectFile* getObjectFile() const override { return ObjFile.get(); }
72 // Subclasses can override these methods to update the image with loaded
73 // addresses for sections and common symbols
74 void updateSectionAddress(const object::SectionRef &Sec,
75 uint64_t Addr) override {}
76 void updateSymbolAddress(const object::SymbolRef &Sym,
77 uint64_t Addr) override {}
79 // Subclasses can override these methods to provide JIT debugging support
80 void registerWithDebugger() override {}
81 void deregisterWithDebugger() override {}
84 } // end namespace llvm