summaryrefslogtreecommitdiffstats
path: root/contrib/llvm/lib/Object
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm/lib/Object')
-rw-r--r--contrib/llvm/lib/Object/COFFObjectFile.cpp166
-rw-r--r--contrib/llvm/lib/Object/COFFYAML.cpp6
-rw-r--r--contrib/llvm/lib/Object/ELFYAML.cpp4
-rw-r--r--contrib/llvm/lib/Object/Error.cpp4
-rw-r--r--contrib/llvm/lib/Object/IRObjectFile.cpp4
-rw-r--r--contrib/llvm/lib/Object/MachOObjectFile.cpp169
-rw-r--r--contrib/llvm/lib/Object/MachOUniversal.cpp20
-rw-r--r--contrib/llvm/lib/Object/Object.cpp32
-rw-r--r--contrib/llvm/lib/Object/ObjectFile.cpp13
-rw-r--r--contrib/llvm/lib/Object/RecordStreamer.h2
-rw-r--r--contrib/llvm/lib/Object/SymbolSize.cpp100
11 files changed, 273 insertions, 247 deletions
diff --git a/contrib/llvm/lib/Object/COFFObjectFile.cpp b/contrib/llvm/lib/Object/COFFObjectFile.cpp
index e2f559e..64bb0d5 100644
--- a/contrib/llvm/lib/Object/COFFObjectFile.cpp
+++ b/contrib/llvm/lib/Object/COFFObjectFile.cpp
@@ -16,6 +16,7 @@
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/ADT/Triple.h"
+#include "llvm/ADT/iterator_range.h"
#include "llvm/Support/COFF.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
@@ -144,68 +145,62 @@ void COFFObjectFile::moveSymbolNext(DataRefImpl &Ref) const {
}
}
-std::error_code COFFObjectFile::getSymbolName(DataRefImpl Ref,
- StringRef &Result) const {
+ErrorOr<StringRef> COFFObjectFile::getSymbolName(DataRefImpl Ref) const {
COFFSymbolRef Symb = getCOFFSymbol(Ref);
- return getSymbolName(Symb, Result);
+ StringRef Result;
+ std::error_code EC = getSymbolName(Symb, Result);
+ if (EC)
+ return EC;
+ return Result;
+}
+
+uint64_t COFFObjectFile::getSymbolValue(DataRefImpl Ref) const {
+ COFFSymbolRef Sym = getCOFFSymbol(Ref);
+
+ if (Sym.isAnyUndefined() || Sym.isCommon())
+ return UnknownAddress;
+
+ return Sym.getValue();
}
std::error_code COFFObjectFile::getSymbolAddress(DataRefImpl Ref,
uint64_t &Result) const {
+ Result = getSymbolValue(Ref);
COFFSymbolRef Symb = getCOFFSymbol(Ref);
-
- if (Symb.isAnyUndefined()) {
- Result = UnknownAddressOrSize;
- return std::error_code();
- }
- if (Symb.isCommon()) {
- Result = UnknownAddressOrSize;
- return std::error_code();
- }
int32_t SectionNumber = Symb.getSectionNumber();
- if (!COFF::isReservedSectionNumber(SectionNumber)) {
- const coff_section *Section = nullptr;
- if (std::error_code EC = getSection(SectionNumber, Section))
- return EC;
- Result = Section->VirtualAddress + Symb.getValue();
+ if (Symb.isAnyUndefined() || Symb.isCommon() ||
+ COFF::isReservedSectionNumber(SectionNumber))
return std::error_code();
- }
- Result = Symb.getValue();
+ const coff_section *Section = nullptr;
+ if (std::error_code EC = getSection(SectionNumber, Section))
+ return EC;
+ Result += Section->VirtualAddress;
return std::error_code();
}
-std::error_code COFFObjectFile::getSymbolType(DataRefImpl Ref,
- SymbolRef::Type &Result) const {
+SymbolRef::Type COFFObjectFile::getSymbolType(DataRefImpl Ref) const {
COFFSymbolRef Symb = getCOFFSymbol(Ref);
int32_t SectionNumber = Symb.getSectionNumber();
- Result = SymbolRef::ST_Other;
-
- if (Symb.isAnyUndefined()) {
- Result = SymbolRef::ST_Unknown;
- } else if (Symb.isFunctionDefinition()) {
- Result = SymbolRef::ST_Function;
- } else if (Symb.isCommon()) {
- Result = SymbolRef::ST_Data;
- } else if (Symb.isFileRecord()) {
- Result = SymbolRef::ST_File;
- } else if (SectionNumber == COFF::IMAGE_SYM_DEBUG ||
- Symb.isSectionDefinition()) {
- // TODO: perhaps we need a new symbol type ST_Section.
- Result = SymbolRef::ST_Debug;
- } else if (!COFF::isReservedSectionNumber(SectionNumber)) {
- const coff_section *Section = nullptr;
- if (std::error_code EC = getSection(SectionNumber, Section))
- return EC;
- uint32_t Characteristics = Section->Characteristics;
- if (Characteristics & COFF::IMAGE_SCN_CNT_CODE)
- Result = SymbolRef::ST_Function;
- else if (Characteristics & (COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
- COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA))
- Result = SymbolRef::ST_Data;
- }
- return std::error_code();
+
+ if (Symb.isAnyUndefined())
+ return SymbolRef::ST_Unknown;
+ if (Symb.isFunctionDefinition())
+ return SymbolRef::ST_Function;
+ if (Symb.isCommon())
+ return SymbolRef::ST_Data;
+ if (Symb.isFileRecord())
+ return SymbolRef::ST_File;
+
+ // TODO: perhaps we need a new symbol type ST_Section.
+ if (SectionNumber == COFF::IMAGE_SYM_DEBUG || Symb.isSectionDefinition())
+ return SymbolRef::ST_Debug;
+
+ if (!COFF::isReservedSectionNumber(SectionNumber))
+ return SymbolRef::ST_Data;
+
+ return SymbolRef::ST_Other;
}
uint32_t COFFObjectFile::getSymbolFlags(DataRefImpl Ref) const {
@@ -236,12 +231,9 @@ uint32_t COFFObjectFile::getSymbolFlags(DataRefImpl Ref) const {
return Result;
}
-uint64_t COFFObjectFile::getSymbolSize(DataRefImpl Ref) const {
+uint64_t COFFObjectFile::getCommonSymbolSizeImpl(DataRefImpl Ref) const {
COFFSymbolRef Symb = getCOFFSymbol(Ref);
-
- if (Symb.isCommon())
- return Symb.getValue();
- return UnknownAddressOrSize;
+ return Symb.getValue();
}
std::error_code
@@ -261,6 +253,11 @@ COFFObjectFile::getSymbolSection(DataRefImpl Ref,
return std::error_code();
}
+unsigned COFFObjectFile::getSymbolSectionID(SymbolRef Sym) const {
+ COFFSymbolRef Symb = getCOFFSymbol(Sym.getRawDataRefImpl());
+ return Symb.getSectionNumber();
+}
+
void COFFObjectFile::moveSectionNext(DataRefImpl &Ref) const {
const coff_section *Sec = toSec(Ref);
Sec += 1;
@@ -314,6 +311,13 @@ bool COFFObjectFile::isSectionBSS(DataRefImpl Ref) const {
return (Sec->Characteristics & BssFlags) == BssFlags;
}
+unsigned COFFObjectFile::getSectionID(SectionRef Sec) const {
+ uintptr_t Offset =
+ uintptr_t(Sec.getRawDataRefImpl().p) - uintptr_t(SectionTable);
+ assert((Offset % sizeof(coff_section)) == 0);
+ return (Offset / sizeof(coff_section)) + 1;
+}
+
bool COFFObjectFile::isSectionVirtual(DataRefImpl Ref) const {
const coff_section *Sec = toSec(Ref);
// In COFF, a virtual section won't have any in-file
@@ -321,14 +325,6 @@ bool COFFObjectFile::isSectionVirtual(DataRefImpl Ref) const {
return Sec->PointerToRawData == 0;
}
-bool COFFObjectFile::sectionContainsSymbol(DataRefImpl SecRef,
- DataRefImpl SymbRef) const {
- const coff_section *Sec = toSec(SecRef);
- COFFSymbolRef Symb = getCOFFSymbol(SymbRef);
- int32_t SecNumber = (Sec - SectionTable) + 1;
- return SecNumber == Symb.getSectionNumber();
-}
-
static uint32_t getNumberOfRelocations(const coff_section *Sec,
MemoryBufferRef M, const uint8_t *base) {
// The field for the number of relocations in COFF section table is only
@@ -846,20 +842,24 @@ std::error_code COFFObjectFile::getString(uint32_t Offset,
std::error_code COFFObjectFile::getSymbolName(COFFSymbolRef Symbol,
StringRef &Res) const {
+ return getSymbolName(Symbol.getGeneric(), Res);
+}
+
+std::error_code COFFObjectFile::getSymbolName(const coff_symbol_generic *Symbol,
+ StringRef &Res) const {
// Check for string table entry. First 4 bytes are 0.
- if (Symbol.getStringTableOffset().Zeroes == 0) {
- uint32_t Offset = Symbol.getStringTableOffset().Offset;
- if (std::error_code EC = getString(Offset, Res))
+ if (Symbol->Name.Offset.Zeroes == 0) {
+ if (std::error_code EC = getString(Symbol->Name.Offset.Offset, Res))
return EC;
return std::error_code();
}
- if (Symbol.getShortName()[COFF::NameSize - 1] == 0)
+ if (Symbol->Name.ShortName[COFF::NameSize - 1] == 0)
// Null terminated, let ::strlen figure out the length.
- Res = StringRef(Symbol.getShortName());
+ Res = StringRef(Symbol->Name.ShortName);
else
// Not null terminated, use all 8 bytes.
- Res = StringRef(Symbol.getShortName(), COFF::NameSize);
+ Res = StringRef(Symbol->Name.ShortName, COFF::NameSize);
return std::error_code();
}
@@ -961,20 +961,13 @@ void COFFObjectFile::moveRelocationNext(DataRefImpl &Rel) const {
reinterpret_cast<const coff_relocation*>(Rel.p) + 1);
}
-std::error_code COFFObjectFile::getRelocationAddress(DataRefImpl Rel,
- uint64_t &Res) const {
+ErrorOr<uint64_t> COFFObjectFile::getRelocationAddress(DataRefImpl Rel) const {
report_fatal_error("getRelocationAddress not implemented in COFFObjectFile");
}
-std::error_code COFFObjectFile::getRelocationOffset(DataRefImpl Rel,
- uint64_t &Res) const {
+uint64_t COFFObjectFile::getRelocationOffset(DataRefImpl Rel) const {
const coff_relocation *R = toRel(Rel);
- const support::ulittle32_t *VirtualAddressPtr;
- if (std::error_code EC =
- getObject(VirtualAddressPtr, Data, &R->VirtualAddress))
- return EC;
- Res = *VirtualAddressPtr;
- return std::error_code();
+ return R->VirtualAddress;
}
symbol_iterator COFFObjectFile::getRelocationSymbol(DataRefImpl Rel) const {
@@ -991,11 +984,9 @@ symbol_iterator COFFObjectFile::getRelocationSymbol(DataRefImpl Rel) const {
return symbol_iterator(SymbolRef(Ref, this));
}
-std::error_code COFFObjectFile::getRelocationType(DataRefImpl Rel,
- uint64_t &Res) const {
+uint64_t COFFObjectFile::getRelocationType(DataRefImpl Rel) const {
const coff_relocation* R = toRel(Rel);
- Res = R->Type;
- return std::error_code();
+ return R->Type;
}
const coff_section *
@@ -1020,14 +1011,22 @@ COFFObjectFile::getCOFFRelocation(const RelocationRef &Reloc) const {
return toRel(Reloc.getRawDataRefImpl());
}
+iterator_range<const coff_relocation *>
+COFFObjectFile::getRelocations(const coff_section *Sec) const {
+ const coff_relocation *I = getFirstReloc(Sec, Data, base());
+ const coff_relocation *E = I;
+ if (I)
+ E += getNumberOfRelocations(Sec, Data, base());
+ return make_range(I, E);
+}
+
#define LLVM_COFF_SWITCH_RELOC_TYPE_NAME(reloc_type) \
case COFF::reloc_type: \
Res = #reloc_type; \
break;
-std::error_code
-COFFObjectFile::getRelocationTypeName(DataRefImpl Rel,
- SmallVectorImpl<char> &Result) const {
+void COFFObjectFile::getRelocationTypeName(
+ DataRefImpl Rel, SmallVectorImpl<char> &Result) const {
const coff_relocation *Reloc = toRel(Rel);
StringRef Res;
switch (getMachine()) {
@@ -1096,7 +1095,6 @@ COFFObjectFile::getRelocationTypeName(DataRefImpl Rel,
Res = "Unknown";
}
Result.append(Res.begin(), Res.end());
- return std::error_code();
}
#undef LLVM_COFF_SWITCH_RELOC_TYPE_NAME
diff --git a/contrib/llvm/lib/Object/COFFYAML.cpp b/contrib/llvm/lib/Object/COFFYAML.cpp
index dda4b7f..9a24b53 100644
--- a/contrib/llvm/lib/Object/COFFYAML.cpp
+++ b/contrib/llvm/lib/Object/COFFYAML.cpp
@@ -335,7 +335,7 @@ struct NDLLCharacteristics {
COFF::DLLCharacteristics Characteristics;
};
-} // namespace
+}
void MappingTraits<COFFYAML::Relocation>::mapping(IO &IO,
COFFYAML::Relocation &Rel) {
@@ -497,5 +497,5 @@ void MappingTraits<COFFYAML::Object>::mapping(IO &IO, COFFYAML::Object &Obj) {
IO.mapRequired("symbols", Obj.Symbols);
}
-} // namespace yaml
-} // namespace llvm
+}
+}
diff --git a/contrib/llvm/lib/Object/ELFYAML.cpp b/contrib/llvm/lib/Object/ELFYAML.cpp
index 50730a9..ecdd468 100644
--- a/contrib/llvm/lib/Object/ELFYAML.cpp
+++ b/contrib/llvm/lib/Object/ELFYAML.cpp
@@ -590,7 +590,7 @@ struct NormalizedOther {
ELFYAML::ELF_STV Visibility;
ELFYAML::ELF_STO Other;
};
-} // namespace
+}
void MappingTraits<ELFYAML::Symbol>::mapping(IO &IO, ELFYAML::Symbol &Symbol) {
IO.mapOptional("Name", Symbol.Name, StringRef());
@@ -723,7 +723,7 @@ struct NormalizedMips64RelType {
ELFYAML::ELF_REL Type3;
ELFYAML::ELF_RSS SpecSym;
};
-} // namespace
+}
void MappingTraits<ELFYAML::Relocation>::mapping(IO &IO,
ELFYAML::Relocation &Rel) {
diff --git a/contrib/llvm/lib/Object/Error.cpp b/contrib/llvm/lib/Object/Error.cpp
index 644a178..7ca2f12 100644
--- a/contrib/llvm/lib/Object/Error.cpp
+++ b/contrib/llvm/lib/Object/Error.cpp
@@ -41,6 +41,10 @@ std::string _object_error_category::message(int EV) const {
return "Invalid data was encountered while parsing the file";
case object_error::unexpected_eof:
return "The end of the file was unexpectedly encountered";
+ case object_error::string_table_non_null_end:
+ return "String table must end with a null terminator";
+ case object_error::invalid_section_index:
+ return "Invalid section index";
case object_error::bitcode_section_not_found:
return "Bitcode section not found in object file";
case object_error::macho_small_load_command:
diff --git a/contrib/llvm/lib/Object/IRObjectFile.cpp b/contrib/llvm/lib/Object/IRObjectFile.cpp
index e90e08d..9f5132e 100644
--- a/contrib/llvm/lib/Object/IRObjectFile.cpp
+++ b/contrib/llvm/lib/Object/IRObjectFile.cpp
@@ -37,9 +37,7 @@ using namespace object;
IRObjectFile::IRObjectFile(MemoryBufferRef Object, std::unique_ptr<Module> Mod)
: SymbolicFile(Binary::ID_IR, Object), M(std::move(Mod)) {
- // Setup a mangler with the DataLayout.
- const DataLayout &DL = M->getDataLayout();
- Mang.reset(new Mangler(&DL));
+ Mang.reset(new Mangler());
const std::string &InlineAsm = M->getModuleInlineAsm();
if (InlineAsm.empty())
diff --git a/contrib/llvm/lib/Object/MachOObjectFile.cpp b/contrib/llvm/lib/Object/MachOObjectFile.cpp
index f76dd0d..4255ed7 100644
--- a/contrib/llvm/lib/Object/MachOObjectFile.cpp
+++ b/contrib/llvm/lib/Object/MachOObjectFile.cpp
@@ -327,16 +327,14 @@ void MachOObjectFile::moveSymbolNext(DataRefImpl &Symb) const {
Symb.p += SymbolTableEntrySize;
}
-std::error_code MachOObjectFile::getSymbolName(DataRefImpl Symb,
- StringRef &Res) const {
+ErrorOr<StringRef> MachOObjectFile::getSymbolName(DataRefImpl Symb) const {
StringRef StringTable = getStringTableData();
MachO::nlist_base Entry = getSymbolTableEntryBase(this, Symb);
const char *Start = &StringTable.data()[Entry.n_strx];
if (Start < getData().begin() || Start >= getData().end())
report_fatal_error(
"Symbol name entry points before beginning or past end of file.");
- Res = StringRef(Start);
- return std::error_code();
+ return StringRef(Start);
}
unsigned MachOObjectFile::getSectionType(SectionRef Sec) const {
@@ -345,23 +343,24 @@ unsigned MachOObjectFile::getSectionType(SectionRef Sec) const {
return Flags & MachO::SECTION_TYPE;
}
+uint64_t MachOObjectFile::getNValue(DataRefImpl Sym) const {
+ if (is64Bit()) {
+ MachO::nlist_64 Entry = getSymbol64TableEntry(Sym);
+ return Entry.n_value;
+ }
+ MachO::nlist Entry = getSymbolTableEntry(Sym);
+ return Entry.n_value;
+}
+
// getIndirectName() returns the name of the alias'ed symbol who's string table
// index is in the n_value field.
std::error_code MachOObjectFile::getIndirectName(DataRefImpl Symb,
StringRef &Res) const {
StringRef StringTable = getStringTableData();
- uint64_t NValue;
- if (is64Bit()) {
- MachO::nlist_64 Entry = getSymbol64TableEntry(Symb);
- NValue = Entry.n_value;
- if ((Entry.n_type & MachO::N_TYPE) != MachO::N_INDR)
- return object_error::parse_failed;
- } else {
- MachO::nlist Entry = getSymbolTableEntry(Symb);
- NValue = Entry.n_value;
- if ((Entry.n_type & MachO::N_TYPE) != MachO::N_INDR)
- return object_error::parse_failed;
- }
+ MachO::nlist_base Entry = getSymbolTableEntryBase(this, Symb);
+ if ((Entry.n_type & MachO::N_TYPE) != MachO::N_INDR)
+ return object_error::parse_failed;
+ uint64_t NValue = getNValue(Symb);
if (NValue >= StringTable.size())
return object_error::parse_failed;
const char *Start = &StringTable.data()[NValue];
@@ -369,23 +368,17 @@ std::error_code MachOObjectFile::getIndirectName(DataRefImpl Symb,
return std::error_code();
}
-std::error_code MachOObjectFile::getSymbolAddress(DataRefImpl Symb,
+uint64_t MachOObjectFile::getSymbolValue(DataRefImpl Sym) const {
+ uint64_t NValue = getNValue(Sym);
+ MachO::nlist_base Entry = getSymbolTableEntryBase(this, Sym);
+ if ((Entry.n_type & MachO::N_TYPE) == MachO::N_UNDF && NValue == 0)
+ return UnknownAddress;
+ return NValue;
+}
+
+std::error_code MachOObjectFile::getSymbolAddress(DataRefImpl Sym,
uint64_t &Res) const {
- if (is64Bit()) {
- MachO::nlist_64 Entry = getSymbol64TableEntry(Symb);
- if ((Entry.n_type & MachO::N_TYPE) == MachO::N_UNDF &&
- Entry.n_value == 0)
- Res = UnknownAddressOrSize;
- else
- Res = Entry.n_value;
- } else {
- MachO::nlist Entry = getSymbolTableEntry(Symb);
- if ((Entry.n_type & MachO::N_TYPE) == MachO::N_UNDF &&
- Entry.n_value == 0)
- Res = UnknownAddressOrSize;
- else
- Res = Entry.n_value;
- }
+ Res = getSymbolValue(Sym);
return std::error_code();
}
@@ -398,37 +391,27 @@ uint32_t MachOObjectFile::getSymbolAlignment(DataRefImpl DRI) const {
return 0;
}
-uint64_t MachOObjectFile::getSymbolSize(DataRefImpl DRI) const {
+uint64_t MachOObjectFile::getCommonSymbolSizeImpl(DataRefImpl DRI) const {
uint64_t Value;
getSymbolAddress(DRI, Value);
- uint32_t flags = getSymbolFlags(DRI);
- if (flags & SymbolRef::SF_Common)
- return Value;
- return UnknownAddressOrSize;
+ return Value;
}
-std::error_code MachOObjectFile::getSymbolType(DataRefImpl Symb,
- SymbolRef::Type &Res) const {
+SymbolRef::Type MachOObjectFile::getSymbolType(DataRefImpl Symb) const {
MachO::nlist_base Entry = getSymbolTableEntryBase(this, Symb);
uint8_t n_type = Entry.n_type;
- Res = SymbolRef::ST_Other;
-
// If this is a STAB debugging symbol, we can do nothing more.
- if (n_type & MachO::N_STAB) {
- Res = SymbolRef::ST_Debug;
- return std::error_code();
- }
+ if (n_type & MachO::N_STAB)
+ return SymbolRef::ST_Debug;
switch (n_type & MachO::N_TYPE) {
case MachO::N_UNDF :
- Res = SymbolRef::ST_Unknown;
- break;
+ return SymbolRef::ST_Unknown;
case MachO::N_SECT :
- Res = SymbolRef::ST_Function;
- break;
+ return SymbolRef::ST_Function;
}
- return std::error_code();
+ return SymbolRef::ST_Other;
}
uint32_t MachOObjectFile::getSymbolFlags(DataRefImpl DRI) const {
@@ -453,7 +436,7 @@ uint32_t MachOObjectFile::getSymbolFlags(DataRefImpl DRI) const {
if ((MachOType & MachO::N_TYPE) == MachO::N_UNDF) {
uint64_t Value;
getSymbolAddress(DRI, Value);
- if (Value && Value != UnknownAddressOrSize)
+ if (Value && Value != UnknownAddress)
Result |= SymbolRef::SF_Common;
}
@@ -491,6 +474,12 @@ std::error_code MachOObjectFile::getSymbolSection(DataRefImpl Symb,
return std::error_code();
}
+unsigned MachOObjectFile::getSymbolSectionID(SymbolRef Sym) const {
+ MachO::nlist_base Entry =
+ getSymbolTableEntryBase(this, Sym.getRawDataRefImpl());
+ return Entry.n_sect - 1;
+}
+
void MachOObjectFile::moveSectionNext(DataRefImpl &Sec) const {
Sec.d.a++;
}
@@ -567,27 +556,15 @@ bool MachOObjectFile::isSectionBSS(DataRefImpl Sec) const {
SectionType == MachO::S_GB_ZEROFILL);
}
+unsigned MachOObjectFile::getSectionID(SectionRef Sec) const {
+ return Sec.getRawDataRefImpl().d.a;
+}
+
bool MachOObjectFile::isSectionVirtual(DataRefImpl Sec) const {
// FIXME: Unimplemented.
return false;
}
-bool MachOObjectFile::sectionContainsSymbol(DataRefImpl Sec,
- DataRefImpl Symb) const {
- SymbolRef::Type ST;
- this->getSymbolType(Symb, ST);
- if (ST == SymbolRef::ST_Unknown)
- return false;
-
- uint64_t SectBegin = getSectionAddress(Sec);
- uint64_t SectEnd = getSectionSize(Sec);
- SectEnd += SectBegin;
-
- uint64_t SymAddr;
- getSymbolAddress(Symb, SymAddr);
- return (SymAddr >= SectBegin) && (SymAddr < SectEnd);
-}
-
relocation_iterator MachOObjectFile::section_rel_begin(DataRefImpl Sec) const {
DataRefImpl Ret;
Ret.d.a = Sec.d.a;
@@ -616,25 +593,20 @@ void MachOObjectFile::moveRelocationNext(DataRefImpl &Rel) const {
++Rel.d.b;
}
-std::error_code MachOObjectFile::getRelocationAddress(DataRefImpl Rel,
- uint64_t &Res) const {
- uint64_t Offset;
- getRelocationOffset(Rel, Offset);
+ErrorOr<uint64_t> MachOObjectFile::getRelocationAddress(DataRefImpl Rel) const {
+ uint64_t Offset = getRelocationOffset(Rel);
DataRefImpl Sec;
Sec.d.a = Rel.d.a;
uint64_t SecAddress = getSectionAddress(Sec);
- Res = SecAddress + Offset;
- return std::error_code();
+ return SecAddress + Offset;
}
-std::error_code MachOObjectFile::getRelocationOffset(DataRefImpl Rel,
- uint64_t &Res) const {
+uint64_t MachOObjectFile::getRelocationOffset(DataRefImpl Rel) const {
assert(getHeader().filetype == MachO::MH_OBJECT &&
"Only implemented for MH_OBJECT");
MachO::any_relocation_info RE = getRelocation(Rel);
- Res = getAnyRelocationAddress(RE);
- return std::error_code();
+ return getAnyRelocationAddress(RE);
}
symbol_iterator
@@ -663,19 +635,15 @@ MachOObjectFile::getRelocationSection(DataRefImpl Rel) const {
return section_iterator(getAnyRelocationSection(getRelocation(Rel)));
}
-std::error_code MachOObjectFile::getRelocationType(DataRefImpl Rel,
- uint64_t &Res) const {
+uint64_t MachOObjectFile::getRelocationType(DataRefImpl Rel) const {
MachO::any_relocation_info RE = getRelocation(Rel);
- Res = getAnyRelocationType(RE);
- return std::error_code();
+ return getAnyRelocationType(RE);
}
-std::error_code
-MachOObjectFile::getRelocationTypeName(DataRefImpl Rel,
- SmallVectorImpl<char> &Result) const {
+void MachOObjectFile::getRelocationTypeName(
+ DataRefImpl Rel, SmallVectorImpl<char> &Result) const {
StringRef res;
- uint64_t RType;
- getRelocationType(Rel, RType);
+ uint64_t RType = getRelocationType(Rel);
unsigned Arch = this->getArch();
@@ -779,35 +747,6 @@ MachOObjectFile::getRelocationTypeName(DataRefImpl Rel,
break;
}
Result.append(res.begin(), res.end());
- return std::error_code();
-}
-
-std::error_code MachOObjectFile::getRelocationHidden(DataRefImpl Rel,
- bool &Result) const {
- unsigned Arch = getArch();
- uint64_t Type;
- getRelocationType(Rel, Type);
-
- Result = false;
-
- // On arches that use the generic relocations, GENERIC_RELOC_PAIR
- // is always hidden.
- if (Arch == Triple::x86 || Arch == Triple::arm || Arch == Triple::ppc) {
- if (Type == MachO::GENERIC_RELOC_PAIR) Result = true;
- } else if (Arch == Triple::x86_64) {
- // On x86_64, X86_64_RELOC_UNSIGNED is hidden only when it follows
- // an X86_64_RELOC_SUBTRACTOR.
- if (Type == MachO::X86_64_RELOC_UNSIGNED && Rel.d.a > 0) {
- DataRefImpl RelPrev = Rel;
- RelPrev.d.a--;
- uint64_t PrevType;
- getRelocationType(RelPrev, PrevType);
- if (PrevType == MachO::X86_64_RELOC_SUBTRACTOR)
- Result = true;
- }
- }
-
- return std::error_code();
}
uint8_t MachOObjectFile::getRelocationLength(DataRefImpl Rel) const {
diff --git a/contrib/llvm/lib/Object/MachOUniversal.cpp b/contrib/llvm/lib/Object/MachOUniversal.cpp
index 2705e7d..1d0e69e 100644
--- a/contrib/llvm/lib/Object/MachOUniversal.cpp
+++ b/contrib/llvm/lib/Object/MachOUniversal.cpp
@@ -123,25 +123,13 @@ MachOUniversalBinary::MachOUniversalBinary(MemoryBufferRef Source,
ec = std::error_code();
}
-static bool getCTMForArch(Triple::ArchType Arch, MachO::CPUType &CTM) {
- switch (Arch) {
- case Triple::x86: CTM = MachO::CPU_TYPE_I386; return true;
- case Triple::x86_64: CTM = MachO::CPU_TYPE_X86_64; return true;
- case Triple::arm: CTM = MachO::CPU_TYPE_ARM; return true;
- case Triple::sparc: CTM = MachO::CPU_TYPE_SPARC; return true;
- case Triple::ppc: CTM = MachO::CPU_TYPE_POWERPC; return true;
- case Triple::ppc64: CTM = MachO::CPU_TYPE_POWERPC64; return true;
- default: return false;
- }
-}
-
ErrorOr<std::unique_ptr<MachOObjectFile>>
-MachOUniversalBinary::getObjectForArch(Triple::ArchType Arch) const {
- MachO::CPUType CTM;
- if (!getCTMForArch(Arch, CTM))
+MachOUniversalBinary::getObjectForArch(StringRef ArchName) const {
+ if (Triple(ArchName).getArch() == Triple::ArchType::UnknownArch)
return object_error::arch_not_found;
+
for (object_iterator I = begin_objects(), E = end_objects(); I != E; ++I) {
- if (I->getCPUType() == static_cast<uint32_t>(CTM))
+ if (I->getArchTypeName() == ArchName)
return I->getAsObjectFile();
}
return object_error::arch_not_found;
diff --git a/contrib/llvm/lib/Object/Object.cpp b/contrib/llvm/lib/Object/Object.cpp
index 85f2436..945252b 100644
--- a/contrib/llvm/lib/Object/Object.cpp
+++ b/contrib/llvm/lib/Object/Object.cpp
@@ -173,10 +173,10 @@ void LLVMMoveToNextRelocation(LLVMRelocationIteratorRef SI) {
// SymbolRef accessors
const char *LLVMGetSymbolName(LLVMSymbolIteratorRef SI) {
- StringRef ret;
- if (std::error_code ec = (*unwrap(SI))->getName(ret))
- report_fatal_error(ec.message());
- return ret.data();
+ ErrorOr<StringRef> Ret = (*unwrap(SI))->getName();
+ if (std::error_code EC = Ret.getError())
+ report_fatal_error(EC.message());
+ return Ret->data();
}
uint64_t LLVMGetSymbolAddress(LLVMSymbolIteratorRef SI) {
@@ -187,22 +187,19 @@ uint64_t LLVMGetSymbolAddress(LLVMSymbolIteratorRef SI) {
}
uint64_t LLVMGetSymbolSize(LLVMSymbolIteratorRef SI) {
- return (*unwrap(SI))->getSize();
+ return (*unwrap(SI))->getCommonSize();
}
// RelocationRef accessors
uint64_t LLVMGetRelocationAddress(LLVMRelocationIteratorRef RI) {
- uint64_t ret;
- if (std::error_code ec = (*unwrap(RI))->getAddress(ret))
- report_fatal_error(ec.message());
- return ret;
+ ErrorOr<uint64_t> Ret = (*unwrap(RI))->getAddress();
+ if (std::error_code EC = Ret.getError())
+ report_fatal_error(EC.message());
+ return *Ret;
}
uint64_t LLVMGetRelocationOffset(LLVMRelocationIteratorRef RI) {
- uint64_t ret;
- if (std::error_code ec = (*unwrap(RI))->getOffset(ret))
- report_fatal_error(ec.message());
- return ret;
+ return (*unwrap(RI))->getOffset();
}
LLVMSymbolIteratorRef LLVMGetRelocationSymbol(LLVMRelocationIteratorRef RI) {
@@ -211,18 +208,13 @@ LLVMSymbolIteratorRef LLVMGetRelocationSymbol(LLVMRelocationIteratorRef RI) {
}
uint64_t LLVMGetRelocationType(LLVMRelocationIteratorRef RI) {
- uint64_t ret;
- if (std::error_code ec = (*unwrap(RI))->getType(ret))
- report_fatal_error(ec.message());
- return ret;
+ return (*unwrap(RI))->getType();
}
// NOTE: Caller takes ownership of returned string.
const char *LLVMGetRelocationTypeName(LLVMRelocationIteratorRef RI) {
SmallVector<char, 0> ret;
- if (std::error_code ec = (*unwrap(RI))->getTypeName(ret))
- report_fatal_error(ec.message());
-
+ (*unwrap(RI))->getTypeName(ret);
char *str = static_cast<char*>(malloc(ret.size()));
std::copy(ret.begin(), ret.end(), str);
return str;
diff --git a/contrib/llvm/lib/Object/ObjectFile.cpp b/contrib/llvm/lib/Object/ObjectFile.cpp
index f6667d9..04e4916 100644
--- a/contrib/llvm/lib/Object/ObjectFile.cpp
+++ b/contrib/llvm/lib/Object/ObjectFile.cpp
@@ -28,12 +28,19 @@ void ObjectFile::anchor() { }
ObjectFile::ObjectFile(unsigned int Type, MemoryBufferRef Source)
: SymbolicFile(Type, Source) {}
+bool SectionRef::containsSymbol(SymbolRef S) const {
+ section_iterator SymSec = getObject()->section_end();
+ if (S.getSection(SymSec))
+ return false;
+ return *this == *SymSec;
+}
+
std::error_code ObjectFile::printSymbolName(raw_ostream &OS,
DataRefImpl Symb) const {
- StringRef Name;
- if (std::error_code EC = getSymbolName(Symb, Name))
+ ErrorOr<StringRef> Name = getSymbolName(Symb);
+ if (std::error_code EC = Name.getError())
return EC;
- OS << Name;
+ OS << *Name;
return std::error_code();
}
diff --git a/contrib/llvm/lib/Object/RecordStreamer.h b/contrib/llvm/lib/Object/RecordStreamer.h
index d694a9f..d861061 100644
--- a/contrib/llvm/lib/Object/RecordStreamer.h
+++ b/contrib/llvm/lib/Object/RecordStreamer.h
@@ -38,5 +38,5 @@ public:
void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
unsigned ByteAlignment) override;
};
-} // namespace llvm
+}
#endif
diff --git a/contrib/llvm/lib/Object/SymbolSize.cpp b/contrib/llvm/lib/Object/SymbolSize.cpp
new file mode 100644
index 0000000..1d5cd78
--- /dev/null
+++ b/contrib/llvm/lib/Object/SymbolSize.cpp
@@ -0,0 +1,100 @@
+//===- SymbolSize.cpp -----------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Object/SymbolSize.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/Object/COFF.h"
+#include "llvm/Object/ELFObjectFile.h"
+#include "llvm/Object/MachO.h"
+
+using namespace llvm;
+using namespace object;
+
+namespace {
+struct SymEntry {
+ symbol_iterator I;
+ uint64_t Address;
+ unsigned Number;
+ unsigned SectionID;
+};
+}
+
+static int compareAddress(const SymEntry *A, const SymEntry *B) {
+ if (A->SectionID != B->SectionID)
+ return A->SectionID - B->SectionID;
+ return A->Address - B->Address;
+}
+
+static unsigned getSectionID(const ObjectFile &O, SectionRef Sec) {
+ if (auto *M = dyn_cast<MachOObjectFile>(&O))
+ return M->getSectionID(Sec);
+ return cast<COFFObjectFile>(O).getSectionID(Sec);
+}
+
+static unsigned getSymbolSectionID(const ObjectFile &O, SymbolRef Sym) {
+ if (auto *M = dyn_cast<MachOObjectFile>(&O))
+ return M->getSymbolSectionID(Sym);
+ return cast<COFFObjectFile>(O).getSymbolSectionID(Sym);
+}
+
+std::vector<std::pair<SymbolRef, uint64_t>>
+llvm::object::computeSymbolSizes(const ObjectFile &O) {
+ std::vector<std::pair<SymbolRef, uint64_t>> Ret;
+
+ if (const auto *E = dyn_cast<ELFObjectFileBase>(&O)) {
+ auto Syms = E->symbols();
+ if (Syms.begin() == Syms.end())
+ Syms = E->getDynamicSymbolIterators();
+ for (ELFSymbolRef Sym : Syms)
+ Ret.push_back({Sym, Sym.getSize()});
+ return Ret;
+ }
+
+ // Collect sorted symbol addresses. Include dummy addresses for the end
+ // of each section.
+ std::vector<SymEntry> Addresses;
+ unsigned SymNum = 0;
+ for (symbol_iterator I = O.symbol_begin(), E = O.symbol_end(); I != E; ++I) {
+ SymbolRef Sym = *I;
+ uint64_t Value = Sym.getValue();
+ Addresses.push_back({I, Value, SymNum, getSymbolSectionID(O, Sym)});
+ ++SymNum;
+ }
+ for (SectionRef Sec : O.sections()) {
+ uint64_t Address = Sec.getAddress();
+ uint64_t Size = Sec.getSize();
+ Addresses.push_back(
+ {O.symbol_end(), Address + Size, 0, getSectionID(O, Sec)});
+ }
+ array_pod_sort(Addresses.begin(), Addresses.end(), compareAddress);
+
+ // Compute the size as the gap to the next symbol
+ for (unsigned I = 0, N = Addresses.size() - 1; I < N; ++I) {
+ auto &P = Addresses[I];
+ if (P.I == O.symbol_end())
+ continue;
+
+ // If multiple symbol have the same address, give both the same size.
+ unsigned NextI = I + 1;
+ while (NextI < N && Addresses[NextI].Address == P.Address)
+ ++NextI;
+
+ uint64_t Size = Addresses[NextI].Address - P.Address;
+ P.Address = Size;
+ }
+
+ // Assign the sorted symbols in the original order.
+ Ret.resize(SymNum);
+ for (SymEntry &P : Addresses) {
+ if (P.I == O.symbol_end())
+ continue;
+ Ret[P.Number] = {*P.I, P.Address};
+ }
+ return Ret;
+}
OpenPOWER on IntegriCloud