2010-11-15 04:21:41 +01: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 01:45:19 +01:00
|
|
|
#ifndef LLVM_OBJECT_OBJECTFILE_H
|
|
|
|
#define LLVM_OBJECT_OBJECTFILE_H
|
2010-11-15 04:21:41 +01:00
|
|
|
|
2010-11-16 02:06:51 +01:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
2017-12-14 23:07:03 +01:00
|
|
|
#include "llvm/ADT/Triple.h"
|
2017-06-06 13:49:48 +02:00
|
|
|
#include "llvm/ADT/iterator_range.h"
|
2017-06-07 05:48:56 +02:00
|
|
|
#include "llvm/BinaryFormat/Magic.h"
|
2016-06-16 11:17:03 +02:00
|
|
|
#include "llvm/MC/SubtargetFeature.h"
|
2017-04-20 01:02:10 +02:00
|
|
|
#include "llvm/Object/Binary.h"
|
|
|
|
#include "llvm/Object/Error.h"
|
2014-02-21 21:10:59 +01:00
|
|
|
#include "llvm/Object/SymbolicFile.h"
|
2017-04-20 01:02:10 +02:00
|
|
|
#include "llvm/Support/Casting.h"
|
|
|
|
#include "llvm/Support/Error.h"
|
2014-01-22 17:04:52 +01:00
|
|
|
#include "llvm/Support/FileSystem.h"
|
2011-06-25 19:54:50 +02:00
|
|
|
#include "llvm/Support/MemoryBuffer.h"
|
2017-04-20 01:02:10 +02:00
|
|
|
#include <cassert>
|
|
|
|
#include <cstdint>
|
|
|
|
#include <memory>
|
|
|
|
#include <system_error>
|
2010-11-15 04:21:41 +01:00
|
|
|
|
|
|
|
namespace llvm {
|
2017-04-20 01:02:10 +02:00
|
|
|
|
2017-01-18 14:52:12 +01:00
|
|
|
class ARMAttributeParser;
|
|
|
|
|
2010-11-15 04:21:41 +01:00
|
|
|
namespace object {
|
|
|
|
|
2014-07-31 05:12:45 +02:00
|
|
|
class COFFObjectFile;
|
|
|
|
class MachOObjectFile;
|
2017-04-20 01:02:10 +02:00
|
|
|
class ObjectFile;
|
|
|
|
class SectionRef;
|
2011-10-18 01:54:46 +02:00
|
|
|
class SymbolRef;
|
2014-02-21 21:10:59 +01:00
|
|
|
class symbol_iterator;
|
2017-04-20 01:02:10 +02:00
|
|
|
class WasmObjectFile;
|
|
|
|
|
|
|
|
using section_iterator = content_iterator<SectionRef>;
|
2010-11-15 04:21:41 +01:00
|
|
|
|
2015-06-24 05:19:35 +02:00
|
|
|
/// This is a value type class that represents a single relocation in the list
|
|
|
|
/// of relocations in the object file.
|
2011-09-08 22:52:17 +02:00
|
|
|
class RelocationRef {
|
|
|
|
DataRefImpl RelocationPimpl;
|
2017-04-20 01:02:10 +02:00
|
|
|
const ObjectFile *OwningObject = nullptr;
|
2011-09-08 22:52:17 +02:00
|
|
|
|
|
|
|
public:
|
2017-04-20 01:02:10 +02:00
|
|
|
RelocationRef() = default;
|
2011-09-08 22:52:17 +02:00
|
|
|
RelocationRef(DataRefImpl RelocationP, const ObjectFile *Owner);
|
|
|
|
|
|
|
|
bool operator==(const RelocationRef &Other) const;
|
|
|
|
|
2014-01-30 03:49:50 +01:00
|
|
|
void moveNext();
|
2011-09-08 22:52:17 +02:00
|
|
|
|
2015-06-30 01:29:12 +02:00
|
|
|
uint64_t getOffset() const;
|
2013-06-05 03:33:53 +02:00
|
|
|
symbol_iterator getSymbol() const;
|
2015-06-30 03:53:01 +02:00
|
|
|
uint64_t getType() const;
|
2011-10-07 21:25:32 +02:00
|
|
|
|
2018-05-01 18:10:38 +02:00
|
|
|
/// Get a string that represents the type of this relocation.
|
2011-10-07 21:25:32 +02:00
|
|
|
///
|
|
|
|
/// This is for display purposes only.
|
2015-06-30 06:08:37 +02:00
|
|
|
void getTypeName(SmallVectorImpl<char> &Result) const;
|
2012-06-18 21:47:16 +02:00
|
|
|
|
|
|
|
DataRefImpl getRawDataRefImpl() const;
|
2015-06-26 16:51:16 +02:00
|
|
|
const ObjectFile *getObject() const;
|
2011-09-08 22:52:17 +02:00
|
|
|
};
|
2017-04-20 01:02:10 +02:00
|
|
|
|
|
|
|
using relocation_iterator = content_iterator<RelocationRef>;
|
2011-09-08 22:52:17 +02:00
|
|
|
|
2015-06-24 05:19:35 +02:00
|
|
|
/// This is a value type class that represents a single section in the list of
|
|
|
|
/// sections in the object file.
|
2010-11-15 04:21:41 +01:00
|
|
|
class SectionRef {
|
2011-07-15 20:39:21 +02:00
|
|
|
friend class SymbolRef;
|
2017-04-20 01:02:10 +02:00
|
|
|
|
2010-11-15 04:21:41 +01:00
|
|
|
DataRefImpl SectionPimpl;
|
2017-04-20 01:02:10 +02:00
|
|
|
const ObjectFile *OwningObject = nullptr;
|
2010-11-15 04:21:41 +01:00
|
|
|
|
|
|
|
public:
|
2017-04-20 01:02:10 +02:00
|
|
|
SectionRef() = default;
|
2010-11-15 04:21:41 +01:00
|
|
|
SectionRef(DataRefImpl SectionP, const ObjectFile *Owner);
|
|
|
|
|
|
|
|
bool operator==(const SectionRef &Other) const;
|
2014-03-21 08:26:41 +01:00
|
|
|
bool operator!=(const SectionRef &Other) const;
|
2012-10-11 00:37:01 +02:00
|
|
|
bool operator<(const SectionRef &Other) const;
|
2010-11-15 04:21:41 +01:00
|
|
|
|
2014-01-30 03:49:50 +01:00
|
|
|
void moveNext();
|
2010-11-15 04:21:41 +01:00
|
|
|
|
2014-06-12 23:46:39 +02:00
|
|
|
std::error_code getName(StringRef &Result) const;
|
2014-10-08 17:28:58 +02:00
|
|
|
uint64_t getAddress() const;
|
2017-05-27 20:10:23 +02:00
|
|
|
uint64_t getIndex() const;
|
2014-10-08 17:28:58 +02:00
|
|
|
uint64_t getSize() const;
|
2014-06-12 23:46:39 +02:00
|
|
|
std::error_code getContents(StringRef &Result) const;
|
2010-11-15 04:21:41 +01:00
|
|
|
|
2018-05-01 18:10:38 +02:00
|
|
|
/// Get the alignment of this section as the actual value (not log 2).
|
2014-10-08 17:28:58 +02:00
|
|
|
uint64_t getAlignment() const;
|
2011-10-10 23:55:43 +02:00
|
|
|
|
2016-05-24 14:48:46 +02:00
|
|
|
bool isCompressed() const;
|
2014-10-08 17:28:58 +02:00
|
|
|
bool isText() const;
|
|
|
|
bool isData() const;
|
|
|
|
bool isBSS() const;
|
|
|
|
bool isVirtual() const;
|
2016-02-29 20:40:10 +01:00
|
|
|
bool isBitcode() const;
|
2017-09-26 16:22:35 +02:00
|
|
|
bool isStripped() const;
|
2011-07-15 20:39:21 +02:00
|
|
|
|
2014-10-08 17:28:58 +02:00
|
|
|
bool containsSymbol(SymbolRef S) const;
|
2011-10-07 21:25:32 +02:00
|
|
|
|
2014-02-10 21:24:04 +01:00
|
|
|
relocation_iterator relocation_begin() const;
|
|
|
|
relocation_iterator relocation_end() const;
|
2014-04-21 20:10:29 +02:00
|
|
|
iterator_range<relocation_iterator> relocations() const {
|
2015-12-06 06:08:07 +01:00
|
|
|
return make_range(relocation_begin(), relocation_end());
|
2014-03-14 15:22:49 +01:00
|
|
|
}
|
2013-05-30 05:05:14 +02:00
|
|
|
section_iterator getRelocatedSection() const;
|
2012-04-12 22:13:57 +02:00
|
|
|
|
|
|
|
DataRefImpl getRawDataRefImpl() const;
|
2014-12-10 21:46:55 +01:00
|
|
|
const ObjectFile *getObject() const;
|
2010-11-15 04:21:41 +01:00
|
|
|
};
|
|
|
|
|
2015-06-24 05:19:35 +02:00
|
|
|
/// This is a value type class that represents a single symbol in the list of
|
|
|
|
/// symbols in the object file.
|
2014-02-21 21:10:59 +01:00
|
|
|
class SymbolRef : public BasicSymbolRef {
|
2011-10-18 01:54:46 +02:00
|
|
|
friend class SectionRef;
|
|
|
|
|
|
|
|
public:
|
|
|
|
enum Type {
|
2012-02-29 03:11:55 +01:00
|
|
|
ST_Unknown, // Type not specified
|
2011-10-18 01:54:46 +02:00
|
|
|
ST_Data,
|
2011-10-18 01:55:06 +02:00
|
|
|
ST_Debug,
|
|
|
|
ST_File,
|
|
|
|
ST_Function,
|
2011-10-18 01:54:46 +02:00
|
|
|
ST_Other
|
|
|
|
};
|
|
|
|
|
2017-04-20 01:02:10 +02:00
|
|
|
SymbolRef() = default;
|
2011-10-18 01:54:46 +02:00
|
|
|
SymbolRef(DataRefImpl SymbolP, const ObjectFile *Owner);
|
2015-06-25 17:00:38 +02:00
|
|
|
SymbolRef(const BasicSymbolRef &B) : BasicSymbolRef(B) {
|
|
|
|
assert(isa<ObjectFile>(BasicSymbolRef::getObject()));
|
|
|
|
}
|
2011-10-18 01:54:46 +02:00
|
|
|
|
2016-04-20 23:24:34 +02:00
|
|
|
Expected<StringRef> getName() const;
|
2012-09-21 09:08:08 +02:00
|
|
|
/// Returns the symbol virtual address (i.e. address at which it will be
|
|
|
|
/// mapped).
|
2016-06-24 20:24:42 +02:00
|
|
|
Expected<uint64_t> getAddress() const;
|
2015-06-24 21:11:10 +02:00
|
|
|
|
|
|
|
/// Return the value of the symbol depending on the object this can be an
|
|
|
|
/// offset or a virtual address.
|
|
|
|
uint64_t getValue() const;
|
|
|
|
|
2018-05-01 18:10:38 +02:00
|
|
|
/// Get the alignment of this symbol as the actual value (not log 2).
|
2015-06-01 01:52:50 +02:00
|
|
|
uint32_t getAlignment() const;
|
2015-06-24 12:20:30 +02:00
|
|
|
uint64_t getCommonSize() const;
|
2016-05-02 22:28:12 +02:00
|
|
|
Expected<SymbolRef::Type> getType() const;
|
2011-10-18 01:54:46 +02:00
|
|
|
|
2018-05-01 18:10:38 +02:00
|
|
|
/// Get section this symbol is defined in reference to. Result is
|
2011-10-18 01:54:46 +02:00
|
|
|
/// end_sections() if it is undefined or is an absolute symbol.
|
2016-05-02 22:28:12 +02:00
|
|
|
Expected<section_iterator> getSection() const;
|
2011-10-18 01:54:46 +02:00
|
|
|
|
2014-02-21 21:10:59 +01: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-18 01:54:46 +02:00
|
|
|
};
|
|
|
|
|
2015-06-24 05:19:35 +02:00
|
|
|
/// This class is the base class for all object file types. Concrete instances
|
|
|
|
/// of this object are created by createObjectFile, which figures out which type
|
|
|
|
/// to create.
|
2014-02-21 21:10:59 +01:00
|
|
|
class ObjectFile : public SymbolicFile {
|
2011-12-20 03:50:00 +01:00
|
|
|
virtual void anchor();
|
2010-11-15 04:21:41 +01:00
|
|
|
|
|
|
|
protected:
|
2014-08-19 20:44:46 +02:00
|
|
|
ObjectFile(unsigned int Type, MemoryBufferRef Source);
|
2010-11-15 04:21:41 +01:00
|
|
|
|
2011-06-25 19:54:50 +02:00
|
|
|
const uint8_t *base() const {
|
2014-08-19 20:44:46 +02:00
|
|
|
return reinterpret_cast<const uint8_t *>(Data.getBufferStart());
|
2011-06-25 19:54:50 +02:00
|
|
|
}
|
2010-11-15 04:21:41 +01: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 19:55:23 +02:00
|
|
|
//
|
|
|
|
// Implementations assume that the DataRefImpl is valid and has not been
|
|
|
|
// modified externally. It's UB otherwise.
|
2010-11-15 04:21:41 +01:00
|
|
|
friend class SymbolRef;
|
2017-04-20 01:02:10 +02:00
|
|
|
|
2016-04-20 23:24:34 +02:00
|
|
|
virtual Expected<StringRef> getSymbolName(DataRefImpl Symb) const = 0;
|
2014-06-12 23:46:39 +02:00
|
|
|
std::error_code printSymbolName(raw_ostream &OS,
|
|
|
|
DataRefImpl Symb) const override;
|
2016-06-24 20:24:42 +02:00
|
|
|
virtual Expected<uint64_t> getSymbolAddress(DataRefImpl Symb) const = 0;
|
2015-07-07 19:12:59 +02:00
|
|
|
virtual uint64_t getSymbolValueImpl(DataRefImpl Symb) const = 0;
|
2015-06-01 01:52:50 +02:00
|
|
|
virtual uint32_t getSymbolAlignment(DataRefImpl Symb) const;
|
2015-06-24 12:20:30 +02:00
|
|
|
virtual uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const = 0;
|
2016-05-02 22:28:12 +02:00
|
|
|
virtual Expected<SymbolRef::Type> getSymbolType(DataRefImpl Symb) const = 0;
|
|
|
|
virtual Expected<section_iterator>
|
2015-08-08 01:27:14 +02:00
|
|
|
getSymbolSection(DataRefImpl Symb) const = 0;
|
2010-11-15 04:21:41 +01:00
|
|
|
|
|
|
|
// Same as above for SectionRef.
|
|
|
|
friend class SectionRef;
|
2017-04-20 01:02:10 +02:00
|
|
|
|
2014-01-30 03:49:50 +01:00
|
|
|
virtual void moveSectionNext(DataRefImpl &Sec) const = 0;
|
2014-06-12 23:46:39 +02:00
|
|
|
virtual std::error_code getSectionName(DataRefImpl Sec,
|
|
|
|
StringRef &Res) const = 0;
|
2014-10-08 17:28:58 +02:00
|
|
|
virtual uint64_t getSectionAddress(DataRefImpl Sec) const = 0;
|
2017-05-27 20:10:23 +02:00
|
|
|
virtual uint64_t getSectionIndex(DataRefImpl Sec) const = 0;
|
2014-10-08 17:28:58 +02:00
|
|
|
virtual uint64_t getSectionSize(DataRefImpl Sec) const = 0;
|
2014-06-12 23:46:39 +02:00
|
|
|
virtual std::error_code getSectionContents(DataRefImpl Sec,
|
|
|
|
StringRef &Res) const = 0;
|
2014-10-08 17:28:58 +02:00
|
|
|
virtual uint64_t getSectionAlignment(DataRefImpl Sec) const = 0;
|
2016-05-24 14:48:46 +02:00
|
|
|
virtual bool isSectionCompressed(DataRefImpl Sec) const = 0;
|
2014-10-08 17:28:58 +02:00
|
|
|
virtual bool isSectionText(DataRefImpl Sec) const = 0;
|
|
|
|
virtual bool isSectionData(DataRefImpl Sec) const = 0;
|
|
|
|
virtual bool isSectionBSS(DataRefImpl Sec) const = 0;
|
2012-04-12 22:13:57 +02:00
|
|
|
// A section is 'virtual' if its contents aren't present in the object image.
|
2014-10-08 17:28:58 +02:00
|
|
|
virtual bool isSectionVirtual(DataRefImpl Sec) const = 0;
|
2016-02-29 20:40:10 +01:00
|
|
|
virtual bool isSectionBitcode(DataRefImpl Sec) const;
|
2017-09-26 16:22:35 +02:00
|
|
|
virtual bool isSectionStripped(DataRefImpl Sec) const;
|
2013-09-27 23:47:05 +02:00
|
|
|
virtual relocation_iterator section_rel_begin(DataRefImpl Sec) const = 0;
|
|
|
|
virtual relocation_iterator section_rel_end(DataRefImpl Sec) const = 0;
|
2013-05-30 05:05:14 +02:00
|
|
|
virtual section_iterator getRelocatedSection(DataRefImpl Sec) const;
|
2010-11-15 04:21:41 +01:00
|
|
|
|
2011-09-08 22:52:17 +02:00
|
|
|
// Same as above for RelocationRef.
|
|
|
|
friend class RelocationRef;
|
2014-01-30 03:49:50 +01:00
|
|
|
virtual void moveRelocationNext(DataRefImpl &Rel) const = 0;
|
2015-06-30 01:29:12 +02:00
|
|
|
virtual uint64_t getRelocationOffset(DataRefImpl Rel) const = 0;
|
2013-06-05 03:33:53 +02:00
|
|
|
virtual symbol_iterator getRelocationSymbol(DataRefImpl Rel) const = 0;
|
2015-06-30 03:53:01 +02:00
|
|
|
virtual uint64_t getRelocationType(DataRefImpl Rel) const = 0;
|
2015-06-30 06:08:37 +02:00
|
|
|
virtual void getRelocationTypeName(DataRefImpl Rel,
|
|
|
|
SmallVectorImpl<char> &Result) const = 0;
|
2011-09-08 22:52:17 +02:00
|
|
|
|
2015-07-07 19:12:59 +02:00
|
|
|
uint64_t getSymbolValue(DataRefImpl Symb) const;
|
|
|
|
|
2010-11-15 04:21:41 +01:00
|
|
|
public:
|
2017-04-20 01:02:10 +02:00
|
|
|
ObjectFile() = delete;
|
|
|
|
ObjectFile(const ObjectFile &other) = delete;
|
|
|
|
|
2015-06-24 12:20:30 +02:00
|
|
|
uint64_t getCommonSymbolSize(DataRefImpl Symb) const {
|
|
|
|
assert(getSymbolFlags(Symb) & SymbolRef::SF_Common);
|
|
|
|
return getCommonSymbolSizeImpl(Symb);
|
|
|
|
}
|
|
|
|
|
2018-06-07 15:30:55 +02:00
|
|
|
virtual std::vector<SectionRef> dynamic_relocation_sections() const {
|
|
|
|
return std::vector<SectionRef>();
|
|
|
|
}
|
|
|
|
|
2017-04-20 01:02:10 +02:00
|
|
|
using symbol_iterator_range = iterator_range<symbol_iterator>;
|
2014-03-17 08:28:19 +01:00
|
|
|
symbol_iterator_range symbols() const {
|
|
|
|
return symbol_iterator_range(symbol_begin(), symbol_end());
|
|
|
|
}
|
2010-11-15 04:21:41 +01:00
|
|
|
|
2014-02-10 21:24:04 +01:00
|
|
|
virtual section_iterator section_begin() const = 0;
|
|
|
|
virtual section_iterator section_end() const = 0;
|
2010-11-15 04:21:41 +01:00
|
|
|
|
2017-04-20 01:02:10 +02:00
|
|
|
using section_iterator_range = iterator_range<section_iterator>;
|
2014-03-13 14:52:54 +01:00
|
|
|
section_iterator_range sections() const {
|
|
|
|
return section_iterator_range(section_begin(), section_end());
|
|
|
|
}
|
|
|
|
|
2018-05-01 18:10:38 +02:00
|
|
|
/// The number of bytes used to represent an address in this object
|
2010-11-15 04:21:41 +01:00
|
|
|
/// file format.
|
|
|
|
virtual uint8_t getBytesInAddress() const = 0;
|
|
|
|
|
|
|
|
virtual StringRef getFileFormatName() const = 0;
|
2017-12-14 23:07:03 +01:00
|
|
|
virtual Triple::ArchType getArch() const = 0;
|
2016-06-16 11:17:03 +02:00
|
|
|
virtual SubtargetFeatures getFeatures() const = 0;
|
2017-01-18 14:52:12 +01:00
|
|
|
virtual void setARMSubArch(Triple &TheTriple) const { }
|
2010-11-15 04:21:41 +01:00
|
|
|
|
2018-05-01 18:10:38 +02:00
|
|
|
/// Create a triple from the data in this object file.
|
2017-09-19 04:22:48 +02:00
|
|
|
Triple makeTriple() const;
|
|
|
|
|
2017-01-18 14:52:12 +01:00
|
|
|
virtual std::error_code
|
|
|
|
getBuildAttributes(ARMAttributeParser &Attributes) const {
|
|
|
|
return std::error_code();
|
|
|
|
}
|
|
|
|
|
2017-06-06 03:22:34 +02:00
|
|
|
/// Maps a debug section name to a standard DWARF section name.
|
|
|
|
virtual StringRef mapDebugSectionName(StringRef Name) const { return Name; }
|
|
|
|
|
2014-08-17 21:09:37 +02:00
|
|
|
/// True if this is a relocatable object (.o/.obj).
|
|
|
|
virtual bool isRelocatableObject() const = 0;
|
|
|
|
|
2010-11-15 04:21:41 +01: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.
|
2018-05-01 18:10:38 +02:00
|
|
|
/// Create ObjectFile from path.
|
2016-04-07 00:14:09 +02:00
|
|
|
static Expected<OwningBinary<ObjectFile>>
|
2014-07-31 05:12:45 +02:00
|
|
|
createObjectFile(StringRef ObjectPath);
|
|
|
|
|
2016-04-07 00:14:09 +02:00
|
|
|
static Expected<std::unique_ptr<ObjectFile>>
|
2017-06-07 05:48:56 +02:00
|
|
|
createObjectFile(MemoryBufferRef Object, llvm::file_magic Type);
|
2016-04-07 00:14:09 +02:00
|
|
|
static Expected<std::unique_ptr<ObjectFile>>
|
2014-08-19 20:44:46 +02:00
|
|
|
createObjectFile(MemoryBufferRef Object) {
|
2017-06-07 05:48:56 +02:00
|
|
|
return createObjectFile(Object, llvm::file_magic::unknown);
|
2014-01-29 01:02:26 +01:00
|
|
|
}
|
|
|
|
|
2017-06-29 21:35:17 +02:00
|
|
|
static bool classof(const Binary *v) {
|
2012-03-09 21:41:57 +01:00
|
|
|
return v->isObject();
|
2011-06-25 19:54:50 +02:00
|
|
|
}
|
|
|
|
|
2017-10-10 22:00:07 +02:00
|
|
|
static Expected<std::unique_ptr<COFFObjectFile>>
|
2014-08-19 20:44:46 +02:00
|
|
|
createCOFFObjectFile(MemoryBufferRef Object);
|
2014-07-31 05:12:45 +02:00
|
|
|
|
2017-10-10 22:00:07 +02:00
|
|
|
static Expected<std::unique_ptr<ObjectFile>>
|
2014-08-19 20:44:46 +02:00
|
|
|
createELFObjectFile(MemoryBufferRef Object);
|
2014-07-31 05:12:45 +02:00
|
|
|
|
2016-03-26 00:11:52 +01:00
|
|
|
static Expected<std::unique_ptr<MachOObjectFile>>
|
2016-10-24 23:15:11 +02:00
|
|
|
createMachOObjectFile(MemoryBufferRef Object,
|
|
|
|
uint32_t UniversalCputype = 0,
|
|
|
|
uint32_t UniversalIndex = 0);
|
2016-02-29 20:40:10 +01:00
|
|
|
|
2016-11-30 17:49:11 +01:00
|
|
|
static Expected<std::unique_ptr<WasmObjectFile>>
|
|
|
|
createWasmObjectFile(MemoryBufferRef Object);
|
2010-11-15 04:21:41 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// Inline function definitions.
|
|
|
|
inline SymbolRef::SymbolRef(DataRefImpl SymbolP, const ObjectFile *Owner)
|
2014-02-21 21:10:59 +01:00
|
|
|
: BasicSymbolRef(SymbolP, Owner) {}
|
2010-11-15 04:21:41 +01:00
|
|
|
|
2016-04-20 23:24:34 +02:00
|
|
|
inline Expected<StringRef> SymbolRef::getName() const {
|
2015-07-02 22:55:21 +02:00
|
|
|
return getObject()->getSymbolName(getRawDataRefImpl());
|
2010-11-15 04:21:41 +01:00
|
|
|
}
|
|
|
|
|
2016-06-24 20:24:42 +02:00
|
|
|
inline Expected<uint64_t> SymbolRef::getAddress() const {
|
2015-07-03 20:19:00 +02:00
|
|
|
return getObject()->getSymbolAddress(getRawDataRefImpl());
|
2010-11-15 04:21:41 +01:00
|
|
|
}
|
|
|
|
|
2015-06-24 21:11:10 +02:00
|
|
|
inline uint64_t SymbolRef::getValue() const {
|
|
|
|
return getObject()->getSymbolValue(getRawDataRefImpl());
|
|
|
|
}
|
|
|
|
|
2015-06-01 01:52:50 +02:00
|
|
|
inline uint32_t SymbolRef::getAlignment() const {
|
|
|
|
return getObject()->getSymbolAlignment(getRawDataRefImpl());
|
2013-04-30 00:24:22 +02:00
|
|
|
}
|
|
|
|
|
2015-06-24 12:20:30 +02:00
|
|
|
inline uint64_t SymbolRef::getCommonSize() const {
|
|
|
|
return getObject()->getCommonSymbolSize(getRawDataRefImpl());
|
2011-10-18 01:54:46 +02:00
|
|
|
}
|
|
|
|
|
2016-05-02 22:28:12 +02:00
|
|
|
inline Expected<section_iterator> SymbolRef::getSection() const {
|
2015-08-08 01:27:14 +02:00
|
|
|
return getObject()->getSymbolSection(getRawDataRefImpl());
|
2011-10-18 01:54:46 +02:00
|
|
|
}
|
|
|
|
|
2016-05-02 22:28:12 +02:00
|
|
|
inline Expected<SymbolRef::Type> SymbolRef::getType() const {
|
2015-06-26 14:18:49 +02:00
|
|
|
return getObject()->getSymbolType(getRawDataRefImpl());
|
2011-09-14 03:22:52 +02:00
|
|
|
}
|
|
|
|
|
2014-02-21 21:10:59 +01:00
|
|
|
inline const ObjectFile *SymbolRef::getObject() const {
|
|
|
|
const SymbolicFile *O = BasicSymbolRef::getObject();
|
|
|
|
return cast<ObjectFile>(O);
|
2011-10-11 04:57:48 +02:00
|
|
|
}
|
|
|
|
|
2010-11-15 04:21:41 +01: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;
|
|
|
|
}
|
|
|
|
|
2014-03-21 08:26:41 +01:00
|
|
|
inline bool SectionRef::operator!=(const SectionRef &Other) const {
|
|
|
|
return SectionPimpl != Other.SectionPimpl;
|
|
|
|
}
|
|
|
|
|
2012-10-11 00:37:01 +02:00
|
|
|
inline bool SectionRef::operator<(const SectionRef &Other) const {
|
2011-11-02 20:33:41 +01:00
|
|
|
return SectionPimpl < Other.SectionPimpl;
|
|
|
|
}
|
|
|
|
|
2014-01-30 03:49:50 +01:00
|
|
|
inline void SectionRef::moveNext() {
|
|
|
|
return OwningObject->moveSectionNext(SectionPimpl);
|
2010-11-15 04:21:41 +01:00
|
|
|
}
|
|
|
|
|
2014-06-12 23:46:39 +02:00
|
|
|
inline std::error_code SectionRef::getName(StringRef &Result) const {
|
2011-06-25 19:55:23 +02:00
|
|
|
return OwningObject->getSectionName(SectionPimpl, Result);
|
2010-11-15 04:21:41 +01:00
|
|
|
}
|
|
|
|
|
2014-10-08 17:28:58 +02:00
|
|
|
inline uint64_t SectionRef::getAddress() const {
|
|
|
|
return OwningObject->getSectionAddress(SectionPimpl);
|
2010-11-15 04:21:41 +01:00
|
|
|
}
|
|
|
|
|
2017-05-27 20:10:23 +02:00
|
|
|
inline uint64_t SectionRef::getIndex() const {
|
|
|
|
return OwningObject->getSectionIndex(SectionPimpl);
|
|
|
|
}
|
|
|
|
|
2014-10-08 17:28:58 +02:00
|
|
|
inline uint64_t SectionRef::getSize() const {
|
|
|
|
return OwningObject->getSectionSize(SectionPimpl);
|
2010-11-15 04:21:41 +01:00
|
|
|
}
|
|
|
|
|
2014-06-12 23:46:39 +02:00
|
|
|
inline std::error_code SectionRef::getContents(StringRef &Result) const {
|
2011-06-25 19:55:23 +02:00
|
|
|
return OwningObject->getSectionContents(SectionPimpl, Result);
|
2010-11-15 04:21:41 +01:00
|
|
|
}
|
|
|
|
|
2014-10-08 17:28:58 +02:00
|
|
|
inline uint64_t SectionRef::getAlignment() const {
|
|
|
|
return OwningObject->getSectionAlignment(SectionPimpl);
|
2011-10-10 23:55:43 +02:00
|
|
|
}
|
|
|
|
|
2016-05-24 14:48:46 +02:00
|
|
|
inline bool SectionRef::isCompressed() const {
|
|
|
|
return OwningObject->isSectionCompressed(SectionPimpl);
|
|
|
|
}
|
|
|
|
|
2014-10-08 17:28:58 +02:00
|
|
|
inline bool SectionRef::isText() const {
|
|
|
|
return OwningObject->isSectionText(SectionPimpl);
|
2010-11-15 04:21:41 +01:00
|
|
|
}
|
|
|
|
|
2014-10-08 17:28:58 +02:00
|
|
|
inline bool SectionRef::isData() const {
|
|
|
|
return OwningObject->isSectionData(SectionPimpl);
|
2011-09-28 22:57:30 +02:00
|
|
|
}
|
|
|
|
|
2014-10-08 17:28:58 +02:00
|
|
|
inline bool SectionRef::isBSS() const {
|
|
|
|
return OwningObject->isSectionBSS(SectionPimpl);
|
2011-09-28 22:57:30 +02:00
|
|
|
}
|
|
|
|
|
2014-10-08 17:28:58 +02:00
|
|
|
inline bool SectionRef::isVirtual() const {
|
|
|
|
return OwningObject->isSectionVirtual(SectionPimpl);
|
2012-04-12 22:13:57 +02:00
|
|
|
}
|
|
|
|
|
2016-02-29 20:40:10 +01:00
|
|
|
inline bool SectionRef::isBitcode() const {
|
|
|
|
return OwningObject->isSectionBitcode(SectionPimpl);
|
|
|
|
}
|
|
|
|
|
2017-09-26 16:22:35 +02:00
|
|
|
inline bool SectionRef::isStripped() const {
|
|
|
|
return OwningObject->isSectionStripped(SectionPimpl);
|
|
|
|
}
|
|
|
|
|
2014-02-10 21:24:04 +01:00
|
|
|
inline relocation_iterator SectionRef::relocation_begin() const {
|
2013-09-27 23:47:05 +02:00
|
|
|
return OwningObject->section_rel_begin(SectionPimpl);
|
2011-10-07 21:25:32 +02:00
|
|
|
}
|
|
|
|
|
2014-02-10 21:24:04 +01:00
|
|
|
inline relocation_iterator SectionRef::relocation_end() const {
|
2013-09-27 23:47:05 +02:00
|
|
|
return OwningObject->section_rel_end(SectionPimpl);
|
2011-10-07 21:25:32 +02:00
|
|
|
}
|
|
|
|
|
2013-05-30 05:05:14 +02:00
|
|
|
inline section_iterator SectionRef::getRelocatedSection() const {
|
|
|
|
return OwningObject->getRelocatedSection(SectionPimpl);
|
|
|
|
}
|
|
|
|
|
2012-04-12 22:13:57 +02:00
|
|
|
inline DataRefImpl SectionRef::getRawDataRefImpl() const {
|
|
|
|
return SectionPimpl;
|
|
|
|
}
|
2011-09-08 22:52:17 +02:00
|
|
|
|
2014-12-10 21:46:55 +01:00
|
|
|
inline const ObjectFile *SectionRef::getObject() const {
|
|
|
|
return OwningObject;
|
|
|
|
}
|
|
|
|
|
2011-09-08 22:52:17 +02: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 03:49:50 +01:00
|
|
|
inline void RelocationRef::moveNext() {
|
|
|
|
return OwningObject->moveRelocationNext(RelocationPimpl);
|
2011-09-08 22:52:17 +02:00
|
|
|
}
|
|
|
|
|
2015-06-30 01:29:12 +02:00
|
|
|
inline uint64_t RelocationRef::getOffset() const {
|
|
|
|
return OwningObject->getRelocationOffset(RelocationPimpl);
|
2011-11-29 18:40:10 +01:00
|
|
|
}
|
|
|
|
|
2013-06-05 03:33:53 +02:00
|
|
|
inline symbol_iterator RelocationRef::getSymbol() const {
|
|
|
|
return OwningObject->getRelocationSymbol(RelocationPimpl);
|
2011-09-08 22:52:17 +02:00
|
|
|
}
|
|
|
|
|
2015-06-30 03:53:01 +02:00
|
|
|
inline uint64_t RelocationRef::getType() const {
|
|
|
|
return OwningObject->getRelocationType(RelocationPimpl);
|
2011-09-08 22:52:17 +02:00
|
|
|
}
|
|
|
|
|
2015-06-30 06:08:37 +02:00
|
|
|
inline void RelocationRef::getTypeName(SmallVectorImpl<char> &Result) const {
|
2011-10-07 21:25:32 +02:00
|
|
|
return OwningObject->getRelocationTypeName(RelocationPimpl, Result);
|
|
|
|
}
|
|
|
|
|
2012-06-18 21:47:16 +02:00
|
|
|
inline DataRefImpl RelocationRef::getRawDataRefImpl() const {
|
|
|
|
return RelocationPimpl;
|
|
|
|
}
|
|
|
|
|
2015-06-26 16:51:16 +02:00
|
|
|
inline const ObjectFile *RelocationRef::getObject() const {
|
2013-05-09 05:39:05 +02:00
|
|
|
return OwningObject;
|
|
|
|
}
|
|
|
|
|
2010-11-15 04:21:41 +01:00
|
|
|
} // end namespace object
|
2017-04-20 01:02:10 +02:00
|
|
|
|
2010-11-15 04:21:41 +01:00
|
|
|
} // end namespace llvm
|
|
|
|
|
2017-04-20 01:02:10 +02:00
|
|
|
#endif // LLVM_OBJECT_OBJECTFILE_H
|