aboutsummaryrefslogtreecommitdiff
path: root/llvm/tools/llvm-objdump/llvm-objdump.cpp
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/llvm-objdump.cpp
parenta11d302fa00ba423b09c94491bc868cb991ff379 (diff)
downloadllvm-bcc00e1afbdc107e05b2977fde26053a52295dd1.zip
llvm-bcc00e1afbdc107e05b2977fde26053a52295dd1.tar.gz
llvm-bcc00e1afbdc107e05b2977fde26053a52295dd1.tar.bz2
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/llvm-objdump.cpp')
-rw-r--r--llvm/tools/llvm-objdump/llvm-objdump.cpp57
1 files changed, 36 insertions, 21 deletions
diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp
index 9383385..7a04e11 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;