summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-objdump
diff options
context:
space:
mode:
authorGeorge Rimar <grimar@accesssoftek.com>2019-08-14 11:10:11 +0000
committerGeorge Rimar <grimar@accesssoftek.com>2019-08-14 11:10:11 +0000
commitbcc00e1afbdc107e05b2977fde26053a52295dd1 (patch)
tree0ad3e328d73375164f99adb046a919273a128c1c /llvm/tools/llvm-objdump
parenta11d302fa00ba423b09c94491bc868cb991ff379 (diff)
downloadbcm5719-llvm-bcc00e1afbdc107e05b2977fde26053a52295dd1.tar.gz
bcm5719-llvm-bcc00e1afbdc107e05b2977fde26053a52295dd1.zip
Recommit r368812 "[llvm/Object] - Convert SectionRef::getName() to return Expected<>"
Changes: no changes. A fix for the clang code will be landed right on top. Original commit message: SectionRef::getName() returns std::error_code now. Returning Expected<> instead has multiple benefits. For example, it forces user to check the error returned. Also Expected<> may keep a valuable string error message, what is more useful than having a error code. (Object\invalid.test was updated to show the new messages printed.) This patch makes a change for all users to switch to Expected<> version. Note: in a few places the error returned was ignored before my changes. In such places I left them ignored. My intention was to convert the interface used, and not to improve and/or the existent users in this patch. (Though I think this is good idea for a follow-ups to revisit such places and either remove consumeError calls or comment each of them to clarify why it is OK to have them). Differential revision: https://reviews.llvm.org/D66089 llvm-svn: 368826
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, 146 insertions, 70 deletions
diff --git a/llvm/tools/llvm-objdump/COFFDump.cpp b/llvm/tools/llvm-objdump/COFFDump.cpp
index 1ba0a68902c..3fb9285bf27 100644
--- a/llvm/tools/llvm-objdump/COFFDump.cpp
+++ b/llvm/tools/llvm-objdump/COFFDump.cpp
@@ -442,8 +442,7 @@ static bool getPDataSection(const COFFObjectFile *Obj,
std::vector<RelocationRef> &Rels,
const RuntimeFunction *&RFStart, int &NumRFs) {
for (const SectionRef &Section : Obj->sections()) {
- StringRef Name;
- error(Section.getName(Name));
+ StringRef Name = unwrapOrError(Section.getName(), Obj->getFileName());
if (Name != ".pdata")
continue;
diff --git a/llvm/tools/llvm-objdump/MachODump.cpp b/llvm/tools/llvm-objdump/MachODump.cpp
index a3f3a9df4c1..c4fa6b5c2a2 100644
--- a/llvm/tools/llvm-objdump/MachODump.cpp
+++ b/llvm/tools/llvm-objdump/MachODump.cpp
@@ -371,11 +371,8 @@ static void getSectionsAndSymbols(MachOObjectFile *MachOObj,
Symbols.push_back(Symbol);
}
- for (const SectionRef &Section : MachOObj->sections()) {
- StringRef SectName;
- Section.getName(SectName);
+ for (const SectionRef &Section : MachOObj->sections())
Sections.push_back(Section);
- }
bool BaseSegmentAddressSet = false;
for (const auto &Command : MachOObj->load_commands()) {
@@ -449,13 +446,11 @@ 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;
- if (std::error_code EC = Section.getName(Name))
- report_error(errorCodeToError(EC), O->getFileName());
- Fmt << Name;
+ StringRef NameOrErr = unwrapOrError(Section.getName(), O->getFileName());
+ Fmt << NameOrErr;
return;
}
@@ -488,10 +483,14 @@ static void printRelocationTargetName(const MachOObjectFile *O,
--I;
advance(SI, 1);
}
- if (SI == O->section_end())
+ if (SI == O->section_end()) {
Fmt << Val << " (?,?)";
- else
- SI->getName(S);
+ } else {
+ if (Expected<StringRef> NameOrErr = SI->getName())
+ S = *NameOrErr;
+ else
+ consumeError(NameOrErr.takeError());
+ }
}
Fmt << S;
@@ -1531,7 +1530,12 @@ static void DumpLiteralPointerSection(MachOObjectFile *O,
uint64_t SectSize = Sect->getSize();
StringRef SectName;
- Sect->getName(SectName);
+ Expected<StringRef> SectNameOrErr = Sect->getName();
+ if (SectNameOrErr)
+ SectName = *SectNameOrErr;
+ else
+ consumeError(SectNameOrErr.takeError());
+
DataRefImpl Ref = Sect->getRawDataRefImpl();
StringRef SegmentName = O->getSectionFinalSegmentName(Ref);
outs() << SegmentName << ":" << SectName << ":";
@@ -1743,7 +1747,12 @@ static void DumpSectionContents(StringRef Filename, MachOObjectFile *O,
}
for (const SectionRef &Section : O->sections()) {
StringRef SectName;
- Section.getName(SectName);
+ Expected<StringRef> SecNameOrErr = Section.getName();
+ if (SecNameOrErr)
+ SectName = *SecNameOrErr;
+ else
+ consumeError(SecNameOrErr.takeError());
+
DataRefImpl Ref = Section.getRawDataRefImpl();
StringRef SegName = O->getSectionFinalSegmentName(Ref);
if ((DumpSegName.empty() || SegName == DumpSegName) &&
@@ -1839,7 +1848,12 @@ static void DumpInfoPlistSectionContents(StringRef Filename,
MachOObjectFile *O) {
for (const SectionRef &Section : O->sections()) {
StringRef SectName;
- Section.getName(SectName);
+ Expected<StringRef> SecNameOrErr = Section.getName();
+ if (SecNameOrErr)
+ SectName = *SecNameOrErr;
+ else
+ consumeError(SecNameOrErr.takeError());
+
DataRefImpl Ref = Section.getRawDataRefImpl();
StringRef SegName = O->getSectionFinalSegmentName(Ref);
if (SegName == "__TEXT" && SectName == "__info_plist") {
@@ -1936,7 +1950,11 @@ static void ProcessMachO(StringRef Name, MachOObjectFile *MachOOF,
if (DisassembleAll) {
for (const SectionRef &Section : MachOOF->sections()) {
StringRef SectName;
- Section.getName(SectName);
+ if (Expected<StringRef> NameOrErr = Section.getName())
+ SectName = *NameOrErr;
+ else
+ consumeError(NameOrErr.takeError());
+
if (SectName.equals("__text")) {
DataRefImpl Ref = Section.getRawDataRefImpl();
StringRef SegName = MachOOF->getSectionFinalSegmentName(Ref);
@@ -3247,7 +3265,13 @@ static const char *get_pointer_64(uint64_t Address, uint32_t &offset,
continue;
if (objc_only) {
StringRef SectName;
- ((*(info->Sections))[SectIdx]).getName(SectName);
+ Expected<StringRef> SecNameOrErr =
+ ((*(info->Sections))[SectIdx]).getName();
+ if (SecNameOrErr)
+ SectName = *SecNameOrErr;
+ else
+ consumeError(SecNameOrErr.takeError());
+
DataRefImpl Ref = ((*(info->Sections))[SectIdx]).getRawDataRefImpl();
StringRef SegName = info->O->getSectionFinalSegmentName(Ref);
if (SegName != "__OBJC" && SectName != "__cstring")
@@ -4039,7 +4063,12 @@ static const SectionRef get_section(MachOObjectFile *O, const char *segname,
const char *sectname) {
for (const SectionRef &Section : O->sections()) {
StringRef SectName;
- Section.getName(SectName);
+ Expected<StringRef> SecNameOrErr = Section.getName();
+ if (SecNameOrErr)
+ SectName = *SecNameOrErr;
+ else
+ consumeError(SecNameOrErr.takeError());
+
DataRefImpl Ref = Section.getRawDataRefImpl();
StringRef SegName = O->getSectionFinalSegmentName(Ref);
if (SegName == segname && SectName == sectname)
@@ -4056,7 +4085,12 @@ walk_pointer_list_64(const char *listname, const SectionRef S,
return;
StringRef SectName;
- S.getName(SectName);
+ Expected<StringRef> SecNameOrErr = S.getName();
+ if (SecNameOrErr)
+ SectName = *SecNameOrErr;
+ else
+ consumeError(SecNameOrErr.takeError());
+
DataRefImpl Ref = S.getRawDataRefImpl();
StringRef SegName = O->getSectionFinalSegmentName(Ref);
outs() << "Contents of (" << SegName << "," << SectName << ") section\n";
@@ -4105,8 +4139,7 @@ walk_pointer_list_32(const char *listname, const SectionRef S,
if (S == SectionRef())
return;
- StringRef SectName;
- S.getName(SectName);
+ StringRef SectName = unwrapOrError(S.getName(), O->getFileName());
DataRefImpl Ref = S.getRawDataRefImpl();
StringRef SegName = O->getSectionFinalSegmentName(Ref);
outs() << "Contents of (" << SegName << "," << SectName << ") section\n";
@@ -5780,7 +5813,12 @@ static void print_message_refs64(SectionRef S, struct DisassembleInfo *info) {
return;
StringRef SectName;
- S.getName(SectName);
+ Expected<StringRef> SecNameOrErr = S.getName();
+ if (SecNameOrErr)
+ SectName = *SecNameOrErr;
+ else
+ consumeError(SecNameOrErr.takeError());
+
DataRefImpl Ref = S.getRawDataRefImpl();
StringRef SegName = info->O->getSectionFinalSegmentName(Ref);
outs() << "Contents of (" << SegName << "," << SectName << ") section\n";
@@ -5843,7 +5881,12 @@ static void print_message_refs32(SectionRef S, struct DisassembleInfo *info) {
return;
StringRef SectName;
- S.getName(SectName);
+ Expected<StringRef> SecNameOrErr = S.getName();
+ if (SecNameOrErr)
+ SectName = *SecNameOrErr;
+ else
+ consumeError(SecNameOrErr.takeError());
+
DataRefImpl Ref = S.getRawDataRefImpl();
StringRef SegName = info->O->getSectionFinalSegmentName(Ref);
outs() << "Contents of (" << SegName << "," << SectName << ") section\n";
@@ -5889,7 +5932,12 @@ static void print_image_info64(SectionRef S, struct DisassembleInfo *info) {
return;
StringRef SectName;
- S.getName(SectName);
+ Expected<StringRef> SecNameOrErr = S.getName();
+ if (SecNameOrErr)
+ SectName = *SecNameOrErr;
+ else
+ consumeError(SecNameOrErr.takeError());
+
DataRefImpl Ref = S.getRawDataRefImpl();
StringRef SegName = info->O->getSectionFinalSegmentName(Ref);
outs() << "Contents of (" << SegName << "," << SectName << ") section\n";
@@ -5946,7 +5994,12 @@ static void print_image_info32(SectionRef S, struct DisassembleInfo *info) {
return;
StringRef SectName;
- S.getName(SectName);
+ Expected<StringRef> SecNameOrErr = S.getName();
+ if (SecNameOrErr)
+ SectName = *SecNameOrErr;
+ else
+ consumeError(SecNameOrErr.takeError());
+
DataRefImpl Ref = S.getRawDataRefImpl();
StringRef SegName = info->O->getSectionFinalSegmentName(Ref);
outs() << "Contents of (" << SegName << "," << SectName << ") section\n";
@@ -5996,7 +6049,12 @@ static void print_image_info(SectionRef S, struct DisassembleInfo *info) {
const char *r;
StringRef SectName;
- S.getName(SectName);
+ Expected<StringRef> SecNameOrErr = S.getName();
+ if (SecNameOrErr)
+ SectName = *SecNameOrErr;
+ else
+ consumeError(SecNameOrErr.takeError());
+
DataRefImpl Ref = S.getRawDataRefImpl();
StringRef SegName = info->O->getSectionFinalSegmentName(Ref);
outs() << "Contents of (" << SegName << "," << SectName << ") section\n";
@@ -6031,11 +6089,8 @@ static void printObjc2_64bit_MetaData(MachOObjectFile *O, bool verbose) {
CreateSymbolAddressMap(O, &AddrMap);
std::vector<SectionRef> Sections;
- for (const SectionRef &Section : O->sections()) {
- StringRef SectName;
- Section.getName(SectName);
+ for (const SectionRef &Section : O->sections())
Sections.push_back(Section);
- }
struct DisassembleInfo info(O, &AddrMap, &Sections, verbose);
@@ -6116,11 +6171,8 @@ static void printObjc2_32bit_MetaData(MachOObjectFile *O, bool verbose) {
CreateSymbolAddressMap(O, &AddrMap);
std::vector<SectionRef> Sections;
- for (const SectionRef &Section : O->sections()) {
- StringRef SectName;
- Section.getName(SectName);
+ for (const SectionRef &Section : O->sections())
Sections.push_back(Section);
- }
struct DisassembleInfo info(O, &AddrMap, &Sections, verbose);
@@ -6214,11 +6266,8 @@ static bool printObjc1_32bit_MetaData(MachOObjectFile *O, bool verbose) {
CreateSymbolAddressMap(O, &AddrMap);
std::vector<SectionRef> Sections;
- for (const SectionRef &Section : O->sections()) {
- StringRef SectName;
- Section.getName(SectName);
+ for (const SectionRef &Section : O->sections())
Sections.push_back(Section);
- }
struct DisassembleInfo info(O, &AddrMap, &Sections, verbose);
@@ -6375,11 +6424,8 @@ static void DumpProtocolSection(MachOObjectFile *O, const char *sect,
CreateSymbolAddressMap(O, &AddrMap);
std::vector<SectionRef> Sections;
- for (const SectionRef &Section : O->sections()) {
- StringRef SectName;
- Section.getName(SectName);
+ for (const SectionRef &Section : O->sections())
Sections.push_back(Section);
- }
struct DisassembleInfo info(O, &AddrMap, &Sections, true);
@@ -7344,8 +7390,12 @@ static void DisassembleMachO(StringRef Filename, MachOObjectFile *MachOOF,
outs() << "(" << DisSegName << "," << DisSectName << ") section\n";
for (unsigned SectIdx = 0; SectIdx != Sections.size(); SectIdx++) {
- StringRef SectName;
- if (Sections[SectIdx].getName(SectName) || SectName != DisSectName)
+ Expected<StringRef> SecNameOrErr = Sections[SectIdx].getName();
+ if (!SecNameOrErr) {
+ consumeError(SecNameOrErr.takeError());
+ continue;
+ }
+ if (*SecNameOrErr != DisSectName)
continue;
DataRefImpl DR = Sections[SectIdx].getRawDataRefImpl();
@@ -7742,8 +7792,12 @@ 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.
- RelocSection.getName(Name);
+ // do is section-relative notation.
+ if (Expected<StringRef> NameOrErr = RelocSection.getName())
+ Name = *NameOrErr;
+ else
+ consumeError(NameOrErr.takeError());
+
Addend = Addr - SectionAddr;
return;
}
@@ -7762,7 +7816,11 @@ 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.
- RelocSection.getName(Name);
+ if (Expected<StringRef> NameOrErr = RelocSection.getName())
+ Name = *NameOrErr;
+ else
+ consumeError(NameOrErr.takeError());
+
Addend = Addr - SectionAddr;
}
@@ -8127,7 +8185,11 @@ void printMachOUnwindInfo(const MachOObjectFile *Obj) {
for (const SectionRef &Section : Obj->sections()) {
StringRef SectName;
- Section.getName(SectName);
+ if (Expected<StringRef> NameOrErr = Section.getName())
+ SectName = *NameOrErr;
+ else
+ consumeError(NameOrErr.takeError());
+
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 93833858282..7a04e1195ed 100644
--- a/llvm/tools/llvm-objdump/llvm-objdump.cpp
+++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp
@@ -344,10 +344,14 @@ typedef std::vector<std::tuple<uint64_t, StringRef, uint8_t>> SectionSymbolsTy;
static bool shouldKeep(object::SectionRef S) {
if (FilterSections.empty())
return true;
- StringRef SecName;
- std::error_code error = S.getName(SecName);
- if (error)
+
+ Expected<StringRef> SecNameOrErr = S.getName();
+ if (!SecNameOrErr) {
+ consumeError(SecNameOrErr.takeError());
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())
@@ -920,10 +924,12 @@ static void addPltEntries(const ObjectFile *Obj,
StringSaver &Saver) {
Optional<SectionRef> Plt = None;
for (const SectionRef &Section : Obj->sections()) {
- StringRef Name;
- if (Section.getName(Name))
+ Expected<StringRef> SecNameOrErr = Section.getName();
+ if (!SecNameOrErr) {
+ consumeError(SecNameOrErr.takeError());
continue;
- if (Name == ".plt")
+ }
+ if (*SecNameOrErr == ".plt")
Plt = Section;
}
if (!Plt)
@@ -1206,9 +1212,8 @@ 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(
@@ -1581,8 +1586,7 @@ void printRelocations(const ObjectFile *Obj) {
}
for (std::pair<SectionRef, std::vector<SectionRef>> &P : SecToRelSec) {
- StringRef SecName;
- error(P.first.getName(SecName));
+ StringRef SecName = unwrapOrError(P.first.getName(), Obj->getFileName());
outs() << "RELOCATION RECORDS FOR [" << SecName << "]:\n";
for (SectionRef Section : P.second) {
@@ -1654,8 +1658,7 @@ void printSectionHeaders(const ObjectFile *Obj) {
"Idx Name Size VMA Type\n";
for (const SectionRef &Section : ToolSectionFilter(*Obj)) {
- StringRef Name;
- error(Section.getName(Name));
+ StringRef Name = unwrapOrError(Section.getName(), Obj->getFileName());
uint64_t VMA = Section.getAddress();
if (shouldAdjustVA(Section))
VMA += AdjustVMA;
@@ -1682,8 +1685,7 @@ void printSectionHeaders(const ObjectFile *Obj) {
void printSectionContents(const ObjectFile *Obj) {
for (const SectionRef &Section : ToolSectionFilter(*Obj)) {
- StringRef Name;
- error(Section.getName(Name));
+ StringRef Name = unwrapOrError(Section.getName(), Obj->getFileName());
uint64_t BaseAddr = Section.getAddress();
uint64_t Size = Section.getSize();
if (!Size)
@@ -1747,11 +1749,16 @@ 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())
- Section->getName(Name);
- else
+ if (Type == SymbolRef::ST_Debug && Section != O->section_end()) {
+ if (Expected<StringRef> NameOrErr = Section->getName())
+ Name = *NameOrErr;
+ else
+ consumeError(NameOrErr.takeError());
+
+ } else {
Name = unwrapOrError(Symbol.getName(), ArchiveName, FileName,
ArchitectureName);
+ }
bool Global = Flags & SymbolRef::SF_Global;
bool Weak = Flags & SymbolRef::SF_Weak;
@@ -1797,8 +1804,8 @@ void printSymbolTable(const ObjectFile *O, StringRef ArchiveName,
StringRef SegmentName = MachO->getSectionFinalSegmentName(DR);
outs() << SegmentName << ",";
}
- StringRef SectionName;
- error(Section->getName(SectionName));
+ StringRef SectionName =
+ unwrapOrError(Section->getName(), O->getFileName());
outs() << SectionName;
}
@@ -1871,7 +1878,11 @@ void printRawClangAST(const ObjectFile *Obj) {
Optional<object::SectionRef> ClangASTSection;
for (auto Sec : ToolSectionFilter(*Obj)) {
StringRef Name;
- Sec.getName(Name);
+ if (Expected<StringRef> NameOrErr = Sec.getName())
+ Name = *NameOrErr;
+ else
+ consumeError(NameOrErr.takeError());
+
if (Name == ClangASTSectionName) {
ClangASTSection = Sec;
break;
@@ -1903,7 +1914,11 @@ static void printFaultMaps(const ObjectFile *Obj) {
for (auto Sec : ToolSectionFilter(*Obj)) {
StringRef Name;
- Sec.getName(Name);
+ if (Expected<StringRef> NameOrErr = Sec.getName())
+ Name = *NameOrErr;
+ else
+ consumeError(NameOrErr.takeError());
+
if (Name == FaultMapSectionName) {
FaultMapSection = Sec;
break;
OpenPOWER on IntegriCloud