summaryrefslogtreecommitdiffstats
path: root/include/llvm/Object
diff options
context:
space:
mode:
Diffstat (limited to 'include/llvm/Object')
-rw-r--r--include/llvm/Object/Archive.h11
-rw-r--r--include/llvm/Object/ArchiveWriter.h4
-rw-r--r--include/llvm/Object/COFF.h8
-rw-r--r--include/llvm/Object/ELF.h101
-rw-r--r--include/llvm/Object/ELFObjectFile.h58
-rw-r--r--include/llvm/Object/ELFTypes.h18
-rw-r--r--include/llvm/Object/ELFYAML.h16
-rw-r--r--include/llvm/Object/MachO.h9
-rw-r--r--include/llvm/Object/ObjectFile.h19
-rw-r--r--include/llvm/Object/RelocVisitor.h15
-rw-r--r--include/llvm/Object/SymbolicFile.h2
11 files changed, 150 insertions, 111 deletions
diff --git a/include/llvm/Object/Archive.h b/include/llvm/Object/Archive.h
index 8da6919..597f0d4 100644
--- a/include/llvm/Object/Archive.h
+++ b/include/llvm/Object/Archive.h
@@ -94,9 +94,7 @@ public:
/// \return the size in the archive header for this member.
uint64_t getRawSize() const;
- StringRef getBuffer() const {
- return StringRef(Data.data() + StartOfFile, getSize());
- }
+ ErrorOr<StringRef> getBuffer() const;
uint64_t getChildOffset() const;
ErrorOr<MemoryBufferRef> getMemoryBufferRef() const;
@@ -183,6 +181,7 @@ public:
};
Kind kind() const { return (Kind)Format; }
+ bool isThin() const { return IsThin; }
child_iterator child_begin(bool SkipInternal = true) const;
child_iterator child_end() const;
@@ -207,6 +206,11 @@ public:
bool hasSymbolTable() const;
child_iterator getSymbolTableChild() const { return SymbolTable; }
+ StringRef getSymbolTable() const {
+ // We know that the symbol table is not an external file,
+ // so we just assert there is no error.
+ return *SymbolTable->getBuffer();
+ }
uint32_t getNumberOfSymbols() const;
private:
@@ -215,6 +219,7 @@ private:
child_iterator FirstRegular;
unsigned Format : 2;
unsigned IsThin : 1;
+ mutable std::vector<std::unique_ptr<MemoryBuffer>> ThinBuffers;
};
}
diff --git a/include/llvm/Object/ArchiveWriter.h b/include/llvm/Object/ArchiveWriter.h
index 1616e46..3648d0c 100644
--- a/include/llvm/Object/ArchiveWriter.h
+++ b/include/llvm/Object/ArchiveWriter.h
@@ -31,7 +31,6 @@ class NewArchiveIterator {
public:
NewArchiveIterator(object::Archive::child_iterator I, StringRef Name);
NewArchiveIterator(StringRef I, StringRef Name);
- NewArchiveIterator();
bool isNewMember() const;
StringRef getName() const;
@@ -44,8 +43,7 @@ public:
std::pair<StringRef, std::error_code>
writeArchive(StringRef ArcName, std::vector<NewArchiveIterator> &NewMembers,
- bool WriteSymtab);
-
+ bool WriteSymtab, object::Archive::Kind Kind, bool Deterministic);
}
#endif
diff --git a/include/llvm/Object/COFF.h b/include/llvm/Object/COFF.h
index fc60582..025a9db 100644
--- a/include/llvm/Object/COFF.h
+++ b/include/llvm/Object/COFF.h
@@ -474,7 +474,7 @@ struct coff_import_header {
support::ulittle16_t OrdinalHint;
support::ulittle16_t TypeInfo;
int getType() const { return TypeInfo & 0x3; }
- int getNameType() const { return (TypeInfo & 0x7) >> 2; }
+ int getNameType() const { return (TypeInfo >> 2) & 0x7; }
};
struct coff_import_directory_table_entry {
@@ -648,9 +648,8 @@ public:
protected:
void moveSymbolNext(DataRefImpl &Symb) const override;
ErrorOr<StringRef> getSymbolName(DataRefImpl Symb) const override;
- std::error_code getSymbolAddress(DataRefImpl Symb,
- uint64_t &Res) const override;
- uint64_t getSymbolValue(DataRefImpl Symb) const override;
+ ErrorOr<uint64_t> getSymbolAddress(DataRefImpl Symb) const override;
+ uint64_t getSymbolValueImpl(DataRefImpl Symb) const override;
uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const override;
uint32_t getSymbolFlags(DataRefImpl Symb) const override;
SymbolRef::Type getSymbolType(DataRefImpl Symb) const override;
@@ -672,7 +671,6 @@ protected:
relocation_iterator section_rel_end(DataRefImpl Sec) const override;
void moveRelocationNext(DataRefImpl &Rel) const override;
- ErrorOr<uint64_t> getRelocationAddress(DataRefImpl Rel) const override;
uint64_t getRelocationOffset(DataRefImpl Rel) const override;
symbol_iterator getRelocationSymbol(DataRefImpl Rel) const override;
uint64_t getRelocationType(DataRefImpl Rel) const override;
diff --git a/include/llvm/Object/ELF.h b/include/llvm/Object/ELF.h
index 3b0c548..cc27185 100644
--- a/include/llvm/Object/ELF.h
+++ b/include/llvm/Object/ELF.h
@@ -16,6 +16,7 @@
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/IntervalMap.h"
#include "llvm/ADT/PointerIntPair.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringSwitch.h"
@@ -139,6 +140,7 @@ public:
typedef Elf_Verneed_Impl<ELFT> Elf_Verneed;
typedef Elf_Vernaux_Impl<ELFT> Elf_Vernaux;
typedef Elf_Versym_Impl<ELFT> Elf_Versym;
+ typedef Elf_Hash_Impl<ELFT> Elf_Hash;
typedef ELFEntityIterator<const Elf_Dyn> Elf_Dyn_Iter;
typedef iterator_range<Elf_Dyn_Iter> Elf_Dyn_Range;
typedef ELFEntityIterator<const Elf_Rela> Elf_Rela_Iter;
@@ -174,8 +176,8 @@ private:
StringRef DotShstrtab; // Section header string table.
StringRef DotStrtab; // Symbol header string table.
const Elf_Shdr *dot_symtab_sec = nullptr; // Symbol table section.
- StringRef DynSymStrTab; // Dynnamic symbol string table.
const Elf_Shdr *DotDynSymSec = nullptr; // Dynamic symbol table section.
+ const Elf_Hash *HashTable = nullptr;
const Elf_Shdr *SymbolTableSectionHeaderIndex = nullptr;
DenseMap<const Elf_Sym *, ELF::Elf64_Word> ExtendedSymbolTable;
@@ -197,6 +199,7 @@ private:
DynRegionInfo DynamicRegion;
DynRegionInfo DynHashRegion;
+ DynRegionInfo DynStrRegion;
DynRegionInfo DynRelaRegion;
// Pointer to SONAME entry in dynamic string table
@@ -229,6 +232,8 @@ private:
void LoadVersionNeeds(const Elf_Shdr *ec) const;
void LoadVersionMap() const;
+ void scanDynamicTable();
+
public:
template<typename T>
const T *getEntry(uint32_t Section, uint32_t Entry) const;
@@ -237,6 +242,7 @@ public:
const Elf_Shdr *getDotSymtabSec() const { return dot_symtab_sec; }
const Elf_Shdr *getDotDynSymSec() const { return DotDynSymSec; }
+ const Elf_Hash *getHashTable() const { return HashTable; }
ErrorOr<StringRef> getStringTable(const Elf_Shdr *Section) const;
const char *getDynamicString(uintX_t Offset) const;
@@ -578,8 +584,10 @@ ELFFile<ELFT>::ELFFile(StringRef Object, std::error_code &EC)
Header = reinterpret_cast<const Elf_Ehdr *>(base());
- if (Header->e_shoff == 0)
+ if (Header->e_shoff == 0) {
+ scanDynamicTable();
return;
+ }
const uint64_t SectionTableOffset = Header->e_shoff;
@@ -604,6 +612,13 @@ ELFFile<ELFT>::ELFFile(StringRef Object, std::error_code &EC)
for (const Elf_Shdr &Sec : sections()) {
switch (Sec.sh_type) {
+ case ELF::SHT_HASH:
+ if (HashTable) {
+ EC = object_error::parse_failed;
+ return;
+ }
+ HashTable = reinterpret_cast<const Elf_Hash *>(base() + Sec.sh_offset);
+ break;
case ELF::SHT_SYMTAB_SHNDX:
if (SymbolTableSectionHeaderIndex) {
// More than one .symtab_shndx!
@@ -640,7 +655,9 @@ ELFFile<ELFT>::ELFFile(StringRef Object, std::error_code &EC)
ErrorOr<StringRef> SymtabOrErr = getStringTable(*SectionOrErr);
if ((EC = SymtabOrErr.getError()))
return;
- DynSymStrTab = *SymtabOrErr;
+ DynStrRegion.Addr = SymtabOrErr->data();
+ DynStrRegion.Size = SymtabOrErr->size();
+ DynStrRegion.EntSize = 1;
break;
}
case ELF::SHT_DYNAMIC:
@@ -701,7 +718,23 @@ ELFFile<ELFT>::ELFFile(StringRef Object, std::error_code &EC)
}
}
- // Scan program headers.
+ scanDynamicTable();
+
+ EC = std::error_code();
+}
+
+template <class ELFT>
+void ELFFile<ELFT>::scanDynamicTable() {
+ // Build load-address to file-offset map.
+ typedef IntervalMap<
+ uintX_t, uintptr_t,
+ IntervalMapImpl::NodeSizer<uintX_t, uintptr_t>::LeafSize,
+ IntervalMapHalfOpenInfo<uintX_t>> LoadMapT;
+ typename LoadMapT::Allocator Alloc;
+ // Allocate the IntervalMap on the heap to work around MSVC bug where the
+ // stack doesn't get realigned despite LoadMap having alignment 8 (PR24113).
+ std::unique_ptr<LoadMapT> LoadMap(new LoadMapT(Alloc));
+
for (Elf_Phdr_Iter PhdrI = program_header_begin(),
PhdrE = program_header_end();
PhdrI != PhdrE; ++PhdrI) {
@@ -709,34 +742,44 @@ ELFFile<ELFT>::ELFFile(StringRef Object, std::error_code &EC)
DynamicRegion.Addr = base() + PhdrI->p_offset;
DynamicRegion.Size = PhdrI->p_filesz;
DynamicRegion.EntSize = sizeof(Elf_Dyn);
- break;
+ continue;
}
+ if (PhdrI->p_type != ELF::PT_LOAD)
+ continue;
+ if (PhdrI->p_filesz == 0)
+ continue;
+ LoadMap->insert(PhdrI->p_vaddr, PhdrI->p_vaddr + PhdrI->p_filesz,
+ PhdrI->p_offset);
}
- // Scan dynamic table.
+ auto toMappedAddr = [&](uint64_t VAddr) -> const uint8_t * {
+ auto I = LoadMap->find(VAddr);
+ if (I == LoadMap->end())
+ return nullptr;
+ return this->base() + I.value() + (VAddr - I.start());
+ };
+
for (Elf_Dyn_Iter DynI = dynamic_table_begin(), DynE = dynamic_table_end();
DynI != DynE; ++DynI) {
switch (DynI->d_tag) {
- case ELF::DT_RELA: {
- uint64_t VBase = 0;
- const uint8_t *FBase = nullptr;
- for (Elf_Phdr_Iter PhdrI = program_header_begin(),
- PhdrE = program_header_end();
- PhdrI != PhdrE; ++PhdrI) {
- if (PhdrI->p_type != ELF::PT_LOAD)
- continue;
- if (DynI->getPtr() >= PhdrI->p_vaddr &&
- DynI->getPtr() < PhdrI->p_vaddr + PhdrI->p_memsz) {
- VBase = PhdrI->p_vaddr;
- FBase = base() + PhdrI->p_offset;
- break;
- }
- }
- if (!VBase)
- return;
- DynRelaRegion.Addr = FBase + DynI->getPtr() - VBase;
+ case ELF::DT_HASH:
+ if (HashTable)
+ continue;
+ HashTable =
+ reinterpret_cast<const Elf_Hash *>(toMappedAddr(DynI->getPtr()));
+ break;
+ case ELF::DT_STRTAB:
+ if (!DynStrRegion.Addr)
+ DynStrRegion.Addr = toMappedAddr(DynI->getPtr());
+ break;
+ case ELF::DT_STRSZ:
+ if (!DynStrRegion.Size)
+ DynStrRegion.Size = DynI->getVal();
+ break;
+ case ELF::DT_RELA:
+ if (!DynRelaRegion.Addr)
+ DynRelaRegion.Addr = toMappedAddr(DynI->getPtr());
break;
- }
case ELF::DT_RELASZ:
DynRelaRegion.Size = DynI->getVal();
break;
@@ -744,8 +787,6 @@ ELFFile<ELFT>::ELFFile(StringRef Object, std::error_code &EC)
DynRelaRegion.EntSize = DynI->getVal();
}
}
-
- EC = std::error_code();
}
template <class ELFT>
@@ -868,9 +909,9 @@ ELFFile<ELFT>::getStringTable(const Elf_Shdr *Section) const {
template <class ELFT>
const char *ELFFile<ELFT>::getDynamicString(uintX_t Offset) const {
- if (!DotDynSymSec || Offset >= DynSymStrTab.size())
+ if (Offset >= DynStrRegion.Size)
return nullptr;
- return (const char *)DynSymStrTab.begin() + Offset;
+ return (const char *)DynStrRegion.Addr + Offset;
}
template <class ELFT>
@@ -983,7 +1024,7 @@ ErrorOr<StringRef> ELFFile<ELFT>::getSymbolVersion(const Elf_Shdr *section,
IsDefault = false;
}
- if (name_offset >= DynSymStrTab.size())
+ if (name_offset >= DynStrRegion.Size)
return object_error::parse_failed;
return StringRef(getDynamicString(name_offset));
}
diff --git a/include/llvm/Object/ELFObjectFile.h b/include/llvm/Object/ELFObjectFile.h
index 5b9b113..6e8ace4 100644
--- a/include/llvm/Object/ELFObjectFile.h
+++ b/include/llvm/Object/ELFObjectFile.h
@@ -196,9 +196,8 @@ protected:
void moveSymbolNext(DataRefImpl &Symb) const override;
ErrorOr<StringRef> getSymbolName(DataRefImpl Symb) const override;
- std::error_code getSymbolAddress(DataRefImpl Symb,
- uint64_t &Res) const override;
- uint64_t getSymbolValue(DataRefImpl Symb) const override;
+ ErrorOr<uint64_t> getSymbolAddress(DataRefImpl Symb) const override;
+ uint64_t getSymbolValueImpl(DataRefImpl Symb) const override;
uint32_t getSymbolAlignment(DataRefImpl Symb) const override;
uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const override;
uint32_t getSymbolFlags(DataRefImpl Symb) const override;
@@ -226,7 +225,6 @@ protected:
section_iterator getRelocatedSection(DataRefImpl Sec) const override;
void moveRelocationNext(DataRefImpl &Rel) const override;
- ErrorOr<uint64_t> getRelocationAddress(DataRefImpl Rel) const override;
uint64_t getRelocationOffset(DataRefImpl Rel) const override;
symbol_iterator getRelocationSymbol(DataRefImpl Rel) const override;
uint64_t getRelocationType(DataRefImpl Rel) const override;
@@ -235,7 +233,6 @@ protected:
uint32_t getSectionType(DataRefImpl Sec) const override;
uint64_t getSectionFlags(DataRefImpl Sec) const override;
- uint64_t getROffset(DataRefImpl Rel) const;
StringRef getRelocationTypeName(uint32_t Type) const;
/// \brief Get the relocation section that contains \a Rel.
@@ -276,11 +273,6 @@ protected:
return DRI;
}
- Elf_Dyn_Iter toELFDynIter(DataRefImpl Dyn) const {
- return Elf_Dyn_Iter(EF.begin_dynamic_table().getEntSize(),
- reinterpret_cast<const char *>(Dyn.p));
- }
-
DataRefImpl toDRI(Elf_Dyn_Iter Dyn) const {
DataRefImpl DRI;
DRI.p = reinterpret_cast<uintptr_t>(Dyn.get());
@@ -378,19 +370,13 @@ uint32_t ELFObjectFile<ELFT>::getSectionType(DataRefImpl Sec) const {
}
template <class ELFT>
-uint64_t ELFObjectFile<ELFT>::getSymbolValue(DataRefImpl Symb) const {
+uint64_t ELFObjectFile<ELFT>::getSymbolValueImpl(DataRefImpl Symb) const {
const Elf_Sym *ESym = getSymbol(Symb);
- switch (ESym->st_shndx) {
- case ELF::SHN_COMMON:
- case ELF::SHN_UNDEF:
- return UnknownAddress;
- case ELF::SHN_ABS:
- return ESym->st_value;
- }
-
- const Elf_Ehdr *Header = EF.getHeader();
uint64_t Ret = ESym->st_value;
+ if (ESym->st_shndx == ELF::SHN_ABS)
+ return Ret;
+ const Elf_Ehdr *Header = EF.getHeader();
// Clear the ARM/Thumb or microMIPS indicator flag.
if ((Header->e_machine == ELF::EM_ARM || Header->e_machine == ELF::EM_MIPS) &&
ESym->getType() == ELF::STT_FUNC)
@@ -400,15 +386,15 @@ uint64_t ELFObjectFile<ELFT>::getSymbolValue(DataRefImpl Symb) const {
}
template <class ELFT>
-std::error_code ELFObjectFile<ELFT>::getSymbolAddress(DataRefImpl Symb,
- uint64_t &Result) const {
- Result = getSymbolValue(Symb);
+ErrorOr<uint64_t>
+ELFObjectFile<ELFT>::getSymbolAddress(DataRefImpl Symb) const {
+ uint64_t Result = getSymbolValue(Symb);
const Elf_Sym *ESym = getSymbol(Symb);
switch (ESym->st_shndx) {
case ELF::SHN_COMMON:
case ELF::SHN_UNDEF:
case ELF::SHN_ABS:
- return std::error_code();
+ return Result;
}
const Elf_Ehdr *Header = EF.getHeader();
@@ -422,7 +408,7 @@ std::error_code ELFObjectFile<ELFT>::getSymbolAddress(DataRefImpl Symb,
Result += Section->sh_addr;
}
- return std::error_code();
+ return Result;
}
template <class ELFT>
@@ -689,31 +675,9 @@ ELFObjectFile<ELFT>::getRelocationSymbol(DataRefImpl Rel) const {
}
template <class ELFT>
-ErrorOr<uint64_t>
-ELFObjectFile<ELFT>::getRelocationAddress(DataRefImpl Rel) const {
- uint64_t ROffset = getROffset(Rel);
- const Elf_Ehdr *Header = EF.getHeader();
-
- if (Header->e_type == ELF::ET_REL) {
- const Elf_Shdr *RelocationSec = getRelSection(Rel);
- ErrorOr<const Elf_Shdr *> RelocatedSec =
- EF.getSection(RelocationSec->sh_info);
- if (std::error_code EC = RelocatedSec.getError())
- return EC;
- return ROffset + (*RelocatedSec)->sh_addr;
- }
- return ROffset;
-}
-
-template <class ELFT>
uint64_t ELFObjectFile<ELFT>::getRelocationOffset(DataRefImpl Rel) const {
assert(EF.getHeader()->e_type == ELF::ET_REL &&
"Only relocatable object files have relocation offsets");
- return getROffset(Rel);
-}
-
-template <class ELFT>
-uint64_t ELFObjectFile<ELFT>::getROffset(DataRefImpl Rel) const {
const Elf_Shdr *sec = getRelSection(Rel);
if (sec->sh_type == ELF::SHT_REL)
return getRel(Rel)->r_offset;
diff --git a/include/llvm/Object/ELFTypes.h b/include/llvm/Object/ELFTypes.h
index 63e1390..27e987b 100644
--- a/include/llvm/Object/ELFTypes.h
+++ b/include/llvm/Object/ELFTypes.h
@@ -10,6 +10,7 @@
#ifndef LLVM_OBJECT_ELFTYPES_H
#define LLVM_OBJECT_ELFTYPES_H
+#include "llvm/ADT/ArrayRef.h"
#include "llvm/Object/Error.h"
#include "llvm/Support/DataTypes.h"
#include "llvm/Support/ELF.h"
@@ -463,6 +464,23 @@ struct Elf_Phdr_Impl<ELFType<TargetEndianness, true>> {
Elf_Xword p_align; // Segment alignment constraint
};
+// ELFT needed for endianess.
+template <class ELFT>
+struct Elf_Hash_Impl {
+ LLVM_ELF_IMPORT_TYPES_ELFT(ELFT)
+ Elf_Word nbucket;
+ Elf_Word nchain;
+
+ ArrayRef<Elf_Word> buckets() const {
+ return ArrayRef<Elf_Word>(&nbucket + 2, &nbucket + 2 + nbucket);
+ }
+
+ ArrayRef<Elf_Word> chains() const {
+ return ArrayRef<Elf_Word>(&nbucket + 2 + nbucket,
+ &nbucket + 2 + nbucket + nchain);
+ }
+};
+
// MIPS .reginfo section
template <class ELFT>
struct Elf_Mips_RegInfo;
diff --git a/include/llvm/Object/ELFYAML.h b/include/llvm/Object/ELFYAML.h
index b455079..df0aa50 100644
--- a/include/llvm/Object/ELFYAML.h
+++ b/include/llvm/Object/ELFYAML.h
@@ -85,7 +85,13 @@ struct SectionOrType {
};
struct Section {
- enum class SectionKind { Group, RawContent, Relocation, MipsABIFlags };
+ enum class SectionKind {
+ Group,
+ RawContent,
+ Relocation,
+ NoBits,
+ MipsABIFlags
+ };
SectionKind Kind;
StringRef Name;
ELF_SHT Type;
@@ -106,6 +112,14 @@ struct RawContentSection : Section {
}
};
+struct NoBitsSection : Section {
+ llvm::yaml::Hex64 Size;
+ NoBitsSection() : Section(SectionKind::NoBits) {}
+ static bool classof(const Section *S) {
+ return S->Kind == SectionKind::NoBits;
+ }
+};
+
struct Group : Section {
// Members of a group contain a flag and a list of section indices
// that are part of the group.
diff --git a/include/llvm/Object/MachO.h b/include/llvm/Object/MachO.h
index f4edfd0..489ecef 100644
--- a/include/llvm/Object/MachO.h
+++ b/include/llvm/Object/MachO.h
@@ -205,9 +205,7 @@ public:
std::error_code getIndirectName(DataRefImpl Symb, StringRef &Res) const;
unsigned getSectionType(SectionRef Sec) const;
- std::error_code getSymbolAddress(DataRefImpl Symb,
- uint64_t &Res) const override;
- uint64_t getSymbolValue(DataRefImpl Symb) const override;
+ ErrorOr<uint64_t> getSymbolAddress(DataRefImpl Symb) const override;
uint32_t getSymbolAlignment(DataRefImpl Symb) const override;
uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const override;
SymbolRef::Type getSymbolType(DataRefImpl Symb) const override;
@@ -233,7 +231,6 @@ public:
relocation_iterator section_rel_end(DataRefImpl Sec) const override;
void moveRelocationNext(DataRefImpl &Rel) const override;
- ErrorOr<uint64_t> getRelocationAddress(DataRefImpl Rel) const override;
uint64_t getRelocationOffset(DataRefImpl Rel) const override;
symbol_iterator getRelocationSymbol(DataRefImpl Rel) const override;
section_iterator getRelocationSection(DataRefImpl Rel) const;
@@ -245,6 +242,8 @@ public:
// MachO specific.
std::error_code getLibraryShortNameByIndex(unsigned Index, StringRef &) const;
+ section_iterator getRelocationRelocatedSection(relocation_iterator Rel) const;
+
// TODO: Would be useful to have an iterator based version
// of the load command interface too.
@@ -425,6 +424,8 @@ public:
}
private:
+ uint64_t getSymbolValueImpl(DataRefImpl Symb) const override;
+
union {
MachO::mach_header_64 Header64;
MachO::mach_header Header;
diff --git a/include/llvm/Object/ObjectFile.h b/include/llvm/Object/ObjectFile.h
index 62eab10..8dd5256 100644
--- a/include/llvm/Object/ObjectFile.h
+++ b/include/llvm/Object/ObjectFile.h
@@ -50,7 +50,6 @@ public:
void moveNext();
- ErrorOr<uint64_t> getAddress() const;
uint64_t getOffset() const;
symbol_iterator getSymbol() const;
uint64_t getType() const;
@@ -135,7 +134,7 @@ public:
ErrorOr<StringRef> getName() const;
/// Returns the symbol virtual address (i.e. address at which it will be
/// mapped).
- std::error_code getAddress(uint64_t &Result) const;
+ ErrorOr<uint64_t> getAddress() const;
/// Return the value of the symbol depending on the object this can be an
/// offset or a virtual address.
@@ -198,9 +197,8 @@ protected:
virtual ErrorOr<StringRef> getSymbolName(DataRefImpl Symb) const = 0;
std::error_code printSymbolName(raw_ostream &OS,
DataRefImpl Symb) const override;
- virtual std::error_code getSymbolAddress(DataRefImpl Symb,
- uint64_t &Res) const = 0;
- virtual uint64_t getSymbolValue(DataRefImpl Symb) const = 0;
+ virtual ErrorOr<uint64_t> getSymbolAddress(DataRefImpl Symb) const = 0;
+ virtual uint64_t getSymbolValueImpl(DataRefImpl Symb) const = 0;
virtual uint32_t getSymbolAlignment(DataRefImpl Symb) const;
virtual uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const = 0;
virtual SymbolRef::Type getSymbolType(DataRefImpl Symb) const = 0;
@@ -229,13 +227,14 @@ protected:
// Same as above for RelocationRef.
friend class RelocationRef;
virtual void moveRelocationNext(DataRefImpl &Rel) const = 0;
- virtual ErrorOr<uint64_t> getRelocationAddress(DataRefImpl Rel) const = 0;
virtual uint64_t getRelocationOffset(DataRefImpl Rel) const = 0;
virtual symbol_iterator getRelocationSymbol(DataRefImpl Rel) const = 0;
virtual uint64_t getRelocationType(DataRefImpl Rel) const = 0;
virtual void getRelocationTypeName(DataRefImpl Rel,
SmallVectorImpl<char> &Result) const = 0;
+ uint64_t getSymbolValue(DataRefImpl Symb) const;
+
public:
uint64_t getCommonSymbolSize(DataRefImpl Symb) const {
assert(getSymbolFlags(Symb) & SymbolRef::SF_Common);
@@ -308,8 +307,8 @@ inline ErrorOr<StringRef> SymbolRef::getName() const {
return getObject()->getSymbolName(getRawDataRefImpl());
}
-inline std::error_code SymbolRef::getAddress(uint64_t &Result) const {
- return getObject()->getSymbolAddress(getRawDataRefImpl(), Result);
+inline ErrorOr<uint64_t> SymbolRef::getAddress() const {
+ return getObject()->getSymbolAddress(getRawDataRefImpl());
}
inline uint64_t SymbolRef::getValue() const {
@@ -430,10 +429,6 @@ inline void RelocationRef::moveNext() {
return OwningObject->moveRelocationNext(RelocationPimpl);
}
-inline ErrorOr<uint64_t> RelocationRef::getAddress() const {
- return OwningObject->getRelocationAddress(RelocationPimpl);
-}
-
inline uint64_t RelocationRef::getOffset() const {
return OwningObject->getRelocationOffset(RelocationPimpl);
}
diff --git a/include/llvm/Object/RelocVisitor.h b/include/llvm/Object/RelocVisitor.h
index 950e2ed..d5e4258 100644
--- a/include/llvm/Object/RelocVisitor.h
+++ b/include/llvm/Object/RelocVisitor.h
@@ -100,9 +100,9 @@ private:
case Triple::mips64:
switch (RelocType) {
case llvm::ELF::R_MIPS_32:
- return visitELF_MIPS_32(R, Value);
+ return visitELF_MIPS64_32(R, Value);
case llvm::ELF::R_MIPS_64:
- return visitELF_MIPS_64(R, Value);
+ return visitELF_MIPS64_64(R, Value);
default:
HasError = true;
return RelocToApply();
@@ -313,11 +313,18 @@ private:
/// MIPS ELF
RelocToApply visitELF_MIPS_32(RelocationRef R, uint64_t Value) {
- uint32_t Res = (Value)&0xFFFFFFFF;
+ uint32_t Res = Value & 0xFFFFFFFF;
+ return RelocToApply(Res, 4);
+ }
+
+ /// MIPS64 ELF
+ RelocToApply visitELF_MIPS64_32(RelocationRef R, uint64_t Value) {
+ int64_t Addend = getELFAddend(R);
+ uint32_t Res = (Value + Addend) & 0xFFFFFFFF;
return RelocToApply(Res, 4);
}
- RelocToApply visitELF_MIPS_64(RelocationRef R, uint64_t Value) {
+ RelocToApply visitELF_MIPS64_64(RelocationRef R, uint64_t Value) {
int64_t Addend = getELFAddend(R);
uint64_t Res = (Value + Addend);
return RelocToApply(Res, 8);
diff --git a/include/llvm/Object/SymbolicFile.h b/include/llvm/Object/SymbolicFile.h
index 3a38231..537997a 100644
--- a/include/llvm/Object/SymbolicFile.h
+++ b/include/llvm/Object/SymbolicFile.h
@@ -115,8 +115,6 @@ public:
typedef content_iterator<BasicSymbolRef> basic_symbol_iterator;
-const uint64_t UnknownAddress = ~0ULL;
-
class SymbolicFile : public Binary {
public:
~SymbolicFile() override;
OpenPOWER on IntegriCloud