summaryrefslogtreecommitdiffstats
path: root/llvm/tools
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/tools')
-rw-r--r--llvm/tools/llvm-nm/llvm-nm.cpp16
-rw-r--r--llvm/tools/llvm-objcopy/COFF/Reader.cpp6
-rw-r--r--llvm/tools/llvm-objdump/MachODump.cpp25
-rw-r--r--llvm/tools/llvm-readobj/ARMWinEHPrinter.cpp14
-rw-r--r--llvm/tools/llvm-readobj/ARMWinEHPrinter.h2
-rw-r--r--llvm/tools/llvm-readobj/COFFDumper.cpp36
6 files changed, 46 insertions, 53 deletions
diff --git a/llvm/tools/llvm-nm/llvm-nm.cpp b/llvm/tools/llvm-nm/llvm-nm.cpp
index 898ffd8bd92..336167f34bb 100644
--- a/llvm/tools/llvm-nm/llvm-nm.cpp
+++ b/llvm/tools/llvm-nm/llvm-nm.cpp
@@ -525,7 +525,8 @@ static void darwinPrintSymbol(SymbolicFile &Obj, const NMSymbol &S,
}
DataRefImpl Ref = Sec->getRawDataRefImpl();
StringRef SectionName;
- MachO->getSectionName(Ref, SectionName);
+ if (Expected<StringRef> NameOrErr = MachO->getSectionName(Ref))
+ SectionName = *NameOrErr;
StringRef SegmentName = MachO->getSectionFinalSegmentName(Ref);
outs() << "(" << SegmentName << "," << SectionName << ") ";
break;
@@ -951,10 +952,9 @@ static char getSymbolNMTypeChar(COFFObjectFile &Obj, symbol_iterator I) {
section_iterator SecI = *SecIOrErr;
const coff_section *Section = Obj.getCOFFSection(*SecI);
Characteristics = Section->Characteristics;
- StringRef SectionName;
- Obj.getSectionName(Section, SectionName);
- if (SectionName.startswith(".idata"))
- return 'i';
+ if (Expected<StringRef> NameOrErr = Obj.getSectionName(Section))
+ if (NameOrErr->startswith(".idata"))
+ return 'i';
}
switch (Symb.getSectionNumber()) {
@@ -1014,7 +1014,8 @@ static char getSymbolNMTypeChar(MachOObjectFile &Obj, basic_symbol_iterator I) {
return 's';
DataRefImpl Ref = Sec->getRawDataRefImpl();
StringRef SectionName;
- Obj.getSectionName(Ref, SectionName);
+ if (Expected<StringRef> NameOrErr = Obj.getSectionName(Ref))
+ SectionName = *NameOrErr;
StringRef SegmentName = Obj.getSectionFinalSegmentName(Ref);
if (Obj.is64Bit() && Obj.getHeader64().filetype == MachO::MH_KEXT_BUNDLE &&
SegmentName == "__TEXT_EXEC" && SectionName == "__text")
@@ -1136,7 +1137,8 @@ static unsigned getNsectForSegSect(MachOObjectFile *Obj) {
for (auto &S : Obj->sections()) {
DataRefImpl Ref = S.getRawDataRefImpl();
StringRef SectionName;
- Obj->getSectionName(Ref, SectionName);
+ if (Expected<StringRef> NameOrErr = Obj->getSectionName(Ref))
+ SectionName = *NameOrErr;
StringRef SegmentName = Obj->getSectionFinalSegmentName(Ref);
if (SegmentName == SegSect[0] && SectionName == SegSect[1])
return Nsect;
diff --git a/llvm/tools/llvm-objcopy/COFF/Reader.cpp b/llvm/tools/llvm-objcopy/COFF/Reader.cpp
index e91f4597187..774427a7704 100644
--- a/llvm/tools/llvm-objcopy/COFF/Reader.cpp
+++ b/llvm/tools/llvm-objcopy/COFF/Reader.cpp
@@ -75,8 +75,10 @@ Error COFFReader::readSections(Object &Obj) const {
ArrayRef<coff_relocation> Relocs = COFFObj.getRelocations(Sec);
for (const coff_relocation &R : Relocs)
S.Relocs.push_back(R);
- if (auto EC = COFFObj.getSectionName(Sec, S.Name))
- return errorCodeToError(EC);
+ if (Expected<StringRef> NameOrErr = COFFObj.getSectionName(Sec))
+ S.Name = *NameOrErr;
+ else
+ return NameOrErr.takeError();
if (Sec->hasExtendedRelocations())
return createStringError(object_error::parse_failed,
"Extended relocations not supported yet");
diff --git a/llvm/tools/llvm-objdump/MachODump.cpp b/llvm/tools/llvm-objdump/MachODump.cpp
index e5e039cd054..42b82ae5a9d 100644
--- a/llvm/tools/llvm-objdump/MachODump.cpp
+++ b/llvm/tools/llvm-objdump/MachODump.cpp
@@ -965,11 +965,10 @@ static void PrintRelocationEntries(const MachOObjectFile *O,
object::DataRefImpl DRI;
DRI.d.a = r_symbolnum-1;
StringRef SegName = O->getSectionFinalSegmentName(DRI);
- StringRef SectName;
- if (O->getSectionName(DRI, SectName))
- outs() << "(?,?)\n";
+ if (Expected<StringRef> NameOrErr = O->getSectionName(DRI))
+ outs() << "(" << SegName << "," << *NameOrErr << ")\n";
else
- outs() << "(" << SegName << "," << SectName << ")\n";
+ outs() << "(?,?)\n";
}
else {
outs() << "(?,?)\n";
@@ -1022,13 +1021,12 @@ static void PrintRelocations(const MachOObjectFile *O, const bool verbose) {
DataRefImpl DRI;
DRI.d.a = J;
const StringRef SegName = O->getSectionFinalSegmentName(DRI);
- StringRef SectName;
- if (O->getSectionName(DRI, SectName))
+ if (Expected<StringRef> NameOrErr = O->getSectionName(DRI))
+ outs() << "Relocation information (" << SegName << "," << *NameOrErr
+ << format(") %u entries", Sec.nreloc);
+ else
outs() << "Relocation information (" << SegName << ",?) "
<< format("%u entries", Sec.nreloc);
- else
- outs() << "Relocation information (" << SegName << ","
- << SectName << format(") %u entries", Sec.nreloc);
outs() << "\naddress pcrel length extern type scattered "
"symbolnum/value\n";
PrintRelocationEntries(O, O->section_rel_begin(DRI),
@@ -1043,13 +1041,12 @@ static void PrintRelocations(const MachOObjectFile *O, const bool verbose) {
DataRefImpl DRI;
DRI.d.a = J;
const StringRef SegName = O->getSectionFinalSegmentName(DRI);
- StringRef SectName;
- if (O->getSectionName(DRI, SectName))
+ if (Expected<StringRef> NameOrErr = O->getSectionName(DRI))
+ outs() << "Relocation information (" << SegName << "," << *NameOrErr
+ << format(") %u entries", Sec.nreloc);
+ else
outs() << "Relocation information (" << SegName << ",?) "
<< format("%u entries", Sec.nreloc);
- else
- outs() << "Relocation information (" << SegName << ","
- << SectName << format(") %u entries", Sec.nreloc);
outs() << "\naddress pcrel length extern type scattered "
"symbolnum/value\n";
PrintRelocationEntries(O, O->section_rel_begin(DRI),
diff --git a/llvm/tools/llvm-readobj/ARMWinEHPrinter.cpp b/llvm/tools/llvm-readobj/ARMWinEHPrinter.cpp
index 770062aa73b..4de14e2e78d 100644
--- a/llvm/tools/llvm-readobj/ARMWinEHPrinter.cpp
+++ b/llvm/tools/llvm-readobj/ARMWinEHPrinter.cpp
@@ -1094,17 +1094,17 @@ void Decoder::dumpProcedureData(const COFFObjectFile &COFF,
break;
}
-std::error_code Decoder::dumpProcedureData(const COFFObjectFile &COFF) {
+Error Decoder::dumpProcedureData(const COFFObjectFile &COFF) {
for (const auto &Section : COFF.sections()) {
- StringRef SectionName;
- if (std::error_code EC =
- COFF.getSectionName(COFF.getCOFFSection(Section), SectionName))
- return EC;
+ Expected<StringRef> NameOrErr =
+ COFF.getSectionName(COFF.getCOFFSection(Section));
+ if (!NameOrErr)
+ return NameOrErr.takeError();
- if (SectionName.startswith(".pdata"))
+ if (NameOrErr->startswith(".pdata"))
dumpProcedureData(COFF, Section);
}
- return std::error_code();
+ return Error::success();
}
}
}
diff --git a/llvm/tools/llvm-readobj/ARMWinEHPrinter.h b/llvm/tools/llvm-readobj/ARMWinEHPrinter.h
index cb3c482f95e..5de7062cb1d 100644
--- a/llvm/tools/llvm-readobj/ARMWinEHPrinter.h
+++ b/llvm/tools/llvm-readobj/ARMWinEHPrinter.h
@@ -156,7 +156,7 @@ public:
Decoder(ScopedPrinter &SW, bool isAArch64) : SW(SW),
OS(SW.getOStream()),
isAArch64(isAArch64) {}
- std::error_code dumpProcedureData(const object::COFFObjectFile &COFF);
+ Error dumpProcedureData(const object::COFFObjectFile &COFF);
};
}
}
diff --git a/llvm/tools/llvm-readobj/COFFDumper.cpp b/llvm/tools/llvm-readobj/COFFDumper.cpp
index aca5d133a82..e8db76f791c 100644
--- a/llvm/tools/llvm-readobj/COFFDumper.cpp
+++ b/llvm/tools/llvm-readobj/COFFDumper.cpp
@@ -1390,15 +1390,11 @@ void COFFDumper::printSymbols() {
void COFFDumper::printDynamicSymbols() { ListScope Group(W, "DynamicSymbols"); }
-static ErrorOr<StringRef>
+static Expected<StringRef>
getSectionName(const llvm::object::COFFObjectFile *Obj, int32_t SectionNumber,
const coff_section *Section) {
- if (Section) {
- StringRef SectionName;
- if (std::error_code EC = Obj->getSectionName(Section, SectionName))
- return EC;
- return SectionName;
- }
+ if (Section)
+ return Obj->getSectionName(Section);
if (SectionNumber == llvm::COFF::IMAGE_SYM_DEBUG)
return StringRef("IMAGE_SYM_DEBUG");
if (SectionNumber == llvm::COFF::IMAGE_SYM_ABSOLUTE)
@@ -1423,11 +1419,10 @@ void COFFDumper::printSymbol(const SymbolRef &Sym) {
if (Obj->getSymbolName(Symbol, SymbolName))
SymbolName = "";
- StringRef SectionName = "";
- ErrorOr<StringRef> Res =
- getSectionName(Obj, Symbol.getSectionNumber(), Section);
- if (Res)
- SectionName = *Res;
+ StringRef SectionName;
+ if (Expected<StringRef> NameOrErr =
+ getSectionName(Obj, Symbol.getSectionNumber(), Section))
+ SectionName = *NameOrErr;
W.printString("Name", SymbolName);
W.printNumber("Value", Symbol.getValue());
@@ -1495,16 +1490,12 @@ void COFFDumper::printSymbol(const SymbolRef &Sym) {
&& Aux->Selection == COFF::IMAGE_COMDAT_SELECT_ASSOCIATIVE) {
const coff_section *Assoc;
StringRef AssocName = "";
- std::error_code EC = Obj->getSection(AuxNumber, Assoc);
- ErrorOr<StringRef> Res = getSectionName(Obj, AuxNumber, Assoc);
- if (Res)
- AssocName = *Res;
- if (!EC)
- EC = Res.getError();
- if (EC) {
- AssocName = "";
+ if (std::error_code EC = Obj->getSection(AuxNumber, Assoc))
error(EC);
- }
+ Expected<StringRef> Res = getSectionName(Obj, AuxNumber, Assoc);
+ if (!Res)
+ error(Res.takeError());
+ AssocName = *Res;
W.printNumber("AssocSection", AssocName, AuxNumber);
}
@@ -1551,7 +1542,8 @@ void COFFDumper::printUnwindInfo() {
case COFF::IMAGE_FILE_MACHINE_ARMNT: {
ARM::WinEH::Decoder Decoder(W, Obj->getMachine() ==
COFF::IMAGE_FILE_MACHINE_ARM64);
- Decoder.dumpProcedureData(*Obj);
+ // TODO Propagate the error.
+ consumeError(Decoder.dumpProcedureData(*Obj));
break;
}
default:
OpenPOWER on IntegriCloud