summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-objdump
diff options
context:
space:
mode:
authorGeorge Rimar <grimar@accesssoftek.com>2019-08-14 08:56:55 +0000
committerGeorge Rimar <grimar@accesssoftek.com>2019-08-14 08:56:55 +0000
commit468919e18231d0c30b5c0f84a87145db06e3554b (patch)
treee1dbabaed556c88253db5a4bc75935b923ecf595 /llvm/tools/llvm-objdump
parenta0c6a3571422826e856002714d9bb008584fe8b3 (diff)
downloadbcm5719-llvm-468919e18231d0c30b5c0f84a87145db06e3554b.tar.gz
bcm5719-llvm-468919e18231d0c30b5c0f84a87145db06e3554b.zip
Revert r368812 "[llvm/Object] - Convert SectionRef::getName() to return Expected<>"
It broke clang BB: http://lab.llvm.org:8011/builders/clang-x86_64-debian-fast/builds/16455 llvm-svn: 368813
Diffstat (limited to 'llvm/tools/llvm-objdump')
-rw-r--r--llvm/tools/llvm-objdump/COFFDump.cpp3
-rw-r--r--llvm/tools/llvm-objdump/MachODump.cpp156
-rw-r--r--llvm/tools/llvm-objdump/llvm-objdump.cpp57
3 files changed, 70 insertions, 146 deletions
diff --git a/llvm/tools/llvm-objdump/COFFDump.cpp b/llvm/tools/llvm-objdump/COFFDump.cpp
index 3fb9285bf27..1ba0a68902c 100644
--- a/llvm/tools/llvm-objdump/COFFDump.cpp
+++ b/llvm/tools/llvm-objdump/COFFDump.cpp
@@ -442,7 +442,8 @@ static bool getPDataSection(const COFFObjectFile *Obj,
std::vector<RelocationRef> &Rels,
const RuntimeFunction *&RFStart, int &NumRFs) {
for (const SectionRef &Section : Obj->sections()) {
- StringRef Name = unwrapOrError(Section.getName(), Obj->getFileName());
+ StringRef Name;
+ error(Section.getName(Name));
if (Name != ".pdata")
continue;
diff --git a/llvm/tools/llvm-objdump/MachODump.cpp b/llvm/tools/llvm-objdump/MachODump.cpp
index c4fa6b5c2a2..a3f3a9df4c1 100644
--- a/llvm/tools/llvm-objdump/MachODump.cpp
+++ b/llvm/tools/llvm-objdump/MachODump.cpp
@@ -371,8 +371,11 @@ static void getSectionsAndSymbols(MachOObjectFile *MachOObj,
Symbols.push_back(Symbol);
}
- for (const SectionRef &Section : MachOObj->sections())
+ for (const SectionRef &Section : MachOObj->sections()) {
+ StringRef SectName;
+ Section.getName(SectName);
Sections.push_back(Section);
+ }
bool BaseSegmentAddressSet = false;
for (const auto &Command : MachOObj->load_commands()) {
@@ -446,11 +449,13 @@ static void printRelocationTargetName(const MachOObjectFile *O,
// If we couldn't find a symbol that this relocation refers to, try
// to find a section beginning instead.
for (const SectionRef &Section : ToolSectionFilter(*O)) {
+ StringRef Name;
uint64_t Addr = Section.getAddress();
if (Addr != Val)
continue;
- StringRef NameOrErr = unwrapOrError(Section.getName(), O->getFileName());
- Fmt << NameOrErr;
+ if (std::error_code EC = Section.getName(Name))
+ report_error(errorCodeToError(EC), O->getFileName());
+ Fmt << Name;
return;
}
@@ -483,14 +488,10 @@ static void printRelocationTargetName(const MachOObjectFile *O,
--I;
advance(SI, 1);
}
- if (SI == O->section_end()) {
+ if (SI == O->section_end())
Fmt << Val << " (?,?)";
- } else {
- if (Expected<StringRef> NameOrErr = SI->getName())
- S = *NameOrErr;
- else
- consumeError(NameOrErr.takeError());
- }
+ else
+ SI->getName(S);
}
Fmt << S;
@@ -1530,12 +1531,7 @@ static void DumpLiteralPointerSection(MachOObjectFile *O,
uint64_t SectSize = Sect->getSize();
StringRef SectName;
- Expected<StringRef> SectNameOrErr = Sect->getName();
- if (SectNameOrErr)
- SectName = *SectNameOrErr;
- else
- consumeError(SectNameOrErr.takeError());
-
+ Sect->getName(SectName);
DataRefImpl Ref = Sect->getRawDataRefImpl();
StringRef SegmentName = O->getSectionFinalSegmentName(Ref);
outs() << SegmentName << ":" << SectName << ":";
@@ -1747,12 +1743,7 @@ static void DumpSectionContents(StringRef Filename, MachOObjectFile *O,
}
for (const SectionRef &Section : O->sections()) {
StringRef SectName;
- Expected<StringRef> SecNameOrErr = Section.getName();
- if (SecNameOrErr)
- SectName = *SecNameOrErr;
- else
- consumeError(SecNameOrErr.takeError());
-
+ Section.getName(SectName);
DataRefImpl Ref = Section.getRawDataRefImpl();
StringRef SegName = O->getSectionFinalSegmentName(Ref);
if ((DumpSegName.empty() || SegName == DumpSegName) &&
@@ -1848,12 +1839,7 @@ static void DumpInfoPlistSectionContents(StringRef Filename,
MachOObjectFile *O) {
for (const SectionRef &Section : O->sections()) {
StringRef SectName;
- Expected<StringRef> SecNameOrErr = Section.getName();
- if (SecNameOrErr)
- SectName = *SecNameOrErr;
- else
- consumeError(SecNameOrErr.takeError());
-
+ Section.getName(SectName);
DataRefImpl Ref = Section.getRawDataRefImpl();
StringRef SegName = O->getSectionFinalSegmentName(Ref);
if (SegName == "__TEXT" && SectName == "__info_plist") {
@@ -1950,11 +1936,7 @@ static void ProcessMachO(StringRef Name, MachOObjectFile *MachOOF,
if (DisassembleAll) {
for (const SectionRef &Section : MachOOF->sections()) {
StringRef SectName;
- if (Expected<StringRef> NameOrErr = Section.getName())
- SectName = *NameOrErr;
- else
- consumeError(NameOrErr.takeError());
-
+ Section.getName(SectName);
if (SectName.equals("__text")) {
DataRefImpl Ref = Section.getRawDataRefImpl();
StringRef SegName = MachOOF->getSectionFinalSegmentName(Ref);
@@ -3265,13 +3247,7 @@ static const char *get_pointer_64(uint64_t Address, uint32_t &offset,
continue;
if (objc_only) {
StringRef SectName;
- Expected<StringRef> SecNameOrErr =
- ((*(info->Sections))[SectIdx]).getName();
- if (SecNameOrErr)
- SectName = *SecNameOrErr;
- else
- consumeError(SecNameOrErr.takeError());
-
+ ((*(info->Sections))[SectIdx]).getName(SectName);
DataRefImpl Ref = ((*(info->Sections))[SectIdx]).getRawDataRefImpl();
StringRef SegName = info->O->getSectionFinalSegmentName(Ref);
if (SegName != "__OBJC" && SectName != "__cstring")
@@ -4063,12 +4039,7 @@ static const SectionRef get_section(MachOObjectFile *O, const char *segname,
const char *sectname) {
for (const SectionRef &Section : O->sections()) {
StringRef SectName;
- Expected<StringRef> SecNameOrErr = Section.getName();
- if (SecNameOrErr)
- SectName = *SecNameOrErr;
- else
- consumeError(SecNameOrErr.takeError());
-
+ Section.getName(SectName);
DataRefImpl Ref = Section.getRawDataRefImpl();
StringRef SegName = O->getSectionFinalSegmentName(Ref);
if (SegName == segname && SectName == sectname)
@@ -4085,12 +4056,7 @@ walk_pointer_list_64(const char *listname, const SectionRef S,
return;
StringRef SectName;
- Expected<StringRef> SecNameOrErr = S.getName();
- if (SecNameOrErr)
- SectName = *SecNameOrErr;
- else
- consumeError(SecNameOrErr.takeError());
-
+ S.getName(SectName);
DataRefImpl Ref = S.getRawDataRefImpl();
StringRef SegName = O->getSectionFinalSegmentName(Ref);
outs() << "Contents of (" << SegName << "," << SectName << ") section\n";
@@ -4139,7 +4105,8 @@ walk_pointer_list_32(const char *listname, const SectionRef S,
if (S == SectionRef())
return;
- StringRef SectName = unwrapOrError(S.getName(), O->getFileName());
+ StringRef SectName;
+ S.getName(SectName);
DataRefImpl Ref = S.getRawDataRefImpl();
StringRef SegName = O->getSectionFinalSegmentName(Ref);
outs() << "Contents of (" << SegName << "," << SectName << ") section\n";
@@ -5813,12 +5780,7 @@ static void print_message_refs64(SectionRef S, struct DisassembleInfo *info) {
return;
StringRef SectName;
- Expected<StringRef> SecNameOrErr = S.getName();
- if (SecNameOrErr)
- SectName = *SecNameOrErr;
- else
- consumeError(SecNameOrErr.takeError());
-
+ S.getName(SectName);
DataRefImpl Ref = S.getRawDataRefImpl();
StringRef SegName = info->O->getSectionFinalSegmentName(Ref);
outs() << "Contents of (" << SegName << "," << SectName << ") section\n";
@@ -5881,12 +5843,7 @@ static void print_message_refs32(SectionRef S, struct DisassembleInfo *info) {
return;
StringRef SectName;
- Expected<StringRef> SecNameOrErr = S.getName();
- if (SecNameOrErr)
- SectName = *SecNameOrErr;
- else
- consumeError(SecNameOrErr.takeError());
-
+ S.getName(SectName);
DataRefImpl Ref = S.getRawDataRefImpl();
StringRef SegName = info->O->getSectionFinalSegmentName(Ref);
outs() << "Contents of (" << SegName << "," << SectName << ") section\n";
@@ -5932,12 +5889,7 @@ static void print_image_info64(SectionRef S, struct DisassembleInfo *info) {
return;
StringRef SectName;
- Expected<StringRef> SecNameOrErr = S.getName();
- if (SecNameOrErr)
- SectName = *SecNameOrErr;
- else
- consumeError(SecNameOrErr.takeError());
-
+ S.getName(SectName);
DataRefImpl Ref = S.getRawDataRefImpl();
StringRef SegName = info->O->getSectionFinalSegmentName(Ref);
outs() << "Contents of (" << SegName << "," << SectName << ") section\n";
@@ -5994,12 +5946,7 @@ static void print_image_info32(SectionRef S, struct DisassembleInfo *info) {
return;
StringRef SectName;
- Expected<StringRef> SecNameOrErr = S.getName();
- if (SecNameOrErr)
- SectName = *SecNameOrErr;
- else
- consumeError(SecNameOrErr.takeError());
-
+ S.getName(SectName);
DataRefImpl Ref = S.getRawDataRefImpl();
StringRef SegName = info->O->getSectionFinalSegmentName(Ref);
outs() << "Contents of (" << SegName << "," << SectName << ") section\n";
@@ -6049,12 +5996,7 @@ static void print_image_info(SectionRef S, struct DisassembleInfo *info) {
const char *r;
StringRef SectName;
- Expected<StringRef> SecNameOrErr = S.getName();
- if (SecNameOrErr)
- SectName = *SecNameOrErr;
- else
- consumeError(SecNameOrErr.takeError());
-
+ S.getName(SectName);
DataRefImpl Ref = S.getRawDataRefImpl();
StringRef SegName = info->O->getSectionFinalSegmentName(Ref);
outs() << "Contents of (" << SegName << "," << SectName << ") section\n";
@@ -6089,8 +6031,11 @@ static void printObjc2_64bit_MetaData(MachOObjectFile *O, bool verbose) {
CreateSymbolAddressMap(O, &AddrMap);
std::vector<SectionRef> Sections;
- for (const SectionRef &Section : O->sections())
+ for (const SectionRef &Section : O->sections()) {
+ StringRef SectName;
+ Section.getName(SectName);
Sections.push_back(Section);
+ }
struct DisassembleInfo info(O, &AddrMap, &Sections, verbose);
@@ -6171,8 +6116,11 @@ static void printObjc2_32bit_MetaData(MachOObjectFile *O, bool verbose) {
CreateSymbolAddressMap(O, &AddrMap);
std::vector<SectionRef> Sections;
- for (const SectionRef &Section : O->sections())
+ for (const SectionRef &Section : O->sections()) {
+ StringRef SectName;
+ Section.getName(SectName);
Sections.push_back(Section);
+ }
struct DisassembleInfo info(O, &AddrMap, &Sections, verbose);
@@ -6266,8 +6214,11 @@ static bool printObjc1_32bit_MetaData(MachOObjectFile *O, bool verbose) {
CreateSymbolAddressMap(O, &AddrMap);
std::vector<SectionRef> Sections;
- for (const SectionRef &Section : O->sections())
+ for (const SectionRef &Section : O->sections()) {
+ StringRef SectName;
+ Section.getName(SectName);
Sections.push_back(Section);
+ }
struct DisassembleInfo info(O, &AddrMap, &Sections, verbose);
@@ -6424,8 +6375,11 @@ static void DumpProtocolSection(MachOObjectFile *O, const char *sect,
CreateSymbolAddressMap(O, &AddrMap);
std::vector<SectionRef> Sections;
- for (const SectionRef &Section : O->sections())
+ for (const SectionRef &Section : O->sections()) {
+ StringRef SectName;
+ Section.getName(SectName);
Sections.push_back(Section);
+ }
struct DisassembleInfo info(O, &AddrMap, &Sections, true);
@@ -7390,12 +7344,8 @@ static void DisassembleMachO(StringRef Filename, MachOObjectFile *MachOOF,
outs() << "(" << DisSegName << "," << DisSectName << ") section\n";
for (unsigned SectIdx = 0; SectIdx != Sections.size(); SectIdx++) {
- Expected<StringRef> SecNameOrErr = Sections[SectIdx].getName();
- if (!SecNameOrErr) {
- consumeError(SecNameOrErr.takeError());
- continue;
- }
- if (*SecNameOrErr != DisSectName)
+ StringRef SectName;
+ if (Sections[SectIdx].getName(SectName) || SectName != DisSectName)
continue;
DataRefImpl DR = Sections[SectIdx].getRawDataRefImpl();
@@ -7792,12 +7742,8 @@ static void findUnwindRelocNameAddend(const MachOObjectFile *Obj,
auto Sym = Symbols.upper_bound(Addr);
if (Sym == Symbols.begin()) {
// The first symbol in the object is after this reference, the best we can
- // do is section-relative notation.
- if (Expected<StringRef> NameOrErr = RelocSection.getName())
- Name = *NameOrErr;
- else
- consumeError(NameOrErr.takeError());
-
+ // do is section-relative notation.
+ RelocSection.getName(Name);
Addend = Addr - SectionAddr;
return;
}
@@ -7816,11 +7762,7 @@ static void findUnwindRelocNameAddend(const MachOObjectFile *Obj,
// There is a symbol before this reference, but it's in a different
// section. Probably not helpful to mention it, so use the section name.
- if (Expected<StringRef> NameOrErr = RelocSection.getName())
- Name = *NameOrErr;
- else
- consumeError(NameOrErr.takeError());
-
+ RelocSection.getName(Name);
Addend = Addr - SectionAddr;
}
@@ -8185,11 +8127,7 @@ void printMachOUnwindInfo(const MachOObjectFile *Obj) {
for (const SectionRef &Section : Obj->sections()) {
StringRef SectName;
- if (Expected<StringRef> NameOrErr = Section.getName())
- SectName = *NameOrErr;
- else
- consumeError(NameOrErr.takeError());
-
+ Section.getName(SectName);
if (SectName == "__compact_unwind")
printMachOCompactUnwindSection(Obj, Symbols, Section);
else if (SectName == "__unwind_info")
diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp
index 7a04e1195ed..93833858282 100644
--- a/llvm/tools/llvm-objdump/llvm-objdump.cpp
+++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp
@@ -344,14 +344,10 @@ typedef std::vector<std::tuple<uint64_t, StringRef, uint8_t>> SectionSymbolsTy;
static bool shouldKeep(object::SectionRef S) {
if (FilterSections.empty())
return true;
-
- Expected<StringRef> SecNameOrErr = S.getName();
- if (!SecNameOrErr) {
- consumeError(SecNameOrErr.takeError());
+ StringRef SecName;
+ std::error_code error = S.getName(SecName);
+ if (error)
return false;
- }
- StringRef SecName = *SecNameOrErr;
-
// StringSet does not allow empty key so avoid adding sections with
// no name (such as the section with index 0) here.
if (!SecName.empty())
@@ -924,12 +920,10 @@ static void addPltEntries(const ObjectFile *Obj,
StringSaver &Saver) {
Optional<SectionRef> Plt = None;
for (const SectionRef &Section : Obj->sections()) {
- Expected<StringRef> SecNameOrErr = Section.getName();
- if (!SecNameOrErr) {
- consumeError(SecNameOrErr.takeError());
+ StringRef Name;
+ if (Section.getName(Name))
continue;
- }
- if (*SecNameOrErr == ".plt")
+ if (Name == ".plt")
Plt = Section;
}
if (!Plt)
@@ -1212,8 +1206,9 @@ static void disassembleObject(const Target *TheTarget, const ObjectFile *Obj,
DataRefImpl DR = Section.getRawDataRefImpl();
SegmentName = MachO->getSectionFinalSegmentName(DR);
}
+ StringRef SectionName;
+ error(Section.getName(SectionName));
- StringRef SectionName = unwrapOrError(Section.getName(), Obj->getFileName());
// If the section has no symbol at the start, just insert a dummy one.
if (Symbols.empty() || std::get<0>(Symbols[0]) != 0) {
Symbols.insert(
@@ -1586,7 +1581,8 @@ void printRelocations(const ObjectFile *Obj) {
}
for (std::pair<SectionRef, std::vector<SectionRef>> &P : SecToRelSec) {
- StringRef SecName = unwrapOrError(P.first.getName(), Obj->getFileName());
+ StringRef SecName;
+ error(P.first.getName(SecName));
outs() << "RELOCATION RECORDS FOR [" << SecName << "]:\n";
for (SectionRef Section : P.second) {
@@ -1658,7 +1654,8 @@ void printSectionHeaders(const ObjectFile *Obj) {
"Idx Name Size VMA Type\n";
for (const SectionRef &Section : ToolSectionFilter(*Obj)) {
- StringRef Name = unwrapOrError(Section.getName(), Obj->getFileName());
+ StringRef Name;
+ error(Section.getName(Name));
uint64_t VMA = Section.getAddress();
if (shouldAdjustVA(Section))
VMA += AdjustVMA;
@@ -1685,7 +1682,8 @@ void printSectionHeaders(const ObjectFile *Obj) {
void printSectionContents(const ObjectFile *Obj) {
for (const SectionRef &Section : ToolSectionFilter(*Obj)) {
- StringRef Name = unwrapOrError(Section.getName(), Obj->getFileName());
+ StringRef Name;
+ error(Section.getName(Name));
uint64_t BaseAddr = Section.getAddress();
uint64_t Size = Section.getSize();
if (!Size)
@@ -1749,16 +1747,11 @@ void printSymbolTable(const ObjectFile *O, StringRef ArchiveName,
section_iterator Section = unwrapOrError(Symbol.getSection(), ArchiveName,
FileName, ArchitectureName);
StringRef Name;
- if (Type == SymbolRef::ST_Debug && Section != O->section_end()) {
- if (Expected<StringRef> NameOrErr = Section->getName())
- Name = *NameOrErr;
- else
- consumeError(NameOrErr.takeError());
-
- } else {
+ if (Type == SymbolRef::ST_Debug && Section != O->section_end())
+ Section->getName(Name);
+ else
Name = unwrapOrError(Symbol.getName(), ArchiveName, FileName,
ArchitectureName);
- }
bool Global = Flags & SymbolRef::SF_Global;
bool Weak = Flags & SymbolRef::SF_Weak;
@@ -1804,8 +1797,8 @@ void printSymbolTable(const ObjectFile *O, StringRef ArchiveName,
StringRef SegmentName = MachO->getSectionFinalSegmentName(DR);
outs() << SegmentName << ",";
}
- StringRef SectionName =
- unwrapOrError(Section->getName(), O->getFileName());
+ StringRef SectionName;
+ error(Section->getName(SectionName));
outs() << SectionName;
}
@@ -1878,11 +1871,7 @@ void printRawClangAST(const ObjectFile *Obj) {
Optional<object::SectionRef> ClangASTSection;
for (auto Sec : ToolSectionFilter(*Obj)) {
StringRef Name;
- if (Expected<StringRef> NameOrErr = Sec.getName())
- Name = *NameOrErr;
- else
- consumeError(NameOrErr.takeError());
-
+ Sec.getName(Name);
if (Name == ClangASTSectionName) {
ClangASTSection = Sec;
break;
@@ -1914,11 +1903,7 @@ static void printFaultMaps(const ObjectFile *Obj) {
for (auto Sec : ToolSectionFilter(*Obj)) {
StringRef Name;
- if (Expected<StringRef> NameOrErr = Sec.getName())
- Name = *NameOrErr;
- else
- consumeError(NameOrErr.takeError());
-
+ Sec.getName(Name);
if (Name == FaultMapSectionName) {
FaultMapSection = Sec;
break;
OpenPOWER on IntegriCloud