2010-11-15 03:21:41 +00:00
|
|
|
//===- ObjectFile.h - File format independent object file -------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file declares a file format independent ObjectFile class.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2013-01-10 00:45:19 +00:00
|
|
|
#ifndef LLVM_OBJECT_OBJECTFILE_H
|
|
|
|
#define LLVM_OBJECT_OBJECTFILE_H
|
2010-11-15 03:21:41 +00:00
|
|
|
|
2010-11-16 01:06:51 +00:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
2014-02-21 20:10:59 +00:00
|
|
|
#include "llvm/Object/SymbolicFile.h"
|
2010-11-29 18:16:10 +00:00
|
|
|
#include "llvm/Support/DataTypes.h"
|
2011-06-25 17:55:23 +00:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2014-01-22 16:04:52 +00:00
|
|
|
#include "llvm/Support/FileSystem.h"
|
2011-06-25 17:54:50 +00:00
|
|
|
#include "llvm/Support/MemoryBuffer.h"
|
2011-01-21 02:27:02 +00:00
|
|
|
#include <cstring>
|
2012-01-22 09:01:03 +00:00
|
|
|
#include <vector>
|
2010-11-15 03:21:41 +00:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
namespace object {
|
|
|
|
|
|
|
|
class ObjectFile;
|
2011-01-21 02:27:02 +00:00
|
|
|
|
2011-10-17 23:54:46 +00:00
|
|
|
class SymbolRef;
|
2014-02-21 20:10:59 +00:00
|
|
|
class symbol_iterator;
|
2010-11-15 03:21:41 +00:00
|
|
|
|
2011-09-08 20:52:17 +00:00
|
|
|
/// RelocationRef - This is a value type class that represents a single
|
|
|
|
/// relocation in the list of relocations in the object file.
|
|
|
|
class RelocationRef {
|
|
|
|
DataRefImpl RelocationPimpl;
|
|
|
|
const ObjectFile *OwningObject;
|
|
|
|
|
|
|
|
public:
|
2012-04-10 01:54:44 +00:00
|
|
|
RelocationRef() : OwningObject(NULL) { }
|
2011-09-08 20:52:17 +00:00
|
|
|
|
|
|
|
RelocationRef(DataRefImpl RelocationP, const ObjectFile *Owner);
|
|
|
|
|
|
|
|
bool operator==(const RelocationRef &Other) const;
|
|
|
|
|
2014-01-30 02:49:50 +00:00
|
|
|
void moveNext();
|
2011-09-08 20:52:17 +00:00
|
|
|
|
|
|
|
error_code getAddress(uint64_t &Result) const;
|
2011-11-29 17:40:10 +00:00
|
|
|
error_code getOffset(uint64_t &Result) const;
|
2013-06-05 01:33:53 +00:00
|
|
|
symbol_iterator getSymbol() const;
|
2011-10-26 17:08:49 +00:00
|
|
|
error_code getType(uint64_t &Result) const;
|
2011-10-07 19:25:32 +00:00
|
|
|
|
2011-10-25 20:35:53 +00:00
|
|
|
/// @brief Indicates whether this relocation should hidden when listing
|
|
|
|
/// relocations, usually because it is the trailing part of a multipart
|
|
|
|
/// relocation that will be printed as part of the leading relocation.
|
|
|
|
error_code getHidden(bool &Result) const;
|
|
|
|
|
2011-10-07 19:25:32 +00:00
|
|
|
/// @brief Get a string that represents the type of this relocation.
|
|
|
|
///
|
|
|
|
/// This is for display purposes only.
|
|
|
|
error_code getTypeName(SmallVectorImpl<char> &Result) const;
|
|
|
|
|
|
|
|
/// @brief Get a string that represents the calculation of the value of this
|
|
|
|
/// relocation.
|
|
|
|
///
|
|
|
|
/// This is for display purposes only.
|
|
|
|
error_code getValueString(SmallVectorImpl<char> &Result) const;
|
2012-06-18 19:47:16 +00:00
|
|
|
|
|
|
|
DataRefImpl getRawDataRefImpl() const;
|
2013-05-09 03:39:05 +00:00
|
|
|
const ObjectFile *getObjectFile() const;
|
2011-09-08 20:52:17 +00:00
|
|
|
};
|
2011-10-07 19:25:32 +00:00
|
|
|
typedef content_iterator<RelocationRef> relocation_iterator;
|
2011-09-08 20:52:17 +00:00
|
|
|
|
2010-11-15 03:21:41 +00:00
|
|
|
/// SectionRef - This is a value type class that represents a single section in
|
|
|
|
/// the list of sections in the object file.
|
2013-05-30 03:05:14 +00:00
|
|
|
class SectionRef;
|
|
|
|
typedef content_iterator<SectionRef> section_iterator;
|
2010-11-15 03:21:41 +00:00
|
|
|
class SectionRef {
|
2011-07-15 18:39:21 +00:00
|
|
|
friend class SymbolRef;
|
2010-11-15 03:21:41 +00:00
|
|
|
DataRefImpl SectionPimpl;
|
|
|
|
const ObjectFile *OwningObject;
|
|
|
|
|
|
|
|
public:
|
2012-04-10 01:54:44 +00:00
|
|
|
SectionRef() : OwningObject(NULL) { }
|
2011-07-05 14:49:08 +00:00
|
|
|
|
2010-11-15 03:21:41 +00:00
|
|
|
SectionRef(DataRefImpl SectionP, const ObjectFile *Owner);
|
|
|
|
|
|
|
|
bool operator==(const SectionRef &Other) const;
|
2012-10-10 22:37:01 +00:00
|
|
|
bool operator<(const SectionRef &Other) const;
|
2010-11-15 03:21:41 +00:00
|
|
|
|
2014-01-30 02:49:50 +00:00
|
|
|
void moveNext();
|
2010-11-15 03:21:41 +00:00
|
|
|
|
2011-06-25 17:55:23 +00:00
|
|
|
error_code getName(StringRef &Result) const;
|
|
|
|
error_code getAddress(uint64_t &Result) const;
|
|
|
|
error_code getSize(uint64_t &Result) const;
|
|
|
|
error_code getContents(StringRef &Result) const;
|
2010-11-15 03:21:41 +00:00
|
|
|
|
2011-10-10 21:55:43 +00:00
|
|
|
/// @brief Get the alignment of this section as the actual value (not log 2).
|
|
|
|
error_code getAlignment(uint64_t &Result) const;
|
|
|
|
|
2010-11-15 03:21:41 +00:00
|
|
|
// FIXME: Move to the normalization layer when it's created.
|
2011-06-25 17:55:23 +00:00
|
|
|
error_code isText(bool &Result) const;
|
2011-09-28 20:57:30 +00:00
|
|
|
error_code isData(bool &Result) const;
|
|
|
|
error_code isBSS(bool &Result) const;
|
2012-04-12 20:13:57 +00:00
|
|
|
error_code isRequiredForExecution(bool &Result) const;
|
|
|
|
error_code isVirtual(bool &Result) const;
|
|
|
|
error_code isZeroInit(bool &Result) const;
|
2012-10-10 01:41:33 +00:00
|
|
|
error_code isReadOnlyData(bool &Result) const;
|
2011-07-15 18:39:21 +00:00
|
|
|
|
|
|
|
error_code containsSymbol(SymbolRef S, bool &Result) const;
|
2011-10-07 19:25:32 +00:00
|
|
|
|
2014-02-10 20:24:04 +00:00
|
|
|
relocation_iterator relocation_begin() const;
|
|
|
|
relocation_iterator relocation_end() const;
|
2013-05-30 03:05:14 +00:00
|
|
|
section_iterator getRelocatedSection() const;
|
2012-04-12 20:13:57 +00:00
|
|
|
|
|
|
|
DataRefImpl getRawDataRefImpl() const;
|
2010-11-15 03:21:41 +00:00
|
|
|
};
|
|
|
|
|
2011-10-17 23:54:46 +00:00
|
|
|
/// SymbolRef - This is a value type class that represents a single symbol in
|
|
|
|
/// the list of symbols in the object file.
|
2014-02-21 20:10:59 +00:00
|
|
|
class SymbolRef : public BasicSymbolRef {
|
2011-10-17 23:54:46 +00:00
|
|
|
friend class SectionRef;
|
|
|
|
|
|
|
|
public:
|
2014-02-21 20:10:59 +00:00
|
|
|
SymbolRef() : BasicSymbolRef() {}
|
2011-10-17 23:54:46 +00:00
|
|
|
|
|
|
|
enum Type {
|
2012-02-29 02:11:55 +00:00
|
|
|
ST_Unknown, // Type not specified
|
2011-10-17 23:54:46 +00:00
|
|
|
ST_Data,
|
2011-10-17 23:55:06 +00:00
|
|
|
ST_Debug,
|
|
|
|
ST_File,
|
|
|
|
ST_Function,
|
2011-10-17 23:54:46 +00:00
|
|
|
ST_Other
|
|
|
|
};
|
|
|
|
|
|
|
|
SymbolRef(DataRefImpl SymbolP, const ObjectFile *Owner);
|
|
|
|
|
|
|
|
error_code getName(StringRef &Result) const;
|
2012-09-21 07:08:08 +00:00
|
|
|
/// Returns the symbol virtual address (i.e. address at which it will be
|
|
|
|
/// mapped).
|
2011-10-17 23:54:46 +00:00
|
|
|
error_code getAddress(uint64_t &Result) const;
|
2011-11-29 17:40:10 +00:00
|
|
|
error_code getFileOffset(uint64_t &Result) const;
|
2013-04-29 22:24:22 +00:00
|
|
|
/// @brief Get the alignment of this symbol as the actual value (not log 2).
|
|
|
|
error_code getAlignment(uint32_t &Result) const;
|
2011-10-17 23:54:46 +00:00
|
|
|
error_code getSize(uint64_t &Result) const;
|
|
|
|
error_code getType(SymbolRef::Type &Result) const;
|
|
|
|
|
|
|
|
/// @brief Get section this symbol is defined in reference to. Result is
|
|
|
|
/// end_sections() if it is undefined or is an absolute symbol.
|
|
|
|
error_code getSection(section_iterator &Result) const;
|
|
|
|
|
2012-10-29 10:47:00 +00:00
|
|
|
/// @brief Get value of the symbol in the symbol table.
|
|
|
|
error_code getValue(uint64_t &Val) const;
|
|
|
|
|
2014-02-21 20:10:59 +00:00
|
|
|
const ObjectFile *getObject() const;
|
|
|
|
};
|
|
|
|
|
|
|
|
class symbol_iterator : public basic_symbol_iterator {
|
|
|
|
public:
|
|
|
|
symbol_iterator(SymbolRef Sym) : basic_symbol_iterator(Sym) {}
|
|
|
|
symbol_iterator(const basic_symbol_iterator &B)
|
|
|
|
: basic_symbol_iterator(SymbolRef(B->getRawDataRefImpl(),
|
|
|
|
cast<ObjectFile>(B->getObject()))) {}
|
|
|
|
|
|
|
|
const SymbolRef *operator->() const {
|
|
|
|
const BasicSymbolRef &P = basic_symbol_iterator::operator *();
|
|
|
|
return static_cast<const SymbolRef*>(&P);
|
|
|
|
}
|
|
|
|
|
|
|
|
const SymbolRef &operator*() const {
|
|
|
|
const BasicSymbolRef &P = basic_symbol_iterator::operator *();
|
|
|
|
return static_cast<const SymbolRef&>(P);
|
|
|
|
}
|
2011-10-17 23:54:46 +00:00
|
|
|
};
|
|
|
|
|
2012-03-01 01:36:50 +00:00
|
|
|
/// LibraryRef - This is a value type class that represents a single library in
|
|
|
|
/// the list of libraries needed by a shared or dynamic object.
|
|
|
|
class LibraryRef {
|
|
|
|
friend class SectionRef;
|
|
|
|
DataRefImpl LibraryPimpl;
|
|
|
|
const ObjectFile *OwningObject;
|
|
|
|
|
|
|
|
public:
|
2012-04-10 01:54:44 +00:00
|
|
|
LibraryRef() : OwningObject(NULL) { }
|
2012-03-01 01:36:50 +00:00
|
|
|
|
|
|
|
LibraryRef(DataRefImpl LibraryP, const ObjectFile *Owner);
|
|
|
|
|
|
|
|
bool operator==(const LibraryRef &Other) const;
|
2012-10-10 22:37:01 +00:00
|
|
|
bool operator<(const LibraryRef &Other) const;
|
2012-03-01 01:36:50 +00:00
|
|
|
|
|
|
|
error_code getNext(LibraryRef &Result) const;
|
|
|
|
|
|
|
|
// Get the path to this library, as stored in the object file.
|
|
|
|
error_code getPath(StringRef &Result) const;
|
|
|
|
|
|
|
|
DataRefImpl getRawDataRefImpl() const;
|
|
|
|
};
|
|
|
|
typedef content_iterator<LibraryRef> library_iterator;
|
|
|
|
|
2010-11-15 03:21:41 +00:00
|
|
|
/// ObjectFile - This class is the base class for all object file types.
|
|
|
|
/// Concrete instances of this object are created by createObjectFile, which
|
2012-10-19 22:10:54 +00:00
|
|
|
/// figures out which type to create.
|
2014-02-21 20:10:59 +00:00
|
|
|
class ObjectFile : public SymbolicFile {
|
2011-12-20 02:50:00 +00:00
|
|
|
virtual void anchor();
|
2012-09-17 07:16:40 +00:00
|
|
|
ObjectFile() LLVM_DELETED_FUNCTION;
|
|
|
|
ObjectFile(const ObjectFile &other) LLVM_DELETED_FUNCTION;
|
2010-11-15 03:21:41 +00:00
|
|
|
|
|
|
|
protected:
|
2014-01-24 21:32:21 +00:00
|
|
|
ObjectFile(unsigned int Type, MemoryBuffer *Source, bool BufferOwned = true);
|
2010-11-15 03:21:41 +00:00
|
|
|
|
2011-06-25 17:54:50 +00:00
|
|
|
const uint8_t *base() const {
|
|
|
|
return reinterpret_cast<const uint8_t *>(Data->getBufferStart());
|
|
|
|
}
|
2010-11-15 03:21:41 +00:00
|
|
|
|
|
|
|
// These functions are for SymbolRef to call internally. The main goal of
|
|
|
|
// this is to allow SymbolRef::SymbolPimpl to point directly to the symbol
|
|
|
|
// entry in the memory mapped object file. SymbolPimpl cannot contain any
|
|
|
|
// virtual functions because then it could not point into the memory mapped
|
|
|
|
// file.
|
2011-06-25 17:55:23 +00:00
|
|
|
//
|
|
|
|
// Implementations assume that the DataRefImpl is valid and has not been
|
|
|
|
// modified externally. It's UB otherwise.
|
2010-11-15 03:21:41 +00:00
|
|
|
friend class SymbolRef;
|
2011-06-25 17:55:23 +00:00
|
|
|
virtual error_code getSymbolName(DataRefImpl Symb, StringRef &Res) const = 0;
|
2014-03-05 07:52:44 +00:00
|
|
|
error_code printSymbolName(raw_ostream &OS, DataRefImpl Symb) const override;
|
2012-10-10 22:37:01 +00:00
|
|
|
virtual error_code getSymbolAddress(DataRefImpl Symb, uint64_t &Res) const = 0;
|
|
|
|
virtual error_code getSymbolFileOffset(DataRefImpl Symb, uint64_t &Res)const=0;
|
2013-04-29 22:24:22 +00:00
|
|
|
virtual error_code getSymbolAlignment(DataRefImpl Symb, uint32_t &Res) const;
|
2011-06-25 17:55:23 +00:00
|
|
|
virtual error_code getSymbolSize(DataRefImpl Symb, uint64_t &Res) const = 0;
|
2011-10-17 23:37:43 +00:00
|
|
|
virtual error_code getSymbolType(DataRefImpl Symb,
|
|
|
|
SymbolRef::Type &Res) const = 0;
|
2011-10-17 23:54:46 +00:00
|
|
|
virtual error_code getSymbolSection(DataRefImpl Symb,
|
|
|
|
section_iterator &Res) const = 0;
|
2012-10-29 10:47:00 +00:00
|
|
|
virtual error_code getSymbolValue(DataRefImpl Symb, uint64_t &Val) const = 0;
|
2010-11-15 03:21:41 +00:00
|
|
|
|
|
|
|
// Same as above for SectionRef.
|
|
|
|
friend class SectionRef;
|
2014-01-30 02:49:50 +00:00
|
|
|
virtual void moveSectionNext(DataRefImpl &Sec) const = 0;
|
2011-06-25 17:55:23 +00:00
|
|
|
virtual error_code getSectionName(DataRefImpl Sec, StringRef &Res) const = 0;
|
|
|
|
virtual error_code getSectionAddress(DataRefImpl Sec, uint64_t &Res) const =0;
|
|
|
|
virtual error_code getSectionSize(DataRefImpl Sec, uint64_t &Res) const = 0;
|
|
|
|
virtual error_code getSectionContents(DataRefImpl Sec, StringRef &Res)const=0;
|
2011-10-10 21:55:43 +00:00
|
|
|
virtual error_code getSectionAlignment(DataRefImpl Sec, uint64_t &Res)const=0;
|
2011-06-25 17:55:23 +00:00
|
|
|
virtual error_code isSectionText(DataRefImpl Sec, bool &Res) const = 0;
|
2011-09-28 20:57:30 +00:00
|
|
|
virtual error_code isSectionData(DataRefImpl Sec, bool &Res) const = 0;
|
|
|
|
virtual error_code isSectionBSS(DataRefImpl Sec, bool &Res) const = 0;
|
2012-04-12 20:13:57 +00:00
|
|
|
virtual error_code isSectionRequiredForExecution(DataRefImpl Sec,
|
|
|
|
bool &Res) const = 0;
|
|
|
|
// A section is 'virtual' if its contents aren't present in the object image.
|
|
|
|
virtual error_code isSectionVirtual(DataRefImpl Sec, bool &Res) const = 0;
|
|
|
|
virtual error_code isSectionZeroInit(DataRefImpl Sec, bool &Res) const = 0;
|
2012-10-10 22:37:01 +00:00
|
|
|
virtual error_code isSectionReadOnlyData(DataRefImpl Sec, bool &Res) const =0;
|
2011-07-15 18:39:21 +00:00
|
|
|
virtual error_code sectionContainsSymbol(DataRefImpl Sec, DataRefImpl Symb,
|
|
|
|
bool &Result) const = 0;
|
2013-09-27 21:47:05 +00:00
|
|
|
virtual relocation_iterator section_rel_begin(DataRefImpl Sec) const = 0;
|
|
|
|
virtual relocation_iterator section_rel_end(DataRefImpl Sec) const = 0;
|
2013-05-30 03:05:14 +00:00
|
|
|
virtual section_iterator getRelocatedSection(DataRefImpl Sec) const;
|
2010-11-15 03:21:41 +00:00
|
|
|
|
2011-09-08 20:52:17 +00:00
|
|
|
// Same as above for RelocationRef.
|
|
|
|
friend class RelocationRef;
|
2014-01-30 02:49:50 +00:00
|
|
|
virtual void moveRelocationNext(DataRefImpl &Rel) const = 0;
|
2011-09-08 20:52:17 +00:00
|
|
|
virtual error_code getRelocationAddress(DataRefImpl Rel,
|
|
|
|
uint64_t &Res) const =0;
|
2011-11-29 17:40:10 +00:00
|
|
|
virtual error_code getRelocationOffset(DataRefImpl Rel,
|
|
|
|
uint64_t &Res) const =0;
|
2013-06-05 01:33:53 +00:00
|
|
|
virtual symbol_iterator getRelocationSymbol(DataRefImpl Rel) const = 0;
|
2011-09-08 20:52:17 +00:00
|
|
|
virtual error_code getRelocationType(DataRefImpl Rel,
|
2011-10-26 17:08:49 +00:00
|
|
|
uint64_t &Res) const = 0;
|
2011-10-07 19:25:32 +00:00
|
|
|
virtual error_code getRelocationTypeName(DataRefImpl Rel,
|
|
|
|
SmallVectorImpl<char> &Result) const = 0;
|
|
|
|
virtual error_code getRelocationValueString(DataRefImpl Rel,
|
|
|
|
SmallVectorImpl<char> &Result) const = 0;
|
2011-10-25 20:35:53 +00:00
|
|
|
virtual error_code getRelocationHidden(DataRefImpl Rel, bool &Result) const {
|
|
|
|
Result = false;
|
|
|
|
return object_error::success;
|
|
|
|
}
|
2011-09-08 20:52:17 +00:00
|
|
|
|
2012-03-01 01:36:50 +00:00
|
|
|
// Same for LibraryRef
|
|
|
|
friend class LibraryRef;
|
|
|
|
virtual error_code getLibraryNext(DataRefImpl Lib, LibraryRef &Res) const = 0;
|
|
|
|
virtual error_code getLibraryPath(DataRefImpl Lib, StringRef &Res) const = 0;
|
|
|
|
|
2010-11-15 03:21:41 +00:00
|
|
|
public:
|
|
|
|
|
2014-02-21 20:10:59 +00:00
|
|
|
symbol_iterator begin_symbols() const;
|
|
|
|
symbol_iterator end_symbols() const;
|
2010-11-15 03:21:41 +00:00
|
|
|
|
2014-02-10 20:24:04 +00:00
|
|
|
virtual section_iterator section_begin() const = 0;
|
|
|
|
virtual section_iterator section_end() const = 0;
|
2010-11-15 03:21:41 +00:00
|
|
|
|
2014-03-13 13:52:54 +00:00
|
|
|
typedef iterator_range<section_iterator> section_iterator_range;
|
|
|
|
section_iterator_range sections() const {
|
|
|
|
return section_iterator_range(section_begin(), section_end());
|
|
|
|
}
|
|
|
|
|
2014-02-10 20:24:04 +00:00
|
|
|
virtual library_iterator needed_library_begin() const = 0;
|
|
|
|
virtual library_iterator needed_library_end() const = 0;
|
2012-03-01 01:36:50 +00:00
|
|
|
|
2010-11-15 03:21:41 +00:00
|
|
|
/// @brief The number of bytes used to represent an address in this object
|
|
|
|
/// file format.
|
|
|
|
virtual uint8_t getBytesInAddress() const = 0;
|
|
|
|
|
|
|
|
virtual StringRef getFileFormatName() const = 0;
|
2010-11-16 01:06:51 +00:00
|
|
|
virtual /* Triple::ArchType */ unsigned getArch() const = 0;
|
2010-11-15 03:21:41 +00:00
|
|
|
|
2012-03-01 22:19:54 +00:00
|
|
|
/// For shared objects, returns the name which this object should be
|
|
|
|
/// loaded from at runtime. This corresponds to DT_SONAME on ELF and
|
|
|
|
/// LC_ID_DYLIB (install name) on MachO.
|
|
|
|
virtual StringRef getLoadName() const = 0;
|
|
|
|
|
2010-11-15 03:21:41 +00:00
|
|
|
/// @returns Pointer to ObjectFile subclass to handle this type of object.
|
|
|
|
/// @param ObjectPath The path to the object file. ObjectPath.isObject must
|
|
|
|
/// return true.
|
|
|
|
/// @brief Create ObjectFile from path.
|
2014-01-22 00:14:49 +00:00
|
|
|
static ErrorOr<ObjectFile *> createObjectFile(StringRef ObjectPath);
|
2014-01-29 00:02:26 +00:00
|
|
|
static ErrorOr<ObjectFile *> createObjectFile(MemoryBuffer *Object,
|
|
|
|
bool BufferOwned,
|
|
|
|
sys::fs::file_magic Type);
|
|
|
|
static ErrorOr<ObjectFile *> createObjectFile(MemoryBuffer *Object) {
|
|
|
|
return createObjectFile(Object, true, sys::fs::file_magic::unknown);
|
|
|
|
}
|
|
|
|
|
2010-11-15 03:21:41 +00:00
|
|
|
|
2011-06-25 17:54:50 +00:00
|
|
|
static inline bool classof(const Binary *v) {
|
2012-03-09 20:41:57 +00:00
|
|
|
return v->isObject();
|
2011-06-25 17:54:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
2014-01-24 21:32:21 +00:00
|
|
|
static ErrorOr<ObjectFile *> createCOFFObjectFile(MemoryBuffer *Object,
|
|
|
|
bool BufferOwned = true);
|
|
|
|
static ErrorOr<ObjectFile *> createELFObjectFile(MemoryBuffer *Object,
|
|
|
|
bool BufferOwned = true);
|
|
|
|
static ErrorOr<ObjectFile *> createMachOObjectFile(MemoryBuffer *Object,
|
|
|
|
bool BufferOwned = true);
|
2010-11-15 03:21:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Inline function definitions.
|
|
|
|
inline SymbolRef::SymbolRef(DataRefImpl SymbolP, const ObjectFile *Owner)
|
2014-02-21 20:10:59 +00:00
|
|
|
: BasicSymbolRef(SymbolP, Owner) {}
|
2010-11-15 03:21:41 +00:00
|
|
|
|
2014-02-21 20:10:59 +00:00
|
|
|
inline symbol_iterator ObjectFile::begin_symbols() const {
|
|
|
|
basic_symbol_iterator I = symbol_begin_impl();
|
|
|
|
const BasicSymbolRef &Ref = *I;
|
|
|
|
const SymbolRef &Cast = static_cast<const SymbolRef&>(Ref);
|
|
|
|
return symbol_iterator(Cast);
|
2011-11-02 19:33:41 +00:00
|
|
|
}
|
|
|
|
|
2014-02-21 20:10:59 +00:00
|
|
|
inline symbol_iterator ObjectFile::end_symbols() const {
|
|
|
|
basic_symbol_iterator I = symbol_end_impl();
|
|
|
|
const BasicSymbolRef &Ref = *I;
|
|
|
|
const SymbolRef &Cast = static_cast<const SymbolRef&>(Ref);
|
|
|
|
return symbol_iterator(Cast);
|
2010-11-15 03:21:41 +00:00
|
|
|
}
|
|
|
|
|
2011-06-25 17:55:23 +00:00
|
|
|
inline error_code SymbolRef::getName(StringRef &Result) const {
|
2014-02-21 20:10:59 +00:00
|
|
|
return getObject()->getSymbolName(getRawDataRefImpl(), Result);
|
2010-11-15 03:21:41 +00:00
|
|
|
}
|
|
|
|
|
2011-06-25 17:55:23 +00:00
|
|
|
inline error_code SymbolRef::getAddress(uint64_t &Result) const {
|
2014-02-21 20:10:59 +00:00
|
|
|
return getObject()->getSymbolAddress(getRawDataRefImpl(), Result);
|
2010-11-15 03:21:41 +00:00
|
|
|
}
|
|
|
|
|
2011-11-29 17:40:10 +00:00
|
|
|
inline error_code SymbolRef::getFileOffset(uint64_t &Result) const {
|
2014-02-21 20:10:59 +00:00
|
|
|
return getObject()->getSymbolFileOffset(getRawDataRefImpl(), Result);
|
2011-09-14 01:22:52 +00:00
|
|
|
}
|
|
|
|
|
2013-04-29 22:24:22 +00:00
|
|
|
inline error_code SymbolRef::getAlignment(uint32_t &Result) const {
|
2014-02-21 20:10:59 +00:00
|
|
|
return getObject()->getSymbolAlignment(getRawDataRefImpl(), Result);
|
2013-04-29 22:24:22 +00:00
|
|
|
}
|
|
|
|
|
2011-06-25 17:55:23 +00:00
|
|
|
inline error_code SymbolRef::getSize(uint64_t &Result) const {
|
2014-02-21 20:10:59 +00:00
|
|
|
return getObject()->getSymbolSize(getRawDataRefImpl(), Result);
|
2011-10-17 23:54:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline error_code SymbolRef::getSection(section_iterator &Result) const {
|
2014-02-21 20:10:59 +00:00
|
|
|
return getObject()->getSymbolSection(getRawDataRefImpl(), Result);
|
2011-10-17 23:54:46 +00:00
|
|
|
}
|
|
|
|
|
2011-10-17 20:19:29 +00:00
|
|
|
inline error_code SymbolRef::getType(SymbolRef::Type &Result) const {
|
2014-02-21 20:10:59 +00:00
|
|
|
return getObject()->getSymbolType(getRawDataRefImpl(), Result);
|
2011-09-14 01:22:52 +00:00
|
|
|
}
|
|
|
|
|
2012-10-29 10:47:00 +00:00
|
|
|
inline error_code SymbolRef::getValue(uint64_t &Val) const {
|
2014-02-21 20:10:59 +00:00
|
|
|
return getObject()->getSymbolValue(getRawDataRefImpl(), Val);
|
2012-10-29 10:47:00 +00:00
|
|
|
}
|
|
|
|
|
2014-02-21 20:10:59 +00:00
|
|
|
inline const ObjectFile *SymbolRef::getObject() const {
|
|
|
|
const SymbolicFile *O = BasicSymbolRef::getObject();
|
|
|
|
return cast<ObjectFile>(O);
|
2011-10-11 02:57:48 +00:00
|
|
|
}
|
|
|
|
|
2010-11-15 03:21:41 +00:00
|
|
|
|
|
|
|
/// SectionRef
|
|
|
|
inline SectionRef::SectionRef(DataRefImpl SectionP,
|
|
|
|
const ObjectFile *Owner)
|
|
|
|
: SectionPimpl(SectionP)
|
|
|
|
, OwningObject(Owner) {}
|
|
|
|
|
|
|
|
inline bool SectionRef::operator==(const SectionRef &Other) const {
|
|
|
|
return SectionPimpl == Other.SectionPimpl;
|
|
|
|
}
|
|
|
|
|
2012-10-10 22:37:01 +00:00
|
|
|
inline bool SectionRef::operator<(const SectionRef &Other) const {
|
2011-11-02 19:33:41 +00:00
|
|
|
return SectionPimpl < Other.SectionPimpl;
|
|
|
|
}
|
|
|
|
|
2014-01-30 02:49:50 +00:00
|
|
|
inline void SectionRef::moveNext() {
|
|
|
|
return OwningObject->moveSectionNext(SectionPimpl);
|
2010-11-15 03:21:41 +00:00
|
|
|
}
|
|
|
|
|
2011-06-25 17:55:23 +00:00
|
|
|
inline error_code SectionRef::getName(StringRef &Result) const {
|
|
|
|
return OwningObject->getSectionName(SectionPimpl, Result);
|
2010-11-15 03:21:41 +00:00
|
|
|
}
|
|
|
|
|
2011-06-25 17:55:23 +00:00
|
|
|
inline error_code SectionRef::getAddress(uint64_t &Result) const {
|
|
|
|
return OwningObject->getSectionAddress(SectionPimpl, Result);
|
2010-11-15 03:21:41 +00:00
|
|
|
}
|
|
|
|
|
2011-06-25 17:55:23 +00:00
|
|
|
inline error_code SectionRef::getSize(uint64_t &Result) const {
|
|
|
|
return OwningObject->getSectionSize(SectionPimpl, Result);
|
2010-11-15 03:21:41 +00:00
|
|
|
}
|
|
|
|
|
2011-06-25 17:55:23 +00:00
|
|
|
inline error_code SectionRef::getContents(StringRef &Result) const {
|
|
|
|
return OwningObject->getSectionContents(SectionPimpl, Result);
|
2010-11-15 03:21:41 +00:00
|
|
|
}
|
|
|
|
|
2011-10-10 21:55:43 +00:00
|
|
|
inline error_code SectionRef::getAlignment(uint64_t &Result) const {
|
|
|
|
return OwningObject->getSectionAlignment(SectionPimpl, Result);
|
|
|
|
}
|
|
|
|
|
2011-06-25 17:55:23 +00:00
|
|
|
inline error_code SectionRef::isText(bool &Result) const {
|
|
|
|
return OwningObject->isSectionText(SectionPimpl, Result);
|
2010-11-15 03:21:41 +00:00
|
|
|
}
|
|
|
|
|
2011-09-28 20:57:30 +00:00
|
|
|
inline error_code SectionRef::isData(bool &Result) const {
|
|
|
|
return OwningObject->isSectionData(SectionPimpl, Result);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline error_code SectionRef::isBSS(bool &Result) const {
|
|
|
|
return OwningObject->isSectionBSS(SectionPimpl, Result);
|
|
|
|
}
|
|
|
|
|
2012-04-12 20:13:57 +00:00
|
|
|
inline error_code SectionRef::isRequiredForExecution(bool &Result) const {
|
|
|
|
return OwningObject->isSectionRequiredForExecution(SectionPimpl, Result);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline error_code SectionRef::isVirtual(bool &Result) const {
|
|
|
|
return OwningObject->isSectionVirtual(SectionPimpl, Result);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline error_code SectionRef::isZeroInit(bool &Result) const {
|
|
|
|
return OwningObject->isSectionZeroInit(SectionPimpl, Result);
|
|
|
|
}
|
|
|
|
|
2012-10-10 01:41:33 +00:00
|
|
|
inline error_code SectionRef::isReadOnlyData(bool &Result) const {
|
|
|
|
return OwningObject->isSectionReadOnlyData(SectionPimpl, Result);
|
|
|
|
}
|
|
|
|
|
2011-07-15 18:39:21 +00:00
|
|
|
inline error_code SectionRef::containsSymbol(SymbolRef S, bool &Result) const {
|
2014-02-21 20:10:59 +00:00
|
|
|
return OwningObject->sectionContainsSymbol(SectionPimpl,
|
|
|
|
S.getRawDataRefImpl(), Result);
|
2011-07-15 18:39:21 +00:00
|
|
|
}
|
|
|
|
|
2014-02-10 20:24:04 +00:00
|
|
|
inline relocation_iterator SectionRef::relocation_begin() const {
|
2013-09-27 21:47:05 +00:00
|
|
|
return OwningObject->section_rel_begin(SectionPimpl);
|
2011-10-07 19:25:32 +00:00
|
|
|
}
|
|
|
|
|
2014-02-10 20:24:04 +00:00
|
|
|
inline relocation_iterator SectionRef::relocation_end() const {
|
2013-09-27 21:47:05 +00:00
|
|
|
return OwningObject->section_rel_end(SectionPimpl);
|
2011-10-07 19:25:32 +00:00
|
|
|
}
|
|
|
|
|
2013-05-30 03:05:14 +00:00
|
|
|
inline section_iterator SectionRef::getRelocatedSection() const {
|
|
|
|
return OwningObject->getRelocatedSection(SectionPimpl);
|
|
|
|
}
|
|
|
|
|
2012-04-12 20:13:57 +00:00
|
|
|
inline DataRefImpl SectionRef::getRawDataRefImpl() const {
|
|
|
|
return SectionPimpl;
|
|
|
|
}
|
2011-09-08 20:52:17 +00:00
|
|
|
|
|
|
|
/// RelocationRef
|
|
|
|
inline RelocationRef::RelocationRef(DataRefImpl RelocationP,
|
|
|
|
const ObjectFile *Owner)
|
|
|
|
: RelocationPimpl(RelocationP)
|
|
|
|
, OwningObject(Owner) {}
|
|
|
|
|
|
|
|
inline bool RelocationRef::operator==(const RelocationRef &Other) const {
|
|
|
|
return RelocationPimpl == Other.RelocationPimpl;
|
|
|
|
}
|
|
|
|
|
2014-01-30 02:49:50 +00:00
|
|
|
inline void RelocationRef::moveNext() {
|
|
|
|
return OwningObject->moveRelocationNext(RelocationPimpl);
|
2011-09-08 20:52:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline error_code RelocationRef::getAddress(uint64_t &Result) const {
|
|
|
|
return OwningObject->getRelocationAddress(RelocationPimpl, Result);
|
|
|
|
}
|
|
|
|
|
2011-11-29 17:40:10 +00:00
|
|
|
inline error_code RelocationRef::getOffset(uint64_t &Result) const {
|
|
|
|
return OwningObject->getRelocationOffset(RelocationPimpl, Result);
|
|
|
|
}
|
|
|
|
|
2013-06-05 01:33:53 +00:00
|
|
|
inline symbol_iterator RelocationRef::getSymbol() const {
|
|
|
|
return OwningObject->getRelocationSymbol(RelocationPimpl);
|
2011-09-08 20:52:17 +00:00
|
|
|
}
|
|
|
|
|
2011-10-26 17:08:49 +00:00
|
|
|
inline error_code RelocationRef::getType(uint64_t &Result) const {
|
2011-09-08 20:52:17 +00:00
|
|
|
return OwningObject->getRelocationType(RelocationPimpl, Result);
|
|
|
|
}
|
|
|
|
|
2011-10-07 19:25:32 +00:00
|
|
|
inline error_code RelocationRef::getTypeName(SmallVectorImpl<char> &Result)
|
|
|
|
const {
|
|
|
|
return OwningObject->getRelocationTypeName(RelocationPimpl, Result);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline error_code RelocationRef::getValueString(SmallVectorImpl<char> &Result)
|
|
|
|
const {
|
|
|
|
return OwningObject->getRelocationValueString(RelocationPimpl, Result);
|
|
|
|
}
|
|
|
|
|
2011-10-25 20:35:53 +00:00
|
|
|
inline error_code RelocationRef::getHidden(bool &Result) const {
|
|
|
|
return OwningObject->getRelocationHidden(RelocationPimpl, Result);
|
|
|
|
}
|
2012-06-18 19:47:16 +00:00
|
|
|
|
|
|
|
inline DataRefImpl RelocationRef::getRawDataRefImpl() const {
|
|
|
|
return RelocationPimpl;
|
|
|
|
}
|
|
|
|
|
2013-05-09 03:39:05 +00:00
|
|
|
inline const ObjectFile *RelocationRef::getObjectFile() const {
|
|
|
|
return OwningObject;
|
|
|
|
}
|
|
|
|
|
2012-03-01 01:36:50 +00:00
|
|
|
// Inline function definitions.
|
|
|
|
inline LibraryRef::LibraryRef(DataRefImpl LibraryP, const ObjectFile *Owner)
|
|
|
|
: LibraryPimpl(LibraryP)
|
|
|
|
, OwningObject(Owner) {}
|
|
|
|
|
|
|
|
inline bool LibraryRef::operator==(const LibraryRef &Other) const {
|
|
|
|
return LibraryPimpl == Other.LibraryPimpl;
|
|
|
|
}
|
|
|
|
|
2012-10-10 22:37:01 +00:00
|
|
|
inline bool LibraryRef::operator<(const LibraryRef &Other) const {
|
2012-03-01 01:36:50 +00:00
|
|
|
return LibraryPimpl < Other.LibraryPimpl;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline error_code LibraryRef::getNext(LibraryRef &Result) const {
|
|
|
|
return OwningObject->getLibraryNext(LibraryPimpl, Result);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline error_code LibraryRef::getPath(StringRef &Result) const {
|
|
|
|
return OwningObject->getLibraryPath(LibraryPimpl, Result);
|
|
|
|
}
|
2011-10-25 20:35:53 +00:00
|
|
|
|
2010-11-15 03:21:41 +00:00
|
|
|
} // end namespace object
|
|
|
|
} // end namespace llvm
|
|
|
|
|
|
|
|
#endif
|