2012-11-14 20:18:34 +00:00
|
|
|
//===-- ObjectImageCommon.h - Format independent executuable object image -===//
|
|
|
|
//
|
2013-12-07 11:21:42 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
2012-11-14 20:18:34 +00: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.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_RUNTIMEDYLD_OBJECTIMAGECOMMON_H
|
|
|
|
#define LLVM_RUNTIMEDYLD_OBJECTIMAGECOMMON_H
|
|
|
|
|
|
|
|
#include "llvm/ExecutionEngine/ObjectBuffer.h"
|
2012-12-04 07:12:27 +00:00
|
|
|
#include "llvm/ExecutionEngine/ObjectImage.h"
|
|
|
|
#include "llvm/Object/ObjectFile.h"
|
2012-11-14 20:18:34 +00:00
|
|
|
|
2014-04-29 21:52:46 +00:00
|
|
|
#include <memory>
|
|
|
|
|
2012-11-14 20:18:34 +00:00
|
|
|
namespace llvm {
|
|
|
|
|
2014-01-08 04:09:09 +00:00
|
|
|
namespace object {
|
|
|
|
class ObjectFile;
|
|
|
|
}
|
|
|
|
|
2012-11-14 20:18:34 +00:00
|
|
|
class ObjectImageCommon : public ObjectImage {
|
|
|
|
ObjectImageCommon(); // = delete
|
|
|
|
ObjectImageCommon(const ObjectImageCommon &other); // = delete
|
2014-03-08 07:51:20 +00:00
|
|
|
void anchor() override;
|
2012-11-14 20:18:34 +00:00
|
|
|
|
|
|
|
protected:
|
2014-04-29 21:52:46 +00:00
|
|
|
std::unique_ptr<object::ObjectFile> ObjFile;
|
2012-11-14 20:18:34 +00:00
|
|
|
|
|
|
|
// This form of the constructor allows subclasses to use
|
|
|
|
// format-specific subclasses of ObjectFile directly
|
2014-04-29 21:52:46 +00:00
|
|
|
ObjectImageCommon(ObjectBuffer *Input, std::unique_ptr<object::ObjectFile> Obj)
|
2012-11-14 20:18:34 +00:00
|
|
|
: ObjectImage(Input), // saves Input as Buffer and takes ownership
|
2014-04-29 21:52:46 +00:00
|
|
|
ObjFile(std::move(Obj))
|
2012-11-14 20:18:34 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
ObjectImageCommon(ObjectBuffer* Input)
|
|
|
|
: ObjectImage(Input) // saves Input as Buffer and takes ownership
|
|
|
|
{
|
2014-04-29 21:52:46 +00:00
|
|
|
// FIXME: error checking? createObjectFile returns an ErrorOr<ObjectFile*>
|
|
|
|
// and should probably be checked for failure.
|
2014-06-23 22:00:37 +00:00
|
|
|
std::unique_ptr<MemoryBuffer> Buf(Buffer->getMemBuffer());
|
|
|
|
ObjFile.reset(object::ObjectFile::createObjectFile(Buf).get());
|
2012-11-14 20:18:34 +00:00
|
|
|
}
|
2014-04-29 21:52:46 +00:00
|
|
|
ObjectImageCommon(std::unique_ptr<object::ObjectFile> Input)
|
|
|
|
: ObjectImage(nullptr), ObjFile(std::move(Input)) {}
|
|
|
|
virtual ~ObjectImageCommon() { }
|
2012-11-14 20:18:34 +00:00
|
|
|
|
2014-03-08 07:51:20 +00: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-14 20:18:34 +00:00
|
|
|
|
2014-03-08 07:51:20 +00: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-14 20:18:34 +00:00
|
|
|
|
2014-03-08 07:51:20 +00:00
|
|
|
/* Triple::ArchType */ unsigned getArch() const override
|
|
|
|
{ return ObjFile->getArch(); }
|
2012-11-14 20:18:34 +00:00
|
|
|
|
2014-03-08 07:51:20 +00:00
|
|
|
StringRef getData() const override { return ObjFile->getData(); }
|
2012-11-14 20:18:34 +00:00
|
|
|
|
2014-04-29 21:52:46 +00:00
|
|
|
object::ObjectFile* getObjectFile() const override { return ObjFile.get(); }
|
2013-01-25 22:50:58 +00:00
|
|
|
|
2012-11-14 20:18:34 +00:00
|
|
|
// Subclasses can override these methods to update the image with loaded
|
|
|
|
// addresses for sections and common symbols
|
2014-03-08 07:51:20 +00:00
|
|
|
void updateSectionAddress(const object::SectionRef &Sec,
|
|
|
|
uint64_t Addr) override {}
|
|
|
|
void updateSymbolAddress(const object::SymbolRef &Sym,
|
|
|
|
uint64_t Addr) override {}
|
2012-11-14 20:18:34 +00:00
|
|
|
|
|
|
|
// Subclasses can override these methods to provide JIT debugging support
|
2014-03-08 07:51:20 +00:00
|
|
|
void registerWithDebugger() override {}
|
|
|
|
void deregisterWithDebugger() override {}
|
2012-11-14 20:18:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // end namespace llvm
|
|
|
|
|
|
|
|
#endif // LLVM_RUNTIMEDYLD_OBJECT_IMAGE_H
|