2012-11-15 04:18:34 +08:00
|
|
|
//===-- ObjectImageCommon.h - Format independent executuable object image -===//
|
|
|
|
//
|
2013-12-07 19:21:42 +08:00
|
|
|
// The LLVM Compiler Infrastructure
|
2012-11-15 04:18:34 +08:00
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file declares a file format independent ObjectImage class.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-08-14 00:26:38 +08:00
|
|
|
#ifndef LLVM_LIB_EXECUTIONENGINE_RUNTIMEDYLD_OBJECTIMAGECOMMON_H
|
|
|
|
#define LLVM_LIB_EXECUTIONENGINE_RUNTIMEDYLD_OBJECTIMAGECOMMON_H
|
2012-11-15 04:18:34 +08:00
|
|
|
|
|
|
|
#include "llvm/ExecutionEngine/ObjectBuffer.h"
|
2012-12-04 15:12:27 +08:00
|
|
|
#include "llvm/ExecutionEngine/ObjectImage.h"
|
|
|
|
#include "llvm/Object/ObjectFile.h"
|
2012-11-15 04:18:34 +08:00
|
|
|
|
2014-04-30 05:52:46 +08:00
|
|
|
#include <memory>
|
|
|
|
|
2012-11-15 04:18:34 +08:00
|
|
|
namespace llvm {
|
|
|
|
|
2014-01-08 12:09:09 +08:00
|
|
|
namespace object {
|
|
|
|
class ObjectFile;
|
|
|
|
}
|
|
|
|
|
2012-11-15 04:18:34 +08:00
|
|
|
class ObjectImageCommon : public ObjectImage {
|
|
|
|
ObjectImageCommon(); // = delete
|
|
|
|
ObjectImageCommon(const ObjectImageCommon &other); // = delete
|
2014-03-08 15:51:20 +08:00
|
|
|
void anchor() override;
|
2012-11-15 04:18:34 +08:00
|
|
|
|
|
|
|
protected:
|
2014-04-30 05:52:46 +08:00
|
|
|
std::unique_ptr<object::ObjectFile> ObjFile;
|
2012-11-15 04:18:34 +08:00
|
|
|
|
|
|
|
// This form of the constructor allows subclasses to use
|
|
|
|
// format-specific subclasses of ObjectFile directly
|
2014-04-30 05:52:46 +08:00
|
|
|
ObjectImageCommon(ObjectBuffer *Input, std::unique_ptr<object::ObjectFile> Obj)
|
2012-11-15 04:18:34 +08:00
|
|
|
: ObjectImage(Input), // saves Input as Buffer and takes ownership
|
2014-04-30 05:52:46 +08:00
|
|
|
ObjFile(std::move(Obj))
|
2012-11-15 04:18:34 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
ObjectImageCommon(ObjectBuffer* Input)
|
|
|
|
: ObjectImage(Input) // saves Input as Buffer and takes ownership
|
|
|
|
{
|
2014-04-30 05:52:46 +08:00
|
|
|
// FIXME: error checking? createObjectFile returns an ErrorOr<ObjectFile*>
|
|
|
|
// and should probably be checked for failure.
|
2014-06-24 06:00:37 +08:00
|
|
|
std::unique_ptr<MemoryBuffer> Buf(Buffer->getMemBuffer());
|
2014-07-31 11:12:45 +08:00
|
|
|
ObjFile = std::move(object::ObjectFile::createObjectFile(Buf).get());
|
2012-11-15 04:18:34 +08:00
|
|
|
}
|
2014-04-30 05:52:46 +08:00
|
|
|
ObjectImageCommon(std::unique_ptr<object::ObjectFile> Input)
|
|
|
|
: ObjectImage(nullptr), ObjFile(std::move(Input)) {}
|
|
|
|
virtual ~ObjectImageCommon() { }
|
2012-11-15 04:18:34 +08:00
|
|
|
|
2014-03-08 15:51:20 +08:00
|
|
|
object::symbol_iterator begin_symbols() const override
|
|
|
|
{ return ObjFile->symbol_begin(); }
|
|
|
|
object::symbol_iterator end_symbols() const override
|
|
|
|
{ return ObjFile->symbol_end(); }
|
2012-11-15 04:18:34 +08:00
|
|
|
|
2014-03-08 15:51:20 +08:00
|
|
|
object::section_iterator begin_sections() const override
|
|
|
|
{ return ObjFile->section_begin(); }
|
|
|
|
object::section_iterator end_sections() const override
|
|
|
|
{ return ObjFile->section_end(); }
|
2012-11-15 04:18:34 +08:00
|
|
|
|
2014-03-08 15:51:20 +08:00
|
|
|
/* Triple::ArchType */ unsigned getArch() const override
|
|
|
|
{ return ObjFile->getArch(); }
|
2012-11-15 04:18:34 +08:00
|
|
|
|
2014-03-08 15:51:20 +08:00
|
|
|
StringRef getData() const override { return ObjFile->getData(); }
|
2012-11-15 04:18:34 +08:00
|
|
|
|
2014-04-30 05:52:46 +08:00
|
|
|
object::ObjectFile* getObjectFile() const override { return ObjFile.get(); }
|
2013-01-26 06:50:58 +08:00
|
|
|
|
2012-11-15 04:18:34 +08:00
|
|
|
// Subclasses can override these methods to update the image with loaded
|
|
|
|
// addresses for sections and common symbols
|
2014-03-08 15:51:20 +08:00
|
|
|
void updateSectionAddress(const object::SectionRef &Sec,
|
|
|
|
uint64_t Addr) override {}
|
|
|
|
void updateSymbolAddress(const object::SymbolRef &Sym,
|
|
|
|
uint64_t Addr) override {}
|
2012-11-15 04:18:34 +08:00
|
|
|
|
|
|
|
// Subclasses can override these methods to provide JIT debugging support
|
2014-03-08 15:51:20 +08:00
|
|
|
void registerWithDebugger() override {}
|
|
|
|
void deregisterWithDebugger() override {}
|
2012-11-15 04:18:34 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
} // end namespace llvm
|
|
|
|
|
2014-08-14 00:26:38 +08:00
|
|
|
#endif
|